From 82c41335d11b5ed18090ac1a548c9b402e4d01a4 Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 19 Sep 2005 01:04:06 +0000 Subject: Updates to GUI alerts --- simplegui.mod/doc/commands.html | 9 ++- simplegui.mod/simplegui.bmx | 118 ++++++++++++++++++++++++++++++++++------ 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 @@

Function Reference

-
Function GUINotify( s:String ) Displays a notification alert with the supplied string.


+
Function GUINotify( s:String, i:TImage=Null ) Displays a notification alert with the supplied string.

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.



-
Function GUIYesNo:Int( s:String ) Displays a yes/no alert with the supplied string.

Returns: True if Yes selected, otherwise False.



+
Function GUIYesNo:Int( s:String, i:TImage=Null ) Displays a yes/no alert with the supplied string.

Returns: True if Yes selected, otherwise False.

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.



-
Function GUIMenu( title:String, options:String[],x,y ) Displays a pop-up menu.

Returns: The index of the selected option, -1 for none.

title is the menu title, options the options to display and x and y specify its position,.



+
Function GUIMenu( title:String, options:String[], x:Int, y:Int, i:TImage=Null ) Displays a pop-up menu.

Returns: The index of the selected option, -1 for none.

title is the menu title, options the options to display and x and y specify its position. +If i is not null then this image is drawn as a mouse cursor.



Type Reference

Type TGUIFont Defines the TBitmapFont to be used by the GUI.

@@ -83,6 +84,8 @@
Method Register( w:TWidget ) Register a widget.

Widgets call this themselves.



Method Clear() Remove all widgets.


+

+
Method SetEnable( state:Int ) Sets the enable state of all widgets.

If state is true then all widgets are enabled, otherwise all widgets are disabled



Method SetFocus( w:TWidget ) Sets the keyboard focus to the supplied widget. Pass null for no focus.


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 @@ -442,6 +442,16 @@ Type TGUIHandler m_widgets.Clear() 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 @@ -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 -- cgit v1.2.3