Constant STORY "GPaint"; Constant HEADLINE "^GREX drawing tool^By L. Ross Raszewski"; ! Include Gwindows Definitions include "gwindefs"; include "parser"; include "verblib"; ! Include GWindows base classes include "gwincls"; !include "gconsole"; ! Include GWindows hooks include "gwindows"; include "grammar"; include "grex"; include "gchar"; include "gmenu"; include "gigrid"; ! InitGWindows. This is where you set up the active interface and the ! main window [ InitGWindows; Active_UI=top; Main_GWindow=mainwin; ]; global activebtn=llb; global clr = 0; class clrbtn with select [; clr=self.number; ]; object clr_pal; clrbtn -> with number 0; clrbtn -> with number $ff; clrbtn -> with number $ff00; clrbtn -> with number $ff0000; clrbtn -> with number $f0f0f0; clrbtn -> with number $0fffff; clrbtn -> with number $ff00ff; clrbtn -> with number $00ffff; clrbtn -> with number $ffff00; clrbtn -> with number $ffffff; WindowPair top; WIndowPair -> mainarea; WIndowPair -> -> btm; Textbuffer -> -> -> mainwin; GImageGrid -> -> -> with rows 1, cols 10, current_map clr_pal, split 10, split_dir winmethod_Above, redraw [ i; self.columnwidth=self.width/self.cols; self.rowheight=self.height/self.rows; self.last=self.start+(self.rows*self.cols); for(i=0;i<10;i++) glk_window_fill_rect(self.winid,scion(self.current_map,i+1).number,(i*(self.width/10)), 0,((i+1)*(self.width/10)), self.height); ], has on; GCanvas -> -> grxwin with split 70, split_dir winmethod_Above, click_event [x y; glk_window_fill_rect(self.winid,0,x-1,y-2,2,2); ! print x, ",", y, "^"; x=(x*self.scale_width)/self.width; y=(y*self.scale_height)/self.height; ! print x, ",", y, "^^"; activebtn.senddata(x,y); ], has on; GMenu -> menuwin with split 25, split_dir winmethod_left; class drawnline(100) class Grex_Line; class drawnpoint(500) class Grex_Point; class drawnbox(100) class Grex_Box; class drawnrect(100) class GREX_Rectangle; class drawntext(100) class Grex_String, with buffr 0 0 0 0 0 0 0 0 0, renderer Grex_Default_Renderer, text [i; for(i=0;i0;i++) print (char) self.&buffr->(WORDSIZE+i); ], create [done x; glk_set_window(gg_mainwin); glk_cancel_line_event(gg_mainwin,0); print "Enter text:"; glk_request_line_event(gg_mainwin, self.&buffr+WORDSIZE,8*WORDSIZE,0); while(~~done) { glk($00C0, gg_event); ! select switch(gg_event-->0) { 5, evtype_Arrange: ! evtype_Arrange DrawStatusLine(); 3: ! evtype_LineInput self.&buffr-->0= gg_event-->2; done=1; evtype_MouseInput: x=FindWindowByWinid(gg_event-->1); gwindows_request_mouse_event(x); evtype_CharInput: x=FindWIndowByWinid(gg_event-->1); gwindows_request_char_event(x); } } glk($00D0, gg_mainwin, buffer+WORDSIZE, INPUT_BUFFER_LEN-WORDSIZE, 0); ! request_line_event ]; class drawbtn with short_name [; if (self==activebtn) print (char) '*'; rfalse; ], select [; activebtn=self; GW_ForceRedraw(menuwin); ]; global thk=1; class twopt class drawbtn with myx, myy, myclass, senddata [ x y o; if (self hasnt general) { give self general; self.myx=x; self.myy=y; } else { give self ~general; o=self.myclass.create(); if (o) { if (o provides thickness) o.thickness=thk; o.xpos = self.myx; o.ypos=self.myy; o.width=x-self.myx; o.col=clr; o.height=y-self.myy; if (o provides endx) { o.endx=x; o.endy=y; } pmove (o,grxwin); } GW_ForceRedraw(grxwin); } ]; Object mc; twopt -> "Rectangle" with myclass drawnrect; twopt -> "Box" with myclass drawnbox; twopt -> llb "Line" with myclass DrawnLine; twopt -> "Text" with myclass drawntext; object -> "Point" with senddata [x y o; o=DrawnPoint.create(); o.xpos=x; o.ypos=y; o.col=clr; pmove(o,grxwin); ]; object -> "Thicker" with select [; thk++; ]; object -> "Thinner" with select [; if (thk >1) thk--; ]; [ Initialise; menuwin.activate(mc); "^^^"; ];