-
Notifications
You must be signed in to change notification settings - Fork 7
/
vtxedit.pas
11320 lines (10135 loc) · 302 KB
/
vtxedit.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
{
BSD 2-Clause License
Copyright (c) 2017, Daniel Mecklenburg Jr. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
{
Notes:
SGR 5 BlinkSlow is iCeBlink
UTF 8 nas no characters in the 128-191 range
https://gist.github.com/NuSkooler/a235339cf383759c49c57ee30d34876c?fref=gc&dti=254577004687053
TODO :
ImportANSI needs font select code
VTX specific
row attributes
page / border / cursor attributes
transparent black in vtx mode
fonts 10-12 in VTX only
Mode Char / Block (sixels in Teletext font)
border on display / center document on window
export as bitmap, rtf, html
import xbin
}
unit VTXEdit;
{$mode objfpc}{$H+}
{$codepage utf8}
{$ASMMODE intel}
{$modeswitch advancedrecords}
interface
uses
{$ifdef WINDOWS}
Windows,
{$endif}
LCLType,
LazFileUtils,
Classes,
SysUtils,
strutils,
FileUtil,
DateTimePicker,
DividerBevel,
Forms,
Controls,
Dialogs,
ExtCtrls,
Menus,
LCL,
StdCtrls,
Buttons,
Graphics,
Spin, ComCtrls,
Math,
BGRABitmap,
BGRABitmapTypes, SynEdit,
Types,
VTXPreviewBox,
VTXConst,
VTXSupport,
VTXEncDetect,
VTXExportOptions,
VTXColorDlg,
UnicodeHelper,
RecList,
LResources,
EditBtn,
Memory,
dateutils,
Inifiles;
type
{ TfMain }
TfMain = class(TForm)
bObjFlipHorz: TToolButton;
bObjFlipVert: TToolButton;
bObjHideOutlines: TToolButton;
bObjLoad: TToolButton;
bObjMerge: TToolButton;
bObjMergeAll: TToolButton;
bObjMoveBack: TToolButton;
bObjMoveToBack: TToolButton;
bObjMoveToFront: TToolButton;
bObjSave: TToolButton;
bObnjMoveForward: TToolButton;
cbCodePage: TComboBox;
cbColorScheme: TComboBox;
cbFont1: TComboBox;
cbFont2: TComboBox;
cbFont3: TComboBox;
cbFont4: TComboBox;
cbFont5: TComboBox;
cbFont6: TComboBox;
cbFont7: TComboBox;
cbFont8: TComboBox;
cbFont9: TComboBox;
cbPageType: TComboBox;
CheckBox1: TCheckBox;
CoolBar1: TCoolBar;
dpAllPanels: TPanel;
dPanel0: TPanel;
dpcDockers0: TPageControl;
dtbAddPage: TToolButton;
dtbClosePage: TToolButton;
dtbControls: TToolBar;
dtbMinMax: TToolButton;
dtbMoveDown: TToolButton;
dtbMoveUp: TToolButton;
dtpSauceDate: TDateTimePicker;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
ilButtons: TImageList;
ilDisabledButtons: TImageList;
ilCursors: TImageList;
ilIcons11x11: TImageList;
ilIcons8x8: TImageList;
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Label2: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
Label31: TLabel;
Label32: TLabel;
lBitmapName: TLabel;
lBitmapSize: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
Label29: TLabel;
Label3: TLabel;
Label30: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
lvObjects: TListView;
memSauceComments: TMemo;
MenuItem1: TMenuItem;
miViewLoadBitmap: TMenuItem;
miViewClearBitmap: TMenuItem;
miShowHideBitmap: TMenuItem;
MenuItem2: TMenuItem;
MenuItem5: TMenuItem;
MenuItem7: TMenuItem;
MenuItem8: TMenuItem;
MenuItem9: TMenuItem;
miFileImport: TMenuItem;
miObjMergeAll: TMenuItem;
miFileSaveAs: TMenuItem;
miFileExport: TMenuItem;
miEditDelete: TMenuItem;
miObjNext: TMenuItem;
miObjPrev: TMenuItem;
miObjBackOne: TMenuItem;
miObjMerge: TMenuItem;
MenuItem11: TMenuItem;
miObjForwardOne: TMenuItem;
MenuItem3: TMenuItem;
miObjFlipHorz: TMenuItem;
MenuItem6: TMenuItem;
miObjToFront: TMenuItem;
miObjToBack: TMenuItem;
miObjFlipVert: TMenuItem;
miObjects: TMenuItem;
miEditUndo: TMenuItem;
miEditCut: TMenuItem;
miEditRedo: TMenuItem;
MenuItem4: TMenuItem;
miEditCopy: TMenuItem;
miEditPaste: TMenuItem;
odObject: TOpenDialog;
odImage: TOpenDialog;
odBitmap: TOpenDialog;
pbRowColor1: TPaintBox;
pbRowColor2: TPaintBox;
Panel1: TPanel;
miFileOpen: TMenuItem;
miFileSave: TMenuItem;
miViewPreview: TMenuItem;
miView: TMenuItem;
odAnsi: TOpenDialog;
pbChars: TPaintBox;
pbColors: TPaintBox;
pbCurrCell: TPaintBox;
pbPage: TPaintBox;
pbRulerLeft: TPaintBox;
pbRulerTop: TPaintBox;
pDockers: TPanel;
pDocument: TPanel;
pMain: TPanel;
pmDockers: TPopupMenu;
miFileExit: TMenuItem;
miFileNew: TMenuItem;
mMenu: TMainMenu;
miFile: TMenuItem;
miEdit: TMenuItem;
miHelp: TMenuItem;
pbStatusBar: TPaintBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
rbRowWidth50: TRadioButton;
rbRowWidth100: TRadioButton;
rbRowWidth150: TRadioButton;
rbRowWidth200: TRadioButton;
sbHorz: TScrollBar;
sbVert: TScrollBar;
ScrollBox1: TScrollBox;
ScrollBox2: TScrollBox;
ScrollBox3: TScrollBox;
ScrollBox4: TScrollBox;
ScrollBox5: TScrollBox;
ScrollBox6: TScrollBox;
ScrollBox7: TScrollBox;
ScrollBox8: TScrollBox;
ScrollBox9: TScrollBox;
sdObject: TSaveDialog;
sdAnsi: TSaveDialog;
irqBlink: TTimer;
seCharacter: TSpinEdit;
seCols: TSpinEdit;
seRows: TSpinEdit;
seXScale: TFloatSpinEdit;
SpeedButton1: TSpeedButton;
seRefTop: TSpinEdit;
seRefLeft: TSpinEdit;
seRefWidth: TSpinEdit;
seRefHeight: TSpinEdit;
ToolBar3: TToolBar;
bFindColor: TToolButton;
tsReferenceImage: TTabSheet;
tsRowAttr: TTabSheet;
ToolBar2: TToolBar;
bRefLoad: TToolButton;
bRefShow: TToolButton;
bRefRemove: TToolButton;
tbRefOpacity: TTrackBar;
tsFonts: TTabSheet;
tbCodePage: TEdit;
tbUnicode: TEdit;
tsCurrent: TTabSheet;
tsSAUCE: TTabSheet;
tbSauceAuthor: TEdit;
tbSauceGroup: TEdit;
tbSauceTitle: TEdit;
tbToolPalette: TToolBar;
tbAttributesPalette: TToolBar;
tbToolFill: TToolButton;
tbToolEyedropper: TToolButton;
tbToolLine: TToolButton;
tbToolRect: TToolButton;
tbToolEllipse: TToolButton;
tbFontPalette: TToolBar;
tbFont0: TToolButton;
tbFont8: TToolButton;
tbFont9: TToolButton;
tbFont10: TToolButton;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton15: TToolButton;
tbModeCharacter: TToolButton;
tbModeLeftRights: TToolButton;
tbModeTopBottoms: TToolButton;
tbModeQuarters: TToolButton;
tbModeSixels: TToolButton;
tbAttrBold: TToolButton;
tbAttrFaint: TToolButton;
tbAttrItalics: TToolButton;
tbAttrUnderline: TToolButton;
tbAttrBlinkSlow: TToolButton;
tbAttrBlinkFast: TToolButton;
tbAttrReverse: TToolButton;
tbAttrConceal: TToolButton;
tbAttrStrikethrough: TToolButton;
tbAttrDoublestrike: TToolButton;
tbAttrShadow: TToolButton;
tbAttrTop: TToolButton;
tbAttrBottom: TToolButton;
tbAttrCharacter: TToolButton;
tbAttrFG: TToolButton;
tbAttrBG: TToolButton;
tbPreview: TToolButton;
tbToolSelect: TToolButton;
tbFont1: TToolButton;
tbFont2: TToolButton;
tbFont3: TToolButton;
tbFont4: TToolButton;
tbFont5: TToolButton;
tbFont6: TToolButton;
tbFont11: TToolButton;
tbFont12: TToolButton;
tbToolPaint: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton8: TToolButton;
tbToolDraw: TToolButton;
tbFont7: TToolButton;
tsCharacters: TTabSheet;
tsColors: TTabSheet;
tsDocument: TTabSheet;
tsObjects: TTabSheet;
procedure bFindColorClick(Sender: TObject);
procedure bRefRemoveClick(Sender: TObject);
procedure bRefShowClick(Sender: TObject);
procedure cbFontChange(Sender: TObject);
procedure ColorButton1Click(Sender: TObject);
function DGetDockerPanel(dockernum : integer) : TPanel;
function DGetPageControl(dockernum : integer) : TPageControl;
function DGetNumDockers : integer;
function DGetNumTabs(dockernum : integer) : integer;
function DGetTabSheet(dockernum, tabnum : integer) : TTabSheet;
function DFindTabSheet(captionstr : string; var dockernum, tabnum : integer) : TTabSheet;
function DFindTabSheet(captionstr : string) : TTabSheet;
procedure dpAllPanelsResize(Sender: TObject);
procedure DRemoveDocker(dockernum : integer);
procedure DividerBevel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure DividerBevel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure DividerBevel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure dpcTabChange(Sender: TObject);
procedure dpcDockersMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure dtbControlsMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure InitDockers;
procedure DeinitDockers;
procedure miEditCopyClick(Sender: TObject);
procedure miEditCutClick(Sender: TObject);
procedure miEditDeleteClick(Sender: TObject);
procedure miEditPasteClick(Sender: TObject);
procedure miEditRedoClick(Sender: TObject);
procedure miEditUndoClick(Sender: TObject);
procedure miViewLoadBitmapClick(Sender: TObject);
procedure pbPageClick(Sender: TObject);
procedure pbRowColor1Click(Sender: TObject);
procedure pbRowColor1Paint(Sender: TObject);
procedure pbRowColor2Click(Sender: TObject);
procedure pbRowColor2Paint(Sender: TObject);
procedure seRefHeightChange(Sender: TObject);
procedure seRefLeftChange(Sender: TObject);
procedure seRefTopChange(Sender: TObject);
procedure seRefWidthChange(Sender: TObject);
procedure SetActiveTab;
procedure AddNewDockerPanel(ts : TTabSheet);
procedure dtbClosePageClick(Sender: TObject);
procedure dtbControlsPaint(Sender: TObject);
procedure dtbMinMaxClick(Sender: TObject);
procedure dtbMoveDownClick(Sender: TObject);
procedure dtbMoveUpClick(Sender: TObject);
procedure AddDocker(Sender: TObject);
function GetBlock(x, y : integer) : integer;
function InToFill(r, c : integer) : boolean;
procedure FloodFillChar(x, y : integer; fillwith : TCell);
procedure FloodFillBlock(x, y, fillwith : integer);
procedure DrawSelectionAndObjects;
function AdjustCellIgnores(cell : TCell; r, c : integer) : TCell;
procedure DrawCharLine(fx, fy, tx, ty : integer; cell : TCell; skipUpdate : boolean = true);
procedure DrawCharEllipse(fx, fy, tx, ty : integer; cell : TCell; skipUpdate : boolean = true);
procedure DrawBlockEllipse(var DrawData : TRecList; fx, fy, tx, ty, cl : integer; skipUpdate : boolean = true);
procedure DrawBlockLine(var DrawData : TRecList; fx, fy, tx, ty, cl : integer; skipUpdate : boolean = true);
procedure EraseLine(fx, fy, tx, ty : integer);
procedure EraseEllipse(fx, fy, tx, ty : integer);
procedure dtpSauceDateEditingDone(Sender: TObject);
procedure ExportTextFile(fname : string; useBOM, usesauce : boolean);
function ComputeSGR(currattr, targetattr : DWORD) : unicodestring;
procedure FormDestroy(Sender: TObject);
procedure memSauceCommentsEditingDone(Sender: TObject);
procedure tsReferenceImageContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure tbRefOpacityChange(Sender: TObject);
procedure tbSauceAuthorEditingDone(Sender: TObject);
procedure tbSauceGroupEditingDone(Sender: TObject);
procedure tbSauceTitleEditingDone(Sender: TObject);
procedure WriteANSI(fs : TFileStream; str : unicodestring);
procedure WriteANSIChunk(fs : TFileStream; maxlen : integer; var rowansi, ansi : unicodestring);
procedure miFileImportClick(Sender: TObject);
procedure OpenVTXFile(fname : string);
procedure SaveVTXFile(fname : string);
procedure SaveAsVTXFile;
procedure ImportANSIFile(fname : string; force8bit : boolean);
procedure ExportANSIFile(fname : string; maxlen : integer; usebom, usesauce, staticobjects: boolean);
procedure CheckToSave;
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure SaveUndoKeys;
procedure ClearAllUndo;
procedure DoObjFlipHorz(objnum : integer);
procedure DoObjFlipVert(objnum : integer);
procedure bObjHideOutlinesClick(Sender: TObject);
procedure bObjMergeAllClick(Sender: TObject);
function lvObjIndex(idx : integer) : integer;
procedure bObjLoadClick(Sender: TObject);
procedure bObjSaveClick(Sender: TObject);
procedure lvObjectsEdited(Sender: TObject; Item: TListItem; var AValue: string);
procedure lvObjectsEditing(Sender: TObject; Item: TListItem; var AllowEdit: Boolean);
procedure miFileExportClick(Sender: TObject);
procedure miFileSaveAsClick(Sender: TObject);
procedure miObjNextClick(Sender: TObject);
procedure miObjPrevClick(Sender: TObject);
procedure RemoveObject(objnum : integer);
procedure InsertObject(obj : TObj; pos : integer);
procedure ObjFlipHorz;
procedure ObjFlipVert;
procedure ObjMoveBack;
procedure ObjMoveForward;
procedure ObjMoveToBack;
procedure ObjMoveToFront;
procedure ObjMerge;
procedure ObjMergeAll;
procedure ObjNext;
procedure ObjPrev;
procedure bObjFlipHorzClick(Sender: TObject);
procedure bObjFlipVertClick(Sender: TObject);
procedure bObjMergeClick(Sender: TObject);
procedure bObjMoveBackClick(Sender: TObject);
procedure bObjMoveToBackClick(Sender: TObject);
procedure bObjMoveToFrontClick(Sender: TObject);
procedure bObnjMoveForwardClick(Sender: TObject);
procedure RefreshObject(objnum : integer);
function GetObjectCell(row, col : integer; var cell : TCell) : integer;
function GetObject(row, col : integer) : integer;
procedure LoadlvObjects;
function CopySelectionToObject : TObj;
procedure BuildCharacterPalette;
function BuildDisplayCopySelection : TRecList;
procedure ResetBlink;
procedure DrawCursor;
procedure lvObjectsDrawItem(Sender: TCustomListView; AItem: TListItem; ARect: TRect; AState: TOwnerDrawState);
procedure lvObjectsMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure pbCharsMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure pbCharsPaint(Sender: TObject);
procedure pbColorsMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure pbColorsPaint(Sender: TObject);
procedure seCharacterChange(Sender: TObject);
procedure tbAttrClick(Sender: TObject);
procedure tbAttrMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure tbFontClick(Sender: TObject);
procedure tbModeClick(Sender: TObject);
procedure tbToolClick(Sender: TObject);
procedure tbAttributesPalettePaintButton(Sender: TToolButton; State: integer);
procedure UpdateTitles;
procedure pbCurrCellPaint(Sender: TObject);
procedure DrawCellEx(cnv : TCanvas; x, y, row, col : integer; skipUpdate : boolean = true; skipDraw : boolean = false; usech : uint16 = _EMPTY; useattr : uint32 = $FFFF);
procedure SetAttrButtons(attr : Uint32);
procedure cbCodePageChange(Sender: TObject);
procedure cbColorSchemeChange(Sender: TObject);
procedure cbPageTypeChange(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyPress(Sender: TObject; var Key: char);
procedure FormResize(Sender: TObject);
procedure irqBlinkTimer(Sender: TObject);
procedure miFileExitClick(Sender: TObject);
procedure miFileOpenClick(Sender: TObject);
procedure miFileNewClick(Sender: TObject);
procedure miFileSaveClick(Sender: TObject);
procedure pbPageMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure pbPageMouseLeave(Sender: TObject);
procedure pbPageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure pbPageMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure pbPageMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure pbPagePaint(Sender: TObject);
procedure pbPreviewClick(Sender: TObject);
procedure pbRulerLeftPaint(Sender: TObject);
procedure pbRulerTopPaint(Sender: TObject);
procedure pbStatusBarPaint(Sender: TObject);
procedure ResizeScrolls;
procedure ResizePage;
procedure ResizePage(row, col : integer);
procedure sbHorzChange(Sender: TObject);
procedure sbVertChange(Sender: TObject);
procedure DrawCell(row, col : integer; skipUpdate : boolean = true);
procedure sePageSizeChange(Sender: TObject);
procedure ScrollToCursor;
procedure CursorRight;
procedure CursorLeft;
procedure CursorUp;
procedure CursorDown;
procedure CursorStatus;
procedure CursorNewLine;
procedure CursorForwardTab;
procedure CursorBackwardTab;
procedure CursorMove(row, col : integer);
procedure seXScaleChange(Sender: TObject);
procedure DrawMouseBox;
procedure PutCharExpand(ch : integer);
procedure PutChar(ch : integer);
procedure PutCharEx(ch, attr, row, col : integer);
function HasUnicodes(cp : TEncoding; chars : array of UInt16) : boolean;
function GetUnicode(cell : TCell) : integer;
function GetCPChar(cp : TEncoding; unicode : integer) : integer;
function GetColors2x1(cell : TCell) : TColors2;
function GetColors1x2(cell : TCell) : TColors2;
function GetColors2x2(cell : TCell) : TColors4;
function GetColors2x3(cell : TCell) : TColors6;
function GetBlockColor(cell : TCell; xsize, ysize, x, y : integer) : integer;
function SetBlockColor(clr: integer; cell : TCell; xsize, ysize, x, y : integer) : TCell;
procedure GenerateBmpPage;
procedure CodePageChange;
function GetNextCell(r, c : integer; staticobjects : boolean; var cell : TCell) : TRowCol;
function GetNextObjectCell(Obj : TObj; r, c : integer; var cell : TCell) : TRowCol;
Procedure LoadSettings;
Procedure SaveSettings;
procedure InitSauce;
procedure NewFile;
procedure DoBlink;
procedure RecordUndoCell(row, col : uint16; newcell : TCell);
procedure UndoTruncate(pos : integer);
procedure UndoAdd(undoblk : TUndoBlock);
procedure UndoPerform(pos : integer);
procedure RedoPerform(pos : integer);
procedure CreateReference;
function ExtractReferenceCell(row, col : integer) : TBGRABitmap;
private
{ private declarations }
public
{ public declarations }
end;
// save as native character. (not converted to unicode)
TFKeySet = array [0..9] of byte;
var
fMain: TfMain;
procedure CopyObject(src : TObj; var dst : TObj);
procedure DebugStart;
procedure nop;
implementation
{$R *.lfm}
{*****************************************************************************}
{ Private Globals }
var
// tool windows
fPreviewBox : TfPreview;
CurrFilePath : unicodestring; // path to this doc.
CurrFileName : unicodestring;
CurrFileChanged : boolean;
PageTop, PageLeft : integer; // upper left corner position
WindowCols, WindowRows : integer; // visible area of window
MouseRow, MouseCol : integer; // mouse position (-1 if off page)
LastDrawRow, LastDrawCol: integer;
LastDrawX, LastDrawY : integer;
BlinkFast, BlinkSlow : boolean; // blink states
MousePan : boolean = false;
MousePanX, MousePanY : integer; // current mouse xy
SubXSize, SubYSize : integer; // coords subdivision size
DrawX, DrawY : integer; // drawing position in draw mode coors
FirstDrawX, FirstDrawY: integer; // starting pos for lines, rec, ellipse
SubX, SubY : integer; // sub pos inside character
MousePanT, MousePanL : integer; // current mouse rc
CursorRow, CursorCol : integer; // cursor location.
CurrChar : integer; // selected char to draw with
CurrAttr : UInt32; // current attributes
CurrFKeySet : integer = 5;
ToolMode : TToolModes;
DrawMode : TDrawModes;
CurrFont : integer; // current font selected.
MouseLeft,
MouseMiddle,
MouseRight : boolean;
// objects
SelectedObject : integer;
dragObj : boolean; // in object move mode?
Clipboard : TObj;
// region selection
CopySelection : TRecList;
drag : boolean; // in drag mode
dragDraw : boolean; // in drawing mode (line, rect, ellipse)
dragType : integer; // 0=select, 1=add, 2=remove
dragRow, dragCol : integer; // drag delta
dragObjRow, dragObjCol : integer; // start pos of obj drag
SkipScroll : boolean; // disable scroll to cursor
SkipResize : boolean; // skip onchange updates on dynamic change.
bmpCharPalette : TBitmap = nil;
// deault FKey char sets - as defined in Pablo. Uses CP437 chars. Translate
// as needed.
FKeys : packed array [0..9] of TFKeySet = (
( $DA, $BF, $C0, $D9, $C4, $B3, $C3, $B4, $C1, $C2 ),
( $C9, $BB, $C8, $BC, $CD, $BA, $CC, $B9, $CA, $CB ),
( $D5, $B8, $D4, $BE, $CD, $B3, $C6, $B5, $CF, $D1 ),
( $D6, $B7, $D3, $BD, $C4, $BA, $C7, $B6, $D0, $D2 ),
( $C5, $CE, $D8, $D7, $E8, $E8, $9B, $9C, $99, $EF ),
( $B0, $B1, $B2, $DB, $DF, $DC, $DD, $DE, $FE, $FA ),
( $01, $02, $03, $04, $05, $06, $F0, $0E, $0F, $20 ),
( $18, $19, $1E, $1F, $10, $11, $12, $1D, $14, $15 ),
( $AE, $AF, $F2, $F3, $A9, $AA, $FD, $F6, $AB, $AC ),
( $E3, $F1, $F4, $F5, $EA, $9D, $E4, $F8, $FB, $FC ));
ObjectRename : boolean = false;
ObjectOutlines : boolean = true;
LastCharNum : integer = 0;
// reference bitmap info
bmpReference : TBGRABitmap = nil; // original reference image
bmpRefScaled : TBGRABitmap = nil; // scaled to below values and opacity
RefTop, RefLeft : integer;
RefWidth, RefHeight : integer;
RefOpacity : byte = 128;
{*****************************************************************************}
// convert object number to lvObjects index
function TfMain.lvObjIndex(idx : integer) : integer;
begin
if idx = -1 then exit(-1);
result := lvObjects.Items.Count - idx - 1;
end;
procedure TfMain.bObjHideOutlinesClick(Sender: TObject);
begin
// toggle outlines on objects
ObjectOutlines := bObjHideOutlines.Down;
pbPage.Invalidate;
end;
// return the topmost cell of an object at row, cell or EMPTYCELL
function TfMain.GetObjectCell(row, col : integer; var cell : TCell) : integer;
var
i : integer;
po : PObj;
objr, objc, p : integer;
cellrec : TCell;
begin
for i := length(Objects) - 1 downto 0 do
begin
po := @Objects[i];
if InRect(col, row, po^.Col, po^.Row, po^.Width, po^.Height) then
begin
// on the col
objr := row - po^.Row;
objc := col - po^.Col;
p := objr * po^.Width + objc;
po^.Data.Get(@cellrec, p);
if cellrec.Chr <> _EMPTY then
begin
cell := cellrec;
exit(i);
end;
end;
end;
cell := Page.Rows[row].Cells[col];
result := -1;
end;
// return the topmost cell of an object at row, cell or EMPTYCELL
function TfMain.GetObject(row, col : integer) : integer;
var
i : integer;
po : PObj;
objr, objc, p : integer;
cellrec : TCell;
begin
for i := length(Objects) - 1 downto 0 do
begin
po := @Objects[i];
if InRect(col, row, po^.Col, po^.Row, po^.Width, po^.Height) then
begin
// on the col
objr := row - po^.Row;
objc := col - po^.Col;
p := objr * po^.Width + objc;
po^.Data.Get(@cellrec, p);
if cellrec.Chr <> _EMPTY then
exit(i);
end;
end;
result := -1;
end;
// draw cursor overlay
procedure TfMain.DrawCursor;
var
x, y : integer;
zz : real;
h1, h2,
v1, v2 : integer;
cnv : TCanvas;
begin
cnv := pbPage.Canvas;
x := (CursorCol - PageLeft) * CellWidthZ;
y := (CursorRow - PageTop) * CellHeightZ;
zz := PageZoom * XScale;
h1 := floor(1 * PageZoom);
h2 := floor(5 * PageZoom);
v1 := floor(1 * zz);
v2 := floor(3 * zz);
cnv.Brush.Color := ANSIColor[GetBits(Page.CrsrAttr, A_CURSOR_COLOR_MASK)];
case GetBits(Page.CrsrAttr, A_CURSOR_VERTICAL or A_CURSOR_SIZE_MASK, 8) of
1: // horz thin
begin
cnv.FillRect(x, y + CellHeightZ - h1, x + CellWidthZ, y + CellHeightZ);
Draw3DRect(cnv, x, y + CellHeightZ - h1, x + CellWidthZ, y + CellHeightZ, false);
end;
2: // horz thick
begin
cnv.FillRect(x, y + CellHeightZ - h2, x + CellWidthZ, y + CellHeightZ);
Draw3DRect(cnv, x, y + CellHeightZ - h2, x + CellWidthZ, y + CellHeightZ, false);
end;
5: // vert thin
begin
cnv.FillRect(x, y, x + v1, y + CellHeightZ);
Draw3DRect(cnv, x, y, x + v1, y + CellHeightZ, false);
end;
6: // vert thick
begin
cnv.FillRect(x, y, x + v2, y + CellHeight);
Draw3DRect(cnv, x, y, x + v2, y + CellHeight, false);
end;
3, 7: // full
begin
cnv.FillRect(x, y, x + CellWidthZ, y + CellHeightZ);
Draw3DRect(cnv, x, y, x + CellWidthZ, y + CellHeightZ, false);
end;
end;
end;
// refresh cursor and blinking text
procedure TfMain.DoBlink;
var
x, y, r, c : integer;
cell : TCell;
cnv : TCanvas;
docell : boolean;
objnum : integer;
i : integer;
cl1, cl2 : TColor;
copyrec : TLoc;
begin
if bmpPage <> nil then
begin
begin
cell := BLANK;
BlinkFast := not BlinkFast;
if BlinkFast then
BlinkSlow := not BlinkSlow;
// only display blink on normal or higher zoom
if PageZoom >= 1 then
begin
cnv := pbPage.Canvas;
y := 0;
for r := PageTop to NumRows - 1 do
begin
if r > PageTop + WindowRows then
break;
x := 0;
for c := PageLeft to NumCols - 1 do
begin
if c > PageLeft + WindowCols then
break;
docell := false;
objnum := GetObjectCell(r, c, cell);
if objnum = -1 then
cell := Page.Rows[r].Cells[c];
if (CursorRow = r) and (CursorCol = c) then
docell := true;
if (HasBits(cell.Attr, A_CELL_BLINKSLOW OR A_CELL_BLINKFAST) and (ColorScheme <> COLORSCHEME_ICE)) then
docell := true;
if docell then
begin
DrawCellEx(cnv, x, y, r, c, true, false, cell.chr, cell.attr);
// draw cursor over top if cursor location (if on page)
if (CursorRow = r) and (CursorCol = c) and (objnum = -1) then
begin
// draw selection border
for i := CopySelection.Count - 1 downto 0 do
begin
CopySelection.Get(@copyrec, i);
if (copyrec.Row = r) and (copyrec.Col = c) then
begin
if not HasBits(copyrec.Neighbors, NEIGHBOR_NORTH) then
DrawDashLine(cnv,
x, y,
x + CellWidthZ, y,
clSelectionArea1, clSelectionArea2);
if not HasBits(copyrec.Neighbors, NEIGHBOR_SOUTH) then
DrawDashLine(cnv,
x, y + CellHeightZ - 1,
x + CellWidthZ, y + CellHeightZ - 1,
clSelectionArea1, clSelectionArea2);
if not HasBits(copyrec.Neighbors, NEIGHBOR_WEST) then
DrawDashLine(cnv,
x, y,
x, y + CellHeightZ,
clSelectionArea1, clSelectionArea2);
if not HasBits(copyrec.Neighbors, NEIGHBOR_EAST) then
DrawDashLine(cnv,
x + CellWidthZ - 1, y,
x + CellWidthZ - 1, y + CellHeightZ,
clSelectionArea1, clSelectionArea2);
break;
end;
end;
if BlinkFast then
DrawCursor;
end
else
begin
// never a object border on a cursor
if ObjectOutlines then
begin
cnv.Brush.Style := bsClear;
if objnum = SelectedObject then
begin
cl1 := clSelectedObject1;
cl2 := clSelectedObject2;
end
else
begin
cl1 := clUnselectedObject1;
cl2 := clUnselectedObject2;
end;
if not HasBits(cell.neighbors, NEIGHBOR_NORTH) then
DrawDashLine(cnv, x, y,
x + CellWidthZ - 1, y, cl1, cl2);
if not HasBits(cell.neighbors, NEIGHBOR_SOUTH) then
DrawDashLine(cnv, x, y + CellHeightZ - 1,
x + CellWidthZ - 1, y + CellHeightZ - 1, cl1, cl2);
if not HasBits(cell.neighbors, NEIGHBOR_WEST) then
DrawDashLine(cnv, x, y,
x, y + CellHeightZ - 1, cl1, cl2);
if not HasBits(cell.neighbors, NEIGHBOR_EAST) then
DrawDashLine(cnv, x + CellWidthZ - 1, y,
x + CellWidthZ - 1, y + CellHeightZ - 1, cl1, cl2);
end;
end;
end;
x += CellWidthZ;
end;
y += CellHeightZ;
end;
end;
end;
end;
end;
procedure TfMain.irqBlinkTimer(Sender: TObject);
begin
DoBlink;
end;
// resize Page based on Cols, Rows
procedure TfMain.ResizePage;
var
r, c, i, j : integer;
begin
r := length(Page.Rows); // get actual size
if r < NumRows then // on add new lines if they do not exist
begin
setlength(Page.Rows, NumRows);
for i := r to NumRows - 1 do
Page.Rows[i].Attr := A_ROW_WIDTH_100;
end;
for i := 0 to NumRows - 1 do
begin
c := length(Page.Rows[i].Cells); // get actual width
if c < NumCols then
begin
setlength(Page.Rows[i].Cells, NumCols);
for j := c to NumCols - 1 do
Page.Rows[i].Cells[j] := BLANK;
end;
end;
if CursorRow >= NumRows then CursorRow := NumRows - 1;
if CursorCol >= NumCols then CursorCol := NumCols - 1;
GenerateBmpPage;
pbPage.Invalidate;
tsRowAttr.Invalidate;
end;
procedure TfMain.ResizePage(row, col : integer);
begin
if row >= NumRows then
seRows.Value := row + 1;
if col >= NumCols then
seCols.Value := col + 1;
end;
procedure TfMain.UpdateTitles;
var
altered : unicodestring;
displayname : unicodestring;
begin
altered := '';
if CurrFileChanged then
altered := '*';
displayname := CurrFileName;
if displayname = '' then
displayname := '<untitled>';
Caption := Format('VTXEdit : %s - %s%s', [ Version, altered, displayname ]);
Application.Title := Format('VTXEdit - %s%s', [ altered, displayname ]);
end;
procedure TfMain.FormCreate(Sender: TObject);
var
cp : TEncoding;
i : integer;
gt : pbyte;
gts : integer;
enc : integer;