From 76ceb4a67dbba4d2c6cd4b9c1a024fe7cf7b3367 Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Wed, 9 Nov 2011 17:48:07 +0100 Subject: [PATCH] Draw : draw simple element: line and disc --- Sources/ewolOObject2DColored.cpp | 203 ++++++++++++++++++++++++------- Sources/ewolOObject2DColored.h | 13 +- Sources/ewolWindows.cpp | 12 +- Sources/widget/ewolButton.cpp | 6 +- Sources/widget/ewolTest.cpp | 72 +++++++++-- Sources/widget/ewolTest.h | 2 + 6 files changed, 245 insertions(+), 63 deletions(-) diff --git a/Sources/ewolOObject2DColored.cpp b/Sources/ewolOObject2DColored.cpp index 658d6a86..33b969ca 100644 --- a/Sources/ewolOObject2DColored.cpp +++ b/Sources/ewolOObject2DColored.cpp @@ -24,12 +24,25 @@ #include #include +#include #undef __class__ #define __class__ "ewol::OObject2DColored" +ewol::OObject2DColored::OObject2DColored(void) +{ + SetColor(1.0, 1.0, 1.0, 1.0); +} + + +ewol::OObject2DColored::~OObject2DColored(void) +{ + m_coord.Clear(); + m_coordColor.Clear(); +} + void ewol::OObject2DColored::Draw(void) { @@ -55,49 +68,6 @@ void ewol::OObject2DColored::Draw(void) } - -void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h, float red, float green, float blue, float alpha) -{ - //EWOL_DEBUG("Add rectangle : ..."); - coord2D_ts point; - color_ts color; - - color.red = red; - color.green = green; - color.blue = blue; - color.alpha = alpha; - - point.x = x; - point.y = y + h; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - point.x = x; - point.y = y; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - point.x = x + w; - point.y = y; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - point.x = x + w; - point.y = y + h; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - point.x = x; - point.y = y + h; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - -} - - void ewol::OObject2DColored::UpdateOrigin(float x, float y) { for (int32_t iii=0; iii 2*M_PI) { + teta -= 2*M_PI; + } + //EWOL_DEBUG("teta = " << (teta*180/(M_PI)) << " deg." ); + double offsety = sin(teta-M_PI/2) * (thickness/2); + double offsetx = cos(teta-M_PI/2) * (thickness/2); + // just for debug ... + /*if (offsetx <= 0.001 && offsetx >= -0.001) { + offsetx = 0; + } + if (offsety <= 0.001 && offsety >= -0.001) { + offsety = 0; + } + EWOL_DEBUG("ofset (" << offsetx << "," << offsety << ")"); + */ + coord2D_ts point; + + point.x = sx - offsetx; + point.y = sy - offsety; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + point.x = sx + offsetx; + point.y = sy + offsety; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + point.x = ex + offsetx; + point.y = ey + offsety; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + point.x = ex - offsetx; + point.y = ey - offsety; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + point.x = sx - offsetx; + point.y = sy - offsety; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); +} + + +void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h) +{ + coord2D_ts point; + + point.x = x; + point.y = y + h; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + point.x = x; + point.y = y; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + point.x = x + w; + point.y = y; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + point.x = x + w; + point.y = y + h; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); + + point.x = x; + point.y = y + h; + m_coord.PushBack(point); + m_coordColor.PushBack(m_Color); +} + + +void ewol::OObject2DColored::Circle(float x, float y, float radius, float thickness) +{ + +} + +void ewol::OObject2DColored::Disc(float x, float y, float radius) +{ + coord2D_ts point; + if (radius<0) { + radius *= -1; + } + int32_t nbOcurence = radius*5; + + for (int32_t iii=0; iii m_coord; //!< internal coord of the object etk::VectorType m_coordColor; //!< internal color of the different point //etk::VectorType m_linkCoord; //!< internal link between point to generate triangle + color_ts m_Color; public: - void Rectangle(float x, float y, float w, float h, float red, float green, float blue, float alpha); + void SetColor(float red, float green, float blue, float alpha = 1.0); + void SetColor(color_ts color); + void Line(float sx, float sy, float ex, float ey, float thickness); + void Rectangle(float x, float y, float w, float h); + void Circle(float x, float y, float radius, float thickness); + void Disc(float x, float y, float radius); public: + // Ewol internal ... : done to update at the origin of the widget ... virtual void UpdateOrigin(float x, float y); }; }; diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp index 0f23a466..5c658226 100644 --- a/Sources/ewolWindows.cpp +++ b/Sources/ewolWindows.cpp @@ -53,9 +53,15 @@ ewol::Windows::Windows(void) SetDecorationDisable(); if (true == m_hasDecoration) { ewol::OObject2DColored * myOObject = new ewol::OObject2DColored(); - myOObject->Rectangle( 0, 0, 20, 20, 1.0, 0.0, 0.0, 1.0); // Close - myOObject->Rectangle(20, 0, 20, 20, 0.0, 1.0, 0.0, 1.0); // Reduce - myOObject->Rectangle(40, 0, 20, 20, 0.0, 0.0, 1.0, 1.0); // Expend - Un-expend + // Close + myOObject->SetColor(1.0, 0.0, 0.0, 1.0); + myOObject->Rectangle( 0, 0, 20, 20); + // Reduce + myOObject->SetColor(0.0, 1.0, 0.0, 1.0); + myOObject->Rectangle(20, 0, 20, 20); + // Expend - Un-expend + myOObject->SetColor(0.0, 0.0, 1.0, 1.0); + myOObject->Rectangle(40, 0, 20, 20); coord origin; coord size; origin.x = 0.0; diff --git a/Sources/widget/ewolButton.cpp b/Sources/widget/ewolButton.cpp index f0ed91a1..0b2eaa93 100644 --- a/Sources/widget/ewolButton.cpp +++ b/Sources/widget/ewolButton.cpp @@ -85,8 +85,10 @@ void ewol::Button::OnRegenerateDisplay(void) ClearOObjectList(); ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored; - tmpOObjects->Rectangle( 2, 2, m_size.x-4, m_size.y-4, 0.0, 0.0, 0.0, 1.0); - tmpOObjects->Rectangle( 3, 3, m_size.x-6, m_size.y-6, 1.0, 1.0, 1.0, 1.0); + tmpOObjects->SetColor(0.0, 0.0, 0.0, 1.0); + tmpOObjects->Rectangle( 2, 2, m_size.x-4, m_size.y-4); + tmpOObjects->SetColor(1.0, 1.0, 1.0, 1.0); + tmpOObjects->Rectangle( 3, 3, m_size.x-6, m_size.y-6); AddOObject(tmpOObjects, "BouttonDecoration"); color_ts textColorFg; diff --git a/Sources/widget/ewolTest.cpp b/Sources/widget/ewolTest.cpp index 28ac5bb8..9b74d395 100644 --- a/Sources/widget/ewolTest.cpp +++ b/Sources/widget/ewolTest.cpp @@ -28,7 +28,7 @@ -//const char * ewolEventButtonPressed = "ewol Button Pressed"; +const char * ewolEventTestPressed = "ewol Test Pressed"; @@ -37,7 +37,7 @@ ewol::Test::Test(void) { - + m_elementID = 0; } @@ -59,8 +59,57 @@ void ewol::Test::OnRegenerateDisplay(void) ClearOObjectList(); ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored; - tmpOObjects->Rectangle( 0, 0, m_size.x, m_size.y, 1.0, 0.0, 0.0, 1.0); - tmpOObjects->Rectangle( 3, 3, m_size.x-6, m_size.y-6, 1.0, 1.0, 1.0, 1.0); + tmpOObjects->SetColor(1.0, 0.0, 0.0, 1.0); + tmpOObjects->Rectangle( 0, 0, m_size.x, m_size.y); + tmpOObjects->SetColor(1.0, 1.0, 1.0, 1.0); + tmpOObjects->Rectangle( 3, 3, m_size.x-6, m_size.y-6); + + tmpOObjects->SetColor(0.0, 0.0, 1.0, 1.0); + + if (0 == m_elementID) { + tmpOObjects->Line(50, 50, 100, 50, 10); // 0° + } else if (1 == m_elementID) { + tmpOObjects->Line(50, 50, 100, 100, 15); // 45° + } else if (2 == m_elementID) { + tmpOObjects->Line(50, 50, 50, 100, 20); // 90° + } else if (3 == m_elementID) { + tmpOObjects->Line(50, 50, 0, 100, 5); // 135° + } else if (4 == m_elementID) { + tmpOObjects->Line(50, 50, 0, 50, 3); // 180° + } else if (5 == m_elementID) { + tmpOObjects->Line(50, 50, 0, 0, 2); // 225° + } else if (6 == m_elementID) { + tmpOObjects->Line(50, 50, 50, 0, 1); // ° + } else { + tmpOObjects->Line(50, 50, 100, 0, 0.5); // ° + } + + if (0 == m_elementID) { + tmpOObjects->SetColor(0.0, 1.0, 0.0, 1.0); + tmpOObjects->Disc(200, 100, 5); + } else if (1 == m_elementID) { + tmpOObjects->SetColor(0.0, 1.0, 0.0, 1.0); + tmpOObjects->Disc(200, 100, 10); + } else if (2 == m_elementID) { + tmpOObjects->SetColor(0.0, 1.0, 0.0, 1.0); + tmpOObjects->Disc(200, 100, 15); + } else if (3 == m_elementID) { + tmpOObjects->SetColor(0.0, 1.0, 0.0, 1.0); + tmpOObjects->Disc(200, 100, 20); + } else if (4 == m_elementID) { + tmpOObjects->SetColor(0.0, 1.0, 0.0, 1.0); + tmpOObjects->Disc(200, 100, 25); + } else if (5 == m_elementID) { + tmpOObjects->SetColor(0.0, 1.0, 0.0, 0.75); + tmpOObjects->Disc(200, 100, 100); + } else if (6 == m_elementID) { + tmpOObjects->SetColor(0.0, 1.0, 0.0, 0.75); + tmpOObjects->Disc(200, 100, 200); + } else { + tmpOObjects->SetColor(0.0, 1.0, 0.0, 0.5); + tmpOObjects->Disc(200, 100, 300); + } + AddOObject(tmpOObjects, "BouttonDecoration"); color_ts textColorFg; @@ -69,9 +118,7 @@ void ewol::Test::OnRegenerateDisplay(void) textColorFg.blue = 0.0; textColorFg.alpha = 1.0; - // Regenerate the event Area: - /* EventAreaRemoveAll(); coord origin; coord size; @@ -79,19 +126,20 @@ void ewol::Test::OnRegenerateDisplay(void) origin.y = 3.0; size.x = m_size.x-6; size.y = m_size.y-6; - AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventButtonPressed); - */ + AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventTestPressed); } bool ewol::Test::OnEventArea(const char * generateEventId, double x, double y) { bool eventIsOK = false; -/* //EWOL_DEBUG("Receive event : \"" << generateEventId << "\""); - if(ewolEventButtonPressed == generateEventId) { - EWOL_INFO("BT pressed ... " << m_label); + if(ewolEventTestPressed == generateEventId) { + m_elementID++; + if (m_elementID > 7 ) { + m_elementID = 0; + } + OnRegenerateDisplay(); eventIsOK = true; } -*/ return eventIsOK; } diff --git a/Sources/widget/ewolTest.h b/Sources/widget/ewolTest.h index 0b0e9f23..3161ff8e 100644 --- a/Sources/widget/ewolTest.h +++ b/Sources/widget/ewolTest.h @@ -40,6 +40,8 @@ namespace ewol { virtual void OnRegenerateDisplay(void); public: virtual bool OnEventArea(const char * generateEventId, double x, double y); + private: + int32_t m_elementID; }; };