2
2
PLIB - A Suite of Portable Game Libraries
3
Copyright (C) 2001 Steve Baker
3
Copyright (C) 1998,2002 Steve Baker
5
5
This library is free software; you can redistribute it and/or
6
6
modify it under the terms of the GNU Library General Public
7
7
License as published by the Free Software Foundation; either
8
8
version 2 of the License, or (at your option) any later version.
10
10
This library is distributed in the hope that it will be useful,
11
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
13
Library General Public License for more details.
15
15
You should have received a copy of the GNU Library General Public
16
License along with this library; if not, write to the Free
16
License along with this library; if not, write to the Free Software
17
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
19
For further information visit http://plib.sourceforge.net
21
$Id: puBiSlider.cxx,v 1.11 2001/06/19 02:42:18 sjbaker Exp $
21
$Id: puBiSlider.cxx,v 1.22 2002/09/02 06:05:45 sjbaker Exp $
24
25
#include "puLocal.h"
27
UL_RTTI_DEF1(puBiSlider,puSlider)
26
30
void puBiSlider::draw ( int dx, int dy )
28
32
if ( !visible || ( window != puGetWindow () ) ) return ;
30
34
// Draw the slider box itself
33
(style==PUSTYLE_BEVELLED||
34
style==PUSTYLE_SHADED) ? -PUSTYLE_BOXED : -style,
36
if ( ( style == PUSTYLE_BEVELLED ) ||
37
( style == PUSTYLE_SHADED ) )
38
abox.draw ( dx, dy, -PUSTYLE_BOXED, colour, FALSE, 2 ) ;
40
abox.draw ( dx, dy, -style, colour, FALSE, border_thickness ) ;
38
43
r_cb ( this, dx, dy, render_data ) ;
50
55
char str_value[10] ;
51
sprintf (str_value, "%d", getCurrentMax() ) ;
56
sprintf (str_value, "%g", getCurrentMax() ) ;
53
draw_slider_box ( dx, dy, val, str_value ) ;
58
draw_slider_box ( dx, dy, abox, val, str_value ) ;
55
60
// Draw the current_min slider and label it
62
sprintf (str_value, "%d", getCurrentMin() ) ;
64
draw_slider_box ( dx, dy, val, str_value ) ;
66
// If greyed out then halve the opacity when drawing the label and legend
69
glColor4fv ( colour [ PUCOL_LEGEND ] ) ;
71
glColor4f ( colour [ PUCOL_LEGEND ][0],
72
colour [ PUCOL_LEGEND ][1],
73
colour [ PUCOL_LEGEND ][2],
74
colour [ PUCOL_LEGEND ][3] / 2.0f ) ; // 50% more transparent
76
int xx = ( abox.max[0] - abox.min[0] - puGetStringWidth(legendFont,legend) ) / 2 ;
77
int yy = ( abox.max[1] - abox.min[1] - puGetStringHeight(legendFont) ) / 2 ;
79
puDrawString ( legendFont, legend,
80
dx + abox.min[0] + xx,
81
dy + abox.min[1] + yy ) ;
67
sprintf (str_value, "%g", getCurrentMin() ) ;
69
draw_slider_box ( dx, dy, abox, val, str_value ) ;
71
draw_legend ( dx, dy ) ;
84
74
draw_label ( dx, dy ) ;
122
112
next_value = (next_value < 0.0f) ? 0.0f : (next_value > 1.0) ? 1.0f : next_value ;
124
int new_value = getMinValue() + (int)( next_value * ( getMaxValue() - getMinValue() ) + 0.5 ) ;
114
float new_value = getMinValue() + next_value * ( getMaxValue() - getMinValue() ) ;
126
116
if ( ( getActiveButton() == 0 ) || ( updown == PU_DOWN ) ) // No currently-active slider, set whichever is closest
128
118
if ( (new_value-getCurrentMin()) < (getCurrentMax()-new_value) ) // Closest to current_min
130
setCurrentMin ( new_value ) ;
120
setCurrentMin ( checkStep(new_value) ) ;
131
121
setActiveButton ( 1 ) ;
133
123
else // Closest to current_max
135
setCurrentMax ( new_value ) ;
125
setCurrentMax ( checkStep(new_value) ) ;
136
126
setActiveButton ( 2 ) ;
139
129
else if ( getActiveButton() == 1 ) // Currently moving current_min
141
setCurrentMin ( new_value ) ;
131
setCurrentMin ( checkStep(new_value) ) ;
142
132
if ( getCurrentMax() < getCurrentMin() ) setCurrentMax ( getCurrentMin() ) ;
144
134
else if ( getActiveButton() == 2 ) // Currently moving current_max
146
setCurrentMax ( new_value ) ;
136
setCurrentMax ( checkStep(new_value) ) ;
147
137
if ( getCurrentMax() < getCurrentMin() ) setCurrentMin ( getCurrentMax() ) ;