00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00030
00031
00032
00033
00034
00035 #include "stratagus.h"
00036 #include "ui.h"
00037 #include "video.h"
00038 #include "font.h"
00039 #include "menus.h"
00040
00041
00042
00043
00044
00045
00046
00047
00048
00058 void DrawMenuButton(ButtonStyle *style, unsigned flags, int x, int y,
00059 const std::string &text)
00060 {
00061 std::string nc;
00062 std::string rc;
00063 std::string oldnc;
00064 std::string oldrc;
00065 int i;
00066 ButtonStyleProperties *p;
00067 ButtonStyleProperties *pimage;
00068
00069 if (flags & MI_FLAGS_CLICKED) {
00070 p = &style->Clicked;
00071 } else if (flags & MI_FLAGS_ACTIVE) {
00072 p = &style->Hover;
00073 } else {
00074 p = &style->Default;
00075 }
00076
00077
00078
00079
00080 pimage = p;
00081 if (!p->Sprite) {
00082
00083 if ((flags & MI_FLAGS_ACTIVE) && style->Hover.Sprite) {
00084 pimage = &style->Hover;
00085 } else if (style->Default.Sprite) {
00086 pimage = &style->Default;
00087 }
00088 }
00089 if (pimage->Sprite) {
00090 pimage->Sprite->Load();
00091 }
00092 if (pimage->Sprite) {
00093 pimage->Sprite->DrawFrame(pimage->Frame, x, y);
00094 }
00095
00096
00097
00098
00099 if (!text.empty()) {
00100 GetDefaultTextColors(oldnc, oldrc);
00101 nc = !p->TextNormalColor.empty() ? p->TextNormalColor :
00102 !style->TextNormalColor.empty() ? style->TextNormalColor : oldnc;
00103 rc = !p->TextReverseColor.empty() ? p->TextReverseColor :
00104 !style->TextReverseColor.empty() ? style->TextReverseColor : oldrc;
00105 SetDefaultTextColors(nc, rc);
00106
00107 if (p->TextAlign == TextAlignCenter || p->TextAlign == TextAlignUndefined) {
00108 VideoDrawTextCentered(x + p->TextX, y + p->TextY,
00109 style->Font, text);
00110 } else if (p->TextAlign == TextAlignLeft) {
00111 VideoDrawText(x + p->TextX, y + p->TextY, style->Font, text);
00112 } else {
00113 VideoDrawText(x + p->TextX - style->Font->Width(text), y + p->TextY,
00114 style->Font, text);
00115 }
00116
00117 SetDefaultTextColors(oldnc, oldrc);
00118 }
00119
00120
00121
00122
00123 if (!p->BorderColor) {
00124 p->BorderColor = Video.MapRGB(TheScreen->format,
00125 p->BorderColorRGB.r, p->BorderColorRGB.g, p->BorderColorRGB.b);
00126 }
00127 if (p->BorderSize) {
00128 for (i = 0; i < p->BorderSize; ++i) {
00129 Video.DrawRectangleClip(p->BorderColor, x - i, y - i,
00130 style->Width + 2 * i, style->Height + 2 * i);
00131 }
00132 }
00133 }
00134