From ea4515f63c9f60ca9aaef22cd0db7222d8bf3492 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 2 Sep 2015 21:11:02 +0200 Subject: [PATCH] [DEV] update some interface --- ewol/compositing/Shaper.cpp | 8 +++++-- ewol/context/Context.cpp | 47 ++++++++++++++++++++++++++----------- ewol/resource/Texture.cpp | 9 +++++-- ewol/resource/Texture.h | 2 +- ewol/widget/Image.cpp | 21 ++++++++++++++--- ewol/widget/Image.h | 20 +++++++++++++++- 6 files changed, 84 insertions(+), 23 deletions(-) diff --git a/ewol/compositing/Shaper.cpp b/ewol/compositing/Shaper.cpp index e4ef748f..7a9e5f5f 100644 --- a/ewol/compositing/Shaper.cpp +++ b/ewol/compositing/Shaper.cpp @@ -257,7 +257,10 @@ bool ewol::compositing::Shaper::periodicCall(const ewol::event::Time& _event) { m_nextStatusRequested = -1; } } - float timeRelativity = m_config->getNumber(m_confIdChangeTime) / 1000.0; + float timeRelativity = 0.0f; + if (m_config != nullptr) { + timeRelativity = m_config->getNumber(m_confIdChangeTime) / 1000.0; + } m_stateTransition += _event.getDeltaCall() / timeRelativity; //m_stateTransition += _event.getDeltaCall(); m_stateTransition = std::avg(0.0f, m_stateTransition, 1.0f); @@ -471,10 +474,11 @@ void ewol::compositing::Shaper::setShape(const vec2& _origin, const vec2& _size, EWOL_ERROR(" inside = " << inside); */ int32_t mode = 0; + bool displayOutside = false; if (m_config != nullptr) { mode = m_config->getNumber(m_confIdMode); + displayOutside = m_config->getBoolean(m_confIdDisplayOutside); } - bool displayOutside = m_config->getBoolean(m_confIdDisplayOutside); m_nbVertexToDisplay = 0; if (displayOutside == true) { addVertexLine(enveloppe.yTop(), border.yTop(), diff --git a/ewol/context/Context.cpp b/ewol/context/Context.cpp index a0f22136..f16ec136 100644 --- a/ewol/context/Context.cpp +++ b/ewol/context/Context.cpp @@ -106,33 +106,40 @@ void ewol::Context::onCreate(gale::Context& _context) { #endif */ EWOL_INFO(" == > Ewol system init (END)"); - if (m_application == nullptr) { + std::shared_ptr appl = m_application; + if (appl == nullptr) { return; } - m_application->onCreate(*this); + appl->onCreate(*this); } void ewol::Context::onStart(gale::Context& _context) { - if (m_application == nullptr) { + std::shared_ptr appl = m_application; + if (appl == nullptr) { // TODO : Request exit of the application .... with error ... return; } - m_application->onStart(*this); + appl->onStart(*this); } void ewol::Context::onResume(gale::Context& _context) { - m_application->onResume(*this); + std::shared_ptr appl = m_application; + if (appl == nullptr) { + return; + } + appl->onResume(*this); } void ewol::Context::onRegenerateDisplay(gale::Context& _context) { //EWOL_INFO("REGENERATE_DISPLAY"); // check if the user selected a windows - if (m_windowsCurrent == nullptr) { + std::shared_ptr window = m_windowsCurrent; + if (window == nullptr) { EWOL_INFO("No windows ..."); return; } // Redraw all needed elements - m_windowsCurrent->onRegenerateDisplay(); + window->onRegenerateDisplay(); if (m_widgetManager.isDrawingNeeded() == true) { markDrawingIsNeeded(); } @@ -144,18 +151,27 @@ void ewol::Context::onDraw(gale::Context& _context) { // clean internal data... m_objectManager.cleanInternalRemoved(); // real draw... - if (m_windowsCurrent == nullptr) { + std::shared_ptr window = m_windowsCurrent; + if (window == nullptr) { return; } - m_windowsCurrent->sysDraw(); + window->sysDraw(); } void ewol::Context::onPause(gale::Context& _context) { - m_application->onPause(*this); + std::shared_ptr appl = m_application; + if (appl == nullptr) { + return; + } + appl->onPause(*this); } void ewol::Context::onStop(gale::Context& _context) { - m_application->onStop(*this); + std::shared_ptr appl = m_application; + if (appl == nullptr) { + return; + } + appl->onStop(*this); } void ewol::Context::onDestroy(gale::Context& _context) { @@ -164,9 +180,12 @@ void ewol::Context::onDestroy(gale::Context& _context) { m_windowsCurrent.reset(); // clean all widget and sub widget with their resources: m_objectManager.cleanInternalRemoved(); - // call application to uninit - m_application->onDestroy(*this); - m_application.reset(); + std::shared_ptr appl = m_application; + if (appl != nullptr) { + // call application to uninit + appl->onDestroy(*this); + m_application.reset(); + } // internal clean elements m_objectManager.cleanInternalRemoved(); EWOL_INFO("List of all widget of this context must be equal at 0 ==> otherwise some remove is missing"); diff --git a/ewol/resource/Texture.cpp b/ewol/resource/Texture.cpp index 7c81cb7e..81e37ebb 100644 --- a/ewol/resource/Texture.cpp +++ b/ewol/resource/Texture.cpp @@ -53,8 +53,12 @@ ewol::resource::Texture::~Texture() { } #include -void ewol::resource::Texture::updateContext() { - std11::unique_lock lock(m_mutex); +bool ewol::resource::Texture::updateContext() { + std11::unique_lock lock(m_mutex, std11::defer_lock); + if (lock.try_lock() == false) { + //Lock error ==> try later ... + return false; + } if (false == m_loaded) { // Request a new texture at openGl : glGenTextures(1, &m_texId); @@ -85,6 +89,7 @@ void ewol::resource::Texture::updateContext() { m_data.getTextureDataPointer() ); // now the data is loaded m_loaded = true; + return true; } void ewol::resource::Texture::removeContext() { diff --git a/ewol/resource/Texture.h b/ewol/resource/Texture.h index cd3655cb..e8effcf6 100644 --- a/ewol/resource/Texture.h +++ b/ewol/resource/Texture.h @@ -42,7 +42,7 @@ namespace ewol { }; // flush the data to send it at the openGl system void flush(); - void updateContext(); + bool updateContext(); void removeContext(); void removeContextToLate(); const ivec2& getOpenGlSize() const { diff --git a/ewol/widget/Image.cpp b/ewol/widget/Image.cpp index 6002f696..b562215c 100644 --- a/ewol/widget/Image.cpp +++ b/ewol/widget/Image.cpp @@ -26,7 +26,8 @@ ewol::widget::Image::Image() : m_keepRatio(*this, "ratio", true, "Keep ratio of the image"), m_posStart(*this, "part-start", vec2(0.0f, 0.0f), vec2(0.0f, 0.0f), vec2(1.0f, 1.0f), "Start display position in the image"), m_posStop(*this, "part-stop", vec2(1.0f, 1.0f), vec2(0.0f, 0.0f), vec2(1.0f, 1.0f), "Start display position in the image"), - m_distanceFieldMode(*this, "distance-field", false, "Distance field mode") { + m_distanceFieldMode(*this, "distance-field", false, "Distance field mode"), + m_smooth(*this, "smooth", true, "Smooth display of the image") { addObjectType("ewol::widget::Image"); m_colorProperty = ewol::resource::ColorFile::create("THEME:COLOR:Image.json"); if (m_colorProperty != nullptr) { @@ -65,7 +66,7 @@ void ewol::widget::Image::onRegenerateDisplay() { vec2 imageBoder = m_border->getPixel(); vec2 origin = imageBoder; imageBoder *= 2.0f; - vec2 imageRealSize = m_minSize - imageBoder; + vec2 imageRealSize = m_realllll - imageBoder; vec2 imageRealSizeMax = m_size - imageBoder; vec2 ratioSizeDisplayRequested = m_posStop.get() - m_posStart.get(); @@ -101,7 +102,11 @@ void ewol::widget::Image::onRegenerateDisplay() { } // set the somposition properties : - m_compositing.setPos(origin); + if (m_smooth.get() == true) { + m_compositing.setPos(origin); + } else { + m_compositing.setPos(ivec2(origin)); + } m_compositing.printPart(imageRealSize, m_posStart, m_posStop); //EWOL_DEBUG("Paint Image at : " << origin << " size=" << imageRealSize << " origin=" << origin); EWOL_VERBOSE("Paint Image :" << m_fileName << " realsize=" << m_compositing.getRealSize() << " size=" << imageRealSize); @@ -111,6 +116,7 @@ void ewol::widget::Image::onRegenerateDisplay() { void ewol::widget::Image::calculateMinMaxSize() { vec2 imageBoder = m_border->getPixel()*2.0f; vec2 imageSize = m_imageSize->getPixel(); + vec2 size = m_userMinSize->getPixel(); if (imageSize!=vec2(0,0)) { m_minSize = imageBoder+imageSize; m_maxSize = m_minSize; @@ -124,6 +130,9 @@ void ewol::widget::Image::calculateMinMaxSize() { m_maxSize = imageBoder+m_userMaxSize->getPixel(); m_minSize.setMin(m_maxSize); } + m_realllll = m_minSize; + m_minSize.setMax(size); + m_maxSize.setMax(m_minSize); //EWOL_DEBUG("set widget min=" << m_minSize << " max=" << m_maxSize << " with real Image size=" << imageSizeReal); markToRedraw(); } @@ -167,6 +176,10 @@ bool ewol::widget::Image::loadXML(const std::shared_ptr& _n if (tmpAttributeValue.size() != 0) { m_border = tmpAttributeValue; } + tmpAttributeValue = _node->getAttribute("smooth"); + if (tmpAttributeValue.size() != 0) { + m_smooth = etk::string_to_bool(tmpAttributeValue); + } //EWOL_DEBUG("Load label:" << node->ToElement()->getText()); if (_node->size() != 0) { setFile(_node->getText()); @@ -195,5 +208,7 @@ void ewol::widget::Image::onParameterChangeValue(const ewol::parameter::Ref& _pa requestUpdateSize(); } else if (_paramPointer == m_distanceFieldMode) { markToRedraw(); + } else if (_paramPointer == m_smooth) { + markToRedraw(); } } diff --git a/ewol/widget/Image.h b/ewol/widget/Image.h index 7c6d8dc1..8f8e65db 100644 --- a/ewol/widget/Image.h +++ b/ewol/widget/Image.h @@ -84,6 +84,7 @@ namespace ewol { }; protected: ewol::parameter::Value m_imageSize; //!< border to add at the image. + vec2 m_realllll; public: /** * @brief set tge Border size around the image @@ -142,7 +143,7 @@ namespace ewol { vec2 getStopPos() const { return m_posStop; }; - public: + protected: ewol::parameter::Value m_distanceFieldMode; //!< to have a parameter public: /** @@ -159,6 +160,23 @@ namespace ewol { bool getDistanceField() const { return m_compositing.getDistanceFieldMode(); } + protected: + ewol::parameter::Value m_smooth; //!< display is done in the pixed approximation if false + public: + /** + * @brief Set smooth rendering mode + * @param[in] _value enable smooting of the display + */ + void setSmooth(bool _value) { + m_smooth.set(_value); + } + /** + * @brief Get smooth rendering mode + * @return Status of the smooting render mode. + */ + bool getSmooth() const { + return m_smooth; + } protected: // Derived function virtual void onDraw(); virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);