-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControlsForm.cpp
6393 lines (5410 loc) · 162 KB
/
ControlsForm.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
//---------------------------------------------------------------------------
//This software is Copyright (c) 2015 Embarcadero Technologies, Inc.
//You may only use this software if you are an authorized licensee
//of an Embarcadero developer tools product.
//This software is considered a Redistributable as defined under
//the software license agreement that comes with the Embarcadero Products
//and is subject to that software license agreement.
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include "ControlsForm.h"
//look at Barf.gua, centering horizontally cause "Invalid pointer" error after failed message box closed
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#pragma resource ("*.Windows.fmx", _PLAT_MSWINDOWS)
int gripSize = 8;
int halfGrip = gripSize / 1;
int qtrGrip = gripSize / 4;
//Variable to hold old data
float LW, LH;
bool inSizeMode = false;
bool onLeft = false;
bool onRight = false;
bool onTop = false;
bool onBottom = false;
//Helper items
TStringList * selectionsList = new TStringList();
TEditFeature *editList = new TEditFeature();
UICodeView * codeView = new UICodeView();
//UNDO/REDO states
TStringList *saveStateString = new TStringList();
bool saveStateChanged = false;
//Current screen display
LUADisplay *disp = new LUADisplay();
//List of all running animations
bool isAnimating = false;
TList *animations = new TList();
//Main form
Tsolar2DForm *solar2DForm;
//---------------------------------------------------------------------------
__fastcall Tsolar2DForm::Tsolar2DForm(TComponent *Owner)
: TForm(Owner)
{
TMetaClass *mc;
mc = __classid(TRectangleEx);
RegisterClasses(&mc, 0);
mc = __classid(TTextEx);
RegisterClasses(&mc, 0);
//mc = __classid(TControlEx);
//RegisterClasses(&mc, 0);
//These functions reside in 'LUADisplay\LUADisplay.h &.cpp'
initFunctionCalls();
//Screen orientation
screenOrientation = 90;
exePath = GetCurrentDir();
//File modified flag
isModified = false;
//Initialobject data updates allowed
allowObjectUpdates = true;
//Set a default screen display: iPhone 4s
//(LUADisplay *)(*luaDisplay[ 38 ])(disp);
}
//--------------------------------------------------------
//
//Main form destruction
//
//--------------------------------------------------------
void __fastcall Tsolar2DForm::FormDestroy(TObject *Sender)
{
delete selectionsList;
delete editList;
delete deviceScreen;
delete codeView;
delete saveStateString;
if (disp)
{
clearDisplayValues(disp);
delete disp;
}
}
//--------------------------------------------------------
//
//Main form creation
//
//--------------------------------------------------------
void __fastcall Tsolar2DForm::FormCreate(TObject *Sender)
{
AnsiString Name;
//Clear in case of design time placement deviceScreen->ChildrenCount
controlTree->Clear();
TRectangle *array[] =
{
TL, TC, TR,
L,R,
BL,BC, BR
};
for (int i = 0; i < 8; i++)
{
array[i]->Height = gripSize;
array[i]->Width = gripSize;
}
//Screen display
initBitmapData(disp);
//Read in settings setting
if (FileExists(exePath + "\\settings.ini"))
{
reloadSettingsClick(NULL);
}
else
{
screenResolutionClick(display38);
}
//Create new window / Text for designing
TRectangleEx *ARect = (TRectangleEx *)createNewControl(deviceScreen, "Rect");
TText *AText = (TText *)createNewControl(deviceScreen, "Text");
ARect->Position->X = (deviceScreen->Width / 2) - (ARect->Width / 2);
ARect->Position->Y = (deviceScreen->Height / 2) - (ARect->Height / 2);
AText->AutoSize = true;
AText->WordWrap = false;
AText->Text = "First text object";
AText->WordWrap = true;
AText->AutoSize = false;
AText->Position->X = ARect->Position->X + ((ARect->Width / 2) - (AText->Width / 2));
AText->Position->Y = (ARect->Position->Y - (AText->Height * 2));
//Get the initial Z order for all USABLE objects
calcControlZOrder(deviceScreen);
//Build sorted by Z Order tree view
updateTreeView();
//Hide helper items
colorArray->Visible = false;
//Non Visual helper items
selectionsList->Clear();
//selectionsList->Duplicates = System::Types::TDuplicates::dupIgnore;
//selectionsList->Sorted = true;
//
editList->Clear();
//
adjustHandles(false, NULL);
updateInspector();
inSizeMode = false;
// //Screen display
//initBitmapData(disp);
//
// //Read in settings setting
//if (FileExists(exePath + "\\settings.ini"))
//{
//reloadSettingsClick(NULL);
//}
//else
//{
//screenResolutionClick(display38);
//}
//Code View triggers
codeView->IsDisplayed = false;
codeView->changesMade = false;
//First UNDO update
//saveStateString->Duplicates = System::Types::TDuplicates::dupIgnore;
//saveStateString->Sorted = true;
//updateUndoStack("", false);
}
//--------------------------------------------------------
//
//Save the INI file with App data tobe reloaded
//
//--------------------------------------------------------
void __fastcall Tsolar2DForm::FormClose(TObject *Sender, TCloseAction &Action)
{
//Save current desktop settings
saveSettingsClick(NULL);
//Make sure nothing needs saving
if (isModified)
{
TmsgForm *msg = new TmsgForm(Application);
msg->messageText->Text = "Project not saved. Do you wish to save your changes?";
msg->Caption = "Save current project...";
msg->ShowModal();
//What result did we receive?
if (msg->ModalResult == mrYes)
{
//Attempt to save the project
saveProjClick(NULL);
}
msgForm->DisposeOf();
}
}
//--------------------------------------------------------
//
//Undo / Redo stack
//
//--------------------------------------------------------
void __fastcall Tsolar2DForm::updateUndoStack(String state, bool isAnimation)
{
if (isAnimating)
return;
if (state == "")
{
TJsonTextWriter *writer = NULL;
TStringWriter * stringWriter = new TStringWriter();
writer = new TJsonTextWriter(stringWriter);
//Attempt to save the project data to a file
if (writer && deviceScreen)
{
//NO Formatting! Easier / Faster to process
//writer->Formatting = TJsonFormatting::Indented;
//writer->Indentation = 1;
//writer->IndentChar = '\t';
//Open it
writer->WriteStartObject();
//Write out all the Objects on the 'deviceScreen'
processJsonWrite(deviceScreen, writer, "");
//Close it
writer->WriteEndObject();
//Running an animation
if (isAnimation)
{
runAnimation->TagString = stringWriter->ToString();
}
else
{
if (saveStateString->Count == MAXSAVESTATES)
{
//Shift and erase some of the older changes. Sorry, user.
saveStateString->Delete(0);
}
//Save the string. Last string in CANNOT match new string in
if (!saveStateString->Count || (saveStateString->Count && AnsiString(saveStateString->Strings[saveStateString->Count - 1]).AnsiCompareIC(stringWriter->ToString())))
{
saveStateString->Add(stringWriter->ToString());
}
}
editUndo->Text = Format("Undo [ %02d / %02d ]", ARRAYOFCONST((saveStateString->Count, MAXSAVESTATES)));
//
delete writer;
delete stringWriter;
}
}
else
{
if ((saveStateString->Count + 1) == MAXSAVESTATES)
{
//Shift and erase some of the older changes. Sorry, user.
saveStateString->Delete(0);
}
//Save the string
saveStateString->Add(state);
}
//Update inspector and menu items
updateInspector();
}
//--------------------------------------------------------
//
//Undo / Redo
//
//--------------------------------------------------------
void __fastcall Tsolar2DForm::editUndoClick(TObject *Sender)
{
//Easiest way to handle this is to save the current state
//of the project as if it were saving the project itself
//Do so as a stream instead of a file
if (isAnimating)
return;
TMenuItem *m = dynamic_cast<TMenuItem *>(Sender);
//Menu item check
if (m || (Sender == NULL && runAnimation->TagString != ""))
{
TStringStream * string = NULL;
TStreamReader * stream = NULL; // = new TStreamReader(FOpen->FileName);
TJsonTextReader *reader = NULL; // = new TJsonTextReader(stream);
//Restore after an animation
if (Sender == NULL && runAnimation->TagString != "")
{
//Load the last state
string = new TStringStream(runAnimation->TagString);
stream = new TStreamReader(string);
reader = new TJsonTextReader(stream);
//
runAnimation->TagString = "";
}
else if (Sender && m->Tag == 0 && saveStateString->Count)
{
//Load the last state
string = new TStringStream(saveStateString->Strings[saveStateString->Count - 1]);
//string->SaveToFile("dummy.txt");
//Pull from stack
saveStateString->Delete(saveStateString->Count - 1);
stream = new TStreamReader(string);
reader = new TJsonTextReader(stream);
//saveStateCount--;
}
//else if (m->Tag == 1 && (saveStateCount + 1) < MAXSAVESTATES && saveStateString[saveStateCount + 1] != "")
//{
// //Redo using the latest change
//saveStateCount++;
//stream = new TStreamReader(saveStateString[saveStateCount]);
//reader = new TJsonTextReader(stream);
//}
//Process the Undo / Redo request
if (reader && stream && deviceScreen)
{
//Prevent Errors from selected items that will be deleted
selectionRect->TagObject = NULL;
clearObjectSelections();
//Kill all children and BG image
deviceScreen->TagString = "";
deviceScreen->DeleteChildren();
deviceScreen->Fill->Bitmap->Bitmap = NULL;
deviceScreen->Fill->Color = TAlphaColorRec::Black;
deviceScreen->Fill->Kind = TBrushKind::Solid;
//Read in all the Objects to the 'deviceScreen'
processJsonRead(deviceScreen, reader);
delete reader;
delete stream;
delete string;
//project modified
isModified = true;
codeView->changesMade = true;
codeView->IsDisplayed = false;
codeMemo->Lines->Clear();
codeTabItem->Text = "Code View [Changes not saved]";
codeMemo->FontColor = claRed;
//Italic
TFontStyles AStyle(2);
codeMemo->Font->Style = codeMemo->Font->Style + AStyle;
//If the tab is visible, show the new data
if (mainTab->ActiveTab == codeTabItem)
{
codeTabItemClick(NULL);
}
//Update all data
updateTreeView();
updateInspector();
alignObjects();
//A little screen clean up
clearObjectSelections();
clearAllCursors(deviceScreen);
//Align all objects on the device screen
setAllAlignments(deviceScreen);
//
selectionRect->TagObject = NULL;
adjustHandles(false, NULL);
//Set the background image if it exists
if (deviceScreen->TagString != "" && FileExists(deviceScreen->TagString))
{
deviceScreen->Fill->Bitmap->Bitmap->LoadFromFile(deviceScreen->TagString);
deviceScreen->Fill->Bitmap->WrapMode = TWrapMode::TileStretch;
deviceScreen->Fill->Kind = TBrushKind::Bitmap;
}
//Clear animation list per selection. Crashes App some times
animListBox->Clear();
//
deviceScreen->Repaint();
}
//
editUndo->Text = Format("Undo [ %02d / %02d ]", ARRAYOFCONST((saveStateString->Count, MAXSAVESTATES)));
}
}
//--------------------------------------------------------
//
//Special case keypresses on the form
//
//--------------------------------------------------------
void __fastcall Tsolar2DForm::FormKeyDown(TObject *Sender, WORD &Key, System::WideChar &KeyChar, TShiftState Shift)
{
//Delete objects
if (Key == VK_DELETE)
{
//Do nothing if animations are running
if (isAnimating)
return;
if (selectionRect->TagObject || selectionsList->Count)
{
TSpeedButton *sb = new TSpeedButton(solar2DForm);
sb->Visible = false;
//Simulate clicking 'Delete'
if (sb)
{
sb->Tag = 6;
objectActionClick(sb);
delete sb;
return;
}
}
}
//Cancel actions
if (Key == VK_ESCAPE)
{
if (isAnimating)
{
stopAnimationClick(NULL);
}
else if (selectionsList->Count)
{
//Release the object
selectionRect->TagObject = NULL;
adjustHandles(false, NULL);
updateInspector();
updateObjectData();
clearAllCursors(deviceScreen);
clearObjectSelections();
deviceScreen->Repaint();
}
else if (selectionRect->TagObject)
{
TControl *c = dynamic_cast<TControl *>(selectionRect->TagObject);
if (c)
{
if (c->ClassType() == __classid(TRectangleEx))
{
((TRectangleEx *)c)->AutoCapture = false;
((TRectangleEx *)c)->Position->X = ((TRectangleEx *)c)->oldX;
((TRectangleEx *)c)->Position->Y = ((TRectangleEx *)c)->oldY;
((TRectangleEx *)c)->Width = ((TRectangleEx *)c)->oldW;
((TRectangleEx *)c)->Height = ((TRectangleEx *)c)->oldH;
}
else
{
((TTextEx *)c)->AutoCapture = false;
((TTextEx *)c)->Position->X = ((TTextEx *)c)->oldX;
((TTextEx *)c)->Position->Y = ((TTextEx *)c)->oldY;
((TTextEx *)c)->Width = ((TTextEx *)c)->oldW;
((TTextEx *)c)->Height = ((TTextEx *)c)->oldH;
}
//Release the object
selectionRect->TagObject = NULL;
adjustHandles(false, NULL);
updateInspector();
updateObjectData();
clearAllCursors(deviceScreen);
clearObjectSelections();
deviceScreen->Repaint();
}
}
}
}
void __fastcall Tsolar2DForm::saveSettingsClick(TObject *Sender)
{
if (isAnimating)
return;
TCustomIniFile *ini = new TIniFile(exePath + "\\settings.ini");
if (ini)
{
ini->WriteInteger("Main Window", "X", Left);
ini->WriteInteger("Main Window", "Y", Top);
ini->WriteInteger("Main Window", "Width", Width);
ini->WriteInteger("Main Window", "Height", Height);
ini->WriteInteger("Main Window", "WindowState", WindowState);
ini->WriteInteger("Main Window", "UseTable", expTable->IsChecked);
//Device Screen
if (deviceScreen->TagString != "" && FileExists(deviceScreen->TagString))
{
ini->WriteString("DeviceScreen", "BG", deviceScreen->TagString);
}
//Device Frame
ini->WriteFloat("DeviceFrame", "X", deviceFrame->Position->X);
ini->WriteFloat("DeviceFrame", "Y", deviceFrame->Position->Y);
ini->WriteFloat("DeviceFrame", "Scale", ScaleTrack->Value);
ini->WriteBool("DeviceFrame", "Borders", borderToggle->IsChecked);
ini->WriteBool("DeviceFrame", "CrossHair", crossHair->IsChecked);
ini->WriteInteger("DeviceFrame", "Device", disp->selectedDisplay);
ini->WriteInteger("DeviceFrame", "Orientation", screenOrientation);
ini->WriteInteger("TabControl", "MainActiveTab", mainTab->TabIndex);
ini->WriteInteger("TabControl", "SubActiveTab", inspectorTab->TabIndex);
//Always clean up after yourself
delete ini;
}
}
void __fastcall Tsolar2DForm::reloadSettingsClick(TObject *Sender)
{
if (isAnimating)
return;
TCustomIniFile *ini = new TIniFile(exePath + "\\settings.ini");
if (ini)
{
//Main window
Left = ini->ReadInteger("Main Window", "X", 0);
Top = ini->ReadInteger("Main Window", "Y", 0);
Width = ini->ReadInteger("Main Window", "Width", 800);
Height = ini->ReadInteger("Main Window", "Height",600);
WindowState = ini->ReadInteger("Main Window", "WindowState", TWindowState::wsNormal);
expTable->IsChecked = ini->ReadBool("Main Window", "UseTable", false);
//
if (WindowState == TWindowState::wsMaximized)
{
Height = 740;
Width = 1080;
Position = TFormPosition::ScreenCenter;
}
//Device Screen
deviceScreen->TagString = ini->ReadString("DeviceScreen", "BG", "");
if (deviceScreen->TagString != "" && FileExists(deviceScreen->TagString))
{
deviceScreen->Fill->Bitmap->Bitmap->LoadFromFile(deviceScreen->TagString);
deviceScreen->Fill->Bitmap->WrapMode = TWrapMode::TileStretch;
deviceScreen->Fill->Kind = TBrushKind::Bitmap;
//Depending on the popup location, some objects may
//retain a resize cursor by accident. Need to clear that up.
clearAllCursors(deviceScreen);
}
//Device Frame
deviceFrame->Position->X = ini->ReadFloat("DeviceFrame", "X", 0);
deviceFrame->Position->Y = ini->ReadFloat("DeviceFrame", "Y", 0);
ScaleTrack->Value = ini->ReadFloat("DeviceFrame", "Scale", 1);
borderToggle->IsChecked = ini->ReadBool("DeviceFrame", "Borders", false);
crossHair->IsChecked = ini->ReadBool("DeviceFrame", "CrossHair", false);
int device = ini->ReadInteger("DeviceFrame", "Device", 38);
screenOrientation = ini->ReadInteger("DeviceFrame", "Orientation", 90);
int activeTab = ini->ReadInteger("TabControl", "MainActiveTab", 0);
mainTab->TabIndex = activeTab;
activeTab = ini->ReadInteger("TabControl", "SubActiveTab", 0);
inspectorTab->TabIndex = activeTab;
//Manually check the right box
//There are two separate groups of Radio Menu items
//Which ever group is active, the other 'complete' group
//needs to be deactivated
TObject *chk[2] =
{
borderlessSubMenu->Children->Items[0],
viewMenu->Children->Items[0]
};
for (int c = 0; c < 2; c++)
{
TControl *parent = dynamic_cast<TControl *>(chk[c]);
if (parent)
{
for (int i = 0; i < parent->ChildrenCount; i++)
{
TMenuItem *c = dynamic_cast<TMenuItem*>(parent->Children->Items[i]);
if (c)
{
if (c->Tag == device)
c->IsChecked = true;
else
c->IsChecked = false;
}
}
}
}
//Set the display
setScreenDisplay(device);
//Always clean up after yourself
delete ini;
}
}
void __fastcall Tsolar2DForm::FormResize(TObject *Sender)
{
//Use the row sizes added together to get final size
int count = propsGridL->RowCollection->Count;
int h = 0;
for (int row = 0; row < count; row++)
{
h += (propsGridL->CellRect[0][row].Bottom - propsGridL->CellRect[0][row].Top);
}
//Set the 'real' size of the grid so the panel adjust and scrollbox reacts correctly
propsSizedPanel->Height = h;
//--------------------------------------
//Align controls
//--------------------------------------
count = alignGridL->RowCollection->Count;
h = 0;
for (int row = 0; row < count; row++)
{
h += (alignGridL->CellRect[0][row].Bottom - alignGridL->CellRect[0][row].Top);
}
//
gridScrollBox->Align = TAlignLayout::None;
alignSizedPanel->Height = h;
//Set the grid to bottom of the scroll box
controlTree->Height = ((Panel2->Height - (alignSplitter->Height*2)) - alignSizedPanel->Height);
gridScrollBox->Align = TAlignLayout::Client;
//--------------------------------------
//Align Items for the Animation grids
//--------------------------------------
count = animGridL->RowCollection->Count;
h = 0;
for (int row = 0; row < count; row++)
{
h += (animGridL->CellRect[0][row].Bottom - animGridL->CellRect[0][row].Top);
}
//
animListBox->Align = TAlignLayout::None;
animSizedPanel->Height = h;
animScrollBox->Height = h + animHSplitter->Height;
//Set the grid to bottom of the scroll box
animListBox->Height = (Panel3->Height - animScrollBox->Height);
animListBox->Align = TAlignLayout::Client;
}
//--------------------------------------------------------
//
//Device screen
//
//--------------------------------------------------------
void __fastcall Tsolar2DForm::screenResolutionClick(TObject *Sender)
{
if (isAnimating)
return;
//Screen Resolution selector
TMenuItem *m = dynamic_cast<TMenuItem*>(Sender);
TControl *parent;
if (m)
{
//
if (m->IsChecked == false)
m->IsChecked = true;
//There are two separate groups of Radio Menu items
//Which ever group is active, the other 'complete' group
//needs to be deactivated
if (m->GroupIndex == 1)
{
//Clear all of GroupIndex 2
parent = dynamic_cast<TControl *>(borderlessSubMenu->Children->Items[0]);
}
else
{
parent = dynamic_cast<TControl *>(viewMenu->Children->Items[0]);
}
if (parent)
{
for (int i = 0; i < parent->ChildrenCount; i++)
{
TMenuItem *c = dynamic_cast<TMenuItem*>(parent->Children->Items[i]);
if (c)
c->IsChecked = false;
}
}
//Set the new display
setScreenDisplay(m->Tag);
//Only show if there is an active SINGLE selection
if (selectionRect->TagObject)
adjustHandles(true, NULL);
else
adjustHandles(false, NULL);
}
}
void __fastcall Tsolar2DForm::ScaleTrackChange(TObject *Sender)
{
//Change scale
deviceFrame->Scale->X = ScaleTrack->Value;
deviceFrame->Scale->Y = ScaleTrack->Value;
//Poistion in top left corner if needed
if (deviceFrame->Width > deviceScrollBox->Width)
deviceFrame->Position->X = 0;
if (deviceFrame->Height > deviceScrollBox->Height)
deviceFrame->Position->Y = 0;
//
TextScale->Text = IntToStr((int)(ScaleTrack->Value*100))+"%";
//Adjust the selection
if (selectionRect->IsVisible)
adjustHandles(true, NULL);
}
void __fastcall Tsolar2DForm::setScreenDisplay(int displayIndex)
{
//Set the deviceScreen to the appropriate resolution
(*luaDisplay[displayIndex])(disp);
//Change the device view
if (!disp->deviceImage->IsEmpty())
{
//
deviceFrame->Fill->Kind = TBrushKind::Bitmap;
deviceFrame->Fill->Bitmap->Bitmap = disp->deviceImage;
int rotate = 0;
while(rotate < screenOrientation)
{
deviceFrame->Fill->Bitmap->Bitmap->Rotate(90);
rotate += 90;
}
}
else
{
deviceFrame->Fill->Kind = TBrushKind::None;
deviceFrame->Fill->Bitmap->Bitmap->Width = 0;
deviceFrame->Fill->Bitmap->Bitmap->Height = 0;
}
//Change the device dressing if exist
if (!disp->screenDressing->IsEmpty())
{
int rotate = 0;
while(rotate < screenOrientation)
{
disp->screenDressing->Rotate(90);
rotate += 90;
}
}
else
{
//deviceFrame->Fill->Kind = TBrushKind::None;
// //deviceFrame->Fill->Bitmap->Bitmap = NULL;
//deviceFrame->Fill->Bitmap->Bitmap->Width = 0;
//deviceFrame->Fill->Bitmap->Bitmap->Height = 0;
}
disp->selectedDisplay = displayIndex;
//Apply display metrics
applyDisplayMetrics();
//Load the DPI, etc data from the table using m->Tag
}
//--------------------------------------------------------
//
//Display Metrics are applied to the Screen and Frame
//
//--------------------------------------------------------
void __fastcall Tsolar2DForm::applyDisplayMetrics()
{
int scW, scH;
int frW, frH;
int scX, scY;
int adjustedX = disp->screenOriginX;
int adjustedY = disp->screenOriginY;
//Change the device view
if (!disp->deviceImage->IsEmpty())
{
//Set orientation
if (screenOrientation == 0 || screenOrientation == 180)//Is it in Landscape more?
{
//X is good, Y needs to adjust
if (screenOrientation == 0)
adjustedY = disp->deviceImage->Height - (disp->screenHeight + adjustedY);
//Y is good, X needs to adjust
if (screenOrientation == 180)
{
adjustedX = disp->deviceImage->Width - (disp->screenWidth + adjustedX);
}
scW = disp->screenWidth;
scH = disp->screenHeight;
scX = adjustedX;
scY = adjustedY;
frH = disp->deviceImage->Height;
frW = disp->deviceImage->Width;
}
else
{
//Defualt fit is 90 degrees. Do nothing
//X & Y needs to adjust
if (screenOrientation == 270)
{
adjustedX = disp->deviceImage->Width - (disp->screenWidth + adjustedX);
adjustedY = disp->deviceImage->Height - (disp->screenHeight + adjustedY);
}
//Set to Landscape mode
scH = disp->screenWidth;
scW = disp->screenHeight;
scY = adjustedX;
scX = adjustedY;
frW = disp->deviceImage->Height;
frH = disp->deviceImage->Width;
}
}
else
{
//Set orientation
if (screenOrientation == 0 || screenOrientation == 180)//Is it in Landscape more?
{
scW = disp->screenWidth;
scH = disp->screenHeight;
scX = adjustedX;
scY = adjustedY;
frH = disp->screenHeight;
frW = disp->screenWidth;
}
else
{
//Set to Landscape mode
scH = disp->screenWidth;
scW = disp->screenHeight;
scY = adjustedX;
scX = adjustedY;
frH = disp->screenWidth;
frW = disp->screenHeight;
}
}
//Screen and positioing
deviceScreen->Position->X = scX;
deviceScreen->Position->Y = scY;
deviceScreen->Width = scW;
deviceScreen->Height = scH;
//Device frame
deviceFrame->Height = frH;
deviceFrame->Width = frW;
}
void __fastcall Tsolar2DForm::deviceScreenPainting(TObject *Sender, TCanvas *Canvas, const TRectF &ARect)
{
//If there is a border Overlay (Dressing). add over all objects
if (!disp->screenDressing->IsEmpty())
{
//Display the overlaydressing
Canvas->DrawBitmap(disp->screenDressing, disp->screenDressing->Bounds, ARect, 1.0, false);
}
if (!disp->screenDressing->IsEmpty())
{
//Display the overlaydressing
Canvas->DrawBitmap(disp->screenDressing, disp->screenDressing->Bounds, ARect, 1.0, false);
}
}
void __fastcall Tsolar2DForm::deviceScreenResize(TObject *Sender)
{
//change scale
deviceFrame->Scale->X = ScaleTrack->Value;
deviceFrame->Scale->Y = ScaleTrack->Value;
TextScale->Text = IntToStr((int)(ScaleTrack->Value*100))+"%";
}
void __fastcall Tsolar2DForm::deviceScreenMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, float X, float Y)
{
if (isAnimating)
return;
adjustHandles(false, NULL);
//Make sure the current object's cursor gets a reset aslo
if (selectionRect->TagObject)
{
((TControl *)selectionRect->TagObject)->Cursor = crDefault;
}
//Clear animation list
animListBox->Clear();
//Clear allthe object inspector data
clearAnimationInspector();
//
selectionRect->TagObject = NULL;
setHandleColors(NULL);
updateInspector();
//Clear all selections in 'selectionsList'
clearObjectSelections();
clearAllCursors(deviceScreen);
//Pass the click on to the parent
deviceFrameMouseDown(NULL, Button, Shift, X + deviceScreen->Position->X, Y + deviceScreen->Position->Y);
}