From adc4ad0c452408c1c85b18938632f232bc01db11 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 5 Nov 2013 21:01:02 +0100 Subject: [PATCH] [DEV] add property on progress bar --- external/egami | 2 +- external/etk | 2 +- sources/ewol/widget/ColorBar.h | 4 ++- sources/ewol/widget/Composer.h | 4 ++- sources/ewol/widget/Container.h | 4 ++- sources/ewol/widget/ContainerN.h | 16 ++++++--- sources/ewol/widget/ContextMenu.h | 4 ++- sources/ewol/widget/Entry.h | 28 +++++++++++---- sources/ewol/widget/Gird.h | 4 ++- sources/ewol/widget/Image.cpp | 26 ++++++++++++-- sources/ewol/widget/Image.h | 20 ++++++++--- sources/ewol/widget/Menu.h | 4 ++- sources/ewol/widget/ProgressBar.cpp | 56 +++++++++++++++++++++++++++++ sources/ewol/widget/ProgressBar.h | 15 ++++++-- 14 files changed, 160 insertions(+), 29 deletions(-) diff --git a/external/egami b/external/egami index ae00cd17..9ead15a4 160000 --- a/external/egami +++ b/external/egami @@ -1 +1 @@ -Subproject commit ae00cd17e33ed3d0a8f0f8065b4b0ab2c2490343 +Subproject commit 9ead15a4d1cb533db919dfe5f6638dae7f788479 diff --git a/external/etk b/external/etk index a3f4d0d1..8806c4e4 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit a3f4d0d129221ea06c6331f0c8fa9a8bd9b0d458 +Subproject commit 8806c4e44ff918b1be25e1bd8958512e11ffe27e diff --git a/sources/ewol/widget/ColorBar.h b/sources/ewol/widget/ColorBar.h index 98bd3189..b2f431b5 100644 --- a/sources/ewol/widget/ColorBar.h +++ b/sources/ewol/widget/ColorBar.h @@ -32,7 +32,9 @@ namespace widget { protected: // Derived function virtual void onDraw(void); public: // Derived function - virtual const char * const getObjectType(void) { return "widget::ColorBar"; }; + virtual const char * const getObjectType(void) { + return "widget::ColorBar"; + }; virtual void calculateMinMaxSize(void); virtual void onRegenerateDisplay(void); virtual bool onEventInput(const ewol::EventInput& _event); diff --git a/sources/ewol/widget/Composer.h b/sources/ewol/widget/Composer.h index 1262b401..5efc8e29 100644 --- a/sources/ewol/widget/Composer.h +++ b/sources/ewol/widget/Composer.h @@ -82,7 +82,9 @@ namespace widget const char * _eventIdgenerated = NULL, const etk::UString& _overloadData=""); public: // herited functions: - virtual const char * const getObjectType(void) { return "ewol::widget::Composer"; }; + virtual const char * const getObjectType(void) { + return "ewol::widget::Composer"; + }; }; }; diff --git a/sources/ewol/widget/Container.h b/sources/ewol/widget/Container.h index ad4f9d31..928ea07b 100644 --- a/sources/ewol/widget/Container.h +++ b/sources/ewol/widget/Container.h @@ -57,7 +57,9 @@ namespace widget { virtual void calculateMinMaxSize(void); virtual ewol::Widget* getWidgetAtPos(const vec2& _pos); virtual ewol::Widget* getWidgetNamed(const etk::UString& _widgetName); - virtual const char * const getObjectType(void) { return "ewol::widget::Container"; }; + virtual const char * const getObjectType(void) { + return "ewol::widget::Container"; + }; virtual bool loadXML(exml::Element* _node); virtual void setOffset(const vec2& _newVal); }; diff --git a/sources/ewol/widget/ContainerN.h b/sources/ewol/widget/ContainerN.h index f05f610b..189a9a5c 100644 --- a/sources/ewol/widget/ContainerN.h +++ b/sources/ewol/widget/ContainerN.h @@ -55,15 +55,21 @@ namespace widget { * @return the ID of the set element */ virtual int32_t subWidgetAdd(ewol::Widget* _newWidget); - inline int32_t subWidgetAddBack(ewol::Widget* _newWidget) { return subWidgetAdd(_newWidget); }; - inline int32_t subWidgetAddEnd(ewol::Widget* _newWidget) { return subWidgetAdd(_newWidget); }; + inline int32_t subWidgetAddBack(ewol::Widget* _newWidget) { + return subWidgetAdd(_newWidget); + }; + inline int32_t subWidgetAddEnd(ewol::Widget* _newWidget) { + return subWidgetAdd(_newWidget); + }; /** * @brief add at start position a Widget (note : This system use an inverted phylisophie (button to top, and left to right) * @param[in] _newWidget the element pointer * @return the ID of the set element */ virtual int32_t subWidgetAddStart(ewol::Widget* _newWidget); - inline int32_t subWidgetAddFront(ewol::Widget* _newWidget) { return subWidgetAddStart(_newWidget); }; + inline int32_t subWidgetAddFront(ewol::Widget* _newWidget) { + return subWidgetAddStart(_newWidget); + }; /** * @brief remove definitly a widget from the system and this layer. * @param[in] _newWidget the element pointer. @@ -82,7 +88,9 @@ namespace widget { virtual void calculateMinMaxSize(void); virtual ewol::Widget* getWidgetAtPos(const vec2& _pos); virtual ewol::Widget* getWidgetNamed(const etk::UString& _widgetName); - virtual const char * const getObjectType(void) { return "Ewol::ContainerN"; }; + virtual const char * const getObjectType(void) { + return "Ewol::ContainerN"; + }; virtual bool loadXML(exml::Element* _node); virtual void setOffset(const vec2& _newVal); }; diff --git a/sources/ewol/widget/ContextMenu.h b/sources/ewol/widget/ContextMenu.h index a5c76464..eb419611 100644 --- a/sources/ewol/widget/ContextMenu.h +++ b/sources/ewol/widget/ContextMenu.h @@ -64,7 +64,9 @@ namespace widget { virtual bool onEventInput(const ewol::EventInput& _event); virtual void calculateSize(const vec2& availlable); virtual void calculateMinMaxSize(void); - virtual const char * const getObjectType(void) { return "ewol::ContextMenu"; }; + virtual const char * const getObjectType(void) { + return "ewol::ContextMenu"; + }; virtual ewol::Widget* getWidgetAtPos(const vec2& pos); }; }; diff --git a/sources/ewol/widget/Entry.h b/sources/ewol/widget/Entry.h index ae7a0d64..6db8764c 100644 --- a/sources/ewol/widget/Entry.h +++ b/sources/ewol/widget/Entry.h @@ -75,7 +75,9 @@ namespace widget { * @brief get the current value in the entry * @return The current display value */ - etk::UString getValue(void) const { return m_data; }; + etk::UString getValue(void) const { + return m_data; + }; private: int32_t m_maxCharacter; //!< number max of xharacter in the list @@ -89,7 +91,9 @@ namespace widget { * @brief Limit the number of Unicode character in the entry * @return Number of max character set in the List. */ - int32_t getMaxChar(void) const { return m_maxCharacter; }; + int32_t getMaxChar(void) const { + return m_maxCharacter; + }; private: etk::RegExp m_regExp; //!< regular expression to limit the input of an entry @@ -103,7 +107,9 @@ namespace widget { * @brief get the regualar expression limitation * @param The regExp string */ - const etk::UString& getRegExp(void) const { return m_regExp.getRegExp(); }; + const etk::UString& getRegExp(void) const { + return m_regExp.getRegExp(); + }; private: bool m_needUpdateTextPos; //!< text position can have change @@ -152,7 +158,9 @@ namespace widget { * @brief get the color for the text. * @return The color requested. */ - const etk::Color<>& getColorText(void) const { return m_textColorFg; }; + const etk::Color<>& getColorText(void) const { + return m_textColorFg; + }; private: etk::Color<> m_textColorBg; //!< Background color. @@ -166,7 +174,9 @@ namespace widget { * @brief get the selected color for the text in selection mode. * @return The color requested. */ - const etk::Color<>& getColorTextSelected(void) const { return m_textColorBg; }; + const etk::Color<>& getColorTextSelected(void) const { + return m_textColorBg; + }; private: etk::UString m_textWhenNothing; //!< Text to display when nothing in in the entry (decorated text...) @@ -180,14 +190,18 @@ namespace widget { * @brief get The text displayed when nothing is in the entry. * @return Text display when nothing */ - const etk::UString& getEmptyText(void) const { return m_textWhenNothing; }; + const etk::UString& getEmptyText(void) const { + return m_textWhenNothing; + }; public: // Derived function virtual void onRegenerateDisplay(void); virtual bool onEventInput(const ewol::EventInput& _event); virtual bool onEventEntry(const ewol::EventEntry& _event); virtual void onReceiveMessage(const ewol::EMessage& _msg); virtual void onEventClipboard(ewol::clipBoard::clipboardListe_te _clipboardID); - virtual const char * const getObjectType(void) { return "EwolEntry"; }; + virtual const char * const getObjectType(void) { + return "EwolEntry"; + }; virtual void calculateMinMaxSize(void); protected: // Derived function virtual void onDraw(void); diff --git a/sources/ewol/widget/Gird.h b/sources/ewol/widget/Gird.h index 24468946..7514a23e 100644 --- a/sources/ewol/widget/Gird.h +++ b/sources/ewol/widget/Gird.h @@ -134,7 +134,9 @@ namespace widget { virtual void onRegenerateDisplay(void); virtual ewol::Widget* getWidgetAtPos(const vec2& pos); virtual void onObjectRemove(ewol::EObject* _removeObject); - virtual const char * const getObjectType(void) { return "Ewol::sizer"; }; + virtual const char * const getObjectType(void) { + return "ewol::gird"; + }; virtual void calculateSize(const vec2& _availlable); virtual void calculateMinMaxSize(void); }; diff --git a/sources/ewol/widget/Image.cpp b/sources/ewol/widget/Image.cpp index b9ba6139..bf3ec28a 100644 --- a/sources/ewol/widget/Image.cpp +++ b/sources/ewol/widget/Image.cpp @@ -114,17 +114,37 @@ void widget::Image::onRegenerateDisplay(void) { vec2 imageRealSize = m_minSize - imageBoder; vec2 imageRealSizeMax = m_size - imageBoder; - vec2 tmpSize = m_compositing.getRealSize(); - if (m_userFill.x()) { + bool xSizeBigger = false; + if (imageRealSize.x() > imageRealSize.y()) { + xSizeBigger = true; + } + + if (m_userFill.x() == true) { imageRealSize.setX(imageRealSizeMax.x()); } else { origin.setX(origin.x() + (m_size.x()-m_minSize.x())*0.5f); } - if (m_userFill.y()) { + if (m_userFill.y() == true) { imageRealSize.setY(imageRealSizeMax.y()); } else { origin.setY(origin.y() + (m_size.y()-m_minSize.y())*0.5f); } + if (m_keepRatio == true) { + vec2 tmpSize = m_compositing.getRealSize(); + float ratio = tmpSize.x() / tmpSize.y(); + float ratioCurrent = imageRealSize.x() / imageRealSize.y(); + if (ratio == ratioCurrent) { + // nothing to do ... + } else if (ratio < ratioCurrent) { + float oldX = imageRealSize.x(); + imageRealSize.setX(imageRealSize.y()*ratio); + origin += vec2((oldX - imageRealSize.x()) * 0.5f, 0); + } else { + float oldY = imageRealSize.y(); + imageRealSize.setY(imageRealSize.x()/ratio); + origin += vec2(0, (oldY - imageRealSize.y()) * 0.5f); + } + } // set the somposition properties : m_compositing.setPos(origin); diff --git a/sources/ewol/widget/Image.h b/sources/ewol/widget/Image.h index 3f10c916..21e562e7 100644 --- a/sources/ewol/widget/Image.h +++ b/sources/ewol/widget/Image.h @@ -63,7 +63,9 @@ namespace widget { * @brief get the file displayed * @return the filename of the image */ - const etk::UString& getFile(void) const { return m_fileName; }; + const etk::UString& getFile(void) const { + return m_fileName; + }; protected: ewol::Dimension m_border; //!< border to add at the image. public: @@ -76,7 +78,9 @@ namespace widget { * @brief get the current border request at the image * @return the border size */ - const ewol::Dimension& getBorder(void) const { return m_border; }; + const ewol::Dimension& getBorder(void) const { + return m_border; + }; protected: ewol::Dimension m_imageSize; //!< border to add at the image. public: @@ -89,7 +93,9 @@ namespace widget { * @brief get the current border request at the image * @return the border size */ - const ewol::Dimension& getImageSize(void) const { return m_imageSize; }; + const ewol::Dimension& getImageSize(void) const { + return m_imageSize; + }; protected: bool m_keepRatio; //!< keep the image ratio between width and hight public: @@ -102,13 +108,17 @@ namespace widget { * @brief get the current status of keeping ratio. * @return The status of keeping the ratio of this image. */ - bool getKeepRatio(void) const { return m_keepRatio; }; + bool getKeepRatio(void) const { + return m_keepRatio; + }; protected: // Derived function virtual void onDraw(void); virtual bool onSetConfig(const ewol::EConfig& _conf); virtual bool onGetConfig(const char* _config, etk::UString& _result) const; public: // Derived function - virtual const char * const getObjectType(void) { return "Ewol::Image"; }; + virtual const char * const getObjectType(void) { + return "Ewol::Image"; + }; virtual void calculateMinMaxSize(void); virtual void onRegenerateDisplay(void); virtual bool onEventInput(const ewol::EventInput& _event); diff --git a/sources/ewol/widget/Menu.h b/sources/ewol/widget/Menu.h index d4017ec5..2f9164c5 100644 --- a/sources/ewol/widget/Menu.h +++ b/sources/ewol/widget/Menu.h @@ -33,7 +33,9 @@ namespace widget { Menu(void); virtual ~Menu(void); // Derived functionv - virtual const char * const getObjectType(void) { return "EwolMenu"; }; + virtual const char * const getObjectType(void) { + return "ewol::menu"; + }; private: virtual void subWidgetRemoveAll(void); virtual int32_t subWidgetAdd(ewol::Widget* _newWidget); diff --git a/sources/ewol/widget/ProgressBar.cpp b/sources/ewol/widget/ProgressBar.cpp index cc05806f..3988c6a6 100644 --- a/sources/ewol/widget/ProgressBar.cpp +++ b/sources/ewol/widget/ProgressBar.cpp @@ -22,6 +22,10 @@ void widget::ProgressBar::init(ewol::WidgetManager& _widgetManager) { _widgetManager.addWidgetCreator(__class__,&create); } +const char* const widget::ProgressBar::configColorBg = "color-bg"; +const char* const widget::ProgressBar::configColorFgOn = "color-on"; +const char* const widget::ProgressBar::configColorFgOff = "color-off"; +const char* const widget::ProgressBar::configValue = "value"; const int32_t dotRadius = 6; @@ -35,6 +39,11 @@ widget::ProgressBar::ProgressBar(void) { m_textColorBgOff = etk::color::black; m_textColorBgOff.setA(0x3F); setCanHaveFocus(true); + registerConfig(configColorBg, "color", NULL, "Background color"); + registerConfig(configColorFgOn, "color", NULL, "Corlor of the true value"); + registerConfig(configColorFgOff, "color", NULL, "Corlor of the false value"); + registerConfig(configValue, "integer", NULL, "Value of the progress bar"); + } widget::ProgressBar::~ProgressBar(void) { @@ -87,3 +96,50 @@ void widget::ProgressBar::onRegenerateDisplay(void) { +bool widget::ProgressBar::onSetConfig(const ewol::EConfig& _conf) { + if (true == ewol::Widget::onSetConfig(_conf)) { + return true; + } + if (_conf.getConfig() == configColorBg) { + m_textColorFg = _conf.getData(); + return true; + } + if (_conf.getConfig() == configColorFgOn) { + m_textColorBgOn = _conf.getData(); + return true; + } + if (_conf.getConfig() == configColorFgOff) { + m_textColorBgOff = _conf.getData(); + return true; + } + if (_conf.getConfig() == configValue) { + m_value = _conf.getData().toFloat(); + return true; + } + return false; +} + +bool widget::ProgressBar::onGetConfig(const char* _config, etk::UString& _result) const { + if (true == ewol::Widget::onGetConfig(_config, _result)) { + return true; + } + if (_config == configColorBg) { + _result = m_textColorFg.getString(); + return true; + } + if (_config == configColorFgOn) { + _result = m_textColorBgOn.getString(); + return true; + } + if (_config == configColorFgOff) { + _result = m_textColorBgOff.getString(); + return true; + } + if (_config == configValue) { + _result = m_value; + return true; + } + return false; +} + + diff --git a/sources/ewol/widget/ProgressBar.h b/sources/ewol/widget/ProgressBar.h index e52f65ce..ac2773ce 100644 --- a/sources/ewol/widget/ProgressBar.h +++ b/sources/ewol/widget/ProgressBar.h @@ -20,6 +20,11 @@ namespace widget { class ProgressBar : public ewol::Widget { public: static void init(ewol::WidgetManager& _widgetManager); + // Config list of properties + static const char* const configColorBg; + static const char* const configColorFgOn; + static const char* const configColorFgOff; + static const char* const configValue; private: ewol::Drawing m_draw; // basic drawing element public: @@ -27,7 +32,9 @@ namespace widget { virtual ~ProgressBar(void); void valueSet(float _val); float valueGet(void); - void setColor(etk::Color<> _newColor) { m_textColorFg = _newColor; }; + void setColor(etk::Color<> _newColor) { + m_textColorFg = _newColor; + }; private: float m_value; //!< % used etk::Color<> m_textColorFg; //!< forder bar color @@ -35,9 +42,13 @@ namespace widget { etk::Color<> m_textColorBgOff; //!< bar color disable protected: // Derived function virtual void onDraw(void); + virtual bool onSetConfig(const ewol::EConfig& _conf); + virtual bool onGetConfig(const char* _config, etk::UString& _result) const; public: // Derived function virtual void onRegenerateDisplay(void); - virtual const char * const getObjectType(void) { return "EwolProgressBar"; }; + virtual const char * const getObjectType(void) { + return "ewol::progressBar"; + }; virtual void calculateMinMaxSize(void); };