annotate dynamin/gui/control.d @ 8:b621b528823d

whenXX methods have to come before the event if switched to template mixins.
author Jordan Miner <jminer7@gmail.com>
date Wed, 15 Jul 2009 14:04:55 -0500
parents 4029d5af7542
children ccc108b25a0a
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) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
77 Cursor.setCurrent(this, _cursor);
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 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
107 protected void dispatchPainting(PaintingEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
108 e.graphics.save();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
109 painting.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
110 e.graphics.restore();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
111 e.graphics.save();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
112 // 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
113 painting.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
114 e.graphics.restore();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
115 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
116
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
117 /// Override this method in a subclass to handle the Moved event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
118 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
119 /// This event occurs after the control has been moved.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
120 Event!() moved;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
121
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
122 /// Override this method in a subclass to handle the Resized event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
123 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
124 /// This event occurs after the control has been resized.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
125 Event!() resized;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
126
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
127 /// Override this method in a subclass to handle the MouseEntered event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
128 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
129 /// This event occurs after the mouse has entered the control.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
130 Event!() mouseEntered;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
131
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
132 /// Override this method in a subclass to handle the MouseLeft event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
133 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
134 /// This event occurs after the mouse has left the control.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
135 Event!() mouseLeft;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
136
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
137 /// Override this method in a subclass to handle the MouseDown event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
138 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
139 /// This event occurs after a mouse button is pressed.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
140 Event!(MouseEventArgs) mouseDown;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
141
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
142 /// Override this method in a subclass to handle the MouseUp event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
143 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
144 /// This event occurs after a mouse button is released.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
145 Event!(MouseEventArgs) mouseUp;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
146
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
147 /// Override this method in a subclass to handle the MouseMoved event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
148 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
149 /// This event occurs after the mouse has been moved.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
150 Event!(MouseEventArgs) mouseMoved;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
151
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
152 /// Override this method in a subclass to handle the MouseMoved event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
153 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
154 /// This event occurs after the mouse has been moved.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
155 Event!(MouseEventArgs) mouseDragged;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
156
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
157 /// Override this method in a subclass to handle the MouseTurned event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
158 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
159 /// This event occurs after the mouse wheel has been turned.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
160 Event!(MouseTurnedEventArgs) mouseTurned;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
161
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
162 /// Override this method in a subclass to handle the KeyDown event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
163 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
164 /// This event occurs after a key is pressed.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
165 Event!(KeyEventArgs) keyDown;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
166
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
167 /// Override this method in a subclass to handle the KeyTyped event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
168 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
169 /// This event occurs after a character key is pressed.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
170 Event!(KeyTypedEventArgs) keyTyped;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
171
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
172 /// Override this method in a subclass to handle the KeyUp event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
173 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
174 /// This event occurs after a key is released.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
175 Event!(KeyEventArgs) keyUp;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
176
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
177 /// 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
178 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
179 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
180 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
181 }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
182 /// This event occurs when the control needs to be painted.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
183 Event!(PaintingEventArgs) painting;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
184
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
185 this() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
186 moved = new Event!()(&whenMoved);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
187 resized = new Event!()(&whenResized);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
188 mouseEntered = new Event!()(&whenMouseEntered, &dispatchMouseEntered);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
189 mouseLeft = new Event!()(&whenMouseLeft);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
190 mouseDown = new Event!(MouseEventArgs)(&whenMouseDown, &dispatchMouseDown);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
191 mouseUp = new Event!(MouseEventArgs)(&whenMouseUp, &dispatchMouseUp);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
192 mouseMoved = new Event!(MouseEventArgs)(&whenMouseMoved, &dispatchMouseMoved);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
193 mouseDragged = new Event!(MouseEventArgs)(&whenMouseDragged, &dispatchMouseDragged);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
194 mouseTurned = new Event!(MouseTurnedEventArgs)(&whenMouseTurned, &dispatchMouseTurned);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
195 keyDown = new Event!(KeyEventArgs)(&whenKeyDown);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
196 keyTyped = new Event!(KeyTypedEventArgs)(&whenKeyTyped);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
197 keyUp = new Event!(KeyEventArgs)(&whenKeyUp);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
198 painting = new Event!(PaintingEventArgs)(&whenPainting, &dispatchPainting);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
199
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
200 _location = Point(0, 0);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
201 _size = Size(100, 100);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
202 _text = "";
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
203 _focusable = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
204 _focused = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
205 _visible = true;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
206 _cursor = Cursor.Arrow;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
207 _elasticX = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
208 _elasticY = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
209
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
210 // TODO: remove these when themes mature
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
211 _foreColor = Color.Black;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
212 _font = new Font("Tahoma", 11);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
213 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
214
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
215 protected Graphics quickCreateGraphics() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
216 if(_parent is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
217 return null;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
218 auto g = _parent.quickCreateGraphics();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
219 g.translate(location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
220 return g;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
221 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
222
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
223 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
224 * 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
225 * and foreground color. Also, clips to this control's rectangle.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
226 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
227 void setupGraphics(Graphics g) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
228 g.rectangle(0, 0, width, height);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
229 g.clip();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
230 g.font = font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
231 g.source = foreColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
232 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
233
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
234 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
235 * Creates a Graphics, calls the specified delegate with it, and deletes
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
236 * it to release resources.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
237 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
238 void withGraphics(void delegate(Graphics g) dg) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
239 auto g = quickCreateGraphics();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
240 setupGraphics(g);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
241 dg(g);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
242 delete g;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
243 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
244
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
245 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
246 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
247 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
248 bool focused() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
249 return _focused;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
250 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
251
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
252 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
253 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
254 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
255 void focus() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
256 if(!_focusable)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
257 return;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
258 Control c = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
259 while(c.parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
260 c = c.parent;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
261 if(auto win = cast(Window)c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
262 if(win.focusedControl) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
263 win.focusedControl._focused = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
264 win.focusedControl.repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
265 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
266 win.focusedControl = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
267 _focused = true;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
268 repaint();
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 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
271
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
272 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
273 * Returns whether this control is on the screen. A control is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
274 * 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
275 * 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
276 * has no parent, then it is clearly not on the screen.
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 bool onScreen() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
279 return _parent && _parent.onScreen;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
280 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
281
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
282 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
283 * 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
284 * thrown if this control is not on the screen.
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 Point screenLocation() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
287 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
288 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
289 return _parent.screenLocation + location;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
290 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
291
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
292 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
293 * Converts the specified point in content coordinates into screen
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
294 * 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
295 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
296 Point contentToScreen(Point pt) { // TODO: content?? even on Window??
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
297 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
298 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
299 return _parent.contentToScreen(pt + location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
300 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
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 * Converts the specified point in screen coordinates into content
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
304 * 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
305 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
306 Point screenToContent(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
307 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
308 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
309 return _parent.screenToContent(pt) - location; // TODO: borders
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
310 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
311
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
312 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
313 * Converts the specified point in this control's content coordinates
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
314 * into the specified control's content coordinates. An exception is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
315 * thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
316 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
317 Point contentToContent(Point pt, Control c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
318 return c.screenToContent(contentToScreen(pt));
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 the specified point is inside this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
323 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
324 bool contains(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
325 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
326 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
327 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
328 bool contains(real x, real y) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
329 return contains(Point(x, y));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
330 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
331
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
332 bool topLevel() { return false; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
333 // TODO: return NativeControl/Window?
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
334 Control getTopLevel() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
335 Control c = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
336 while(c.parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
337 c = c.parent;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
338 return c.topLevel ? c : null;
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 * Gets this control's parent.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
343 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
344 Container parent() { return _parent; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
345 package void parent(Container c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
346 _parent = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
347 //ParentChanged(new EventArgs); // TODO: add event
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
348 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
349
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
350 /**
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
351 * 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
352 * on top-level windows.
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 //void visible(bool b) { visible = b; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
355 bool visible() { return _visible; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
356
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
357 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
358 * 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
359 * coordinates.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
360 * Examples:
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 * control.location = [5, 35];
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
363 * control.location = Point(50, 50);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
364 * -----
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 location() { return _location; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
367 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
368 void location(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
369 if((cast(Window)_parent) !is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
370 throw new Exception("cannot set location of a window's content");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
371 pt.x = round(pt.x);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
372 pt.y = round(pt.y);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
373 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
374 _location = pt;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
375 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
376 moved(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
377 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
378 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
379 void location(real[] pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
380 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
381 location = Point(pt[0], pt[1]);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
382 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
383
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
384 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
385 * Gets or sets the size of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
386 * Examples:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
387 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
388 * control.size = [75, 23];
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
389 * control.size = Size(80, 20);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
390 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
391 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
392 Size size() { return _size; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
393 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
394 void size(Size newSize) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
395 if(newSize.width < 0)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
396 newSize.width = 0;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
397 if(newSize.height < 0)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
398 newSize.height = 0;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
399 newSize.width = round(newSize.width);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
400 newSize.height = round(newSize.height);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
401 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
402 _size = newSize;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
403 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
404 resized(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
405 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
406 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
407 void size(real[] newSize) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
408 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
409 size = Size(newSize[0], newSize[1]);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
410 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
411
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
412 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
413 * 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
414 * 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
415 * 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
416 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
417 * 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
418 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
419 Size bestSize() { return Size(100, 100); }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
420
0
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 * 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
423 * 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
424 * text, 0 may be returned.
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 int baseline() { return 0; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
427
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
428 /// Same as location.x
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
429 real x() { return location.x; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
430 /// Same as location.y
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
431 real y() { return location.y; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
432 /// Same as size.width
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
433 real width() { return size.width; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
434 /// Same as size.height
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
435 real height() { return size.height; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
436
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 * Gets or sets whether this control is elastic horizontally or vertically.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
439 * 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
440 * best size.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
441 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
442 bool elasticX() { return _elasticX; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
443 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
444 void elasticX(bool b) { _elasticX = b; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
445 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
446 bool elasticY() { return _elasticY; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
447 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
448 void elasticY(bool b) { _elasticY = b; }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
449
0
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 * Gets or sets the text that this control shows.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
452 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
453 string text() { return _text.dup; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
454 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
455 void text(string str) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
456 _text = str.dup;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
457 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
458 //TextChanged(EventArgs e) // TODO: add event
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
461 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
462 * Gets or sets the background color of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
463 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
464 Color backColor() { return _backColor; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
465 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
466 void backColor(Color c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
467 _backColor = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
468 repaint();
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
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 * Gets or sets the foreground color of this control.
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 Color foreColor() { return _foreColor; }
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 foreColor(Color c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
477 _foreColor = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
478 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
479 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
480
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 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
483 * 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
484 * current theme's font is used. The default is null.
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 Font font() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
487 // TODO: if font is null (unset), return from theme
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
488 //if(font is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
489 // return Theme.Current.Control_Font(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
490 //else
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
491 return _font;
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 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
494 void font(Font f) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
495 _font = f;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
496 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
497 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
498
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
499 Cursor cursor() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
500 return _cursor;
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 void cursor(Cursor cur) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
503 if(_cursor is cur)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
504 return;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
505 _cursor = cur;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
506 if(getHotControl() is this)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
507 Cursor.setCurrent(this, _cursor);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
508 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
509
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 * Causes the part of the control inside the specified
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
512 * rectangle to be repainted. The rectangle is in content coordinates.
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 * The control will not be repainted before this method returns; rather,
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
515 * the area is just marked as needing to be repainted. The next time there
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
516 * are no other system events to be processed, a painting event will called.
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 void repaint(Rect rect) {
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
519 // 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
520 // not invalidated
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
521 if(_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
522 _parent.repaint(rect + location);
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 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
525 void repaint(real x, real y, real width, real height) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
526 repaint(Rect(x, y, width, height));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
527 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
528 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
529 * Causes the entire control to be repainted.
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 void repaint() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
532 repaint(Rect(0, 0, width, height));
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 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
535
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
536