annotate mde/gui/widget/PopupMenu.d @ 119:d28aea50c6da

Basic edit cursor placement using the mouse. Moved textContent.d's contents into TextWidget.d.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 01 Jan 2009 14:52:09 +0000
parents aba2dd815a1f
children 5b37d0400732
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
16 /*************************************************************************************************
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
17 * Pop-up menus based on content structures.
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
18 *************************************************************************************************/
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
19 module mde.gui.widget.PopupMenu;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 import mde.gui.widget.Widget;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
22 import mde.gui.widget.TextWidget;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
23 import mde.gui.widget.layout;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
24
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
25 import mde.content.miscContent;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
26 import mde.gui.exception;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
28 debug {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
29 import tango.util.log.Log : Log, Logger;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
30 private Logger logger;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
31 static this () {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
32 logger = Log.getLogger ("mde.gui.widget.PopupMenu");
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
33 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
34 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
35
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
36 /*************************************************************************************************
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
37 * Widget which pops up a menu based on a content.
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
38 *************************************************************************************************/
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
39 class PopupMenuWidget : AParentSingleWidget
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
41 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
42 content = c;
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
43 WDCMinCheck (data, 1,1, content);
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
44 subWidget = mgr.makeWidget (data.strings[0], content);
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
45
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
46 adapter = mgr.renderer.getAdapter;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
47 adapter.text = content.toString (1);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
48 adapter.getDimensions (mw, mh);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
49 w = mw;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
50 h = mh;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
51 super (mgr, id, data);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
52 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
53
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
54 override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
55 if (b == 1 && state == true) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
56 // If active, the popup is closed by WidgetManager since the click isn't on the popup.
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
57 if (!pushed) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
58 pushed = true;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
59 mgr.addPopup (this, subWidget); // causes redraw
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
60 mgr.addClickCallback (&openMenuCallback); // prevents first up-click from closing menu, if on self.
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
61 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
62 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
63 return 0;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
64 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
65
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
66 override void popupClose () {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
67 pushed = false;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
68 }
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
69 override bool popupParentClick () {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
70 pushed = false;
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
71 return true;
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
72 }
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
73
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
74 override void draw () {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
75 mgr.renderer.drawButton (x,y, w,h, pushed);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
76 adapter.draw (x,y);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
77 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
78
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
79 protected:
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
80 bool openMenuCallback (wdabs cx, wdabs cy, ubyte b, bool state) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
81 if (b == 1 && state == false) { // receive first up-click
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
82 mgr.removeCallbacks (cast(void*) this);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
83 if (cx >= x && cx < x+w && cy >= y && cy < y+h)
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
84 return true; // up-click is on self; don't close the menu
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
85 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
86 return false;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
87 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
88 bool pushed = false;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
89 IRenderer.TextAdapter adapter;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
90 IContent content;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
91 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
92
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
93 /*************************************************************************************************
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
94 * Widget which pops up a sub-menu based on a content on mouse-over.
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
95 *************************************************************************************************/
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
96 class SubMenuWidget : PopupMenuWidget
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
97 {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
98 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
99 super (mgr, id, data, c);
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
100 }
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
101
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
102 override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
103 return 0;
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
104 }
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
105
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
106 override void highlight (bool state) {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
107 if (state && !pushed) {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
108 pushed = true;
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
109 mgr.addPopup (this, subWidget, 1); // causes redraw
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
110 }
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
111 }
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
112 }
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
113
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
114 /*************************************************************************************************
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
115 * A function which returns a ContentListWidget or MenuButtonContentWidget.
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
116 *************************************************************************************************/
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
117 IChildWidget flatMenuContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
118 if (c is null) throw new ContentException;
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
119 if (cast(IContentList) c)
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
120 return new ContentListWidget(mgr,id,data,c);
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
121 else if (cast(EventContent) c)
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
122 return new MenuButtonContentWidget(mgr,id,data,c);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
123 else // generic uneditable option
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
124 return new DisplayContentWidget(mgr,id,data,c);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
125 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
126
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
127 /*************************************************************************************************
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
128 * A function which returns a SubMenuWidget or MenuButtonContentWidget.
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
129 *************************************************************************************************/
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
130 IChildWidget subMenuContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
131 if (c is null) throw new ContentException;
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
132 if (cast(IContentList) c)
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
133 return new SubMenuWidget(mgr,id,data,c);
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
134 else if (cast(EventContent) c)
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
135 return new MenuButtonContentWidget(mgr,id,data,c);
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
136 else // generic uneditable option
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
137 return new DisplayContentWidget(mgr,id,data,c);
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
138 }
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
139
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
140 /*************************************************************************************************
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
141 * A menu content-button, like ButtonContentWidget, but which can be activated with the up-click.
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
142 *************************************************************************************************/
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
143 class MenuButtonContentWidget : ATextWidget
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
144 {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
145 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
146 content = cast(EventContent) c;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
147 WDCMinCheck (data, 1,0, content);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
148 adapter = mgr.renderer.getAdapter ();
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
149 super (mgr, id, data);
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 }
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
152 override bool setup (uint n, uint flags) {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
153 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
154 adapter.text = content.toString(1);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
155 return super.setup (n, 3); // force redimensioning
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
156 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
157
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
158 override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
159 if (b == 1) { // on up or down click
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
160 pushed = false;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
161 mgr.requestRedraw;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
162 content.endEvent;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
163 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
164 return 0;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
165 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
166
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
167 override void highlight (bool state) {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
168 pushed = state;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
169 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
170
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
171 override void draw () {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
172 mgr.renderer.drawButton (x,y, w,h, pushed);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
173 adapter.draw (x,y);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
174 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
175
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
176 protected:
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
177 EventContent content;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
178 bool pushed;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
179 }