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