summaryrefslogtreecommitdiff
path: root/simplegui.mod/simplegui.bmx
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-09-19 23:24:16 +0000
committerIan C <ianc@noddybox.co.uk>2005-09-19 23:24:16 +0000
commit6daa6ca8f55c86512d92fa187cdf21bc7c279a6a (patch)
tree307fc314d2dc2531cd0eaaa14c186f078fbc0b99 /simplegui.mod/simplegui.bmx
parent82c41335d11b5ed18090ac1a548c9b402e4d01a4 (diff)
Added simple number spinners
Diffstat (limited to 'simplegui.mod/simplegui.bmx')
-rw-r--r--simplegui.mod/simplegui.bmx172
1 files changed, 172 insertions, 0 deletions
diff --git a/simplegui.mod/simplegui.bmx b/simplegui.mod/simplegui.bmx
index 678497b..7b5e7ef 100644
--- a/simplegui.mod/simplegui.bmx
+++ b/simplegui.mod/simplegui.bmx
@@ -398,6 +398,178 @@ Type TButtonList Extends TWidget
End Type
Rem
+bbdoc: A number up/down widget for floats
+EndRem
+Type TNumberFloat Extends TWidget
+
+ Rem
+ bbdoc: The value
+ EndRem
+ Field value:Float
+
+ Rem
+ bbdoc: The increment/decrement
+ EndRem
+ Field change:Float
+
+ Rem
+ bbdoc: The maximum value
+ EndRem
+ Field maxval:Float
+
+ Rem
+ bbdoc: The minimum value
+ EndRem
+ Field minval:Float
+
+ Rem
+ bbdoc: Create a TNumber widget.
+ returns: The created widget.
+ about: @gui is the @TGUIHandler object managing this wiget. @x and @y are its position.
+ about: @callback is called when the value changes.
+ EndRem
+ Function Create:TNumberFloat(gui:TGUIHandler, x:Int, y:Int, callback(w:TWidget)=Null)
+ Local o:TNumberFloat=New TNumberFloat
+ o.enabled=True
+ o.value=0
+ o.minval=0
+ o.maxval=100
+ o.change=10
+ o.x=x
+ o.y=y
+ o.w=TGUIFont.font.MaxHeight()*2+8
+ o.h=TGUIFont.font.MaxHeight()+2
+ o.callback=callback
+ gui.Register(o)
+ Return o
+ End Function
+
+ Method HandleClick()
+ Local old:Float=value
+
+ If MouseX()<x+w/2
+ value=Min(value+change,maxval)
+ Else
+ value=Max(value-change,minval)
+ EndIf
+
+ If value<>old And callback<>Null
+ callback(Self)
+ EndIf
+ End Method
+
+ Method Draw()
+ If mouse_over
+ If MouseX()<x+w/2
+ SetColor(128,128,128)
+ DrawRect(x,y,w/2,h)
+ SetColor(64,64,64)
+ DrawRect(x+w/2,y,w/2,h)
+ Else
+ SetColor(64,64,64)
+ DrawRect(x,y,w/2,h)
+ SetColor(128,128,128)
+ DrawRect(x+w/2,y,w/2,h)
+ EndIf
+ Else
+ SetColor(64,64,64)
+ DrawRect(x,y,w,h)
+ EndIf
+
+ Draw3DBox(x+2,y+2,h-4,h-4,False,1)
+ Draw3DBox(x+w-h,y+2,h-4,h-4,False,1)
+
+ TGUIFont.font.Draw(value,x+w+2,y+1)
+ End Method
+End Type
+
+Rem
+bbdoc: A number up/down widget for ints
+EndRem
+Type TNumberInt Extends TWidget
+
+ Rem
+ bbdoc: The value
+ EndRem
+ Field value:Int
+
+ Rem
+ bbdoc: The increment/decrement
+ EndRem
+ Field change:Int
+
+ Rem
+ bbdoc: The maximum value
+ EndRem
+ Field maxval:Int
+
+ Rem
+ bbdoc: The minimum value
+ EndRem
+ Field minval:Int
+
+ Rem
+ bbdoc: Create a TNumber widget.
+ returns: The created widget.
+ about: @gui is the @TGUIHandler object managing this wiget. @x and @y are its position.
+ about: @callback is called when the value changes.
+ EndRem
+ Function Create:TNumberInt(gui:TGUIHandler, x:Int, y:Int, callback(w:TWidget)=Null)
+ Local o:TNumberInt=New TNumberInt
+ o.enabled=True
+ o.value=0
+ o.minval=0
+ o.maxval=100
+ o.change=10
+ o.x=x
+ o.y=y
+ o.w=TGUIFont.font.MaxHeight()*2+8
+ o.h=TGUIFont.font.MaxHeight()+2
+ o.callback=callback
+ gui.Register(o)
+ Return o
+ End Function
+
+ Method HandleClick()
+ Local old:Int=value
+
+ If MouseX()<x+w/2
+ value=Min(value+change,maxval)
+ Else
+ value=Max(value-change,minval)
+ EndIf
+
+ If value<>old And callback<>Null
+ callback(Self)
+ EndIf
+ End Method
+
+ Method Draw()
+ If mouse_over
+ If MouseX()<x+w/2
+ SetColor(128,128,128)
+ DrawRect(x,y,w/2,h)
+ SetColor(64,64,64)
+ DrawRect(x+w/2,y,w/2,h)
+ Else
+ SetColor(64,64,64)
+ DrawRect(x,y,w/2,h)
+ SetColor(128,128,128)
+ DrawRect(x+w/2,y,w/2,h)
+ EndIf
+ Else
+ SetColor(64,64,64)
+ DrawRect(x,y,w,h)
+ EndIf
+
+ Draw3DBox(x+2,y+2,h-4,h-4,False,1)
+ Draw3DBox(x+w-h,y+2,h-4,h-4,False,1)
+
+ TGUIFont.font.Draw(value,x+w+2,y+1)
+ End Method
+End Type
+
+Rem
bbdoc: Handles the GUI.
EndRem
Type TGUIHandler