Add drawing part of circle and change button display

This commit is contained in:
Edouard Dupin 2011-11-13 14:36:26 +01:00
parent 1aa8310c45
commit 4a4c8fcbac
8 changed files with 151 additions and 20 deletions

View File

@ -60,7 +60,7 @@ class Plop :public ewol::Windows
ewol::Test * myTest = new ewol::Test();
mySizerVert->SubWidgetAdd(myTest);
myButton = new ewol::Button(" 4 4 BT");
myButton = new ewol::Button("4 4 BT");
//myButton->SetExpendY(true);
mySizerVert->SubWidgetAdd(myButton);

View File

@ -488,6 +488,51 @@ void ewol::OObject2DColored::Circle(etkFloat_t x, etkFloat_t y, etkFloat_t radiu
}
}
void ewol::OObject2DColored::CirclePart(etkFloat_t x, etkFloat_t y, etkFloat_t radius, etkFloat_t thickness, etkFloat_t angleStart, etkFloat_t angleStop)
{
ResetCount();
if (radius<0) {
radius *= -1;
}
if (radius < thickness/2) {
Disc(x, y, thickness/2 + radius);
}
angleStart -= 90;
angleStop -= 90;
etkFloat_t AStart = angleStart * (M_PI)/180;
etkFloat_t AStop = angleStop * (M_PI)/180;
etkFloat_t angleLinear = (angleStop-angleStart)* (M_PI)/180;
int32_t nbOcurence = radius;
if (nbOcurence < 10)
{
nbOcurence = 10;
}
for (int32_t iii=0; iii<nbOcurence; iii++) {
etkFloat_t angleOne = AStart + (angleLinear* iii / nbOcurence) ;
etkFloat_t offsetExty = sin(angleOne) * (radius+thickness/2);
etkFloat_t offsetExtx = cos(angleOne) * (radius+thickness/2);
etkFloat_t offsetInty = sin(angleOne) * (radius-thickness/2);
etkFloat_t offsetIntx = cos(angleOne) * (radius-thickness/2);
etkFloat_t angleTwo = AStart + (angleLinear* (iii+1) / nbOcurence );
etkFloat_t offsetExt2y = sin(angleTwo) * (radius+thickness/2);
etkFloat_t offsetExt2x = cos(angleTwo) * (radius+thickness/2);
etkFloat_t offsetInt2y = sin(angleTwo) * (radius-thickness/2);
etkFloat_t offsetInt2x = cos(angleTwo) * (radius-thickness/2);
SetPoint(x + offsetIntx, y + offsetInty);
SetPoint(x + offsetExtx, y + offsetExty);
SetPoint(x + offsetExt2x, y + offsetExt2y);
SetPoint(x + offsetExt2x, y + offsetExt2y);
SetPoint(x + offsetInt2x, y + offsetInt2y);
SetPoint(x + offsetIntx, y + offsetInty);
}
}
void ewol::OObject2DColored::Disc(etkFloat_t x, etkFloat_t y, etkFloat_t radius)
{
ResetCount();
@ -517,4 +562,39 @@ void ewol::OObject2DColored::Disc(etkFloat_t x, etkFloat_t y, etkFloat_t radius)
}
}
void ewol::OObject2DColored::DiscPart(etkFloat_t x, etkFloat_t y, etkFloat_t radius, etkFloat_t angleStart, etkFloat_t angleStop)
{
ResetCount();
if (radius<0) {
radius *= -1;
}
angleStart -= 90;
angleStop -= 90;
etkFloat_t AStart = angleStart * (M_PI)/180;
etkFloat_t AStop = angleStop * (M_PI)/180;
etkFloat_t angleLinear = (angleStop-angleStart)* (M_PI)/180;
//EWOL_DEBUG("Write a part of disk " << angleStart << " -> " << angleStop << " ocurence=" << (angleLinear*180/(M_PI)) );
int32_t nbOcurence = radius*0.50;
if (nbOcurence < 15)
{
nbOcurence = 15;
}
for (int32_t iii=0; iii<nbOcurence; iii++) {
SetPoint(x, y);
etkFloat_t angleOne = AStart + (angleLinear* iii / nbOcurence) ;
etkFloat_t offsety = sin(angleOne) * radius;
etkFloat_t offsetx = cos(angleOne) * radius;
SetPoint(x + offsetx, y + offsety);
etkFloat_t angleTwo = AStart + (angleLinear* (iii+1) / nbOcurence) ;
offsety = sin(angleTwo) * radius;
offsetx = cos(angleTwo) * radius;
SetPoint(x + offsetx, y + offsety);
}
}

View File

