X11: change position and resize OK...

This commit is contained in:
Edouard Dupin 2011-11-01 15:47:17 +01:00
parent 0265f54413
commit 922e9cf485
5 changed files with 212 additions and 46 deletions

View File

@ -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; iii<NB_MAX_INPUT; iii++) {
inputIsPressed[iii] = false;
}
CreateX11Context();
CreateOGlContext();
m_run = true;
@ -417,6 +430,31 @@ namespace guiAbstraction {
case ConfigureNotify:
m_width = event.xconfigure.width;
m_height = event.xconfigure.height;
m_originX = event.xconfigure.x;
m_originY = event.xconfigure.y;
break;
case ButtonPress:
m_cursorEventX = event.xbutton.x;
m_cursorEventY = event.xbutton.y;
if (event.xbutton.button < NB_MAX_INPUT) {
inputIsPressed[event.xbutton.button] = true;
}
break;
case ButtonRelease:
m_cursorEventX = event.xbutton.x;
m_cursorEventY = event.xbutton.y;
if (event.xbutton.button < NB_MAX_INPUT) {
inputIsPressed[event.xbutton.button] = false;
}
break;
case EnterNotify:
case LeaveNotify:
m_cursorEventX = event.xcrossing.x;
m_cursorEventY = event.xcrossing.y;
break;
case MotionNotify:
m_cursorEventX = event.xmotion.x;
m_cursorEventY = event.xmotion.y;
break;
}
// parse event
@ -436,6 +474,8 @@ namespace guiAbstraction {
break;
case ButtonPress:
{
m_moveMode = false;
m_resizeMode = false;
int32_t btId = event.xbutton.button;
//EWOL_DEBUG("X11 bt=" << btId << " event : " << event.type << "=\"ButtonPress\" (" << (double)event.xbutton.x << "," << (double)event.xbutton.y << ")");
// Send Down message
@ -465,8 +505,9 @@ namespace guiAbstraction {
break;
case ButtonRelease:
{
m_moveMode = false;
m_resizeMode = false;
int32_t btId = event.xbutton.button;
//EWOL_DEBUG("X11 bt=" << btId << " event : " << event.type << "=\"ButtonRelease\" (" << (double)event.xbutton.x << "," << (double)event.xbutton.y << ")");
// send Up event ...
m_uniqueWindows->GenEventInput(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;
}
}

View File

@ -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);
};

View File

@ -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);
}

View File

@ -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);
};

View File

@ -30,23 +30,6 @@
#include <ewolTexture.h>
#include <ewolFont.h>
#include <ewol.h>
#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 <GL/gl.h>
@ -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;
}