annotate dynamin/gui/control.d @ 47:41b76c218851

Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
author Jordan Miner <jminer7@gmail.com>
date Tue, 04 Aug 2009 20:28:18 -0500
parents d55b5b998412
children 62742ce025ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
1 // Written in the D programming language
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
2 // www.digitalmars.com/d/
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
3
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
4 /*
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
5 * The contents of this file are subject to the Mozilla Public License Version
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
6 * 1.1 (the "License"); you may not use this file except in compliance with
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
7 * the License. You may obtain a copy of the License at
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
8 * http://www.mozilla.org/MPL/
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
9 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
10 * Software distributed under the License is distributed on an "AS IS" basis,
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
12 * for the specific language governing rights and limitations under the
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
13 * License.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
14 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
15 * The Original Code is the Dynamin library.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
16 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
17 * The Initial Developer of the Original Code is Jordan Miner.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
18 * Portions created by the Initial Developer are Copyright (C) 2006-2009
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
19 * the Initial Developer. All Rights Reserved.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
20 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
21 * Contributor(s):
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
22 * Jordan Miner <jminer7@gmail.com>
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
23 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
24 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
25
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
26 module dynamin.gui.control;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
27
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
28 import dynamin.all_core;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
29 import dynamin.all_painting;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
30 import dynamin.gui.container;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
31 import dynamin.gui.events;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
32 import dynamin.gui.window;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
33 import dynamin.gui.cursor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
34 import tango.io.Stdout;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
35
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
36 Control hotControl;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
37 // the hot control is the one the mouse is over
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
38 package void setHotControl(Control c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
39 if(c !is hotControl) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
40 if(hotControl)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
41 hotControl.mouseLeft(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
42 hotControl = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
43 if(c)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
44 c.mouseEntered(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
45 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
46 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
47 package Control getHotControl() { return hotControl; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
48 Control captorControl;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
49 package void setCaptorControl(Control c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
50 captorControl = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
51 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
52 package Control getCaptorControl() { return captorControl; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
53
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
54 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
55 * The painting event is an exception to the rule that added handlers are called
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
56 * before whenPainting. The painting event is far more useful since
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
57 * added handles are called after the control's whenPainting has finished.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
58 * Otherwise, anything handlers painted would likely be painted over when the
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
59 * control painted.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
60 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
61 class Control {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
62 protected:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
63 bool _visible;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
64 bool _focusable;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
65 bool _focused;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
66 package Point _location;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
67 package Size _size;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
68 string _text;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
69 Color _backColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
70 Color _foreColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
71 Font _font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
72 Cursor _cursor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
73 Container _parent;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
74 bool _elasticX, _elasticY;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
75 public:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
76 protected void dispatchMouseEntered(EventArgs e) {
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
77 setCurrentCursor(_cursor);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
78 mouseEntered.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
79 mouseEntered.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
80 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
81 protected void dispatchMouseDown(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
82 setCaptorControl(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
83 mouseDown.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
84 mouseDown.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
85 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
86 protected void dispatchMouseUp(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
87 setCaptorControl(null);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
88 mouseUp.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
89 mouseUp.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
90 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
91 protected void dispatchMouseMoved(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
92 setHotControl(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
93 mouseMoved.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
94 mouseMoved.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
95 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
96 protected void dispatchMouseDragged(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
97 setHotControl(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
98 mouseDragged.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
99 mouseDragged.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
100 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
101 protected void dispatchMouseTurned(MouseTurnedEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
102 mouseTurned.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
103 mouseTurned.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
104 if(!e.stopped && _parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
105 _parent.mouseTurned(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
106 }
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
107 protected void dispatchKeyDown(KeyEventArgs e) {
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
108 keyDown.callHandlers(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
109 keyDown.callMainHandler(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
110 if(!e.stopped && _parent)
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
111 _parent.keyDown(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
112 }
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
113 protected void dispatchKeyUp(KeyEventArgs e) {
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
114 keyUp.callHandlers(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
115 keyUp.callMainHandler(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
116 if(!e.stopped && _parent)
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
117 _parent.keyUp(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
118 }
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
119 protected void dispatchKeyTyped(KeyTypedEventArgs e) {
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
120 keyTyped.callHandlers(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
121 keyTyped.callMainHandler(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
122 if(!e.stopped && _parent)
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
123 _parent.keyTyped(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
124 }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
125 protected void dispatchPainting(PaintingEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
126 e.graphics.save();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
127 painting.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
128 e.graphics.restore();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
129 e.graphics.save();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
130 // TODO: every call to a handler should be wrapped in a save/restore
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
131 painting.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
132 e.graphics.restore();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
133 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
134
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
135 /// Override this method in a subclass to handle the moved event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
136 protected void whenMoved(EventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
137 /// This event occurs after the control has been moved.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
138 Event!(whenMoved) moved;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
139
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
140 /// Override this method in a subclass to handle the resized event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
141 protected void whenResized(EventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
142 /// This event occurs after the control has been resized.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
143 Event!(whenResized) resized;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
144
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
145 /// Override this method in a subclass to handle the mouseEntered event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
146 protected void whenMouseEntered(EventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
147 /// This event occurs after the mouse has entered the control.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
148 Event!(whenMouseEntered) mouseEntered;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
149
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
150 /// Override this method in a subclass to handle the mouseLeft event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
151 protected void whenMouseLeft(EventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
152 /// This event occurs after the mouse has left the control.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
153 Event!(whenMouseLeft) mouseLeft;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
154
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
155 /// Override this method in a subclass to handle the mouseDown event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
156 protected void whenMouseDown(MouseEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
157 /// This event occurs after a mouse button is pressed.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
158 Event!(whenMouseDown) mouseDown;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
159
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
160 /// Override this method in a subclass to handle the mouseUp event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
161 protected void whenMouseUp(MouseEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
162 /// This event occurs after a mouse button is released.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
163 Event!(whenMouseUp) mouseUp;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
164
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
165 /// Override this method in a subclass to handle the mouseMoved event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
166 protected void whenMouseMoved(MouseEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
167 /// This event occurs after the mouse has been moved.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
168 Event!(whenMouseMoved) mouseMoved;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
169
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
170 /// Override this method in a subclass to handle the mouseMoved event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
171 protected void whenMouseDragged(MouseEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
172 /// This event occurs after the mouse has been moved.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
173 Event!(whenMouseDragged) mouseDragged;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
174
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
175 /// Override this method in a subclass to handle the mouseTurned event.
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
176 /// If this event is not stopped, it will be sent to the control's parent.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
177 protected void whenMouseTurned(MouseTurnedEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
178 /// This event occurs after the mouse wheel has been turned.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
179 Event!(whenMouseTurned) mouseTurned;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
180
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
181 /// Override this method in a subclass to handle the keyDown event.
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
182 /// If this event is not stopped, it will be sent to the control's parent.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
183 protected void whenKeyDown(KeyEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
184 /// This event occurs after a key is pressed.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
185 Event!(whenKeyDown) keyDown;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
186
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
187 /// Override this method in a subclass to handle the keyTyped event.
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
188 /// If this event is not stopped, it will be sent to the control's parent.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
189 protected void whenKeyTyped(KeyTypedEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
190 /// This event occurs after a character key is pressed.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
191 Event!(whenKeyTyped) keyTyped;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
192
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
193 /// Override this method in a subclass to handle the keyUp event.
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
194 /// If this event is not stopped, it will be sent to the control's parent.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
195 protected void whenKeyUp(KeyEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
196 /// This event occurs after a key is released.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
197 Event!(whenKeyUp) keyUp;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
198
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
199 /// Override this method in a subclass to handle the painting event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
200 protected void whenPainting(PaintingEventArgs e) {
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
201 e.graphics.source = backColor;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
202 e.graphics.paint();
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
203 }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
204 /// This event occurs when the control needs to be painted.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
205 Event!(whenPainting) painting;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
206
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
207 this() {
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
208 moved.mainHandler = &whenMoved;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
209 resized.mainHandler = &whenResized;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
210 mouseEntered.mainHandler = &whenMouseEntered;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
211 mouseEntered.dispatcher = &dispatchMouseEntered;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
212 mouseLeft.mainHandler = &whenMouseLeft;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
213 mouseDown.mainHandler = &whenMouseDown;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
214 mouseDown.dispatcher = &dispatchMouseDown;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
215 mouseUp.mainHandler = &whenMouseUp;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
216 mouseUp.dispatcher = &dispatchMouseUp;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
217 mouseMoved.mainHandler = &whenMouseMoved;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
218 mouseMoved.dispatcher = &dispatchMouseMoved;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
219 mouseDragged.mainHandler = &whenMouseDragged;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
220 mouseDragged.dispatcher = &dispatchMouseDragged;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
221 mouseTurned.mainHandler = &whenMouseTurned;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
222 mouseTurned.dispatcher = &dispatchMouseTurned;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
223 keyDown.mainHandler = &whenKeyDown;
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
224 keyDown.dispatcher = &dispatchKeyDown;
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
225 keyTyped.mainHandler = &whenKeyTyped;
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
226 keyTyped.dispatcher = &dispatchKeyTyped;
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
227 keyUp.mainHandler = &whenKeyUp;
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
228 keyUp.dispatcher = &dispatchKeyUp;
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
229 painting.mainHandler = &whenPainting;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
230 painting.dispatcher = &dispatchPainting;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
231
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
232 _location = Point(0, 0);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
233 _size = Size(100, 100);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
234 _text = "";
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
235 _focusable = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
236 _focused = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
237 _visible = true;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
238 _cursor = Cursor.Arrow;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
239 _elasticX = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
240 _elasticY = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
241
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
242 // TODO: remove these when themes mature
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
243 _foreColor = Color.Black;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
244 _font = new Font("Tahoma", 11);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
245 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
246
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
247 protected Graphics quickCreateGraphics() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
248 if(_parent is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
249 return null;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
250 auto g = _parent.quickCreateGraphics();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
251 g.translate(location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
252 return g;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
253 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
254
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
255 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
256 * Sets the specified Graphics' font and source to this control's font
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
257 * and foreground color. Also, clips to this control's rectangle.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
258 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
259 void setupGraphics(Graphics g) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
260 g.rectangle(0, 0, width, height);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
261 g.clip();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
262 g.font = font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
263 g.source = foreColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
264 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
265
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
266 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
267 * Creates a Graphics, calls the specified delegate with it, and deletes
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
268 * it to release resources.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
269 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
270 void withGraphics(void delegate(Graphics g) dg) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
271 auto g = quickCreateGraphics();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
272 setupGraphics(g);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
273 dg(g);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
274 delete g;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
275 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
276
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
277 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
278 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
279 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
280 bool focused() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
281 return _focused;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
282 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
283
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
284 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
285 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
286 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
287 void focus() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
288 if(!_focusable)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
289 return;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
290 Control c = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
291 while(c.parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
292 c = c.parent;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
293 if(auto win = cast(Window)c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
294 if(win.focusedControl) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
295 win.focusedControl._focused = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
296 win.focusedControl.repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
297 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
298 win.focusedControl = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
299 _focused = true;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
300 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
301 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
302 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
303
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
304 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
305 * Returns whether this control is on the screen. A control is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
306 * on screen if one of its ancestors is a top level window. Whether or
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
307 * not the control is visible has no bearing on this value. If a control
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
308 * has no parent, then it is clearly not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
309 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
310 bool onScreen() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
311 return _parent && _parent.onScreen;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
312 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
313
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
314 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
315 * Gets the location of this control in screen coordinates. An exception is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
316 * thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
317 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
318 Point screenLocation() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
319 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
320 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
321 return _parent.screenLocation + location;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
322 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
323
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
324 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
325 * Converts the specified point in content coordinates into screen
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
326 * coordinates. An exception is thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
327 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
328 Point contentToScreen(Point pt) { // TODO: content?? even on Window??
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
329 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
330 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
331 return _parent.contentToScreen(pt + location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
332 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
333
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
334 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
335 * Converts the specified point in screen coordinates into content
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
336 * coordinates. An exception is thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
337 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
338 Point screenToContent(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
339 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
340 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
341 return _parent.screenToContent(pt) - location; // TODO: borders
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
342 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
343
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
344 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
345 * Converts the specified point in this control's content coordinates
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
346 * into the specified control's content coordinates. An exception is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
347 * thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
348 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
349 Point contentToContent(Point pt, Control c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
350 return c.screenToContent(contentToScreen(pt));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
351 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
352
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
353 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
354 * Returns whether the specified point is inside this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
355 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
356 bool contains(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
357 return pt.x >= 0 && pt.y >= 0 && pt.x < width && pt.y < height;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
358 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
359 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
360 bool contains(real x, real y) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
361 return contains(Point(x, y));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
362 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
363
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
364 bool topLevel() { return false; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
365 // TODO: return NativeControl/Window?
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
366 Control getTopLevel() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
367 Control c = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
368 while(c.parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
369 c = c.parent;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
370 return c.topLevel ? c : null;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
371 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
372
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
373 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
374 * Gets this control's parent.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
375 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
376 Container parent() { return _parent; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
377 package void parent(Container c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
378 _parent = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
379 //ParentChanged(new EventArgs); // TODO: add event
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
380 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
381
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
382 /**
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
383 * Gets or sets whether is control is visible. The default is true, except
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
384 * on top-level windows.
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
385 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
386 //void visible(bool b) { visible = b; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
387 bool visible() { return _visible; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
388
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
389 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
390 * Gets or sets the location of this control in its parent's content
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
391 * coordinates.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
392 * Examples:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
393 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
394 * control.location = [5, 35];
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
395 * control.location = Point(50, 50);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
396 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
397 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
398 Point location() { return _location; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
399 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
400 void location(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
401 if((cast(Window)_parent) !is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
402 throw new Exception("cannot set location of a window's content");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
403 pt.x = round(pt.x);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
404 pt.y = round(pt.y);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
405 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
406 _location = pt;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
407 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
408 moved(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
409 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
410 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
411 void location(real[] pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
412 assert(pt.length == 2, "pt must be just an x and y");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
413 location = Point(pt[0], pt[1]);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
414 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
415
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
416 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
417 * Gets or sets the size of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
418 * Examples:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
419 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
420 * control.size = [75, 23];
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
421 * control.size = Size(80, 20);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
422 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
423 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
424 Size size() { return _size; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
425 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
426 void size(Size newSize) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
427 if(newSize.width < 0)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
428 newSize.width = 0;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
429 if(newSize.height < 0)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
430 newSize.height = 0;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
431 newSize.width = round(newSize.width);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
432 newSize.height = round(newSize.height);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
433 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
434 _size = newSize;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
435 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
436 resized(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
437 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
438 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
439 void size(real[] newSize) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
440 assert(newSize.length == 2, "size must be just a width and height");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
441 size = Size(newSize[0], newSize[1]);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
442 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
443
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
444 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
445 * Gets the size at which this control looks the best. It is intended that
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
446 * the control not be made smaller than this size, and only be made larger
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
447 * if it is elastic, or if it needs to be aligned with other controls.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
448 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
449 * This property should be overridden in subclasses to return a best size.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
450 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
451 Size bestSize() { return Size(100, 100); }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
452
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
453 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
454 * Gets the distance from the top of this control to the baseline of
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
455 * the first line of this control's text. If this control does not have
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
456 * text, 0 may be returned.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
457 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
458 int baseline() { return 0; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
459
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
460 /// Same as location.x
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
461 real x() { return location.x; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
462 /// Same as location.y
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
463 real y() { return location.y; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
464 /// Same as size.width
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
465 real width() { return size.width; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
466 /// Same as size.height
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
467 real height() { return size.height; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
468
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
469 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
470 * Gets or sets whether this control is elastic horizontally or vertically.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
471 * If a control is elastic, then it is intended to be made larger than its
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
472 * best size.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
473 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
474 bool elasticX() { return _elasticX; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
475 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
476 void elasticX(bool b) { _elasticX = b; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
477 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
478 bool elasticY() { return _elasticY; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
479 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
480 void elasticY(bool b) { _elasticY = b; }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
481
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
482 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
483 * Gets or sets the text that this control shows.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
484 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
485 string text() { return _text.dup; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
486 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
487 void text(string str) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
488 _text = str.dup;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
489 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
490 //TextChanged(EventArgs e) // TODO: add event
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
491 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
492
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
493 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
494 * Gets or sets the background color of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
495 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
496 Color backColor() { return _backColor; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
497 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
498 void backColor(Color c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
499 _backColor = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
500 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
501 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
502
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
503 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
504 * Gets or sets the foreground color of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
505 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
506 Color foreColor() { return _foreColor; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
507 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
508 void foreColor(Color c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
509 _foreColor = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
510 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
511 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
512
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
513 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
514 * Gets or sets the font of this control uses to display text. A value of
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
515 * null means that the font is unset. When the font is null, the
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
516 * current theme's font is used. The default is null.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
517 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
518 Font font() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
519 // TODO: if font is null (unset), return from theme
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
520 //if(font is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
521 // return Theme.Current.Control_Font(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
522 //else
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
523 return _font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
524 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
525 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
526 void font(Font f) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
527 _font = f;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
528 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
529 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
530
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
531 void setCurrentCursor(Cursor cur) {
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
532 if(parent)
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
533 parent.setCurrentCursor(cur);
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
534 }
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
535 /**
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
536 * Gets or sets the mouse cursor that will be shown when the mouse
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
537 * is over this control.
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
538 */
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
539 Cursor cursor() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
540 return _cursor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
541 }
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
542 /// ditto
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
543 void cursor(Cursor cur) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
544 if(_cursor is cur)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
545 return;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
546 _cursor = cur;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
547 if(getHotControl() is this)
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
548 setCurrentCursor(_cursor);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
549 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
550
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
551 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
552 * Causes the part of the control inside the specified
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
553 * rectangle to be repainted. The rectangle is in content coordinates.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
554 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
555 * The control will not be repainted before this method returns; rather,
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
556 * the area is just marked as needing to be repainted. The next time there
15
96b29f2efa4d Fix typo in doc comment.
Jordan Miner <jminer7@gmail.com>
parents: 10
diff changeset
557 * are no other system events to be processed, a painting event will
96b29f2efa4d Fix typo in doc comment.
Jordan Miner <jminer7@gmail.com>
parents: 10
diff changeset
558 * be called.
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
559 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
560 void repaint(Rect rect) {
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
561 // TODO: make sure that parts clipped off by the parent are
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
562 // not invalidated
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
563 if(_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
564 _parent.repaint(rect + location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
565 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
566 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
567 void repaint(real x, real y, real width, real height) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
568 repaint(Rect(x, y, width, height));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
569 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
570 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
571 * Causes the entire control to be repainted.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
572 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
573 void repaint() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
574 repaint(Rect(0, 0, width, height));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
575 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
576 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
577
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
578