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