[DEV] set ButtonColor support parameters instead of direct set & get

This commit is contained in:
Edouard DUPIN 2014-10-18 08:18:13 +02:00
parent e858cf8a74
commit e3a1b37130
2 changed files with 29 additions and 23 deletions

View File

@ -29,8 +29,8 @@ static const char* const eventColorHasChange = "ewol-widget-ButtonColor-colorCha
ewol::widget::ButtonColor::ButtonColor() : ewol::widget::ButtonColor::ButtonColor() :
signalChange(*this, "change", "Button color change value"), signalChange(*this, "change", "Button color change value"),
m_textColorFg(etk::color::black), m_widgetContextMenu(nullptr),
m_widgetContextMenu(nullptr) { m_textColorFg(*this, "color", etk::color::black, "Current color") {
addObjectType("ewol::widget::ButtonColor"); addObjectType("ewol::widget::ButtonColor");
changeStatusIn(STATUS_UP); changeStatusIn(STATUS_UP);
setCanHaveFocus(true); setCanHaveFocus(true);
@ -41,7 +41,7 @@ ewol::widget::ButtonColor::ButtonColor() :
void ewol::widget::ButtonColor::init(etk::Color<> _baseColor, std::string _shaperName) { void ewol::widget::ButtonColor::init(etk::Color<> _baseColor, std::string _shaperName) {
ewol::Widget::init(); ewol::Widget::init();
m_shaper.setSource(_shaperName); m_shaper.setSource(_shaperName);
m_textColorFg = _baseColor; m_textColorFg.set(_baseColor);
} }
ewol::widget::ButtonColor::~ButtonColor() { ewol::widget::ButtonColor::~ButtonColor() {
@ -107,15 +107,15 @@ void ewol::widget::ButtonColor::onRegenerateDisplay() {
// clean the element // clean the element
m_text.reset(); m_text.reset();
if( m_textColorFg.r() < 100 if( m_textColorFg.get().r() < 100
|| m_textColorFg.g() < 100 || m_textColorFg.get().g() < 100
|| m_textColorFg.b() < 100) { || m_textColorFg.get().b() < 100) {
m_text.setColor(etk::color::white); m_text.setColor(etk::color::white);
} else { } else {
m_text.setColor(etk::color::black); m_text.setColor(etk::color::black);
} }
m_text.setPos(tmpTextOrigin); m_text.setPos(tmpTextOrigin);
m_text.setColorBg(m_textColorFg); m_text.setColorBg(m_textColorFg.get());
m_text.setTextAlignement(tmpTextOrigin.x(), tmpTextOrigin.x()+localSize.x(), ewol::compositing::alignCenter); m_text.setTextAlignement(tmpTextOrigin.x(), tmpTextOrigin.x()+localSize.x(), ewol::compositing::alignCenter);
m_text.print(label); m_text.print(label);
@ -169,7 +169,7 @@ bool ewol::widget::ButtonColor::onEventInput(const ewol::event::Input& _event) {
m_buttonPressed = false; m_buttonPressed = false;
m_mouseHover = false; m_mouseHover = false;
// create a context menu : // create a context menu :
m_widgetContextMenu = std::make_shared<ewol::widget::ContextMenu>(); m_widgetContextMenu = ewol::widget::ContextMenu::create();
if (nullptr == m_widgetContextMenu) { if (nullptr == m_widgetContextMenu) {
EWOL_ERROR("Allocation Error"); EWOL_ERROR("Allocation Error");
return true; return true;
@ -179,7 +179,7 @@ bool ewol::widget::ButtonColor::onEventInput(const ewol::event::Input& _event) {
m_widgetContextMenu->setPositionMark(ewol::widget::ContextMenu::markButtom, tmpPos ); m_widgetContextMenu->setPositionMark(ewol::widget::ContextMenu::markButtom, tmpPos );
std::shared_ptr<ewol::widget::ColorChooser> myColorChooser = widget::ColorChooser::create(); std::shared_ptr<ewol::widget::ColorChooser> myColorChooser = widget::ColorChooser::create();
myColorChooser->setColor(m_textColorFg); myColorChooser->setColor(m_textColorFg.get());
// set it in the pop-up-system : // set it in the pop-up-system :
m_widgetContextMenu->setSubWidget(myColorChooser); m_widgetContextMenu->setSubWidget(myColorChooser);
myColorChooser->signalChange.bind(shared_from_this(), &ewol::widget::ButtonColor::onCallbackColorChange); myColorChooser->signalChange.bind(shared_from_this(), &ewol::widget::ButtonColor::onCallbackColorChange);
@ -213,16 +213,6 @@ void ewol::widget::ButtonColor::onCallbackColorChange(const etk::Color<>& _color
setValue(_color); setValue(_color);
} }
void ewol::widget::ButtonColor::setValue(const etk::Color<>& _color) {
m_textColorFg = _color;
signalChange.emit(m_textColorFg);
markToRedraw();
}
etk::Color<> ewol::widget::ButtonColor::getValue() {
return m_textColorFg;
}
void ewol::widget::ButtonColor::changeStatusIn(int32_t _newStatusId) { void ewol::widget::ButtonColor::changeStatusIn(int32_t _newStatusId) {
if (true == m_shaper.changeStatusIn(_newStatusId) ) { if (true == m_shaper.changeStatusIn(_newStatusId) ) {
periodicCallEnable(); periodicCallEnable();
@ -236,3 +226,12 @@ void ewol::widget::ButtonColor::periodicCall(const ewol::event::Time& _event) {
} }
markToRedraw(); markToRedraw();
} }
void ewol::widget::ButtonColor::onParameterChangeValue(const ewol::object::ParameterRef& _paramPointer) {
ewol::Widget::onParameterChangeValue(_paramPointer);
if (_paramPointer == m_textColorFg) {
signalChange.emit(m_textColorFg);
markToRedraw();
}
}

View File

@ -28,7 +28,6 @@ namespace ewol {
private: private:
ewol::compositing::Shaper m_shaper; //!< Compositing theme. ewol::compositing::Shaper m_shaper; //!< Compositing theme.
ewol::compositing::Text m_text; //!< Compositing Test display. ewol::compositing::Text m_text; //!< Compositing Test display.
etk::Color<> m_textColorFg; //!< Current color.
std::shared_ptr<ewol::widget::ContextMenu> m_widgetContextMenu; //!< Specific context menu. std::shared_ptr<ewol::widget::ContextMenu> m_widgetContextMenu; //!< Specific context menu.
bool m_mouseHover; //!< Flag to know where the mouse is (inside the displayed widget (if not fill)). bool m_mouseHover; //!< Flag to know where the mouse is (inside the displayed widget (if not fill)).
bool m_buttonPressed; //!< Flag to know if the button is curently pressed. bool m_buttonPressed; //!< Flag to know if the button is curently pressed.
@ -42,7 +41,7 @@ namespace ewol {
* @param[in] _shaperName The new shaper filename. * @param[in] _shaperName The new shaper filename.
*/ */
ButtonColor(); ButtonColor();
void init(etk::Color<> _baseColor=etk::color::black, std::string _shaperName="THEME:GUI:widgetButton.json"); void init(etk::Color<> _baseColor=etk::color::black, std::string _shaperName="THEME:GUI:Button.json");
public: public:
DECLARE_WIDGET_FACTORY(ButtonColor, "ButtonColor"); DECLARE_WIDGET_FACTORY(ButtonColor, "ButtonColor");
/** /**
@ -54,22 +53,30 @@ namespace ewol {
* @param[in] _shaperName The new shaper filename. * @param[in] _shaperName The new shaper filename.
*/ */
void setShaperName(std::string _shaperName); void setShaperName(std::string _shaperName);
protected:
ewol::object::Param<etk::Color<>> m_textColorFg; //!< Current color.
public:
/** /**
* @brief get the current color of the color selection widget * @brief get the current color of the color selection widget
* @return The current color * @return The current color
*/ */
etk::Color<> getValue(); const etk::Color<>& getValue() {
return m_textColorFg.get();
}
/** /**
* @brief Specify the current color. * @brief Specify the current color.
* @param[in] _color The new display color. * @param[in] _color The new display color.
*/ */
void setValue(const etk::Color<>& _color); void setValue(const etk::Color<>& _color) {
m_textColorFg.set(_color);
}
protected: // Derived function protected: // Derived function
virtual void onDraw(); virtual void onDraw();
public: // Derived function public: // Derived function
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventInput(const ewol::event::Input& _event);
virtual void onParameterChangeValue(const ewol::object::ParameterRef& _paramPointer);
private: private:
/** /**
* @brief internal system to change the property of the current status * @brief internal system to change the property of the current status