-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathASCIITab.Mod
301 lines (283 loc) · 8.02 KB
/
ASCIITab.Mod
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
(* OBERON System 3, Release 2.3.
Copyright 1999 ETH Zürich Institute for Computer Systems,
ETH Center, CH-8092 Zürich. e-mail: [email protected].
This module may be used under the conditions of the general Oberon
System 3 license contract. The full text can be downloaded from
"ftp://ftp.inf.ethz.ch/pub/software/Oberon/System3/license.txt;A"
Under the license terms stated it is in particular (a) prohibited to modify
the interface of this module in any way that disagrees with the style
or content of the system and (b) requested to provide all conversions
of the source code to another platform with the name OBERON. *)
MODULE ASCIITab; (** portable *) (* EJZ, *)
IMPORT Files, Objects, Display, Printer, Fonts, Texts, Display3, Printer3, Effects, Oberon, Gadgets;
CONST
middle = 1;
TYPE
Frame* = POINTER TO FrameDesc;
FrameDesc* = RECORD (Gadgets.FrameDesc)
font: Fonts.Font
END;
VAR
W: Texts.Writer;
PROCEDURE Restore(F: Frame; Q: Display3.Mask; x, y, w, h: INTEGER);
VAR
pat: Display.Pattern;
i, j, x0, y0, dx, cx, cy, cw, ch, dw, dh: INTEGER;
BEGIN
Display3.ReplConst(Q, Display3.textbackC, x, y, w, h, Display.replace);
x0 := x; y0 := y;
dw := F.font.maxX-F.font.minX;
cw := (F.W-1) DIV 32;
IF cw > dw THEN
dw := cw
END;
x := x+(F.W-32*dw) DIV 2;
dh := F.font.height;
ch := (F.H-1) DIV 8;
IF ch > dh THEN
dh := ch
END;
y := y+(F.H-8*dh) DIV 2;
FOR i := 0 TO 31 DO
FOR j := 0 TO 7 DO
Fonts.GetChar(F.font, CHR(i+32*j), dx, cx, cy, cw, ch, pat);
Display3.CopyPattern(Q, Display.FG, pat, x+i*dw+(dw-cw) DIV 2, y+(7-j)*dh+(dh-ch) DIV 2, Display.paint)
END
END;
FOR i := 0 TO 32 DO
Display3.ReplConst(Q, Display3.black, x+i*dw, y, 1, 8*dh, Display.replace)
END;
FOR j := 0 TO 8 DO
Display3.ReplConst(Q, Display3.black, x, y+j*dh, 32*dw, 1, Display.replace)
END;
IF Gadgets.selected IN F.state THEN
Display3.FillPattern(Q, Display3.white, Display3.selectpat, x0, y0, x0, y0, w, h, Display.paint)
END
END Restore;
PROCEDURE Print (F: Frame; VAR M: Display.DisplayMsg);
VAR
Q: Display3.Mask;
pat: Display.Pattern;
x, y, w, h: INTEGER;
i, j, x0, y0, dx, cx, cy, cw, ch, dw, dh: INTEGER;
str: ARRAY 2 OF CHAR;
PROCEDURE P(x: INTEGER): INTEGER;
BEGIN
RETURN SHORT(x * Display.Unit DIV Printer.Unit)
END P;
BEGIN
Gadgets.MakePrinterMask(F, M.x, M.y, M.dlink, Q);
x := M.x; y := M.y; w := P(F.W); h := P(F.H);
Printer3.ReplConst(Q, Display3.textbackC, x, y, w, h, Display.replace);
x0 := x; y0 := y;
dw := F.font.maxX-F.font.minX;
cw := (F.W-1) DIV 32;
IF cw > dw THEN
dw := cw
END;
x := x+P((F.W-32*dw) DIV 2);
dh := F.font.height;
ch := (F.H-1) DIV 8;
IF ch > dh THEN
dh := ch
END;
y := y+P((F.H-8*dh) DIV 2);
FOR i := 0 TO 31 DO
FOR j := 0 TO 7 DO
Fonts.GetChar(F.font, CHR(i+32*j), dx, cx, cy, cw, ch, pat);
str[0] := CHR(i+32*j); str[1] := 0X;
Printer3.String(Q, Display.FG, x+P(i*dw+(dw-cw) DIV 2), y+P((7-j)*dh+(dh-ch) DIV 2), F.font, str, Display.paint)
END
END;
FOR i := 0 TO 32 DO
Printer3.ReplConst(Q, Display3.black, x+P(i*dw), y, P(1), P(8*dh), Display.replace)
END;
FOR j := 0 TO 8 DO
Printer3.ReplConst(Q, Display3.black, x, y+P(j*dh), P(32*dw), P(1), Display.replace)
END;
IF Gadgets.selected IN F.state THEN
Printer3.FillPattern(Q, Display3.white, Display3.selectpat, x0, y0, x0, y0, w, h, Display.paint)
END
END Print;
PROCEDURE Track(F: Frame; VAR M: Oberon.InputMsg; x, y: INTEGER);
VAR
w, h, i, j: INTEGER;
keysum: SET;
Q: Display3.Mask;
Ca: Oberon.CaretMsg;
BEGIN
Gadgets.MakeMask(F, x, y, M.dlink, Q);
w := F.font.maxX-F.font.minX;
IF ((F.W-1) DIV 32) > w THEN
w := (F.W-1) DIV 32
END;
x := x+(F.W-32*w) DIV 2;
h := F.font.height;
IF ((F.H-1) DIV 8) > h THEN
h := (F.H-1) DIV 8
END;
y := y+(F.H-8*h) DIV 2;
i := (M.X-x) DIV w;
j := (M.Y-y) DIV h;
Oberon.RemoveMarks(x+i*w, y+j*h, w+1, h+1);
Display3.ReplConst(Q, Display.FG, x+i*w, y+j*h, w+1, h+1, Display.invert);
keysum := M.keys;
REPEAT
Effects.TrackMouse(M.keys, M.X, M.Y, Effects.Arrow);
Oberon.RemoveMarks(x+i*w, y+j*h, w+1, h+1);
Display3.ReplConst(Q, Display.FG, x+i*w, y+j*h, w+1, h+1, Display.invert);
i := (M.X-x) DIV w;
j := (M.Y-y) DIV h;
IF i < 0 THEN
i := 0
ELSIF i > 31 THEN
i := 31
END;
IF j < 0 THEN
j := 0
ELSIF j > 7 THEN
j := 7
END;
Oberon.RemoveMarks(x+i*w, y+j*h, w+1, h+1);
Display3.ReplConst(Q, Display.FG, x+i*w, y+j*h, w+1, h+1, Display.invert);
keysum := keysum + M.keys
UNTIL M.keys = {};
Oberon.RemoveMarks(x+i*w, y+j*h, w+1, h+1);
Display3.ReplConst(Q, Display.FG, x+i*w, y+j*h, w+1, h+1, Display.invert);
M.res := 0;
IF keysum = {middle} THEN
Ca.id := Oberon.get;
Ca.car := NIL;
Ca.F := NIL;
Ca.text := NIL;
Ca.pos := 0;
Ca.res := -1;
Display.Broadcast(Ca);
IF Ca.text # NIL THEN
Texts.SetFont(W, F.font);
Texts.Write(W, CHR(i+(7-j)*32));
Texts.Insert(Ca.text, Ca.pos, W.buf);
Ca.F := Ca.car;
Ca.id := Oberon.set;
INC(Ca.pos);
Display.Broadcast(Ca)
END
END
END Track;
PROCEDURE CopyFrame(VAR M: Objects.CopyMsg; F, F1: Frame);
BEGIN
Gadgets.CopyFrame(M, F, F1);
F1.font := F.font
END CopyFrame;
PROCEDURE Handle*(F: Objects.Object; VAR M: Objects.ObjMsg);
VAR
x, y, w, h: INTEGER;
Q: Display3.Mask;
name: ARRAY 32 OF CHAR;
copy: Frame;
BEGIN
WITH F: Frame DO
IF M IS Display.FrameMsg THEN
WITH M: Display.FrameMsg DO
IF (M.F = NIL) OR (M.F = F) THEN
x := M.x + F.X;
y := M.y + F.Y;
w := F.W;
h := F.H;
IF M IS Display.DisplayMsg THEN
WITH M: Display.DisplayMsg DO
IF M.device = Display.screen THEN
IF (M.id = Display.full) OR (M.F = NIL) THEN
Gadgets.MakeMask(F, x, y, M.dlink, Q);
Restore(F, Q, x, y, w, h)
ELSIF M.id = Display.area THEN
Gadgets.MakeMask(F, x, y, M.dlink, Q);
Display3.AdjustMask(Q, x + M.u, y + h - 1 + M.v, M.w, M.h);
Restore(F, Q, x, y, w, h)
END
ELSIF M.device = Display.printer THEN
Print(F, M)
END
END
ELSIF M IS Oberon.InputMsg THEN
WITH M: Oberon.InputMsg DO
IF (M.id = Oberon.track) & Gadgets.InActiveArea(F, M) & (M.keys = {middle}) THEN
Track(F, M, x, y)
ELSE
Gadgets.framehandle(F, M)
END
END
ELSE
Gadgets.framehandle(F, M)
END
END
END
ELSIF M IS Objects.AttrMsg THEN
WITH M: Objects.AttrMsg DO
IF M.id = Objects.get THEN
IF M.name = "Gen" THEN
M.class := Objects.String;
M.s := "ASCIITab.NewFrame";
M.res := 0
ELSIF M.name = "Font" THEN
M.class := Objects.String;
M.s := F.font.name;
M.res := 0
ELSE
Gadgets.framehandle(F, M)
END
ELSIF M.id = Objects.set THEN
IF (M.class = Objects.String) & (M.name = "Font") THEN
F.font := Fonts.This(M.s);
M.res := 0
ELSE
Gadgets.framehandle(F, M)
END
ELSIF M.id = Objects.enum THEN
Gadgets.framehandle(F, M);
M.Enum("Font");
M.res := 0
END
END
ELSIF M IS Objects.CopyMsg THEN
WITH M: Objects.CopyMsg DO
IF M.stamp = F.stamp THEN
M.obj := F.dlink
ELSE
NEW(copy);
F.stamp := M.stamp;
F.dlink := copy;
CopyFrame(M, F, copy);
M.obj := copy
END
END
ELSIF M IS Objects.FileMsg THEN
WITH M: Objects.FileMsg DO
Gadgets.framehandle(F, M);
IF M.id = Objects.store THEN
Files.WriteString(M.R, F.font.name)
ELSIF M.id = Objects.load THEN
Files.ReadString(M.R, name);
F.font := Fonts.This(name)
END
END
ELSE
Gadgets.framehandle(F, M)
END
END
END Handle;
PROCEDURE NewFrame*;
VAR F: Frame;
BEGIN
NEW(F);
F.font := Fonts.Default;
F.W := 32*(4+F.font.maxX-F.font.minX)+1;
F.H := 8*(2+F.font.height)+1;
F.handle := Handle;
Objects.NewObj := F
END NewFrame;
BEGIN
Texts.OpenWriter(W)
END ASCIITab.Text
Gadgets.Insert ASCIITab.NewFrame ~
System.Free ASCIITab ~