@ -55,9 +55,9 @@ namespace ewol {
//void RectangleBorder(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t thickness);
//void RectangleBorder(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t thickness, etkFloat_t angle);
void Circle(etkFloat_t x, etkFloat_t y, etkFloat_t radius, etkFloat_t thickness);
//void CirclePart(etkFloat_t x, etkFloat_t y, etkFloat_t radius, etkFloat_t thickness, etkFloat_t angleStart, etkFloat_t angleStop);
void CirclePart(etkFloat_t x, etkFloat_t y, etkFloat_t radius, etkFloat_t thickness, etkFloat_t angleStart, etkFloat_t angleStop);
void Disc(etkFloat_t x, etkFloat_t y, etkFloat_t radius);
//void DiscPart(etkFloat_t x, etkFloat_t y, etkFloat_t radius, etkFloat_t angleStart, etkFloat_t angleStop);
void DiscPart(etkFloat_t x, etkFloat_t y, etkFloat_t radius, etkFloat_t angleStart, etkFloat_t angleStop);
public:
// Ewol internal ... : done to update at the origin of the widget ...
virtual void UpdateSize(etkFloat_t sizeX, etkFloat_t sizeY);

View File

@ -38,8 +38,10 @@ ewol::Widget::Widget(void)
// user settings :
m_userMinSize.x = -1.0;
m_userMinSize.y = -1.0;
m_userExpendX = false;
m_userExpendY = false;
SetExpendX();
SetExpendY();
SetFillX();
SetFillY();
m_genericDraw = true;
m_specificDraw = false;
}

View File

