| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name menu_proc.cpp - The menu processing code. */ |
| 11 |
// |
| 12 |
// (c) Copyright 1999-2007 by Andreas Arens, Jimmy Salmon, Nehal Mistry |
| 13 |
// |
| 14 |
// This program is free software; you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation; only version 2 of the License. |
| 17 |
// |
| 18 |
// This program is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program; if not, write to the Free Software |
| 25 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
// 02111-1307, USA. |
| 27 |
// |
| 28 |
|
| 29 |
//@{ |
| 30 |
|
| 31 |
/*---------------------------------------------------------------------------- |
| 32 |
-- Includes |
| 33 |
----------------------------------------------------------------------------*/ |
| 34 |
|
| 35 |
#include "stratagus.h" |
| 36 |
#include "ui.h" |
| 37 |
#include "video.h" |
| 38 |
#include "font.h" |
| 39 |
#include "menus.h" |
| 40 |
|
| 41 |
/*---------------------------------------------------------------------------- |
| 42 |
-- Variables |
| 43 |
----------------------------------------------------------------------------*/ |
| 44 |
|
| 45 |
/*---------------------------------------------------------------------------- |
| 46 |
-- Menu operation functions |
| 47 |
----------------------------------------------------------------------------*/ |
| 48 |
|
| 49 |
/** |
| 50 |
** Draw menu button 'button' on x,y |
| 51 |
** |
| 52 |
** @param style Button style |
| 53 |
** @param flags State of Button (clicked, mouse over...) |
| 54 |
** @param x X display position |
| 55 |
** @param y Y display position |
| 56 |
** @param text text to print on button |
| 57 |
*/ |
| 58 |
void DrawMenuButton(ButtonStyle *style, unsigned flags, int x, int y, |
| 59 |
const std::string &text) |
| 60 |
{ |
| 61 |
std::string *nc; |
| 62 |
std::string *rc; |
| 63 |
std::string oldnc; |
| 64 |
std::string oldrc; |
| 65 |
ButtonStyleProperties *p; |
| 66 |
ButtonStyleProperties *pimage; |
| 67 |
|
| 68 |
if (flags & MI_FLAGS_CLICKED) { |
| 69 |
p = &style->Clicked; |
| 70 |
} else if (flags & MI_FLAGS_ACTIVE) { |
| 71 |
p = &style->Hover; |
| 72 |
} else { |
| 73 |
p = &style->Default; |
| 74 |
} |
| 75 |
|
| 76 |
// |
| 77 |
// Image |
| 78 |
// |
| 79 |
pimage = p; |
| 80 |
if (!p->Sprite) { |
| 81 |
// No image. Try hover, selected, then default |
| 82 |
if ((flags & MI_FLAGS_ACTIVE) && style->Hover.Sprite) { |
| 83 |
pimage = &style->Hover; |
| 84 |
} else if (style->Default.Sprite) { |
| 85 |
pimage = &style->Default; |
| 86 |
} |
| 87 |
} |
| 88 |
if (pimage->Sprite) { |
| 89 |
pimage->Sprite->Load(); |
| 90 |
} |
| 91 |
if (pimage->Sprite) { |
| 92 |
pimage->Sprite->DrawFrame(pimage->Frame, x, y); |
| 93 |
} |
| 94 |
|
| 95 |
// |
| 96 |
// Text |
| 97 |
// |
| 98 |
if (!text.empty()) { |
| 99 |
GetDefaultTextColors(oldnc, oldrc); |
| 100 |
nc = !p->TextNormalColor.empty() ? &p->TextNormalColor : |
| 101 |
!style->TextNormalColor.empty() ? &style->TextNormalColor : &oldnc; |
| 102 |
rc = !p->TextReverseColor.empty() ? &p->TextReverseColor : |
| 103 |
!style->TextReverseColor.empty() ? &style->TextReverseColor : &oldrc; |
| 104 |
SetDefaultTextColors(*nc, *rc); |
| 105 |
|
| 106 |
if (p->TextAlign == TextAlignCenter || p->TextAlign == TextAlignUndefined) { |
| 107 |
VideoDrawTextCentered(x + p->TextX, y + p->TextY, |
| 108 |
style->Font, text); |
| 109 |
} else if (p->TextAlign == TextAlignLeft) { |
| 110 |
VideoDrawText(x + p->TextX, y + p->TextY, style->Font, text); |
| 111 |
} else { |
| 112 |
VideoDrawText(x + p->TextX - style->Font->Width(text), y + p->TextY, |
| 113 |
style->Font, text); |
| 114 |
} |
| 115 |
|
| 116 |
SetDefaultTextColors(oldnc, oldrc); |
| 117 |
} |
| 118 |
|
| 119 |
// |
| 120 |
// Border |
| 121 |
// |
| 122 |
if (!p->BorderColor) { |
| 123 |
p->BorderColor = Video.MapRGB(TheScreen->format, |
| 124 |
p->BorderColorRGB.r, p->BorderColorRGB.g, p->BorderColorRGB.b); |
| 125 |
} |
| 126 |
if (p->BorderSize) { |
| 127 |
for (int i = 0; i < p->BorderSize; ++i) { |
| 128 |
Video.DrawRectangleClip(p->BorderColor, x - i, y - i, |
| 129 |
style->Width + 2 * i, style->Height + 2 * i); |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
//@} |