From 4c757b1080fe345a528f0659fe2af86779315e8d Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 15 Sep 2005 01:03:01 +0000 Subject: Added simple gui --- simplegui.mod/.cvsignore | 5 ++ simplegui.mod/simplegui.bmx | 135 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 simplegui.mod/.cvsignore create mode 100644 simplegui.mod/simplegui.bmx (limited to 'simplegui.mod') diff --git a/simplegui.mod/.cvsignore b/simplegui.mod/.cvsignore new file mode 100644 index 0000000..6644509 --- /dev/null +++ b/simplegui.mod/.cvsignore @@ -0,0 +1,5 @@ +.bmx +simplegui.debug.win32.a +simplegui.debug.win32.i +simplegui.release.win32.a +simplegui.release.win32.i \ No newline at end of file diff --git a/simplegui.mod/simplegui.bmx b/simplegui.mod/simplegui.bmx new file mode 100644 index 0000000..deb6dfc --- /dev/null +++ b/simplegui.mod/simplegui.bmx @@ -0,0 +1,135 @@ +Module noddybox.simplegui + +ModuleInfo "Framework: (Very) Simple GUI" +ModuleInfo "Copyright: Public Domain" +ModuleInfo "Author: Ian Cowburn" +ModuleInfo "Version: $Revision$" + +' $Id$ + +Strict +Import brl.Max2D +Import brl.Basic +Import noddybox.bitmapfont + +Type TWidget Abstract + + Field text:String + Field x:Int + Field y:Int + Field w:Int + Field h:Int + Field font:TBitmapFont + Field owner:TGUIHandler + Field callback() + + Method HandleKey(key:String) + End Method + + Method MouseEnter() + End Method + + Method MouseLeave() + End Method + + Method HandleClick() + End Method + + Method Draw() Abstract +End Type + +Type TLabel Extends TWidget + Function Create:TLabel(font:TBitmapFont,x:Int, y:Int, text:String) + Local o:TLabel=New TLabel + o.font=font + o.x=x + o.y=y + o.w=font.TextWidth(text)+2 + o.h=font.MaxHeight()+1 + o.text=text + Return o + End Function + + Method Draw() + font.Draw(text,x+1,y+1) + End Method +End Type + +Type TText Extends TWidget + Field maxlen:Int + + Function Create:TText(font:TBitmapFont,x:Int, y:Int, text:String, maxlen:Int) + Local o:TText=New TText + o.font=font + o.x=x + o.y=y + o.maxlen=maxlen + o.w=font.MaxWidth()*(maxlen+1)+2 + o.h=font.MaxHeight()+2 + o.text=text + Return o + End Function + + Method Draw() + Local s:String=text + + If owner.GetFocus()=Self + SetColor(128,128,128) + s:+"_" + Else + SetColor(64,64,64) + EndIf + + DrawRect(x,y,w,h) + + font.Draw(s,x+1,y+1) + End Method +End Type + +Type TGUIHandler + + ' These are private + ' + Field m_widgets:TList + Field m_focus:TWidget + + ' Creates a new GUI handler + ' + Function Create:TGUIHandler() + Local o:TGUIHandler + + o=New TGUIHandler + + o.m_widgets=CreateList() + o.m_focus=Null + + Return o + End Function + + ' Register a widget + ' + Method Register(w:TWidget) + m_widgets.AddLast(w) + w.owner=Self + End Method + + ' Set the keyboard focus (null for none) + ' + Method SetFocus(w:TWidget) + m_focus=w + End Method + + ' Get the keyboard focus (null for none) + ' + Method GetFocus:TWidget() + Return m_focus + End Method + + ' Perform a loop and any necessary events + ' + Method EventLoop() + For Local w:TWidget=EachIn m_widgets + w.Draw() + Next + End Method +End Type -- cgit v1.2.3