[DEV] set slider support parameters instead of direct set & get
This commit is contained in:
parent
a41605b9b3
commit
e858cf8a74
@ -16,13 +16,13 @@
|
||||
const int32_t dotRadius = 6;
|
||||
|
||||
ewol::widget::Slider::Slider() :
|
||||
signalChange(*this, "change") {
|
||||
signalChange(*this, "change"),
|
||||
m_value(*this, "value", 0.0f, "Value of the Slider"),
|
||||
m_min(*this, "min", 0.0f, "Minium value"),
|
||||
m_max(*this, "max", 10.0f, "Maximum value"),
|
||||
m_step(*this, "step", 1.0f, "Step size") {
|
||||
addObjectType("ewol::widget::Slider");
|
||||
|
||||
m_value = 0;
|
||||
m_min = 0;
|
||||
m_max = 10;
|
||||
|
||||
m_textColorFg = etk::color::black;
|
||||
|
||||
m_textColorBg = etk::color::black;
|
||||
@ -47,27 +47,6 @@ void ewol::widget::Slider::calculateMinMaxSize() {
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void ewol::widget::Slider::setValue(int32_t _val) {
|
||||
m_value = std::max(std::min(_val, m_max), m_min);
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
int32_t ewol::widget::Slider::getValue() {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void ewol::widget::Slider::setMin(int32_t _val) {
|
||||
m_min = _val;
|
||||
m_value = std::max(std::min(m_value, m_max), m_min);
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void ewol::widget::Slider::setMax(int32_t _val) {
|
||||
m_max = _val;
|
||||
m_value = std::max(std::min(m_value, m_max), m_min);
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void ewol::widget::Slider::onDraw() {
|
||||
m_draw.draw();
|
||||
}
|
||||
@ -87,7 +66,7 @@ void ewol::widget::Slider::onRegenerateDisplay() {
|
||||
|
||||
etk::Color<> borderDot = m_textColorFg;
|
||||
borderDot.setA(borderDot.a()/2);
|
||||
m_draw.setPos(vec3(4+((float)(m_value-m_min)/(float)(m_max-m_min))*(float)(m_size.x()-2*dotRadius), m_size.y()/2, 0) );
|
||||
m_draw.setPos(vec3(4+((m_value-m_min)/(m_max-m_min))*(m_size.x()-2*dotRadius), m_size.y()/2, 0) );
|
||||
m_draw.setColorBg(borderDot);
|
||||
m_draw.circle(dotRadius);
|
||||
m_draw.setColorBg(m_textColorFg);
|
||||
@ -96,19 +75,17 @@ void ewol::widget::Slider::onRegenerateDisplay() {
|
||||
|
||||
bool ewol::widget::Slider::onEventInput(const ewol::event::Input& _event) {
|
||||
vec2 relativePos = relativePosition(_event.getPos());
|
||||
//EWOL_DEBUG("Event on Slider ...");
|
||||
EWOL_ERROR("Event on Slider ..." << _event);
|
||||
if (1 == _event.getId()) {
|
||||
if( ewol::key::statusSingle == _event.getStatus()
|
||||
|| ewol::key::statusMove == _event.getStatus()) {
|
||||
// get the new position :
|
||||
EWOL_VERBOSE("Event on Slider (" << relativePos.x() << "," << relativePos.y() << ")");
|
||||
int32_t oldValue = m_value;
|
||||
m_value = m_min + (float)(relativePos.x() - dotRadius) / (float)(m_size.x()-2*dotRadius) * (float)(m_max-m_min);
|
||||
m_value = std::max(std::min(m_value, m_max), m_min);
|
||||
EWOL_INFO("Event on Slider (" << relativePos.x() << "," << relativePos.y() << ")");
|
||||
float oldValue = m_value.get();
|
||||
updateValue(m_min + (float)(relativePos.x() - dotRadius) / (m_size.x()-2*dotRadius) * (m_max-m_min));
|
||||
if (oldValue != m_value) {
|
||||
EWOL_DEBUG(" new value : " << m_value << " in [" << m_min << ".." << m_max << "]");
|
||||
signalChange.emit(m_value);
|
||||
markToRedraw();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -116,4 +93,36 @@ bool ewol::widget::Slider::onEventInput(const ewol::event::Input& _event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ewol::widget::Slider::updateValue(float _newValue) {
|
||||
_newValue = std::max(std::min(_newValue, m_max.get()), m_min.get());
|
||||
if (m_step.get() == 0.0f) {
|
||||
m_value = _newValue;
|
||||
} else {
|
||||
float basicVal = (int64_t)(_newValue / m_step.get());
|
||||
m_value = basicVal * m_step.get();
|
||||
}
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
// TODO : Review this really bad things ...
|
||||
void ewol::widget::Slider::onParameterChangeValue(const ewol::object::ParameterRef& _paramPointer) {
|
||||
ewol::Widget::onParameterChangeValue(_paramPointer);
|
||||
if (_paramPointer == m_value) {
|
||||
updateValue(m_value.get());
|
||||
return;
|
||||
}
|
||||
if (_paramPointer == m_min) {
|
||||
updateValue(m_value.get());
|
||||
return;
|
||||
}
|
||||
if (_paramPointer == m_max) {
|
||||
updateValue(m_value.get());
|
||||
return;
|
||||
}
|
||||
if (_paramPointer == m_step) {
|
||||
updateValue(m_value.get());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,25 +31,90 @@ namespace ewol {
|
||||
public:
|
||||
DECLARE_WIDGET_FACTORY(Slider, "Slider");
|
||||
virtual ~Slider();
|
||||
void setValue(int32_t _val);
|
||||
int32_t getValue();
|
||||
void setMin(int32_t _val);
|
||||
void setMax(int32_t _val);
|
||||
protected:
|
||||
ewol::object::Param<float> m_value; //!< current value of the Slider
|
||||
public:
|
||||
/**
|
||||
* @brief Set the value of the slider.
|
||||
* @param[in] _val New value to apply.
|
||||
*/
|
||||
void setValue(float _val) {
|
||||
m_value.set(_val);
|
||||
}
|
||||
/**
|
||||
* @brief Get the value of the slider.
|
||||
* @return The current value of the slider.
|
||||
*/
|
||||
float getValue() {
|
||||
return m_value;
|
||||
}
|
||||
protected:
|
||||
ewol::object::Param<float> m_min; //!< minimum value of the slider
|
||||
public:
|
||||
/**
|
||||
* @brief Set the minumum value of the slider.
|
||||
* @param[in] _val New minimum value to apply.
|
||||
*/
|
||||
void setMin(float _val) {
|
||||
m_min.set(_val);
|
||||
}
|
||||
/**
|
||||
* @brief Get the minimum value of the slider.
|
||||
* @return The minimum value of the slider.
|
||||
*/
|
||||
float getMin() {
|
||||
return m_min;
|
||||
}
|
||||
protected:
|
||||
ewol::object::Param<float> m_max; //!< maximum value of the slider
|
||||
public:
|
||||
/**
|
||||
* @brief Set the maximum value of the slider.
|
||||
* @param[in] _val New maximum value to apply.
|
||||
*/
|
||||
void setMax(float _val) {
|
||||
m_max.set(_val);
|
||||
}
|
||||
/**
|
||||
* @brief Get the maximum value of the slider.
|
||||
* @return The maximum value of the slider.
|
||||
*/
|
||||
float getMax() {
|
||||
return m_max;
|
||||
}
|
||||
protected:
|
||||
ewol::object::Param<float> m_step;
|
||||
public:
|
||||
/**
|
||||
* @brief Set the step value of the slider.
|
||||
* @param[in] _val New step value to apply.
|
||||
*/
|
||||
void setStep(float _val) {
|
||||
m_step.set(_val);
|
||||
}
|
||||
/**
|
||||
* @brief Get the step value of the slider.
|
||||
* @return The wtep value of the slider.
|
||||
*/
|
||||
float getStep() {
|
||||
return m_step;
|
||||
}
|
||||
public:
|
||||
// TODO : Rewoek the color in the theme ...
|
||||
void setColor(etk::Color<> _newColor) {
|
||||
m_textColorFg = _newColor;
|
||||
};
|
||||
protected:
|
||||
ewol::compositing::Drawing m_draw; //!< drawing tool.
|
||||
int32_t m_value;
|
||||
int32_t m_min;
|
||||
int32_t m_max;
|
||||
etk::Color<> m_textColorFg; //!< Text color
|
||||
etk::Color<> m_textColorBg; //!< Background color
|
||||
void updateValue(float _newValue);
|
||||
public: // Derived function
|
||||
virtual void onDraw();
|
||||
virtual void calculateMinMaxSize();
|
||||
virtual void onRegenerateDisplay();
|
||||
virtual bool onEventInput(const ewol::event::Input& _event);
|
||||
virtual void onParameterChangeValue(const ewol::object::ParameterRef& _paramPointer);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user