diff options
author | Ian C <ianc@noddybox.co.uk> | 2005-09-23 23:36:40 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2005-09-23 23:36:40 +0000 |
commit | 263cefaad986b5fe61084b486422bc618b4d1aa2 (patch) | |
tree | 54a87b38f2ca4a3b044947618c1c8f24898763f9 | |
parent | 565ab31801e4868f59f727cda4c602ddbd7d5077 (diff) |
Adde TPanel and simple dialog functionality to the GUI
-rw-r--r-- | simplegui.mod/simplegui.bmx | 100 |
1 files changed, 98 insertions, 2 deletions
diff --git a/simplegui.mod/simplegui.bmx b/simplegui.mod/simplegui.bmx index 7b5e7ef..2d3a570 100644 --- a/simplegui.mod/simplegui.bmx +++ b/simplegui.mod/simplegui.bmx @@ -66,6 +66,10 @@ Type TWidget Abstract bbdoc: The @TGUIHandler that owns this widget. EndRem Field owner:TGUIHandler + Rem + bbdoc: True if this widget consumes events, False otherwise. + EndRem + Field consumes:Int Rem bbdoc: Override this accept keypresses @@ -143,6 +147,46 @@ Type TWidget Abstract End Type Rem +bbdoc: The panel widget (simply displays itself as a white bordered black box) +EndRem +Type TPanel Extends TWidget + + Rem + bbdoc: Create a TPanel widget. + returns: The created widget. + about: @gui is the @TGUIHandler object managing this wiget. @x, @y, @x and @h are its position and size. If @x or @y is -1 they are centered. + EndRem + Function Create:TPanel(gui:TGUIHandler,x:Int, y:Int, w:Int, h:Int) + Local o:TPanel=New TPanel + o.enabled=True + o.consumes=False + + If x=-1 + x=(GraphicsWidth()-w)/2 + EndIf + + If y=-1 + y=(GraphicsHeight()-h)/2 + EndIf + + o.x=x + o.y=y + o.w=w + o.h=h + gui.Register(o) + Return o + End Function + + Method Draw() + SetColor(0,0,0) + DrawRect(x,y,w,h) + SetColor(255,255,255) + DrawBox(x,y,w,h) + End Method + +End Type + +Rem bbdoc: The label widget (simply displays the supplied string) EndRem Type TLabel Extends TWidget @@ -154,6 +198,7 @@ Type TLabel Extends TWidget Function Create:TLabel(gui:TGUIHandler,x:Int, y:Int, text:String) Local o:TLabel=New TLabel o.enabled=True + o.consumes=False o.x=x o.y=y o.w=TGUIFont.font.TextWidth(text)+2 @@ -184,6 +229,7 @@ Type TText Extends TWidget Function Create:TText(gui:TGUIHandler,x:Int, y:Int, text:String, maxlen:Int, callback(w:TWidget)=Null) Local o:TText=New TText o.enabled=True + o.consumes=True o.x=x o.y=y o.maxlen=maxlen @@ -249,6 +295,7 @@ Type TCheckbox Extends TWidget Function Create:TCheckbox(gui:TGUIHandler, x:Int, y:Int, text:String, callback(w:TWidget)=Null) Local o:TCheckbox=New TCheckbox o.enabled=True + o.consumes=True o.x=x o.y=y o.w=TGUIFont.font.TextWidth(" "+text)+4+TGUIFont.font.MaxHeight() @@ -302,6 +349,7 @@ Type TButton Extends TWidget Function Create:TButton(gui:TGUIHandler, x:Int, y:Int, w:Int, h:Int, text:String, callback(w:TWidget)) Local o:TButton=New TButton o.enabled=True + o.consumes=True o.x=x o.y=y o.w=w @@ -354,6 +402,7 @@ Type TButtonList Extends TWidget Local o:TButtonList=New TButtonList Local maxw:Int=0 o.enabled=True + o.consumes=True o.x=x o.y=y o.options=options @@ -431,6 +480,7 @@ Type TNumberFloat Extends TWidget Function Create:TNumberFloat(gui:TGUIHandler, x:Int, y:Int, callback(w:TWidget)=Null) Local o:TNumberFloat=New TNumberFloat o.enabled=True + o.consumes=True o.value=0 o.minval=0 o.maxval=100 @@ -517,6 +567,7 @@ Type TNumberInt Extends TWidget Function Create:TNumberInt(gui:TGUIHandler, x:Int, y:Int, callback(w:TWidget)=Null) Local o:TNumberInt=New TNumberInt o.enabled=True + o.consumes=True o.value=0 o.minval=0 o.maxval=100 @@ -683,7 +734,7 @@ Type TGUIHandler Local k:Int=GetChar() - If k<>0 And m_focus<>Null And m_focus.enabled + If k<>0 And m_focus<>Null And m_focus.enabled And m_focus.consumes m_focus.HandleKey(k) EndIf End Method @@ -692,7 +743,7 @@ Type TGUIHandler ' Method LocateWidget:TWidget(x:Int,y:Int) For Local w:TWidget=EachIn m_widgets - If x>=w.x And y>=w.y And x<w.x+w.w And y<w.y+w.h + If x>=w.x And y>=w.y And x<w.x+w.w And y<w.y+w.h And w.consumes Return w EndIf Next @@ -738,6 +789,7 @@ Function GUINotify(s:String, i:TImage=Null) click=gui.Clicked() If i<>Null + SetColor(255,255,255) DrawImage(i,MouseX(),MouseY()) EndIf @@ -785,6 +837,7 @@ Function GUIYesNo:Int(s:String, i:TImage=Null) click=gui.Clicked() If i<>Null + SetColor(255,255,255) DrawImage(i,MouseX(),MouseY()) EndIf @@ -835,6 +888,7 @@ Function GUIMenu(title:String, options:String[], x:Int, y:Int, i:TImage=Null) click=gui.Clicked() If i<>Null + SetColor(255,255,255) DrawImage(i,MouseX(),MouseY()) EndIf @@ -851,6 +905,48 @@ Function GUIMenu(title:String, options:String[], x:Int, y:Int, i:TImage=Null) Return -1 End Function +Rem +bbdoc: Handles a TGUIHandler as if it's a modal dialog. +returns: True if @ok is pressed, False if @cancel or the ESCAPE key is pressed. +about: @gui is the GUI handler and widgets to display as a dialog., @ok is the clickable widget that OK's the dialog, @cancel the widget that cancels it. +about: If @i is not null then this image is drawn as a mouse cursor. +EndRem +Function GUIDialog(gui:TGUIHandler, ok:TWidget, cancel:TWidget, i:TImage=Null) + Local back:TImage=CreateImage(GraphicsWidth(),GraphicsHeight(),1,0) + GrabImage(back,0,0) + + Local done:Int=False + Local ok_pressed:Int + Local click:TWidget + + While done=False + Cls + DrawImage(back,0,0) + gui.EventLoop() + click=gui.Clicked() + + If click=ok + done=True + ok_pressed=True + EndIf + + If click=cancel Or KeyHit(KEY_ESCAPE) + done=True + ok_pressed=False + EndIf + + If i<>Null + SetColor(255,255,255) + DrawImage(i,MouseX(),MouseY()) + EndIf + + Flip + FlushMem + Wend + + Return ok_pressed +End Function + Private Type TSplitText |