1 /*
2 Copyright (C) 2001-2013 The Exult Team
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18 
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22 
23 #include "Gump_ToggleButton.h"
24 #include "gamewin.h"
25 #include "Gump.h"
26 
activate(int button)27 bool Gump_ToggleButton::activate(int button) {
28 	int delta;
29 	if (button == 1)
30 		delta = 2;
31 	else if (button == 3)
32 		delta = 2 * numselections - 2;
33 	else
34 		return false;
35 
36 	set_frame((get_framenum() + delta) % (2 * numselections));
37 	toggle(get_framenum() / 2);
38 	paint();
39 	gwin->set_painted();
40 	return true;
41 }
42 
push(int button)43 bool Gump_ToggleButton::push(int button) {
44 	if (button == 1 || button == 3) {
45 		set_pushed(button);
46 		paint();
47 		gwin->set_painted();
48 		return true;
49 	}
50 	return false;
51 }
52 
53 
unpush(int button)54 void Gump_ToggleButton::unpush(
55     int button
56 ) {
57 	if (button == 1 || button == 3) {
58 		set_pushed(false);
59 		paint();
60 		gwin->set_painted();
61 	}
62 }
63 
activate(int button)64 bool Gump_ToggleTextButton::activate(int button) {
65 	int delta;
66 	int numselections = selections.size();
67 	if (button == 1)
68 		delta = 1;
69 	else if (button == 3)
70 		delta = numselections - 1;
71 	else
72 		return false;
73 
74 	set_frame((get_framenum() + delta) % numselections);
75 	text = selections[get_framenum()];
76 	init();
77 	toggle(get_framenum());
78 	paint();
79 	gwin->set_painted();
80 	return true;
81 }
82 
push(int button)83 bool Gump_ToggleTextButton::push(int button) {
84 	if (button == 1 || button == 3) {
85 		set_pushed(button);
86 		paint();
87 		gwin->set_painted();
88 		return true;
89 	}
90 	return false;
91 }
92 
93 
unpush(int button)94 void Gump_ToggleTextButton::unpush(
95     int button
96 ) {
97 	if (button == 1 || button == 3) {
98 		set_pushed(false);
99 		paint();
100 		gwin->set_painted();
101 	}
102 }
103