-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pas
1341 lines (1191 loc) · 34.8 KB
/
main.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
//------------------------------------------------------------------------------
//
// DD_FONT: Doom Font Creator
// Copyright (C) 2021-2022 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// DESCRIPTION:
// Main Form
//
//------------------------------------------------------------------------------
// E-Mail: jimmyvalavanis@yahoo.gr
// Site : https://sourceforge.net/projects/dd-font/
//------------------------------------------------------------------------------
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, Buttons, Clipbrd, ExtDlgs, Menus, ImgList, jpeg,
StdCtrls, pngimage, xTGA, zBitmap, ff_undo, ff_filemenuhistory, ff_engine,
ff_slider;
const
MINZOOM = 0;
MAXZOOM = 10;
const
MOUSEWHEELTIMEOUT = 100; // Msecs until next mouse wheel even to be proccessed
type
TForm1 = class(TForm)
TopToolbarPanel: TPanel;
StatusBar1: TStatusBar;
LeftToolbarPanel: TPanel;
OpenSpeedButton1: TSpeedButton;
SaveSpeedButton1: TSpeedButton;
CopySpeedButton1: TSpeedButton;
GridButton1: TSpeedButton;
MainMenu1: TMainMenu;
File1: TMenuItem;
Open1: TMenuItem;
SaveAs1: TMenuItem;
N1: TMenuItem;
Exit1: TMenuItem;
Edit1: TMenuItem;
Copy1: TMenuItem;
N2: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
Timer1: TTimer;
Panel4: TPanel;
ScrollBox1: TScrollBox;
PaintBox1: TPaintBox;
Panel6: TPanel;
New1: TMenuItem;
N3: TMenuItem;
Save2: TMenuItem;
HistoryItem0: TMenuItem;
HistoryItem1: TMenuItem;
HistoryItem2: TMenuItem;
HistoryItem3: TMenuItem;
HistoryItem4: TMenuItem;
HistoryItem5: TMenuItem;
HistoryItem6: TMenuItem;
HistoryItem7: TMenuItem;
HistoryItem8: TMenuItem;
HistoryItem9: TMenuItem;
N14: TMenuItem;
Undo1: TMenuItem;
Redo1: TMenuItem;
N4: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
NewSpeedButton1: TSpeedButton;
UndoSpeedButton1: TSpeedButton;
RedoSpeedButton1: TSpeedButton;
FontDialog1: TFontDialog;
ColorDialog1: TColorDialog;
ZoomInSpeedButton1: TSpeedButton;
ZoomOutSpeedButton1: TSpeedButton;
WidthInfoLabel: TLabel;
SavePictureDialog1: TSavePictureDialog;
Export1: TMenuItem;
ExportImage1: TMenuItem;
N5: TMenuItem;
Tools1: TMenuItem;
Openexternalfont1: TMenuItem;
OpenDialog2: TOpenDialog;
Panel5: TPanel;
ToolPanel: TPanel;
BoldSpeedButton: TSpeedButton;
ItalicSpeedButton: TSpeedButton;
UnderlineSpeedButton: TSpeedButton;
StrikeOutSpeedButton: TSpeedButton;
BackColorSpeedButton: TSpeedButton;
FrontColorSpeedButton: TSpeedButton;
SmallerSpeedButton: TSpeedButton;
BiggerSpeedButton: TSpeedButton;
SelectFontSpeedButton: TSpeedButton;
Label1: TLabel;
FontSizeLabel: TLabel;
FontNamesComboBox: TComboBox;
GroupBox1: TGroupBox;
DrawHeightPaintBox: TPaintBox;
DrawWidthPaintBox: TPaintBox;
CharWidthLabel: TLabel;
CharHeightLabel: TLabel;
Label2: TLabel;
ExportPanel: TPanel;
Panel1: TPanel;
FixedPitchCheckBox: TCheckBox;
PaletteRadioGroup: TRadioGroup;
PerlinNoiseCheckBox: TCheckBox;
ChooseOtherPalettePanel: TPanel;
OtherPaletteEdit: TEdit;
LoadPaletteSpeedButton: TSpeedButton;
OpenPaletteDialog: TOpenDialog;
ExportPageControl: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
Label3: TLabel;
TextExportEdit: TEdit;
Label4: TLabel;
FontSequencePrefixEdit: TEdit;
Label5: TLabel;
NumberSequencePrefixEdit: TEdit;
PreviewGroupBox: TGroupBox;
PreviewImage: TImage;
SaveWADDialog: TSaveDialog;
GenerateSpeedButton: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure Copy1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Edit1Click(Sender: TObject);
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Undo1Click(Sender: TObject);
procedure Redo1Click(Sender: TObject);
procedure File1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure New1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure SaveAs1Click(Sender: TObject);
procedure BoldSpeedButtonClick(Sender: TObject);
procedure ItalicSpeedButtonClick(Sender: TObject);
procedure UnderlineSpeedButtonClick(Sender: TObject);
procedure StrikeOutSpeedButtonClick(Sender: TObject);
procedure FontNamesComboBoxClick(Sender: TObject);
procedure SmallerSpeedButtonClick(Sender: TObject);
procedure BiggerSpeedButtonClick(Sender: TObject);
procedure BackColorSpeedButtonClick(Sender: TObject);
procedure FrontColorSpeedButtonClick(Sender: TObject);
procedure SelectFontSpeedButtonClick(Sender: TObject);
procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure ZoomIn1Click(Sender: TObject);
procedure ZoomOut1Click(Sender: TObject);
procedure GridButton1Click(Sender: TObject);
procedure ExportImage1Click(Sender: TObject);
procedure Openexternalfont1Click(Sender: TObject);
procedure LoadPaletteSpeedButtonClick(Sender: TObject);
procedure OtherPaletteEditChange(Sender: TObject);
procedure FixedPitchCheckBoxClick(Sender: TObject);
procedure PerlinNoiseCheckBoxClick(Sender: TObject);
procedure PaletteRadioGroupClick(Sender: TObject);
procedure ExportPageControlChange(Sender: TObject);
procedure TextExportEditChange(Sender: TObject);
procedure FontSequencePrefixEditChange(Sender: TObject);
procedure NumberSequencePrefixEditChange(Sender: TObject);
procedure GenerateSpeedButtonClick(Sender: TObject);
private
{ Private declarations }
buffer: TBitmap;
drawbuffer: TBitmap;
mousedown: boolean;
changed: boolean;
needsupdate: boolean;
needsgenerationcontrolsupdate: boolean;
undoManager: TUndoRedoManager;
filemenuhistory: TFileMenuHistory;
ffilename: string;
ff: TFontEngine;
zoom: integer;
flastzoomwheel: int64;
DrawWidthSlider: TSliderHook;
DrawHeightSlider: TSliderHook;
ExternalFonts: TStringList;
sPalette: string;
procedure Idle(Sender: TObject; var Done: Boolean);
procedure Hint(Sender: TObject);
procedure UpdateEnable(const force: Boolean = False);
procedure InvalidatePaintBox;
procedure PaintBox1Responer(const X, Y: Integer);
procedure CreateDrawBuffer;
procedure DoCreateNew;
procedure DoLoadFromStream(const s: TStream);
procedure DoSaveToStream(const s: TStream);
procedure DoLoadUndo(const s: TStream);
procedure DoSaveUndo(const s: TStream);
function DoLoadFromFile(const aname: string): boolean;
procedure DoSaveToFile(const aname: string);
procedure OnLoadFileMenuHistory(Sender: TObject; const aname: string);
function CheckCanClose: boolean;
procedure SetFileName(const fname: string);
procedure UpdateControls;
procedure UpdateFontGenerationControls;
procedure DrawGrid;
procedure OnDrawWidthChange(Sender: TObject);
procedure OnDrawHeightChange(Sender: TObject);
procedure InstallExternalFont(const ttffile: string);
procedure InstallDoomFont;
procedure sPaletteToControls;
procedure sPaletteFromControls;
procedure DoGenerateWAD;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
ff_utils, ff_defs, ff_doomfont, ff_tmp, ff_palettes, ff_wadwriter, ff_export;
var
finitialized: boolean = False;
function EnumFontsProc(var LogFont: TLogFont; var TextMetric: TTextMetric;
FontType: Integer; Data: Pointer): Integer; stdcall;
var
S: TStrings;
Temp: string;
begin
S := TStrings(Data);
Temp := LogFont.lfFaceName;
if (S.Count = 0) or (AnsiCompareText(S[S.Count - 1], Temp) <> 0) then
S.Add(Temp);
Result := 1;
end;
procedure CollectFonts(FontList: TStringList);
var
DC: HDC;
LFont: TLogFont;
begin
DC := GetDC(0);
FillChar(LFont, sizeof(LFont), 0);
LFont.lfCharset := DEFAULT_CHARSET;
EnumFontFamiliesEx(DC, LFont, @EnumFontsProc, LPARAM(FontList), 0);
ReleaseDC(0, DC);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
doCreate: boolean;
fList: TStringList;
begin
DoubleBuffered := True;
for i := 0 to ComponentCount - 1 do
if Components[i].InheritsFrom(TWinControl) then
if not (Components[i] is TListBox) then
(Components[i] as TWinControl).DoubleBuffered := True;
buffer := TBitmap.Create;
drawbuffer := TBitmap.Create;
flastzoomwheel := GetTickCount;
ExportPageControl.ActivePageIndex := 0;
ExternalFonts := TStringList.Create;
InstallDoomFont; // Must be called before filling the FontNamesComboBox and after creating ExternalFonts
ff := TFontEngine.Create;
DrawWidthSlider := TSliderHook.Create(DrawWidthPaintBox);
DrawWidthSlider.Min := 5.0;
DrawWidthSlider.Max := 32.0;
DrawWidthSlider.Step := 1.0;
DrawWidthSlider.PageStep := 5.0;
DrawWidthSlider.OnSliderHookChange := OnDrawWidthChange;
DrawHeightSlider := TSliderHook.Create(DrawHeightPaintBox);
DrawHeightSlider.Min := 5.0;
DrawHeightSlider.Max := 32.0;
DrawHeightSlider.Step := 1.0;
DrawHeightSlider.PageStep := 5.0;
DrawHeightSlider.OnSliderHookChange := OnDrawHeightChange;
mousedown := False;
ff_LoadSettingFromFile(ChangeFileExt(ParamStr(0), '.ini'));
undoManager := TUndoRedoManager.Create;
undoManager.OnLoadFromStream := DoLoadUndo;
undoManager.OnSaveToStream := DoSaveUndo;
filemenuhistory := TFileMenuHistory.Create(self);
filemenuhistory.MenuItem0 := HistoryItem0;
filemenuhistory.MenuItem1 := HistoryItem1;
filemenuhistory.MenuItem2 := HistoryItem2;
filemenuhistory.MenuItem3 := HistoryItem3;
filemenuhistory.MenuItem4 := HistoryItem4;
filemenuhistory.MenuItem5 := HistoryItem5;
filemenuhistory.MenuItem6 := HistoryItem6;
filemenuhistory.MenuItem7 := HistoryItem7;
filemenuhistory.MenuItem8 := HistoryItem8;
filemenuhistory.MenuItem9 := HistoryItem9;
filemenuhistory.OnOpen := OnLoadFileMenuHistory;
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory9));
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory8));
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory7));
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory6));
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory5));
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory4));
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory3));
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory2));
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory1));
filemenuhistory.AddPath(bigstringtostring(@opt_filemenuhistory0));
ffilename := '';
GridButton1.Down := opt_showgrid;
zoom := GetIntInRange(opt_zoom, MINZOOM, MAXZOOM);
DrawWidthSlider.Position := opt_DrawWidth;
DrawHeightSlider.Position := opt_DrawHeight;
FixedPitchCheckBox.Checked := opt_FixedPitch;
PerlinNoiseCheckBox.Checked := opt_PerlinNoise;
sPalette := bigstringtostring(@opt_Palette);
sPaletteToControls;
OtherPaletteEdit.Text := bigstringtostring(@opt_ExternalPalette);
TextExportEdit.Text := bigstringtostring(@opt_TextExport);
FontSequencePrefixEdit.Text := bigstringtostring(@opt_FontSequencePrefix);
NumberSequencePrefixEdit.Text := bigstringtostring(@opt_NumberSequencePrefix);
ff.FontSize := opt_FontSize;
ff.FontName := bigstringtostring(@opt_FontName);
ff.Bold := opt_Bold;
ff.Italic := opt_Italic;
ff.Underline := opt_Underline;
ff.StrikeOut := opt_StrikeOut;
ff.FrontColor := opt_FgColor;
ff.BackColor := opt_BkColor;
fList := TStringList.Create;
CollectFonts(fList);
for i := 0 to fList.Count -1 do
FontNamesComboBox.Items.Add(FList[i]);
fList.Free;
doCreate := True;
if ParamCount > 0 then
if DoLoadFromFile(ParamStr(1)) then
doCreate := False;
needsgenerationcontrolsupdate := True;
if docreate then
begin
SetFileName('');
changed := False;
needsupdate := True;
undoManager.Clear;
end
else
DoCreateNew;
Application.OnIdle := Idle;
Application.OnHint := Hint;
finitialized := True;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
PaintBox1.Canvas.Draw(0, 0, drawbuffer);
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
i: integer;
p: PChar;
begin
undoManager.Free;
stringtobigstring(filemenuhistory.PathStringIdx(0), @opt_filemenuhistory0);
stringtobigstring(filemenuhistory.PathStringIdx(1), @opt_filemenuhistory1);
stringtobigstring(filemenuhistory.PathStringIdx(2), @opt_filemenuhistory2);
stringtobigstring(filemenuhistory.PathStringIdx(3), @opt_filemenuhistory3);
stringtobigstring(filemenuhistory.PathStringIdx(4), @opt_filemenuhistory4);
stringtobigstring(filemenuhistory.PathStringIdx(5), @opt_filemenuhistory5);
stringtobigstring(filemenuhistory.PathStringIdx(6), @opt_filemenuhistory6);
stringtobigstring(filemenuhistory.PathStringIdx(7), @opt_filemenuhistory7);
stringtobigstring(filemenuhistory.PathStringIdx(8), @opt_filemenuhistory8);
stringtobigstring(filemenuhistory.PathStringIdx(9), @opt_filemenuhistory9);
opt_showgrid := GridButton1.Down;
opt_zoom := zoom;
opt_DrawWidth := Round(DrawWidthSlider.Position);
opt_DrawHeight := Round(DrawHeightSlider.Position);
opt_FixedPitch := FixedPitchCheckBox.Checked;
opt_PerlinNoise := PerlinNoiseCheckBox.Checked;
sPaletteFromControls;
stringtobigstring(sPalette, @opt_Palette);
stringtobigstring(OtherPaletteEdit.Text, @opt_ExternalPalette);
stringtobigstring(TextExportEdit.Text, @opt_TextExport);
stringtobigstring(FontSequencePrefixEdit.Text, @opt_FontSequencePrefix);
stringtobigstring(NumberSequencePrefixEdit.Text, @opt_NumberSequencePrefix);
opt_FontSize := ff.FontSize;
stringtobigstring(ff.FontName, @opt_FontName);
opt_Bold := ff.Bold;
opt_Italic := ff.Italic;
opt_Underline := ff.Underline;
opt_StrikeOut := ff.StrikeOut;
opt_FgColor := ff.FrontColor;
opt_BkColor := ff.BackColor;
ff_SaveSettingsToFile(ChangeFileExt(ParamStr(0), '.ini'));
filemenuhistory.Free;
buffer.Free;
drawbuffer.Free;
DrawWidthSlider.Free;
DrawHeightSlider.Free;
for i := 0 to ExternalFonts.Count - 1 do
begin
p := PChar(ExternalFonts.Strings[i]);
RemoveFontResourceEx(p, FR_PRIVATE, 0);
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
end;
ExternalFonts.Free;
ff.Free;
end;
procedure TForm1.Idle(Sender: TObject; var Done: Boolean);
begin
UpdateEnable;
end;
procedure TForm1.UpdateEnable;
begin
if not finitialized then
Exit;
Undo1.Enabled := undoManager.CanUndo;
Redo1.Enabled := undoManager.CanRedo;
UndoSpeedButton1.Enabled := undoManager.CanUndo;
RedoSpeedButton1.Enabled := undoManager.CanRedo;
ZoomInSpeedButton1.Enabled := zoom < MAXZOOM;
ZoomOutSpeedButton1.Enabled := zoom > MINZOOM;
if needsupdate or needsgenerationcontrolsupdate then
begin
UpdateFontGenerationControls;
needsgenerationcontrolsupdate := False;
end;
if needsupdate then
begin
UpdateControls;
InvalidatePaintBox;
needsupdate := False;
end;
end;
procedure TForm1.Hint(Sender: TObject);
begin
StatusBar1.SimpleText := Application.Hint;
end;
resourcestring
rsTitle = 'Doom Font Creator';
procedure TForm1.About1Click(Sender: TObject);
begin
MessageBox(
Handle,
PChar(Format('%s'#13#10'Version %s'#13#10#13#10'A tool for creating font images for Doom.'#13#10'© 2021-2022, jvalavanis@gmail.com', [rsTitle, I_VersionBuilt])),
PChar(rsTitle),
MB_OK or MB_ICONINFORMATION or MB_APPLMODAL);
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Copy1Click(Sender: TObject);
begin
Clipboard.Assign(buffer);
end;
procedure TForm1.Open1Click(Sender: TObject);
begin
if not CheckCanClose then
Exit;
if OpenDialog1.Execute then
DoLoadFromFile(OpenDialog1.FileName);
end;
procedure TForm1.InvalidatePaintBox;
begin
if not finitialized then
Exit;
ff.DrawToBitmap(buffer);
CreateDrawBuffer;
PaintBox1.Width := drawbuffer.Width;
PaintBox1.Height := drawbuffer.Height;
PaintBox1.Invalidate;
ScrollBox1.Invalidate;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
UpdateEnable;
InvalidatePaintBox;
end;
procedure TForm1.Edit1Click(Sender: TObject);
begin
Undo1.Enabled := undoManager.CanUndo;
Redo1.Enabled := undoManager.CanRedo;
end;
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
mousedown := Button in [mbLeft];
PaintBox1Responer(X, Y);
end;
procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
mousedown := False;
end;
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
PaintBox1Responer(X, Y);
end;
procedure TForm1.PaintBox1Responer(const X, Y: Integer);
begin
if mousedown then
begin
InvalidatePaintBox;
end;
end;
procedure TForm1.CreateDrawBuffer;
begin
drawbuffer.Width := Round(buffer.Width * (1 + 3 * zoom / MAXZOOM));
drawbuffer.Height := Round(buffer.Height * (1 + 3 * zoom / MAXZOOM));
drawbuffer.Canvas.StretchDraw(Rect(0, 0, drawbuffer.Width, drawbuffer.Height), buffer);
DrawGrid;
end;
procedure TForm1.Undo1Click(Sender: TObject);
begin
if undoManager.CanUndo then
undoManager.Undo;
end;
procedure TForm1.Redo1Click(Sender: TObject);
begin
if undoManager.CanRedo then
undoManager.Redo;
end;
procedure TForm1.File1Click(Sender: TObject);
begin
filemenuhistory.RefreshMenuItems;
end;
procedure TForm1.DoCreateNew;
begin
undoManager.Clear;
SetFileName('');
ff.Reset;
needsupdate := True;
changed := False;
end;
procedure TForm1.DoLoadFromStream(const s: TStream);
begin
ff.LoadFromStream(s);
needsupdate := True;
end;
procedure TForm1.DoSaveToStream(const s: TStream);
begin
ff.SaveToStream(s);
end;
procedure TForm1.DoLoadUndo(const s: TStream);
begin
DoLoadFromStream(s);
changed := True;
end;
procedure TForm1.DoSaveUndo(const s: TStream);
begin
DoSaveToStream(s);
end;
function TForm1.DoLoadFromFile(const aname: string): boolean;
var
fs: TFileStream;
begin
if not FileExists(aname) then
begin
Result := False;
Exit;
end;
undoManager.Clear;
Result := True;
fs := TFileStream.Create(aname, fmOpenRead);
try
DoLoadFromStream(fs);
SetFileName(aname);
filemenuhistory.AddPath(aname);
changed := False;
finally
fs.Free;
end;
end;
procedure TForm1.DoSaveToFile(const aname: string);
var
fs: TFileStream;
begin
BackupFile(aname);
fs := TFileStream.Create(aname, fmCreate);
try
DoSaveToStream(fs);
SetFileName(aname);
filemenuhistory.AddPath(aname);
changed := False;
finally
fs.Free;
end;
end;
procedure TForm1.OnLoadFileMenuHistory(Sender: TObject; const aname: string);
begin
if CheckCanClose then
DoLoadFromFile(aname);
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := CheckCanClose;
end;
function TForm1.CheckCanClose: boolean;
var
ret: integer;
begin
if changed then
begin
ret := MessageBox(Handle, 'Do you want to save changes?', PChar(rsTitle), MB_YESNOCANCEL or MB_ICONQUESTION or MB_APPLMODAL);
if ret = IDCANCEL then
begin
Result := False;
exit;
end;
if ret = IDNO then
begin
Result := True;
exit;
end;
if ret = IDYES then
begin
Save1Click(self);
Result := not changed;
exit;
end;
end;
Result := True;
end;
procedure TForm1.New1Click(Sender: TObject);
begin
if not CheckCanClose then
Exit;
DoCreateNew;
end;
procedure TForm1.SetFileName(const fname: string);
begin
ffilename := fname;
Caption := rsTitle;
if ffilename <> '' then
Caption := Caption + ' - ' + MkShortName(ffilename);
end;
procedure TForm1.Save1Click(Sender: TObject);
begin
if ffilename = '' then
begin
SaveAs1Click(Sender);
Exit;
end;
DoSaveToFile(ffilename);
end;
procedure TForm1.SaveAs1Click(Sender: TObject);
begin
if SaveDialog1.Execute then
DoSaveToFile(SaveDialog1.FileName);
end;
procedure TForm1.UpdateControls;
begin
BoldSpeedButton.Down := fsBold in ff.Style;
ItalicSpeedButton.Down := fsItalic in ff.Style;
UnderlineSpeedButton.Down := fsUnderline in ff.Style;
StrikeOutSpeedButton.Down := fsStrikeOut in ff.Style;
FontNamesComboBox.ItemIndex := FontNamesComboBox.Items.IndexOf(ff.FontName);
FontSizeLabel.Caption := IntToStr(ff.FontSize);
WidthInfoLabel.Caption := Format('Image Size: %dx%d Character Rect Size: %dx%d',
[
ff.GridWidth * ff.DrawWidth,
ff.GridHeight * ff.DrawHeight,
ff.DrawWidth,
ff.DrawHeight
]
);
DrawWidthSlider.Position := ff.DrawWidth;
DrawWidthPaintBox.Hint := IntToStr(ff.DrawWidth);
CharWidthLabel.Caption := Format('Rect Width: %d', [ff.DrawWidth]);
DrawHeightSlider.Position := ff.DrawHeight;
DrawHeightPaintBox.Hint := IntToStr(ff.DrawHeight);
CharHeightLabel.Caption := Format('Rect Height: %d', [ff.DrawHeight]);
end;
procedure TForm1.UpdateFontGenerationControls;
begin
ChooseOtherPalettePanel.Visible := PaletteRadioGroup.ItemIndex = 6;
PreviewImage.Picture.Bitmap.Width := 320;
PreviewImage.Picture.Bitmap.Height := ff.DrawHeight;
case ExportPageControl.ActivePageIndex of
0: ff.DrawStringToBitmap(PreviewImage.Picture.Bitmap, TextExportEdit.Text, FixedPitchCheckBox.Checked);
1: ff.DrawStringToBitmap(PreviewImage.Picture.Bitmap, '!@#$%+-AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz', FixedPitchCheckBox.Checked);
2: ff.DrawStringToBitmap(PreviewImage.Picture.Bitmap, '1234567890', FixedPitchCheckBox.Checked);
end;
GenerateSpeedButton.Enabled := (ExportPageControl.ActivePageIndex <> 0) or (remove_spaces(TextExportEdit.Text) <> '');
end;
procedure TForm1.BoldSpeedButtonClick(Sender: TObject);
var
stl: TFontStylesBase;
begin
stl := ff.Style;
if BoldSpeedButton.Down then
Include(stl, fsBold)
else
Exclude(stl, fsBold);
if stl <> ff.Style then
begin
undoManager.SaveUndo;
changed := True;
ff.Style := stl;
needsupdate := True;
end;
end;
procedure TForm1.ItalicSpeedButtonClick(Sender: TObject);
var
stl: TFontStylesBase;
begin
stl := ff.Style;
if ItalicSpeedButton.Down then
Include(stl, fsItalic)
else
Exclude(stl, fsItalic);
if stl <> ff.Style then
begin
undoManager.SaveUndo;
changed := True;
ff.Style := stl;
needsupdate := True;
end;
end;
procedure TForm1.UnderlineSpeedButtonClick(Sender: TObject);
var
stl: TFontStylesBase;
begin
stl := ff.Style;
if UnderlineSpeedButton.Down then
Include(stl, fsUnderline)
else
Exclude(stl, fsUnderline);
if stl <> ff.Style then
begin
undoManager.SaveUndo;
changed := True;
ff.Style := stl;
needsupdate := True;
end;
end;
procedure TForm1.StrikeOutSpeedButtonClick(Sender: TObject);
var
stl: TFontStylesBase;
begin
stl := ff.Style;
if StrikeOutSpeedButton.Down then
Include(stl, fsStrikeOut)
else
Exclude(stl, fsStrikeOut);
if stl <> ff.Style then
begin
undoManager.SaveUndo;
changed := True;
ff.Style := stl;
needsupdate := True;
end;
end;
procedure TForm1.FontNamesComboBoxClick(Sender: TObject);
begin
if FontNamesComboBox.Items.IndexOf(FontNamesComboBox.Text) >= 0 then
begin
if FontNamesComboBox.Text <> ff.FontName then
begin
undoManager.SaveUndo;
changed := True;
ff.FontName := FontNamesComboBox.Text;
needsupdate := True;
end;
end;
end;
procedure TForm1.SmallerSpeedButtonClick(Sender: TObject);
begin
if ff.FontSize > MINFONTSIZE then
begin
undoManager.SaveUndo;
changed := True;
if ff.FontSize < 21 then
ff.FontSize := ff.FontSize - 1
else if ff.FontSize < 24 then
ff.FontSize := 20
else
ff.FontSize := ff.FontSize - 4;
if ff.FontSize > MAXFONTSIZE then
ff.FontSize := MAXFONTSIZE;
needsupdate := True;
end;
end;
procedure TForm1.BiggerSpeedButtonClick(Sender: TObject);
begin
if ff.FontSize < MAXFONTSIZE then
begin
undoManager.SaveUndo;
changed := True;
if ff.FontSize > 19 then
begin
ff.FontSize := ff.FontSize + 4;
if ff.FontSize > MAXFONTSIZE then
ff.FontSize := MAXFONTSIZE;
end
else
ff.FontSize := ff.FontSize + 1;
if ff.FontSize < MINFONTSIZE then
ff.FontSize := MINFONTSIZE;
needsupdate := True;
end;
end;
procedure TForm1.BackColorSpeedButtonClick(Sender: TObject);
begin
ColorDialog1.Color := ff.BackColor;
if ColorDialog1.Execute then
if ColorDialog1.Color <> ff.BackColor then
begin
undoManager.SaveUndo;
changed := True;
ff.BackColor := ColorDialog1.Color;
needsupdate := True;
end;
end;
procedure TForm1.FrontColorSpeedButtonClick(Sender: TObject);
begin
ColorDialog1.Color := ff.FrontColor;
if ColorDialog1.Execute then
if ColorDialog1.Color <> ff.FrontColor then
begin
undoManager.SaveUndo;
changed := True;
ff.FrontColor := ColorDialog1.Color;
needsupdate := True;
end;
end;
procedure TForm1.SelectFontSpeedButtonClick(Sender: TObject);
begin
ff.ToFont(FontDialog1.Font);
if FontDialog1.Execute then
begin
undoManager.SaveUndo;
changed := True;
ff.FromFont(FontDialog1.Font);
needsupdate := True;
end;
end;
procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
var
pt: TPoint;
r: TRect;
tick: int64;
begin
tick := GetTickCount;
if tick <= flastzoomwheel + MOUSEWHEELTIMEOUT then
Exit;
flastzoomwheel := tick;
pt := PaintBox1.Parent.ScreenToClient(MousePos);
r := PaintBox1.ClientRect;
if r.Right > ScrollBox1.Width then
r.Right := ScrollBox1.Width;
if r.Bottom > ScrollBox1.Height then
r.Bottom := ScrollBox1.Height;
if PtInRect(r, pt) then
ZoomOut1Click(Sender);
end;
procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
var
pt: TPoint;
r: TRect;
tick: int64;
begin
tick := GetTickCount;
if tick <= flastzoomwheel + MOUSEWHEELTIMEOUT then
Exit;
flastzoomwheel := tick;
pt := PaintBox1.Parent.ScreenToClient(MousePos);
r := PaintBox1.ClientRect;
if r.Right > ScrollBox1.Width then
r.Right := ScrollBox1.Width;
if r.Bottom > ScrollBox1.Height then