|
|
|
program SimplePaint;
uses Types, QuickDraw, Events;
const
BRUSHSIZE = 10;
var
i, x, y: Integer;
mouse: Point;
r, closeBox, clearBox, tbar: Rect;
colors: array[0..15] of Rect;
{ Draw screen }
procedure drawScreen;
begin
{ Draw title bar }
clearScreen(black);
setSolidPenPat(white);
setRect(tbar, 0, 0, 319, 20);
paintRect(tbar);
{ Draw close box }
setSolidPenPat(black);
setRect(closeBox, 5, 5, 15, 15);
frameRect(closeBox);
{ Draw clear box }
moveTo(21, 12);
setForeColor(black);
setBackColor(white);
drawString('c');
setRect(clearBox, 20, 5, 30, 15);
frameRRect(clearBox, 5, 5);
{ Draw color bar }
for i := 0 to 15 do begin
setRect(colors[i], 35 + i * 10, 5, 35 + i * 10 + 10, 15);
setSolidPenPat(i);
paintRect(colors[i]);
setSolidPenPat(0);
frameRect(colors[i]);
end;
{ Draw title }
moveTo(205, 13);
setForeColor(9);
setBackColor(4);
drawString(' Simple Paint ');
setSolidPenPat(white);
end;
{ Draw dots }
procedure drawDots(x, y: Integer);
var
ox, oy, ix, iy: Integer;
begin
while button(0) do begin
getMouse(mouse);
if not PtInRect(mouse, tbar) then begin
ox := x;
oy := y;
x := mouse.h;
y := mouse.v;
ix := (ox + x) div 2;
iy := (oy + y) div 2;
setRect(r, ix, iy, ix + BRUSHSIZE, iy + BRUSHSIZE);
paintOval(r);
setRect(r, x, y, x + BRUSHSIZE, y + BRUSHSIZE);
paintOval(r);
end;
end;
end;
begin
graphics(320);
drawScreen;
while true do begin
if button(0) then begin
getMouse(mouse);
{ Set color }
for i := 0 to 15 do begin
if ptInRect(mouse, colors[i]) then
setSolidPenPat(i);
end;
{ Perform mouse action }
if ptInRect(mouse, closeBox) then
halt
else if ptInRect(mouse, clearBox) then begin
drawScreen;
cycle;
end
else
drawDots(mouse.h, mouse.v);
end;
end;
end. |
|