This repository was archived by the owner on Jan 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVbDraw.frm
More file actions
1443 lines (1267 loc) · 41.1 KB
/
VbDraw.frm
File metadata and controls
1443 lines (1267 loc) · 41.1 KB
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
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmVbDraw
BorderStyle = 1 'Fixed Single
Caption = "VbDraw []"
ClientHeight = 6585
ClientLeft = 150
ClientTop = 720
ClientWidth = 9375
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6585
ScaleWidth = 9375
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox picHidden
AutoRedraw = -1 'True
BackColor = &H00FFFFFF&
Height = 615
Left = 3840
ScaleHeight = 555
ScaleWidth = 555
TabIndex = 10
Top = 120
Visible = 0 'False
Width = 615
End
Begin MSComctlLib.ImageList imlFillStyles
Left = 1920
Top = 2520
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 48
ImageHeight = 16
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 8
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":0000
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":0212
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":0424
Key = ""
EndProperty
BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":0636
Key = ""
EndProperty
BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":0848
Key = ""
EndProperty
BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":0A5A
Key = ""
EndProperty
BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":0C6C
Key = ""
EndProperty
BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":0E7E
Key = ""
EndProperty
EndProperty
End
Begin MSComctlLib.ImageList imlDrawStyles
Left = 1200
Top = 2520
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 48
ImageHeight = 16
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 6
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":1090
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":12A2
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":14B4
Key = ""
EndProperty
BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":16C6
Key = ""
EndProperty
BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":18D8
Key = ""
EndProperty
BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":1AEA
Key = ""
EndProperty
EndProperty
End
Begin VB.PictureBox picColorToolbar
Align = 2 'Align Bottom
Height = 855
Left = 0
ScaleHeight = 795
ScaleWidth = 9315
TabIndex = 2
Top = 5730
Width = 9375
Begin MSComctlLib.ImageCombo icbDrawStyle
Height = 330
Left = 1920
TabIndex = 7
Top = 0
Width = 1095
_ExtentX = 1931
_ExtentY = 582
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
ImageList = "imlDrawStyles"
End
Begin VB.PictureBox picBackColorSample
Height = 255
Index = 0
Left = 840
ScaleHeight = 195
ScaleWidth = 195
TabIndex = 6
Top = 240
Width = 255
End
Begin VB.PictureBox picForeColorSample
Height = 255
Index = 0
Left = 840
ScaleHeight = 195
ScaleWidth = 195
TabIndex = 5
Top = 0
Width = 255
End
Begin VB.PictureBox picBackColor
AutoRedraw = -1 'True
Height = 255
Left = 120
ScaleHeight = 195
ScaleWidth = 435
TabIndex = 4
Top = 360
Width = 495
End
Begin VB.PictureBox picForeColor
AutoRedraw = -1 'True
Height = 255
Left = 120
ScaleHeight = 195
ScaleWidth = 435
TabIndex = 3
Top = 120
Width = 495
End
Begin MSComctlLib.ImageCombo icbFillStyle
Height = 330
Left = 1920
TabIndex = 8
Top = 360
Width = 1095
_ExtentX = 1931
_ExtentY = 582
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
ImageList = "imlFillStyles"
End
Begin MSComctlLib.ImageCombo icbDrawWidth
Height = 330
Left = 3120
TabIndex = 9
Top = 0
Width = 1095
_ExtentX = 1931
_ExtentY = 582
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
ImageList = "imlDrawWidths"
End
End
Begin VB.PictureBox picCanvas
BackColor = &H00FFFFFF&
Height = 2415
Left = 480
ScaleHeight = 2355
ScaleWidth = 3075
TabIndex = 1
Top = 0
Width = 3135
End
Begin MSComDlg.CommonDialog dlgFile
Left = 3840
Top = 1320
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin MSComctlLib.Toolbar tbrTools
Align = 3 'Align Left
Height = 5730
Left = 0
TabIndex = 0
Top = 0
Width = 420
_ExtentX = 741
_ExtentY = 10107
ButtonWidth = 609
ButtonHeight = 582
Appearance = 1
ImageList = "imlTools"
_Version = 393216
BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628}
NumButtons = 6
BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Arrow"
Object.ToolTipText = "Select"
ImageIndex = 1
Style = 2
EndProperty
BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Line"
Object.ToolTipText = "Line"
ImageIndex = 3
Style = 2
EndProperty
BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Scribble"
Object.ToolTipText = "Scribble"
ImageIndex = 4
Style = 2
EndProperty
BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Polyline"
Object.ToolTipText = "Polyline"
ImageIndex = 5
Style = 2
EndProperty
BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Polygon"
Object.ToolTipText = "Polygon"
ImageIndex = 6
Style = 2
EndProperty
BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Rectangle"
Object.ToolTipText = "Rectangle"
ImageIndex = 7
Style = 2
EndProperty
EndProperty
End
Begin MSComctlLib.ImageList imlTools
Left = 480
Top = 2520
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 16
ImageHeight = 16
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 8
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":1CFC
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":1E0E
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":1F20
Key = ""
EndProperty
BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":2032
Key = ""
EndProperty
BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":2144
Key = ""
EndProperty
BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":2256
Key = ""
EndProperty
BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":2368
Key = ""
EndProperty
BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":247A
Key = ""
EndProperty
EndProperty
End
Begin MSComctlLib.ImageList imlDrawWidths
Left = 2640
Top = 2520
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 48
ImageHeight = 16
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 10
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":258C
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":279E
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":29B0
Key = ""
EndProperty
BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":2BC2
Key = ""
EndProperty
BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":2DD4
Key = ""
EndProperty
BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":2FE6
Key = ""
EndProperty
BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":31F8
Key = ""
EndProperty
BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":340A
Key = ""
EndProperty
BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":361C
Key = ""
EndProperty
BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "VbDraw.frx":382E
Key = ""
EndProperty
EndProperty
End
Begin VB.Menu mnuFile
Caption = "&File"
Begin VB.Menu mnuFileNew
Caption = "&New"
Shortcut = ^N
End
Begin VB.Menu mnuFileOpen
Caption = "&Open..."
Shortcut = ^O
End
Begin VB.Menu mnuFileOpenSep
Caption = "-"
End
Begin VB.Menu mnuFileSave
Caption = "&Save"
Enabled = 0 'False
Shortcut = ^S
End
Begin VB.Menu mnuFileSaveAs
Caption = "Save &As..."
Shortcut = ^A
End
Begin VB.Menu mnuFileSaveBitmapSep
Caption = "-"
End
Begin VB.Menu mnuFileSaveBitmap
Caption = "Save &Bitmap..."
Shortcut = ^B
End
Begin VB.Menu mnuFileSaveMetafile
Caption = "Save &Metafile..."
Shortcut = ^M
End
Begin VB.Menu mnuFileExitSep
Caption = "-"
End
Begin VB.Menu mnuFileExit
Caption = "E&xit"
End
Begin VB.Menu mnuFileMRU
Caption = "-"
Index = 0
Visible = 0 'False
End
End
Begin VB.Menu mnuEdit
Caption = "&Edit"
Begin VB.Menu mnuEditUndo
Caption = "&Undo"
Shortcut = ^Z
End
Begin VB.Menu mnuEditRedo
Caption = "&Redo"
Shortcut = ^Y
End
End
Begin VB.Menu mnuArrange
Caption = "&Arrange"
Begin VB.Menu mnuArrangeSendToFront
Caption = "&Bring To Front"
Enabled = 0 'False
Shortcut = ^J
End
Begin VB.Menu mnuArrangeSendToBack
Caption = "&Send To Back"
Enabled = 0 'False
Shortcut = ^K
End
End
Begin VB.Menu mnuTransform
Caption = "&Transform"
Begin VB.Menu mnuTransformClear
Caption = "&Clear Transformations"
Enabled = 0 'False
End
Begin VB.Menu mnuTransformRotate
Caption = "&Rotate..."
Enabled = 0 'False
End
Begin VB.Menu mnuTransformScale
Caption = "&Scale..."
Enabled = 0 'False
End
End
End
Attribute VB_Name = "frmVbDraw"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' The new object we are building.
Private m_NewObject As vbdObject
Private m_ToolKey As String
' The selected object.
Private m_SelectedObjects As Collection
' Undo variables.
Private Const MAX_UNDO = 50
Private m_Snapshots As Collection
Private m_CurrentSnapshot As Integer
' The scene that holds all objects.
Private m_TheScene As vbdObject
' The currently selected colors.
Private m_ForeColor As Integer
Private m_BackColor As Integer
' The name and title of the current file.
Private m_FileName As String
Private m_FileTitle As String
' MRU list file names.
Private m_MruList As Collection
' Indicates the data has changed since load/save.
Private m_DataModified As Boolean
Private Declare Function CreateMetaFile Lib "gdi32" Alias "CreateMetaFileA" (ByVal lpString As String) As Long
Private Declare Function CloseMetaFile Lib "gdi32" (ByVal hmf As Long) As Long
Private Declare Function DeleteMetaFile Lib "gdi32" (ByVal hmf As Long) As Long
Private Declare Function SetWindowExtEx Lib "gdi32" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpSize As SIZE) As Long
Private Type SIZE
cx As Long
cy As Long
End Type
' Arrange the color toolbar.
Private Sub ArrangeColorToolbar()
Dim i As Integer
Dim tf As Single
Dim tb As Single
Dim X As Single
Dim dx As Single
tf = (picColorToolbar.ScaleHeight - 2 * picForeColor.Height) / 3
tb = picForeColor.Height + 2 * tf
' Arrange the forecolor and backcolor pictures.
picForeColor.Move tf, tf
picBackColor.Move tf, tb
X = picBackColor.Width + 2 * tf
dx = picForeColorSample(0).Width + tf / 2
' Create the color samples.
For i = 0 To 15
If i > 0 Then
Load picForeColorSample(i)
Load picBackColorSample(i)
End If
picForeColorSample(i).Top = tf
picForeColorSample(i).Left = X
picForeColorSample(i).BackColor = QBColor(i)
picForeColorSample(i).Visible = True
picBackColorSample(i).Top = tb
picBackColorSample(i).Left = X
picBackColorSample(i).BackColor = QBColor(i)
picBackColorSample(i).Visible = True
X = X + dx
Next i
' Arrange the DrawStyles ImageCombo.
X = X + dx + tf
dx = icbFillStyle.Width + tf / 2
tf = (picColorToolbar.ScaleHeight - 2 * icbDrawStyle.Height) / 3
tb = icbDrawStyle.Height + 2 * tf
icbDrawStyle.Top = tf
icbDrawStyle.Left = X
Set icbDrawStyle.ImageList = imlDrawStyles
For i = 1 To 6
icbDrawStyle.ComboItems.Add i
icbDrawStyle.ComboItems(i).Image = i
Next i
' Arrange the FillStyles ImageCombo.
icbFillStyle.Top = tb
icbFillStyle.Left = X
Set icbFillStyle.ImageList = imlFillStyles
For i = 1 To 8
icbFillStyle.ComboItems.Add i
icbFillStyle.ComboItems(i).Image = i
Next i
X = X + dx
' Arrange the DrawWidth ImageCombo.
icbDrawWidth.Top = tb
icbDrawWidth.Left = X
Set icbDrawWidth.ImageList = imlDrawWidths
For i = 1 To 10
icbDrawWidth.ComboItems.Add i
icbDrawWidth.ComboItems(i).Image = i
Next i
End Sub
' Return True if it is safe to discard the
' current picture.
Private Function DataSafe() As Boolean
If Not m_DataModified Then
DataSafe = True
Else
Select Case MsgBox("The data has been modified. Do you want to save the changes?", vbYesNoCancel)
Case vbYes
mnuFileSave_Click
DataSafe = Not m_DataModified
Case vbNo
DataSafe = True
Case vbCancel
DataSafe = False
End Select
End If
End Function
' Save the picture.
Private Sub DataSave(ByVal file_name As String, ByVal file_title As String)
Dim fnum As Integer
On Error GoTo SaveError
' Open the file.
fnum = FreeFile
Open file_name For Output As fnum
' Write the scene serialization into the file.
Print #fnum, m_TheScene.Serialization
' Close the file.
Close fnum
' Update the caption.
SetFileName file_name, file_title
m_DataModified = False
Exit Sub
SaveError:
MsgBox "Error " & Format$(Err.Number) & _
" saving file " & file_name & "." & _
vbCrLf & Err.Description
Exit Sub
End Sub
' Load the picture.
Private Sub DataLoad(ByVal file_name As String, ByVal file_title As String)
Dim fnum As Integer
Dim txt As String
Dim token_name As String
Dim token_value As String
On Error GoTo LoadError
' Open the file.
fnum = FreeFile
Open file_name For Input As fnum
' Read the scene serialization from the file.
txt = Input$(LOF(fnum), fnum)
' Close the file.
Close fnum
' Initialize the scene.
GetNamedToken txt, token_name, token_value
If token_name <> "vbdScene" Then
MsgBox "Error loading file " & file_name & "." & _
vbCrLf & "This is not a VbDraw file."
Else
m_TheScene.Serialization = token_value
' Update the caption.
SetFileName file_name, file_title
m_DataModified = False
' Prepare to edit.
PrepareToEdit
End If
Exit Sub
LoadError:
MsgBox "Error " & Format$(Err.Number) & _
" loading file " & file_name & "." & _
vbCrLf & Err.Description
Exit Sub
End Sub
' Deselect this object.
Private Sub DeselectVbdObject(ByVal target As vbdObject)
Dim obj As vbdObject
Dim i As Integer
' Remove the object from the
' m_SelectedObjects collection.
i = 1
For Each obj In m_SelectedObjects
If obj Is target Then
m_SelectedObjects.Remove i
Exit For
End If
i = i + 1
Next obj
' Mark the object as not selected.
target.Selected = False
End Sub
' Deselect all objects.
Private Sub DeselectAllVbdObjects()
Dim obj As vbdObject
' Deselect all selected objects.
For Each obj In m_SelectedObjects
obj.Selected = False
Next obj
' Empty the m_SelectedObjects collection.
Set m_SelectedObjects = New Collection
End Sub
' Enable the appropriate transformation menus.
Private Sub EnableMenusForSelection()
Dim objects_selected As Boolean
objects_selected = (m_SelectedObjects.Count > 0)
mnuArrangeSendToFront.Enabled = objects_selected
mnuArrangeSendToBack.Enabled = objects_selected
mnuTransformClear.Enabled = objects_selected
mnuTransformRotate.Enabled = objects_selected
mnuTransformScale.Enabled = objects_selected
End Sub
' Select the arrow tool.
Private Sub SelectArrowTool()
' Make sure the arrow button is pressed.
tbrTools.Buttons("Arrow").Value = tbrPressed
' Prepare to deal with this tool.
SelectTool "Arrow"
End Sub
' Create an appropriate object for this tool.
Private Sub SelectTool(ByVal Key As String)
Dim new_pgon As vbdPolygon
Dim new_line As vbdLine
' Free any previously started object.
Set m_NewObject = Nothing
' Create the new object.
m_ToolKey = Key
Select Case m_ToolKey
Case "Polyline"
Set m_NewObject = New vbdPolygon
Set new_pgon = m_NewObject
new_pgon.IsClosed = False
Case "Polygon"
Set m_NewObject = New vbdPolygon
Set new_pgon = m_NewObject
new_pgon.IsClosed = True
Case "Line"
Set m_NewObject = New vbdLine
Set new_line = m_NewObject
new_line.IsBox = False
Case "Rectangle"
Set m_NewObject = New vbdLine
Set new_line = m_NewObject
new_line.IsBox = True
Case "Scribble"
Set m_NewObject = New vbdScribble
' Case "Ellipse"
' Set m_NewObject = New vbdEllipse
End Select
' Let the new object receive picCanvas events.
If Not (m_NewObject Is Nothing) Then
Set m_NewObject.Canvas = picCanvas
End If
End Sub
' Select this object.
Private Sub SelectVbdObject(ByVal target As vbdObject)
' See if it is aleady selected.
If target.Selected Then Exit Sub
' Add the object to the
' m_SelectedObjects collection.
m_SelectedObjects.Add target
' Mark the object as selected.
target.Selected = True
End Sub
' Find the object at this position.
Private Function FindObjectAt(ByVal X As Single, ByVal Y As Single) As vbdObject
Dim the_scene As vbdScene
Set the_scene = m_TheScene
Set FindObjectAt = the_scene.FindObjectAt(X, Y)
End Function
' Add this file name to the MRU list.
Private Sub MruAddName(ByVal file_name As String)
Dim i As Integer
' Remove any duplicates.
For i = m_MruList.Count To 1 Step -1
If m_MruList(i) = file_name Then
m_MruList.Remove i
End If
Next i
' Add the new name at the front.
If m_MruList.Count = 0 Then
m_MruList.Add file_name
Else
m_MruList.Add file_name, , 1
End If
' Only keep 4.
Do While m_MruList.Count > 4
m_MruList.Remove 5
Loop
' Save the MRU list in the registry.
For i = 1 To m_MruList.Count
SaveSetting App.Title, "MRU", _
Format$(i), m_MruList(i)
Next i
For i = m_MruList.Count + 1 To 4
SaveSetting App.Title, "MRU", _
Format$(i), ""
Next i
' Display the MRU list.
MruDisplay
End Sub
' Display the MRU list.
Private Sub MruDisplay()
Dim i As Integer
mnuFileMRU(0).Visible = (m_MruList.Count > 0)
For i = 1 To m_MruList.Count
If i > mnuFileMRU.UBound Then
Load mnuFileMRU(i)
End If
mnuFileMRU(i).Caption = "&" & _
Format$(i) & " " & m_MruList(i)
mnuFileMRU(i).Visible = True
Next i
End Sub
' Load the MRU list.
Private Sub MruLoad()
Dim i As Integer
Dim file_name As String
Set m_MruList = New Collection
For i = 1 To 4
file_name = GetSetting(App.Title, "MRU", _
Format$(i), "")
If Len(file_name) > 0 Then
m_MruList.Add file_name
End If
Next i
' Display the list.
MruDisplay
End Sub
' Select default values and prepare to edit.
Private Sub PrepareToEdit()
' Select default colors.
picForeColorSample_Click 0 ' Black
picbackColorSample_Click 7 ' Gray
' Save the initial snapshot.
Set m_Snapshots = New Collection
m_CurrentSnapshot = 0
SaveSnapshot
' Start at normal (pixel) scale.
picCanvas.ScaleMode = vbPixels
' Select the arrow tool.
tbrTools.Buttons("Arrow").Value = tbrPressed
' Select the solid DrawStyle.
icbDrawStyle.SelectedItem = icbDrawStyle.ComboItems(1)
' Select the solid FillStyle.
icbFillStyle.SelectedItem = icbDrawStyle.ComboItems(1)
' Select the 1 pixel DrawWidth.
icbDrawWidth.SelectedItem = icbDrawStyle.ComboItems(1)
' Redraw.
picCanvas.Refresh
End Sub
' Flag the data as modified.
Private Sub SetDirty()
If Not m_DataModified Then
Caption = App.Title & "*[" & m_FileTitle & "]"
End If
' Save the current snapshot.
SaveSnapshot
m_DataModified = True
End Sub
' Set the file's name.
Private Sub SetFileName(ByVal file_name As String, ByVal file_title As String)
' Save the file's name and title.
m_FileName = file_name
m_FileTitle = file_title
mnuFileSave.Enabled = Len(m_FileTitle) > 0
' Update the caption.
Caption = App.Title & " [" & m_FileTitle & "]"
' Add the name to the MRU list.
If Len(m_FileName) > 0 Then MruAddName m_FileName
End Sub
' Enable or disable the undo and redo menus.
Private Sub SetUndoMenus()
mnuEditUndo.Enabled = (m_CurrentSnapshot > 1)
mnuEditRedo.Enabled = (m_CurrentSnapshot < m_Snapshots.Count)
End Sub
' Save a snapshot for undo.
Private Sub SaveSnapshot()
' Remove any previously undone snapshots.
Do While m_Snapshots.Count > m_CurrentSnapshot
m_Snapshots.Remove m_Snapshots.Count
Loop
' Save the current snapshot.
m_Snapshots.Add m_TheScene.Serialization
If m_Snapshots.Count > MAX_UNDO + 1 Then
m_Snapshots.Remove 1
End If
m_CurrentSnapshot = m_Snapshots.Count
' Enable/disable the undo and redo menus.
SetUndoMenus
End Sub
' Add this object to the collection.
Public Sub AddObject(ByVal obj As vbdObject)
Dim the_scene As vbdScene
' Give the object its drawing properties.
obj.ForeColor = QBColor(m_ForeColor)
obj.FillColor = QBColor(m_BackColor)
obj.DrawStyle = icbDrawStyle.SelectedItem.Index - 1
obj.FillStyle = icbFillStyle.SelectedItem.Index - 1
obj.DrawWidth = icbDrawWidth.SelectedItem.Index
' Save the new object.
Set the_scene = m_TheScene
the_scene.SceneObjects.Add obj
Set m_NewObject = Nothing
' Select the new object only.
DeselectAllVbdObjects
SelectVbdObject obj
' See if any objects are selected.
EnableMenusForSelection
' Select the arrow tool.
SelectArrowTool
' The data has changed.
SetDirty
' Redraw.
picCanvas.Refresh
End Sub
' Cancel adding an object to the collection.
Public Sub CancelObject()
Set m_NewObject = Nothing
' Select the arrow tool.
SelectArrowTool
End Sub
' Restore the previous snapshot.
Private Sub Undo()
Dim token_name As String
Dim token_value As String
If m_CurrentSnapshot <= 1 Then Exit Sub
' Restore the previous snapshot.
m_CurrentSnapshot = m_CurrentSnapshot - 1
GetNamedToken m_Snapshots(m_CurrentSnapshot), token_name, token_value
m_TheScene.Serialization = token_value
' Display the scene.
picCanvas.Refresh
' Enable/disable the undo and redo menus.
SetUndoMenus
End Sub
' Reapply a previously undone snapshot.
Private Sub Redo()
Dim token_name As String
Dim token_value As String
If m_CurrentSnapshot >= m_Snapshots.Count Then Exit Sub
' Restore the previous snapshot.
m_CurrentSnapshot = m_CurrentSnapshot + 1
GetNamedToken m_Snapshots(m_CurrentSnapshot), token_name, token_value
m_TheScene.Serialization = token_value
' Display the scene.
picCanvas.Refresh
' Enable/disable the undo and redo menus.
SetUndoMenus
End Sub
' Process key presses.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim the_scene As vbdScene
Select Case KeyCode