forked from JBontes/Life32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit2.pas
1278 lines (1054 loc) · 29.8 KB
/
Unit2.pas
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
unit Unit2;
(* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. *)
interface
uses
Windows, ComObj, ActiveX, Comctrls, Life32_TLB,
unit1, LifeBox, LifeGen, snapshot, StdVcl;
type
TLifeApplication = class;
TLifeWindow = class;
TLifeUniverse = class;
TLifeSelection = class;
TLifeToolbar = class;
TLifeStatusbar = class;
TLifeWindows = class;
TLifeScrapbook = class;
TLifeScraplet = class;
TLifeSnapshots = class;
TLifeSidepanel = class;
TLifeSnapshot = class;
TLifeSelection = class(TAutoObject, ILifeSelection)
private
FMyRect: TRect;
FLifeBox: TLifeBox;
procedure Init(ALifeBox: TLifeBox); virtual;
property MyRect: TRect read FMyRect write FMyRect;
protected
function Get_Bottom: Integer; safecall;
function Get_Left: Integer; safecall;
function Get_Top: Integer; safecall;
function Get_Right: Integer; safecall;
procedure Clear; safecall;
procedure Copy; safecall;
procedure Cut; safecall;
procedure DrawBox; safecall;
procedure FillBlack; safecall;
procedure FillRandom; safecall;
procedure Invert; safecall;
procedure Paste; safecall;
procedure Set_Bottom(Value: Integer); safecall;
procedure Set_Left(Value: Integer); safecall;
procedure Set_Top(Value: Integer); safecall;
procedure Set_Right(Value: Integer); safecall;
function Get_CellCount: Integer; safecall;
function Get_AsText: WideString; safecall;
procedure MoveBy(dx, dy: Integer); safecall;
procedure Set_AsText(const Value: WideString); safecall;
procedure ClearOutsideSelection; safecall;
procedure MirrorHorz; safecall;
procedure MirrorVert; safecall;
procedure Rotate180; safecall;
procedure Rotate270; safecall;
procedure Rotate90; safecall;
function Get_Universe: LifeUniverse; safecall;
end;
TLifeApplication = class(TAutoObject, ILifeApplication)
private
MainForm: TLife32MainForm;
MyLifeBox: TLifeWindow;
FToolbar: TLifeToolbar;
FStatusbar: TLifeStatusbar;
FSidepanel: TLifeSidepanel;
protected
function Get_ActiveWindow: LifeWindow; safecall;
procedure Close; safecall;
procedure Pause; safecall;
procedure Play(step: Integer); safecall;
procedure RegisterKeyHandler(const Name: WideString); safecall;
procedure UnregisterKeyhandler(const Name: WideString); safecall;
procedure SkipTo(Generation: Integer); safecall;
function Get_PlaySpeed: Integer; safecall;
procedure Set_PlaySpeed(Value: Integer); safecall;
function Get_ShowScrollbar: WordBool; safecall;
function Get_Statusbar: LifeStatusbar; safecall;
function Get_Toolbar: LifeToolbar; safecall;
procedure Set_ShowScrollbar(Value: WordBool); safecall;
function Get_CursorMode: eCursorMode; safecall;
function Get_PasteMode: ePasteMode; safecall;
procedure Set_CursorMode(Value: eCursorMode); safecall;
procedure Set_PasteMode(Value: ePasteMode); safecall;
function Get_DirectXEnabled: WordBool; safecall;
procedure Set_DirectXEnabled(Value: WordBool); safecall;
function Get_Speed: Integer; safecall;
procedure Set_Speed(Value: Integer); safecall;
function Get_WindowState: eWindowState; safecall;
procedure Set_WindowState(Value: eWindowState); safecall;
procedure SetFocus; safecall;
procedure MessageBox(const Message: WideString); safecall;
function Ask(const Message: WideString): WideString; safecall;
function Get_Zoom: Integer; safecall;
procedure Set_Zoom(Value: Integer); safecall;
function Get_Sidepanel: LifeSidepanel; safecall;
function Get_FrameDropInterval: Integer; safecall;
procedure Set_FrameDropInterval(Value: Integer); safecall;
function Get_Colors: LifeColors; safecall;
function Get_Windows: LifeWindows; safecall;
function Get_Scrapbook: LifeScrapbook; safecall;
procedure Set_Scrapbook(const Value: LifeScrapbook); safecall;
public
destructor Destroy; override;
procedure Initialize; override;
property ActiveWindow: LifeWindow read Get_ActiveWindow;
end;
TLifeWindow = class(TAutoObject, ILifeWindow)
private
FLifeBox: TLifeBox;
FUniverse: TLifeUniverse;
FApplication: TLifeApplication;
MainForm: TLife32MainForm;
FSelection: TLifeSelection;
procedure Init(ALifeBox: TLifeBox; MyApp: TLifeApplication); virtual;
protected
function Get_Application: LifeApplication; safecall;
function Get_Height: Integer; safecall;
function Get_Selection: LifeSelection; safecall;
function Get_Universe: LifeUniverse; safecall;
function Get_Width: Integer; safecall;
procedure CenterOnPattern; safecall;
procedure MoveBy(dx, dy: Integer); safecall;
procedure MoveTo(x, y: Integer); safecall;
procedure RandomDot; safecall;
procedure SelectAll; safecall;
procedure ZoomToFit; safecall;
procedure ZoomToSelection; safecall;
procedure Redraw; safecall;
function Get_ShowGrid: WordBool; safecall;
procedure Set_ShowGrid(Value: WordBool); safecall;
function Get_Zoom: Integer; safecall;
procedure Set_Zoom(Value: Integer); safecall;
function Get_Caption: WideString; safecall;
procedure Set_Caption(const Value: WideString); safecall;
function MakeSnapshot: LifeSnapshots; safecall;
function Get_Snapshots: LifeSnapshots; safecall;
procedure Set_Snapshots(const Value: LifeSnapshots); safecall;
public
destructor Destroy; override;
end;
TLifeUniverse = class(TAutoObject, ILifeUniverse)
private
FUniverse: TUniverse;
FIsClone: boolean;
procedure Init(AUniverse: TUniverse); virtual;
protected
function Get_Generation: Integer; safecall;
function Get_Rules: WideString; safecall;
procedure Set_Rules(const Value: WideString); safecall;
procedure SaveToFile(const AFile: WideString); safecall;
procedure LoadFromFile(const AFile: WideString); safecall;
function CellState(x, y: Integer): WordBool; safecall;
procedure ChangeCell(x, y: Integer; State: WordBool); safecall;
function Get_CellCount: Integer; safecall;
function Get_Height: Integer; safecall;
function Get_Width: Integer; safecall;
function Clone: LifeUniverse; safecall;
procedure DrawLine(x1, y1, x2, y2: Integer; Fill: WordBool); safecall;
function Get_Description: WideString; safecall;
procedure Set_Description(const Value: WideString); safecall;
function Get_Rule: WideString; safecall;
procedure Set_Rule(const Value: WideString); safecall;
public
property Generation: Integer read Get_Generation;
property Rules: WideString read Get_Rules write Set_Rules;
property IsClone: boolean read FIsClone;
destructor Destroy; override;
end;
TLifeToolbar = class(TAutoObject, ILifeToolbar)
private
MainForm: TLife32MainForm;
procedure Init(AMainForm: TLife32MainForm);
protected
function Get_Visible: WordBool; safecall;
procedure Set_Visible(Value: WordBool); safecall;
end;
TLifeStatusbar = class(TAutoObject, ILifeStatusbar)
private
MainForm: TLife32MainForm;
procedure Init(AMainForm: TLife32MainForm);
protected
function Get_Visible: WordBool; safecall;
procedure Set_Visible(Value: WordBool); safecall;
end;
{$HINTS OFF}
TLifeWindows = class(TAutoObject, ILifeWindows)
private
MainForm: TLife32MainForm;
procedure Init(AMainForm: TLife32MainForm);
protected
function Get_Count: Integer; safecall;
function Get_Item(index: Integer): LifeWindow; safecall;
function New: LifeWindow; safecall;
function Next: LifeWindow; safecall;
function Previous: LifeWindow; safecall;
procedure Delete(index: Integer); safecall;
procedure Set_Item(index: Integer; const Value: LifeWindow); safecall;
end;
TLifeScrapbook = class(TAutoObject, ILifeScrapbook)
private
Scrapbook: TListView;
procedure Init(AScrapbook: TListView);
protected
function Get_Count: Integer; safecall;
function Get_Item(index: Integer): LifeScraplet; safecall;
function Insert(const Universe: LifeUniverse): LifeScraplet; safecall;
function Next: LifeScraplet; safecall;
function Previous: LifeScraplet; safecall;
procedure Delete(index: Integer); safecall;
procedure Set_Count(Value: Integer); safecall;
procedure Set_Item(index: Integer; const Value: LifeScraplet); safecall;
end;
TLifeScraplet = class(TAutoObject, ILifeScraplet)
private
ListItem: TListItem;
procedure Init(AListItem: TListItem);
protected
function Get_Caption: WideString; safecall;
function Get_ShortcutKey: WideString; safecall;
function Get_Universe: LifeUniverse; safecall;
procedure Set_Caption(const Value: WideString); safecall;
procedure Set_ShortcutKey(const Value: WideString); safecall;
procedure Set_Universe(const Value: LifeUniverse); safecall;
end;
{$HINTS ON}
TLifeSnapshots = class(TAutoObject, ILifeSnapshots)
private
SnapshotList: TSnapshotList;
procedure Init(ASnapshotList: TSnapshotList);
protected
function Get_Count: Integer; safecall;
function Get_Item(index: Integer): LifeSnapshot; safecall;
function Get_Window: LifeWindow; safecall;
procedure Delete(index: Integer); safecall;
procedure MakeSnapshot(Cause: Integer); safecall;
procedure RevertToSnapshot(index: Integer); safecall;
procedure SortBy(SortKey: Integer; Ascending: WordBool); safecall;
end;
TLifeSidepanel = class(TAutoObject, ILifeSidepanel)
private
MainForm: TLife32MainForm;
procedure Init(AMainForm: TLife32MainForm);
protected
function Get_PageIndex: Integer; safecall;
function Get_Visible: WordBool; safecall;
function Get_Width: Integer; safecall;
procedure Set_PageIndex(Value: Integer); safecall;
procedure Set_Visible(Value: WordBool); safecall;
procedure Set_Width(Value: Integer); safecall;
end;
{$HINTS OFF}
TLifeSnapshot = class(TAutoObject, ILifeSnapshot)
private
ListItem: TListItem;
procedure Init(AListItem: TListItem);
protected
function Get_Cause: Integer; safecall;
function Get_Filename: Integer; safecall;
function Get_Generation: Integer; safecall;
function Get_PatternNumber: Integer; safecall;
function Get_RevisionNumber: Integer; safecall;
procedure Set_Cause(Value: Integer); safecall;
procedure Set_Filename(Value: Integer); safecall;
procedure Set_Generation(Value: Integer); safecall;
procedure Set_PatternNumber(Value: Integer); safecall;
procedure Set_RevisionNumber(Value: Integer); safecall;
end;
{$HINTS ON}
implementation
uses
Classes, ComServ, SysUtils, Forms, Dialogs, LifeConst, LifeCel, Menus;
procedure TLifeApplication.Initialize;
begin
//MessageBox(0,PChar(IntToStr(ComServer.ObjectCount)),'ObjectCount',0);
inherited Initialize;
MainForm:= Application.MainForm as TLife32MainForm;
end;
destructor TLifeApplication.Destroy;
begin
MyLifeBox.Free;
inherited Destroy;
end;
function TLifeApplication.Get_ActiveWindow: LifeWindow;
begin
if MyLifeBox = nil then begin
MyLifeBox:= TLifeWindow.Create;
MyLifeBox.Init(MainForm.LifeBox1, Self);
end; {if}
Result:= MyLifeBox as ILifeWindow;
Result._AddRef;
end;
function TLifeApplication.Get_Statusbar: LifeStatusbar;
begin
if FStatusbar = nil then begin
FStatusbar:= TLifeStatusbar.Create;
FStatusbar.Init(MainForm);
end; {if}
Result:= FStatusbar as ILifeStatusBar;
Result._AddRef;
end;
function TLifeApplication.Get_Toolbar: LifeToolbar;
begin
if FToolbar = nil then begin
FToolbar:= TLifeToolbar.Create;
FToolbar.Init(MainForm);
end; {if}
Result:= FToolbar as ILifeToolBar;
Result._AddRef;
end;
function TLifeApplication.Get_ShowScrollbar: WordBool;
begin
Result:= not(MainForm.HideScrollbars);
end;
procedure TLifeApplication.Set_ShowScrollbar(Value: WordBool);
begin
MainForm.HideScrollbars:= not(value);
end;
function TLifeApplication.Get_PlaySpeed: Integer;
begin
Result:= MainForm.PlaySpeed;
end;
procedure TLifeApplication.Set_PlaySpeed(Value: Integer);
begin
MainForm.PlaySpeed:= Value;
end;
procedure TLifeApplication.Play(step: Integer);
var
TargetGen: integer;
begin
if MainForm = nil then begin
MainForm:= Application.MainForm as TLife32MainForm;
end;
if step = 0 then MainForm.PlayButton.Click
else begin
TargetGen:= MainForm.Generation + step;
MainForm.Generation:= TargetGen;
end; {else}
end;
procedure TLifeApplication.SkipTo(Generation: Integer);
begin
MainForm.ShowGenerations:= true;
MainForm.Generation:= Generation;
end;
procedure TLifeApplication.Pause;
begin
if MainForm = nil then begin
MainForm:= Application.MainForm as TLife32MainForm;
end;
MainForm.PauseButton.Click;
end;
procedure TLifeApplication.Close;
begin
Pause;
Free;
MainForm.Close;
end;
procedure TLifeApplication.RegisterKeyHandler(const Name: WideString);
begin
end;
procedure TLifeApplication.UnregisterKeyhandler(const Name: WideString);
begin
end;
procedure TLifeWindow.init(ALifeBox: TLifeBox; MyApp: TLifeApplication);
begin
FLifeBox:= ALifeBox;
FApplication:= MyApp;
MainForm:= (MyApp.MainForm as TLife32MainForm);
end;
destructor TLifeWindow.Destroy;
begin
FSelection.Free;
FUniverse.Free;
inherited Destroy;
end;
function TLifeWindow.Get_Application: LifeApplication;
begin
Result:= FApplication as ILifeApplication;
Result._AddRef;
end;
function TLifeWindow.Get_Universe: LifeUniverse;
begin
if not(Assigned(FUniverse)) then begin
FUniverse:= TLifeUniverse.Create;
FUniverse.Init(FLifeBox.Universe);
end; {if}
Result:= FUniverse as ILifeUniverse;
FUniverse._AddRef;
end;
function TLifeWindow.Get_Selection: LifeSelection;
begin
if FSelection = nil then begin
FSelection:= TLifeSelection.Create;
FSelection.Init(FLifeBox);
end; {if}
Result:= FSelection as ILifeSelection;
Result._AddRef;
end;
function TLifeWindow.Get_ShowGrid: WordBool;
begin
Result:= FLifeBox.Grid;
end;
procedure TLifeWindow.Set_ShowGrid(Value: WordBool);
begin
FLifeBox.Grid:= Value;
end;
function TLifeWindow.Get_Height: Integer;
begin
Result:= FLifeBox.CelsDown;
end;
function TLifeWindow.Get_Width: Integer;
begin
Result:= FLifeBox.CelsAcross;
end;
procedure TLifeWindow.ZoomToFit;
begin
FLifeBox.ZoomToFit(true,10);
end;
procedure TLifeWindow.CenterOnPattern;
begin
FLifeBox.CenterOnPattern(true);
end;
procedure TLifeWindow.MoveBy(dx, dy: Integer);
begin
FLifeBox.MoveBy(dx,dy);
end;
procedure TLifeWindow.MoveTo(x, y: Integer);
begin
FLifeBox.MoveTo(x,y);
end;
procedure TLifeWindow.SelectAll;
begin
FLifeBox.SelectAll(true);
if not Assigned(FSelection) then Get_Selection;
FSelection.MyRect:= FlifeBox.SelectionRect;
end;
procedure TLifeWindow.ZoomToSelection;
begin
FLifeBox.ZoomToSelection(MaxZoom);
end;
procedure TLifeWindow.RandomDot;
begin
FLifeBox.RandomDot;
end;
procedure TLifeWindow.Redraw;
begin
FLifeBox.RedrawAll;
end;
procedure TLifeUniverse.Init(AUniverse: TUniverse);
begin
FUniverse:= AUniverse;
end;
destructor TLifeUniverse.Destroy;
begin
if IsClone then FUniverse.Free;
inherited Destroy;
end;
function TLifeUniverse.Get_Generation: Integer;
begin
Result:= FUniverse.Counter;
end;
function TLifeUniverse.Get_Rules: WideString;
begin
Result:= FUniverse.RuleString;
end;
procedure TLifeUniverse.Set_Rules(const Value: WideString);
begin
FUniverse.RuleString:= value;
end;
function TLifeUniverse.Get_CellCount: Integer;
begin
Result:= FUniverse.CountCelsNow;
end;
function TLifeUniverse.Get_Height: Integer;
var
BoundingBox: TRect;
begin
BoundingBox:= FUniverse.GetBoundingBox;
Result:= BoundingBox.Bottom - BoundingBox.Top;
end;
function TLifeUniverse.Get_Width: Integer;
var
BoundingBox: TRect;
begin
BoundingBox:= FUniverse.GetBoundingBox;
Result:= BoundingBox.Right - BoundingBox.Left;
end;
procedure TLifeUniverse.SaveToFile(const AFile: WideString);
begin
FUniverse.SaveToFile(AFile,1,false);
end;
procedure TLifeUniverse.LoadFromFile(const AFile: WideString);
begin
FUniverse.LoadFromFile(AFile);
end;
function TLifeUniverse.CellState(x, y: Integer): WordBool;
begin
Result:= FUniverse.CelState(x,y)
end;
procedure TLifeUniverse.ChangeCell(x, y: Integer; State: WordBool);
begin
FUniverse.ChangeCel(x,y,State);
end;
procedure TLifeUniverse.DrawLine(x1, y1, x2, y2: Integer; Fill: WordBool);
begin
if Fill then FUniverse.DrawLine(x1,y1,x2,y2,lds_on)
else FUniverse.DrawLine(x1,y1,x2,y2,lds_off);
end;
function TLifeUniverse.Clone: LifeUniverse;
var
AUniverse: TLifeUniverse;
begin
AUniverse:= TLifeUniverse.Create;
try
AUniverse.Init(FUniverse.Clone);
AUniverse.FIsClone:= true;
Result:= AUniverse as ILifeUniverse;
Result._AddRef;
except
Result:= nil;
end;
end;
procedure TLifeSelection.Init(ALifeBox: TLifeBox);
begin
FLifeBox:= ALifeBox;
end;
function TLifeSelection.Get_Left: Integer;
begin
Result:= FMyRect.Left;
end;
function TLifeSelection.Get_Top: Integer;
begin
Result:= FMyRect.Top;
end;
function TLifeSelection.Get_Right: Integer;
begin
Result:= FMyRect.Right;
end;
function TLifeSelection.Get_Bottom: Integer;
begin
Result:= FMyRect.Bottom;
end;
procedure TLifeSelection.Set_Left(Value: Integer);
begin
FMyRect.Left:= Value;
FLifeBox.SelectionRect:= MyRect;
end;
procedure TLifeSelection.Set_Top(Value: Integer);
begin
FMyRect.Top:= Value;
FLifeBox.SelectionRect:= MyRect;
end;
procedure TLifeSelection.Set_Right(Value: Integer);
begin
FMyRect.Right:= value;
FLifeBox.SelectionRect:= MyRect;
end;
procedure TLifeSelection.Set_Bottom(Value: Integer);
begin
FMyRect.Bottom:= value;
FLifeBox.SelectionRect:= MyRect;
end;
function TLifeSelection.Get_CellCount: Integer;
var
TempCutOut: TUniverse;
begin
TempCutOut:= FLifeBox.Universe.CopyRect(MyRect,cNoClipboard);
Result:= TempCutOut.CountCelsNow;
TempCutOut.Free;
end;
function TLifeSelection.Get_AsText: WideString;
var
CutOut: TUniverse;
TempStringList: TStringlist;
begin
Result:= '#c !error occurred';
CutOut:= FLifeBox.Universe.CopyRect(MyRect,cNoClipBoard);
CutOut.ResetBoundingBox;
try
TempStringList:= CutOut.SaveToStringList(smDefault,false);
finally
CutOut.Free;
end; {try}
try
Result:= TempStringList.Text;
finally
TempStringList.Free;
end; {try} (**)
end;
procedure TLifeSelection.Set_AsText(const Value: WideString);
var
TempStringList: TStringlist;
CutOut: TUniverse;
begin
TempStringList:= TStringList.Create;
try
TempStringList.Text:= Value;
CutOut:= TUniverse.Create('',nbDefault); //Rules don't matter
try
CutOut.LoadFromStringList(TempStringList);
//start inserting at top-left of selection and ignore offset in Text.
CutOut.ResetBoundingBox;
FLifeBox.InsertShape(CutOut);
finally
CutOut.Free;
end;
finally
TempStringList.Free;
end;
end;
procedure TLifeSelection.Clear;
begin
FLifeBox.ClearSelection;
end;
procedure TLifeSelection.Copy;
begin
FLifeBox.CopySelection;
end;
procedure TLifeSelection.Cut;
begin
FLifeBox.CutSelection;
end;
procedure TLifeSelection.DrawBox;
begin
FLifeBox.DrawBox;
end;
procedure TLifeSelection.FillBlack;
begin
FLifeBox.FillBlack;
end;
procedure TLifeSelection.FillRandom;
begin
FLifeBox.FillRandom;
end;
procedure TLifeSelection.Invert;
begin
FLifeBox.InvertSelection;
end;
procedure TLifeSelection.Paste;
begin
FLifeBox.PasteSelection
end;
procedure TLifeSelection.MoveBy(dx, dy: Integer);
var
CutOut: TUniverse;
begin
CutOut:= FLifeBox.Universe.CutRect(MyRect,cNoClipboard);
try
OffsetRect(FMyRect,dx,dy);
FLifeBox.SelectionRect:= MyRect;
FLifeBox.InsertShape(CutOut);
finally
CutOut.Free;
end;
end;
procedure TLifeSelection.ClearOutsideSelection;
begin
FLifeBox.ClearOutsideSelection;
end;
procedure TLifeSelection.MirrorHorz;
begin
FLifeBox.MirrorSelHorz;
end;
procedure TLifeSelection.MirrorVert;
begin
FLifeBox.MirrorSelVert;
end;
procedure TLifeSelection.Rotate180;
begin
FLifeBox.RotateSel180;
end;
procedure TLifeSelection.Rotate270;
begin
FLifeBox.RotateSel270;
end;
procedure TLifeSelection.Rotate90;
begin
FLifeBox.RotateSel90;
end;
procedure TLifeToolbar.Init(AMainForm: TLife32MainForm);
begin
MainForm:= AMainForm;
end;
function TLifeToolbar.Get_Visible: WordBool;
begin
Result:= not(MainForm.HideScrollbars);
end;
procedure TLifeToolbar.Set_Visible(Value: WordBool);
begin
MainForm.HideScrollbars:= not(value);
end;
procedure TLifeStatusbar.Init(AMainForm: TLife32MainForm);
begin
MainForm:= AMainForm;
end;
function TLifeStatusbar.Get_Visible: WordBool;
begin
Result:= MainForm.Statusbar.Visible;
end;
procedure TLifeStatusbar.Set_Visible(Value: WordBool);
begin
MainForm.Statusbar.Visible:= value;
end;
function TLifeUniverse.Get_Description: WideString;
begin
Result:= FUniverse.Description.Text;
end;
procedure TLifeUniverse.Set_Description(const Value: WideString);
begin
FUniverse.Description.Text:= Value;
end;
function TLifeApplication.Get_CursorMode: eCursorMode;
begin
Result:= MainForm.LifeBox1.EditorMode;
end;
function TLifeApplication.Get_PasteMode: ePasteMode;
begin
Result:= MainForm.LifeBox1.PasteMode;
end;
procedure TLifeApplication.Set_CursorMode(Value: eCursorMode);
begin
MainForm.LifeBox1.EditorMode:= value;
end;
procedure TLifeApplication.Set_PasteMode(Value: ePasteMode);
begin
MainForm.LifeBox1.PasteMode:= value;
end;
function TLifeApplication.Get_DirectXEnabled: WordBool;
begin
Result:= (DDFast and LifeCel.MyDDSurface.DirectDrawEnabled) = DDFast;
end;
procedure TLifeApplication.Set_DirectXEnabled(Value: WordBool);
begin
MyDDSurface.DirectDrawEnabled:= MyDDSurface.DirectDrawEnabled or DDfast;
end;
function TLifeApplication.Get_Speed: Integer;
begin
Result:= MainForm.PlaySpeed;
end;
procedure TLifeApplication.Set_Speed(Value: Integer);
begin
MainForm.PlaySpeed:= value;
end;
function TLifeWindow.Get_Zoom: Integer;
begin
Result:= Self.FLifeBox.PixelsPerCel;
end;
procedure TLifeWindow.Set_Zoom(Value: Integer);
begin
FLifeBox.PixelsPerCel:= value;
end;
function TLifeApplication.Get_WindowState: eWindowState;
begin
case MainForm.WindowState of
wsMaximized: result:= ewsMaximized;
wsMinimized: result:= ewsMinimized;
wsNormal: result:= ewsNormal;
end; {case}
end;
procedure TLifeApplication.Set_WindowState(Value: eWindowState);
begin
case Value of
ewsMaximized: MainForm.WindowState:= wsMaximized;
ewsMinimized: MainForm.WindowState:= wsMinimized;
ewsNormal: MainForm.WindowState:= wsNormal;
end; {case}
end;
procedure TLifeApplication.SetFocus;
begin
Self.MainForm.SetFocus;
end;
procedure TLifeApplication.MessageBox(const Message: WideString);
begin
ShowMessage(message);
end;
function TLifeApplication.Ask(const Message: WideString): WideString;
begin
Result:= Self.MainForm.Ask(Message);
end;
function TLifeApplication.Get_Zoom: Integer;
begin
Result:= MainForm.LifeBox1.PixelsPerCel;
end;
procedure TLifeApplication.Set_Zoom(Value: Integer);
begin
MainForm.LifeBox1.PixelsPerCel:= value;
end;
function TLifeWindow.Get_Caption: WideString;
begin
Result:= MainForm.Caption;
end;
procedure TLifeWindow.Set_Caption(const Value: WideString);
begin
MainForm.Caption:= Value;
end;
function TLifeSelection.Get_Universe: LifeUniverse;
var
Temp: TLifeUniverse;
begin
Temp:= TLifeUniverse.Create;
Temp.Init(FLifeBox.GetCutOut);
Result:= Temp as ILifeUniverse;
if Assigned(Result) then Result._AddRef;
end;
function TLifeWindow.MakeSnapshot: LifeSnapshots;
var
Temp: TLifeSnapshots;
begin
Temp:= TLifeSnapShots.Create;
Temp.Init(FApplication.MainForm.RewindList1);
FApplication.MainForm.MakeSnapshot1.Click;
Result:= Temp as ILifeSnapshots;
if Assigned(Result) then Result._AddRef;
end;
function TLifeApplication.Get_Sidepanel: LifeSidepanel;
begin
if FSidepanel = nil then begin
FSidepanel:= TLifeSidepanel.Create;
FSidepanel.Init(MainForm);
end;
Result:= FSidepanel as ILifeSidepanel;
Result._AddRef;
end;
function TLifeWindow.Get_Snapshots: LifeSnapshots;
begin
end;
procedure TLifeWindow.Set_Snapshots(const Value: LifeSnapshots);
begin
end;
procedure TLifeWindows.Init(AMainForm: TLife32MainForm);
begin
MainForm:= AMainForm;
end;
function TLifeWindows.Get_Count: Integer;
begin
Result:= MainForm.UniverseTabset.Tabs.Count;
end;
function TLifeWindows.Get_Item(index: Integer): LifeWindow;
begin
end;
function TLifeWindows.New: LifeWindow;
begin
MainForm.Newsheet1Click(MainForm);
end;
function TLifeWindows.Next: LifeWindow;
begin
with MainForm do begin
if (UniverseTabset.TabIndex < UniverseTabset.Tabs.Count -1) then
UniverseTabset.SelectNext(true);
end; {with}
end;
function TLifeWindows.Previous: LifeWindow;
begin
with MainForm do begin
if (UniverseTabset.TabIndex > 0) then
UniverseTabset.SelectNext(false);
end; {with}
end;
procedure TLifeWindows.Delete(index: Integer);
begin
end;
procedure TLifeWindows.Set_Item(index: Integer; const Value: LifeWindow);
begin
end;