summaryrefslogtreecommitdiff
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
parent82c41335d11b5ed18090ac1a548c9b402e4d01a4 (diff)
Added simple number spinners
-rw-r--r--simplegui.mod/doc/commands.html26
-rw-r--r--simplegui.mod/simplegui.bmx172
2 files changed, 198 insertions, 0 deletions
diff --git a/simplegui.mod/doc/commands.html b/simplegui.mod/doc/commands.html
index 56b78b5..b857360 100644
--- a/simplegui.mod/doc/commands.html
+++ b/simplegui.mod/doc/commands.html
@@ -79,6 +79,32 @@ If <b>i</b> is not null then this image is drawn as a mouse cursor.</div><br></d
<div class=rootdoc><font class=token>Function Create:TButtonList( gui:TGUIHandler, x:Int, y:Int, options:String[], selected:Int, callback(w:TWidget) )</font> Create a TButtonList widget.</div><div class=indent><p><b>Returns:</b> The created widget.<p><b>gui</b> is the <b>TGUIHandler</b> object managing this wiget. <b>x</b> and <b>y</b> are its position. <b>options</b> are the options for the list and
<b>selected</b> is the currently selected item. <b>callback</b> is called when the selection changes.</div><br></div><br>
</div><br>
+<p><div id=TNumberFloat class=ref>
+<div class=rootdoc><font class=token>Type TNumberFloat Extends TWidget</font> A number up/down widget for floats</div><div class=indent></div><br><p><div id=value>
+<div class=rootdoc><font class=token>Field value:Float</font> The value</div><div class=indent></div><br></div><br>
+<p><div id=change>
+<div class=rootdoc><font class=token>Field change:Float</font> The increment/decrement</div><div class=indent></div><br></div><br>
+<p><div id=maxval>
+<div class=rootdoc><font class=token>Field maxval:Float</font> The maximum value</div><div class=indent></div><br></div><br>
+<p><div id=minval>
+<div class=rootdoc><font class=token>Field minval:Float</font> The minimum value</div><div class=indent></div><br></div><br>
+<p><div id=Create>
+<div class=rootdoc><font class=token>Function Create:TNumberFloat( gui:TGUIHandler, x:Int, y:Int, callback(w:TWidget)=Null )</font> Create a TNumber widget.</div><div class=indent><p><b>Returns:</b> The created widget.<p><b>gui</b> is the <b>TGUIHandler</b> object managing this wiget. <b>x</b> and <b>y</b> are its position.
+<b>callback</b> is called when the value changes.</div><br></div><br>
+</div><br>
+<p><div id=TNumberInt class=ref>
+<div class=rootdoc><font class=token>Type TNumberInt Extends TWidget</font> A number up/down widget for ints</div><div class=indent></div><br><p><div id=value>
+<div class=rootdoc><font class=token>Field value:Int</font> The value</div><div class=indent></div><br></div><br>
+<p><div id=change>
+<div class=rootdoc><font class=token>Field change:Int</font> The increment/decrement</div><div class=indent></div><br></div><br>
+<p><div id=maxval>
+<div class=rootdoc><font class=token>Field maxval:Int</font> The maximum value</div><div class=indent></div><br></div><br>
+<p><div id=minval>
+<div class=rootdoc><font class=token>Field minval:Int</font> The minimum value</div><div class=indent></div><br></div><br>
+<p><div id=Create>
+<div class=rootdoc><font class=token>Function Create:TNumberInt( gui:TGUIHandler, x:Int, y:Int, callback(w:TWidget)=Null )</font> Create a TNumber widget.</div><div class=indent><p><b>Returns:</b> The created widget.<p><b>gui</b> is the <b>TGUIHandler</b> object managing this wiget. <b>x</b> and <b>y</b> are its position.
+<b>callback</b> is called when the value changes.</div><br></div><br>
+</div><br>
<p><div id=TGUIHandler class=ref>
<div class=rootdoc><font class=token>Type TGUIHandler</font> Handles the GUI.</div><div class=indent></div><br><p><div id=Register>
<div class=rootdoc><font class=token>Method Register( w:TWidget )</font> Register a widget.</div><div class=indent><p>Widgets call this themselves.</div><br></div><br>
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