summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-09-19 01:04:06 +0000
committerIan C <ianc@noddybox.co.uk>2005-09-19 01:04:06 +0000
commit82c41335d11b5ed18090ac1a548c9b402e4d01a4 (patch)
tree76bc70a3acfe6190869568ab59ab4c9efef0395d
parentf8de91ae41929286b1cf43c72093e5c996b1f949 (diff)
Updates to GUI alerts
-rw-r--r--simplegui.mod/doc/commands.html9
-rw-r--r--simplegui.mod/simplegui.bmx118
2 files changed, 106 insertions, 21 deletions
diff --git a/simplegui.mod/doc/commands.html b/simplegui.mod/doc/commands.html
index c66334a..56b78b5 100644
--- a/simplegui.mod/doc/commands.html
+++ b/simplegui.mod/doc/commands.html
@@ -6,11 +6,12 @@
<body>
<h1>Function Reference</h1>
<p><div id=GUINotify class=ref>
-<div class=rootdoc><font class=token>Function GUINotify( s:String )</font> Displays a notification alert with the supplied string.</div><div class=indent></div><br></div><br>
+<div class=rootdoc><font class=token>Function GUINotify( s:String, i:TImage=Null )</font> Displays a notification alert with the supplied string.</div><div class=indent><p>The string <b>s</b> can be split into multiple lines using the '|' character. If <b>i</b> is not null then this image is drawn as a mouse cursor.</div><br></div><br>
<p><div id=GUIYesNo class=ref>
-<div class=rootdoc><font class=token>Function GUIYesNo:Int( s:String )</font> Displays a yes/no alert with the supplied string.</div><div class=indent><p><b>Returns:</b> True if Yes selected, otherwise False.</div><br></div><br>
+<div class=rootdoc><font class=token>Function GUIYesNo:Int( s:String, i:TImage=Null )</font> Displays a yes/no alert with the supplied string.</div><div class=indent><p><b>Returns:</b> True if Yes selected, otherwise False.<p>The string <b>s</b> can be split into multiple lines using the '|' character. If <b>i</b> is not null then this image is drawn as a mouse cursor.</div><br></div><br>
<p><div id=GUIMenu class=ref>
-<div class=rootdoc><font class=token>Function GUIMenu( title:String, options:String[],x,y )</font> Displays a pop-up menu.</div><div class=indent><p><b>Returns:</b> The index of the selected option, -1 for none.<p><b>title</b> is the menu title, <b>options</b> the options to display and <b>x</b> and <b>y</b> specify its position,.</div><br></div><br>
+<div class=rootdoc><font class=token>Function GUIMenu( title:String, options:String[], x:Int, y:Int, i:TImage=Null )</font> Displays a pop-up menu.</div><div class=indent><p><b>Returns:</b> The index of the selected option, -1 for none.<p><b>title</b> is the menu title, <b>options</b> the options to display and <b>x</b> and <b>y</b> specify its position.
+If <b>i</b> is not null then this image is drawn as a mouse cursor.</div><br></div><br>
<h1>Type Reference</h1>
<p><div id=TGUIFont class=ref>
<div class=rootdoc><font class=token>Type TGUIFont</font> Defines the <b>TBitmapFont</b> to be used by the GUI.</div><div class=indent></div><br><p><div id=font>
@@ -83,6 +84,8 @@
<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>
<p><div id=Clear>
<div class=rootdoc><font class=token>Method Clear()</font> Remove all widgets.</div><div class=indent></div><br></div><br>
+<p><div id=SetEnable>
+<div class=rootdoc><font class=token>Method SetEnable( state:Int )</font> Sets the enable state of all widgets.</div><div class=indent><p>If <b>state</b> is true then all widgets are enabled, otherwise all widgets are disabled</div><br></div><br>
<p><div id=SetFocus>
<div class=rootdoc><font class=token>Method SetFocus( w:TWidget )</font> Sets the keyboard focus to the supplied widget. Pass null for no focus.</div><div class=indent></div><br></div><br>
<p><div id=GetFocus>
diff --git a/simplegui.mod/simplegui.bmx b/simplegui.mod/simplegui.bmx
index bcabdb0..678497b 100644
--- a/simplegui.mod/simplegui.bmx
+++ b/simplegui.mod/simplegui.bmx
@@ -443,6 +443,16 @@ Type TGUIHandler
End Method
Rem
+ bbdoc: Sets the enable state of all widgets.
+ about: If @state is true then all widgets are enabled, otherwise all widgets are disabled
+ EndRem
+ Method SetEnable(state:Int)
+ For Local w:TWidget=EachIn m_widgets
+ w.enabled=state
+ Next
+ End Method
+
+ Rem
bbdoc: Sets the keyboard focus to the supplied widget. Pass null for no focus.
EndRem
Method SetFocus(w:TWidget)
@@ -478,9 +488,9 @@ Type TGUIHandler
Local w:TWidget=LocateWidget(x,y)
- For Local w:TWidget=EachIn m_widgets
- If w.enabled
- w.Draw()
+ For Local wid:TWidget=EachIn m_widgets
+ If wid.enabled
+ wid.Draw()
EndIf
Next
@@ -521,21 +531,30 @@ End Type
Rem
bbdoc: Displays a notification alert with the supplied string.
+about: The string @s can be split into multiple lines using the '|' character. If @i is not null then this image is drawn as a mouse cursor.
EndRem
-Function GUINotify(s:String)
+Function GUINotify(s:String, i:TImage=Null)
Local back:TImage=CreateImage(GraphicsWidth(),GraphicsHeight(),1,0)
GrabImage(back,0,0)
- Local w:Int=Max(TGUIFont.font.TextWidth(s)+10,GraphicsWidth()/4)
- Local h:Int=TGUIFont.font.TextHeight(s)*5
+ Local txt:TSplitText=TSplitText.Create(s)
+
+ Local w:Int=Max(txt.width+10,GraphicsWidth()/4)
+ Local h:Int=txt.Height+TGUIFont.font.MaxHeight()*4
Local x:Int=GraphicsWidth()/2-w/2
Local y=GraphicsHeight()/2-h/2
- Local by=y+TGUIFont.font.TextHeight(s)*2.5
+ Local by=y+h-TGUIFont.font.MaxHeight()*2.5
Local gui:TGUIHandler=TGUIHandler.Create()
- Local label:TLabel=TLabel.Create(gui,x+5,y+5,s)
- Local button:TButton=TButton.Create(gui,x+5,by,w-10,TGUIFont.font.TextHeight(s)+10,"OK",Null)
+ Local ty:Int=y+5
+
+ For Local t:String=EachIn txt.lines
+ Local label:TLabel=TLabel.Create(gui,x+5,ty,t)
+ ty:+TGUIFont.font.TextHeight(t)
+ Next
+
+ Local button:TButton=TButton.Create(gui,x+5,by,w-10,TGUIFont.font.MaxHeight()*2,"OK",Null)
Local click:TWidget=Null
@@ -545,6 +564,11 @@ Function GUINotify(s:String)
TWidget.Draw3DBox(x,y,w,h,False,2)
gui.EventLoop()
click=gui.Clicked()
+
+ If i<>Null
+ DrawImage(i,MouseX(),MouseY())
+ EndIf
+
Flip
FlushMem
Wend
@@ -553,22 +577,31 @@ End Function
Rem
bbdoc: Displays a yes/no alert with the supplied string.
returns: True if Yes selected, otherwise False.
+about: The string @s can be split into multiple lines using the '|' character. If @i is not null then this image is drawn as a mouse cursor.
EndRem
-Function GUIYesNo:Int(s:String)
+Function GUIYesNo:Int(s:String, i:TImage=Null)
Local back:TImage=CreateImage(GraphicsWidth(),GraphicsHeight(),1,0)
GrabImage(back,0,0)
- Local w:Int=Max(TGUIFont.font.TextWidth(s)+10,GraphicsWidth()/4)
- Local h:Int=TGUIFont.font.TextHeight(s)*7
+ Local txt:TSplitText=TSplitText.Create(s)
+
+ Local w:Int=Max(txt.width+10,GraphicsWidth()/4)
+ Local h:Int=txt.Height+TGUIFont.font.MaxHeight()*4
Local x:Int=GraphicsWidth()/2-w/2
Local y=GraphicsHeight()/2-h/2
- Local by=y+TGUIFont.font.TextHeight(s)*2
+ Local by=y+h-TGUIFont.font.MaxHeight()*2.5
Local gui:TGUIHandler=TGUIHandler.Create()
- Local label:TLabel=TLabel.Create(gui,x+5,y+5,s)
- Local yes:TButton=TButton.Create(gui,x+5,by,w-10,TGUIFont.font.TextHeight(s)+10,"Yes",Null)
- Local no:TButton=TButton.Create(gui,x+5,by+yes.h+2,w-10,TGUIFont.font.TextHeight(s)+10,"No",Null)
+ Local ty:Int=y+5
+
+ For Local t:String=EachIn txt.lines
+ Local label:TLabel=TLabel.Create(gui,x+5,ty,t)
+ ty:+TGUIFont.font.TextHeight(t)
+ Next
+
+ Local yes:TButton=TButton.Create(gui,x+5,by,w/2-10,TGUIFont.font.MaxHeight()*2,"Yes",Null)
+ Local no:TButton=TButton.Create(gui,x+w/2+5,by,w/2-10,TGUIFont.font.MaxHeight()*2,"No",Null)
Local click:TWidget=Null
@@ -578,6 +611,11 @@ Function GUIYesNo:Int(s:String)
TWidget.Draw3DBox(x,y,w,h,False,2)
gui.EventLoop()
click=gui.Clicked()
+
+ If i<>Null
+ DrawImage(i,MouseX(),MouseY())
+ EndIf
+
Flip
FlushMem
Wend
@@ -589,9 +627,10 @@ End Function
Rem
bbdoc: Displays a pop-up menu.
returns: The index of the selected option, -1 for none.
-about: @title is the menu title, @options the options to display and @x and @y specify its position,.
+about: @title is the menu title, @options the options to display and @x and @y specify its position.
+about: If @i is not null then this image is drawn as a mouse cursor.
EndRem
-Function GUIMenu(title:String, options:String[],x,y)
+Function GUIMenu(title:String, options:String[], x:Int, y:Int, i:TImage=Null)
Local f:Int
Local back:TImage=CreateImage(GraphicsWidth(),GraphicsHeight(),1,0)
GrabImage(back,0,0)
@@ -622,6 +661,11 @@ Function GUIMenu(title:String, options:String[],x,y)
TWidget.Draw3DBox(x,y,w,h,False,2)
gui.EventLoop()
click=gui.Clicked()
+
+ If i<>Null
+ DrawImage(i,MouseX(),MouseY())
+ EndIf
+
Flip
FlushMem
Wend
@@ -634,3 +678,41 @@ Function GUIMenu(title:String, options:String[],x,y)
Return -1
End Function
+
+Private
+
+Type TSplitText
+ Field lines:TList
+ Field width:Int
+ Field height:Int
+
+ Function Create:TSplitText(s:String)
+ Local o:TSplitText=New TSplitText
+
+ o.lines=CreateList()
+ o.width=0
+ o.height=0
+
+ Local sub:String=""
+
+ For Local f:Int=0 Until s.length
+ Local c:Int=s[f]
+ If c=Asc("|")
+ o.lines.AddLast(sub)
+ o.width=Max(o.width,TGUIFont.font.TextWidth(sub))
+ o.height:+TGUIFont.font.TextHeight(sub)
+ sub=""
+ Else
+ sub:+Chr(c)
+ EndIf
+ Next
+
+ If sub.length>0
+ o.lines.AddLast(sub)
+ o.width=Max(o.width,TGUIFont.font.TextWidth(sub))
+ o.height:+TGUIFont.font.TextHeight(sub)
+ EndIf
+
+ Return o
+ End Function
+EndType