'{mandatory GUI config Option Base 0 Const cGy=&hdddddd'Pale grey screen background Dim Integer Objs=20,P=0,Flags,Xt,Yt,CMM2 Dim Integer O(Objs,10)'GUI object settings Dim String Ot(Objs) Length 64'GUI object text Colour 0,cGy:Cls 'CMM2 Compatibility - and any others if necessary Select Case MM.Device$ Case "Colour Maximite 2" mp=MM.info(option mouse) ' mouse port CMM2=1 Option Console Serial GUI CURSOR ON 0, 100,100,rgb(red) CONTROLLER MOUSE OPEN mp Case Else End Select '}
=GUIObjDef(21,1,10,10,80,30,"Save";,,,1)
=GUIObjDef(40,2,170,100,0,0,"Red",4800,&hff0000)
=GUIObjDef(61,8,10,210,300,20,"",0,5000,&h0000ff02)
=GUIObjPSet(21,&b00001100)
=GUIObjPSet(40,&b00001000)
Result=GUIObjPSet(myObj,GUIObjPGet(myObj) OR &b00000100)
Result=GUIObjPSet(myObj,GUIObjPGet(myObj) AND&b11111011)
=GUIObjPGet(21) AND &b00010000
Ot(GUIObjFind(id))="New Text" GUIObjDraw id
Ot(GUIObjFind(id))="New Text" GUIObjDraw(id)
'V0.68 '{mandatory GUI config Option Base 0 Const CGy=&hdddddd,Cgh=&h909090'Pale grey screen background Colour 0,cGy:Cls Dim Integer Objs=20,P=0,Flags,Xt,Yt,CMM2 Dim Integer O(Objs,10)'GUI object settings Dim String Ot(Objs) Length 63'GUI object text 'CMM2 Compatibility - and any others if necessary Select Case MM.Device$ Case "Colour Maximite 2" mp=MM.info(Option Mouse) ' mouse port CMM2=1 Option Console Serial GUI Cursor On 0, 100,100,rgb(red) Controller Mouse Open mp Case Else End Select '} Backlight 80' 100 is off MainInit: Dim Integer res 'Buttons res=GUIObjDef(21,1,10,10,80,30,"Save",&hff0000,&hffffff,1) res=GUIObjDef(23,1,10,50,80,30,"Exit",,,1) 'Checkboxes res=GUIObjDef(25,3,10,100,,,"Checked") res=GUIObjDef(27,3,10,120,,,"Disabled") res=GUIObjDef(29,3,10,140,,,"Not Checked") 'Radio boxes (in a frame) res=GUIObjDef(40,2,170,100,,,"Red",1,&hff0000) 'res=GUIObjDef(40,2,170,100,,,"Red",1,0) res=GUIObjDef(41,2,170,120,,,"Green",1,&hff00) 'res=GUIObjDef(41,2,170,120,,,"Green",1,0) res=GUIObjDef(42,2,170,140,,,"Blue",1,&hff) 'res=GUIObjDef(42,2,170,140,,,"Blue",1,0) res=GUIObjDef(39,9,165,90,80,65,"Colours",,,&h05) 'text boxes res=GUIObjDef(50,5,160,10,150,15,"L Text black frame",&h00aa00,&hffff00,&h04) res=GUIObjDef(51,5,160,35,150,15,"C Text no frame",cGy,0,&h10) res=GUIObjDef(52,5,160,60,150,15,"",&hffffff,0,&h22) 'progress bar res=GUIObjDef(61,8,10,210,300,20,"",0,500,&h0000ff02) res=GUIObjDef(62,8,270,90,40,65,"",0,500,&hff000012) 'Slider res=GUIObjDef(71,4,20,180,100,,"",0,500,51) Main: 'set the properties of the object, visibility, enabled etc... res=GUIObjPSet(21,&b00001100) res=GUIObjPSet(23,&b00001000) res=GUIObjPSet(25,&b00101100) res=GUIObjPSet(27,&b00101000) res=GUIObjPSet(29,&b00001100) res=GUIObjPSet(39,&b00001100) res=GUIObjPSet(40,&b00101100) res=GUIObjPSet(41,&b00001100) res=GUIObjPSet(42,&b00001000) res=GUIObjPSet(50,&b00001100) res=GUIObjPSet(51,&b00001100) res=GUIObjPSet(52,&b00001100) res=GUIObjPSet(61,&b00001100) res=GUIObjPSet(62,&b00001100) res=GUIObjPSet(71,&b00001100) 'nothing appears on the screen until you draw the object 'this allows multiple updates at once and you control when it happens GUIObjDraw 21 GUIObjDraw 23 GUIObjDraw 25 GUIObjDraw 27 GUIObjDraw 29 GUIObjDraw 39 GUIObjDraw 40 GUIObjDraw 41 GUIObjDraw 42 GUIObjDraw 50 GUIObjDraw 51 GUIObjDraw 52 GUIObjDraw 61 GUIObjDraw 62 GUIObjVSet 71,250 GUIObjDraw 71 'a little example code q=1000 If res <>-1 Then timer=0 'draw the progress bars for increasing value For n=1 To q step 25 GUIObjVSet 61,n GUIObjDraw 61 GUIObjVSet 62,q-n GUIObjDraw 62 Next 'set the contents of a text box Ot(GUIObjFind(52))="R "+Str$(timer/n)+"mS" GUIObjDraw 52 EndIf 'go round in a loop printing (to the console) the ID (numeric name) of 'any touched objects and how long it was touched for Do Timer=0 q=ProcessTouch() If q<>-1 Then ? "Obj ";q,,"Dwell";Timer;"mS" 'get the value from the slider and update a text box If q=71 Then For m=50 to 52 'Ot(GUIObjFind(m))=Str$(GUIObjVGet(71)):GUIObjDraw m Next EndIf Pause 100 Loop End '------------------ The GUI pack 'Main touch processor. Regular calls here will get the numeric name of 'screen objects that are touched, return -1 if no object is touched 'animates and manages status etc Function ProcessTouch() As Integer ProcessTouch=-1 GetTouch If Xt=-1 Then Exit Function Local Integer n,m For n=0 To P-1 If Xt>=O(n,3) Then If Yt>=O(n,4) Then If Xt<=O(n,5) Then If Yt<=O(n,6) Then If O(n,2) And 8 Then If O(n,2) And 4 Then ProcessTouch=O(n,0) O(n,2)=O(n,2) Or &b00010000'touched Select Case O(n,1)'click animation Case 1 O(n,9)=2 GUIObjDraw O(n,0) Case 2 For m=0 To P If O(n,0)<>O(m,0) Then If O(m,1)=2 Then If O(m,7)=O(n,7) Then O(m,2)=O(m,2) And &b11011111 GUIObjDraw O(m,0) EndIf EndIf EndIf Next O(n,2)=O(n,2) Or &h20 GUIObjDraw O(n,0) Case 3 If O(n,2) And &b00100000 Then O(n,2)=O(n,2) And &b11011111 Else O(n,2)=O(n,2) Or &b00100000 EndIf GUIObjDraw O(n,0) Case 4'slider Local w If CMM2 Then GUI Cursor Hide Do 'Watchdog in here GetTouch If Xt=-1 Then Exit Do w=O(n,5)-O(n,3) Xt=Constrain(Xt-O(n,3),0,w) w=Xt/(w/(O(n,8)-O(n,7))) GUIObjVSet O(n,0),w If O(n,9) Then Ot(GUIObjFind(O(n,9)))=Str$(w):GUIObjDraw O(n,9) EndIf GUIObjDraw O(n,0) Loop If CMM2 Then GUI Cursor Show Case 6 Case 7 End Select WaitNoTouch Select Case O(n,1)'release animation Case 1 O(n,9)=1 GUIObjDraw O(n,0) Case 6 Case 7 End Select Exit Function EndIf EndIf EndIf EndIf EndIf EndIf Next End Function 'waits for the stylus to be lifted off the panel Sub WaitNoTouch If CMM2 Then Do 'Watchdog here if you want it Pause 10 Loop Until Mouse(L,mp)=0 Else Do 'Watchdog here if you want it Pause 10 Loop Until Touch(X)=-1 EndIf End Sub 'Sub will draw any object in it's current state Sub GuiObjDraw(id As Integer) Local Integer n,m,x,y,z,w,h Local Float nn Local a$ n=GUIObjFind(id) If n>-1 Then GUIObjCleanup n x=O(n,3):y=O(n,4) w=O(n,5)-x:h=O(n,6)-y Select Case O(n,1) Case 1'button If O(n,2) And 8 Then'visible Box x,y,w,h,,O(n,7),O(n,7) GUIFrame n,0 If O(n,2) And 4 Then'Enabled z=O(n,8) Else'ghosted z=Cgh EndIf Text w/2+x-FW()*Len(Ot(n))/2,h/2+y-FH()/2,Ot(n),,,,z,O(n,7) Else'erase GUIObjCleanup n,1 EndIf Case 2'radio If O(n,2) And 8 Then'visible x=x+5:y=y+5 If O(n,2) And 4 Then'Enabled If O(n,2) And 32 Then'set Circle x,y,4,,,O(n,8),O(n,8) Colour 0:For nn=2.34 To 5.5 Step 0.2:Pixel x+6*Sin(nn),y+6*Cos(nn):Next Colour &hffffff:For nn=5.5 To 8.64 Step 0.2:Pixel x+6*Sin(nn),y+6*Cos(nn):Next Else Circle x,y,4,,,CGy,CGy Colour &hffffff:For nn=2.34 To 5.5 Step 0.2:Pixel x+6*Sin(nn),y+6*Cos(nn):Next Colour 0:For nn=5.5 To 8.64 Step 0.2:Pixel x+6*Sin(nn),y+6*Cos(nn):Next EndIf Colour 0 Else Circle x,y,4,,,CGy,CGy Colour Cgh:For nn=0 To 6.4 Step 0.2:Pixel x+6*Sin(nn),y+6*Cos(nn):Next EndIf Text x+15,y+(h/2)-FH(),Ot(n) Else'erase GUIObjCleanup n,1 EndIf Case 3'checkbox If O(n,2) And 8 Then'visible Colour 0:Line x,y,x,y+11:Line x,y,x+11,y:Colour &hffffff:Line x+11,y,x+11,y+11:Line x+11,y+11,x,y+11 If O(n,2) And 4 Then'Enabled Colour 0 Else'ghosted Colour Cgh EndIf If O(n,2) And 32 Then'checked GUI Bitmap x+2,y+2,&h18386C6CC6020301 Else GUI Bitmap x+2,y+2,0 EndIf Text x+15,y+(h/2)-(FH()/2),Ot(n) Else'erase GUIObjCleanup n,1 EndIf Case 4'slider If O(n,2) And 8 Then'visible Box x-5,y,w+11,h+1,,CGY,CGy y=y+(h/2) Colour 0:Line x,y-2,x+w,y-2:Line x,y-2,x,y+2:Colour &hffffff:Line x,y+2,x+w,y+2:Line x+w,y+2,x+w,y-2: x=x+((w/(O(n,8)-O(n,7)))*O(n,10)) y=O(n,4) 'pointer If O(n,2) And 4 Then'Enabled Box x-5,y,11,h,,CGY,CGy Colour 0:Line x+5,y+3,x+5,y+h:Line x+5,y+h,x-5,y+h:Colour Cgh:Line x,y,x+5,y+3:Colour &hffffff:Line x-5,y+h,x-5,y+3:Line x-5,y+3,x,y Else Box x-5,y,11,h,,CGY,CGy Colour Cgh:Line x+5,y+3,x+5,y+h:Line x+5,y+h,x-5,y+h:Line x,y,x+5,y+3:Line x-5,y+h,x-5,y+3:Line x-5,y+3,x,y EndIf Else'erase GUIObjCleanup n,1 EndIf Case 5'textbox If O(n,2) And 8 Then'visible Box x,y,w+1,h+1,,O(n,7),O(n,7) GUIFrame n,1 Select Case O(n,9)>>4 Case 0'L Text x,y,Ot(n),,,,O(n,8),O(n,7) Case 1'C Text w/2+x-FW()*Len(Ot(n))/2,h/2+y-FH()/2,Ot(n),,,,O(n,8),O(n,7) Case 2'R Text O(n,5)-(FW()*Len(Ot(n))),h/2+y-FH()/2,Ot(n),,,,O(n,8),O(n,7) End Select Else'erase GUIObjCleanup n,1 EndIf Case 6'list static Case 7'list dropdown Case 8'progress bar If O(n,2) And 8 Then'visible GUIFrame n,1 If O(n,9) And &h10 Then'vert z=(h/(O(n,8)-O(n,7)))*O(n,10) Box x,y,w,h-z,,cGy,cGy Box x,(y+h)-z,w,z,,O(n,9)>>8,O(n,9)>>8 Else'hoz z=(w/(O(n,8)-O(n,7)))*O(n,10) Box x+z,y,w-z,h,,cGy,cGy Box x,y,z,h,,O(n,9)>>8,O(n,9)>>8 EndIf Else'erase GUIObjCleanup n,1 EndIf Case 9'frame GUIFrame n,0 Colour 0,cGy Text x+5,y-FH()/2,Ot(n) End Select EndIf End Sub 'set values of gadget by its numeric name Sub GUIObjVSet(id As Integer,cv As Integer) Local Integer n n=GUIObjFind(id) If n>-1 Then Select Case O(n,1) Case 4,8 O(n,10)=Constrain(cv,O(n,7),O(n,8)) End Select EndIf End Sub Function GUIObjVGet(id As Integer) Local Integer n n=GUIObjFind(id) If n>-1 Then Select Case O(n,1) Case 2,3 GUIObjVGet=O(n,2) And 32 Case 4,8 GUIObjVGet=O(n,10) End Select EndIf End Function 'draws any type of border around an object Sub GUIFrame(n As Integer,os As Integer) Local Integer c1,c2 Select Case O(n,9) And &h0F Case 0'none c1=cGy:c2=cGy Case 1'button style raised c1=&hffffff:c2=0 Case 2'button style depressed c1=0:c2=&hffffff Case 3'white c1=&hffffff:c2=&hffffff Case 4'black c1=0:c2=0 Case 5'grey (disabled) c1=Cgh:c2=Cgh End Select Colour c1:Line O(n,3)-os,O(n,4)-os,O(n,3)-os,O(n,6)+os:Line O(n,3)-os,O(n,4)-os,O(n,5)+os,O(n,4)-os:Colour c2:Line O(n,5)+os,O(n,4)-os,O(n,5)+os,O(n,6)+os:Line O(n,3)-os,O(n,6)+os,O(n,5)+os,O(n,6)+os End Sub 'removes an object from the screen by its internal reference Sub GUIObjCleanup(n,f) If f Or (O(n,2) And 64) Then Box O(n,3)-1,O(n,4)-1,O(n,5)-O(n,3)+1,O(n,6)-O(n,4)+1,,cGy,cGy EndIf O(n,2)=O(n,2) And &hBF'clear cleanup flag End Sub 'Sets the properties of an object 'Returns -1 if not found Function GUIObjPSet(id As Integer,b As Integer) As Integer'id,enabled,visible,touched,Set,cleanup Local Integer n n=GUIObjFind(id) If n>-1 Then O(n,2)=b:Exit Function EndIf GUIObjPSet=-1'object not found End Function 'Returns the properties of an object by its numeric name 'Returns the properties or -1 if not found Function GUIObjPGet(id As Integer) As Integer Local Integer n n=GUIObjFind(id) If n>-1 Then GUIObjPGet=O(n,2):Exit Function EndIf GUIObjPGet=-1'object not found End Function 'Finds the internal reference for an object from its numeric name 'Returns the object number or -1 if not found Function GUIObjFind(id) Local Integer n For n=0 To P-1 If O(n,0)=id Then GUIObjFind=n:Exit Function'object exists Next GUIObjFind=-1 End Function 'force a value within boundaries Function Constrain(v As Integer,l As Integer,u As Integer) As Integer Constrain=Min(Max(v,l),u) End Function 'defines an object but doesn't draw anything. returns 0 if all OK. 'res=GUIObjDef(21,1,10,10,80,30,"Save",&hffggbb,,1) Function GUIObjDef(id As Integer,tp As Integer,x As Integer,y As Integer,w As Integer,h As Integer,t$,g As Integer,c As Integer,d As Integer) As Integer Local Integer n If P>Objs Then GUIObjDef=1:Exit Function'too many objects n=GUIObjFind(id) If n=-1 Then n=P:P=P+1'define or redefine. P always points to the next free "slot" O(n,0)=id O(n,1)=tp O(n,2)=0 O(n,3)=x O(n,4)=y O(n,7)=g O(n,8)=c O(n,9)=d O(n,10)=g Ot(n)=t$ Select Case tp Case 1,5,8,9'button,textbox,progress bar,frame O(n,5)=x+w O(n,6)=y+h If O(n,7)+O(n,8)=0 Then O(n,7)=CGy Case 2,3'Radio,checkbox O(n,5)=x+15+FW()*Len(t$) O(n,6)=y+FH() Case 4'Slider O(n,4)=y-4 O(n,5)=x+w O(n,6)=y+14 Case 6'List Static Case 7'List DropDown End Select End Function 'compatibility functions Function FH() As Integer If CMM2 Then FH=MM.INFO(FONTHEIGHT) Else FH=MM.FONTHEIGHT EndIf End Function Function FW() As Integer If CMM2 Then FW=MM.INFO(FONTWIDTH) Else FW=MM.FONTWIDTH EndIf End Function Sub GetTouch If CMM2 Then GUI CURSOR MOUSE(x,0),MOUSE(y,0)'here or main loop Xt=-1 If Mouse(R,mp) Then Save Image "GUI.bmp",0,0,320,240 If Mouse(L,mp) Then Xt=mouse(X,mp):Yt=mouse(Y,mp) EndIf Else Xt=Touch(X):Yt=Touch(Y) EndIf End Sub