summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mwidget/test.bmx331
-rw-r--r--mwidget/toolbar.pngbin0 -> 429 bytes
2 files changed, 313 insertions, 18 deletions
diff --git a/mwidget/test.bmx b/mwidget/test.bmx
index 38812f7..8c80dd2 100644
--- a/mwidget/test.bmx
+++ b/mwidget/test.bmx
@@ -3,6 +3,7 @@ Strict
Import noddybox.mwidget
Incbin "icons.png"
+Incbin "toolbar.png"
Const SUBCLASS:Int=False
Const TESTTIMER:Int=False
@@ -41,6 +42,28 @@ Global tree:TMTreeView
Global tree_node:TMTextField
Global tree_add:TMButton
Global tree_remove:TMButton
+Global tree_count:TMButton
+
+Global menu:TMMenu
+Global popup:TMMenu
+
+Global menu_path:TMTextField
+Global menu_name:TMTextField
+Global menu_add:TMButton
+Global menu_remove:TMButton
+Global menu_check:TMButton
+Global menu_uncheck:TMButton
+Global menu_enable:TMButton
+Global menu_disable:TMButton
+Global menu_popup:TMButton
+Global menu_status:TMLabel
+
+Global canvas:TMCanvas
+
+Global canvas_mx:Int
+Global canvas_my:Int
+
+Global toolbar:TMToolbar
'
' CALLBACK FUNCTION VERSION
@@ -141,6 +164,80 @@ Function OnMenu_Tree(o:TMWidget, path:String, tag:Object)
top.StatusText(MilliSecs() + " -- Menu " + path + " (" + tag.ToString() + ")")
End Function
+Function OnRedraw_Canvas(w:TMWidget)
+ Local c:TMCanvas=TMCanvas(w)
+ c.SetupGraphics()
+ SetColor(Rand(100,200),Rand(100,200),Rand(100,200))
+ DrawRect(0,0,w.Width(),w.Height())
+ Flip
+End Function
+
+Function OnMouseEnter_Canvas(w:TMWidget)
+ SetPointer(POINTER_CROSS)
+End Function
+
+Function OnMouseLeave_Canvas(w:TMWidget)
+ SetPointer(POINTER_DEFAULT)
+End Function
+
+Function OnButtonDown_Canvas(w:TMWidget, b:Int)
+ Local c:TMCanvas=TMCanvas(w)
+ c.SetupGraphics()
+ SetColor(255,255,255)
+ DrawLine(w.Width(),w.Height(),canvas_mx,canvas_my)
+ Flip()
+ top.StatusText(MilliSecs() + " -- Button Down " + b)
+End Function
+
+Function OnButtonUp_Canvas(w:TMWidget, b:Int)
+ top.StatusText(MilliSecs() + " -- Button Up " + b)
+End Function
+
+Function OnMouseMove_Canvas(w:TMWidget, x:Int, y:Int)
+ canvas_mx=x
+ canvas_my=y
+ top.StatusText(MilliSecs() + " -- Mouse move " + x + "," + y)
+End Function
+
+Function OnMouseWheel_Canvas(w:TMWidget, b:Int)
+ top.StatusText(MilliSecs() + " -- Mouse wheel " + b)
+End Function
+
+Function OnKeyDown_Canvas(w:TMWidget, b:Int)
+ Local c:TMCanvas=TMCanvas(w)
+ SetColor(0,0,0)
+ DrawRect(0,0,600,19)
+ c.SetupGraphics()
+ SetColor(255,255,255)
+ DrawText(MilliSecs() + " -- Key down " + b,0,0)
+ Flip()
+End Function
+
+Function OnKeyUp_Canvas(w:TMWidget, b:Int)
+ Local c:TMCanvas=TMCanvas(w)
+ c.SetupGraphics()
+ SetColor(0,0,0)
+ DrawRect(0,20,600,19)
+ SetColor(255,255,255)
+ DrawText(MilliSecs() + " -- Key up " + b,0,20)
+ Flip()
+End Function
+
+Function OnKey_Canvas(w:TMWidget, b:Int)
+ Local c:TMCanvas=TMCanvas(w)
+ c.SetupGraphics()
+ SetColor(0,0,0)
+ DrawRect(0,40,600,19)
+ SetColor(255,255,255)
+ DrawText(MilliSecs() + " -- Key " + b + "(" + Chr(b) + ")",0,40)
+ Flip()
+End Function
+
+Function OnSelected_Toolbar(w:TMWidget, i:Int)
+ Local tb:TMToolbar=TMToolbar(w)
+ top.StatusText(MilliSecs() + " -- Toolbar " + i)
+ toolbar.ItemEnabled(1,Not i=0)
+End Function
'
' SUBCLASS VERSION
'
@@ -275,8 +372,84 @@ Type MyTree Extends TMTreeView
End Method
End Type
+Type MyCanvas Extends TMCanvas
+ Field mx:Int
+ Field my:Int
+
+ Method OnRedraw()
+ SetupGraphics()
+ SetColor(Rand(100,200),Rand(100,200),Rand(100,200))
+ DrawRect(0,0,Width(),Height())
+ Flip
+ End Method
+
+ Method OnMouseEnter()
+ SetPointer(POINTER_CROSS)
+ End Method
+
+ Method OnMouseLeave()
+ SetPointer(POINTER_DEFAULT)
+ End Method
+
+ Method OnButtonDown(b:Int)
+ SetupGraphics()
+ SetColor(255,255,255)
+ DrawLine(0,0,mx,my)
+ Flip()
+ top.StatusText(MilliSecs() + " -- Button Down " + b)
+ End Method
+
+ Method OnButtonUp(b:Int)
+ top.StatusText(MilliSecs() + " -- Button Up " + b)
+ End Method
+
+ Method OnMouseMove(x:Int, y:Int)
+ mx=x
+ my=y
+ top.StatusText(MilliSecs() + " -- Mouse move " + x + "," + y)
+ End Method
+
+ Method OnMouseWheel(b:Int)
+ top.StatusText(MilliSecs() + " -- Mouse wheel " + b)
+ End Method
+
+ Method OnKeyDown(b:Int)
+ SetupGraphics()
+ SetColor(0,0,0)
+ DrawRect(0,0,600,19)
+ SetColor(255,255,255)
+ DrawText(MilliSecs() + " -- Key down " + b,0,0)
+ Flip()
+ End Method
+
+ Method OnKeyUp(b:Int)
+ SetupGraphics()
+ SetColor(0,0,0)
+ DrawRect(0,20,600,19)
+ SetColor(255,255,255)
+ DrawText(MilliSecs() + " -- Key up " + b,0,20)
+ Flip()
+ End Method
+
+ Method OnKey(b:Int)
+ SetupGraphics()
+ SetColor(0,0,0)
+ DrawRect(0,40,600,19)
+ SetColor(255,255,255)
+ DrawText(MilliSecs() + " -- Key " + b + "(" + Chr(b) + ")",0,40)
+ Flip()
+ End Method
+End Type
+
+Type MyToolbar Extends TMToolbar
+ Method OnSelected(i:Int)
+ top.StatusText(MilliSecs() + " -- Toolbar " + i)
+ ItemEnabled(1,Not i=0)
+ End Method
+End Type
+
'
-' GENERIC SUBCLASSES
+' ALWAYS SUBCLASSES
'
Type AddToTree Extends TMButton
Method OnPress()
@@ -290,6 +463,72 @@ Type RemoveFromTree Extends TMButton
End Method
End Type
+Type CountTree Extends TMButton
+ Method OnPress()
+ Local path:String=tree_node.GetText()
+ Notify("Children of " + path + " = " + tree.CountChildren(path))
+ End Method
+End Type
+
+Type AddToMenu Extends TMButton
+ Method OnPress()
+ menu.Set(menu_path.GetText(),menu_name.GetText(),MenuCallback)
+ End Method
+End Type
+
+Type RemoveFromMenu Extends TMButton
+ Method OnPress()
+ menu.Remove(menu_path.GetText())
+ End Method
+End Type
+
+Type MenuCheck Extends TMButton
+ Method OnPress()
+ menu.Check(menu_path.GetText(),True)
+ End Method
+End Type
+
+Type MenuUncheck Extends TMButton
+ Method OnPress()
+ menu.Check(menu_path.GetText(),False)
+ End Method
+End Type
+
+Type MenuEnable Extends TMButton
+ Method OnPress()
+ menu.Enable(menu_path.GetText(),True)
+ End Method
+End Type
+
+Type MenuDisable Extends TMButton
+ Method OnPress()
+ menu.Enable(menu_path.GetText(),False)
+ End Method
+End Type
+
+Type MenuPopup Extends TMButton
+ Method OnPress()
+ popup.Popup(Self)
+ End Method
+End Type
+
+Type MyMenu Extends TMMenu
+ Method OnMenuItem(path:String, tag:Object)
+ menu_status.Text(MilliSecs() + " -- Selected " + path + " (" + tag.ToString() + ") check=" + IsChecked(path))
+ End Method
+End Type
+
+'
+' ALWAYS CALLBACKS
+'
+Function MenuCallback(m:TMMenu, path:String, tag:Object)
+ top.StatusText(MilliSecs() + " -- Selected " + path + " (" + tag.ToString() + ") check=" + m.IsChecked(path))
+End Function
+
+Function PopupMenuCallback(m:TMMenu, path:String, tag:Object)
+ top.StatusText(MilliSecs() + " -- Selected popup " + path + " (" + tag.ToString() + ") check=" + m.IsChecked(path))
+End Function
+
'
' TEST
'
@@ -306,7 +545,7 @@ EndIf
top.MinSize(top.Width(),top.Height())
-tabs=New TMTabber.Create(0,10,640,390,top)
+tabs=New TMTabber.Create(0,30,640,370,top)
tabs.SetIconStrip(icons)
tabs.AddItem(CreateListEntry("Buttons",0,0,"Test different button types"))
tabs.AddItem(CreateListEntry("Text",0,1,"Test text entry fields"))
@@ -314,6 +553,7 @@ tabs.AddItem(CreateListEntry("Sliders",0,2,"Test sliders"))
tabs.AddItem(CreateListEntry("Lists",0,3,"Test list"))
tabs.AddItem(CreateListEntry("HTML",0,-1,"Test HTML view"))
tabs.AddItem(CreateListEntry("Tree View",0,-1,"Test tree view"))
+tabs.AddItem(CreateListEntry("Menu",0,-1,"Test menus"))
tabs.AddItem(CreateListEntry("Canvas",0,-1,"Test canvas"))
If SUBCLASS
@@ -338,13 +578,17 @@ If SUBCLASS
list=New MyList.Create(10,10,300,300,tabs)
- html=New MyHTML.Create(10,10,620,300,tabs,HTMLVIEW_NOCONTEXTMENU|HTMLVIEW_NONAVIGATE)
- html_url=New TMTextField.Create(10,320,620,20,tabs)
- html_go=New MyGo.Create("GO",10,345,90,20,tabs)
- html_back=New MyBack.Create("Back",110,345,90,20,tabs)
- html_forward=New MyForward.Create("Forward",210,345,90,20,tabs)
+ html=New MyHTML.Create(10,10,620,280,tabs,HTMLVIEW_NOCONTEXTMENU|HTMLVIEW_NONAVIGATE)
+ html_url=New TMTextField.Create(10,300,620,20,tabs)
+ html_go=New MyGo.Create("GO",10,325,90,20,tabs)
+ html_back=New MyBack.Create("Back",110,325,90,20,tabs)
+ html_forward=New MyForward.Create("Forward",210,325,90,20,tabs)
tree=New MyTree.Create(10,10,620,250,tabs)
+
+ canvas=New MyCanvas.Create(10,10,620,320,tabs)
+
+ toolbar=New MyToolbar.Create("incbin::toolbar.png",top)
Else
ok=New TMButton.CreateOK("OK",10,300,80,30,tabs)
cancel=New TMButton.CreateCancel("Cancel",100,300,80,30,tabs)
@@ -367,13 +611,17 @@ Else
list=New TMListBox.Create(10,10,300,300,tabs)
- html=New TMHTMLView.Create(10,10,620,300,tabs,HTMLVIEW_NOCONTEXTMENU|HTMLVIEW_NONAVIGATE)
- html_url=New TMTextField.Create(10,320,620,20,tabs)
- html_go=New TMButton.Create("GO",10,345,90,20,tabs)
- html_back=New TMButton.Create("Back",110,345,90,20,tabs)
- html_forward=New TMButton.Create("Forward",210,345,90,20,tabs)
+ html=New TMHTMLView.Create(10,10,620,280,tabs,HTMLVIEW_NOCONTEXTMENU|HTMLVIEW_NONAVIGATE)
+ html_url=New TMTextField.Create(10,300,620,20,tabs)
+ html_go=New TMButton.Create("GO",10,325,90,20,tabs)
+ html_back=New TMButton.Create("Back",110,325,90,20,tabs)
+ html_forward=New TMButton.Create("Forward",210,325,90,20,tabs)
tree=New TMTreeView.Create(10,10,620,250,tabs)
+
+ canvas=New TMCanvas.Create(10,10,620,320,tabs)
+
+ toolbar=New TMToolbar.Create("incbin::toolbar.png",top)
ok.OnPressEvent.Add(OnPress_OK)
cancel.OnPressEvent.Add(OnPress_Cancel)
@@ -402,6 +650,18 @@ Else
tree.OnCollapsedEvent.Add(OnCollapsed_Tree)
tree.OnMenuEvent.Add(OnMenu_Tree)
+ canvas.OnRedrawEvent.Add(OnRedraw_Canvas)
+ canvas.OnMouseEnterEvent.Add(OnMouseEnter_Canvas)
+ canvas.OnMouseLeaveEvent.Add(OnMouseLeave_Canvas)
+ canvas.OnButtonDownEvent.Add(OnButtonDown_Canvas)
+ canvas.OnButtonUpEvent.Add(OnButtonUp_Canvas)
+ canvas.OnMouseWheelEvent.Add(OnMouseWheel_Canvas)
+ canvas.OnMouseMoveEvent.Add(OnMouseMove_Canvas)
+ canvas.OnKeyDownEvent.Add(OnKeyDown_Canvas)
+ canvas.OnKeyUpEvent.Add(OnKeyUp_Canvas)
+ canvas.OnKeyEvent.Add(OnKey_Canvas)
+
+ toolbar.OnSelectedEvent.Add(OnSelected_Toolbar)
EndIf
Local label:TMLabel=New TMLabel.Create("Label:",10,10,80,20,tabs)
@@ -420,7 +680,7 @@ tabs.ItemEnabled(6,False)
list.SetSelectedIndex(0)
-tree.SetIconStrip(icons)
+'tree.SetIconStrip(icons)
tree.BeginUpdate()
tree.Set("/dir1","Dir1",0)
tree.Set("/dir2","Dir2",1)
@@ -433,15 +693,50 @@ tree.EndUpdate()
html.Go("http://www.noddybox.demon.co.uk")
tree_node=New TMTextField.Create(10,280,300,20,tabs)
-tree_add=New AddToTree.Create("Add",320,280,100,20,tabs)
-tree_remove=New RemoveFromTree.Create("Remove",430,280,100,20,tabs)
-
-tabs.SetPages([ [TMWidget(ok),TMWidget(cancel),TMWidget(check),TMWidget(radio1),TMWidget(radio2),TMWidget(radio3)], ..
+tree_add=New AddToTree.Create("Add",320,280,80,20,tabs)
+tree_remove=New RemoveFromTree.Create("Remove",420,280,80,20,tabs)
+tree_count=New CountTree.Create("Count",520,280,80,20,tabs)
+
+menu=New MyMenu.CreateWindowMenu(top)
+popup=New MyMenu.CreatePopupMenu()
+
+popup.Set("/menu1","Menu 1")
+popup.Set("/menu2","Menu 2")
+popup.Set("/menu1/opt1","Opt 1.1",PopupMenuCallback)
+popup.Set("/menu1/opt2","Opt 1.2",PopupMenuCallback)
+popup.Set("/menu2/opt1","Opt 2.1",PopupMenuCallback)
+
+menu.Set("/file","File")
+menu.Set("/file/quit","Quit",MenuCallback)
+
+menu_status=New TMLabel.Create("",10,10,600,20,tabs)
+menu_path=New TMTextField.Create(10,30,300,20,tabs)
+menu_name=New TMTextField.Create(320,30,300,20,tabs)
+menu_add=New AddToMenu.Create("Add",10,60,100,20,tabs)
+menu_remove=New RemoveFromMenu.Create("Remove",200,60,100,20,tabs)
+menu_check=New MenuCheck.Create("Check",10,90,100,20,tabs)
+menu_uncheck=New MenuUncheck.Create("Uncheck",200,90,100,20,tabs)
+menu_enable=New MenuEnable.Create("Enable",10,120,100,20,tabs)
+menu_disable=New MenuDisable.Create("Disable",200,120,100,20,tabs)
+menu_popup=New MenuPopup.Create("Popup",10,150,100,20,tabs)
+
+toolbar.SetTooltips(["Tip1","Tip2","","Tip3","Tip4"])
+
+toolbar.AddItem(0,0,"Tip5")
+toolbar.AddItem(1,0,"Tip6")
+toolbar.AddItem(3,0,"Tip7")
+toolbar.AddItem(4,0,"Tip8")
+
+tabs.SetPages([ ..
+ [TMWidget(ok),TMWidget(cancel),TMWidget(check),TMWidget(radio1),TMWidget(radio2),TMWidget(radio3)], ..
[TMWidget(label),TMWidget(txtfield),TMWidget(txtarea)], ..
[TMWidget(slider1),TMWidget(slider2)], ..
[TMWidget(list)], ..
[TMWidget(html), TMWidget(html_url), TMWidget(html_go), TMWidget(html_back), TMWidget(html_forward)], ..
- [TMWidget(tree), TMWidget(tree_node), TMWidget(tree_add), TMWidget(tree_remove)]])
+ [TMWidget(tree), TMWidget(tree_node), TMWidget(tree_add), TMWidget(tree_remove), TMWidget(tree_count)], ..
+ [TMWidget(menu_status), TMWidget(menu_path), TMWidget(menu_name), TMWidget(menu_add), TMWidget(menu_remove), TMWidget(menu_check), TMWidget(menu_uncheck), TMWidget(menu_enable), TMWidget(menu_disable), TMWidget(menu_popup)], ..
+ [TMWidget(canvas)] ..
+ ])
tabs.SetSelectedIndex(0)
diff --git a/mwidget/toolbar.png b/mwidget/toolbar.png
new file mode 100644
index 0000000..583d180
--- /dev/null
+++ b/mwidget/toolbar.png
Binary files differ