-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBookMenu.cpp
242 lines (217 loc) · 5.77 KB
/
BookMenu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#include "BookMenu.h"
BookMenu::BookMenu()
{
}
BookMenu::~BookMenu()
{
}
void BookMenu::InitZom()
{
int btn_width = 113;
int btn_height = 40;
SetBtnBmp(L"res\\images\\interface\\menu\\handbook\\Button.png", btn_width, btn_height);
MENU_INFO menuInfo;
menuInfo.align = 1;
menuInfo.fontName = L"黑体";
menuInfo.focusTextColor = Color::Color(16,237,22);
menuInfo.normalTextColor = Color::Color(16,237, 22);
menuInfo.space = MENU_SPACE;
menuInfo.isBold = true;
menuInfo.width = btn_width;
menuInfo.height = btn_height;
SetMenuInfo(menuInfo);
MENUITEM item;
item.pos.x = 600;
item.pos.y = 350;
item.ItemName = L"查看僵尸";
AddMenuItem(item);
}
void BookMenu::InitSun()
{
int btn_width = 110;
int btn_height = 41;
SetBtnBmp(L"res\\images\\interface\\menu\\handbook\\Button.png", btn_width, btn_height);
MENU_INFO menuInfo;
menuInfo.align = 1;
menuInfo.fontName = L"黑体";
menuInfo.focusTextColor = Color::Color(255, 203, 105);
menuInfo.normalTextColor = Color::Color(255, 203, 105);
menuInfo.space = MENU_SPACE;
menuInfo.isBold = true;
menuInfo.width = btn_width;
menuInfo.height = btn_height;
SetMenuInfo(menuInfo);
MENUITEM item;
item.pos.x = 200;
item.pos.y = 350;
item.ItemName = L"查看植物";
AddMenuItem(item);
}
void BookMenu::InitReturn()
{
int btn_width = 89;
int btn_height = 26;
SetBtnBmp(L"res\\images\\interface\\menu\\handbook\\Almanac_CloseButton.png", btn_width, btn_height);
MENU_INFO menuInfo;
menuInfo.align = 1;
menuInfo.fontName = L"黑体";
menuInfo.focusTextColor = Color::Black;
menuInfo.normalTextColor = Color::Black;
menuInfo.space = MENU_SPACE;
menuInfo.isBold = true;
menuInfo.width = btn_width;
menuInfo.height = btn_height;
SetMenuInfo(menuInfo);
MENUITEM item;
item.pos.x = WIN_WIDTH - btn_width - 80;
item.pos.y = WIN_HEIGHT - btn_height - 50 ;
item.ItemName = L"返 回";
AddMenuItem(item);
}
void BookMenu::InitShut() {
int btn_width = 89;
int btn_height = 26;
SetBtnBmp(L"res\\images\\interface\\menu\\handbook\\Almanac_CloseButton.png", btn_width, btn_height);
MENU_INFO menuInfo;
menuInfo.align = 1;
menuInfo.fontName = L"黑体";
menuInfo.focusTextColor = Color::Black;
menuInfo.normalTextColor = Color::Black;
menuInfo.space = MENU_SPACE;
menuInfo.isBold = true;
menuInfo.width = btn_width;
menuInfo.height = btn_height;
SetMenuInfo(menuInfo);
MENUITEM item;
item.pos.x = WIN_WIDTH - btn_width - 80;
item.pos.y = WIN_HEIGHT - btn_height - 15;
item.ItemName = L"关闭";
AddMenuItem(item);
}
void BookMenu::InitP_return() {
int btn_width = 164;
int btn_height = 26;
SetBtnBmp(L"res\\images\\interface\\menu\\handbook\\Almanac_IndexButton.png", btn_width, btn_height);
MENU_INFO menuInfo;
menuInfo.align = 1;
menuInfo.fontName = L"黑体";
menuInfo.focusTextColor = Color::Black;
menuInfo.normalTextColor = Color::Black;
menuInfo.space = MENU_SPACE;
menuInfo.isBold = true;
menuInfo.width = btn_width;
menuInfo.height = btn_height;
SetMenuInfo(menuInfo);
MENUITEM item;
item.pos.x = 70;
item.pos.y = WIN_HEIGHT - btn_height - 15;
item.ItemName = L"返回索引";
AddMenuItem(item);
}
int BookMenu::GetMenuIndex(int x, int y)
{
int Index = -1;
POINT pt;
pt.x = x;
pt.y = y;
int w = menu_info.width;
int h = menu_info.height;
RECT rec;
int iCount = 0;
vector<MENUITEM>::iterator iter;
for (iter = gm_menuItems.begin(); iter != gm_menuItems.end(); iter++)
{
rec.left = iter->pos.x;
rec.top = iter->pos.y;
rec.right = rec.left + w;
rec.bottom = rec.top + h;
if (PtInRect(&rec, pt))
{
return iCount;
}
iCount++;
}
return Index;
}
void BookMenu::DrawMenu(HDC hdc, BYTE btnTrans, bool startState)
{
if (&gm_menuBkg != NULL && startState == true)
{
gm_menuBkg.PaintImage(hdc, (WIN_WIDTH - gm_menuBkg.GetImageWidth()) / 2, (WIN_HEIGHT - gm_menuBkg.GetImageHeight()) / 2,
gm_menuBkg.GetImageWidth(), gm_menuBkg.GetImageHeight(), bkImageAlpha);
}
int w = menu_info.width;
int h = menu_info.height;
int FontHeight;
int px = 0;
int w_px = w / (MaxMenuItemLen + 1); //计算每个字所占的像素
int h_px = (int)((float)(h / 2.5));
if (w_px > h_px)
{
px = h_px;
}
else
{
px = w_px;
}
FontHeight = (px * 72) / 88; //根据每个字的像素计算字号
if (isItemFocused == FALSE)
{
Gdiplus::RectF Rec;
vector<MENUITEM>::iterator iter;
for (iter = gm_menuItems.begin(); iter != gm_menuItems.end(); iter++)
{
int x = iter->pos.x;
int y = iter->pos.y;
// 绘制按钮图像
if (&BtnDIB != NULL)
{
BtnDIB.PaintRegion(BtnDIB.GetBmpHandle(), hdc, x, y, 0, 0, w, h, 1, 0, btnTrans);
}
Rec.X = (float)x;
Rec.Y = (float)y;
Rec.Width = (float)w;
Rec.Height = (float)h;
// 绘制按钮文字
wstring item = iter->ItemName.c_str();
T_Graph::PaintText(hdc, Rec, item, (REAL)FontHeight, menu_info.fontName,
menu_info.normalTextColor, GetFontStyle(), GetAlignment());
}
}
if (isItemFocused == TRUE)
{
int mIndex = 0;
Gdiplus::RectF Rec;
vector<MENUITEM>::iterator iter;
for (iter = gm_menuItems.begin(); iter != gm_menuItems.end(); iter++)
{
int x = iter->pos.x;
int y = iter->pos.y;
Rec.X = (float)x;
Rec.Y = (float)y;
Rec.Width = (float)w;
Rec.Height = (float)h;
if (mIndex != m_index)
{
if (&BtnDIB != NULL)
{
BtnDIB.PaintRegion(BtnDIB.GetBmpHandle(), hdc, x, y, 0, 0, w, h, 1, 0, btnTrans);
}
wstring item = iter->ItemName.c_str();
T_Graph::PaintText(hdc, Rec, item, (REAL)FontHeight, menu_info.fontName,
menu_info.normalTextColor, GetFontStyle(), GetAlignment());
}
if (mIndex == m_index)
{
if (&BtnDIB != NULL)
{
BtnDIB.PaintRegion(BtnDIB.GetBmpHandle(), hdc, x, y, 0, h, w, h, 1, 0, btnTrans);
}
wstring item = iter->ItemName.c_str();
T_Graph::PaintText(hdc, Rec, item, (REAL)FontHeight, menu_info.fontName,
menu_info.focusTextColor, GetFontStyle(), GetAlignment());
}
mIndex = mIndex + 1;
}
}
}