Mercurial > projects > dynamin
annotate dynamin/gui/check_box.d @ 113:4636a64afabc default tip
Add reverse() function.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 19 Jan 2013 21:08:52 -0600 |
parents | 73060bc3f004 |
children |
rev | line source |
---|---|
0 | 1 |
2 /* | |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
78
diff
changeset
|
3 * Copyright Jordan Miner |
0 | 4 * |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
78
diff
changeset
|
5 * This Source Code Form is subject to the terms of the Mozilla Public |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
78
diff
changeset
|
6 * License, v. 2.0. If a copy of the MPL was not distributed with this |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
78
diff
changeset
|
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
0 | 8 * |
9 */ | |
10 | |
11 module dynamin.gui.check_box; | |
12 | |
13 import dynamin.all_core; | |
14 import dynamin.all_gui; | |
15 import dynamin.all_painting; | |
16 import tango.io.Stdout; | |
17 | |
18 enum CheckState { | |
19 /// | |
20 Unchecked, | |
21 /// | |
22 Checked, | |
23 /// | |
24 Both | |
25 } | |
26 | |
27 /** | |
28 * A control that can be checked or unchecked independent of other controls. | |
29 * | |
30 * The appearance of a check box with Windows Classic: | |
31 * | |
32 * $(IMAGE ../web/example_check_box.png) | |
33 */ | |
34 class CheckBox : Button { | |
35 protected: | |
36 CheckState _checkState = CheckState.Unchecked; | |
37 override void whenClicked(EventArgs e) { | |
38 checked = !checked; | |
39 focus(); | |
40 } | |
41 override void whenPainting(PaintingEventArgs e) { | |
42 Theme.current.CheckBox_paint(this, e.graphics); | |
43 } | |
44 | |
45 public: | |
10
ccc108b25a0a
Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents:
8
diff
changeset
|
46 /// Override this method in a subclass to handle the checkedChanged event. |
8
b621b528823d
whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
47 protected void whenCheckedChanged(EventArgs e) { } |
0 | 48 /// This event occurs after . |
10
ccc108b25a0a
Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents:
8
diff
changeset
|
49 Event!(whenCheckedChanged) checkedChanged; |
0 | 50 this() { |
78
651082a9b364
Add Event.setUp() and use in place of mainHandler and dispatcher.
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
51 checkedChanged.setUp(&whenCheckedChanged); |
0 | 52 _focusable = true; |
53 } | |
54 this(string text) { | |
55 this(); | |
56 this.text = text; | |
57 } | |
51 | 58 /// Gets or sets whether this check box is checked. |
0 | 59 bool checked() { |
60 return _checkState == CheckState.Checked; | |
61 } | |
51 | 62 /// ditto |
0 | 63 void checked(bool b) { |
68
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
51
diff
changeset
|
64 auto old = _checkState; |
0 | 65 _checkState = b ? CheckState.Checked : CheckState.Unchecked; |
68
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
51
diff
changeset
|
66 if(_checkState == old) |
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
51
diff
changeset
|
67 return; |
0 | 68 repaint(); |
69 checkedChanged(new EventArgs); | |
70 } | |
71 override Size bestSize() { | |
72 return Size(70, 15); | |
73 } | |
74 override void paintFore(Graphics g) { | |
75 g.drawText(text, 0, (height-g.getTextExtents(text).height)/2); | |
76 } | |
77 } | |
78 |