Draw : draw simple element: line and disc
This commit is contained in:
parent
172c5d31ec
commit
76ceb4a67d
@ -24,12 +24,25 @@
|
||||
|
||||
#include <ewolOObject2DColored.h>
|
||||
#include <GL/gl.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#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<m_coord.Size(); iii++) {
|
||||
@ -106,3 +76,150 @@ void ewol::OObject2DColored::UpdateOrigin(float x, float y)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ewol::OObject2DColored::SetColor( float red, float green, float blue, float alpha)
|
||||
{
|
||||
m_Color.red = red;
|
||||
m_Color.green = green;
|
||||
m_Color.blue = blue;
|
||||
m_Color.alpha = alpha;
|
||||
}
|
||||
|
||||
|
||||
void ewol::OObject2DColored::Line(float sx, float sy, float ex, float ey, float thickness)
|
||||
{
|
||||
if (sx == ex && sy == ey) {
|
||||
EWOL_WARNING("Try to draw an line width 0");
|
||||
return;
|
||||
}
|
||||
//teta = tan-1(oposer/adjacent)
|
||||
double teta = 0;
|
||||
if (sx <= ex) {
|
||||
teta = atan((ey-sy)/(ex-sx));
|
||||
} else {
|
||||
teta = M_PI + atan((ey-sy)/(ex-sx));
|
||||
}
|
||||
if (teta < 0) {
|
||||
teta += 2*M_PI;
|
||||
} else if (teta > 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<nbOcurence; iii++) {
|
||||
point.x = x;
|
||||
point.y = y;
|
||||
m_coord.PushBack(point);
|
||||
m_coordColor.PushBack(m_Color);
|
||||
|
||||
double angleOne = 2*M_PI* iii / nbOcurence ;
|
||||
double offsety = sin(angleOne) * radius;
|
||||
double offsetx = cos(angleOne) * radius;
|
||||
|
||||
point.x = x + offsetx;
|
||||
point.y = y + offsety;
|
||||
m_coord.PushBack(point);
|
||||
m_coordColor.PushBack(m_Color);
|
||||
|
||||
double angleTwo = 2*M_PI* (iii+1) / nbOcurence ;
|
||||
offsety = sin(angleTwo) * radius;
|
||||
offsetx = cos(angleTwo) * radius;
|
||||
|
||||
point.x = x + offsetx;
|
||||
point.y = y + offsety;
|
||||
m_coord.PushBack(point);
|
||||
m_coordColor.PushBack(m_Color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,17 +31,24 @@ namespace ewol {
|
||||
class OObject2DColored :public ewol::OObject
|
||||
{
|
||||
public:
|
||||
OObject2DColored(void) {};
|
||||
virtual ~OObject2DColored(void) {};
|
||||
OObject2DColored(void);
|
||||
virtual ~OObject2DColored(void);
|
||||
public:
|
||||
virtual void Draw(void);
|
||||
protected:
|
||||
etk::VectorType<coord2D_ts> m_coord; //!< internal coord of the object
|
||||
etk::VectorType<color_ts> m_coordColor; //!< internal color of the different point
|
||||
//etk::VectorType<linkCoord_ts> 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);
|
||||
};
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user