1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <GLW/GLWSlider.h>
22 #include <GLW/GLWFont.h>
23 #include <GLEXT/GLState.h>
24 #include <common/Keyboard.h>
25 #include <common/ToolTip.h>
26 #include <client/ScorchedClient.h>
27 #include <tank/TankContainer.h>
28 #include <tank/TankState.h>
29 #include <tank/TankPosition.h>
31 REGISTER_CLASS_SOURCE(GLWSlider
);
33 GLWSlider::GLWSlider(float x
, float y
, float w
,
34 float min
, float max
, int marks
) :
35 GLWidget(x
, y
, w
, 20.0f
),
43 GLWSlider::~GLWSlider()
48 void GLWSlider::draw()
50 glBegin(GL_LINE_LOOP
);
51 drawBox(x_
- 4.0f
, y_
+ 8.0f
, w_
+ 12.0f
, 4.0f
, false);
54 glColor3f(0.0f
, 0.0f
, 0.0f
);
56 for (int i
=0; i
<=marks_
; i
++)
58 float dist
= float(i
) / float(marks_
);
59 glVertex2f(x_
+ w_
* dist
, y_
+ 12.0f
);
60 glVertex2f(x_
+ w_
* dist
, y_
+ 18.0f
);
62 glVertex2f(x_
+ w_
* dist
, y_
+ 2.0f
);
63 glVertex2f(x_
+ w_
* dist
, y_
+ 8.0f
);
67 float dist
= (current_
- min_
) / max_
;
68 glColor3f(0.8f
, 0.8f
, 1.0f
);
70 glVertex2f(x_
+ w_
* dist
, y_
);
71 glVertex2f(x_
+ w_
* dist
+ 4.0f
, y_
);
72 glVertex2f(x_
+ w_
* dist
+ 4.0f
, y_
+ 20.0f
);
73 glVertex2f(x_
+ w_
* dist
, y_
+ 20.0f
);
75 glBegin(GL_LINE_LOOP
);
76 drawBox(x_
+ w_
* dist
, y_
, 4.0f
, 20.0f
, true);
80 void GLWSlider::setCurrent(float current
)
83 if (handler_
) handler_
->currentChanged(getId(), current_
);
86 void GLWSlider::mouseDown(int button
, float x
, float y
, bool &skipRest
)
88 if (inBox(x
, y
, x_
, y_
, w_
, h_
))
92 float dist
= (x
- x_
) / w_
;
93 if (dist
>= 0.0f
&& dist
<= 1.0f
)
95 setCurrent(((max_
- min_
) * dist
) + min_
);
100 void GLWSlider::mouseUp(int button
, float x
, float y
, bool &skipRest
)
104 void GLWSlider::mouseDrag(int button
, float mx
, float my
, float x
, float y
, bool &skipRest
)
106 mouseDown(button
, mx
, my
, skipRest
);