initial commit
[ld42_outofspace] / src / goatkit / checkbox.cc
1 /*
2 GoatKit - a themable/animated widget toolkit for games
3 Copyright (C) 2014-2015  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "checkbox.h"
19 #include "boolanm.h"
20
21 namespace goatkit {
22
23 struct CheckBoxImpl {
24         BoolAnim checked;
25 };
26
27 CheckBox::CheckBox()
28 {
29         cbox = new CheckBoxImpl;
30         cbox->checked = false;
31         cbox->checked.set_transition_duration(60);
32 }
33
34 CheckBox::~CheckBox()
35 {
36         delete cbox;
37 }
38
39 const char *CheckBox::get_type_name() const
40 {
41         return "checkbox";
42 }
43
44
45 void CheckBox::check()
46 {
47         cbox->checked.change(true);
48 }
49
50 void CheckBox::uncheck()
51 {
52         cbox->checked.change(false);
53 }
54
55 float CheckBox::get_checked() const
56 {
57         return cbox->checked.get_value();
58 }
59
60 bool CheckBox::is_checked() const
61 {
62         return cbox->checked.get_state();
63 }
64
65 void CheckBox::toggle()
66 {
67         if(is_checked()) {
68                 uncheck();
69         } else {
70                 check();
71         }
72 }
73
74 void CheckBox::set_toggle_transition(long msec)
75 {
76         cbox->checked.set_transition_duration(msec);
77 }
78
79 long CheckBox::get_toggle_transition() const
80 {
81         return cbox->checked.get_transition_duration();
82 }
83
84 void CheckBox::on_click()
85 {
86         toggle();
87
88         Event ev;
89         ev.type = EV_CHANGE;
90         handle_event(ev);
91 }
92
93 }       // namespace goatkit