1
- #include " GUIEditorApp .h"
2
- #include " GUIEditorUtil .h"
1
+ #include " EditorApp .h"
2
+ #include " EditorUtil .h"
3
3
#include " GUIButton.h"
4
4
#include " GUICheckbox.h"
5
5
#include " GUILabel.h"
6
6
#include " GUITextBox.h"
7
- #include " allegro.h"
8
7
#include " winalleg.h"
9
8
10
9
namespace RTEGUI {
11
10
12
11
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
13
12
14
- bool GUIEditorApp ::Initialize () {
13
+ bool EditorApp ::Initialize () {
15
14
set_color_depth (32 );
16
15
set_color_conversion (COLORCONV_MOST);
17
16
set_window_title (" Cortex Command GUI Editor" );
@@ -25,6 +24,9 @@ namespace RTEGUI {
25
24
m_BackBuffer = create_bitmap (GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN));
26
25
clear_to_color (m_BackBuffer, 0 );
27
26
27
+ m_ZoomBuffer = create_bitmap (m_WorkspaceWidth * 2 , m_WorkspaceHeight * 2 );
28
+ clear_to_color (m_ZoomBuffer, 0 );
29
+
28
30
m_Screen = std::make_unique<AllegroScreen>(m_BackBuffer);
29
31
m_Input = std::make_unique<AllegroInput>(-1 );
30
32
@@ -43,7 +45,7 @@ namespace RTEGUI {
43
45
44
46
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45
47
46
- void GUIEditorApp ::CreateEditorLayout () {
48
+ void EditorApp ::CreateEditorLayout () {
47
49
m_EditorBase.reset (dynamic_cast <GUICollectionBox *>(m_EditorManager->AddControl (" EditorBase" , " COLLECTIONBOX" , nullptr , 0 , 0 , m_ResX, m_ResY)));
48
50
m_EditorBase->SetDrawBackground (true );
49
51
m_EditorBase->SetDrawColor (makecol (32 , 32 , 32 ));
@@ -142,7 +144,14 @@ namespace RTEGUI {
142
144
143
145
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
144
146
145
- void GUIEditorApp::SelectActiveControlInList () const {
147
+ void EditorApp::DestroyBackBuffers () {
148
+ destroy_bitmap (m_BackBuffer);
149
+ destroy_bitmap (m_ZoomBuffer);
150
+ }
151
+
152
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
153
+
154
+ void EditorApp::SelectActiveControlInList () const {
146
155
if (m_SelectionInfo.Control == nullptr ) {
147
156
m_CollectionBoxList->SetSelectedIndex (-1 );
148
157
return ;
@@ -160,7 +169,7 @@ namespace RTEGUI {
160
169
161
170
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
162
171
163
- void GUIEditorApp ::AddItemToCollectionBoxList (GUIControl *control, const std::string &indent) const {
172
+ void EditorApp ::AddItemToCollectionBoxList (GUIControl *control, const std::string &indent) const {
164
173
m_CollectionBoxList->AddItem (indent + control->GetName ());
165
174
for (GUIControl *childControl : *control->GetChildren ()) {
166
175
if ((control = dynamic_cast <GUICollectionBox *>(childControl))) {
@@ -171,7 +180,7 @@ namespace RTEGUI {
171
180
172
181
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
173
182
174
- void GUIEditorApp ::PopulateCollectionBoxList () const {
183
+ void EditorApp ::PopulateCollectionBoxList () const {
175
184
m_CollectionBoxList->ClearList ();
176
185
GUICollectionBox *collectionBox = nullptr ;
177
186
@@ -192,7 +201,7 @@ namespace RTEGUI {
192
201
193
202
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
194
203
195
- void GUIEditorApp ::PopulateCollectionBoxChildrenList (GUICollectionBox *collectionBox) const {
204
+ void EditorApp ::PopulateCollectionBoxChildrenList (GUICollectionBox *collectionBox) const {
196
205
m_ControlsInActiveCollectionBoxList->ClearList ();
197
206
198
207
std::vector<GUIControl *> controls = *collectionBox->GetChildren ();
@@ -210,7 +219,7 @@ namespace RTEGUI {
210
219
211
220
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
212
221
213
- GUIControl * GUIEditorApp ::ControlUnderMouse (GUIControl *parent, int mousePosX, int mousePosY) {
222
+ GUIControl * EditorApp ::ControlUnderMouse (GUIControl *parent, int mousePosX, int mousePosY) {
214
223
assert (parent);
215
224
216
225
// Clicked on the parent?
@@ -246,7 +255,7 @@ namespace RTEGUI {
246
255
247
256
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
248
257
249
- int GUIEditorApp ::HandleUnderMouse (GUIControl *control, int mousePosX, int mousePosY) const {
258
+ int EditorApp ::HandleUnderMouse (GUIControl *control, int mousePosX, int mousePosY) const {
250
259
int xPos;
251
260
int yPos;
252
261
int width;
@@ -279,13 +288,13 @@ namespace RTEGUI {
279
288
280
289
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
281
290
282
- bool GUIEditorApp ::MouseInsideBox (int mousePosX, int mousePosY, int xPos, int yPos, int width, int height) const {
291
+ bool EditorApp ::MouseInsideBox (int mousePosX, int mousePosY, int xPos, int yPos, int width, int height) const {
283
292
return (mousePosX >= xPos && mousePosX <= xPos + width && mousePosY >= yPos && mousePosY <= yPos + height) ? true : false ;
284
293
}
285
294
286
295
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
287
296
288
- void GUIEditorApp ::CalculateHandleResize (int mousePosX, int mousePosY, int *xPos, int *yPos, int *width, int *height) {
297
+ void EditorApp ::CalculateHandleResize (int mousePosX, int mousePosY, int *xPos, int *yPos, int *width, int *height) {
289
298
int controlPosX;
290
299
int controlPosY;
291
300
int controlWidth;
@@ -353,7 +362,7 @@ namespace RTEGUI {
353
362
354
363
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
355
364
356
- int GUIEditorApp ::ProcessSnapCoord (int position) const {
365
+ int EditorApp ::ProcessSnapCoord (int position) const {
357
366
if (m_SnapToGrid) {
358
367
float unsnappedPosition = std::round (static_cast <float >(position) / static_cast <float >(m_GridSize));
359
368
position = static_cast <int >(unsnappedPosition) * m_GridSize;
@@ -363,7 +372,7 @@ namespace RTEGUI {
363
372
364
373
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
365
374
366
- void GUIEditorApp ::AddNewControl (GUIEvent &editorEvent) {
375
+ void EditorApp ::AddNewControl (GUIEvent &editorEvent) {
367
376
std::string controlClass = editorEvent.GetControl ()->GetName ().substr (2 , std::string::npos);
368
377
GUIControl *parent = m_RootControl;
369
378
@@ -384,7 +393,7 @@ namespace RTEGUI {
384
393
385
394
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
386
395
387
- std::string GUIEditorApp ::GenerateControlName (std::string controlType) const {
396
+ std::string EditorApp ::GenerateControlName (std::string controlType) const {
388
397
for (int i = 1 ; i < 1000 ; i++) {
389
398
std::string controlName = controlType;
390
399
std::transform (controlName.begin (), controlName.end (), controlName.begin (), tolower);
@@ -407,7 +416,7 @@ namespace RTEGUI {
407
416
408
417
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
409
418
410
- void GUIEditorApp ::UpdateCollectionBoxList () {
419
+ void EditorApp ::UpdateCollectionBoxList () {
411
420
const GUIListPanel::Item *item = m_CollectionBoxList->GetSelected ();
412
421
413
422
if (item) {
@@ -433,7 +442,7 @@ namespace RTEGUI {
433
442
434
443
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
435
444
436
- void GUIEditorApp ::UpdateGridSize (GUIEvent &editorEvent) {
445
+ void EditorApp ::UpdateGridSize (GUIEvent &editorEvent) {
437
446
std::string newValue = dynamic_cast <GUITextBox *>(editorEvent.GetControl ())->GetText ();
438
447
if (newValue.empty ()) { newValue = " 1" ; }
439
448
@@ -452,7 +461,7 @@ namespace RTEGUI {
452
461
453
462
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
454
463
455
- void GUIEditorApp ::UpdateControlProperties (GUIControl *control, bool setUnsavedChanges) {
464
+ void EditorApp ::UpdateControlProperties (GUIControl *control, bool setUnsavedChanges) {
456
465
control->StoreProperties ();
457
466
458
467
GUIProperties properties;
@@ -465,7 +474,7 @@ namespace RTEGUI {
465
474
466
475
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
467
476
468
- void GUIEditorApp ::UpdatePropertyPage (GUIEvent &editorEvent) {
477
+ void EditorApp ::UpdatePropertyPage (GUIEvent &editorEvent) {
469
478
if (editorEvent.GetMsg () == GUIPropertyPage::Enter) {
470
479
// Update the focused control properties
471
480
GUIControl *control = m_SelectionInfo.Control ;
@@ -481,7 +490,7 @@ namespace RTEGUI {
481
490
482
491
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
483
492
484
- bool GUIEditorApp ::Update () {
493
+ bool EditorApp ::Update () {
485
494
m_EditorManager->Update ();
486
495
GUIEvent editorEvent;
487
496
while (m_EditorManager->GetEvent (&editorEvent)) {
@@ -526,7 +535,7 @@ namespace RTEGUI {
526
535
527
536
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
528
537
529
- void GUIEditorApp ::ProcessMouseInput () {
538
+ void EditorApp ::ProcessMouseInput () {
530
539
std::array<int , 3 > mouseButtons;
531
540
std::array<int , 3 > mouseStates;
532
541
int mousePosX;
@@ -627,7 +636,7 @@ namespace RTEGUI {
627
636
628
637
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
629
638
630
- void GUIEditorApp ::ProcessKeyboardInput () {
639
+ void EditorApp ::ProcessKeyboardInput () {
631
640
// Handle keyboard input directly from Allegro instead of through AllegroInput to make life easier.
632
641
for (int i = 0 ; i < KEY_MAX; ++i) {
633
642
m_KeyStates.at (i) = key[i];
@@ -687,8 +696,8 @@ namespace RTEGUI {
687
696
688
697
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
689
698
690
- void GUIEditorApp ::DrawSelectionBox (GUIControl *control) {
691
- RTEAssert (control, " Trying to draw selection box for a null control! " );
699
+ void EditorApp ::DrawSelectionBox (GUIControl *control) {
700
+ assert (control);
692
701
693
702
int mousePosX;
694
703
int mousePosY;
@@ -729,15 +738,15 @@ namespace RTEGUI {
729
738
730
739
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
731
740
732
- void GUIEditorApp ::DrawSelectionResizeBox (int xPos, int yPos) const {
741
+ void EditorApp ::DrawSelectionResizeBox (int xPos, int yPos) const {
733
742
int boxSize = (m_Zoom) ? 5 : 7 ;
734
743
m_Screen->GetBitmap ()->DrawRectangle (xPos - boxSize / 2 , yPos - boxSize / 2 , boxSize, boxSize, 0x000000 , true );
735
744
m_Screen->GetBitmap ()->DrawRectangle (xPos - boxSize / 2 , yPos - boxSize / 2 , boxSize, boxSize, 0xFFFFFF , false );
736
745
}
737
746
738
747
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
739
748
740
- void GUIEditorApp ::DrawEditor () {
749
+ void EditorApp ::DrawEditor () {
741
750
if (m_WindowResized) {
742
751
acknowledge_resize ();
743
752
m_WindowResized = false ;
@@ -752,19 +761,17 @@ namespace RTEGUI {
752
761
m_EditorManager->DrawMouse ();
753
762
754
763
if (m_Zoom) {
755
- BITMAP *tempBackbuffer = create_bitmap (m_WorkspaceWidth * 2 , m_WorkspaceHeight * 2 );
756
- stretch_blit (m_BackBuffer, tempBackbuffer, m_WorkspacePosX, m_WorkspacePosY, m_WorkspaceWidth, m_WorkspaceHeight, 0 , 0 , m_WorkspaceWidth * 2 , m_WorkspaceHeight * 2 );
757
- blit (tempBackbuffer, m_BackBuffer, 0 , 0 , m_WorkspacePosX, m_WorkspacePosY - 30 , m_WorkspaceWidth * 2 , m_WorkspaceHeight * 2 );
758
- destroy_bitmap (tempBackbuffer);
764
+ stretch_blit (m_BackBuffer, m_ZoomBuffer, m_WorkspacePosX, m_WorkspacePosY, m_WorkspaceWidth, m_WorkspaceHeight, 0 , 0 , m_WorkspaceWidth * 2 , m_WorkspaceHeight * 2 );
765
+ blit (m_ZoomBuffer, m_BackBuffer, 0 , 0 , m_WorkspacePosX, m_WorkspacePosY - 30 , m_WorkspaceWidth * 2 , m_WorkspaceHeight * 2 );
759
766
}
760
767
blit (m_BackBuffer, screen, 0 , 0 , 0 , 0 , screen->w , screen->h );
761
768
}
762
769
763
770
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
764
771
765
- void GUIEditorApp ::OnLoadButton (bool addControls) {
772
+ void EditorApp ::OnLoadButton (bool addControls) {
766
773
std::string newFilename;
767
- if (GUIEditorUtil ::DisplayLoadGUIFile (&newFilename, win_get_window ())) {
774
+ if (EditorUtil ::DisplayLoadGUIFile (&newFilename, win_get_window ())) {
768
775
m_ControlManager->Load (newFilename, addControls);
769
776
m_Filename = newFilename;
770
777
@@ -787,10 +794,10 @@ namespace RTEGUI {
787
794
788
795
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
789
796
790
- void GUIEditorApp ::OnSaveButton (bool saveAsNewFile) {
797
+ void EditorApp ::OnSaveButton (bool saveAsNewFile) {
791
798
if (saveAsNewFile || m_Filename.empty ()) {
792
799
std::string newFilename;
793
- if (GUIEditorUtil ::DisplaySaveGUIFile (&newFilename, win_get_window ())) { m_Filename = newFilename; }
800
+ if (EditorUtil ::DisplaySaveGUIFile (&newFilename, win_get_window ())) { m_Filename = newFilename; }
794
801
}
795
802
// Move the root object to top left corner before saving so it is displayed correctly in-game.
796
803
m_RootControl->Move (0 , 0 );
@@ -805,18 +812,18 @@ namespace RTEGUI {
805
812
806
813
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
807
814
808
- void GUIEditorApp ::OnQuitButton () {
815
+ void EditorApp ::OnQuitButton () {
809
816
int quitResult = 1 ;
810
817
if (m_UnsavedChanges) {
811
- quitResult = GUIEditorUtil ::QuitMessageBox (" Save changes made?" , win_get_window ());
818
+ quitResult = EditorUtil ::QuitMessageBox (" Save changes made?" , win_get_window ());
812
819
if (quitResult == 1 ) { OnSaveButton (); }
813
820
}
814
821
m_Quit = (quitResult != 0 ) ? true : false ;
815
822
}
816
823
817
824
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
818
825
819
- void GUIEditorApp ::OnWindowResize (RESIZE_DISPLAY_EVENT *resizeInfo) {
826
+ void EditorApp ::OnWindowResize (RESIZE_DISPLAY_EVENT *resizeInfo) {
820
827
m_EditorBase->Resize (resizeInfo->new_w , resizeInfo->new_h );
821
828
m_LeftColumn->Resize (m_LeftColumn->GetWidth (), resizeInfo->new_h );
822
829
m_RightColumn->Resize (m_RightColumn->GetWidth (), resizeInfo->new_h );
0 commit comments