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
|
#include <lib/gui/slider.h>
#include <lib/gui/eskin.h>
#include <lib/gui/elabel.h>
#include <lib/gui/guiactions.h>
#include <lib/base/init.h>
#include <lib/base/init_num.h>
inline void swap( gColor& a, gColor& b )
{
gColor tmp = a;
a = b;
b = tmp;
}
eSlider::eSlider( eWidget* parent, const eWidget *descr, int min, int max )
:eProgress( parent, 1), descr(descr)
{
activated_left = eSkin::getActive()->queryScheme( "eSlider.activated.left" );
activated_right = eSkin::getActive()->queryScheme( "eSlider.activated.right" );
setMin(min);
setMax(max);
incrementation = 4; // in Percent
addActionMap(&i_cursorActions->map);
}
void eSlider::setMin( int i )
{
min = i;
}
void eSlider::setMax( int i )
{
max = (i <= min) ? 99 : i;
}
void eSlider::setValue( int i )
{
if ( i >= min && i <= max )
setPerc( (int) round( i * (double)100/((max-min)+1) ) );
else
setPerc( 0 );
}
int eSlider::getValue()
{
int ret = (int) ( (double) perc / 100 * ( (max-min)+1));
return (ret > max ? max : ret);
}
void eSlider::setIncrement( int i )
{
if (!i)
incrementation = 4;
else
incrementation = i;
}
int eSlider::setProperty( const eString &prop, const eString &val)
{
if (prop == "leftColorActive")
activated_left=eSkin::getActive()->queryColor( prop );
else if (prop == "rightColorActive")
activated_right=eSkin::getActive()->queryColor( prop );
else if (prop == "incrementation")
setIncrement( atoi( val.c_str() ) );
else if (prop == "min")
setMin( atoi(val.c_str()) );
else if (prop == "max")
setMax( atoi(val.c_str()) );
else
return eProgress::setProperty( prop, val );
return 0;
}
void eSlider::gotFocus()
{
have_focus++;
swap( left, activated_left );
swap( right, activated_right );
#ifndef DISABLE_LCD
if (parent && parent->LCDElement) // detect if LCD Avail
{
LCDTmp = new eProgress( parent->LCDElement );
LCDTmp->hide();
LCDTmp->setForegroundColor( 255 );
((eSlider*)LCDTmp)->left=255;
((eSlider*)LCDTmp)->right=0;
((eProgress*)LCDTmp)->setPerc( perc );
eSize s = parent->LCDElement->getSize();
if (descr)
{
LCDTmp->move(ePoint(0, s.height()/2 + s.height()/4 - 6 ));
LCDTmp->resize( eSize(s.width(), 12) );
tmpDescr = new eLabel(parent->LCDElement);
tmpDescr->hide();
tmpDescr->move(ePoint(0,0));
tmpDescr->resize(eSize(s.width(), s.height()/2));
tmpDescr->setText(descr->getText());
tmpDescr->show();
}
else
{
LCDTmp->resize( eSize(s.width(), 8) );
LCDTmp->move(ePoint(0, s.height() / 2 - 6));
}
((eProgress*)LCDTmp)->setPerc( perc );
LCDTmp->show();
}
#endif // DISABLE_LCD
redraw();
}
void eSlider::lostFocus()
{
// swap back;
swap( left, activated_left );
swap( right, activated_right );
#ifndef DISABLE_LCD
if (LCDTmp)
{
delete LCDTmp;
LCDTmp=0;
if (tmpDescr)
{
delete tmpDescr;
tmpDescr=0;
}
}
#endif
have_focus--;
invalidate();
}
int eSlider::eventHandler( const eWidgetEvent& event )
{
switch (event.type)
{
case eWidgetEvent::evtAction:
{
if(event.action == &i_cursorActions->right)
{
if ( (perc += incrementation) > 100 )
perc = 100;
}
else if(event.action == &i_cursorActions->left)
{
if ( (perc-=incrementation) < 0 )
perc = 0;
}
else
break;
redraw();
/* emit */ changed( getValue() );
#ifndef DISABLE_LCD
if (LCDTmp)
((eProgress*)LCDTmp)->setPerc( perc );
#endif
return 1;
}
default:
break;
}
return eProgress::eventHandler( event );
}
static eWidget *create_eSlider(eWidget *parent)
{
return new eSlider(parent);
}
class eSliderSkinInit
{
public:
eSliderSkinInit()
{
eSkin::addWidgetCreator("eSlider", create_eSlider);
}
~eSliderSkinInit()
{
eSkin::removeWidgetCreator("eSlider", create_eSlider);
}
};
eAutoInitP0<eSliderSkinInit> init_eSliderSkinInit(eAutoInitNumbers::guiobject, "eSlider");
|