# Drawing Program in ICON # Written by Christopher Huyler link graphics record tool_record(type,x,y,w,h) global tools global current_tool record color_record(color,x,y,w,h) global colors global W procedure main() local radius,x,y,px,py,w,h,drag draw:=0 px:=py:=-10 current_tool := "circle" W := WOpen("size=512,384") | stop("*** cannot open window") WAttrib(W,"drawop=reverse") chdir("img") reset() repeat { case Event() of { "q"|"Q": break &lpress:{ every t := tools[1 to *tools] do { if (t.x <= &x <= t.x+t.w) & (t.y <= &y <= t.y+t.h) then current_tool := t.type } every c := colors[1 to *colors] do { if (c.x <= &x <= c.x+c.w) & (c.y <= &y <= c.y+c.h) then Fg(c.color) } if (72 <= &x <= 472) & (72 <= &y <= 372) then { draw := 1 WriteImage(W,"buff.bmp",72,72,400,300) case current_tool of { "pencil": {WAttrib(W,"drawop=copy");DrawRectangle(W,x:=&x,y:=&y,1,1);WAttrib(W,"drawop=reverse")} "circle": DrawCircle(W,x:=&x,y:=&y,radius:=0) "square": DrawRectangle(W,x:=&x,y:=&y,w:=0,h:=0) "line" : DrawLine(W,x:=&x,y:=&y,px:=&x+1,py:=&y+1) } } if (160 <= &x <= 224) & (24 <= &y <= 48) then reset() if (224 <= &x <= 288) & (24 <= &y <= 48) then if OpenDialog(W) == "Okay" then {WAttrib(W,"drawop=copy");ReadImage(W,dialog_value,72,72);WAttrib(W,"drawop=reverse")} if (288 <= &x <= 352) & (24 <= &y <= 48) then if SaveDialog(W) == "Yes" then WriteImage(W,dialog_value,72,72,400,300) if (44 <= &x <= 69) & (200 <= &y <= 225) then ReadImage(W,"buff.bmp",72,72) if (410 <= &x <= 474) & (24 <= &y <= 48) then break } &ldrag:{ if draw == 1 then case current_tool of { "pencil": {WAttrib(W,"drawop=copy") DrawLine(W,x,y,px:=&x,py:=&y) WAttrib(W,"drawop=reverse");x:=px;y:=py} "circle": {DrawCircle(W,x,y,radius) DrawCircle(W,x,y,radius:=sqrt((&x-x)^2+(&y-y)^2))} "square": {DrawRectangle(W,x,y,w,h) DrawRectangle(W,x,y,w:=&x-x,h:=&y-y)} "line" : {DrawLine(W,x,y,px,py) DrawLine(W,x,y,px:=&x,py:=&y)} } } &lrelease: { WAttrib(W,"drawop=copy") if draw == 1 then { draw := 0 case current_tool of { "circle": DrawCircle(W,x,y,radius) "square": FillRectangle(W,x,y,w+1,h+1) "square": DrawLine(W,x,y,px,py) } } WAttrib(W,"drawop=reverse") } }} end procedure reset() WAttrib(W,"drawop=copy") Fg("light gray") FillRectangle(W,0,0,512,384) Fg("gray") FillRectangle(W,69,69,406,306) Fg("very light gray") FillRectangle(W,72,72,403,303) Fg("white") FillRectangle(W,72,72,400,300) Fg("black") ReadImage(W,"tools.gif",44,72) ReadImage(W,"colors.gif",32,343) ReadImage(W,"buttons.gif",160,24) ReadImage(W,"undo.gif",44,200) ReadImage(W,"exit.gif",410,24) pencil := tool_record("pencil",44,72,25,25) circle := tool_record("circle",44,97,25,25) square := tool_record("square",44,122,25,25) line := tool_record("line",44,147,25,25) tools := [pencil,circle,square,line] colors := [color_record("black",32,343,15,15), color_record("blue",47,343,15,15), color_record("medium red",32,358,15,15), color_record("dark green",47,358,15,15)] WAttrib(W,"drawop=reverse") Clip(W,72,72,400,300) end