annotate dynamin/gui/control.d @ 51:d5823ccfddc6

Add a couple doc comments.
author Jordan Miner <jminer7@gmail.com>
date Tue, 04 Aug 2009 20:59:38 -0500
parents a18c2fd9fe36
children 6e33b00595e9
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;
49
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
66 int _tabIndex;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
67 package Point _location;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
68 package Size _size;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
69 string _text;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
70 Color _backColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
71 Color _foreColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
72 Font _font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
73 Cursor _cursor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
74 Container _parent;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
75 bool _elasticX, _elasticY;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
76 public:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
77 protected void dispatchMouseEntered(EventArgs e) {
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
78 setCurrentCursor(_cursor);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
79 mouseEntered.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
80 mouseEntered.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
81 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
82 protected void dispatchMouseDown(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
83 setCaptorControl(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
84 mouseDown.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
85 mouseDown.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
86 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
87 protected void dispatchMouseUp(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
88 setCaptorControl(null);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
89 mouseUp.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
90 mouseUp.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
91 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
92 protected void dispatchMouseMoved(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
93 setHotControl(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
94 mouseMoved.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
95 mouseMoved.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
96 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
97 protected void dispatchMouseDragged(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
98 setHotControl(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
99 mouseDragged.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
100 mouseDragged.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
101 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
102 protected void dispatchMouseTurned(MouseTurnedEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
103 mouseTurned.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
104 mouseTurned.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
105 if(!e.stopped && _parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
106 _parent.mouseTurned(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
107 }
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
108 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
109 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
110 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
111 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
112 _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
113 }
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 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
115 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
116 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
117 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
118 _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
119 }
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 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
121 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
122 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
123 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
124 _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
125 }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
126 protected void dispatchPainting(PaintingEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
127 e.graphics.save();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
128 painting.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
129 e.graphics.restore();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
130 e.graphics.save();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
131 // 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
132 painting.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
133 e.graphics.restore();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
134 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
135
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
136 /// 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
137 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
138 /// 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
139 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
140
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
141 /// 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
142 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
143 /// 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
144 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
145
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
146 /// 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
147 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
148 /// 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
149 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
150
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
151 /// 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
152 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
153 /// 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
154 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
155
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
156 /// 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
157 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
158 /// 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
159 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
160
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
161 /// 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
162 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
163 /// 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
164 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
165
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
166 /// 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
167 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
168 /// 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
169 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
170
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
171 /// 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
172 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
173 /// 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
174 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
175
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
176 /// 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
177 /// 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
178 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
179 /// 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
180 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
181
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
182 /// 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
183 /// 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
184 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
185 /// 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
186 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
187
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
188 /// 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
189 /// 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
190 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
191 /// 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
192 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
193
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
194 /// 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
195 /// 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
196 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
197 /// 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
198 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
199
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
200 /// 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
201 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
202 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
203 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
204 }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
205 /// 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
206 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
207
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
208 this() {
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
209 moved.mainHandler = &whenMoved;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
210 resized.mainHandler = &whenResized;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
211 mouseEntered.mainHandler = &whenMouseEntered;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
212 mouseEntered.dispatcher = &dispatchMouseEntered;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
213 mouseLeft.mainHandler = &whenMouseLeft;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
214 mouseDown.mainHandler = &whenMouseDown;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
215 mouseDown.dispatcher = &dispatchMouseDown;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
216 mouseUp.mainHandler = &whenMouseUp;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
217 mouseUp.dispatcher = &dispatchMouseUp;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
218 mouseMoved.mainHandler = &whenMouseMoved;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
219 mouseMoved.dispatcher = &dispatchMouseMoved;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
220 mouseDragged.mainHandler = &whenMouseDragged;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
221 mouseDragged.dispatcher = &dispatchMouseDragged;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
222 mouseTurned.mainHandler = &whenMouseTurned;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
223 mouseTurned.dispatcher = &dispatchMouseTurned;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
224 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
225 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
226 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
227 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
228 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
229 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
230 painting.mainHandler = &whenPainting;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
231 painting.dispatcher = &dispatchPainting;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
232
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
233 _location = Point(0, 0);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
234 _size = Size(100, 100);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
235 _text = "";
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
236 _focusable = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
237 _focused = false;
49
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
238 _tabIndex = 0;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
239 _visible = true;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
240 _cursor = Cursor.Arrow;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
241 _elasticX = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
242 _elasticY = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
243
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
244 // TODO: remove these when themes mature
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
245 _foreColor = Color.Black;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
246 _font = new Font("Tahoma", 11);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
247 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
248
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
249 protected Graphics quickCreateGraphics() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
250 if(_parent is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
251 return null;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
252 auto g = _parent.quickCreateGraphics();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
253 g.translate(location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
254 return g;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
255 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
256
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
257 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
258 * 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
259 * and foreground color. Also, clips to this control's rectangle.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
260 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
261 void setupGraphics(Graphics g) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
262 g.rectangle(0, 0, width, height);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
263 g.clip();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
264 g.font = font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
265 g.source = foreColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
266 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
267
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
268 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
269 * Creates a Graphics, calls the specified delegate with it, and deletes
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
270 * it to release resources.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
271 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
272 void withGraphics(void delegate(Graphics g) dg) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
273 auto g = quickCreateGraphics();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
274 setupGraphics(g);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
275 dg(g);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
276 delete g;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
277 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
278
0
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 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
281 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
282 bool focused() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
283 return _focused;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
284 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
285
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
286 /**
49
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
287 * Gets or sets this control's tab index. The tab index of controls
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
288 * decides in what order they are focused when the tab key is pressed.
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
289 * If multiple controls in a window have the same tab index, focus is
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
290 * changed based on the order they were added to the window.
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
291 * The default is 0.
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
292 */
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
293 int tabIndex() {
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
294 return _tabIndex;
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
295 }
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
296 /// ditto
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
297 void tabIndex(int i) {
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
298 _tabIndex = i;
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
299 }
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
300
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
301 /**
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
302 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
303 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
304 void focus() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
305 if(!_focusable)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
306 return;
50
a18c2fd9fe36 Fix a crash if Control.focus was called on a Control not in a Window.
Jordan Miner <jminer7@gmail.com>
parents: 49
diff changeset
307 auto top = getTopLevel();
a18c2fd9fe36 Fix a crash if Control.focus was called on a Control not in a Window.
Jordan Miner <jminer7@gmail.com>
parents: 49
diff changeset
308 if(!top)
a18c2fd9fe36 Fix a crash if Control.focus was called on a Control not in a Window.
Jordan Miner <jminer7@gmail.com>
parents: 49
diff changeset
309 return;
a18c2fd9fe36 Fix a crash if Control.focus was called on a Control not in a Window.
Jordan Miner <jminer7@gmail.com>
parents: 49
diff changeset
310 if(auto win = cast(Window)top) {
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
311 if(win.focusedControl) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
312 win.focusedControl._focused = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
313 win.focusedControl.repaint();
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 win.focusedControl = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
316 _focused = true;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
317 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
318 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
319 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
320
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
321 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
322 * Returns whether this control is on the screen. A control is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
323 * 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
324 * 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
325 * has no parent, then it is clearly not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
326 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
327 bool onScreen() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
328 return _parent && _parent.onScreen;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
329 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
330
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
331 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
332 * 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
333 * thrown if this control is not on the screen.
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 Point screenLocation() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
336 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
337 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
338 return _parent.screenLocation + location;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
339 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
340
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
341 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
342 * Converts the specified point in content coordinates into screen
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
343 * 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
344 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
345 Point contentToScreen(Point pt) { // TODO: content?? even on Window??
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
346 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
347 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
348 return _parent.contentToScreen(pt + location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
349 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
350
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
351 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
352 * Converts the specified point in screen coordinates into content
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
353 * 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
354 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
355 Point screenToContent(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
356 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
357 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
358 return _parent.screenToContent(pt) - location; // TODO: borders
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
359 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
360
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
361 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
362 * Converts the specified point in this control's content coordinates
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
363 * into the specified control's content coordinates. An exception is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
364 * thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
365 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
366 Point contentToContent(Point pt, Control c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
367 return c.screenToContent(contentToScreen(pt));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
368 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
369
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
370 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
371 * Returns whether the specified point is inside this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
372 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
373 bool contains(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
374 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
375 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
376 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
377 bool contains(real x, real y) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
378 return contains(Point(x, y));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
379 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
380
51
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
381 /**
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
382 * Returns true if this control is a top-level control and false otherwise.
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
383 * Top-level controls do not have parents. Non-top-level controls can only
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
384 * be shown on the screen by adding them as children to a top-level control.
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
385 * Currently, the only top-level control is Window.
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
386 */
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
387 bool topLevel() { return false; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
388 // TODO: return NativeControl/Window?
51
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
389 /**
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
390 * Loops over this control's ancestors, and if a top-level control is found,
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
391 * it is returned. If this control does not have a top-level ancestor,
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
392 * null is returned.
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
393 */
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
394 Control getTopLevel() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
395 Control c = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
396 while(c.parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
397 c = c.parent;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
398 return c.topLevel ? c : null;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
399 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
400
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
401 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
402 * Gets this control's parent.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
403 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
404 Container parent() { return _parent; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
405 package void parent(Container c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
406 _parent = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
407 //ParentChanged(new EventArgs); // TODO: add event
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
408 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
409
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
410 /**
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
411 * 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
412 * on top-level windows.
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
413 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
414 //void visible(bool b) { visible = b; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
415 bool visible() { return _visible; }
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 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
418 * 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
419 * coordinates.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
420 * Examples:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
421 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
422 * control.location = [5, 35];
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
423 * control.location = Point(50, 50);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
424 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
425 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
426 Point location() { return _location; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
427 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
428 void location(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
429 if((cast(Window)_parent) !is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
430 throw new Exception("cannot set location of a window's content");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
431 pt.x = round(pt.x);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
432 pt.y = round(pt.y);
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 _location = pt;
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 moved(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 location(real[] pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
440 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
441 location = Point(pt[0], pt[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 or sets the size of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
446 * Examples:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
447 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
448 * control.size = [75, 23];
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
449 * control.size = Size(80, 20);
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 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
452 Size size() { return _size; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
453 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
454 void size(Size newSize) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
455 if(newSize.width < 0)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
456 newSize.width = 0;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
457 if(newSize.height < 0)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
458 newSize.height = 0;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
459 newSize.width = round(newSize.width);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
460 newSize.height = round(newSize.height);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
461 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
462 _size = newSize;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
463 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
464 resized(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
465 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
466 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
467 void size(real[] newSize) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
468 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
469 size = Size(newSize[0], newSize[1]);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
470 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
471
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
472 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
473 * 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
474 * 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
475 * 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
476 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
477 * 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
478 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
479 Size bestSize() { return Size(100, 100); }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
480
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
481 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
482 * 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
483 * 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
484 * text, 0 may be returned.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
485 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
486 int baseline() { return 0; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
487
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
488 /// Same as location.x
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
489 real x() { return location.x; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
490 /// Same as location.y
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
491 real y() { return location.y; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
492 /// Same as size.width
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
493 real width() { return size.width; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
494 /// Same as size.height
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
495 real height() { return size.height; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
496
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
497 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
498 * Gets or sets whether this control is elastic horizontally or vertically.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
499 * 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
500 * best size.
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 bool elasticX() { return _elasticX; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
503 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
504 void elasticX(bool b) { _elasticX = b; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
505 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
506 bool elasticY() { return _elasticY; }
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 elasticY(bool b) { _elasticY = b; }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
509
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
510 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
511 * Gets or sets the text that this control shows.
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 string text() { return _text.dup; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
514 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
515 void text(string str) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
516 _text = str.dup;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
517 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
518 //TextChanged(EventArgs e) // TODO: add event
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
519 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
520
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
521 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
522 * Gets or sets the background color of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
523 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
524 Color backColor() { return _backColor; }
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 backColor(Color c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
527 _backColor = c;
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 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
530
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
531 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
532 * Gets or sets the foreground color of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
533 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
534 Color foreColor() { return _foreColor; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
535 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
536 void foreColor(Color c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
537 _foreColor = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
538 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
539 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
540
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
541 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
542 * 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
543 * 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
544 * current theme's font is used. The default is null.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
545 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
546 Font font() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
547 // TODO: if font is null (unset), return from theme
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
548 //if(font is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
549 // return Theme.Current.Control_Font(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
550 //else
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
551 return _font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
552 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
553 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
554 void font(Font f) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
555 _font = f;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
556 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
557 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
558
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
559 void setCurrentCursor(Cursor cur) {
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
560 if(parent)
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
561 parent.setCurrentCursor(cur);
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
562 }
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
563 /**
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
564 * 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
565 * is over this control.
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
566 */
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
567 Cursor cursor() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
568 return _cursor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
569 }
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
570 /// ditto
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
571 void cursor(Cursor cur) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
572 if(_cursor is cur)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
573 return;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
574 _cursor = cur;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
575 if(getHotControl() is this)
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
576 setCurrentCursor(_cursor);
0
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
579 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
580 * Causes the part of the control inside the specified
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
581 * rectangle to be repainted. The rectangle is in content coordinates.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
582 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
583 * The control will not be repainted before this method returns; rather,
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
584 * 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
585 * 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
586 * be called.
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
587 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
588 void repaint(Rect rect) {
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
589 // 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
590 // not invalidated
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
591 if(_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
592 _parent.repaint(rect + location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
593 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
594 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
595 void repaint(real x, real y, real width, real height) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
596 repaint(Rect(x, y, width, height));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
597 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
598 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
599 * Causes the entire control to be repainted.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
600 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
601 void repaint() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
602 repaint(Rect(0, 0, width, height));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
603 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
604 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
605
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
606