From 922e9cf4859a1bd4266bf6af8a001e766d885084 Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Tue, 1 Nov 2011 15:47:17 +0100 Subject: [PATCH] X11: change position and resize OK... --- Sources/base/guiX11.cpp | 163 ++++++++++++++++++++++++++++++++++++++-- Sources/base/guiX11.h | 4 + Sources/ewol.cpp | 36 +++++++++ Sources/ewol.h | 6 ++ Sources/ewolWindows.cpp | 49 +++--------- 5 files changed, 212 insertions(+), 46 deletions(-) diff --git a/Sources/base/guiX11.cpp b/Sources/base/guiX11.cpp index ac1c5572..d13b1b08 100644 --- a/Sources/base/guiX11.cpp +++ b/Sources/base/guiX11.cpp @@ -84,7 +84,7 @@ static int VisualData[] = { }; #endif - +#define NB_MAX_INPUT (20) #define SEPARATED_CLICK_TIME (30) namespace guiAbstraction { @@ -119,6 +119,10 @@ namespace guiAbstraction { #endif int32_t m_width; int32_t m_height; + int32_t m_originX; + int32_t m_originY; + int32_t m_cursorEventX; + int32_t m_cursorEventY; XVisualInfo * m_visual; bool m_doubleBuffered; bool m_run; @@ -374,6 +378,15 @@ namespace guiAbstraction { m_previous_y = -1; m_previousTime = 0; m_previousDouble = false; + m_resizeMode=false; + m_moveMode=false; + m_originX = 0; + m_originY = 0; + m_cursorEventX = 0; + m_cursorEventY = 0; + for (int32_t iii=0; iiiGenEventInput(btId, ewol::EVENT_INPUT_TYPE_UP, (double)event.xbutton.x, (double)event.xbutton.y); @@ -543,22 +584,42 @@ namespace guiAbstraction { } break; case EnterNotify: + m_resizeMode = false; + m_moveMode = false; //EWOL_DEBUG("X11 event : " << event.type << " = \"EnterNotify\" (" << (double)event.xcrossing.x << "," << (double)event.xcrossing.y << ")"); m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_ENTER, (double)event.xcrossing.x, (double)event.xcrossing.y); break; case MotionNotify: - //EWOL_DEBUG("X11 event : " << event.type << " = \"MotionNotify\" (" << (double)event.xmotion.x << "," << (double)event.xmotion.y << ")"); - m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_MOVE, (double)event.xmotion.x, (double)event.xmotion.y); + if (true == m_resizeMode) { + ChangeSize(m_cursorEventX, m_cursorEventY); + } else if (true == m_moveMode) { + int32_t tmpX, tmpY; + this->GetAbsPos(tmpX, tmpY); + //EWOL_DEBUG("Current absolute position : " << tmpX << "x" << tmpY); + int32_t newPosX = (m_startX - m_screenOffsetX) - (m_startX - tmpX); + int32_t newPosY = (m_startY - m_screenOffsetY) - (m_startY - tmpY); + //EWOL_DEBUG("Change POS : (" << (m_startY - m_screenOffsetX) << "," << (m_startY - m_screenOffsetY) << ") ==> (" << newPosX << "," << newPosY << ")"); + this->ChangePos(newPosX, newPosY); + } else { + //EWOL_DEBUG("X11 event : " << event.type << " = \"MotionNotify\" (" << (double)event.xmotion.x << "," << (double)event.xmotion.y << ")"); + m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_MOVE, (double)event.xmotion.x, (double)event.xmotion.y); + } break; case LeaveNotify: + m_resizeMode = false; + m_moveMode = false; //EWOL_DEBUG("X11 event : " << event.type << " = \"LeaveNotify\" (" << (double)event.xcrossing.x << "," << (double)event.xcrossing.y << ")"); m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_LEAVE, (double)event.xcrossing.x, (double)event.xcrossing.y); break; case FocusIn: + m_resizeMode = false; + m_moveMode = false; EWOL_DEBUG("X11 event : " << event.type << " = \"FocusIn\""); m_uniqueWindows->SetFocus(); break; case FocusOut: + m_resizeMode = false; + m_moveMode = false; EWOL_DEBUG("X11 event : " << event.type << " = \"FocusOut\""); m_uniqueWindows->RmFocus(); break; @@ -596,21 +657,72 @@ namespace guiAbstraction { Draw(); usleep( 100000 ); } - } + }; void Stop(void) { m_run = false; - } + }; void ChangeSize(int32_t w, int32_t h) { XResizeWindow(m_display, WindowHandle, w, h); - } + }; void ChangePos(int32_t x, int32_t y) { XMoveWindow(m_display, WindowHandle, x, y); + }; + + void GetAbsPos(int32_t & x, int32_t & y) + { + int tmp; + unsigned int tmp2; + Window fromroot, tmpwin; + XQueryPointer(m_display, WindowHandle, &fromroot, &tmpwin, &x, &y, &tmp, &tmp, &tmp2); + }; + + private: + bool m_resizeMode; + bool m_moveMode; + int32_t m_startX; + int32_t m_startY; + int32_t m_screenOffsetX; + int32_t m_screenOffsetY; + + public: + void StartResizeSystem(void) + { + EWOL_INFO("Start Resizing the windows"); + m_resizeMode = true; + this->GetAbsPos(m_startX, m_startY); + m_screenOffsetX = m_cursorEventX; + m_screenOffsetY = m_cursorEventY; + }; + public: + // TODO : need to Check all of this... to write a better code... if needed... + void StartMoveSystem(void) + { + EWOL_INFO("Start Moving the windows"); + m_moveMode=true; + this->GetAbsPos(m_startX, m_startY); + EWOL_DEBUG("ref pos : (" << m_startX << "," << m_startY << ") (" << m_cursorEventX << "," << m_cursorEventY << ")"); + m_screenOffsetX = m_cursorEventX; + m_screenOffsetY = m_cursorEventY; + }; + private: + bool inputIsPressed[20]; + public: + bool IsPressedInput(int32_t inputID) + { + if( NB_MAX_INPUT > inputID + && 0 <= inputID) + { + return inputIsPressed[inputID]; + } else { + EWOL_WARNING("Wrong input ID : " << inputID); + return false; + } } }; }; @@ -698,3 +810,40 @@ void guiAbstraction::ChangePos(int32_t x, int32_t y) } } +void guiAbstraction::GetAbsPos(int32_t & x, int32_t & y) +{ + if (true == guiAbstractionIsInit) { + myX11Access->GetAbsPos(x, y); + } else { + EWOL_CRITICAL("X11 ==> not init ... "); + } +} + +void guiAbstraction::StartResizeSystem(void) +{ + if (true == guiAbstractionIsInit) { + myX11Access->StartResizeSystem(); + } else { + EWOL_CRITICAL("X11 ==> not init ... "); + } +} + +void guiAbstraction::StartMoveSystem(void) +{ + if (true == guiAbstractionIsInit) { + myX11Access->StartMoveSystem(); + } else { + EWOL_CRITICAL("X11 ==> not init ... "); + } +} + +bool guiAbstraction::IsPressedInput(int32_t inputID) +{ + if (true == guiAbstractionIsInit) { + return myX11Access->IsPressedInput(inputID); + } else { + EWOL_CRITICAL("X11 ==> not init ... "); + return false; + } +} + diff --git a/Sources/base/guiX11.h b/Sources/base/guiX11.h index 7eaeedc0..698e06d1 100644 --- a/Sources/base/guiX11.h +++ b/Sources/base/guiX11.h @@ -38,6 +38,10 @@ namespace guiAbstraction void SetDisplayOnWindows(ewol::Windows * newOne); void ChangeSize(int32_t w, int32_t h); void ChangePos(int32_t x, int32_t y); + void GetAbsPos(int32_t & x, int32_t & y); + void StartResizeSystem(void); + void StartMoveSystem(void); + bool IsPressedInput(int32_t inputID); }; diff --git a/Sources/ewol.cpp b/Sources/ewol.cpp index 89c9fc5a..ccf2b289 100644 --- a/Sources/ewol.cpp +++ b/Sources/ewol.cpp @@ -76,3 +76,39 @@ void ewol::Stop(void) } +void ewol::ChangeSize(int32_t w, int32_t h) +{ + guiAbstraction::ChangeSize(w, h); +} + +void ewol::ChangePos(int32_t x, int32_t y) +{ + guiAbstraction::ChangePos(x, y); +} + +void ewol::GetAbsPos(int32_t & x, int32_t & y) +{ + guiAbstraction::GetAbsPos(x, y); +} + + +void ewol::StartResizeSystem(void) +{ +#if __PLATFORM__ == X11 + guiAbstraction::StartResizeSystem(); +#endif +} + +void ewol::StartMoveSystem(void) +{ +#if __PLATFORM__ == X11 + guiAbstraction::StartMoveSystem(); +#endif +} + + +bool ewol::IsPressedInput(int32_t inputID) +{ + return guiAbstraction::IsPressedInput(inputID); +} + diff --git a/Sources/ewol.h b/Sources/ewol.h index fde13e64..2b07ba44 100644 --- a/Sources/ewol.h +++ b/Sources/ewol.h @@ -37,6 +37,12 @@ namespace ewol { void Stop(void); void UnInit(void); void DisplayWindows(ewol::Windows * windows); + void ChangeSize(int32_t w, int32_t h); + void ChangePos(int32_t x, int32_t y); + void GetAbsPos(int32_t & x, int32_t & y); + void StartResizeSystem(void); + void StartMoveSystem(void); + bool IsPressedInput(int32_t inputID); }; diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp index b93002cf..0fb23936 100644 --- a/Sources/ewolWindows.cpp +++ b/Sources/ewolWindows.cpp @@ -30,23 +30,6 @@ #include #include #include - -#if __PLATFORM__ == X11 - #include "guiX11.h" -#elif __PLATFORM__ == DoubleBuffer - #include "guiDoubleBuffer.h" -#elif __PLATFORM__ == Android - #include "guiAndroid.h" -#elif __PLATFORM__ == AndroidTablet - #include "guiAndroidTablet.h" -#elif __PLATFORM__ == IPhone - #include "guiIPhone.h" -#elif __PLATFORM__ == IPad - #include "guiIPad.h" -#else - #error you need to specify a platform ... -#endif - #include @@ -98,28 +81,16 @@ bool ewol::Windows::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, d if( x >= 60 && y <=20) { - static int32_t test=0; - static int32_t lastX=x; - static int32_t lastY=x; - if( 1 == IdInput - && EVENT_INPUT_TYPE_DOWN == typeEvent) { - test = 1; - lastX=x; - lastY=y; - EWOL_DEBUG("EVENT DOWN ... "); - } else if( 1 == IdInput - && EVENT_INPUT_TYPE_UP == typeEvent) { - test = 0; - EWOL_DEBUG("EVENT UP ... "); - } else if(EVENT_INPUT_TYPE_MOVE == typeEvent) { - EWOL_DEBUG("EVENT MOVE ... "); - if (test==1) { - EWOL_DEBUG("change POS ... "); - guiAbstraction::ChangePos(m_origin.x + (x - lastX), m_origin.y + (y - lastY)); - lastX=x; - lastY=y; - } - } + if(EVENT_INPUT_TYPE_MOVE == typeEvent && true == ewol::IsPressedInput(1) ) { + ewol::StartMoveSystem(); + } + } + if( x >= m_size.x - 20 + && y >= m_size.y - 20) + { + if(EVENT_INPUT_TYPE_MOVE == typeEvent && true == ewol::IsPressedInput(1) ) { + ewol::StartResizeSystem(); + } } return true; }