From 3e2981665123e329948f6c6e0b92c13617a43e05 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 14 Apr 2013 14:07:14 +0200 Subject: [PATCH] [DEV] image rework base ok --- external/etk | 2 +- external/parsersvg | 2 +- sources/ewol/Dimension.cpp | 71 ++++++++++--- sources/ewol/compositing/Image.cpp | 11 ++ sources/ewol/compositing/Image.h | 39 +++++--- sources/ewol/renderer/ResourceManager.cpp | 17 ++-- sources/ewol/renderer/ResourceManager.h | 2 +- sources/ewol/renderer/resources/Image.cpp | 15 +-- sources/ewol/renderer/resources/Image.h | 3 + sources/ewol/widget/Image.cpp | 117 +++++++++++++++++----- sources/ewol/widget/Image.h | 64 +++++++----- sources/ewol/widget/Menu.cpp | 44 +++++--- sources/ewol/widget/meta/FileChooser.cpp | 71 +++++++++++-- sources/ewol/widget/newSystem.txt | 18 ++-- 14 files changed, 352 insertions(+), 124 deletions(-) diff --git a/external/etk b/external/etk index 32da0ffb..dffd6233 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit 32da0ffb78f9ff9e3ede49c87a9fd5c19e23136b +Subproject commit dffd6233d37dd886f910ca95d9f176724b6fc4ff diff --git a/external/parsersvg b/external/parsersvg index b8287243..928deb22 160000 --- a/external/parsersvg +++ b/external/parsersvg @@ -1 +1 @@ -Subproject commit b8287243a8aef3ff97aa608b284e17c847481cd7 +Subproject commit 928deb22eeec43ee683f331c33547845f6304d1f diff --git a/sources/ewol/Dimension.cpp b/sources/ewol/Dimension.cpp index 792043ca..585ba5b7 100644 --- a/sources/ewol/Dimension.cpp +++ b/sources/ewol/Dimension.cpp @@ -14,16 +14,16 @@ static vec2 ratio(9999999,888888); static vec2 invRatio(1,1); static ewol::Dimension windowsSize(vec2(9999999,888888), ewol::Dimension::Pixel); -static const float inchToMillimeter = 1.0f/25.4f; -static const float footToMillimeter = 1.0f/304.8f; -static const float meterToMillimeter = 1.0f/1000.0f; -static const float centimeterToMillimeter = 1.0f/10.0f; -static const float kilometerToMillimeter = 1.0f/1000000.0f; -static const float millimeterToInch = 25.4f; -static const float millimeterToFoot = 304.8f; -static const float millimeterToMeter = 1000.0f; -static const float millimeterToCentimeter = 10.0f; -static const float millimeterToKilometer = 1000000.0f; +static const float inchToMillimeter = 25.4f; +static const float footToMillimeter = 304.8f; +static const float meterToMillimeter = 1000.0f; +static const float centimeterToMillimeter = 10.0f; +static const float kilometerToMillimeter = 1000000.0f; +static const float millimeterToInch = 1.0f/25.4f; +static const float millimeterToFoot = 1.0f/304.8f; +static const float millimeterToMeter = 1.0f/1000.0f; +static const float millimeterToCentimeter = 1.0f/10.0f; +static const float millimeterToKilometer = 1.0f/1000000.0f; void ewol::dimension::Init(void) @@ -146,16 +146,20 @@ vec2 ewol::Dimension::GetPixel(void) const { if (m_type!=ewol::Dimension::Pourcent) { return m_data; + } else { + vec2 windDim = windowsSize.GetPixel(); + return vec2(windDim.x()*m_data.x(), windDim.y()*m_data.y()); } - vec2 windDim = windowsSize.GetPixel(); - return vec2(windDim.x()*m_data.x(), windDim.y()*m_data.y()); } vec2 ewol::Dimension::GetPourcent(void) const { if (m_type!=ewol::Dimension::Pourcent) { vec2 windDim = windowsSize.GetPixel(); - return vec2(m_data.x()/windDim.x()*100.0f, m_data.y()/windDim.y()*100.0f); + //EWOL_DEBUG(" windows dimention : " /*<< windowsSize*/ << " ==> " << windDim << "px"); // ==> infinite loop ... + //printf(" windows dimention : %f,%f", windDim.x(),windDim.y()); + //printf(" data : %f,%f", m_data.x(),m_data.y()); + return vec2((m_data.x()/windDim.x())*100.0f, (m_data.y()/windDim.y())*100.0f); } return vec2(m_data.x()*100.0f, m_data.y()*100.0f);; } @@ -167,7 +171,7 @@ vec2 ewol::Dimension::GetMeter(void) const vec2 ewol::Dimension::GetCentimeter(void) const { - return ewol::Dimension::GetMillimeter()*millimeterToMeter; + return ewol::Dimension::GetMillimeter()*millimeterToCentimeter; } vec2 ewol::Dimension::GetMillimeter(void) const @@ -225,9 +229,46 @@ etk::UString ewol::Dimension::GetString(void) } return ret; } + + void ewol::Dimension::SetString(const etk::UString& value) { - EWOL_TODO(" not done yet ..."); + etk::UString value2 = value; + int32_t nbElementToRemove=0; + vec2 data; + distance_te type; + if (value.EndWith("%")==true) { + nbElementToRemove=1; + type = ewol::Dimension::Pourcent; + } else if (value.EndWith("px")==true) { + nbElementToRemove=2; + type = ewol::Dimension::Pixel; + } else if (value.EndWith("cm")==true) { + nbElementToRemove=2; + type = ewol::Dimension::Centimeter; + } else if (value.EndWith("mm")==true) { + nbElementToRemove=2; + type = ewol::Dimension::Millimeter; + } else if (value.EndWith("km")==true) { + nbElementToRemove=2; + type = ewol::Dimension::Kilometer; + } else if (value.EndWith("m")==true) { + nbElementToRemove=1; + type = ewol::Dimension::Meter; + } else if (value.EndWith("in")==true) { + nbElementToRemove=2; + type = ewol::Dimension::Inch; + } else if (value.EndWith("ft")==true) { + nbElementToRemove=2; + type = ewol::Dimension::foot; + } else { + EWOL_WARNING("you might st an unit at : \"" << value << "\""); + nbElementToRemove=0; + type = ewol::Dimension::Pixel; + } + value2.Remove(value2.Size()-nbElementToRemove, nbElementToRemove); + data=value2; + Set(data, type); } diff --git a/sources/ewol/compositing/Image.cpp b/sources/ewol/compositing/Image.cpp index 583fa2c9..16892be8 100644 --- a/sources/ewol/compositing/Image.cpp +++ b/sources/ewol/compositing/Image.cpp @@ -268,3 +268,14 @@ bool ewol::Image::HasSources(void) return m_resource!=NULL; } + +vec2 ewol::Image::GetRealSize(void) +{ + if (NULL==m_resource) { + return vec2(0,0); + } + return m_resource->GetRealSize(); +} + + + diff --git a/sources/ewol/compositing/Image.h b/sources/ewol/compositing/Image.h index b13a1ea3..8fec7268 100644 --- a/sources/ewol/compositing/Image.h +++ b/sources/ewol/compositing/Image.h @@ -18,26 +18,26 @@ namespace ewol class Image : public ewol::Compositing { private: - vec3 m_position; //!< The current position to draw + vec3 m_position; //!< The current position to draw vec3 m_clippingPosStart; //!< Clipping start position - vec3 m_clippingPosStop; //!< Clipping stop position - bool m_clippingEnable; //!< true if the clipping must be activated + vec3 m_clippingPosStop; //!< Clipping stop position + bool m_clippingEnable; //!< true if the clipping must be activated private: draw::Color m_color; //!< The text foreground color - vec3 m_axes; //!< Rotation axes (instant) - float m_angle; //!< Angle to set at the axes + vec3 m_axes; //!< Rotation axes (instant) + float m_angle; //!< Angle to set at the axes private: - ewol::Program* m_GLprogram; //!< pointer on the opengl display program - int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) - int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) - int32_t m_GLColor; //!< openGL id on the element (color buffer) - int32_t m_GLtexture; //!< openGL id on the element (Texture position) - int32_t m_GLtexID; //!< openGL id on the element (texture ID) + ewol::Program* m_GLprogram; //!< pointer on the opengl display program + int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) + int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) + int32_t m_GLColor; //!< openGL id on the element (color buffer) + int32_t m_GLtexture; //!< openGL id on the element (Texture position) + int32_t m_GLtexID; //!< openGL id on the element (texture ID) private: - ewol::TextureFile* m_resource; //!< texture resources - etk::Vector m_coord; //!< internal coord of the object - etk::Vector m_coordTex; //!< internal texture coordinate for every point - etk::Vector m_coordColor; //!< internal color of the different point + ewol::TextureFile* m_resource; //!< texture resources + etk::Vector m_coord; //!< internal coord of the object + etk::Vector m_coordTex; //!< internal texture coordinate for every point + etk::Vector m_coordColor; //!< internal color of the different point private: /** * @brief Load the openGL program and get all the ID needed @@ -72,11 +72,13 @@ namespace ewol * @param[in] pos Position of the text (in 3D) */ void SetPos(const vec3& pos); + inline void SetPos(const vec2& pos) { SetPos(vec3(pos.x(),pos.y(),0)); }; /** * @brief Set relative position for the next text writen * @param[in] pos ofset apply of the text (in 3D) */ void SetRelPos(const vec3& pos); + inline void SetRelPos(const vec2& pos) { SetRelPos(vec3(pos.x(),pos.y(),0)); }; /** * @brief Set the Color of the current foreground font * @param[in] color Color to set on foreground (for next print) @@ -88,12 +90,14 @@ namespace ewol * @param[in] width Width size of the clipping */ void SetClippingWidth(const vec3& pos, vec3 width); + inline void SetClippingWidth(const vec2& pos, const vec2& width) { SetClippingWidth(vec3(pos.x(),pos.y(),0), vec3(width.x(),width.y(),0)); }; /** * @brief Request a clipping area for the text (next draw only) * @param[in] pos Start position of the clipping * @param[in] posEnd End position of the clipping */ void SetClipping(const vec3& pos, vec3 posEnd); + inline void SetClipping(const vec2& pos, const vec2& posEnd) { SetClipping(vec3(pos.x(),pos.y(),0), vec3(posEnd.x(),posEnd.y(),0)); }; /** * @brief Enable/Disable the clipping (without lose the current clipping position) * @brief newMode The new status of the clipping @@ -132,6 +136,11 @@ namespace ewol * @return the validity od the resources. */ bool HasSources(void); + /** + * @brief Get the source image registered size in the file (<0 when multiple size image) + * @return tre image registered size + */ + vec2 GetRealSize(void); }; }; diff --git a/sources/ewol/renderer/ResourceManager.cpp b/sources/ewol/renderer/ResourceManager.cpp index 31e0c9ec..ce658211 100644 --- a/sources/ewol/renderer/ResourceManager.cpp +++ b/sources/ewol/renderer/ResourceManager.cpp @@ -298,12 +298,17 @@ static int32_t nextP2(int32_t value) bool ewol::resource::Keep(const etk::UString& filename, ewol::TextureFile*& object, ivec2 size) { - ivec2 size2(nextP2(size.x()), nextP2(size.y())); etk::UString TmpFilename = filename; - TmpFilename += ":"; - TmpFilename += size2.x(); - TmpFilename += "x"; - TmpFilename += size2.y(); + if (false == filename.EndWith(".svg") ) { + size = ivec2(-1,-1); + } + if (size.x()>0 && size.y()>0) { + ivec2 size2(nextP2(size.x()), nextP2(size.y())); + TmpFilename += ":"; + TmpFilename += size2.x(); + TmpFilename += "x"; + TmpFilename += size2.y(); + } EWOL_INFO("KEEP : TextureFile : file : \"" << TmpFilename << "\" basic size=" << size); object = static_cast(LocalKeep(TmpFilename)); @@ -312,7 +317,7 @@ bool ewol::resource::Keep(const etk::UString& filename, ewol::TextureFile*& obje } EWOL_INFO(" ==> create new one..."); // need to crate a new one ... - object = new ewol::TextureFile(TmpFilename, filename, size2); + object = new ewol::TextureFile(TmpFilename, filename, size); if (NULL == object) { EWOL_ERROR("allocation error of a resource : " << filename); return false; diff --git a/sources/ewol/renderer/ResourceManager.h b/sources/ewol/renderer/ResourceManager.h index 3d5bdea1..eaeee0e2 100644 --- a/sources/ewol/renderer/ResourceManager.h +++ b/sources/ewol/renderer/ResourceManager.h @@ -75,7 +75,7 @@ namespace ewol bool Keep(const etk::UString& filename, ewol::Program*& object); bool Keep(const etk::UString& filename, ewol::Shader*& object); bool Keep(ewol::Texture*& object); // no name needed here ... - bool Keep(const etk::UString& filename, ewol::TextureFile*& object, ivec2 size); + bool Keep(const etk::UString& filename, ewol::TextureFile*& object, ivec2 size=ivec2(-1,-1)); bool Keep(const etk::UString& accesMode, ewol::VirtualBufferObject*& object); bool Keep(const etk::UString& filename, ewol::MeshObj*& object); bool Keep(const etk::UString& meshName, ewol::Mesh*& object); diff --git a/sources/ewol/renderer/resources/Image.cpp b/sources/ewol/renderer/resources/Image.cpp index 46293a35..fddfdb78 100644 --- a/sources/ewol/renderer/resources/Image.cpp +++ b/sources/ewol/renderer/resources/Image.cpp @@ -25,10 +25,6 @@ ewol::TextureFile::TextureFile(etk::UString genName, etk::UString tmpfileName, i Texture(genName) { etk::UString tmpName = tmpfileName; - // get the upper paw2 ot the size requested... - if (size.x()>0 && size.y()>0) { - SetImageSize(size); - } // load data if (true == tmpName.EndWith(".bmp") ) { // generate the texture @@ -40,8 +36,13 @@ ewol::TextureFile::TextureFile(etk::UString genName, etk::UString tmpfileName, i if (false == m_element.IsLoadOk()) { EWOL_ERROR("Error To load SVG file " << tmpName ); } else { - // generate the texture - m_element.GenerateAnImage(size, m_data); + if (size.x()>0 && size.y()>0) { + // generate the texture + m_element.GenerateAnImage(size, m_data); + } else { + // generate the texture + m_element.GenerateAnImage(m_data); + } } } else if (true == tmpName.EndWith(".png") ) { // generate the texture @@ -51,6 +52,8 @@ ewol::TextureFile::TextureFile(etk::UString genName, etk::UString tmpfileName, i } else { EWOL_ERROR("Extention not managed " << tmpName << " Sopported extention : .bmp / .svg / .png"); } + ivec2 tmp = m_data.GetSize(); + m_realImageSize = vec2(tmp.x(), tmp.y()); Flush(); } diff --git a/sources/ewol/renderer/resources/Image.h b/sources/ewol/renderer/resources/Image.h index 79dc19ec..49c62885 100644 --- a/sources/ewol/renderer/resources/Image.h +++ b/sources/ewol/renderer/resources/Image.h @@ -19,10 +19,13 @@ namespace ewol { class TextureFile : public ewol::Texture { + private: + vec2 m_realImageSize; public: TextureFile(etk::UString genName, etk::UString fileName, ivec2 size); ~TextureFile(void) { }; virtual const char* GetType(void) { return "ewol::TextureFile"; }; + const vec2& GetRealSize(void) { return m_realImageSize; }; }; }; diff --git a/sources/ewol/widget/Image.cpp b/sources/ewol/widget/Image.cpp index 3a59f1c2..665dd546 100644 --- a/sources/ewol/widget/Image.cpp +++ b/sources/ewol/widget/Image.cpp @@ -13,10 +13,10 @@ #include -extern const char * const ewolEventImagePressed = "ewol-image-Pressed"; +extern const char * const ewolEventImagePressed = "ewol-image-Pressed"; #undef __class__ -#define __class__ "Image" +#define __class__ "Image" static ewol::Widget* Create(void) { @@ -34,9 +34,12 @@ void widget::Image::UnInit(void) } -widget::Image::Image(const etk::UString& file, const ewol::Dimension& size, const ewol::Dimension& border) +widget::Image::Image(const etk::UString& file, const ewol::Dimension& border) : + m_imageSize(vec2(0,0)), + m_keepRatio(true) { - Set(file, border, size); + AddEventId(ewolEventImagePressed); + Set(file, border); } @@ -47,7 +50,7 @@ void widget::Image::SetFile(const etk::UString& file) // Force redraw all : MarkToRedraw(); ewol::RequestUpdateSize(); - m_compositing.SetSource(m_fileName, m_size); + m_compositing.SetSource(m_fileName, vec2(64,64)); } void widget::Image::SetBorder(const ewol::Dimension& border) @@ -56,30 +59,38 @@ void widget::Image::SetBorder(const ewol::Dimension& border) m_border = border; // Force redraw all : MarkToRedraw(); + // TODO : Change the size with no size requested ... ewol::RequestUpdateSize(); } -void widget::Image::SetSize(const ewol::Dimension& size) +void widget::Image::SetKeepRatio(bool keep) { - // copy data : - m_imageSize = size; - // Force redraw all : - MarkToRedraw(); - if (m_compositing.HasSources()) { - m_compositing.SetSource(m_fileName, m_size); + if (m_keepRatio != keep) { + // copy data : + m_keepRatio = keep; + // Force redraw all : + MarkToRedraw(); + ewol::RequestUpdateSize(); } } -void widget::Image::Set(const etk::UString& file, const ewol::Dimension& size, const ewol::Dimension& border) +void widget::Image::SetImageSize(const ewol::Dimension& size) +{ + m_imageSize = size; + MarkToRedraw(); + ewol::RequestUpdateSize(); + m_compositing.SetSource(m_fileName, m_imageSize.GetPixel()); +} + +void widget::Image::Set(const etk::UString& file, const ewol::Dimension& border) { // copy data : m_border = border; - m_imageSize = size; m_fileName = file; // Force redraw all : MarkToRedraw(); ewol::RequestUpdateSize(); - m_compositing.SetSource(m_fileName, m_size); + m_compositing.SetSource(m_fileName, m_imageSize.GetPixel()); } @@ -93,19 +104,51 @@ void widget::Image::OnRegenerateDisplay(void) if (true == NeedRedraw()) { // remove data of the previous composition : m_compositing.Clear(); + // calculate the new position and size : - vec2 origin = m_origin + m_border.GetPixel(); + vec2 imageBoder = m_border.GetPixel(); + vec2 origin = imageBoder; + imageBoder *= 2.0f; + vec2 imageRealSize = m_minSize - imageBoder; + vec2 imageRealSizeMax = m_size - imageBoder; + + vec2 tmpSize = m_compositing.GetRealSize(); + if (m_userFill.x()) { + imageRealSize.setX(imageRealSizeMax.x()); + } else { + origin.setX(origin.x() + (m_size.x()-m_minSize.x())*0.5f); + } + if (m_userFill.y()) { + imageRealSize.setY(imageRealSizeMax.y()); + } else { + origin.setY(origin.y() + (m_size.y()-m_minSize.y())*0.5f); + } + // set the somposition properties : - m_compositing.SetPos(vec3(origin.x(), origin.y(), 0) ); - m_compositing.Print(m_imageSize.GetPixel()); - EWOL_DEBUG("Paint Image at : " << origin << " size=" << m_imageSize.GetPixel() << " border=" << m_border.GetPixel()); + m_compositing.SetPos(origin); + m_compositing.Print(imageRealSize); + EWOL_DEBUG("Paint Image at : " << origin << " size=" << imageRealSize << " origin=" << origin); } } void widget::Image::CalculateMinMaxSize(void) { - m_minSize = m_border.GetPixel()*2+m_imageSize.GetPixel(); - m_maxSize = m_userMaxSize.GetPixel(); + vec2 imageBoder = m_border.GetPixel()*2.0f; + vec2 imageSize = m_imageSize.GetPixel(); + if (imageSize!=vec2(0,0)) { + m_minSize = imageBoder+imageSize; + m_maxSize = m_minSize; + } else { + vec2 imageSizeReal = m_compositing.GetRealSize(); + vec2 min1 = imageBoder+m_userMinSize.GetPixel(); + m_minSize = imageBoder+imageSizeReal; + //EWOL_DEBUG(" set max : " << m_minSize << " " << min1); + m_minSize.setMax(min1); + //EWOL_DEBUG(" result : " << m_minSize); + m_maxSize = imageBoder+m_userMaxSize.GetPixel(); + m_minSize.setMin(m_maxSize); + } + //EWOL_DEBUG("set widget min=" << m_minSize << " max=" << m_maxSize << " with real Image Size=" << imageSizeReal); MarkToRedraw(); } @@ -129,9 +172,35 @@ bool widget::Image::LoadXML(TiXmlNode* node) } ewol::Widget::LoadXML(node); // get internal data : - // TODO : Unparse data type XML ... + + const char *tmpAttributeValue = node->ToElement()->Attribute("ratio"); + if (NULL != tmpAttributeValue) { + if (strcmp(tmpAttributeValue,"true")==0) { + m_keepRatio = true; + } else if (strcmp(tmpAttributeValue,"1")==0) { + m_keepRatio = true; + } else { + m_keepRatio = false; + } + } + tmpAttributeValue = node->ToElement()->Attribute("size"); + if (NULL != tmpAttributeValue) { + //EWOL_CRITICAL(" Parse SIZE : " << tmpAttributeValue); + m_imageSize = tmpAttributeValue; + //EWOL_CRITICAL(" ==> " << m_imageSize); + } + tmpAttributeValue = node->ToElement()->Attribute("border"); + if (NULL != tmpAttributeValue) { + m_border = tmpAttributeValue; + } //EWOL_DEBUG("Load label:" << node->ToElement()->GetText()); - //SetLabel(node->ToElement()->GetText()); + if (node->ToElement()->GetText() != NULL) { + SetFile(node->ToElement()->GetText()); + } else { + tmpAttributeValue = node->ToElement()->Attribute("src"); + if (NULL != tmpAttributeValue) { + SetFile(tmpAttributeValue); + } + } return true; } - diff --git a/sources/ewol/widget/Image.h b/sources/ewol/widget/Image.h index 31ebd69e..cb9c9965 100644 --- a/sources/ewol/widget/Image.h +++ b/sources/ewol/widget/Image.h @@ -30,58 +30,76 @@ namespace widget { */ static void UnInit(void); protected: - ewol::Dimension m_border; //!< border to add at the image. - etk::UString m_fileName; //!< File name of the image. - ewol::Dimension m_imageSize; //!< requested image Size ewol::Image m_compositing; //!< compositing element of the image. public: /** * @brief */ Image(const etk::UString& file="", - const ewol::Dimension& size=ewol::Dimension(vec2(10,10),ewol::Dimension::Centimeter), - const ewol::Dimension& border=ewol::Dimension(vec2(2,2),ewol::Dimension::Millimeter)); + const ewol::Dimension& border=ewol::Dimension(vec2(0,0),ewol::Dimension::Millimeter)); /** * @brief */ virtual ~Image(void) { }; - /** - * @brief Set the new filename - * @param[in] file Filaneme of the new image - */ - void SetFile(const etk::UString& file); - /** - * @brief Set tge Border size around the image - * @param[in] border New border size to set - */ - void SetBorder(const ewol::Dimension& border); - /** - * @brief Set the display size of the image (can be greater than the widget size (it will be clipped) - * @param[in] size new size of the display - */ - void SetSize(const ewol::Dimension& size); /** * @brief Set All the configuration of the current image * @param[in] file Filaneme of the new image * @param[in] border New border size to set * @param[in] size new size of the display */ - void Set(const etk::UString& file, const ewol::Dimension& border, const ewol::Dimension& size); + void Set(const etk::UString& file, const ewol::Dimension& border); + protected: + etk::UString m_fileName; //!< File name of the image. + public: + /** + * @brief Set the new filename + * @param[in] file Filaneme of the new image + */ + void SetFile(const etk::UString& file); /** * @brief Get the file displayed * @return the filename of the image */ const etk::UString& GetFile() { return m_fileName; }; + protected: + ewol::Dimension m_border; //!< border to add at the image. + public: + /** + * @brief Set tge Border size around the image + * @param[in] border New border size to set + */ + void SetBorder(const ewol::Dimension& border); /** * @brief Get the current border request at the image * @return the border size */ const ewol::Dimension& GetBorder() { return m_border; }; + protected: + ewol::Dimension m_imageSize; //!< border to add at the image. + public: /** - * @brief Get the current Image display size - * @return the size of the image + * @brief Set tge Border size around the image + * @param[in] border New border size to set + */ + void SetImageSize(const ewol::Dimension& size); + /** + * @brief Get the current border request at the image + * @return the border size */ const ewol::Dimension& GetImageSize() { return m_imageSize; }; + protected: + bool m_keepRatio; //!< Keep the image ratio between width and hight + public: + /** + * @brief Set the current status of keeping ratio. + * @param[in] The new status of keeping the ratio of this image. + */ + void SetKeepRatio(bool keep); + /** + * @brief Get the current status of keeping ratio. + * @return The status of keeping the ratio of this image. + */ + bool GetKeepRatio(void) { return m_keepRatio; }; public: // Derived function virtual const char * const GetObjectType(void) { return "Ewol::Image"; }; diff --git a/sources/ewol/widget/Menu.cpp b/sources/ewol/widget/Menu.cpp index c579fa99..43e84a8e 100644 --- a/sources/ewol/widget/Menu.cpp +++ b/sources/ewol/widget/Menu.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #undef __class__ #define __class__ "Menu" @@ -81,22 +83,30 @@ int32_t widget::Menu::Add(int32_t parent, etk::UString label, etk::UString image tmpObject->m_message = message; m_listElement.PushBack(tmpObject); if (-1 == tmpObject->m_parentId) { - // TODO : When button are back ... - /* widget::Button * myButton = NULL; - myButton = new widget::Button(label); + myButton = new widget::Button(); if (NULL == myButton) { EWOL_ERROR("Allocation button error"); return tmpObject->m_localId; } - // set the image if one is present ... - myButton->SetImage(tmpObject->m_image); + if (tmpObject->m_image.Size()!=0) { + myButton->SetSubWidget( + new widget::Composer(widget::Composer::String, + etk::UString("\n") + + " \n" + " m_image + "\" size=\"8,8mm\"/>\n" + " \n" + " \n" + "SetSubWidget( new widget::Label(label) ); + } + // add it in the widget list widget::Sizer::SubWidgetAdd(myButton); // keep the specific event ... myButton->RegisterOnEvent(this, ewolEventButtonPressed, ewolEventButtonPressed); tmpObject->m_widgetPointer = myButton; - */ } return tmpObject->m_localId; } @@ -172,22 +182,30 @@ void widget::Menu::OnReceiveMessage(ewol::EObject * CallerObject, const char * e for(int32_t jjj=m_listElement.Size()-1; jjj>=0; jjj--) { if (m_listElement[iii]!=NULL) { if (m_listElement[iii]->m_localId == m_listElement[jjj]->m_parentId) { - // TODO : When button are back ... - /* - myButton = new widget::Button(m_listElement[jjj]->m_label); + myButton = new widget::Button(); if (NULL == myButton) { EWOL_ERROR("Allocation Error"); } else { + /*if (m_listElement[jjj]->m_image.Size()!=0) { + myButton->SetSubWidget( + new widget::Composer(widget::Composer::String, + etk::UString("\n") + + " \n" + " m_image + "\" size=\"8,8mm\"/>\n" + " \n" + " \n" + "SetSubWidget( new widget::Label(etk::UString("") + m_listElement[jjj]->m_label + "") ); + } // set the image if one is present ... - myButton->SetImage(m_listElement[jjj]->m_image); myButton->RegisterOnEvent(this, ewolEventButtonPressed, ewolEventButtonPressed); - myButton->SetExpandX(true); - myButton->SetFillX(true); + myButton->SetExpand(bvec2(true,false)); + myButton->SetFill(bvec2(true,false)); // add it in the widget list mySizer->SubWidgetAdd(myButton); m_listElement[jjj]->m_widgetPointer = myButton; } - */ } } } diff --git a/sources/ewol/widget/meta/FileChooser.cpp b/sources/ewol/widget/meta/FileChooser.cpp index 33d4af9a..6cd8ba80 100644 --- a/sources/ewol/widget/meta/FileChooser.cpp +++ b/sources/ewol/widget/meta/FileChooser.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include //#include #include @@ -77,6 +78,42 @@ widget::FileChooser::FileChooser(void) #endif m_file = ""; + + + /* + SubWidgetSet(new widget::Composer(widget::Composer::String, + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " display might be in error"); @@ -105,25 +142,36 @@ widget::FileChooser::FileChooser(void) mySpacer->SetExpand(bvec2(true,false)); mySizerHori->SubWidgetAdd(mySpacer); } - // TODO : set if back : - /* - m_widgetValidate = new widget::Button("Validate"); + m_widgetValidate = new widget::Button(); if (NULL == m_widgetValidate) { EWOL_ERROR("Can not allocate widget ==> display might be in error"); } else { - m_widgetValidate->SetImage("THEME:GUI:Load.svg"); + m_widgetValidate->SetSubWidget( + new widget::Composer(widget::Composer::String, + "\n" + " \n" + " \n" + " \n" + " \n" + "RegisterOnEvent(this, ewolEventButtonPressed, ewolEventFileChooserValidate); mySizerHori->SubWidgetAdd(m_widgetValidate); } - m_widgetCancel = new widget::Button("Cancel"); + m_widgetCancel = new widget::Button(); if (NULL == m_widgetCancel) { EWOL_ERROR("Can not allocate widget ==> display might be in error"); } else { - m_widgetCancel->SetImage("THEME:GUI:Remove.svg"); + m_widgetCancel->SetSubWidget( + new widget::Composer(widget::Composer::String, + "\n" + " \n" + " \n" + " \n" + " \n" + "RegisterOnEvent(this, ewolEventButtonPressed, ewolEventFileChooserCancel); mySizerHori->SubWidgetAdd(m_widgetCancel); } - */ } mySizerHori = new widget::Sizer(widget::Sizer::modeHori); if (NULL == mySizerHori) { @@ -186,7 +234,8 @@ widget::FileChooser::FileChooser(void) if (NULL == myImage) { EWOL_ERROR("Can not allocate widget ==> display might be in error"); } else { - myImage->SetFill(bvec2(false,true)); + myImage->SetImageSize(ewol::Dimension(vec2(8,8),ewol::Dimension::Millimeter)); + //myImage->SetExpand(bvec2(false,true)); mySizerHori->SubWidgetAdd(myImage); } m_widgetCurrentFileName = new widget::Entry(m_file); @@ -210,7 +259,8 @@ widget::FileChooser::FileChooser(void) if (NULL == myImage) { EWOL_ERROR("Can not allocate widget ==> display might be in error"); } else { - myImage->SetFill(bvec2(false,true)); + myImage->SetImageSize(ewol::Dimension(vec2(8,8),ewol::Dimension::Millimeter)); + //myImage->SetExpand(bvec2(false,true)); mySizerHori->SubWidgetAdd(myImage); } @@ -229,8 +279,9 @@ widget::FileChooser::FileChooser(void) if (NULL == myImage) { EWOL_ERROR("Can not allocate widget ==> display might be in error"); } else { + myImage->SetImageSize(ewol::Dimension(vec2(8,8),ewol::Dimension::Millimeter)); myImage->RegisterOnEvent(this, ewolEventImagePressed, ewolEventFileChooserHome); - myImage->SetFill(bvec2(false,true)); + //myImage->SetExpand(bvec2(false,true)); mySizerHori->SubWidgetAdd(myImage); } } diff --git a/sources/ewol/widget/newSystem.txt b/sources/ewol/widget/newSystem.txt index 409098e8..9391ba83 100644 --- a/sources/ewol/widget/newSystem.txt +++ b/sources/ewol/widget/newSystem.txt @@ -14,8 +14,6 @@ ewol::Widget [OK] |== widget::Container [OK] | . | /|\ - | |== widget::Button [OK] - | | | \== widget::Composer [OK] | |== widget::ContainerN [OK] @@ -24,11 +22,19 @@ ewol::Widget [OK] | |== widget::Layer [OK] | | | \== widget::Sizer [OK] + | + |== widget::Button [OK] + | + |== widget::Entry [TOEND] + | + |== widget::Label [OK] + | + |== widget::Image [TOEND] + | ewol::EObject ewol::Widget ## Windows : - widget::Windows main application windows widget::PopUp Widget to display basic pop-up ## Meta-widget : // (multiple and complex widget commonly used) @@ -37,9 +43,6 @@ ewol::EObject widget::ColorChooser Select a specific color widget::Calendar [*TODO*] display the current calendar ## Basics : - widget::Image - widget::Label - widget::Entry widget::EntryNumericSpin [*TODO*] widget::Checkbox widget::Joystick @@ -55,12 +58,9 @@ ewol::EObject widget::ButtonImage widget::ButtonImageText ## contener : - widget::Sizer widget::Gird - widget::Layer widget::WSlider widget::FreePosition [*TODO*] set the widget at the desird position - widget::WSlider widget::ColorBar.cpp