/
CGUI_Impl.cpp
1702 lines (1437 loc) · 57 KB
/
CGUI_Impl.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
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
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: gui/CGUI_Impl.cpp
* PURPOSE: Graphical User Interface module class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"
#include "CEGUIExceptions.h"
using std::list;
#define CGUI_MTA_DEFAULT_FONT "tahoma.ttf" // %WINDIR%/font/<...>
#define CGUI_MTA_DEFAULT_FONT_BOLD "tahomabd.ttf" // %WINDIR%/font/<...>
#define CGUI_MTA_CLEAR_FONT "verdana.ttf" // %WINDIR%/font/<...>
#define CGUI_MTA_DEFAULT_REG "Tahoma (TrueType)"
#define CGUI_MTA_DEFAULT_REG_BOLD "Tahoma Bold (TrueType)"
#define CGUI_MTA_CLEAR_REG "Verdana (TrueType)"
#define CGUI_MTA_SUBSTITUTE_FONT "cgui/unifont.ttf" // GTA/MTA/<...>
#define CGUI_MTA_SANS_FONT "cgui/sans.ttf" // GTA/MTA/<...>
#define CGUI_SA_HEADER_FONT "cgui/saheader.ttf" // GTA/MTA/<...>
#define CGUI_SA_GOTHIC_FONT "cgui/sagothic.ttf" // GTA/MTA/<...>
#define CGUI_SA_HEADER_SIZE 26
#define CGUI_SA_GOTHIC_SIZE 47
#define CGUI_MTA_SANS_FONT_SIZE 9
CGUI_Impl::CGUI_Impl(IDirect3DDevice9* pDevice) : m_HasSchemeLoaded(false), m_fCurrentServerCursorAlpha(1.0f)
{
m_RenderOkTimer.SetMaxIncrement(100);
// Init
m_pDevice = pDevice;
/*
m_pCharacterKeyHandler = NULL;
m_pKeyDownHandler = NULL;
m_pMouseClickHandler = NULL;
m_pMouseDoubleClickHandler = NULL;
m_pMouseWheelHandler = NULL;
m_pMouseMoveHandler = NULL;
m_pMouseEnterHandler = NULL;
m_pMouseLeaveHandler = NULL;
m_pMovedHandler = NULL;
m_pSizedHandler = NULL;
*/
m_Channel = INPUT_CORE;
// Create a GUI system and get the windowmanager
m_pRenderer = new CEGUI::DirectX9Renderer(pDevice, 0);
m_pSystem = new CEGUI::System(m_pRenderer, CEGUI::String(CalcMTASAPath(PathJoin("MTA", "logs", "CEGUI.log"))).data());
// Get pointers to various stuff from CEGUI singletons
m_pFontManager = CEGUI::FontManager::getSingletonPtr();
m_pImageSetManager = CEGUI::ImagesetManager::getSingletonPtr();
m_pSchemeManager = CEGUI::SchemeManager::getSingletonPtr();
m_pWindowManager = CEGUI::WindowManager::getSingletonPtr();
SetDefaultGuiWorkingDirectory(CalcMTASAPath("MTA"));
// Set logging to Informative for debug and Standard for release
#if defined(_DEBUG) || defined(DEBUG)
CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
#else
CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Standard);
#endif
// Load our fonts
SString strFontsPath = PathJoin(GetSystemWindowsPath(), "fonts");
try
{
m_pUniFont = (CGUIFont_Impl*)CreateFnt("unifont", CGUI_MTA_SUBSTITUTE_FONT, 9, 0, false);
m_pFontManager->setSubstituteFont(m_pUniFont->GetFont());
}
catch (CEGUI::InvalidRequestException e)
{
SString strMessage = e.getMessage().c_str();
BrowseToSolution("create-fonts", EXIT_GAME_FIRST | ASK_GO_ONLINE, SString("Error loading fonts!\n\n%s", *strMessage));
}
// Window fonts first
m_pDefaultFont = (CGUIFont_Impl*)CreateFntFromWinFont("default-normal", CGUI_MTA_DEFAULT_REG, CGUI_MTA_DEFAULT_FONT, 9, 0);
m_pSmallFont = (CGUIFont_Impl*)CreateFntFromWinFont("default-small", CGUI_MTA_DEFAULT_REG, CGUI_MTA_DEFAULT_FONT, 7, 0);
m_pBoldFont = (CGUIFont_Impl*)CreateFntFromWinFont("default-bold-small", CGUI_MTA_DEFAULT_REG_BOLD, CGUI_MTA_DEFAULT_FONT_BOLD, 8, 0);
m_pClearFont = (CGUIFont_Impl*)CreateFntFromWinFont("clear-normal", CGUI_MTA_CLEAR_REG, CGUI_MTA_CLEAR_FONT, 9);
try
{
m_pSAHeaderFont = (CGUIFont_Impl*)CreateFnt("sa-header", CGUI_SA_HEADER_FONT, CGUI_SA_HEADER_SIZE, 0, true);
m_pSAGothicFont = (CGUIFont_Impl*)CreateFnt("sa-gothic", CGUI_SA_GOTHIC_FONT, CGUI_SA_GOTHIC_SIZE, 0, true);
m_pSansFont = (CGUIFont_Impl*)CreateFnt("sans", CGUI_MTA_SANS_FONT, CGUI_MTA_SANS_FONT_SIZE, 0, false);
}
catch (CEGUI::InvalidRequestException e)
{
SString strMessage = e.getMessage().c_str();
BrowseToSolution("create-fonts", EXIT_GAME_FIRST | ASK_GO_ONLINE, SString("Error loading fonts!\n\n%s", *strMessage));
}
}
CGUI_Impl::~CGUI_Impl()
{
delete CEGUI::System::getSingletonPtr();
}
void CGUI_Impl::SetSkin(const char* szName)
{
if (m_HasSchemeLoaded)
{
CEGUI::GlobalEventSet::getSingletonPtr()->removeAllEvents();
CEGUI::SchemeManager::getSingleton().unloadScheme(m_CurrentSchemeName);
}
PushGuiWorkingDirectory(CalcMTASAPath(PathJoin("skins", szName)));
CEGUI::Scheme* scheme = CEGUI::SchemeManager::getSingleton().loadScheme("CGUI.xml");
m_CurrentSchemeName = scheme->getName().c_str();
m_HasSchemeLoaded = true;
PopGuiWorkingDirectory();
CEGUI::System::getSingleton().setDefaultMouseCursor("CGUI-Images", "MouseArrow");
// Destroy any windows we already have
CEGUI::WindowManager::getSingleton().destroyAllWindows();
// Create dummy GUI root
m_pTop = reinterpret_cast<CEGUI::DefaultWindow*>(m_pWindowManager->createWindow("DefaultWindow", "guiroot"));
m_pSystem->setGUISheet(m_pTop);
// Disable single click timeouts
m_pSystem->setSingleClickTimeout(100000000.0f);
// Set our default font
m_pSystem->setDefaultFont(m_pDefaultFont->GetFont());
// Grab our default cursor
m_pCursor = m_pSystem->getDefaultMouseCursor();
// Used to create unique names for widget instances
m_ulPreviousUnique = 0;
SubscribeToMouseEvents();
// Disallow input routing to the GUI unless edit box has focus
m_eInputMode = INPUTMODE_NO_BINDS_ON_EDIT;
}
void CGUI_Impl::SetBidiEnabled(bool bEnabled)
{
m_pSystem->SetBidiEnabled(bEnabled);
}
void CGUI_Impl::SubscribeToMouseEvents()
{
// Mouse events
CEGUI::GlobalEventSet* pEvents = CEGUI::GlobalEventSet::getSingletonPtr();
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventCharacterKey, CEGUI::Event::Subscriber(&CGUI_Impl::Event_CharacterKey, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventKeyDown, CEGUI::Event::Subscriber(&CGUI_Impl::Event_KeyDown, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventMouseClick, CEGUI::Event::Subscriber(&CGUI_Impl::Event_MouseClick, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventMouseDoubleClick, CEGUI::Event::Subscriber(&CGUI_Impl::Event_MouseDoubleClick, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventMouseButtonDown, CEGUI::Event::Subscriber(&CGUI_Impl::Event_MouseButtonDown, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventMouseButtonUp, CEGUI::Event::Subscriber(&CGUI_Impl::Event_MouseButtonUp, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventMouseWheel, CEGUI::Event::Subscriber(&CGUI_Impl::Event_MouseWheel, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventMouseMove, CEGUI::Event::Subscriber(&CGUI_Impl::Event_MouseMove, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventMouseEnters, CEGUI::Event::Subscriber(&CGUI_Impl::Event_MouseEnter, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventMouseLeaves, CEGUI::Event::Subscriber(&CGUI_Impl::Event_MouseLeave, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventMoved, CEGUI::Event::Subscriber(&CGUI_Impl::Event_Moved, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventSized, CEGUI::Event::Subscriber(&CGUI_Impl::Event_Sized, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventRedrawRequested, CEGUI::Event::Subscriber(&CGUI_Impl::Event_RedrawRequested, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventActivated, CEGUI::Event::Subscriber(&CGUI_Impl::Event_FocusGained, this));
pEvents->subscribeEvent("Window/" + CEGUI::Window::EventDeactivated, CEGUI::Event::Subscriber(&CGUI_Impl::Event_FocusLost, this));
}
CVector2D CGUI_Impl::GetResolution()
{
return CVector2D(m_pRenderer->getWidth(), m_pRenderer->getHeight());
}
void CGUI_Impl::SetResolution(float fWidth, float fHeight)
{
reinterpret_cast<CEGUI::DirectX9Renderer*>(m_pRenderer)->setDisplaySize(CEGUI::Size(fWidth, fHeight));
}
void CGUI_Impl::Draw()
{
// Redraw the changed elements
if (!m_RedrawQueue.empty())
{
list<CGUIElement*>::const_iterator iter = m_RedrawQueue.begin();
for (; iter != m_RedrawQueue.end(); iter++)
{
(*iter)->ForceRedraw();
}
m_RedrawQueue.clear();
}
if (!m_pSystem->renderGUI())
{
if (m_RenderOkTimer.Get() > 4000)
{
// 4 seconds and over 40 failed calls means we have a problem
BrowseToSolution("gui-render", EXIT_GAME_FIRST, "Some sort of DirectX problem has occurred");
}
}
else
m_RenderOkTimer.Reset();
}
void CGUI_Impl::Invalidate()
{
reinterpret_cast<CEGUI::DirectX9Renderer*>(m_pRenderer)->preD3DReset();
}
void CGUI_Impl::Restore()
{
try
{
reinterpret_cast<CEGUI::DirectX9Renderer*>(m_pRenderer)->postD3DReset();
}
catch (CEGUI::RendererException& exception)
{
MessageBox(0, exception.getMessage().c_str(), "CEGUI Exception", MB_OK | MB_ICONERROR | MB_TOPMOST);
TerminateProcess(GetCurrentProcess(), 1);
}
}
void CGUI_Impl::DrawMouseCursor()
{
CEGUI::MouseCursor::getSingleton().draw();
}
void CGUI_Impl::ProcessMouseInput(CGUIMouseInput eMouseInput, unsigned long ulX, unsigned long ulY, CGUIMouseButton eMouseButton)
{
switch (eMouseInput)
{
case CGUI_MI_MOUSEMOVE:
m_pSystem->injectMouseMove(static_cast<float>(ulX), static_cast<float>(ulY));
break;
case CGUI_MI_MOUSEPOS:
m_pSystem->injectMousePosition(static_cast<float>(ulX), static_cast<float>(ulY));
break;
case CGUI_MI_MOUSEDOWN:
m_pSystem->injectMouseButtonDown(static_cast<CEGUI::MouseButton>(eMouseButton));
break;
case CGUI_MI_MOUSEUP:
m_pSystem->injectMouseButtonUp(static_cast<CEGUI::MouseButton>(eMouseButton));
break;
case CGUI_MI_MOUSEWHEEL:
if ((signed long)ulX > 0)
m_pSystem->injectMouseWheelChange(+1);
else
m_pSystem->injectMouseWheelChange(-1);
break;
}
}
void CGUI_Impl::ProcessKeyboardInput(unsigned long ulKey, bool bIsDown)
{
if (bIsDown)
{
m_pSystem->injectKeyDown(ulKey);
}
else
{
m_pSystem->injectKeyUp(ulKey);
}
}
bool CGUI_Impl::GetGUIInputEnabled()
{
switch (m_eInputMode)
{
case INPUTMODE_ALLOW_BINDS:
return false;
break;
case INPUTMODE_NO_BINDS:
return true;
break;
case INPUTMODE_NO_BINDS_ON_EDIT:
{
CEGUI::Window* pActiveWindow = m_pTop->getActiveChild();
if (!pActiveWindow || pActiveWindow == m_pTop || !pActiveWindow->isVisible())
{
return false;
}
if (pActiveWindow->getType() == "CGUI/Editbox")
{
CEGUI::Editbox* pEditBox = reinterpret_cast<CEGUI::Editbox*>(pActiveWindow);
return (!pEditBox->isReadOnly() && pEditBox->hasInputFocus());
}
else if (pActiveWindow->getType() == "CGUI/MultiLineEditbox")
{
CEGUI::MultiLineEditbox* pMultiLineEditBox = reinterpret_cast<CEGUI::MultiLineEditbox*>(pActiveWindow);
return (!pMultiLineEditBox->isReadOnly() && pMultiLineEditBox->hasInputFocus());
}
else if (pActiveWindow->getType() == CGUIWEBBROWSER_NAME)
{
auto pElement = reinterpret_cast<CGUIElement_Impl*>(pActiveWindow->getUserData());
if (pElement->GetType() == CGUI_WEBBROWSER)
{
auto pWebBrowser = reinterpret_cast<CGUIWebBrowser_Impl*>(pElement);
return pWebBrowser->HasInputFocus();
}
}
return false;
}
break;
default:
return false;
}
}
void CGUI_Impl::SetGUIInputMode(eInputMode a_eMode)
{
m_eInputMode = a_eMode;
}
eInputMode CGUI_Impl::GetGUIInputMode()
{
return m_eInputMode;
}
CEGUI::String CGUI_Impl::GetUTFString(const char* szInput)
{
CEGUI::String strUTF = (CEGUI::utf8*)szInput; // Convert into a CEGUI String
return strUTF;
}
CEGUI::String CGUI_Impl::GetUTFString(const std::string& strInput)
{
CEGUI::String strUTF = (CEGUI::utf8*)strInput.c_str(); // Convert into a CEGUI String
return strUTF;
}
void CGUI_Impl::ProcessCharacter(unsigned long ulCharacter)
{
m_pSystem->injectChar(ulCharacter);
}
CGUIMessageBox* CGUI_Impl::CreateMessageBox(const char* szTitle, const char* szMessage, unsigned int uiFlags)
{
return new CGUIMessageBox_Impl(this, szTitle, szMessage, uiFlags);
}
CGUIButton* CGUI_Impl::_CreateButton(CGUIElement_Impl* pParent, const char* szCaption)
{
return new CGUIButton_Impl(this, pParent, szCaption);
}
CGUICheckBox* CGUI_Impl::_CreateCheckBox(CGUIElement_Impl* pParent, const char* szCaption, bool bChecked)
{
return new CGUICheckBox_Impl(this, pParent, szCaption, bChecked);
}
CGUIRadioButton* CGUI_Impl::_CreateRadioButton(CGUIElement_Impl* pParent, const char* szCaption)
{
return new CGUIRadioButton_Impl(this, pParent, szCaption);
}
CGUIEdit* CGUI_Impl::_CreateEdit(CGUIElement_Impl* pParent, const char* szText)
{
return new CGUIEdit_Impl(this, pParent, szText);
}
CGUIFont* CGUI_Impl::CreateFnt(const char* szFontName, const char* szFontFile, unsigned int uSize, unsigned int uFlags, bool bAutoScale)
{
return new CGUIFont_Impl(this, szFontName, szFontFile, uSize, uFlags, bAutoScale);
}
CGUIFont* CGUI_Impl::CreateFntFromWinFont(const char* szFontName, const char* szFontWinReg, const char* szFontWinFile, unsigned int uSize, unsigned int uFlags,
bool bAutoScale)
{
SString strFontWinRegName = GetSystemRegistryValue((uint)HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", szFontWinReg);
SString strWinFontsPath = PathJoin(GetSystemWindowsPath(), "fonts");
// Compile a list of places to look
std::vector<SString> lookList;
if (strFontWinRegName.Contains(":") || strFontWinRegName.BeginsWith("\\") || strFontWinRegName.BeginsWith("/"))
lookList.push_back(strFontWinRegName);
lookList.push_back(PathJoin(strWinFontsPath, strFontWinRegName));
lookList.push_back(PathJoin("cgui", szFontWinFile));
lookList.push_back(PathJoin(strWinFontsPath, szFontWinFile));
// Try each place
CGUIFont* pResult = NULL;
for (uint i = 0; i < lookList.size(); i++)
{
if (FileExists(lookList[i]))
{
try
{
pResult = (CGUIFont_Impl*)CreateFnt(szFontName, lookList[i], uSize, uFlags, bAutoScale);
}
catch (CEGUI::Exception e)
{
}
}
if (pResult)
break;
}
if (!pResult)
{
BrowseToSolution("create-fonts", EXIT_GAME_FIRST | ASK_GO_ONLINE, SString("Error loading font!\n\n(%s)", szFontWinFile));
}
return pResult;
}
CGUIGridList* CGUI_Impl::_CreateGridList(CGUIElement_Impl* pParent, bool bFrame)
{
return new CGUIGridList_Impl(this, pParent, bFrame);
}
CGUILabel* CGUI_Impl::_CreateLabel(CGUIElement_Impl* pParent, const char* szCaption)
{
return new CGUILabel_Impl(this, pParent, szCaption);
}
CGUIProgressBar* CGUI_Impl::_CreateProgressBar(CGUIElement_Impl* pParent)
{
return new CGUIProgressBar_Impl(this, pParent);
}
CGUIMemo* CGUI_Impl::_CreateMemo(CGUIElement_Impl* pParent, const char* szText)
{
return new CGUIMemo_Impl(this, pParent, szText);
}
CGUIStaticImage* CGUI_Impl::_CreateStaticImage(CGUIElement_Impl* pParent)
{
return new CGUIStaticImage_Impl(this, pParent);
}
CGUITabPanel* CGUI_Impl::_CreateTabPanel(CGUIElement_Impl* pParent)
{
return new CGUITabPanel_Impl(this, pParent);
}
CGUIScrollPane* CGUI_Impl::_CreateScrollPane(CGUIElement_Impl* pParent)
{
return new CGUIScrollPane_Impl(this, pParent);
}
CGUIScrollBar* CGUI_Impl::_CreateScrollBar(bool bHorizontal, CGUIElement_Impl* pParent)
{
return new CGUIScrollBar_Impl(this, bHorizontal, pParent);
}
CGUIComboBox* CGUI_Impl::_CreateComboBox(CGUIElement_Impl* pParent, const char* szCaption)
{
return new CGUIComboBox_Impl(this, pParent, szCaption);
}
CGUIWebBrowser* CGUI_Impl::_CreateWebBrowser(CGUIElement_Impl* pParent)
{
return new CGUIWebBrowser_Impl(this, pParent);
}
CGUITexture* CGUI_Impl::CreateTexture()
{
return new CGUITexture_Impl(this);
}
CGUIWindow* CGUI_Impl::CreateWnd(CGUIElement* pParent, const char* szCaption)
{
return new CGUIWindow_Impl(this, pParent, szCaption);
}
void CGUI_Impl::SetCursorEnabled(bool bEnabled)
{
if (bEnabled)
{
CEGUI::MouseCursor::getSingleton().show();
}
else
{
CEGUI::MouseCursor::getSingleton().hide();
}
}
bool CGUI_Impl::IsCursorEnabled()
{
return CEGUI::MouseCursor::getSingleton().isVisible();
}
void CGUI_Impl::SetCursorAlpha(float fAlpha, bool bOnlyCurrentServer)
{
CEGUI::MouseCursor::getSingleton().setAlpha(fAlpha);
if (bOnlyCurrentServer)
SetCurrentServerCursorAlpha(fAlpha);
}
void CGUI_Impl::SetCurrentServerCursorAlpha(float fAlpha)
{
m_fCurrentServerCursorAlpha = fAlpha;
}
float CGUI_Impl::GetCurrentServerCursorAlpha()
{
return m_fCurrentServerCursorAlpha;
}
eCursorType CGUI_Impl::GetCursorType()
{
auto image = CEGUI::MouseCursor::getSingleton().getImage();
if (image == nullptr)
return CURSORTYPE_NONE;
auto imageName = image->getName();
if (!imageName.compare("MouseArrow"))
return CURSORTYPE_DEFAULT;
else if (!imageName.compare("NSSizingCursorImage"))
return CURSORTYPE_SIZING_NS;
else if (!imageName.compare("EWSizingCursorImage"))
return CURSORTYPE_SIZING_EW;
else if (!imageName.compare("NWSESizingCursorImage"))
return CURSORTYPE_SIZING_NWSE;
else if (!imageName.compare("NESWSizingCursorImage"))
return CURSORTYPE_SIZING_NESW;
else if (!imageName.compare("MouseEsWeCursor"))
return CURSORTYPE_SIZING_ESWE;
else if (!imageName.compare("MouseMoveCursor"))
return CURSORTYPE_MOVE;
else
return CURSORTYPE_DEFAULT;
}
void CGUI_Impl::AddChild(CGUIElement_Impl* pChild)
{
m_pTop->addChildWindow(pChild->GetWindow());
}
CGUIWindow* CGUI_Impl::LoadLayout(CGUIElement* pParent, const SString& strFilename)
{
try
{
return new CGUIWindow_Impl(this, pParent, "szCaption", strFilename);
}
catch (...)
{
return NULL;
}
}
bool CGUI_Impl::LoadImageset(const SString& strFilename)
{
try
{
return GetImageSetManager()->createImageset(strFilename, "", true) != NULL;
}
catch (CEGUI::AlreadyExistsException exc)
{
return true;
}
catch (...)
{
return false;
}
}
CEGUI::FontManager* CGUI_Impl::GetFontManager()
{
return m_pFontManager;
}
CEGUI::ImagesetManager* CGUI_Impl::GetImageSetManager()
{
return m_pImageSetManager;
}
CEGUI::System* CGUI_Impl::GetGUISystem()
{
return m_pSystem;
}
CEGUI::Renderer* CGUI_Impl::GetRenderer()
{
return m_pRenderer;
}
CEGUI::SchemeManager* CGUI_Impl::GetSchemeManager()
{
return m_pSchemeManager;
}
CEGUI::WindowManager* CGUI_Impl::GetWindowManager()
{
return m_pWindowManager;
}
void CGUI_Impl::GetUniqueName(char* pBuf)
{
snprintf(pBuf, CGUI_CHAR_SIZE, "%x", m_ulPreviousUnique);
m_ulPreviousUnique++;
}
bool CGUI_Impl::Event_CharacterKey(const CEGUI::EventArgs& Args)
{
if (m_CharacterKeyHandlers[m_Channel])
{
const CEGUI::KeyEventArgs& e = reinterpret_cast<const CEGUI::KeyEventArgs&>(Args);
CGUIKeyEventArgs NewArgs;
// copy the variables
NewArgs.codepoint = e.codepoint;
NewArgs.scancode = (CGUIKeys::Scan)e.scancode;
NewArgs.sysKeys = e.sysKeys;
// get the CGUIElement
CGUIElement* pElement = reinterpret_cast<CGUIElement*>((e.window)->getUserData());
NewArgs.pWindow = pElement;
m_CharacterKeyHandlers[m_Channel](NewArgs);
}
return true;
}
CGUIFont* CGUI_Impl::GetDefaultFont()
{
return m_pDefaultFont;
}
CGUIFont* CGUI_Impl::GetSmallFont()
{
return m_pSmallFont;
}
CGUIFont* CGUI_Impl::GetBoldFont()
{
return m_pBoldFont;
}
CGUIFont* CGUI_Impl::GetClearFont()
{
return m_pClearFont;
}
CGUIFont* CGUI_Impl::GetSAHeaderFont()
{
return m_pSAHeaderFont;
}
CGUIFont* CGUI_Impl::GetSAGothicFont()
{
return m_pSAGothicFont;
}
CGUIFont* CGUI_Impl::GetSansFont()
{
return m_pSansFont;
}
float CGUI_Impl::GetTextExtent(const char* szText, const char* szFont)
{
return m_pFontManager->getFont(szFont)->getTextExtent(CGUI_Impl::GetUTFString(szText));
}
float CGUI_Impl::GetMaxTextExtent(SString strFont, SString arg, ...)
{
float fMaxTextExtent = NULL;
va_list arguments;
for (va_start(arguments, arg); arg != ""; arg = va_arg(arguments, SString))
{
float fExtent = m_pFontManager->getFont(strFont)->getTextExtent(CGUI_Impl::GetUTFString(arg));
if (fExtent > fMaxTextExtent)
fMaxTextExtent = fExtent;
}
va_end(arguments);
return fMaxTextExtent;
}
bool CGUI_Impl::Event_KeyDown(const CEGUI::EventArgs& Args)
{
// Cast it to a set of keyboard arguments
const CEGUI::KeyEventArgs& KeyboardArgs = reinterpret_cast<const CEGUI::KeyEventArgs&>(Args);
// Call the callback if present
if (m_KeyDownHandlers[m_Channel])
{
const CEGUI::KeyEventArgs& e = reinterpret_cast<const CEGUI::KeyEventArgs&>(Args);
CGUIKeyEventArgs NewArgs;
// copy the variables
NewArgs.codepoint = e.codepoint;
NewArgs.scancode = (CGUIKeys::Scan)e.scancode;
NewArgs.sysKeys = e.sysKeys;
// get the CGUIElement
CGUIElement* pElement = reinterpret_cast<CGUIElement*>((e.window)->getUserData());
NewArgs.pWindow = pElement;
m_KeyDownHandlers[m_Channel](NewArgs);
}
switch (KeyboardArgs.scancode)
{
// Cut/Copy keys
case CEGUI::Key::X:
case CEGUI::Key::C:
{
if (KeyboardArgs.sysKeys & CEGUI::Control)
{
// Data to copy
CEGUI::String strTemp;
// Edit boxes
CEGUI::Window* Wnd = reinterpret_cast<CEGUI::Window*>(KeyboardArgs.window);
if (Wnd->getType() == "CGUI/Editbox")
{
// Turn our event window into an editbox
CEGUI::Editbox* WndEdit = reinterpret_cast<CEGUI::Editbox*>(Wnd);
// Don't allow cutting/copying if the editbox is masked
if (!WndEdit->isTextMasked())
{
// Get the text from the editbox
size_t sizeSelectionStart = WndEdit->getSelectionStartIndex();
size_t sizeSelectionLength = WndEdit->getSelectionLength();
strTemp = WndEdit->getText().substr(sizeSelectionStart, sizeSelectionLength);
// If the user cut, remove the text too
if (KeyboardArgs.scancode == CEGUI::Key::X)
{
// Read only?
if (!WndEdit->isReadOnly())
{
// Remove the text from the source
CEGUI::String strTemp2 = WndEdit->getText();
strTemp2.replace(sizeSelectionStart, sizeSelectionLength, "", 0);
WndEdit->setText(strTemp2);
}
}
}
}
// Multiline editboxes
if (Wnd->getType() == "CGUI/MultiLineEditbox")
{
// Turn our event window into an editbox
CEGUI::MultiLineEditbox* WndEdit = reinterpret_cast<CEGUI::MultiLineEditbox*>(Wnd);
// Get the text from the editbox
size_t sizeSelectionStart = WndEdit->getSelectionStartIndex();
size_t sizeSelectionLength = WndEdit->getSelectionLength();
strTemp = WndEdit->getText().substr(sizeSelectionStart, sizeSelectionLength);
// If the user cut, remove the text too
if (KeyboardArgs.scancode == CEGUI::Key::X)
{
// Read only?
if (!WndEdit->isReadOnly())
{
// Remove the text from the source
CEGUI::String strTemp2 = WndEdit->getText();
strTemp2.replace(sizeSelectionStart, sizeSelectionLength, "", 0);
WndEdit->setText(strTemp2);
}
}
}
// If we got something to copy
if (strTemp.length() > 0)
{
// Convert it to Unicode
std::wstring strUTF = MbUTF8ToUTF16(strTemp.c_str());
// Open and empty the clipboard
OpenClipboard(NULL);
EmptyClipboard();
// Allocate the clipboard buffer and copy the data
HGLOBAL hBuf = GlobalAlloc(GMEM_DDESHARE, strUTF.length() * sizeof(wchar_t) + sizeof(wchar_t));
wchar_t* buf = reinterpret_cast<wchar_t*>(GlobalLock(hBuf));
wcscpy(buf, strUTF.c_str());
GlobalUnlock(hBuf);
// Copy the data into the clipboard
SetClipboardData(CF_UNICODETEXT, hBuf);
// Close the clipboard
CloseClipboard();
}
}
break;
}
// Paste keys
case CEGUI::Key::V:
{
if (KeyboardArgs.sysKeys & CEGUI::Control)
{
CEGUI::Window* Wnd = reinterpret_cast<CEGUI::Window*>(KeyboardArgs.window);
if (Wnd->getType() == "CGUI/Editbox" || Wnd->getType() == "CGUI/MultiLineEditbox")
{
// Open the clipboard
OpenClipboard(NULL);
// Get the clipboard's data and put it into a char array
const wchar_t* ClipboardBuffer = reinterpret_cast<const wchar_t*>(GetClipboardData(CF_UNICODETEXT));
// Check to make sure we have valid data.
if (ClipboardBuffer)
{
size_t iSelectionStart, iSelectionLength, iMaxLength, iCaratIndex;
CEGUI::String strEditText;
bool bReplaceNewLines = true;
bool bIsBoxFull = false;
if (Wnd->getType() == "CGUI/Editbox")
{
// Turn our event window into an editbox
CEGUI::Editbox* WndEdit = reinterpret_cast<CEGUI::Editbox*>(Wnd);
// Don't paste if we're read only
if (WndEdit->isReadOnly())
{
CloseClipboard();
return true;
}
strEditText = WndEdit->getText();
iSelectionStart = WndEdit->getSelectionStartIndex();
iSelectionLength = WndEdit->getSelectionLength();
iMaxLength = WndEdit->getMaxTextLength();
iCaratIndex = WndEdit->getCaratIndex();
}
else
{
CEGUI::MultiLineEditbox* WndEdit = reinterpret_cast<CEGUI::MultiLineEditbox*>(Wnd);
// Don't paste if we're read only
if (WndEdit->isReadOnly())
{
CloseClipboard();
return true;
}
strEditText = WndEdit->getText();
iSelectionStart = WndEdit->getSelectionStartIndex();
iSelectionLength = WndEdit->getSelectionLength();
iMaxLength = WndEdit->getMaxTextLength();
iCaratIndex = WndEdit->getCaratIndex();
bReplaceNewLines = false;
// Plus one character, because there is always an extra '\n' in
// MultiLineEditbox's text data and it causes MaxLength limit to
// be exceeded during pasting the text
iMaxLength += 1;
}
std::wstring strClipboardText = ClipboardBuffer;
size_t iNewlineIndex;
// Remove the newlines inserting spaces instead
if (bReplaceNewLines)
{
do
{
iNewlineIndex = strClipboardText.find('\n');
if (iNewlineIndex != SString::npos)
{
if (iNewlineIndex > 0 && strClipboardText[iNewlineIndex - 1] == '\r')
{
// \r\n
strClipboardText[iNewlineIndex - 1] = ' ';
strClipboardText.replace(iNewlineIndex, strClipboardText.length() - iNewlineIndex, strClipboardText.c_str(),
iNewlineIndex + 1, strClipboardText.length() - iNewlineIndex - 1);
}
else
{
strClipboardText[iNewlineIndex] = ' ';
}
}
} while (iNewlineIndex != SString::npos);
}
// Put the editbox's data into a string and insert the data if it has not reached it's maximum text length
std::wstring tmp = MbUTF8ToUTF16(strEditText.c_str());
if ((strClipboardText.length() + tmp.length() - iSelectionLength) <= iMaxLength)
{
// Are there characters selected?
size_t sizeCaratIndex = 0;
if (iSelectionLength > 0)
{
// Replace what's selected with the pasted buffer and set the new carat index
tmp.replace(iSelectionStart, iSelectionLength, strClipboardText.c_str(), strClipboardText.length());
sizeCaratIndex = iSelectionStart + strClipboardText.length();
}
else
{
// If not, insert the clipboard buffer where we were and set the new carat index
tmp.insert(iSelectionStart, strClipboardText.c_str(), strClipboardText.length());
sizeCaratIndex = iCaratIndex + strClipboardText.length();
}
// Set the new text and move the carat at the end of what we pasted
CEGUI::String strText((CEGUI::utf8*)UTF16ToMbUTF8(tmp).c_str());
strEditText = strText;
iCaratIndex = sizeCaratIndex;
}
else
{
bIsBoxFull = true;
}
if (bIsBoxFull)
{
// Fire an event if the editbox is full
if (Wnd->getType() == "CGUI/Editbox")
{
CEGUI::Editbox* WndEdit = reinterpret_cast<CEGUI::Editbox*>(Wnd);
CEGUI::WindowEventArgs args(WndEdit);
WndEdit->fireEvent(CEGUI::Editbox::EventEditboxFull, args);
}
else
{
CEGUI::MultiLineEditbox* WndEdit = reinterpret_cast<CEGUI::MultiLineEditbox*>(Wnd);
CEGUI::WindowEventArgs args(WndEdit);
WndEdit->fireEvent(CEGUI::Editbox::EventEditboxFull, args);
}
}
else
{
if (Wnd->getType() == "CGUI/Editbox")
{
CEGUI::Editbox* WndEdit = reinterpret_cast<CEGUI::Editbox*>(Wnd);
WndEdit->setText(strEditText);
WndEdit->setCaratIndex(iCaratIndex);
}
else
{
CEGUI::MultiLineEditbox* WndEdit = reinterpret_cast<CEGUI::MultiLineEditbox*>(Wnd);
WndEdit->setText(strEditText);
WndEdit->setCaratIndex(iCaratIndex);
}
}
}
// Close the clipboard
CloseClipboard();
}
}
break;
}
// Select all key
case CEGUI::Key::A:
{
if (KeyboardArgs.sysKeys & CEGUI::Control)
{
// Edit boxes
CEGUI::Window* Wnd = reinterpret_cast<CEGUI::Window*>(KeyboardArgs.window);
if (Wnd->getType() == "CGUI/Editbox")
{
// Turn our event window into an editbox
CEGUI::Editbox* WndEdit = reinterpret_cast<CEGUI::Editbox*>(Wnd);
WndEdit->setSelection(0, WndEdit->getText().size());
}
else if (Wnd->getType() == "CGUI/MultiLineEditbox")
{
// Turn our event window into a multiline editbox
CEGUI::MultiLineEditbox* WndEdit = reinterpret_cast<CEGUI::MultiLineEditbox*>(Wnd);
WndEdit->setSelection(0, WndEdit->getText().size());
}
}
break;
}
}
return true;
}
void CGUI_Impl::SetDefaultGuiWorkingDirectory(const SString& strDir)
{
assert(m_GuiWorkingDirectoryStack.empty());
m_GuiWorkingDirectoryStack.push_back(PathConform(strDir + "\\"));
ApplyGuiWorkingDirectory();
}
void CGUI_Impl::PushGuiWorkingDirectory(const SString& strDir)
{
m_GuiWorkingDirectoryStack.push_back(PathConform(strDir + "\\"));
ApplyGuiWorkingDirectory();
}
void CGUI_Impl::PopGuiWorkingDirectory(const SString& strDirCheck)
{