summaryrefslogtreecommitdiff
path: root/simplegui.mod/simplegui.bmx
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 /simplegui.mod/simplegui.bmx
parentf8de91ae41929286b1cf43c72093e5c996b1f949 (diff)
Updates to GUI alerts
Diffstat (limited to 'simplegui.mod/simplegui.bmx')
-rw-r--r--simplegui.mod/simplegui.bmx118
1 files changed, 100 insertions, 18 deletions
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