2
Copyright (C) 2006 Parallel Realities
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.
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.
13
See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include "../headers.h"
45
void Slider::setProperties(Properties *properties)
47
setBaseValues(properties);
49
min = properties->getInt("min", 0);
50
max = properties->getInt("max", 100);
52
step = properties->getInt("step", 1);
54
value = properties->getInt("value", 0);
56
smooth = properties->getInt("smooth", 1);
59
void Slider::use(int mx, int my)
61
if (Collision::collision(mx, my, 1, 1, x + 24, y, width - 48, 16))
64
percent = mx - (x + 24);
65
percent /= (width - 48);
67
value = percent * max;
73
bool Slider::hasChanged()
86
value += (dir * step * Engine::getInstance()->getTimeDifference(TD_ANIMATION));
87
Math::limit(&value, min, max);
94
if ((dir == -1) || (dir == 1))
100
void Slider::mouseMoved(int mx, int my)
107
if ((mx >= x + 24) && (mx <= x + width - 16))
110
percent = mx - (x + 24);
111
percent /= (width - 48);
113
value = percent * max;
115
Math::limit(&value, min, max);
135
void Slider::mousePressed(SDL_MouseButtonEvent mouse)
137
if (Collision::collision(mouse.x, mouse.y, 1, 1, x, y, 16, 16))
142
if (Collision::collision(mouse.x, mouse.y, 1, 1, x + width - 16, y, 16, 16))
147
if (Collision::collision(mouse.x, mouse.y, 1, 1, x + 24, y, width - 48, 16))
150
percent = mouse.x - (x + 24);
151
percent /= (width - 48);
153
value = percent * max;
161
void Slider::mouseReleased(SDL_MouseButtonEvent mouse)
167
void Slider::change(int x)
171
Math::limit(&value, min, max);