forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrowButton.cpp
More file actions
209 lines (180 loc) · 3.89 KB
/
Copy pathArrowButton.cpp
File metadata and controls
209 lines (180 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Copyright 2010 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ArrowButton.h"
#include "TextList.h"
#include "../Engine/Timer.h"
namespace OpenXcom
{
/**
* Sets up an arrow button with the specified size and position.
* @param shape Shape of the arrow.
* @param width Width in pixels.
* @param height Height in pixels.
* @param x X position in pixels.
* @param y Y position in pixels.
*/
ArrowButton::ArrowButton(ArrowShape shape, int width, int height, int x, int y) : ImageButton(width, height, x, y), _shape(shape), _list(0)
{
_validButton = SDL_BUTTON_LEFT;
_timer = new Timer(50);
_timer->onTimer((SurfaceHandler)&ArrowButton::scroll);
}
/**
* Deletes timers.
*/
ArrowButton::~ArrowButton()
{
delete _timer;
}
/**
* Changes the color for the arrow button.
* @param color Color value.
*/
void ArrowButton::setColor(Uint8 color)
{
ImageButton::setColor(color);
draw();
}
/**
* Changes the text associated with the arrow button.
* This makes the button scroll that list.
* @param list Pointer to text list.
*/
void ArrowButton::setTextList(TextList *list)
{
_list = list;
}
/**
* Draws the button with the specified arrow shape.
*/
void ArrowButton::draw()
{
lock();
// Draw button
SDL_Rect square;
int color = _color - 1;
square.x = 0;
square.y = 0;
square.w = getWidth() - 1;
square.h = getHeight() - 1;
drawRect(&square, color);
square.x++;
square.y++;
color = _color + 2;
drawRect(&square, color);
square.w--;
square.h--;
color = _color + 1;
drawRect(&square, color);
setPixel(0, 0, _color - 2);
setPixel(0, getHeight() - 1, _color + 1);
setPixel(getWidth() - 1, 0, _color + 1);
color = _color - 2;
if (_shape == ARROW_BIG_UP)
{
// Draw arrow square
square.x = 5;
square.y = 8;
square.w = 3;
square.h = 3;
drawRect(&square, color);
// Draw arrow triangle
square.x = 2;
square.y = 7;
square.w = 9;
square.h = 1;
for (; square.w > 1; square.w -= 2)
{
drawRect(&square, color);
square.x++;
square.y--;
}
drawRect(&square, color);
}
else if (_shape == ARROW_BIG_DOWN)
{
// Draw arrow square
square.x = 5;
square.y = 3;
square.w = 3;
square.h = 3;
drawRect(&square, color);
// Draw arrow triangle
square.x = 2;
square.y = 6;
square.w = 9;
square.h = 1;
for (; square.w > 1; square.w -= 2)
{
drawRect(&square, color);
square.x++;
square.y++;
}
drawRect(&square, color);
}
unlock();
}
/**
* Keeps the scrolling timers running.
*/
void ArrowButton::think()
{
_timer->think(0, this);
}
/**
* Scrolls the list.
*/
void ArrowButton::scroll()
{
if (_shape == ARROW_BIG_UP)
{
_list->scrollUp();
}
else if (_shape == ARROW_BIG_DOWN)
{
_list->scrollDown();
}
}
/**
* Starts scrolling the associated list.
* @param action Pointer to an action.
* @param state State that the action handlers belong to.
*/
void ArrowButton::mousePress(Action *action, State *state)
{
ImageButton::mousePress(action, state);
if (_list != 0)
{
_timer->start();
}
}
/*
* Stops scrolling the associated list.
* @param action Pointer to an action.
* @param state State that the action handlers belong to.
*/
void ArrowButton::mouseRelease(Action *action, State *state)
{
ImageButton::mouseRelease(action, state);
if (_list != 0)
{
_timer->stop();
}
}
}