annotate dynamin/gui/check_box.d @ 103:73060bc3f004

Change license to Boost 1.0 and MPL 2.0.
author Jordan Miner <jminer7@gmail.com>
date Tue, 15 May 2012 22:06:02 -0500
parents 651082a9b364
children
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
8 *
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
11 module dynamin.gui.check_box;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
12
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
13 import dynamin.all_core;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
14 import dynamin.all_gui;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
15 import dynamin.all_painting;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
16 import tango.io.Stdout;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
17
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
18 enum CheckState {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
19 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
20 Unchecked,
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
21 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
22 Checked,
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 Both
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
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 * A control that can be checked or unchecked independent of other controls.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
29 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
30 * The appearance of a check box with Windows Classic:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
31 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
32 * $(IMAGE ../web/example_check_box.png)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
33 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
34 class CheckBox : Button {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
35 protected:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
36 CheckState _checkState = CheckState.Unchecked;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
37 override void whenClicked(EventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
38 checked = !checked;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
39 focus();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
40 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
41 override void whenPainting(PaintingEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
42 Theme.current.CheckBox_paint(this, e.graphics);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
43 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
44
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
52 _focusable = true;
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 this(string text) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
55 this();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
56 this.text = text;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
57 }
51
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 10
diff changeset
58 /// Gets or sets whether this check box is checked.
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
59 bool checked() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
60 return _checkState == CheckState.Checked;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
61 }
51
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 10
diff changeset
62 /// ditto
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
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
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
68 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
69 checkedChanged(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
70 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
71 override Size bestSize() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
72 return Size(70, 15);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
73 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
74 override void paintFore(Graphics g) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
75 g.drawText(text, 0, (height-g.getTextExtents(text).height)/2);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
76 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
77 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
78