diff --git a/Sources/Main.cpp b/Sources/Main.cpp index d7c3fde0..2414b7cc 100644 --- a/Sources/Main.cpp +++ b/Sources/Main.cpp @@ -53,10 +53,10 @@ class Plop :public ewol::Windows myButton = new ewol::Button("BT 3"); myButton->SetExpendX(true); - myButton->SetExpendY(true); + //myButton->SetExpendY(true); mySizerVert->SubWidgetAdd(myButton); myButton = new ewol::Button(" 4 4 BT"); - myButton->SetExpendY(true); + //myButton->SetExpendY(true); mySizerVert->SubWidgetAdd(myButton); myButton = new ewol::Button("Exemple 2"); diff --git a/Sources/ewolWidget.cpp b/Sources/ewolWidget.cpp index e25a6470..da8be44e 100644 --- a/Sources/ewolWidget.cpp +++ b/Sources/ewolWidget.cpp @@ -143,7 +143,8 @@ bool ewol::Widget::AddEventArea(coord origin, coord size, uint64_t flags, const newEvent.generateEventId = generateEventId; newEvent.widgetCall = -1; // by default no widget is called newEvent.mode = EWOL_EVENT_AREA; - newEvent.area.origin = origin; + newEvent.area.origin.x = origin.x + m_origin.x; + newEvent.area.origin.y = origin.y + m_origin.y; newEvent.area.size = size; newEvent.area.flags = flags; m_inputEvent.PushBack(newEvent); @@ -179,7 +180,7 @@ void ewol::Widget::AddOObject(ewol::OObject* newObject, etk::String name) return; } newObject->SetName(name); - EWOL_INFO("UPDATE AT origin : (" << m_origin.x << "," << m_origin.y << ")"); + //EWOL_INFO("UPDATE AT origin : (" << m_origin.x << "," << m_origin.y << ")"); newObject->UpdateOrigin(m_origin.x, m_origin.y); m_listOObject.PushBack(newObject); } diff --git a/Sources/ewolWidget.h b/Sources/ewolWidget.h index 1256f02d..f374d8b1 100644 --- a/Sources/ewolWidget.h +++ b/Sources/ewolWidget.h @@ -156,6 +156,7 @@ namespace ewol { bool m_userExpendY; public: void SetOrigin(double x, double y) { m_origin.x=x; m_origin.y=y; }; + coord GetOrigin(void) { return m_origin; }; virtual bool CalculateSize(double availlableX, double availlableY); // this generate the current size ... virtual bool CalculateMinSize(void) {m_minSize.x = m_userMinSize.x; m_minSize.y = m_userMinSize.y; return true; }; //update the min Size ... and the expend parameters for the sizer virtual void SetMinSise(double x=-1, double y=-1) { m_userMinSize.x = x; m_userMinSize.y = y; }; @@ -217,6 +218,7 @@ namespace ewol { bool GenEventInput(int32_t IdInput, eventInputType_te typeEvent, double X, double Y); // call when input event arrive and call OnEventInput, if no event detected bool GenEventShortCut(bool shift, bool control, bool alt, bool pomme, char UTF8_data[UTF8_MAX_SIZE]); protected: + void EventAreaRemoveAll(void) { m_inputEvent.Clear(); }; bool AddEventArea(coord origin, coord size, uint64_t flags, const char * generateEventId); bool AddEventShortCut(bool shift, bool control, bool alt, bool pomme, char UTF8_data[UTF8_MAX_SIZE], const char * generateEventId); bool AddEventShortCut(char * descriptiveString, const char * generateEventId); diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp index 4039f08e..cfa08a38 100644 --- a/Sources/ewolWindows.cpp +++ b/Sources/ewolWindows.cpp @@ -122,6 +122,9 @@ bool ewol::Windows::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, d } } } + if (NULL != m_subWidget) { + m_subWidget->GenEventInput(IdInput, typeEvent, x, y); + } return true; } @@ -181,27 +184,6 @@ bool ewol::Windows::OnDraw(void) if (NULL != m_subWidget) { m_subWidget->GenDraw(); } - /* - // Test AREA : - ewol::OObject2DColored tmpOObjects; - tmpOObjects.Rectangle( 50, 50, 200, 300, 1.0, 0.0, 0.0, 1.0); - tmpOObjects.Draw(); - - glColor4f(0.0, 0.0, 0.0, 1.0); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, 1); - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex3f(50.0, 50.0, 0.0); - glTexCoord2f(1.0, 0.0); - glVertex3f(250.0, 50.0, 0.0); - glTexCoord2f(1.0, 1.0); - glVertex3f(250.0, 350.0, 0.0); - glTexCoord2f(0.0, 1.0); - glVertex3f(50.0, 350.0, 0.0); - glEnd(); - glDisable(GL_TEXTURE_2D); - */ return true; } @@ -220,6 +202,7 @@ bool ewol::Windows::OnEventArea(const char * generateEventId, double x, double y EWOL_INFO("Request Expend of the windows"); eventIsOK = true; } + return eventIsOK; } diff --git a/Sources/ewolWindows.h b/Sources/ewolWindows.h index 4a3529d2..ab8d91b5 100644 --- a/Sources/ewolWindows.h +++ b/Sources/ewolWindows.h @@ -55,7 +55,7 @@ namespace ewol { virtual bool OnEventArea(const char * generateEventId, double x, double y); // Widget overwrite function public: - virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, double X, double Y); + virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, double x, double y); private: bool m_hasDecoration; public: diff --git a/Sources/widget/ewolButton.cpp b/Sources/widget/ewolButton.cpp index 860d079c..b593f248 100644 --- a/Sources/widget/ewolButton.cpp +++ b/Sources/widget/ewolButton.cpp @@ -26,6 +26,12 @@ #include + + +const char * ewolEventButtonPressed = "ewol Button Pressed"; + + + #undef __class__ #define __class__ "ewol::Button" @@ -91,8 +97,41 @@ void ewol::Button::OnRegenerateDisplay(void) int32_t fontId = GetDefaultFontId(); int32_t fontHeight = ewol::GetHeight(fontId); - int32_t pos = (m_size.y - fontHeight)/2; - ewol::OObject2DText * tmpText = new ewol::OObject2DText(5, pos, "", -1, FONT_MODE_BOLD, textColorFg, m_label.c_str()); + 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; + ewol::OObject2DText * tmpText = new ewol::OObject2DText(posx, posy, "", -1, FONT_MODE_BOLD, textColorFg, m_label.c_str()); AddOObject(tmpText, "BouttonText"); + + + // Regenerate the event Area: + EventAreaRemoveAll(); + coord origin; + coord size; + origin.x = 3.0; + 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); +} + +/* +bool ewol::Button::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, double x, double y) +{ + EWOL_DEBUG("Event on BT ..."); + return true; +} +*/ + +bool ewol::Button::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); + eventIsOK = true; + } + + return eventIsOK; } diff --git a/Sources/widget/ewolButton.h b/Sources/widget/ewolButton.h index 5c82ee1a..c88addfe 100644 --- a/Sources/widget/ewolButton.h +++ b/Sources/widget/ewolButton.h @@ -48,6 +48,9 @@ namespace ewol { etk::String m_label; public: virtual void OnRegenerateDisplay(void); + public: + //virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, double x, double y); + virtual bool OnEventArea(const char * generateEventId, double x, double y); }; }; diff --git a/Sources/widget/ewolSizerHori.cpp b/Sources/widget/ewolSizerHori.cpp index 6840eb08..4e2e3af8 100644 --- a/Sources/widget/ewolSizerHori.cpp +++ b/Sources/widget/ewolSizerHori.cpp @@ -213,3 +213,20 @@ void ewol::SizerHori::OnRegenerateDisplay(void) } +bool ewol::SizerHori::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, double x, double y) +{ + for (int32_t iii=0; iiiGetSize(); + coord tmpOrigin = m_subWidget[iii]->GetOrigin(); + if( (tmpOrigin.x <= x && tmpOrigin.x + tmpSize.x >= x) + && (tmpOrigin.y <= y && tmpOrigin.y + tmpSize.y >= y) ) + { + return m_subWidget[iii]->GenEventInput(IdInput, typeEvent, x, y); + } + } + } + return true; +} + + diff --git a/Sources/widget/ewolSizerHori.h b/Sources/widget/ewolSizerHori.h index 5aad7362..25136be2 100644 --- a/Sources/widget/ewolSizerHori.h +++ b/Sources/widget/ewolSizerHori.h @@ -52,6 +52,8 @@ namespace ewol { virtual bool OnDraw(void); public: virtual void OnRegenerateDisplay(void); + public: + virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, double x, double y); }; }; diff --git a/Sources/widget/ewolSizerVert.cpp b/Sources/widget/ewolSizerVert.cpp index 9ae87538..386e4de8 100644 --- a/Sources/widget/ewolSizerVert.cpp +++ b/Sources/widget/ewolSizerVert.cpp @@ -212,3 +212,19 @@ void ewol::SizerVert::OnRegenerateDisplay(void) } +bool ewol::SizerVert::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, double x, double y) +{ + for (int32_t iii=0; iiiGetSize(); + coord tmpOrigin = m_subWidget[iii]->GetOrigin(); + if( (tmpOrigin.x <= x && tmpOrigin.x + tmpSize.x >= x) + && (tmpOrigin.y <= y && tmpOrigin.y + tmpSize.y >= y) ) + { + return m_subWidget[iii]->GenEventInput(IdInput, typeEvent, x, y); + } + } + } + return true; +} + diff --git a/Sources/widget/ewolSizerVert.h b/Sources/widget/ewolSizerVert.h index a37ce283..3b150a29 100644 --- a/Sources/widget/ewolSizerVert.h +++ b/Sources/widget/ewolSizerVert.h @@ -52,6 +52,8 @@ namespace ewol { virtual bool OnDraw(void); public: virtual void OnRegenerateDisplay(void); + public: + virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, double x, double y); }; };