[DEV] grep the mouse events
This commit is contained in:
parent
95c94a9c9e
commit
426faa2012
@ -21,6 +21,7 @@ void game::Camera::Update(void)
|
|||||||
m_matrix.Rotate(vec3(0,0,1), m_angles.z );
|
m_matrix.Rotate(vec3(0,0,1), m_angles.z );
|
||||||
vec3 tmpp = m_position * -1;
|
vec3 tmpp = m_position * -1;
|
||||||
m_matrix.Translate(tmpp);
|
m_matrix.Translate(tmpp);
|
||||||
|
m_needUpdate = false;
|
||||||
//EWOL_DEBUG("camera: pos=" << m_position << " angle=" << m_angles);
|
//EWOL_DEBUG("camera: pos=" << m_position << " angle=" << m_angles);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,17 +29,26 @@ game::Camera::Camera(vec3 pos, vec3 angles) :
|
|||||||
m_position(pos),
|
m_position(pos),
|
||||||
m_angles(angles)
|
m_angles(angles)
|
||||||
{
|
{
|
||||||
Update();
|
m_needUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game::Camera::SetPosition(vec3 pos)
|
void game::Camera::SetPosition(vec3 pos)
|
||||||
{
|
{
|
||||||
|
m_needUpdate = true;
|
||||||
m_position = pos;
|
m_position = pos;
|
||||||
Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void game::Camera::SetAngle(vec3 angles)
|
void game::Camera::SetAngle(vec3 angles)
|
||||||
{
|
{
|
||||||
|
m_needUpdate = true;
|
||||||
m_angles = angles;
|
m_angles = angles;
|
||||||
Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mat4& game::Camera::GetMatrix(void)
|
||||||
|
{
|
||||||
|
if(m_needUpdate==true) {
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
return m_matrix;
|
||||||
|
};
|
||||||
|
@ -19,9 +19,10 @@ namespace game
|
|||||||
class Camera
|
class Camera
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
vec3 m_position; //!< position of the camera.
|
vec3 m_position; //!< position of the camera.
|
||||||
vec3 m_angles; //!< Angles to the camera is seing.
|
vec3 m_angles; //!< Angles to the camera is seing.
|
||||||
mat4 m_matrix; //!< transformation matrix.
|
mat4 m_matrix; //!< transformation matrix.
|
||||||
|
bool m_needUpdate; //!< matrix is nor anymore correct...
|
||||||
/**
|
/**
|
||||||
* @brief Update the matrix property
|
* @brief Update the matrix property
|
||||||
*/
|
*/
|
||||||
@ -56,7 +57,7 @@ namespace game
|
|||||||
* @brief Get the transformation matix for the camera.
|
* @brief Get the transformation matix for the camera.
|
||||||
* @return the current transformation matrix
|
* @return the current transformation matrix
|
||||||
*/
|
*/
|
||||||
mat4& GetMatrix(void) { return m_matrix; };
|
mat4& GetMatrix(void);
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -103,9 +103,11 @@ int32_t m_originY = 0;
|
|||||||
int32_t m_cursorEventX = 0;
|
int32_t m_cursorEventX = 0;
|
||||||
int32_t m_cursorEventY = 0;
|
int32_t m_cursorEventY = 0;
|
||||||
int32_t m_currentHeight = 0;
|
int32_t m_currentHeight = 0;
|
||||||
|
int32_t m_currentWidth = 0;
|
||||||
XVisualInfo * m_visual = NULL;
|
XVisualInfo * m_visual = NULL;
|
||||||
bool m_doubleBuffered = 0;
|
bool m_doubleBuffered = 0;
|
||||||
bool m_run = 0;
|
bool m_run = 0;
|
||||||
|
bool m_grabAllEvent = false;
|
||||||
|
|
||||||
bool inputIsPressed[20];
|
bool inputIsPressed[20];
|
||||||
|
|
||||||
@ -685,6 +687,7 @@ void X11_Run(void)
|
|||||||
m_originX = event.xconfigure.x;
|
m_originX = event.xconfigure.x;
|
||||||
m_originY = event.xconfigure.y;
|
m_originY = event.xconfigure.y;
|
||||||
m_currentHeight = event.xconfigure.height;
|
m_currentHeight = event.xconfigure.height;
|
||||||
|
m_currentWidth = event.xconfigure.width;
|
||||||
eSystem::Resize(event.xconfigure.width, event.xconfigure.height);
|
eSystem::Resize(event.xconfigure.width, event.xconfigure.height);
|
||||||
break;
|
break;
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
@ -747,6 +750,22 @@ void X11_Run(void)
|
|||||||
eSystem::SetMouseMotion(0, (float)event.xmotion.x, (float)(m_currentHeight-event.xmotion.y));
|
eSystem::SetMouseMotion(0, (float)event.xmotion.x, (float)(m_currentHeight-event.xmotion.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (m_grabAllEvent == true) {
|
||||||
|
XWarpPointer(m_display, None, WindowHandle, 0,0, 0, 0, m_currentWidth/2, m_currentHeight/2);
|
||||||
|
XFlush(m_display);
|
||||||
|
XEvent nev;
|
||||||
|
// remove next generated event ...
|
||||||
|
XNextEvent(m_display, &nev);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (m_grabAllEvent == true) {
|
||||||
|
EWOL_DEBUG("X11 mouse move(" << (float)event.xmotion.x << "," << (float)(m_currentHeight-event.xmotion.y) << ")");
|
||||||
|
if (BadWindow == XWarpPointer(m_display, None, WindowHandle, 0,0, 0, 0, 200, 200)) {
|
||||||
|
EWOL_WARNING("X11 mouse mouve (BadWindow)");
|
||||||
|
}
|
||||||
|
XSync(m_display, False);
|
||||||
|
}
|
||||||
|
*/
|
||||||
break;
|
break;
|
||||||
case FocusIn:
|
case FocusIn:
|
||||||
#ifdef DEBUG_X11_EVENT
|
#ifdef DEBUG_X11_EVENT
|
||||||
@ -1070,6 +1089,7 @@ void guiInterface::ChangeSize(ivec2 size)
|
|||||||
EWOL_INFO("X11: ChangeSize");
|
EWOL_INFO("X11: ChangeSize");
|
||||||
#endif
|
#endif
|
||||||
m_currentHeight = size.y;
|
m_currentHeight = size.y;
|
||||||
|
m_currentWidth = size.x;
|
||||||
XResizeWindow(m_display, WindowHandle, size.x, size.y);
|
XResizeWindow(m_display, WindowHandle, size.x, size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1094,6 +1114,78 @@ void guiInterface::GetAbsPos(ivec2& pos)
|
|||||||
XQueryPointer(m_display, WindowHandle, &fromroot, &tmpwin, &pos.x, &pos.y, &tmp, &tmp, &tmp2);
|
XQueryPointer(m_display, WindowHandle, &fromroot, &tmpwin, &pos.x, &pos.y, &tmp, &tmp, &tmp2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void guiInterface::CursorDisplay(bool isVisible)
|
||||||
|
{
|
||||||
|
if (false == isVisible) {
|
||||||
|
EWOL_DEBUG("Hide Cursor");
|
||||||
|
Cursor invisibleCursor;
|
||||||
|
Pixmap bitmapNoData;
|
||||||
|
XColor black;
|
||||||
|
static char noData[] = { 0,0,0,0,0,0,0,0 };
|
||||||
|
black.red = 0;
|
||||||
|
black.green = 0;
|
||||||
|
black.blue = 0;
|
||||||
|
bitmapNoData = XCreateBitmapFromData(m_display, WindowHandle, noData, 8, 8);
|
||||||
|
invisibleCursor = XCreatePixmapCursor(m_display, bitmapNoData, bitmapNoData,
|
||||||
|
&black, &black, 0, 0);
|
||||||
|
XDefineCursor(m_display,WindowHandle, invisibleCursor);
|
||||||
|
XFreeCursor(m_display, invisibleCursor);
|
||||||
|
} else {
|
||||||
|
EWOL_DEBUG("Show Cursor");
|
||||||
|
XUndefineCursor(m_display, WindowHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void guiInterface::GrabPointerEvents(bool isGrabbed)
|
||||||
|
{
|
||||||
|
if (true == isGrabbed) {
|
||||||
|
EWOL_DEBUG("Grab Events");
|
||||||
|
|
||||||
|
//EWOL_DEBUG("X11 mouse move(" << (float)event.xmotion.x << "," << (float)(m_currentHeight-event.xmotion.y) << ")");
|
||||||
|
if (BadWindow == XWarpPointer(m_display, None, WindowHandle, 0,0, 0, 0, 20, 20)) {
|
||||||
|
EWOL_WARNING("X11 mouse mouve (BadWindow)");
|
||||||
|
}
|
||||||
|
XSync(m_display, False);
|
||||||
|
XFlush(m_display);
|
||||||
|
/*
|
||||||
|
int32_t test = XGrabPointer(m_display,RootWindow(m_display, DefaultScreen(m_display)), True,
|
||||||
|
ButtonPressMask |
|
||||||
|
ButtonReleaseMask |
|
||||||
|
PointerMotionMask |
|
||||||
|
FocusChangeMask |
|
||||||
|
EnterWindowMask |
|
||||||
|
LeaveWindowMask,
|
||||||
|
GrabModeAsync,
|
||||||
|
GrabModeAsync,
|
||||||
|
RootWindow(m_display, DefaultScreen(m_display)),
|
||||||
|
None,
|
||||||
|
CurrentTime);
|
||||||
|
|
||||||
|
if (GrabSuccess != test)
|
||||||
|
{
|
||||||
|
EWOL_CRITICAL("Display error " << test);
|
||||||
|
switch (test)
|
||||||
|
{
|
||||||
|
case BadCursor:
|
||||||
|
EWOL_CRITICAL(" BadCursor");
|
||||||
|
break;
|
||||||
|
case BadValue:
|
||||||
|
EWOL_CRITICAL(" BadValue");
|
||||||
|
break;
|
||||||
|
case BadWindow:
|
||||||
|
EWOL_CRITICAL(" BadWindow");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
m_grabAllEvent = true;
|
||||||
|
} else {
|
||||||
|
EWOL_DEBUG("Un-Grab Events");
|
||||||
|
XUngrabPointer(m_display, CurrentTime);
|
||||||
|
m_grabAllEvent = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Main of the program
|
* @brief Main of the program
|
||||||
@ -1106,7 +1198,7 @@ int guiInterface::main(int argc, const char *argv[])
|
|||||||
for (int32_t iii=0; iii<NB_MAX_INPUT; iii++) {
|
for (int32_t iii=0; iii<NB_MAX_INPUT; iii++) {
|
||||||
inputIsPressed[iii] = false;
|
inputIsPressed[iii] = false;
|
||||||
}
|
}
|
||||||
|
m_grabAllEvent = false;
|
||||||
// start X11 thread ...
|
// start X11 thread ...
|
||||||
X11_Init();
|
X11_Init();
|
||||||
//start the basic thread :
|
//start the basic thread :
|
||||||
@ -1114,7 +1206,8 @@ int guiInterface::main(int argc, const char *argv[])
|
|||||||
// get the icon file :
|
// get the icon file :
|
||||||
etk::UString myIcon = APP_Icon();
|
etk::UString myIcon = APP_Icon();
|
||||||
SetIcon(myIcon);
|
SetIcon(myIcon);
|
||||||
|
CursorDisplay(true);
|
||||||
|
GrabPointerEvents(true);
|
||||||
// Run ...
|
// Run ...
|
||||||
X11_Run();
|
X11_Run();
|
||||||
// close X11 :
|
// close X11 :
|
||||||
|
@ -22,70 +22,65 @@ namespace guiInterface
|
|||||||
int main(int argc, const char *argv[]);
|
int main(int argc, const char *argv[]);
|
||||||
/**
|
/**
|
||||||
* @brief Get the curent time in micro-second
|
* @brief Get the curent time in micro-second
|
||||||
* @param ---
|
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
int64_t GetTime(void);
|
int64_t GetTime(void);
|
||||||
/**
|
/**
|
||||||
* @brief Stop the current program
|
* @brief Stop the current program
|
||||||
* @param ---
|
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void Stop(void);
|
void Stop(void);
|
||||||
/**
|
/**
|
||||||
* @brief Change the current Windows size
|
* @brief Change the current Windows size
|
||||||
* @param size The requested size
|
* @param size The requested size
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void ChangeSize(ivec2 size);
|
void ChangeSize(ivec2 size);
|
||||||
/**
|
/**
|
||||||
* @brief Change the current Windows position
|
* @brief Change the current Windows position
|
||||||
* @param pos The position where the winsdows might be placed.
|
* @param pos The position where the winsdows might be placed.
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void ChangePos(ivec2 pos);
|
void ChangePos(ivec2 pos);
|
||||||
/**
|
/**
|
||||||
* @brief Get the current Windows position
|
* @brief Get the current Windows position
|
||||||
* @param pos The position where the winsdows is.
|
* @param pos The position where the winsdows is.
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void GetAbsPos(ivec2& pos);
|
void GetAbsPos(ivec2& pos);
|
||||||
/**
|
/**
|
||||||
* @brief Display the virtal keyboard (for touch system only)
|
* @brief Display the virtal keyboard (for touch system only)
|
||||||
* @param ---
|
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void KeyboardShow(void);
|
void KeyboardShow(void);
|
||||||
/**
|
/**
|
||||||
* @brief Hide the virtal keyboard (for touch system only)
|
* @brief Hide the virtal keyboard (for touch system only)
|
||||||
* @param ---
|
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void KeyboardHide(void);
|
void KeyboardHide(void);
|
||||||
/**
|
/**
|
||||||
* @brief Inform the Gui that we want to have a copy of the clipboard
|
* @brief Inform the Gui that we want to have a copy of the clipboard
|
||||||
* @param ID of the clipboard (STD/SELECTION) only apear here
|
* @param ID of the clipboard (STD/SELECTION) only apear here
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void ClipBoardGet(ewol::clipBoard::clipboardListe_te clipboardID);
|
void ClipBoardGet(ewol::clipBoard::clipboardListe_te clipboardID);
|
||||||
/**
|
/**
|
||||||
* @brief Inform the Gui that we are the new owner of the clipboard
|
* @brief Inform the Gui that we are the new owner of the clipboard
|
||||||
* @param ID of the clipboard (STD/SELECTION) only apear here
|
* @param ID of the clipboard (STD/SELECTION) only apear here
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void ClipBoardSet(ewol::clipBoard::clipboardListe_te clipboardID);
|
void ClipBoardSet(ewol::clipBoard::clipboardListe_te clipboardID);
|
||||||
/**
|
/**
|
||||||
* @brief Set the new title of the windows
|
* @brief Set the new title of the windows
|
||||||
* @param title New desired title
|
* @param title New desired title
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void SetTitle(etk::UString& title);
|
void SetTitle(etk::UString& title);
|
||||||
/**
|
/**
|
||||||
* @brief Force the screen orientation (availlable on portable elements ...
|
* @brief Force the screen orientation (availlable on portable elements ...
|
||||||
* @param orientation Selected orientation.
|
* @param orientation Selected orientation.
|
||||||
* @return ---
|
|
||||||
*/
|
*/
|
||||||
void ForceOrientation(ewol::orientation_te orientation);
|
void ForceOrientation(ewol::orientation_te orientation);
|
||||||
|
/**
|
||||||
|
* @brief Set the cursor visible or not.
|
||||||
|
* @param isVisible set the cursor visible of hiden (sometime neede to hide system cursor).
|
||||||
|
*/
|
||||||
|
void CursorDisplay(bool isVisible);
|
||||||
|
/**
|
||||||
|
* @brief Get all the event from the X system
|
||||||
|
* @param isGrabbed true if all the event will be get, false if we want only ours.
|
||||||
|
*/
|
||||||
|
void GrabPointerEvents(bool isGrabbed);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,7 +113,6 @@ void widget::Scene::PeriodicCall(int64_t localTime)
|
|||||||
}
|
}
|
||||||
m_lastCallTime = curentTime;
|
m_lastCallTime = curentTime;
|
||||||
MarkToRedraw();
|
MarkToRedraw();
|
||||||
|
|
||||||
if (m_walk!=0) {
|
if (m_walk!=0) {
|
||||||
if( (m_walk&WALK_FLAG_FORWARD)!=0
|
if( (m_walk&WALK_FLAG_FORWARD)!=0
|
||||||
&& (m_walk&WALK_FLAG_BACK)!=0) {
|
&& (m_walk&WALK_FLAG_BACK)!=0) {
|
||||||
@ -121,20 +120,22 @@ void widget::Scene::PeriodicCall(int64_t localTime)
|
|||||||
} else if ( (m_walk&WALK_FLAG_FORWARD)!=0) {
|
} else if ( (m_walk&WALK_FLAG_FORWARD)!=0) {
|
||||||
vec3 angles = m_camera.GetAngle();
|
vec3 angles = m_camera.GetAngle();
|
||||||
angles.x = cosf(angles.z);
|
angles.x = cosf(angles.z);
|
||||||
angles.y = sinf(angles.z);
|
angles.y = -sinf(angles.z);
|
||||||
angles.z = 0;
|
angles.z = 0;
|
||||||
|
//EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles);
|
||||||
vec3 pos = m_camera.GetPosition();
|
vec3 pos = m_camera.GetPosition();
|
||||||
// walk is 6 km/h
|
// walk is 6 km/h
|
||||||
pos += angles*0.001666f/deltaTime;
|
pos += angles*3.333f*deltaTime;
|
||||||
m_camera.SetPosition(pos);
|
m_camera.SetPosition(pos);
|
||||||
} else if ( (m_walk&WALK_FLAG_BACK)!=0) {
|
} else if ( (m_walk&WALK_FLAG_BACK)!=0) {
|
||||||
vec3 angles = m_camera.GetAngle();
|
vec3 angles = m_camera.GetAngle();
|
||||||
angles.x = cosf(angles.z);
|
angles.x = -cosf(angles.z);
|
||||||
angles.y = sinf(angles.z);
|
angles.y = sinf(angles.z);
|
||||||
angles.z = 0;
|
angles.z = 0;
|
||||||
|
//EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles);
|
||||||
vec3 pos = m_camera.GetPosition();
|
vec3 pos = m_camera.GetPosition();
|
||||||
// walk is 6 km/h
|
// walk is 6 km/h
|
||||||
pos -= angles*0.001666f/deltaTime;
|
pos += angles*3.333f*deltaTime;
|
||||||
m_camera.SetPosition(pos);
|
m_camera.SetPosition(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,21 +144,23 @@ void widget::Scene::PeriodicCall(int64_t localTime)
|
|||||||
// request left and right in the same time ... this is really bad ....
|
// request left and right in the same time ... this is really bad ....
|
||||||
} else if ( (m_walk&WALK_FLAG_LEFT)!=0) {
|
} else if ( (m_walk&WALK_FLAG_LEFT)!=0) {
|
||||||
vec3 angles = m_camera.GetAngle();
|
vec3 angles = m_camera.GetAngle();
|
||||||
angles.x = cosf(angles.z+M_PI/2.0);
|
angles.x = cosf(angles.z-M_PI/2.0);
|
||||||
angles.y = sinf(angles.z+M_PI/2.0);
|
angles.y = -sinf(angles.z-M_PI/2.0);
|
||||||
angles.z = 0;
|
angles.z = 0;
|
||||||
|
//EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles);
|
||||||
vec3 pos = m_camera.GetPosition();
|
vec3 pos = m_camera.GetPosition();
|
||||||
// lateral walk is 4 km/h
|
// lateral walk is 4 km/h
|
||||||
pos += angles*0.0011f/deltaTime;
|
pos += angles*2.2f*deltaTime;
|
||||||
m_camera.SetPosition(pos);
|
m_camera.SetPosition(pos);
|
||||||
} else if ( (m_walk&WALK_FLAG_RIGHT)!=0) {
|
} else if ( (m_walk&WALK_FLAG_RIGHT)!=0) {
|
||||||
vec3 angles = m_camera.GetAngle();
|
vec3 angles = m_camera.GetAngle();
|
||||||
angles.x = cosf(angles.z+M_PI/2.0);
|
angles.x = -cosf(angles.z-M_PI/2.0);
|
||||||
angles.y = sinf(angles.z+M_PI/2.0);
|
angles.y = sinf(angles.z-M_PI/2.0);
|
||||||
angles.z = 0;
|
angles.z = 0;
|
||||||
|
//EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles);
|
||||||
vec3 pos = m_camera.GetPosition();
|
vec3 pos = m_camera.GetPosition();
|
||||||
// lateral walk is 4 km/h
|
// lateral walk is 4 km/h
|
||||||
pos -= angles*0.0011f/deltaTime;
|
pos += angles*2.2f*deltaTime;
|
||||||
m_camera.SetPosition(pos);
|
m_camera.SetPosition(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,7 +177,7 @@ void widget::Scene::GenDraw(ewol::DrawProperty displayProp)
|
|||||||
m_size.y);
|
m_size.y);
|
||||||
float ratio = m_size.x / m_size.y;
|
float ratio = m_size.x / m_size.y;
|
||||||
//EWOL_INFO("ratio : " << ratio);
|
//EWOL_INFO("ratio : " << ratio);
|
||||||
mat4 tmpProjection = etk::matPerspective( M_PI/2.0, ratio, 1, 4000);
|
mat4 tmpProjection = etk::matPerspective( M_PI/3.0, ratio, 1, 4000);
|
||||||
ewol::openGL::SetCameraMatrix(m_camera.GetMatrix());
|
ewol::openGL::SetCameraMatrix(m_camera.GetMatrix());
|
||||||
//mat4 tmpMat = tmpProjection * m_camera.GetMatrix();
|
//mat4 tmpMat = tmpProjection * m_camera.GetMatrix();
|
||||||
// set internal matrix system :
|
// set internal matrix system :
|
||||||
|
Loading…
x
Reference in New Issue
Block a user