1 #include <lib/gui/slider.h>
3 #include <lib/gui/eskin.h>
4 #include <lib/gui/elabel.h>
5 #include <lib/gui/guiactions.h>
6 #include <lib/system/init.h>
7 #include <lib/system/init_num.h>
9 inline void swap( gColor
& a
, gColor
& b
)
16 eSlider::eSlider( eWidget
* parent
, const eWidget
*descr
, int min
, int max
)
17 :eProgress( parent
, 1), descr(descr
)
19 activated_left
= eSkin::getActive()->queryScheme( "eSlider.activated.left" );
20 activated_right
= eSkin::getActive()->queryScheme( "eSlider.activated.right" );
23 incrementation
= 4; // in Percent
24 addActionMap(&i_cursorActions
->map
);
27 void eSlider::setMin( int i
)
32 void eSlider::setMax( int i
)
34 max
= (i
<= min
) ? 99 : i
;
37 void eSlider::setValue( int i
)
39 if ( i
>= min
&& i
<= max
)
40 // setPerc( (int) round( i * (double)100/((max-min)+1) ) );
41 setPerc((i
-min
) * 100 / (max
-min
));
46 int eSlider::getValue()
48 int ret
= (int) ( (double) perc
/ 100 * ( (max
-min
)+1));
49 return (ret
> max
? max
: ret
);
52 void eSlider::setIncrement( int i
)
60 int eSlider::setProperty( const eString
&prop
, const eString
&val
)
62 if (prop
== "leftColorActive")
63 activated_left
=eSkin::getActive()->queryColor( prop
);
64 else if (prop
== "rightColorActive")
65 activated_right
=eSkin::getActive()->queryColor( prop
);
66 else if (prop
== "incrementation")
67 setIncrement( atoi( val
.c_str() ) );
68 else if (prop
== "min")
69 setMin( atoi(val
.c_str()) );
70 else if (prop
== "max")
71 setMax( atoi(val
.c_str()) );
73 return eProgress::setProperty( prop
, val
);
77 void eSlider::gotFocus()
80 swap( left
, activated_left
);
81 swap( right
, activated_right
);
84 if (parent
&& parent
->LCDElement
) // detect if LCD Avail
86 LCDTmp
= new eProgress( parent
->LCDElement
);
88 LCDTmp
->setForegroundColor( 255 );
89 ((eSlider
*)LCDTmp
)->left
=255;
90 ((eSlider
*)LCDTmp
)->right
=0;
91 ((eProgress
*)LCDTmp
)->setPerc( perc
);
92 eSize s
= parent
->LCDElement
->getSize();
96 LCDTmp
->move(ePoint(0, s
.height()/2 + s
.height()/4 - 6 ));
97 LCDTmp
->resize( eSize(s
.width(), 12) );
98 tmpDescr
= new eLabel(parent
->LCDElement
);
100 tmpDescr
->move(ePoint(0,0));
101 tmpDescr
->resize(eSize(s
.width(), s
.height()/2));
102 tmpDescr
->setText(descr
->getText());
107 LCDTmp
->resize( eSize(s
.width(), 8) );
108 LCDTmp
->move(ePoint(0, s
.height() / 2 - 6));
110 ((eProgress
*)LCDTmp
)->setPerc( perc
);
113 #endif // DISABLE_LCD
117 void eSlider::lostFocus()
120 swap( left
, activated_left
);
121 swap( right
, activated_right
);
139 int eSlider::eventHandler( const eWidgetEvent
& event
)
143 case eWidgetEvent::evtAction
:
145 if(event
.action
== &i_cursorActions
->right
)
147 if ( (perc
+= incrementation
) > 100 )
150 else if(event
.action
== &i_cursorActions
->left
)
152 if ( (perc
-=incrementation
) < 0 )
158 /* emit */ changed( getValue() );
161 ((eProgress
*)LCDTmp
)->setPerc( perc
);
168 return eProgress::eventHandler( event
);
171 static eWidget
*create_eSlider(eWidget
*parent
)
173 return new eSlider(parent
);
176 class eSliderSkinInit
181 eSkin::addWidgetCreator("eSlider", create_eSlider
);
185 eSkin::removeWidgetCreator("eSlider", create_eSlider
);
189 eAutoInitP0
<eSliderSkinInit
> init_eSliderSkinInit(eAutoInitNumbers::guiobject
, "eSlider");