forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameWindowManager.cpp
More file actions
4064 lines (3282 loc) · 139 KB
/
GameWindowManager.cpp
File metadata and controls
4064 lines (3282 loc) · 139 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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: GameWindowManager.cpp ////////////////////////////////////////////////////////////////////
// Created: Colin Day, June 2001
// Dean Iverson, March 1998 (Original window code)
// Desc: The game window manager is the singleton class that we interface
// with to interact with the game windowing system.
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/Debug.h"
#include "Common/Language.h"
#include "GameClient/Display.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GameWindow.h"
#include "GameClient/Mouse.h"
#include "GameClient/DisplayStringManager.h"
#include "GameClient/WindowLayout.h"
#include "GameClient/Gadget.h"
#include "GameClient/GameWindowGlobal.h"
#include "GameClient/GadgetListBox.h"
#include "GameClient/GadgetComboBox.h"
#include "GameClient/GadgetTabControl.h"
#include "GameClient/GadgetProgressBar.h"
#include "GameClient/GadgetStaticText.h"
#include "GameClient/GadgetTextEntry.h"
#include "GameClient/GadgetSlider.h"
#include "GameClient/GadgetRadioButton.h"
#include "GameClient/GadgetCheckBox.h"
#include "GameClient/GlobalLanguage.h"
#include "GameClient/GameWindowTransitions.h"
#include "Common/NameKeyGenerator.h"
// PUBLIC DATA ////////////////////////////////////////////////////////////////////////////////////
GameWindowManager *TheWindowManager = nullptr;
UnsignedInt WindowLayoutCurrentVersion = 2;
///////////////////////////////////////////////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// with this status set to true, the window system will propagate mouse position
// messages to windows. You may want to disable this if you feel the mouse position
// messages are "spamming" your window and making a particular debugging situation
// difficult. Make sure you do enable this before you check in again tho because
// it is necessary for any code that needs to look at objects or anything under
// the radar cursor
//
static Bool sendMousePosMessages = TRUE;
//-------------------------------------------------------------------------------------------------
/** Process windows waiting to be destroyed */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::processDestroyList()
{
GameWindow *next;
GameWindow *doDestroy;
//
// we need to pass the ownership of the destroy list so
// if, while destroying a window, we need to add other windows
// to the destroy list it won't cause problems.
//
doDestroy = m_destroyList;
// set the list to empty
m_destroyList = nullptr;
// do the destroys
for( ; doDestroy; doDestroy = next )
{
next = doDestroy->m_next;
// Check to see if this window is "special"
if( m_mouseCaptor == doDestroy )
winRelease( doDestroy );
if( m_keyboardFocus == doDestroy )
winSetFocus( nullptr );
if( (m_modalHead != nullptr) && (doDestroy == m_modalHead->window) )
winUnsetModal( m_modalHead->window );
if( m_currMouseRgn == doDestroy )
m_currMouseRgn = nullptr;
if( m_grabWindow == doDestroy )
m_grabWindow = nullptr;
// send the destroy message to the window we're about to kill
winSendSystemMsg( doDestroy, GWM_DESTROY, 0, 0 );
DEBUG_ASSERTCRASH(doDestroy->winGetUserData() == nullptr, ("Win user data is expected to be deleted now"));
// free the memory
deleteInstance(doDestroy);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
/** Generic function to simply propagate only button press messages to parent and let it deal with it */
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType PassSelectedButtonsToParentSystem( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
// sanity
if( window == nullptr )
return MSG_IGNORED;
if( (msg == GBM_SELECTED) || (msg == GBM_SELECTED_RIGHT) || (msg == GBM_MOUSE_ENTERING) || (msg == GBM_MOUSE_LEAVING) || (msg == GEM_EDIT_DONE))
{
GameWindow *parent = window->winGetParent();
if( parent )
return TheWindowManager->winSendSystemMsg( parent, msg, mData1, mData2 );
}
return MSG_IGNORED;
}
//-------------------------------------------------------------------------------------------------
/** Generic function to simply propagate only button press messages to parent and let it deal with it */
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType PassMessagesToParentSystem( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
// sanity
if( window == nullptr )
return MSG_IGNORED;
GameWindow *parent = window->winGetParent();
if( parent )
return TheWindowManager->winSendSystemMsg( parent, msg, mData1, mData2 );
return MSG_IGNORED;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
GameWindowManager::GameWindowManager()
{
m_windowList = nullptr; // list of all top level windows
m_windowTail = nullptr; // last in windowList
m_destroyList = nullptr; // list of windows to destroy
m_currMouseRgn = nullptr; // window that mouse is over
m_mouseCaptor = nullptr; // window that captured mouse
m_keyboardFocus = nullptr; // window that has input focus
m_modalHead = nullptr; // top of windows in the modal stack
m_grabWindow = nullptr; // window that grabbed the last down event
m_loneWindow = nullptr; // Set if we just opened a combo box
m_cursorBitmap = nullptr;
m_captureFlags = 0;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
GameWindowManager::~GameWindowManager()
{
// destroy all windows
winDestroyAll();
freeStaticStrings();
delete TheTransitionHandler;
TheTransitionHandler = nullptr;
}
//-------------------------------------------------------------------------------------------------
/** Initialize the game window manager system */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::init()
{
if(!TheTransitionHandler)
TheTransitionHandler = NEW GameWindowTransitionsHandler;
TheTransitionHandler->load();
TheTransitionHandler->init();
}
//-------------------------------------------------------------------------------------------------
/** Reset window system */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::reset()
{
// destroy all windows left
winDestroyAll();
if(TheTransitionHandler)
TheTransitionHandler->reset();
}
//-------------------------------------------------------------------------------------------------
/** Update cycle for game window manager */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::update()
{
// Process windows waiting to be destroyed
processDestroyList();
if(TheTransitionHandler)
TheTransitionHandler->update();
}
//-------------------------------------------------------------------------------------------------
/** Puts a window at the head of the window list */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::linkWindow( GameWindow *window )
{
GameWindow *lastModalWindow = nullptr;
GameWindow *tmp = m_windowList;
while (tmp)
{
const ModalWindow *modal = m_modalHead;
while (modal)
{
if (modal->window == tmp && modal->window != window)
{
lastModalWindow = tmp;
}
modal = modal->next;
}
tmp = tmp->m_next;
}
if (!lastModalWindow)
{
// Add to head of the top level window list
window->m_prev = nullptr;
window->m_next = m_windowList;
if( m_windowList )
m_windowList->m_prev = window;
else
{
// first on list is also the tail
m_windowTail = window;
}
m_windowList = window;
}
else
{
// lastModalWindow points to a modal window - add behind it
window->m_prev = lastModalWindow;
window->m_next = lastModalWindow->m_next;
lastModalWindow->m_next = window;
if (window->m_next)
{
window->m_next->m_prev = window;
}
}
}
//-------------------------------------------------------------------------------------------------
/** Insert the window ahead of the the 'aheadOf' window. 'aheadOf' can
* be a window in the master list or a child of any window in that master
* list */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::insertWindowAheadOf( GameWindow *window,
GameWindow *aheadOf )
{
// sanity
if( window == nullptr )
return;
// we'll say that an aheadOf window means at the head of the list
if( aheadOf == nullptr )
{
linkWindow( window );
return;
}
// get parent of aheadOf
GameWindow *aheadOfParent = aheadOf->winGetParent();
//
// if ahead of has no parent insert it in the master list just before
// ahead of
//
if( aheadOfParent == nullptr )
{
window->m_prev = aheadOf->m_prev;
if( aheadOf->m_prev )
aheadOf->m_prev->m_next = window;
else
m_windowList = window;
aheadOf->m_prev = window;
window->m_next = aheadOf;
}
else
{
window->m_prev = aheadOf->m_prev;
if( aheadOf->m_prev )
aheadOf->m_prev->m_next = window;
else
aheadOfParent->m_child = window;
aheadOf->m_prev = window;
window->m_next = aheadOf;
window->m_parent = aheadOfParent;
}
}
//-------------------------------------------------------------------------------------------------
/** Takes a window off the window list */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::unlinkWindow( GameWindow *window )
{
if( window->m_next )
window->m_next->m_prev = window->m_prev;
else
{
// no next means this is the tail
m_windowTail = window->m_prev;
}
if( window->m_prev )
window->m_prev->m_next = window->m_next;
else
m_windowList = window->m_next;
}
//-------------------------------------------------------------------------------------------------
/** Takes a child window off its parent's window list */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::unlinkChildWindow( GameWindow *window )
{
if( window->m_prev )
{
window->m_prev->m_next = window->m_next;
if( window->m_next )
window->m_next->m_prev = window->m_prev;
}
else
{
if( window->m_next )
{
window->m_parent->m_child = window->m_next;
window->m_next->m_prev = window->m_prev;
window->m_next = nullptr;
}
else
{
window->m_parent->m_child = nullptr;
}
}
// remove the parent reference from this window
window->m_parent = nullptr;
}
//-------------------------------------------------------------------------------------------------
/** Check window and parents to see if this window is enabled */
//-------------------------------------------------------------------------------------------------
Bool GameWindowManager::isEnabled( GameWindow *win )
{
// sanity
if( win == nullptr )
return FALSE;
if( BitIsSet( win->m_status, WIN_STATUS_ENABLED ) == FALSE )
{
return FALSE;
}
while( win->m_parent )
{
win = win->m_parent;
if( BitIsSet( win->m_status, WIN_STATUS_ENABLED ) == FALSE )
{
return FALSE;
}
}
return TRUE;
}
//-------------------------------------------------------------------------------------------------
/** Check window and parents to see if this window is hidden */
//-------------------------------------------------------------------------------------------------
Bool GameWindowManager::isHidden( GameWindow *win )
{
// we'll allow for the idea that if a window doesn't exist it is hidden
if( win == nullptr )
return TRUE;
if( BitIsSet( win->m_status, WIN_STATUS_HIDDEN ))
{
return TRUE;
}
while( win->m_parent )
{
win = win->m_parent;
if( BitIsSet( win->m_status, WIN_STATUS_HIDDEN ))
{
return TRUE;
}
}
return FALSE;
}
//-------------------------------------------------------------------------------------------------
// Adds a child window to its parent.
//-------------------------------------------------------------------------------------------------
void GameWindowManager::addWindowToParent( GameWindow *window,
GameWindow *parent )
{
if( parent )
{
// add to parent's list of children
window->m_prev = nullptr;
window->m_next = parent->m_child;
if( parent->m_child )
parent->m_child->m_prev = window;
parent->m_child = window;
window->m_parent = parent;
}
}
//-------------------------------------------------------------------------------------------------
/** Add a child window to the parent, put place it at the end of the
* parent window child list */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::addWindowToParentAtEnd( GameWindow *window,
GameWindow *parent )
{
if( parent )
{
window->m_prev = nullptr;
window->m_next = nullptr;
if( parent->m_child )
{
GameWindow *last;
// wind down to last child in list
last = parent->m_child;
while( last->m_next != nullptr )
last = last->m_next;
// tie to list
last->m_next = window;
window->m_prev = last;
}
else
parent->m_child = window;
// assign the parent to the window
window->m_parent = parent;
}
}
//-------------------------------------------------------------------------------------------------
/** this gets called from winHide() when a window hides itself */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::windowHiding( GameWindow *window )
{
// if this window has keyboard focus remove it
if( m_keyboardFocus == window )
m_keyboardFocus = nullptr;
// if this is the modal head, unset it
if( m_modalHead && m_modalHead->window == window )
winUnsetModal( window );
// if this is the captor, it shall no longer be
if( m_mouseCaptor == window )
winCapture( nullptr );
//
// since hiding a parent will also hide the children, when a parent
// hides we must call this same method for all the children so they
// each have a chance to go through this logic
//
GameWindow *child;
for( child = window->winGetChild(); child; child = child->winGetNext() )
windowHiding( child );
}
//-------------------------------------------------------------------------------------------------
/** Hide all windows in a certain range of id's (inclusive) */
//-------------------------------------------------------------------------------------------------
void GameWindowManager::hideWindowsInRange( GameWindow *baseWindow,
Int first, Int last,
Bool hideFlag )
{
Int i;
GameWindow *window;
for( i = first; i <= last; i++ )
{
window = winGetWindowFromId( baseWindow, i );
if( window )
window->winHide( hideFlag );
}
}
//-------------------------------------------------------------------------------------------------
// Enable all windows in a certain range of id's (inclusive)
//-------------------------------------------------------------------------------------------------
void GameWindowManager::enableWindowsInRange( GameWindow *baseWindow,
Int first, Int last,
Bool enableFlag )
{
Int i;
GameWindow *window;
for( i =first; i <= last; i++ )
{
window = winGetWindowFromId( baseWindow, i );
if( window )
window->winEnable( enableFlag );
}
}
//-------------------------------------------------------------------------------------------------
/** Captures the mouse capture. */
//-------------------------------------------------------------------------------------------------
Int GameWindowManager::winCapture( GameWindow *window )
{
if( m_mouseCaptor != nullptr)
return WIN_ERR_MOUSE_CAPTURED;
m_mouseCaptor = window;
return WIN_ERR_OK;
}
//-------------------------------------------------------------------------------------------------
/** Releases the mouse capture. */
//-------------------------------------------------------------------------------------------------
Int GameWindowManager::winRelease( GameWindow *window )
{
if( window == m_mouseCaptor )
m_mouseCaptor = nullptr;
return WIN_ERR_OK;
}
//-------------------------------------------------------------------------------------------------
/** Returns the current mouse captor. */
//-------------------------------------------------------------------------------------------------
GameWindow *GameWindowManager::winGetCapture()
{
return m_mouseCaptor;
}
//-------------------------------------------------------------------------------------------------
/** Gets the window pointer from its id */
//-------------------------------------------------------------------------------------------------
GameWindow *GameWindowManager::winGetWindowFromId( GameWindow *window, Int id )
{
if( window == nullptr )
window = m_windowList;
for( ; window; window = window->m_next )
{
if( window->winGetWindowId() == id)
return window;
else if( window->m_child )
{
GameWindow *child = winGetWindowFromId( window->m_child, id );
if( child )
return child;
}
}
return nullptr;
}
//-------------------------------------------------------------------------------------------------
/** Gets the Window List Pointer */
//-------------------------------------------------------------------------------------------------
GameWindow *GameWindowManager::winGetWindowList()
{
return m_windowList;
}
//-------------------------------------------------------------------------------------------------
/** Send a system message to the specified window */
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType GameWindowManager::winSendSystemMsg( GameWindow *window,
UnsignedInt msg,
WindowMsgData mData1,
WindowMsgData mData2 )
{
if( window == nullptr)
return MSG_IGNORED;
if( msg != GWM_DESTROY && BitIsSet( window->m_status, WIN_STATUS_DESTROYED ) )
return MSG_IGNORED;
return window->m_system( window, msg, mData1, mData2 );
}
//-------------------------------------------------------------------------------------------------
/** Send a system message to the specified window */
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType GameWindowManager::winSendInputMsg( GameWindow *window,
UnsignedInt msg,
WindowMsgData mData1,
WindowMsgData mData2 )
{
if( window == nullptr )
return MSG_IGNORED;
if( msg != GWM_DESTROY && BitIsSet( window->m_status, WIN_STATUS_DESTROYED ) )
return MSG_IGNORED;
return window->m_input( window, msg, mData1, mData2 );
}
//-------------------------------------------------------------------------------------------------
/** Get the current input focus */
//-------------------------------------------------------------------------------------------------
GameWindow *GameWindowManager::winGetFocus()
{
return m_keyboardFocus;
}
//-------------------------------------------------------------------------------------------------
/** Set the current input focus */
//-------------------------------------------------------------------------------------------------
Int GameWindowManager::winSetFocus( GameWindow *window )
{
Bool wantsFocus = FALSE;
// if a window doesn't want keyboard focus don't give it
if( window )
if( BitIsSet( window->winGetStatus(), WIN_STATUS_NO_FOCUS) )
return 0;
//
// Tell current focus window that it's losing focus
// unless we are trying to give focus to the current focus window
//
if( (m_keyboardFocus) && (m_keyboardFocus != window) )
{
Bool wf; // dummy var, ignored, but must be passed
winSendSystemMsg( m_keyboardFocus, GWM_INPUT_FOCUS, FALSE, (WindowMsgData)&wf );
}
// Set focus to new window
m_keyboardFocus = window;
// Tell new focus window that it has focus
if( m_keyboardFocus )
{
for (;;)
{
winSendSystemMsg( window, GWM_INPUT_FOCUS, TRUE, (WindowMsgData)&wantsFocus );
if (wantsFocus)
break;
window = window->winGetParent();
if( window == nullptr )
break;
}
}
// If new window doesn't want focus, set focus to nullptr
if( wantsFocus == FALSE )
m_keyboardFocus = nullptr;
return WIN_ERR_OK;
}
//-------------------------------------------------------------------------------------------------
/** Process key press through the GUI. */
//-------------------------------------------------------------------------------------------------
WinInputReturnCode GameWindowManager::winProcessKey( UnsignedByte key,
UnsignedByte state )
{
WinInputReturnCode returnCode = WIN_INPUT_NOT_USED;
// Check for keyboard focus and a legal key for sanity
if( m_keyboardFocus && (key != KEY_NONE) )
{
GameWindow *win = m_keyboardFocus;
returnCode = WIN_INPUT_USED; // assume input will be used
//
// Pass the keystroke up the window hierarchy until it is
// processed or we reach the top level window
//
while( winSendInputMsg( win, GWM_CHAR, key, state ) == MSG_IGNORED )
{
win = win->winGetParent();
if( win == nullptr )
{
returnCode = WIN_INPUT_NOT_USED; // oops, it wasn't used after all
break;
}
}
}
return returnCode;
}
//-------------------------------------------------------------------------------------------------
/** Process a single mouse event through the window system */
//-------------------------------------------------------------------------------------------------
WinInputReturnCode GameWindowManager::winProcessMouseEvent( GameWindowMessage msg,
ICoord2D *mousePos,
void *data )
{
WinInputReturnCode returnCode = WIN_INPUT_NOT_USED;
Bool objectTooltip = FALSE;
UnsignedInt packedMouseCoords;
GameWindow *window = nullptr;
GameWindow *toolTipWindow = nullptr;
Int dx, dy;
Bool clearGrabWindow = FALSE;
// pack mouse coords into one entity for message passing
packedMouseCoords = SHORTTOLONG( mousePos->x, mousePos->y );
// clear tooltip ... it will be reset if necessary
TheMouse->setCursorTooltip( UnicodeString::TheEmptyString );
// Check for mouse capture
if( m_mouseCaptor )
{
// no window grabbed as of yet
m_grabWindow = nullptr;
// what what window within the captured window are we in
window = m_mouseCaptor->winPointInChild( mousePos->x, mousePos->y );
//
// send buttons, drags, wheels to the windows, we don't continually
// send mouse positions
//
if( sendMousePosMessages == TRUE || msg != GWM_MOUSE_POS )
{
GameWindow *win = window;
if( win )
{
while( win != nullptr )
{
if( winSendInputMsg( win, msg, packedMouseCoords, 0 ) == MSG_HANDLED )
{
// if used clear the event
returnCode = WIN_INPUT_USED;
break;
}
// if we just tested mouseCaptor don't go any higher in the chain
if( win == m_mouseCaptor )
break;
win = win->winGetParent();
}
}
else
{
// if used clear the event
if( winSendInputMsg( m_mouseCaptor, msg, packedMouseCoords, 0 ) == MSG_HANDLED )
returnCode = WIN_INPUT_USED;
}
}
}
else
{
if( m_grabWindow )
{
GameWindow *parent;
switch( msg )
{
// --------------------------------------------------------------------
case GWM_LEFT_UP:
{
//Play a beep sound if the window is disabled.
m_grabWindow->winPointInChild( mousePos->x, mousePos->y, FALSE, TRUE );
BitClear( m_grabWindow->m_status, WIN_STATUS_ACTIVE );
if( m_grabWindow->winPointInWindow( mousePos->x, mousePos->y ) )
winSendInputMsg( m_grabWindow, GWM_LEFT_UP, packedMouseCoords, 0 );
else if( BitIsSet( m_grabWindow->m_status, WIN_STATUS_DRAGGABLE ))
{
winSendInputMsg( m_grabWindow, GWM_LEFT_UP, packedMouseCoords, 0 );
}
clearGrabWindow = TRUE;
break;
}
// --------------------------------------------------------------------
case MOUSE_EVENT_NONE:
case GWM_LEFT_DRAG:
{
if( BitIsSet( m_grabWindow->m_status, WIN_STATUS_DRAGGABLE ) )
{
ICoord2D *mouseDelta = (ICoord2D *)data;
dx = mouseDelta->x;
dy = mouseDelta->y;
// Clip window to parent
if( m_grabWindow->winGetParent() )
{
parent = m_grabWindow->winGetParent();
if( m_grabWindow->m_region.lo.x + dx < 0 )
dx = 0 - m_grabWindow->m_region.lo.x;
else if( m_grabWindow->m_region.hi.x + dx > parent->m_size.x )
dx = parent->m_size.x - m_grabWindow->m_region.hi.x;
if( m_grabWindow->m_region.lo.y + dy < 0 )
dy = 0 - m_grabWindow->m_region.lo.y;
else if( m_grabWindow->m_region.hi.y + dy > parent->m_size.y )
dy = parent->m_size.y - m_grabWindow->m_region.hi.y;
}
// Move the window, but keep it completely visible within screen boundaries
IRegion2D newRegion;
ICoord2D grabSize;
m_grabWindow->winGetPosition( &newRegion.lo.x, &newRegion.lo.y );
m_grabWindow->winGetSize( &grabSize.x, &grabSize.y );
newRegion.lo.x += dx;
newRegion.lo.y += dy;
if( newRegion.lo.x < 0 )
newRegion.lo.x = 0;
if( newRegion.lo.y < 0 )
newRegion.lo.y = 0;
newRegion.hi.x = newRegion.lo.x + grabSize.x;
newRegion.hi.y = newRegion.lo.y + grabSize.y;
if( newRegion.hi.x > (Int)TheDisplay->getWidth() )
newRegion.hi.x = (Int)TheDisplay->getWidth();
if( newRegion.hi.y > (Int)TheDisplay->getHeight() )
newRegion.hi.y = (Int)TheDisplay->getHeight();
newRegion.lo.x = newRegion.hi.x - grabSize.x;
newRegion.lo.y = newRegion.hi.y - grabSize.y;
m_grabWindow->winSetPosition( newRegion.lo.x, newRegion.lo.y );
}
// Send mouse drag message
winSendInputMsg( m_grabWindow, msg, packedMouseCoords, 0 );
break;
}
}
// mark event handled
returnCode = WIN_INPUT_USED;
}
else
{