-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangles.Mod.txt
118 lines (103 loc) · 4.54 KB
/
Rectangles.Mod.txt
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
MODULE Rectangles; (*NW 25.2.90 / 18.4.2013*)
IMPORT SYSTEM, Display, Files, Input, Texts, Oberon, Graphics, GraphicFrames;
TYPE
Rectangle* = POINTER TO RectDesc;
RectDesc* = RECORD (Graphics.ObjectDesc)
lw*, vers*: INTEGER
END ;
VAR method*: Graphics.Method;
tack*, grey*: INTEGER;
PROCEDURE New*;
VAR r: Rectangle;
BEGIN NEW(r); r.do := method; Graphics.New(r)
END New;
PROCEDURE Copy(src, dst: Graphics.Object);
BEGIN dst.x := src.x; dst.y := src.y; dst.w := src.w; dst.h := src.h; dst.col := src.col;
dst(Rectangle).lw := src(Rectangle).lw; dst(Rectangle).vers := src(Rectangle).vers
END Copy;
PROCEDURE mark(f: GraphicFrames.Frame; col, x, y: INTEGER);
BEGIN GraphicFrames.ReplConst(f, col, x+1, y+1, 4, 4, 0)
END mark;
PROCEDURE Draw(obj: Graphics.Object; VAR M: Graphics.Msg);
VAR x, y, w, h, lw, col: INTEGER; f: GraphicFrames.Frame;
PROCEDURE draw(f: GraphicFrames.Frame; col, x, y, w, h, lw: INTEGER);
BEGIN
GraphicFrames.ReplConst(f, col, x, y, w, lw, Display.replace);
GraphicFrames.ReplConst(f, col, x+w-lw, y, lw, h, Display.replace);
GraphicFrames.ReplConst(f, col, x, y+h-lw, w, lw, Display.replace);
GraphicFrames.ReplConst(f, col, x, y, lw, h, Display.replace)
END draw;
BEGIN
CASE M OF GraphicFrames.DrawMsg:
x := obj.x + M.x; y := obj.y + M.y; w := obj.w; h := obj.h; f := M.f;
lw := obj(Rectangle).lw;
IF (x < f.X1) & (x+w > f.X) & (y < f.Y1) & (y+h > f.Y) THEN
IF M.col = Display.black THEN col := obj.col ELSE col := M.col END ;
IF M.mode = 0 THEN
draw(f, col, x, y, w, h, lw);
IF obj.selected THEN mark(f, Display.white, x, y) END
ELSIF M.mode = 1 THEN mark(f, Display.white, x, y) (*normal -> selected*)
ELSIF M.mode = 2 THEN mark(f, Display.black, x, y) (*selected -> normal*)
ELSIF M.mode = 3 THEN draw(f, Display.black, x, y, w, h, lw); mark(f, Display.black, x, y) (*erase*)
END
END
END
END Draw;
PROCEDURE Selectable(obj: Graphics.Object; x, y: INTEGER): BOOLEAN;
BEGIN
RETURN (obj.x <= x) & (x <= obj.x + 4) & (obj.y <= y) & (y <= obj.y + 4)
END Selectable;
PROCEDURE Change(obj: Graphics.Object; VAR M: Graphics.Msg);
VAR x0, y0, x1, y1, dx, dy: INTEGER; k: SET;
BEGIN
CASE M OF
Graphics.WidMsg: obj(Rectangle).lw := M.w |
Graphics.ColorMsg: obj.col := M.col
END
END Change;
PROCEDURE Read(obj: Graphics.Object; VAR R: Files.Rider; VAR C: Graphics.Context);
VAR b: BYTE; len: INTEGER;
BEGIN Files.ReadByte(R, b); (*len*);
Files.ReadByte(R, b); obj(Rectangle).lw := b;
Files.ReadByte(R, b); obj(Rectangle).vers := b;
END Read;
PROCEDURE Write(obj: Graphics.Object; cno: INTEGER; VAR W: Files.Rider; VAR C: Graphics.Context);
BEGIN Graphics.WriteObj(W, cno, obj); Files.WriteByte(W, 2);
Files.WriteByte(W, obj(Rectangle).lw); Files.WriteByte(W, obj(Rectangle).vers)
END Write;
(* PROCEDURE Print(obj: Graphics.Object; x, y: INTEGER);
VAR w, h, lw, s: INTEGER;
BEGIN INC(x, obj.x * 4); INC(y, obj.y * 4); w := obj.w * 4; h := obj.h * 4;
lw := obj(Rectangle).lw * 2; s := obj(Rectangle).vers;
Printer.ReplConst(x, y, w, lw);
Printer.ReplConst(x+w-lw, y, lw, h);
Printer.ReplConst(x, y+h-lw, w, lw);
Printer.ReplConst(x, y, lw, h);
IF s > 0 THEN Printer.ReplPattern(x, y, w, h, s) END
END Print; *)
PROCEDURE Make*; (*command*)
VAR x0, x1, y0, y1: INTEGER;
R: Rectangle;
G: GraphicFrames.Frame;
BEGIN G := GraphicFrames.Focus();
IF (G # NIL) & (G.mark.next # NIL) THEN
GraphicFrames.Deselect(G);
x0 := G.mark.x; y0 := G.mark.y; x1 := G.mark.next.x; y1 := G.mark.next.y;
NEW(R); R.col := Oberon.CurCol;
R.w := ABS(x1-x0); R.h := ABS(y1-y0);
IF x1 < x0 THEN x0 := x1 END ;
IF y1 < y0 THEN y0 := y1 END ;
R.x := x0 - G.x; R.y := y0 - G.y;
R.lw := Graphics.width; R.vers := 0; R.do := method;
Graphics.Add(G.graph, R);
GraphicFrames.Defocus(G); GraphicFrames.DrawObj(G, R)
END
END Make;
BEGIN NEW(method);
method.module := "Rectangles"; method.allocator := "New";
method.new := New; method.copy := Copy; method.draw := Draw;
method.selectable := Selectable; method.change := Change;
method.read := Read; method.write := Write; (*method.print := Print*)
tack := SYSTEM.ADR($0707 4122 1408 1422 4100$);
grey := SYSTEM.ADR($2004 0000 1111 1111 0000 0000 4444 4444 0000 0000$)
END Rectangles.