-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathPicButton.cpp
More file actions
403 lines (348 loc) · 10.4 KB
/
Copy pathPicButton.cpp
File metadata and controls
403 lines (348 loc) · 10.4 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/*
PicButton.h - animated button with picture
Copyright (C) 2010 Uncle Mike
Copyright (C) 2017 a1batross
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "extdll_menu.h"
#include "BaseMenu.h"
#include "Bitmap.h"
#include "PicButton.h"
#include "Utils.h"
#include "Scissor.h"
#include "Btns.h"
#include <stdlib.h>
#include "Framework.h"
static int g_hotkeys[PC_BUTTONCOUNT] =
{
'n', // PC_NEW_GAME = 0,
'r', // PC_RESUME_GAME,
'h', // PC_HAZARD_COURSE,
'c', // PC_CONFIG,
'l', // PC_LOAD_GAME,
's', // PC_SAVE_LOAD_GAME,
'v', // PC_VIEW_README,
'q', // PC_QUIT,
'm', // PC_MULTIPLAYER,
'e', // PC_EASY,
'm', // PC_MEDIUM,
'd', // PC_DIFFICULT,
's', // PC_SAVE_GAME,
'l', // PC_LOAD_GAME2,
'c', // PC_CANCEL,
'g', // PC_GAME_OPTIONS,
'v', // PC_VIDEO,
'a', // PC_AUDIO,
'c', // PC_CONTROLS,
'd', // PC_DONE,
'q', // PC_QUICKSTART,
'u', // PC_USE_DEFAULTS,
'o', // PC_OK,
'v', // PC_VID_OPT,
'm', // PC_VID_MODES,
'a', // PC_ADV_CONTROLS,
'o', // PC_ORDER_HL,
'd', // PC_DELETE,
'i', // PC_INET_GAME,
'h', // PC_CHAT_ROOMS,
'l', // PC_LAN_GAME,
'u', // PC_CUSTOMIZE,
's', // PC_SKIP,
'e', // PC_EXIT,
'c', // PC_CONNECT,
'r', // PC_REFRESH,
'f', // PC_FILTER,
'f', // PC_FILTER2,
'c', // PC_CREATE,
't', // PC_CREATE_GAME,
'h', // PC_CHAT_ROOMS2,
'l', // PC_LIST_ROOMS,
's', // PC_SEARCH,
's', // PC_SERVERS,
'j', // PC_JOIN,
'f', // PC_FIND,
'r', // PC_CREATE_ROOM,
'j', // PC_JOIN_GAME,
's', // PC_SEARCH_GAMES,
'f', // PC_FIND_GAME,
't', // PC_START_GAME,
'v', // PC_VIEW_GAME_INFO,
'u', // PC_UPDATE,
'a', // PC_ADD_SERVER,
'd', // PC_DISCONNECT,
'o', // PC_CONSOLE, // a1ba: set to O
'o', // PC_CONTENT_CONTROL,
'u', // PC_UPDATE2,
'w', // PC_VISIT_WON,
'p', // PC_PREVIEWS,
'a', // PC_ADV_OPT,
0, // PC_3DINFO_SITE,
'u', // PC_CUSTOM_GAME,
'a', // PC_ACTIVATE,
'i', // PC_INSTALL,
'v', // PC_VISIT_WEB_SITE,
'r', // PC_REFRESH_LIST,
'e', // PC_DEACTIVATE,
'a', // PC_ADV_OPT2,
's', // PC_SPECTATE_GAME,
'p', // PC_SPECTATE_GAMES,
};
CMenuPicButton::CMenuPicButton() : BaseClass()
{
bEnableTransitions = true;
eFocusAnimation = QM_HIGHLIGHTIFFOCUS;
iFlags = QMF_DROPSHADOW;
iFocusStartTime = 0;
eTextAlignment = QM_LEFT;
hPic = 0;
hotkey = 0;
button_id = -1;
iOldState = BUTTON_NOFOCUS;
m_iLastFocusTime = -512;
bPulse = false;
size = uiStatic.buttons_draw_size;
SetCharSize( QM_DEFAULTFONT );
}
/*
=================
CMenuPicButton::Key
=================
*/
bool CMenuPicButton::KeyUp( int key )
{
bool handled = false;
if( UI::Key::IsEnter( key ) && !(iFlags & QMF_MOUSEONLY) )
handled = true;
else if( UI::Key::IsLeftMouse( key ) && ( iFlags & QMF_HASMOUSEFOCUS ) )
handled = true;
if( handled )
_Event( QM_RELEASED );
return handled;
}
void CMenuPicButton::_Event( int ev )
{
BaseClass::_Event( ev );
if( ev == QM_RELEASED )
{
PlayLocalSound( uiStatic.sounds[SND_LAUNCH] );
CheckWindowChanged( );
}
}
void CMenuPicButton::CheckWindowChanged()
{
// parent is not a window, ignore
if( !m_pParent->IsWindow())
return;
CMenuBaseWindow *parentWindow = (CMenuBaseWindow*)m_pParent;
CMenuBaseWindow *newWindow = parentWindow->WindowStack()->Current();
// menu is closed, ignore
if( !newWindow )
return;
// no change, ignore
if( parentWindow == newWindow )
return;
// parent and new are not a root windows, ignore
if( !parentWindow->IsRoot() || !newWindow->IsRoot() )
return;
// decide transition direction
if( FBitSet( parentWindow->iFlags, QMF_CLOSING ))
{
// our parent window is closing right now
// play backward animation
// Con_NPrintf( 10, "%s banner down", parentWindow->szName );
CMenuFramework *f = (CMenuFramework*)parentWindow;
f->PrepareBannerAnimation( CMenuFramework::ANIM_CLOSING, nullptr );
}
else
{
// new window overlaps parent window
// play forward animation
// Con_NPrintf( 10, "%s banner up", newWindow->szName );
CMenuFramework *f = (CMenuFramework*)newWindow;
f->PrepareBannerAnimation( CMenuFramework::ANIM_OPENING, this );
}
}
bool CMenuPicButton::KeyDown( int key )
{
bool handled = false;
if( UI::Key::IsEnter( key ) && !(iFlags & QMF_MOUSEONLY) )
handled = true;
else if( UI::Key::IsLeftMouse( key ) && ( iFlags & QMF_HASMOUSEFOCUS ) )
handled = true;
if( handled )
_Event( QM_PRESSED );
return handled;
}
/*
=================
CMenuPicButton::DrawButton
=================
*/
void CMenuPicButton::DrawButton( int r, int g, int b, int a, wrect_t *rects, int state )
{
EngFuncs::PIC_Set( hPic, r, g, b, a );
EngFuncs::PIC_DrawAdditive( m_scPos, uiStatic.buttons_draw_size.Scale(), &rects[state] );
}
/*
=================
CMenuPicButton::Draw
=================
*/
void CMenuPicButton::Draw( )
{
int state = BUTTON_NOFOCUS;
if( iFlags & (QMF_HASMOUSEFOCUS|QMF_HASKEYBOARDFOCUS))
{
state = BUTTON_FOCUS;
}
// make sure what cursor in rect
if( m_bPressed )
state = BUTTON_PRESSED;
if( iOldState == BUTTON_NOFOCUS && state != BUTTON_NOFOCUS )
iFocusStartTime = uiStatic.realTime;
if( szStatusText && FBitSet( iFlags, QMF_NOTIFY ) && !FBitSet( gMenu.m_gameinfo.flags, GFL_NOSKILLS ))
{
Point coord;
coord.x = m_scPos.x + ( uiStatic.buttons_draw_size.w + 40 ) * uiStatic.scaleX;
coord.y = m_scPos.y + m_scSize.h / 2 - EngFuncs::ConsoleCharacterHeight() / 2;
int r, g, b;
UnpackRGB( r, g, b, uiColorHelp );
EngFuncs::DrawSetTextColor( r, g, b );
EngFuncs::DrawConsoleString( coord, szStatusText );
}
int a = (512 - (uiStatic.realTime - m_iLastFocusTime)) >> 1;
if( hPic && !uiStatic.renderPicbuttonText )
{
int r, g, b;
UnpackRGB( r, g, b, iFlags & QMF_GRAYED ? uiColorDkGrey : uiColorWhite );
wrect_t rects[3];
for( int i = 0; i < 3; i++ )
{
if( button_id >= 0 )
{
rects[i].left = uiStatic.btns.GetX( button_id );
rects[i].right = uiStatic.btns.GetX( button_id ) + uiStatic.btns.GetWidth();
rects[i].top = uiStatic.btns.GetY( button_id ) + i * uiStatic.btns.GetTexStride();
rects[i].bottom = rects[i].top + uiStatic.btns.GetTexH();
}
else
{
rects[i].left = 0;
rects[i].right = EngFuncs::PIC_Width( hPic );
rects[i].top = round( EngFuncs::PIC_Height( hPic ) * i / 3.0f );
rects[i].bottom = round( EngFuncs::PIC_Height( hPic ) * ( i + 1 ) / 3.0f );
}
}
// decay
if( state == BUTTON_NOFOCUS && a > 0 )
{
DrawButton( r, g, b, a, rects, BUTTON_FOCUS );
}
// pulse code.
if( ( state == BUTTON_NOFOCUS && bPulse ) ||
( state == BUTTON_FOCUS && eFocusAnimation == QM_PULSEIFFOCUS ) )
{
a = 255 * (0.5f + 0.5f * sin( (float)uiStatic.realTime / ( UI_PULSE_DIVISOR * 2 )));
DrawButton( r, g, b, a, rects, BUTTON_FOCUS );
DrawButton( r, g, b, 255, rects, BUTTON_NOFOCUS );
}
// special handling for focused
else if( state == BUTTON_FOCUS )
{
DrawButton( r, g, b, 255, rects, BUTTON_FOCUS );
DrawButton( r, g, b, 255, rects, BUTTON_NOFOCUS );
}
else
{
// just draw
DrawButton( r, g, b, 255, rects, state );
}
}
else if( !uiStatic.lowmemory )
{
const uint heavy_blur_flags = ETF_NOSIZELIMIT | ETF_FORCECOL;
const uint light_blur_flags = ETF_NOSIZELIMIT | ETF_FORCECOL | ETF_ADDITIVE;
CColor light_blur_color, heavy_blur_color = colorBase;
Point pos = m_scPos;
if( iFlags & QMF_GRAYED )
light_blur_color = InterpColor( uiColorBlack, colorBase, 0.333f ); // because additive, tone down all channels
else
light_blur_color = colorBase;
pos.x += 7 * uiStatic.scaleX;
pos.y -= uiStatic.scaleY;
if( this != m_pParent->ItemAtCursor() )
{
if( a > 0 )
{
UI_DrawString( uiStatic.hHeavyBlur, pos, m_scSize, szName,
PackAlpha( heavy_blur_color, a ), m_scChSize, eTextAlignment, heavy_blur_flags );
}
UI_DrawString( uiStatic.hLightBlur, pos, m_scSize, szName, light_blur_color, m_scChSize, eTextAlignment, light_blur_flags );
}
else if( m_bPressed )
{
UI_DrawString( uiStatic.hHeavyBlur, pos, m_scSize, szName, heavy_blur_color, m_scChSize, eTextAlignment, heavy_blur_flags );
UI_DrawString( uiStatic.hLightBlur, pos, m_scSize, szName, 0xFF000000, m_scChSize, eTextAlignment, light_blur_flags & ( ~ETF_ADDITIVE ));
}
else if( eFocusAnimation == QM_HIGHLIGHTIFFOCUS )
{
UI_DrawString( uiStatic.hHeavyBlur, pos, m_scSize, szName, heavy_blur_color, m_scChSize, eTextAlignment, heavy_blur_flags );
UI_DrawString( uiStatic.hLightBlur, pos, m_scSize, szName, light_blur_color, m_scChSize, eTextAlignment, light_blur_flags );
}
else if( eFocusAnimation == QM_PULSEIFFOCUS )
{
float pulsar = 0.5f + 0.5f * sin( (float)uiStatic.realTime / UI_PULSE_DIVISOR );
UI_DrawString( uiStatic.hHeavyBlur, pos, m_scSize, szName,
InterpColor( uiColorBlack, heavy_blur_color, pulsar ), m_scChSize, eTextAlignment, heavy_blur_flags );
UI_DrawString( uiStatic.hLightBlur, pos, m_scSize, szName, light_blur_color, m_scChSize, eTextAlignment, light_blur_flags );
}
}
else
{
uint textflags = ETF_NOSIZELIMIT | ETF_FORCECOL;
SetBits( textflags, (iFlags & QMF_DROPSHADOW) ? ETF_SHADOW : 0 );
if( iFlags & QMF_GRAYED )
{
UI_DrawString( font, m_scPos, m_scSize, szName, uiColorDkGrey, m_scChSize, eTextAlignment, textflags );
}
else if( this != m_pParent->ItemAtCursor() )
{
UI_DrawString( font, m_scPos, m_scSize, szName, colorBase, m_scChSize, eTextAlignment, textflags );
}
else if( eFocusAnimation == QM_HIGHLIGHTIFFOCUS )
{
UI_DrawString( font, m_scPos, m_scSize, szName, colorFocus, m_scChSize, eTextAlignment, textflags );
}
else if( eFocusAnimation == QM_PULSEIFFOCUS )
{
float pulsar = 0.5f + 0.5f * sin( (float)uiStatic.realTime / UI_PULSE_DIVISOR );
UI_DrawString( font, m_scPos, m_scSize, szName,
InterpColor( colorBase, colorFocus, pulsar ), m_scChSize, eTextAlignment, textflags );
}
}
iOldState = state;
}
void CMenuPicButton::SetPicture( EDefaultBtns ID )
{
if( ID < 0 || ID > PC_BUTTONCOUNT )
return; // bad id
hPic = uiStatic.btns.GetPic( ID );
button_id = ID;
hotkey = g_hotkeys[ID];
}
void CMenuPicButton::SetPicture( const char *filename, int hk )
{
hPic = EngFuncs::PIC_Load( filename );
hotkey = hk;
}
bool CMenuPicButton::HotKey( int key )
{
return hotkey == key;
}