diff --git a/Sources/libewol/ewol/Game/GameElement.cpp b/Sources/libewol/ewol/Game/GameElement.cpp new file mode 100644 index 00000000..04a58b51 --- /dev/null +++ b/Sources/libewol/ewol/Game/GameElement.cpp @@ -0,0 +1,125 @@ +/** + ******************************************************************************* + * @file ewol/Game/GameElement.cpp + * @brief ewol game element system (Sources) + * @author Edouard DUPIN + * @date 06/04/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 + + +/** + * @brief Constructor : here are requested all the needed sprite and effect that can be used in the game + * @param --- + * @return --- + */ +ewol::GameElement::GameElement(void) +{ + m_visible = true; + m_position.x = 0.0; + m_position.y = 0.0; + m_acceleration.x = 0.0; + m_acceleration.y = 0.0; + m_size = 64.0; + m_angle = 0.0; +} + + +/** + * @brief Destructor : This does not remove the sprite requested, they will be supressed when the scene is removed ... + * @param --- + * @return --- + */ +ewol::GameElement::~GameElement(void) +{ + +} + + +/** + * @brief Periodicly this fuction will be call tu change property of all the dynamic obbjects + * @param[in] time Current game time (start at 0) + * @param[in] deltaTime delta time before the previous call + * @param[in,out] listOfSprite Reference on the list where the display must be done for every sprite + * @param[in,out] listOfEffects Reference on the list where the display must be done for every effects + * @return true if the object must be remove + * @return false if the object must be keep + */ +bool ewol::GameElement::Process(int64_t time, int32_t deltaTime, etk::VectorType & listOfElement) +{ + // nothing to do here ... + return false; +} + + +/** + * @brief Requuest the draw of the current element, it will be done on the current Sprite list + * @param[in,out] listOfSprite Reference on the list where the display must be done for every sprite + * @param[in,out] listOfEffects Reference on the list where the display must be done for every effects + * @return --- + */ +void ewol::GameElement::Draw(etk::VectorType & listOfSprite, etk::VectorType & listOfEffects) +{ + // nothing to do here ... +} + + +/** + * @brief an element has been remove, just remove reference on it or ID on IT, it can be replace whith an other that have no link + * @param[in] idOfElement Id of the element that has been removed + * @return --- + */ +void ewol::GameElement::RemoveElement(int32_t idOfElement) +{ + // nothing to do here ... +} + + +/** + * @brief Requuest the draw of the current element, it will be done on the current Sprite list + * @param[in,out] listOfElement Reference on the list of sprite that we need to find if it exist or added a new one + * @param[in] fileName Sprite name + * @param[in] maxSize maximum size of the sprite + * @return the id of the sprite requested or -1 if it does not existed + */ +int32_t ewol::GameElement::LoadSprite(etk::VectorType listOfElement[NB_BOUBLE_BUFFER], etk::UString fileName, coord2D_ts maxSize) +{ + for (int32_t iii=0; iiiHasName(fileName) == true) { + // TODO : control the size ... + return iii; + } + } + } + for(int32_t iii=0; iii created it ... + ewol::Sprite* tmpSprite = new ewol::Sprite(fileName, maxSize.x, maxSize.y); + if (NULL == tmpSprite) { + EWOL_ERROR("Allocation error on the sprite : " << fileName); + return -1; + } + // add it : + listOfElement[iii].PushBack(tmpSprite); + } + return listOfElement[0].Size() -1; +} + diff --git a/Sources/libewol/ewol/Game/GameElement.h b/Sources/libewol/ewol/Game/GameElement.h new file mode 100644 index 00000000..ed5e2732 --- /dev/null +++ b/Sources/libewol/ewol/Game/GameElement.h @@ -0,0 +1,65 @@ +/** + ******************************************************************************* + * @file ewol/Game/GameElement.h + * @brief ewol game element system (header) + * @author Edouard DUPIN + * @date 06/04/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_GAME_ELEMENT_H__ +#define __EWOL_GAME_ELEMENT_H__ + +#include +#include +#include +#include + + +namespace ewol { + class GameElement + { + protected: + bool m_visible; + coord2D_ts m_position; + coord2D_ts m_acceleration; + etkFloat_t m_size; + etkFloat_t m_angle; + public: + GameElement(void); + virtual ~GameElement(void); + bool IsVisible(void) { return m_visible; }; + void SetVisible(bool state) { m_visible = state; }; + coord2D_ts PositionGet(void) { return m_position; }; + void PositionSet(coord2D_ts state) { m_position = state; }; + void PositionSet(etkFloat_t xxx, etkFloat_t yyy) { m_position.x = xxx; m_position.y = yyy; }; + coord2D_ts AccelerationGet(void) { return m_acceleration; }; + void AccelerationSet(coord2D_ts state) { m_acceleration = state; }; + etkFloat_t SizeGet(void) { return m_size; }; + void SizeSet(etkFloat_t state) { m_size = state; }; + etkFloat_t AngleGet(void) { return m_angle; }; + void AngleSet(etkFloat_t state) { m_angle = state; }; + virtual bool Process(int64_t time, int32_t deltaTime, etk::VectorType & listOfElement); + virtual void Draw(etk::VectorType & listOfSprite, etk::VectorType & listOfEffects); + virtual void RemoveElement(int32_t idOfElement); + int32_t LoadSprite(etk::VectorType listOfElement[NB_BOUBLE_BUFFER], etk::UString fileName, coord2D_ts maxSize); + }; + +}; + +#endif diff --git a/Sources/libewol/ewol/OObject/Sprite.cpp b/Sources/libewol/ewol/OObject/Sprite.cpp index 6ed81b9b..34215aa2 100644 --- a/Sources/libewol/ewol/OObject/Sprite.cpp +++ b/Sources/libewol/ewol/OObject/Sprite.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #undef __class__ #define __class__ "Sprite" @@ -53,7 +54,7 @@ ewol::Sprite::~Sprite(void) void ewol::Sprite::Draw(void) { if (m_coord.Size()<=0) { - EWOL_WARNING("Nothink to draw..."); + //EWOL_WARNING("Nothink to draw..."); return; } if (m_textureId == -1) { @@ -75,56 +76,56 @@ void ewol::Sprite::Draw(void) glDisable(GL_TEXTURE_2D); } -void ewol::Sprite::Rectangle(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t texX, etkFloat_t texY, etkFloat_t texSX, etkFloat_t texSY) +void ewol::Sprite::Clear(void) { - //EWOL_DEBUG("Add rectangle : ..."); - coord2D_ts point; - texCoord_ts tex; - - tex.u = texX; - tex.v = texY; - point.x = x; - point.y = y; - m_coord.PushBack(point); - m_coordTex.PushBack(tex); - - - tex.u = texSX; - tex.v = texY; - point.x = x + w; - point.y = y; - m_coord.PushBack(point); - m_coordTex.PushBack(tex); - - - tex.u = texSX; - tex.v = texSY; - point.x = x + w; - point.y = y + h; - m_coord.PushBack(point); - m_coordTex.PushBack(tex); - - m_coord.PushBack(point); - m_coordTex.PushBack(tex); - - tex.u = texX; - tex.v = texSY; - point.x = x; - point.y = y + h; - m_coord.PushBack(point); - m_coordTex.PushBack(tex); - - tex.u = texX; - tex.v = texY; - point.x = x; - point.y = y; - m_coord.PushBack(point); - m_coordTex.PushBack(tex); + m_coord.Clear(); + m_coordTex.Clear(); } - -void Element(coord2D_ts pos, etkFloat_t size, etkFloat_t angle) +void ewol::Sprite::Element(coord2D_ts pos, etkFloat_t size, etkFloat_t angle) { + angle -= M_PI/4; + size *= 0.7; + texCoord_ts texA, texB, texC, texD; + texA.u = 0.0; + texA.v = 0.0; + texB.u = 0.0; + texB.v = 1.0; + texC.u = 1.0; + texC.v = 1.0; + texD.u = 1.0; + texD.v = 0.0; + coord2D_ts point; + etkFloat_t yyySin = sin(angle) * size; + etkFloat_t xxxCos = cos(angle) * size; + + point.x = xxxCos + pos.x; + point.y = yyySin + pos.y; + m_coord.PushBack(point); + m_coordTex.PushBack(texB); + + point.x = yyySin + pos.x; + point.y = -xxxCos + pos.y; + m_coord.PushBack(point); + m_coordTex.PushBack(texC); + + point.x = -xxxCos + pos.x; + point.y = -yyySin + pos.y; + m_coord.PushBack(point); + m_coordTex.PushBack(texD); + + m_coord.PushBack(point); + m_coordTex.PushBack(texD); + + point.x = -yyySin + pos.x; + point.y = xxxCos + pos.y; + m_coord.PushBack(point); + m_coordTex.PushBack(texA); + + point.x = xxxCos + pos.x; + point.y = yyySin + pos.y; + m_coord.PushBack(point); + m_coordTex.PushBack(texB); } diff --git a/Sources/libewol/ewol/OObject/Sprite.h b/Sources/libewol/ewol/OObject/Sprite.h index b187abad..ac981882 100644 --- a/Sources/libewol/ewol/OObject/Sprite.h +++ b/Sources/libewol/ewol/OObject/Sprite.h @@ -36,10 +36,10 @@ namespace ewol { Sprite(etk::UString spriteName); Sprite(etk::UString spriteName, etkFloat_t sizeX, etkFloat_t sizeY); virtual ~Sprite(void); - public: virtual void Draw(void); - void Rectangle(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t texX=0.0, etkFloat_t texY=0.0, etkFloat_t texSX=1.0, etkFloat_t texSY=1.0); + void Clear(void); void Element(coord2D_ts pos, etkFloat_t size, etkFloat_t angle); + bool HasName(etk::UString& name) { return name == m_name; }; protected: int32_t m_textureId; //!< texture internal ID etk::VectorType m_coord; //!< internal coord of the object diff --git a/Sources/libewol/ewol/Widget.cpp b/Sources/libewol/ewol/Widget.cpp index 227d1990..a647e863 100644 --- a/Sources/libewol/ewol/Widget.cpp +++ b/Sources/libewol/ewol/Widget.cpp @@ -276,3 +276,17 @@ void ewol::Widget::GenDraw(void) glPopMatrix(); return; } + +/** + * @brief Request that the current widegt have a periodic call + * @param statusToSet true if the periodic call is needed + * @return --- + */ +void ewol::Widget::PeriodicCallSet(bool statusToSet) +{ + if (true == statusToSet) { + ewol::widgetManager::PeriodicCallAdd(this); + } else { + ewol::widgetManager::PeriodicCallRm(this); + } +} \ No newline at end of file diff --git a/Sources/libewol/ewol/Widget.h b/Sources/libewol/ewol/Widget.h index f2d4d2ef..85b715fd 100644 --- a/Sources/libewol/ewol/Widget.h +++ b/Sources/libewol/ewol/Widget.h @@ -317,7 +317,21 @@ namespace ewol { * @return --- */ virtual void OnLostFocus(void) {}; - + protected: + /** + * @brief Request that the current widegt have a periodic call + * @param statusToSet true if the periodic call is needed + * @return --- + */ + void PeriodicCallSet(bool statusToSet); + public: + /** + * @brief Periodic call of this widget + * @param localTime curent system time + * @return --- + */ + virtual void PeriodicCall(int64_t localTime) { }; + public: /** * @brief Get the widget at the specific windows absolute position diff --git a/Sources/libewol/ewol/WidgetManager.cpp b/Sources/libewol/ewol/WidgetManager.cpp index fd361fe6..688d96d4 100644 --- a/Sources/libewol/ewol/WidgetManager.cpp +++ b/Sources/libewol/ewol/WidgetManager.cpp @@ -27,6 +27,7 @@ #include #include //#include +#include #undef __class__ #define __class__ "WidgetManager" @@ -37,6 +38,8 @@ static bool IsInit = false; // For the focus Management static ewol::Widget * m_focusWidgetDefault = NULL; static ewol::Widget * m_focusWidgetCurrent = NULL; +static etk::VectorType l_listOfPeriodicWidget; +static bool l_havePeriodic = false; void ewol::widgetManager::Init(void) { @@ -47,6 +50,8 @@ void ewol::widgetManager::Init(void) // prevent android error ==> can create memory leak but I prefer m_focusWidgetDefault = NULL; m_focusWidgetCurrent = NULL; + l_listOfPeriodicWidget.Clear(); + l_havePeriodic = false; // init all the widget global parameters : ewol::WIDGET_JoystickInit(); ewol::WIDGET_ButtonInit(); @@ -64,12 +69,14 @@ void ewol::widgetManager::UnInit(void) IsInit = false; + l_listOfPeriodicWidget.Clear(); int ret = pthread_mutex_destroy(&localMutex); EWOL_ASSERT(ret == 0, "Error destroying Mutex ..."); } void ewol::widgetManager::Rm(ewol::Widget * newWidget) { + PeriodicCallRm(newWidget); FocusRemoveIfRemove(newWidget); } @@ -160,6 +167,54 @@ void ewol::widgetManager::FocusRemoveIfRemove(ewol::Widget * newWidget) } + +void ewol::widgetManager::PeriodicCallAdd(ewol::Widget * pWidget) +{ + for (int32_t iii=0; iii < l_listOfPeriodicWidget.Size(); iii++) { + if (l_listOfPeriodicWidget[iii] == pWidget) { + return; + } + } + for (int32_t iii=0; iii < l_listOfPeriodicWidget.Size(); iii++) { + if (NULL == l_listOfPeriodicWidget[iii]) { + l_listOfPeriodicWidget[iii] = pWidget; + return; + } + } + l_listOfPeriodicWidget.PushBack(pWidget); + l_havePeriodic = true; +} + +void ewol::widgetManager::PeriodicCallRm(ewol::Widget * pWidget) +{ + int32_t nbElement = 0; + for (int32_t iii=0; iii < l_listOfPeriodicWidget.Size(); iii++) { + if (l_listOfPeriodicWidget[iii] == pWidget) { + l_listOfPeriodicWidget[iii] = NULL; + } else { + nbElement++; + } + } + if (0 == nbElement) { + l_havePeriodic = false; + } +} + +void ewol::widgetManager::PeriodicCall(int64_t localTime) +{ + for (int32_t iii=0; iii < l_listOfPeriodicWidget.Size(); iii++) { + if (NULL != l_listOfPeriodicWidget[iii]) { + l_listOfPeriodicWidget[iii]->PeriodicCall(localTime); + } + } +} + +bool ewol::widgetManager::PeriodicCallHave(void) +{ + return l_havePeriodic; +} + + static bool needRedraw = true; void ewol::widgetManager::DoubleBufferLock(void) diff --git a/Sources/libewol/ewol/WidgetManager.h b/Sources/libewol/ewol/WidgetManager.h index 06169af4..0e48616f 100644 --- a/Sources/libewol/ewol/WidgetManager.h +++ b/Sources/libewol/ewol/WidgetManager.h @@ -44,6 +44,13 @@ namespace ewol { ewol::Widget * FocusGet( void); void FocusRemoveIfRemove(ewol::Widget * newWidget); + + void PeriodicCallAdd(ewol::Widget * pWidget); + void PeriodicCallRm( ewol::Widget * pWidget); + void PeriodicCall(int64_t localTime); + bool PeriodicCallHave(void); + + // TODO : Remove this from here ... int32_t GetDoubleBufferCreate(void); int32_t GetDoubleBufferDraw(void); diff --git a/Sources/libewol/ewol/base/MainThread.cpp b/Sources/libewol/ewol/base/MainThread.cpp index 979c19a7..e6855a19 100644 --- a/Sources/libewol/ewol/base/MainThread.cpp +++ b/Sources/libewol/ewol/base/MainThread.cpp @@ -194,6 +194,10 @@ static void* BaseAppEntry(void* param) } if (0 == ewol::threadMsg::WaitingMessage(androidJniMsg)) { if (countNbEvent > 0) { + if(true == ewol::threadMsg::HasDisplayDone(androidJniMsg)) { + + ewol::widgetManager::PeriodicCall(0); + } EWOL_NativeRegenerateDisplay(); countNbEvent = 0; } diff --git a/Sources/libewol/ewol/base/gui.cpp b/Sources/libewol/ewol/base/gui.cpp index 5ef64305..f36c1a68 100644 --- a/Sources/libewol/ewol/base/gui.cpp +++ b/Sources/libewol/ewol/base/gui.cpp @@ -173,6 +173,9 @@ void EWOL_GenericDraw(bool everyTime) if ( (currentTime - startTime) > DISPLAY_PERIODE_MS) { display = true; } + if (ewol::widgetManager::PeriodicCallHave()) { + everyTime = true; + } ewol::widgetManager::DoubleBufferLock(); if( true == ewol::widgetManager::GetDoubleBufferNeedDraw() || true == everyTime) diff --git a/Sources/libewol/ewol/threadMsg.cpp b/Sources/libewol/ewol/threadMsg.cpp index 23e68818..53ceeafb 100644 --- a/Sources/libewol/ewol/threadMsg.cpp +++ b/Sources/libewol/ewol/threadMsg.cpp @@ -182,10 +182,31 @@ int32_t ewol::threadMsg::WaitingMessage(threadMsg_ts& messageData) void ewol::threadMsg::SendDisplayDone(threadMsg_ts& messageData) { + if (false == messageData.isInit) { + return; + } + pthread_mutex_lock(&messageData.mutex); + messageData.displayHasDone = true; + pthread_cond_broadcast(&messageData.condition); + pthread_mutex_unlock(&messageData.mutex); } +bool ewol::threadMsg::HasDisplayDone(threadMsg_ts& messageData) +{ + if (false == messageData.isInit) { + return false; + } + bool state = false; + pthread_mutex_lock(&messageData.mutex); + state = messageData.displayHasDone; + messageData.displayHasDone = false;; + pthread_mutex_unlock(&messageData.mutex); + return state; +} + + #include diff --git a/Sources/libewol/ewol/threadMsg.h b/Sources/libewol/ewol/threadMsg.h index d9790c11..72aaec03 100644 --- a/Sources/libewol/ewol/threadMsg.h +++ b/Sources/libewol/ewol/threadMsg.h @@ -65,6 +65,7 @@ namespace ewol { int32_t WaitingMessage(threadMsg_ts& messageData); bool SendMessage(threadMsg_ts& messageData, uint32_t type, msgPriority_te prio = MSG_PRIO_NONE, void * data = NULL, uint32_t size = 0); void SendDisplayDone(threadMsg_ts& messageData); + bool HasDisplayDone(threadMsg_ts& messageData); }; namespace simpleMsg { diff --git a/Sources/libewol/ewol/widget/Joystick.cpp b/Sources/libewol/ewol/widget/Joystick.cpp index 730db92a..33683838 100644 --- a/Sources/libewol/ewol/widget/Joystick.cpp +++ b/Sources/libewol/ewol/widget/Joystick.cpp @@ -343,3 +343,17 @@ void ewol::Joystick::Foreground(etk::UString imageNameInData) EWOL_INFO("Set default Joystick Foreground at " << m_foreground); } + +/** + * @brief Get the property of the joystick + * @param[out] distance distance to the center + * @param[out] angle angle of the joy + * @return --- + */ +void ewol::Joystick::GetProperty(etkFloat_t& distance, etkFloat_t& angle) +{ + distance = m_distance; + angle = m_angle+M_PI/2; +} + + diff --git a/Sources/libewol/ewol/widget/Joystick.h b/Sources/libewol/ewol/widget/Joystick.h index e4fafc46..df08e516 100644 --- a/Sources/libewol/ewol/widget/Joystick.h +++ b/Sources/libewol/ewol/widget/Joystick.h @@ -112,6 +112,15 @@ namespace ewol { * @return --- */ void Foreground(etk::UString imageNameInData); + + /** + * @brief Get the property of the joystick + * @param[out] distance distance to the center + * @param[out] angle angle of the joy + * @return --- + */ + void GetProperty(etkFloat_t& distance, etkFloat_t& angle); + }; /** diff --git a/Sources/libewol/ewol/widget/Scene.cpp b/Sources/libewol/ewol/widget/Scene.cpp index 3d1efd08..5ac05ef0 100644 --- a/Sources/libewol/ewol/widget/Scene.cpp +++ b/Sources/libewol/ewol/widget/Scene.cpp @@ -45,6 +45,7 @@ void ewol::WIDGET_SceneInit(void) ewol::Scene::Scene(void) { SetCanHaveFocus(true); + PeriodicCallSet(true); } @@ -95,5 +96,85 @@ const char * const ewol::Scene::GetObjectType(void) void ewol::Scene::OnRegenerateDisplay(void) { if (true == NeedRedraw()) { + // clean elements + for (int32_t iii=0; iiiClear(); + } + } + // clean effects + for (int32_t iii=0; iiiClear(); + } + } + for (int32_t iii=0; iiiDraw(m_animated[m_currentCreateId], m_effects[m_currentCreateId]); + } + } } } + +/** + * @brief Common widget drawing function (called by the drawing thread [Android, X11, ...]) + * @param --- + * @return --- + */ +void ewol::Scene::OnDraw(void) +{ + //EWOL_ERROR(" On draw : " << m_currentDrawId); + // draw background + // TODO : ... + // draw elements + for (int32_t iii=0; iiiDraw(); + } + } + // draw effects + for (int32_t iii=0; iiiDraw(); + } + } + m_needFlipFlop = true; +} + + +void ewol::Scene::AddElement(ewol::GameElement* newElement) +{ + if (NULL == newElement) { + return; + } + for (int32_t iii=0; iiiProcess(localTime, 100, m_listAnimatedElements); + } + } + MarkToReedraw(); +} + + diff --git a/Sources/libewol/ewol/widget/Scene.h b/Sources/libewol/ewol/widget/Scene.h index 2dbe9c7d..831f8ac5 100644 --- a/Sources/libewol/ewol/widget/Scene.h +++ b/Sources/libewol/ewol/widget/Scene.h @@ -27,27 +27,19 @@ #include #include -#include #include +#include +#include namespace ewol { - class GameElement - { - private: - bool m_visible; - coord2D_ts m_position; - public: - GameElement(void) { m_visible = true; m_position.x=0.0; m_position.y=0.0;}; - virtual ~GameElement(void) {}; - }; - class Scene :public ewol::WidgetScrooled { // TODO : Set it in private ... protected: etk::VectorType m_backgroundElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first - etk::VectorType m_backgrouanimatedElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first + etk::VectorType m_animated[NB_BOUBLE_BUFFER]; //!< element that must be display the first + etk::VectorType m_effects[NB_BOUBLE_BUFFER]; //!< element that must be display the first etk::VectorType m_listAnimatedElements; //!< generic element to display... public: Scene(void); @@ -68,6 +60,20 @@ namespace ewol { */ virtual const char * const GetObjectType(void); virtual void OnRegenerateDisplay(void); + + /** + * @brief Periodic call of this widget + * @param localTime curent system time + * @return --- + */ + virtual void PeriodicCall(int64_t localTime); + /** + * @brief Common widget drawing function (called by the drawing thread [Android, X11, ...]) + * @param --- + * @return --- + */ + virtual void OnDraw(void); + void AddElement(ewol::GameElement* newElement); }; /** diff --git a/Sources/libewol/file.mk b/Sources/libewol/file.mk index 161e0166..0588987c 100644 --- a/Sources/libewol/file.mk +++ b/Sources/libewol/file.mk @@ -10,6 +10,7 @@ FILE_LIST = ewol/ewol.cpp \ ewol/EObject.cpp \ ewol/EObjectManager.cpp \ ewol/OObject.cpp \ + ewol/Game/GameElement.cpp \ ewol/OObject/2DText.cpp \ ewol/OObject/2DTextColored.cpp \ ewol/OObject/2DColored.cpp \ diff --git a/Sources/libparsersvg/parserSVG/Base.cpp b/Sources/libparsersvg/parserSVG/Base.cpp index 72bbdff9..f6ce1dae 100644 --- a/Sources/libparsersvg/parserSVG/Base.cpp +++ b/Sources/libparsersvg/parserSVG/Base.cpp @@ -228,6 +228,61 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node) if (NULL != content) { m_paint.strokeWidth = ParseLength(content); } + content = node->ToElement()->Attribute("opacity"); + if (NULL != content) { + etkFloat_t opacity = ParseLength(content); + opacity = etk_max(0.0, etk_min(1.0, opacity)); + m_paint.fill.alpha = opacity*0xFF; + m_paint.stroke.alpha = opacity*0xFF; + } + content = node->ToElement()->Attribute("fill-opacity"); + if (NULL != content) { + etkFloat_t opacity = ParseLength(content); + opacity = etk_max(0.0, etk_min(1.0, opacity)); + m_paint.fill.alpha = opacity*0xFF; + } + content = node->ToElement()->Attribute("stroke-opacity"); + if (NULL != content) { + etkFloat_t opacity = ParseLength(content); + opacity = etk_max(0.0, etk_min(1.0, opacity)); + m_paint.stroke.alpha = opacity*0xFF; + } + content = node->ToElement()->Attribute("fill-rule"); + if (NULL != content) { + if (0 == strcmp(content, "nonzero") ) { + m_paint.flagEvenOdd = false; + } else if (0 == strcmp(content, "evenodd") ) { + m_paint.flagEvenOdd = true; + } else { + SVG_ERROR("not know fill-rule value : \"" << content << "\", not in [nonzero,evenodd]"); + } + } + content = node->ToElement()->Attribute("stroke-linecap"); + if (NULL != content) { + if (0 == strcmp(content, "butt") ) { + m_paint.lineCap = svg::LINECAP_BUTT; + } else if (0 == strcmp(content, "round") ) { + m_paint.lineCap = svg::LINECAP_ROUND; + } else if (0 == strcmp(content, "square") ) { + m_paint.lineCap = svg::LINECAP_SQUARE; + } else { + m_paint.lineCap = svg::LINECAP_BUTT; + SVG_ERROR("not know stroke-linecap value : \"" << content << "\", not in [butt,round,square]"); + } + } + content = node->ToElement()->Attribute("stroke-linejoin"); + if (NULL != content) { + if (0 == strcmp(content, "miter") ) { + m_paint.lineJoin = svg::LINEJOIN_MITER; + } else if (0 == strcmp(content, "round") ) { + m_paint.lineJoin = svg::LINEJOIN_ROUND; + } else if (0 == strcmp(content, "bevel") ) { + m_paint.lineJoin = svg::LINEJOIN_BEVEL; + } else { + m_paint.lineJoin = svg::LINEJOIN_MITER; + SVG_ERROR("not know stroke-linejoin value : \"" << content << "\", not in [miter,round,bevel]"); + } + } content = node->ToElement()->Attribute("style"); if (NULL != content) { char outputType[1024] = ""; @@ -287,6 +342,8 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node) m_paint.lineJoin = svg::LINEJOIN_MITER; SVG_ERROR("not know " << outputType << " value : \"" << outputValue << "\", not in [miter,round,bevel]"); } + } else if (0 == strcmp(outputType, "marker-start") ) { + // TODO : ... } else { SVG_ERROR("not know painting element in style balise : \"" << outputType << "\" with value : \"" << outputValue << "\""); } @@ -491,7 +548,7 @@ color8_ts svg::Base::ParseColor(const char *inputData) uint32_t red, green, blue, alpha; float fred, fgreen, fblue, falpha; size_t len = strlen(inputData); - + if( len >=1 && inputData[0] == '#') { if(len == 4) {