1
1
#include " EditorApp.h"
2
2
#include " EditorUtil.h"
3
- #include " GUIButton.h"
4
3
#include " GUICheckbox.h"
5
- #include " GUILabel.h"
6
4
#include " GUITextBox.h"
7
5
#include " winalleg.h"
8
6
9
7
namespace RTEGUI {
10
8
9
+ int64_t EditorApp::s_FrameTime = 0 ;
10
+
11
11
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12
12
13
- bool EditorApp::Initialize () {
13
+ void EditorApp::Initialize () {
14
14
set_color_depth (32 );
15
15
set_color_conversion (COLORCONV_MOST);
16
16
set_window_title (" Cortex Command GUI Editor" );
@@ -24,73 +24,28 @@ namespace RTEGUI {
24
24
m_BackBuffer = create_bitmap (GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN));
25
25
clear_to_color (m_BackBuffer, 0 );
26
26
27
- m_ZoomBuffer = create_bitmap (m_WorkspaceWidth * 2 , m_WorkspaceHeight * 2 );
28
- clear_to_color (m_ZoomBuffer, 0 );
29
-
30
27
m_Screen = std::make_unique<AllegroScreen>(m_BackBuffer);
31
28
m_Input = std::make_unique<AllegroInput>(-1 );
32
29
33
30
// Initialize the UI
34
-
35
- return true ;
36
- }
37
-
31
+ m_EditorManager = std::make_unique<EditorManager>(m_Screen.get (), m_Input.get (), " Assets" , " EditorSkin.ini" );
38
32
39
33
// Only allow workspace zoom if the screen resolution is FHD or above, smaller resolutions can't fully display it
34
+ if (m_BackBuffer->w < 1920 && m_BackBuffer->h < 1080 ) {
35
+ m_EditorManager->DisableZoomCheckbox ();
36
+ } else {
37
+ m_ZoomBuffer = create_bitmap (m_EditorManager->GetWorkspaceWidth () * 2 , m_EditorManager->GetWorkspaceHeight () * 2 );
38
+ clear_to_color (m_ZoomBuffer, 0 );
40
39
}
41
40
41
+ // show_os_cursor(MOUSE_CURSOR_ARROW);
42
42
}
43
43
44
44
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45
45
46
46
void EditorApp::DestroyBackBuffers () {
47
47
destroy_bitmap (m_BackBuffer);
48
- destroy_bitmap (m_ZoomBuffer);
49
- }
50
-
51
- // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52
-
53
- bool EditorApp::Update () {
54
- m_EditorManager->Update ();
55
- GUIEvent editorEvent;
56
- while (m_EditorManager->GetEvent (&editorEvent)) {
57
- switch (editorEvent.GetType ()) {
58
- case GUIEvent::Command:
59
- if (editorEvent.GetControl ()->GetName () == " QuitButton" ) {
60
- OnQuitButton ();
61
- } else if (editorEvent.GetControl ()->GetName () == " LoadButton" ) {
62
- OnLoadButton ();
63
- } else if (editorEvent.GetControl ()->GetName () == " AddButton" ) {
64
- OnLoadButton (true );
65
- } else if (editorEvent.GetControl ()->GetName () == " SaveButton" ) {
66
- OnSaveButton ();
67
- } else if (editorEvent.GetControl ()->GetName () == " SaveAsButton" ) {
68
- OnSaveButton (true );
69
- } else if (editorEvent.GetControl ()->GetName ().substr (0 , 2 ).compare (" C_" ) == 0 ) {
70
- AddNewControl (editorEvent);
71
- }
72
- break ;
73
- case GUIEvent::Notification:
74
- if (editorEvent.GetControl ()->GetName () == " ActiveCollectionBoxes" && editorEvent.GetMsg () == GUIListBox::MouseDown) {
75
- UpdateCollectionBoxList ();
76
- } else if (editorEvent.GetControl ()->GetName () == " PropertyPage" ) {
77
- UpdatePropertyPage (editorEvent);
78
- } else if (editorEvent.GetControl ()->GetName () == " GridSizeTextBox" && editorEvent.GetMsg () == GUITextBox::Enter) {
79
- UpdateGridSize (editorEvent);
80
- } else if (editorEvent.GetControl ()->GetName () == " SnapCheckBox" ) {
81
- m_SnapToGrid = (dynamic_cast <GUICheckbox *>(editorEvent.GetControl ()))->GetCheck () == GUICheckbox::Checked;
82
- } else if (editorEvent.GetControl ()->GetName () == " ZoomCheckBox" ) {
83
- m_Zoom = (dynamic_cast <GUICheckbox *>(editorEvent.GetControl ()))->GetCheck () == GUICheckbox::Checked;
84
- }
85
- break ;
86
- default :
87
- break ;
88
- }
89
- }
90
- ProcessMouseInput ();
91
- ProcessKeyboardInput ();
92
-
93
- return !m_Quit;
48
+ if (m_ZoomBuffer) { destroy_bitmap (m_ZoomBuffer); }
94
49
}
95
50
96
51
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -256,9 +211,52 @@ namespace RTEGUI {
256
211
257
212
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
258
213
214
+ bool EditorApp::UpdateEditor () {
215
+ m_EditorManager->GetControlManager ()->Update ();
216
+ GUIEvent editorEvent;
217
+ while (m_EditorManager->GetControlManager ()->GetEvent (&editorEvent)) {
218
+ std::string controlName = editorEvent.GetControl ()->GetName ();
219
+ switch (editorEvent.GetType ()) {
220
+ case GUIEvent::Command:
221
+ if (controlName == " QuitButton" ) {
222
+ OnQuitButton ();
223
+ } else if (controlName == " LoadButton" ) {
224
+ OnLoadButton ();
225
+ } else if (controlName == " AddButton" ) {
226
+ OnLoadButton (true );
227
+ } else if (controlName == " SaveButton" ) {
228
+ OnSaveButton ();
229
+ } else if (controlName == " SaveAsButton" ) {
230
+ OnSaveButton (true );
231
+ } else if (controlName.substr (0 , 2 ).compare (" C_" ) == 0 ) {
232
+ m_UnsavedChanges = m_EditorManager->AddNewControl (editorEvent);
233
+ }
234
+ break ;
235
+ case GUIEvent::Notification:
236
+ if (controlName == " PropertyPage" ) {
237
+ m_UnsavedChanges = m_EditorManager->UpdatePropertyPage (editorEvent);
238
+ } else if (controlName == " CollectionBoxList" && editorEvent.GetMsg () == GUIListBox::MouseDown) {
239
+ m_EditorManager->UpdateCollectionBoxList ();
240
+ } else if (controlName == " ControlsInCollectionBoxList" && editorEvent.GetMsg () == GUIListBox::MouseDown) {
241
+ // m_EditorManager->UpdateControlsInCollectionBoxList();
242
+ } else if (controlName == " GridSizeTextBox" && editorEvent.GetMsg () == GUITextBox::Enter) {
243
+ m_EditorManager->UpdateSnapGridSize (editorEvent);
244
+ } else if (controlName == " SnapCheckBox" ) {
245
+ EditorSelection::s_SnapToGrid = dynamic_cast <GUICheckbox *>(editorEvent.GetControl ())->GetCheck () == GUICheckbox::Checked;
246
+ } else if (controlName == " ZoomCheckBox" ) {
247
+ m_ZoomWorkspace = (dynamic_cast <GUICheckbox *>(editorEvent.GetControl ()))->GetCheck () == GUICheckbox::Checked;
248
+ }
249
+ break ;
250
+ default :
251
+ break ;
252
+ }
259
253
}
254
+ ProcessMouseInput ();
255
+ ProcessKeyboardInput ();
260
256
257
+ m_EditorManager->SetFrameTimeLabelText (s_FrameTime);
261
258
259
+ return !m_Quit;
262
260
}
263
261
264
262
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -270,59 +268,66 @@ namespace RTEGUI {
270
268
}
271
269
clear_to_color (m_BackBuffer, 0 );
272
270
273
- m_EditorBase ->Draw (m_Screen.get ());
274
- m_ControlManager ->Draw ();
275
- if (m_SelectionInfo. Control ) { DrawSelectionBox (m_SelectionInfo. Control ); }
276
- m_LeftColumn ->Draw (m_Screen.get ());
277
- m_RightColumn ->Draw (m_Screen.get ());
278
- m_EditorManager->DrawMouse ();
271
+ m_EditorManager-> GetEditorBase () ->Draw (m_Screen.get ());
272
+ m_EditorManager-> GetWorkspaceManager () ->Draw ();
273
+ m_EditorManager-> GetCurrentSelection (). DrawSelectionBox (m_Screen. get (), m_Input. get ());
274
+ m_EditorManager-> GetLeftColumn () ->Draw (m_Screen.get ());
275
+ m_EditorManager-> GetRightColumn () ->Draw (m_Screen.get ());
276
+ m_EditorManager->GetControlManager ()-> DrawMouse ();
279
277
280
- if (m_Zoom ) {
281
- stretch_blit (m_BackBuffer, m_ZoomBuffer, m_WorkspacePosX, m_WorkspacePosY, m_WorkspaceWidth, m_WorkspaceHeight , 0 , 0 , m_WorkspaceWidth * 2 , m_WorkspaceHeight * 2 );
282
- blit (m_ZoomBuffer, m_BackBuffer, 0 , 0 , m_WorkspacePosX, m_WorkspacePosY - 30 , m_WorkspaceWidth * 2 , m_WorkspaceHeight * 2 );
278
+ if (m_ZoomWorkspace ) {
279
+ stretch_blit (m_BackBuffer, m_ZoomBuffer, m_EditorManager-> GetWorkspacePosX (), m_EditorManager-> GetWorkspacePosY (), m_EditorManager-> GetWorkspaceWidth (), m_EditorManager-> GetWorkspaceHeight () , 0 , 0 , m_EditorManager-> GetWorkspaceWidth () * 2 , m_EditorManager-> GetWorkspaceHeight () * 2 );
280
+ blit (m_ZoomBuffer, m_BackBuffer, 0 , 0 , m_EditorManager-> GetWorkspacePosX (), m_EditorManager-> GetWorkspacePosY () - 30 , m_EditorManager-> GetWorkspaceWidth () * 2 , m_EditorManager-> GetWorkspaceHeight () * 2 );
283
281
}
284
282
blit (m_BackBuffer, screen, 0 , 0 , 0 , 0 , screen->w , screen->h );
285
283
}
286
284
287
285
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
288
286
289
287
void EditorApp::OnLoadButton (bool addControls) {
288
+ if (m_UnsavedChanges) {
289
+ int result = EditorUtil::DisplayDialogBox (" Save changes made?" , win_get_window ());
290
+ if (result == 0 ) {
291
+ return ;
292
+ } else if (result == 1 ) {
293
+ OnSaveButton ();
294
+ }
295
+ }
290
296
std::string newFilename;
291
- if (EditorUtil::DisplayLoadGUIFile (& newFilename, win_get_window ())) {
292
- m_ControlManager ->Load (newFilename, addControls);
293
- m_Filename = newFilename;
297
+ if (EditorUtil::DisplayLoadFileDialogBox ( newFilename, win_get_window ())) {
298
+ m_EditorManager-> GetWorkspaceManager () ->Load (newFilename, addControls);
299
+ m_ActiveFileName = newFilename;
294
300
295
- GUIControl *newRootControl = m_ControlManager->GetControlList ()->front ();
296
- m_RootControl = newRootControl;
297
- newRootControl->Move (m_WorkspacePosX, m_WorkspacePosY);
301
+ GUIControl *newRootControl = m_EditorManager->GetWorkspaceManager ()->GetControlList ()->front ();
302
+ newRootControl->Move (m_EditorManager->GetWorkspacePosX (), m_EditorManager->GetWorkspacePosY ());
298
303
newRootControl->StoreProperties ();
299
304
300
305
GUIProperties newRootControlProps;
301
306
newRootControlProps.Update (newRootControl->GetProperties (), true );
302
307
newRootControl->GetPanel ()->BuildProperties (&newRootControlProps);
303
308
304
- m_SelectionInfo. ClearSelection ();
305
- m_PropertyPage-> ClearValues ( );
309
+ m_EditorManager-> ClearCurrentSelection ();
310
+ m_EditorManager-> SetRootControl (newRootControl );
306
311
m_UnsavedChanges = false ;
307
312
308
- PopulateCollectionBoxList ();
313
+ m_EditorManager-> PopulateCollectionBoxList ();
309
314
}
310
315
}
311
316
312
317
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
313
318
314
319
void EditorApp::OnSaveButton (bool saveAsNewFile) {
315
- if (saveAsNewFile || m_Filename .empty ()) {
320
+ if (saveAsNewFile || m_ActiveFileName .empty ()) {
316
321
std::string newFilename;
317
- if (EditorUtil::DisplaySaveGUIFile (& newFilename, win_get_window ())) { m_Filename = newFilename; }
322
+ if (EditorUtil::DisplaySaveFileDialogBox ( newFilename, win_get_window ())) { m_ActiveFileName = newFilename; }
318
323
}
319
324
// Move the root object to top left corner before saving so it is displayed correctly in-game.
320
- m_RootControl ->Move (0 , 0 );
325
+ m_EditorManager-> GetRootControl () ->Move (0 , 0 );
321
326
322
- m_ControlManager-> Save (m_Filename );
327
+ m_EditorManager-> GetWorkspaceManager ()-> Save (m_ActiveFileName );
323
328
324
329
// Move the root object back to the workspace position in the editor
325
- m_RootControl-> Move (m_WorkspacePosX, m_WorkspacePosY );
330
+ m_EditorManager-> GetRootControl ()-> Move (m_EditorManager-> GetWorkspacePosX (), m_EditorManager-> GetWorkspacePosY () );
326
331
327
332
m_UnsavedChanges = false ;
328
333
}
@@ -332,7 +337,7 @@ namespace RTEGUI {
332
337
void EditorApp::OnQuitButton () {
333
338
int quitResult = 1 ;
334
339
if (m_UnsavedChanges) {
335
- quitResult = EditorUtil::QuitMessageBox (" Save changes made?" , win_get_window ());
340
+ quitResult = EditorUtil::DisplayDialogBox (" Save changes made?" , win_get_window ());
336
341
if (quitResult == 1 ) { OnSaveButton (); }
337
342
}
338
343
m_Quit = (quitResult != 0 ) ? true : false ;
@@ -341,11 +346,7 @@ namespace RTEGUI {
341
346
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
342
347
343
348
void EditorApp::OnWindowResize (RESIZE_DISPLAY_EVENT *resizeInfo) {
344
- m_EditorBase->Resize (resizeInfo->new_w , resizeInfo->new_h );
345
- m_LeftColumn->Resize (m_LeftColumn->GetWidth (), resizeInfo->new_h );
346
- m_RightColumn->Resize (m_RightColumn->GetWidth (), resizeInfo->new_h );
347
- m_RightColumn->Move (resizeInfo->new_w - m_RightColumn->GetWidth (), 0 );
348
- m_ControlsInActiveCollectionBoxList->Resize (m_CollectionBoxList->GetWidth (), resizeInfo->new_h - m_ControlsInActiveCollectionBoxList->GetRelYPos () - 5 );
349
+ m_EditorManager->GetRightColumn ()->Move (resizeInfo->new_w - m_EditorManager->GetRightColumn ()->GetWidth (), 0 );
349
350
m_WindowResized = true ;
350
351
}
351
352
}
0 commit comments