-
Notifications
You must be signed in to change notification settings - Fork 0
/
REDRAWOP.PAS
345 lines (326 loc) · 7.81 KB
/
REDRAWOP.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
Unit Redrawop;
Interface
Uses
Dos,Crt,Graph,Mousedrv,Majkvars;
procedure Redrawmenu;
procedure Refresh(barback : boolean);
procedure Savemenubar;
procedure Replacemenubar;
procedure Printonbar(strn : string; penst : shortint);
procedure Servkeys;
procedure Help;
Implementation
var
ply : array[0..7] of integer;
procedure Help;
var
srbuf : pointer;
srsiz : word;
begin
ply[0]:=(MAXX div 2)-(25*TEXTW);
ply[2]:=ply[0];
ply[4]:=(MAXX div 2)+(25*TEXTW);
ply[6]:=ply[4];
ply[1]:=(MAXY div 2)-TEXTH*3;
ply[3]:=(MAXY div 2)+TEXTH*2;
ply[5]:=ply[3];
ply[7]:=ply[1];
Setfillstyle(SOLIDFILL,0);
Mshow(FALSE);
srsiz:=Imagesize(ply[0],ply[1],ply[4],ply[3]);
Getmem(srbuf,srsiz);
Getimage(ply[0],ply[1],ply[4],ply[3],srbuf^);
Fillpoly(4,ply);
Outtextxy(ply[0]+5,ply[1]+5,HELPMSGS[mode,0]);
Outtextxy(ply[0]+5,ply[1]+5+TEXTH+3,HELPMSGS[mode,1]);
Outtextxy(ply[0]+5,ply[1]+5+((TEXTH+3)*2),HELPMSGS[mode,2]);
while (not Keypressed) do;
Putimage(ply[0],ply[1],srbuf^,NORMALPUT);
Freemem(srbuf,srsiz);
Mshow(TRUE);
end;
procedure Servkeys;
{
READS KEYBOARD, IF BACKSPACE HAS BEEN PRESSED THEN THE LAST OBJECT DRAWN IS
REMOVED BY DECREASING curobj
LOCALS : ch = CHAR READ FROM KEYBOARD
}
var
ch : char;
begin
ch :=Readkey;
case ch of
#0 : begin
ch :=Readkey;
if ch = #59 then Help;
end;
BKSPC : if (mode>1) then
begin
drawingchanged:=TRUE;
Sound(600);Delay(50);Nosound;
if curobj>0 then
begin
Dec(curobj);
Refresh(NOBAR);
end;
end;
end;
end;
procedure Savemenubar;
{
STORES MENUBAR IN A GLOBAL BUFFER
}
begin
Mshow(false);
barsiz :=Imagesize(0,0,BARRIGHT,BARBOT);
Getmem(barbuf,barsiz);
Getimage(0,0,BARRIGHT,BARBOT,barbuf^);
Mshow(true);
end;
procedure Replacemenubar;
{
PUTS THE MENUBAR BACK ONTO THE SCREEN
}
begin
Mshow(false);
Putimage(0,0,barbuf^,NORMALPUT);
Mshow(true);
end;
procedure Printonbar(strn : string; penst : shortint);
{
CLEARS THE MENUBAR AND PRINTS A STRING OVER IT, ALSO PEN STATE AND CURRENT OBJECT
IF REQUIRED
PARAMS : strn = STRING TO BE PRINTED
penst = STATUS OF PEN
LOCALS : curstr = OBJECT NUMBER STRING FOR PRINTING
}
var
curstr : string[30];
begin
Mshow(FALSE);
Setfillstyle(1,0);
Fillpoly(4,BARBOX);
Outtextxy(TEXTW*2,2,strn);
case penst of
PENON : Outtextxy(TEXTW*40,2,PENDMSG);
PENOFF : Outtextxy(TEXTW*40,2,PENUMSG);
NOPEN : ;
end;
curstr:='Object No='+I2S(curobj);
if penst<>NOPEN then Outtextxy(MAXX-Textwidth(curstr),2,curstr); {DISPLAYS OBJECT NUMBER IF REQUIRED}
Mshow(TRUE);
end;
procedure Refresh(barback : boolean);
{
REDRAWS ALL OBJECTS UP TO CURRENT OBJECT
LOCALS : a = COUNTER
}
var
a : word;
begin
Mshow(FALSE);
Mremove;
if not gridcall then
begin
options[3,0]:='Grid ON';
grdst :=FALSE;
end;
Cleardevice;
if curobj>0 then
for a:=0 to curobj-1 do
begin
case picobject[a].objectype of {SCAN ALL OBJECTS AND REDRAW THE ONES FOUND}
POINT : with picobject[a] do
Putpixel(Round(px*scale)+xoff,Round(py*scale)+yoff,MAXC);
LIN : with picobject[a] do
Line(Round(lx1*scale)+xoff,Round(ly1*scale)+yoff,
Round(lx2*scale)+xoff,Round(ly2*scale)+yoff);
ELLIPS : with picobject[a] do
Ellipse(Round(ex1*scale)+xoff,Round(ey1*scale)+yoff,
0,360,Round(ex2*scale),Round(ey2*scale));
RECT : with picobject[a] do
Rectangle(Round(rx1*scale)+xoff,Round(ry1*scale)+yoff,
Round(rx2*scale)+xoff,Round(ry2*scale)+yoff);
end;
end;
if barback then Replacemenubar;
Rectangle(0,0,MAXX,MAXY);
Mshow(TRUE);
end;
procedure Clear;
{
CLEARS ALL OBJECTS BY SETTING CUROBJ TO ZERO
}
begin
Printonbar('Are you sure about clearing the memory? LEFT = YES RIGHT = NO',NOPEN);
repeat until Mstatus<>0;
if regs.bx<>LEFTBUT then
begin
Replacemenubar;
exit;
end;
picobject[0].objectype :=NULL;
curobj :=0;
scale:=2;
drawingchanged:=false;
xoff:=EXOFF;
yoff:=EYOFF;
Refresh(BAR);
end;
procedure Zoom;
{
ALLOWS USER TO ZOOM IN ON OBJECTS
LOCALS : jump = STEP SIZE OF SCALE
count = COUNTS NUMBER OF JUMPS
pol = AREA TO CLEAR BY USING FILLPOLY TO PRINT STRING
prntstr = STRING TO PASS TO PRINTONBAR
ch = FOR READKEY
}
var
jump : real;
count : byte;
pol : array[0..7] of integer;
prntstr : string;
ch : char;
begin
mode:=7;
ch:=#255;
prntstr:='Zoom active. Escape Exit. Both buttons Refresh. Left Zoom Out. Right Zoom In.';
Mshow(FALSE);
jump:=0.01;
count:=1;
Mremove;
Printonbar(prntstr,NOPEN);
pol[0]:=50; pol[1]:=50;
pol[2]:=pol[0]+Textwidth('Scale=')+TEXTW*7; pol[3]:=pol[1];
pol[4]:=pol[2]; pol[5]:=pol[1]+TEXTH+4;
pol[6]:=pol[0]; pol[7]:=pol[5];
Mremove;
Fillpoly(4,pol);
Outtextxy(pol[0]+4,pol[1]+3,'Scale='+R2S(scale));
Mremove;
repeat
while (Mstatus=LEFTBUT) and (scale-jump>1) do
begin
scale:=scale-jump; {REDUCES SCALE}
Inc(count);
Mremove;
Fillpoly(4,pol);
Outtextxy(pol[0]+4,pol[1]+3,'Scale='+R2S(scale));
Mremove;
if count>10 then {EVERY 10TH INCREASE THE STEP SIZE IS DOUBLED}
begin
count:=1;
jump:=jump*2;
end;
end;
while (Mstatus=RIGHTBUT) and (scale+jump<100) do
begin
scale:=scale+jump; {INCREASES SCALE}
Inc(count);
Mremove;
Fillpoly(4,pol);
Outtextxy(pol[0]+4,pol[1]+3,'Scale='+R2S(scale));
Mremove;
if count>10 then
begin
count:=1;
jump:=jump*2;
end;
end;
count:=1;
jump:=0.01;
if Mstatus=BOTHBUT then
begin
Refresh(NOBAR);
Printonbar(prntstr,NOPEN);
Mremove;
Fillpoly(4,pol);
Outtextxy(pol[0]+4,pol[1]+3,'Scale='+R2S(scale));
Mremove;
end;
if Keypressed then ch:=Readkey;
if ch=#59 then Help;
until ch=ESC;
Refresh(BAR);
Mshow(TRUE);
Mremove;
end;
procedure Moveobj;
{
ALLOWS USER TO MOVE ALL OF THE OBJECTS AROUND THE SCREEN
LOCALS : step = DISTANCE TO OFFSET OBJECT BY
}
var
step : integer;
ch : char;
begin
mode:=8;
Printonbar('Move Active. Leftbutton to RECENTER, Rightbutton to EXIT.',NOPEN);
Mshow(FALSE);
Line((MAXX div 2)-20,MAXY div 2,(MAXX div 2)+20,MAXY div 2);
Line(MAXX div 2,(MAXY div 2)-15,MAXX div 2,(MAXY div 2)+15);
Mshow(TRUE);
repeat
if Mstatus=LEFTBUT then
begin
if regs.cx>exoff then
begin
step:=regs.cx-exoff;
Dec(xoff,step);
end
else
begin
step:=exoff-regs.cx;
Inc(xoff,step);
end;
if regs.dx>eyoff then
begin
step:=regs.dx-eyoff;
Dec(yoff,step);
end
else
begin
step:=eyoff-regs.dx;
Inc(yoff,step);
end;
Refresh(NOBAR);
Printonbar('Move Active. Leftbutton to RECENTER, Rightbutton to EXIT.',NOPEN);
Mshow(FALSE);
Line((MAXX div 2)-20,MAXY div 2,(MAXX div 2)+20,MAXY div 2);
Line(MAXX div 2,(MAXY div 2)-15,MAXX div 2,(MAXY div 2)+15);
Mshow(TRUE);
end;
if Keypressed then
begin
ch:=Readkey;
if ch=#59 then Help;
end;
until Mstatus=RIGHTBUT;
Refresh(BAR);
end;
procedure Normalize;
{
INCASE USER LOSES PICTURE THEN THIS PROCEDURE WITH THE SET SCALE AND OFFSETS TO DEFAULTS
}
begin
scale:=2;
xoff:=EXOFF;
yoff:=EYOFF;
Refresh(BAR);
end;
procedure Redrawmenu;
{
CONTROLLING PROCEDURE FOR REDRAW MENU
}
begin
case ono of
0 : Clear;
1 : Refresh(BAR);
2 : Zoom;
3 : Moveobj;
4 : Normalize;
end;
end;
end.