-
Notifications
You must be signed in to change notification settings - Fork 0
/
FControl.pas
149 lines (134 loc) · 3.45 KB
/
FControl.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
//******************************************************************************
// LBA Font Editor - editing lfn (font) files from Little Big Adventure 1 & 2
//
// FControl unit.
// Contains file opening/saving routines.
//
// Copyright (C) Zink
// e-mail: zink@poczta.onet.pl
// See the GNU General Public License (License.txt) for details.
//******************************************************************************
unit FControl;
interface
Uses Dialogs, Windows, SysUtils, Forms, Controls;
type
TCharImage = Record
Height, Width: Byte;
OffsetX, OffsetY: Byte;
Data: array of Record
LCount: Byte;
Lines: array of Byte;
end;
end;
const CharCount: Integer = 256;
var
LFont: Record
FileLen: DWord;
CharOffset: array[0..255] of DWord;
LChar: array[0..255] of TCharImage;
end;
CurrentFile: String;
procedure OpenFile(path: String);
procedure SaveFile(path: String);
Procedure CheckFileSave;
implementation
uses LBAFont1, Preview;
procedure OpenFile(path: String);
var f: File;
var a, b, c: Integer;
begin
AssignFile(f,path);
Reset(f,1);
With LFont do begin
For a:=0 to 255 do
BlockRead(f,CharOffset[a],4);
BlockRead(f,FileLen,4);
For a:=0 to 255 do begin
BlockRead(f,LChar[a].Width,1);
BlockRead(f,LChar[a].Height,1);
BlockRead(f,LChar[a].OffsetX,1);
BlockRead(f,LChar[a].OffsetY,1);
SetLength(LChar[a].Data,LChar[a].Height);
For b:=0 to LChar[a].Height-1 do begin
BlockRead(f,LChar[a].Data[b].LCount,1);
SetLength(LChar[a].Data[b].Lines,LChar[a].Data[b].LCount);
For c:=0 to LChar[a].Data[b].LCount-1 do
BlockRead(f,LChar[a].Data[b].Lines[c],1);
end;
end;
CloseFile(f);
Form1.CharScr.Max:=1600;
Form1.CharScr.PageSize:=Form1.CharPB.Height+1;
Form1.CharScr.Position:=0;
Form1.CharScr.Enabled:=True;
Form1.aEdit.Enabled:=True;
Form1.CharPB.Visible:=True;
PaintChars;
ShowChars(0);
UpdatePanels;
end;
Form1.Label1.Hide;
Form1.Caption:='LBA Font Editor - '+ExtractFileName(Path);
Form1.aSave.Enabled:=True;
Form1.aSaveAs.Enabled:=True;
Form1.aReload.Enabled:=True;
Form1.aPreview.Enabled:=True;
Form1.Panel1.Visible:=False;
PaintPreview;
CurrentFile:=Path;
Beep;
end;
Procedure CalcOffsets;
var a, b: Byte;
Off: DWord;
begin
Off:=1028;
For a:=0 to 255 do begin
LFont.CharOffset[a]:=Off;
Inc(Off,4);
For b:=0 to Length(LFont.LChar[a].Data)-1 do
Inc(Off,LFont.LChar[a].Data[b].LCount+1);
end;
LFont.FileLen:=Off;
end;
procedure SaveFile(path: String);
var a, b, c: Integer;
F1: File;
begin
Screen.Cursor:=crHourGlass;
CalcOffsets;
AssignFile(F1,path);
Rewrite(F1,1);
With LFont do begin
For a:=0 to 255 do
BlockWrite(F1,CharOffset[a],4);
BlockWrite(F1,FileLen,4);
For a:=0 to 255 do begin
BlockWrite(F1,LChar[a].Width,1);
BlockWrite(F1,LChar[a].Height,1);
BlockWrite(F1,LChar[a].OffsetX,1);
BlockWrite(F1,LChar[a].OffsetY,1);
For b:=0 to LChar[a].Height-1 do begin
BlockWrite(F1,LChar[a].Data[b].LCount,1);
For c:=0 to LChar[a].Data[b].LCount-1 do
BlockWrite(F1,LChar[a].Data[b].Lines[c],1);
end;
end;
CloseFile(F1);
end;
Screen.Cursor:=crArrow;
Form1.label1.Hide;
Form1.Caption:='LBA Font Editor - '+ExtractFileName(Path);
CurrentFile:=Path;
Beep;
end;
Procedure CheckFileSave;
begin
If Form1.Label1.Visible then
Case MessageBox(Form1.Handle,'The file has been modified. Do you want to save changes?','LBA Font Editor',MB_ICONQUESTION+MB_YESNOCANCEL)
of
IDYES:Form1.aSave.Execute;
IDCANCEL:Abort;
end;
end;
end.