@ -85,7 +85,7 @@ namespace ewol {
FLAG_EVENT_INPUT_MOTION = 1 << 20,
FLAG_EVENT_INPUT_ENTER = 1 << 21,
FLAG_EVENT_INPUT_LEAVE = 1 << 21,
FLAG_EVENT_INPUT_LEAVE = 1 << 22,
FLAG_EVENT_INPUT_DOWN = 1 << 23,
FLAG_EVENT_INPUT_UP = 1 << 24,
FLAG_EVENT_INPUT_CLICKED = 1 << 25,
@ -154,6 +154,8 @@ namespace ewol {
coord m_userMinSize; //!< user define the minimum size of the widget
bool m_userExpendX;
bool m_userExpendY;
bool m_userFillX;
bool m_userFillY;
public:
void SetOrigin(etkFloat_t x, etkFloat_t y) { m_origin.x=x; m_origin.y=y; };
coord GetOrigin(void) { return m_origin; };
@ -168,6 +170,10 @@ namespace ewol {
bool CanExpentX(void) { return m_userExpendX; };
virtual void SetExpendY(bool newExpend=false) { m_userExpendY = newExpend; };
bool CanExpentY(void) { return m_userExpendY; };
virtual void SetFillX(bool newFill=false) { m_userFillX = newFill; };
bool CanFillX(void) { return m_userFillX; };
virtual void SetFillY(bool newFill=false) { m_userFillY = newFill; };
bool CanFillY(void) { return m_userFillY; };
// ----------------------------------------------------------------------------------------------------------------
// -- Focus Area

View File

@ -29,20 +29,38 @@
const char * ewolEventButtonPressed = "ewol Button Pressed";
const char * ewolEventButtonEnter = "ewol Button Enter";
const char * ewolEventButtonLeave = "ewol Button Leave";
#undef __class__
#define __class__ "ewol::Button"
void ewol::Button::Init(void)
{
m_textColorFg.red = 0.0;
m_textColorFg.green = 0.0;
m_textColorFg.blue = 0.0;
m_textColorFg.alpha = 1.0;
m_textColorBg.red = 0.0;
m_textColorBg.green = 0.0;
m_textColorBg.blue = 0.0;
m_textColorBg.alpha = 0.25;
}
ewol::Button::Button(void)
{
m_label = "No Label";
Init();
}
ewol::Button::Button(etk::String newLabel)
{
m_label = newLabel;
Init();
}
@ -53,7 +71,6 @@ ewol::Button::~Button(void)
bool ewol::Button::CalculateMinSize(void)
{
//SetMinSise(55, 24);
int32_t fontId = GetDefaultFontId();
int32_t minWidth = ewol::GetWidth(fontId, m_label.c_str());
int32_t minHeight = ewol::GetHeight(fontId);
@ -84,6 +101,9 @@ void ewol::Button::OnRegenerateDisplay(void)
// clean the object list ...
ClearOObjectList();
/*
ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored;
tmpOObjects->SetColor(0.0, 0.0, 0.0, 1.0);
tmpOObjects->Rectangle( 2, 2, m_size.x-4, m_size.y-4);
@ -91,24 +111,37 @@ void ewol::Button::OnRegenerateDisplay(void)
tmpOObjects->Rectangle( 3, 3, m_size.x-6, m_size.y-6);
AddOObject(tmpOObjects, "BouttonDecoration");
color_ts textColorFg;
textColorFg.red = 0.0;
textColorFg.green = 0.0;
textColorFg.blue = 0.0;
textColorFg.alpha = 1.0;
ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, textColorFg);
*/
ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, m_textColorFg);
int32_t fontId = GetDefaultFontId();
int32_t fontHeight = ewol::GetHeight(fontId);
int32_t fontWidth = ewol::GetWidth(fontId, m_label.c_str());
int32_t posy = (m_size.y - fontHeight - 6)/2 + 3;
int32_t posx = (m_size.x - fontWidth - 6)/2 + 3;
tmpText->Text(posx, posy, m_label.c_str());
tmpText->Text(posx+2, posy+3, m_label.c_str());
ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored;
int32_t radius = fontHeight / 2;
tmpOObjects->SetColor(m_textColorBg);
tmpOObjects->Rectangle( ((m_size.x-fontWidth-10)/2)+radius, posy, fontWidth-radius, radius*2);
tmpOObjects->SetColor(m_textColorFg);
EWOL_DEBUG("m_textColorFg=(" << m_textColorFg.red << " " << m_textColorFg.green << " " << m_textColorFg.blue << " " << m_textColorFg.alpha << ")" );
tmpOObjects->Line( ((m_size.x-fontWidth-10)/2)+radius, posy, ((m_size.x-fontWidth-10)/2)+fontWidth, posy, 1);
tmpOObjects->Line( ((m_size.x-fontWidth-10)/2)+radius, posy+fontHeight, ((m_size.x-fontWidth-10)/2)+fontWidth, posy+fontHeight, 1);
posy += fontHeight/2;
tmpOObjects->SetColor(m_textColorBg);
tmpOObjects->DiscPart(((m_size.x-fontWidth-10)/2)+radius, posy, radius, 180, 360);
tmpOObjects->SetColor(m_textColorFg);
tmpOObjects->CirclePart(((m_size.x-fontWidth-10)/2)+radius, posy, radius, 1, 180, 360);
tmpOObjects->SetColor(m_textColorBg);
tmpOObjects->DiscPart(((m_size.x-fontWidth-10)/2)+fontWidth, posy, radius, 0, 180);
tmpOObjects->SetColor(m_textColorFg);
tmpOObjects->CirclePart(((m_size.x-fontWidth-10)/2)+fontWidth, posy, radius, 1, 0, 180);
AddOObject(tmpOObjects, "BouttonDecoration");
AddOObject(tmpText, "BouttonText");
// Regenerate the event Area:
EventAreaRemoveAll();
coord origin;
@ -118,6 +151,9 @@ void ewol::Button::OnRegenerateDisplay(void)
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_ENTER, ewolEventButtonEnter);
AddEventArea(origin, size, FLAG_EVENT_INPUT_LEAVE, ewolEventButtonLeave);
}
/*
@ -135,7 +171,8 @@ bool ewol::Button::OnEventArea(const char * generateEventId, etkFloat_t x, etkFl
if(ewolEventButtonPressed == generateEventId) {
EWOL_INFO("BT pressed ... " << m_label);
eventIsOK = true;
} else if(ewolEventButtonEnter == generateEventId) {
OnRegenerateDisplay();
}
return eventIsOK;
}

View File

@ -35,6 +35,7 @@ namespace ewol {
public:
Button(void);
Button(etk::String newLabel);
void Init(void);
virtual ~Button(void);
virtual bool CalculateMinSize(void);
void SetLabel(etk::String newLabel);
@ -46,6 +47,8 @@ namespace ewol {
bool GetValue(void);
private:
etk::String m_label;
color_ts m_textColorFg; //!< Text color
color_ts m_textColorBg; //!< Background color
public:
virtual void OnRegenerateDisplay(void);
public:

View File

@ -127,7 +127,10 @@ void ewol::Test::OnRegenerateDisplay(void)
} else {
tmpOObjects->Circle(100, 100, 100, 50);
}
tmpOObjects->SetColor(1.0, 1.0, 0.0, 1.0);
tmpOObjects->DiscPart(150, 60, 60, 45, 180);
tmpOObjects->SetColor(0.0, 0.0, 0.0, 1.0);
tmpOObjects->CirclePart(150, 60, 60, 2, 45, 180);
AddOObject(tmpOObjects, "BouttonDecoration");