Some functions for GUI elements such as check boxes, labels, buttons etc. All use custom graphics.
-
Example program shows how to use them.
Language:
Dark Basic Pro
Code:
sync on rem GUI variables: global msx as integer global msy as integer global msc as integer global omc as integer global msd as integer global TxtInput as string rem THIS IS THE EXAMPLE PROGRAM ink rgb(255,255,255),0 circle 100,100,99 get image 1,0,0,200,200,1 rem Box images ink rgb(0,255,255),0 box 0,0,200,100 get image 2,0,0,200,100,1 ink rgb(255,0,0),0 box 0,0,200,100 get image 3,0,0,200,100,1 cls box 5,5,195,95 get image 4,0,0,200,100,1 rem elipse image cls ink rgb(255,255,0),0 ellipse 300,150,300,150 get image 5,0,0,600,300,1 ink rgb(255,255,255),0 ellipse 300,150,300,150 get image 6,0,0,600,300,1 cls ink rgb(255,255,255),0 box 0,0,100,50 get image 7,0,0,100,50,1 ink 0,0 box 1,1,99,49 get image 8,0,0,100,50,1 do UpdateGUI() clicked = GUIRectangleButton(100,100,100,100,200,100,2,3,4) clicked = GUICircleButton(300,600,200,500,100,1,1,1) clicked = GUIOvalButton(700,400,400,250,300,150,5,6,6) value = GUICheckbox(value,700,10,700,10,100,50,7,8) GUIBoxLabel(405,15,400,10,200,25,GUITextInput(),rgb(255,255,255),2,rgb(255,0,0)) sync cls loop rem END OF EXAMPLE PROGRAM function UpdateGUI() msx = mousex() msy = mousey() omc = msc msc = mouseclick() msd = msc-omc endfunction function GUIRectangleButton(X, Y, ImageX, ImageY, Width, Height, Image, MouseOverImage, MouseDownImage) if GUIPointInRectangle(msx, msy, X, Y, Width, Height) if msc=1 Image = MouseDownImage if msd=1 paste image Image,ImageX,ImageY,1 exitfunction 1 endif else Image = MouseOverImage endif endif paste image Image,ImageX,ImageY,1 endfunction 0 function GUICircleButton(X, Y, ImageX, ImageY, Radius, Image, MouseOverImage, MouseDownImage) if GUIPointInCircle(msx, msy, X, Y, Radius) if msc=1 Image = MouseDownImage if msd=1 paste image Image,ImageX,ImageY,1 exitfunction 1 endif else Image = MouseOverImage endif endif paste image Image,ImageX,ImageY,1 endfunction 0 function GUIOvalButton(X, Y, ImageX, ImageY, RadiusX, RadiusY, Image, MouseOverImage, MouseDownImage) if GUIPointInOval(msx, msy, X, Y, RadiusX, RadiusY) if msc=1 Image = MouseDownImage if msd=1 paste image Image,ImageX,ImageY,1 exitfunction 1 endif else Image = MouseOverImage endif endif paste image Image,ImageX,ImageY,1 endfunction 0 function GUIPointInRectangle(X, Y, Left, Top, Width, Height) if X >= Left if X <= Left+Width if Y >= Top if Y <= Top+Height exitfunction 1 endif endif endif endif endfunction 0 function GUIPointInCircle(X, Y, MidX, MidY, Radius) XD = MidX-X YD = MidY-Y if XD*XD+YD*YD <= Radius*Radius exitfunction 1 endif endfunction 0 function GUIPointInOval(X, Y, MidX, MidY, XRadius#, YRadius#) XD = MidX-X YD = MidY-Y YD = YD*(XRadius#/YRadius#) if XD*XD+YD*YD <= XRadius#*XRadius# exitfunction 1 endif endfunction 0 function GUIImageLabel(X, Y, ImageX, ImageY, Image, Text$) paste image Image, ImageX, ImageY text X, Y, Text$ endfunction function GUIBoxLabel(X, Y, BoxX, BoxY, Width, Height, Text$, BackColour, BorderSize, BorderColour) box BoxX,BoxY,BoxX+Width,BoxY+Height,BorderColour,BorderColour,BorderColour,BorderColour box BoxX+BorderSize,BoxY+BorderSize,BoxX+Width-BorderSize,BoxY+Height-BorderSize,BackColour,BackColour,BackColour,BackColour text X, Y, Text$ endfunction function GUIClearInput() TxtInput = "" clear entry buffer endfunction function GUITextInput() TxtInput = entry$(1) endfunction TxtInput function GUICheckBox(Value as boolean, X, Y, ImageX, ImageY, Width, Height, CheckedImage, UncheckedImage) if GUIPointInRectangle(msx, msy, X, Y, Width, Height) if msd=1 Value = 1-Value endif endif if Value paste image CheckedImage,ImageX,ImageY,1 else paste image UncheckedImage,ImageX,ImageY,1 endif endfunction Value function GUIDrawCursor(Image) paste image Image,msx,msy,1 endfunction
(2 votes)