From 81075dff9cdd5bea3b4cb598be6f2afa85646d1b Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Mon, 5 Mar 2012 00:07:43 +0100 Subject: [PATCH] add button color (not ended) --- Sources/libewol/ewol/widget/ButtonColor.cpp | 213 ++++++++++++++++++++ Sources/libewol/ewol/widget/ButtonColor.h | 66 ++++++ Sources/libewol/file.mk | 1 + exemple/2DObject.e2d | 13 ++ 4 files changed, 293 insertions(+) create mode 100644 Sources/libewol/ewol/widget/ButtonColor.cpp create mode 100644 Sources/libewol/ewol/widget/ButtonColor.h create mode 100644 exemple/2DObject.e2d diff --git a/Sources/libewol/ewol/widget/ButtonColor.cpp b/Sources/libewol/ewol/widget/ButtonColor.cpp new file mode 100644 index 00000000..c767b190 --- /dev/null +++ b/Sources/libewol/ewol/widget/ButtonColor.cpp @@ -0,0 +1,213 @@ +/** + ******************************************************************************* + * @file ewol/widget/ButtonColor.cpp + * @brief ewol Button select color widget system (Sources) + * @author Edouard DUPIN + * @date 04/03/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include + +#include +#include + + +extern const char * const ewolEventButtonColorChange = "ewol-Button-Color-Change"; + + + +#undef __class__ +#define __class__ "ButtonColor" + + +void ewol::ButtonColor::Init(void) +{ + AddEventId(ewolEventButtonColorChange); + + m_alignement = ewol::TEXT_ALIGN_CENTER; + + #ifdef __PLATFORM__Android + m_padding.y = 12; + m_padding.x = 12; + #else + m_padding.y = 4; + m_padding.x = 4; + #endif + + m_textColorFg.red = 0.0; + m_textColorFg.green = 0.0; + m_textColorFg.blue = 0.0; + m_textColorFg.alpha = 1.0; + + m_textColorBg.red = 0.0; + m_textColorBg.green = 0.0; + m_textColorBg.blue = 0.0; + m_textColorBg.alpha = 0.25; + SetCanHaveFocus(true); +} + +ewol::ButtonColor::ButtonColor(void) +{ + m_label = "No Label"; + Init(); +} + +ewol::ButtonColor::ButtonColor(etk::UString newLabel) +{ + m_label = newLabel; + Init(); +} + + +ewol::ButtonColor::~ButtonColor(void) +{ + +} + +void ewol::ButtonColor::SetPadding(coord2D_ts newPadding) +{ + m_padding = newPadding; +} + +bool ewol::ButtonColor::CalculateMinSize(void) +{ + int32_t fontId = GetDefaultFontId(); + int32_t minWidth = ewol::GetWidth(fontId, m_label); + int32_t minHeight = ewol::GetHeight(fontId); + m_minSize.x = m_padding.x*2 + minWidth; + m_minSize.y = m_padding.y*2 + minHeight; + MarkToReedraw(); + return true; +} + + +void ewol::ButtonColor::SetLabel(etk::UString newLabel) +{ + m_label = newLabel; + MarkToReedraw(); +} + +void ewol::ButtonColor::SetValue(bool val) +{ + +} + +void ewol::ButtonColor::SetAlignement(textAlignement_te typeAlign) +{ + m_alignement = typeAlign; + MarkToReedraw(); +} + + +bool ewol::ButtonColor::GetValue(void) +{ + return false; +} + + +void ewol::ButtonColor::OnRegenerateDisplay(void) +{ + if (true == NeedRedraw()) { + // clean the object list ... + ClearOObjectList(); + + int32_t tmpSizeX = m_minSize.x; + int32_t tmpSizeY = m_minSize.y; + int32_t tmpOriginX = (m_size.x - m_minSize.x) / 2; + int32_t tmpOriginY = (m_size.y - m_minSize.y) / 2; + // no change for the text orogin : + int32_t tmpTextOriginX = (m_size.x - m_minSize.x) / 2 + m_padding.x; + int32_t tmpTextOriginY = (m_size.y - m_minSize.y) / 2 + m_padding.y; + + if (true==m_userFillX) { + tmpSizeX = m_size.x; + tmpOriginX = 0; + if (m_alignement == ewol::TEXT_ALIGN_LEFT) { + tmpTextOriginX = m_padding.x; + } + } + if (true==m_userFillY) { + tmpSizeY = m_size.y; + tmpOriginY = 0; + } + tmpOriginX += m_padding.x; + tmpOriginY += m_padding.y; + tmpSizeX -= 2*m_padding.x; + tmpSizeY -= 2*m_padding.y; + + ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, m_textColorFg); + /* + int32_t fontId = GetDefaultFontId(); + int32_t fontHeight = ewol::GetHeight(fontId); + int32_t fontWidth = ewol::GetWidth(fontId, m_label.c_str()); + */ + coord2D_ts textPos; + textPos.x = tmpTextOriginX; + textPos.y = tmpTextOriginY; + clipping_ts drawClipping; + drawClipping.x = m_padding.x; + drawClipping.y = m_padding.y; + drawClipping.w = m_size.x - 2*m_padding.x; + drawClipping.h = m_size.y - 2*m_padding.y; + tmpText->Text(textPos, drawClipping, m_label); + + ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored; + tmpOObjects->SetColor(m_textColorBg); + tmpOriginX -= m_padding.x/2; + tmpOriginY -= m_padding.y/2; + tmpSizeX += m_padding.x/1; + tmpSizeY += m_padding.y/1; + tmpOObjects->Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY); + AddOObject(tmpOObjects); + + AddOObject(tmpText); + } +} + + +bool ewol::ButtonColor::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, eventPosition_ts pos) +{ + //EWOL_DEBUG("Event on BT ..."); + if (1 == IdInput) { + if( ewol::EVENT_INPUT_TYPE_SINGLE == typeEvent + || ewol::EVENT_INPUT_TYPE_DOUBLE == typeEvent + || ewol::EVENT_INPUT_TYPE_TRIPLE == typeEvent) { + // nothing to do ... + GenerateEventId(ewolEventButtonPressed); + MarkToReedraw(); + return true; + } + } + return false; +} + + +void ewol::ButtonColor::SetCurrentColor(color_ts color) +{ + m_selectedColor = color; + m_textColorBg = m_selectedColor; + char colorText[256]; + sprintf(colorText, "#%02X%02X%02X%02X", + (uint8_t)(color.red * 0xFF), + (uint8_t)(color.green * 0xFF), + (uint8_t)(color.blue * 0xFF), + (uint8_t)(color.alpha * 0xFF)); + //set the new label ... + SetLabel(colorText); +} diff --git a/Sources/libewol/ewol/widget/ButtonColor.h b/Sources/libewol/ewol/widget/ButtonColor.h new file mode 100644 index 00000000..deee65b2 --- /dev/null +++ b/Sources/libewol/ewol/widget/ButtonColor.h @@ -0,0 +1,66 @@ +/** + ******************************************************************************* + * @file ewol/widget/ButtonColor.h + * @brief ewol Button select color widget system (header) + * @author Edouard DUPIN + * @date 04/03/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_BUTTON_COLOR_H__ +#define __EWOL_BUTTON_COLOR_H__ + +#include +#include +#include +#include + +extern const char * const ewolEventButtonColorChange; + +namespace ewol { + class ButtonColor :public ewol::Drawable + { + public: + ButtonColor(void); + ButtonColor(etk::UString newLabel); + void Init(void); + virtual ~ButtonColor(void); + virtual bool CalculateMinSize(void); + void SetLabel(etk::UString newLabel); + etk::UString GetLabel(void) {return m_label;}; + void SetValue(bool val); + bool GetValue(void); + void SetAlignement(textAlignement_te typeAlign); + void SetPadding(coord2D_ts newPadding); + private: + textAlignement_te m_alignement; + coord2D_ts m_padding; + etk::UString m_label; + color_ts m_textColorFg; //!< Text color + color_ts m_textColorBg; //!< Background color + color_ts m_selectedColor; //!< user current selected Color + public: + virtual void OnRegenerateDisplay(void); + public: + virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, eventPosition_ts pos); + color_ts GetCurrentColor(void) { return m_selectedColor; }; + void SetCurrentColor(color_ts color); + }; +}; + +#endif diff --git a/Sources/libewol/file.mk b/Sources/libewol/file.mk index 6898b44c..43c274f8 100644 --- a/Sources/libewol/file.mk +++ b/Sources/libewol/file.mk @@ -22,6 +22,7 @@ FILE_LIST = ewol/ewol.cpp \ ewol/widget/WidgetScrolled.cpp \ ewol/widget/Drawable.cpp \ ewol/widget/Button.cpp \ + ewol/widget/ButtonColor.cpp \ ewol/widget/Label.cpp \ ewol/widget/CheckBox.cpp \ ewol/widget/Entry.cpp \ diff --git a/exemple/2DObject.e2d b/exemple/2DObject.e2d new file mode 100644 index 00000000..64f5c805 --- /dev/null +++ b/exemple/2DObject.e2d @@ -0,0 +1,13 @@ + + + + + + + + + + +