From 426faa2012e4aaecdc91011840cf4f9a489419cb Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 20 Dec 2012 22:09:45 +0100 Subject: [PATCH] [DEV] grep the mouse events --- sources/ewol/game/Camera.cpp | 16 ++++- sources/ewol/game/Camera.h | 9 +-- sources/ewol/renderer/os/gui.X11.cpp | 97 +++++++++++++++++++++++++++- sources/ewol/renderer/os/gui.h | 25 +++---- sources/ewol/widget/Scene.cpp | 27 ++++---- 5 files changed, 138 insertions(+), 36 deletions(-) diff --git a/sources/ewol/game/Camera.cpp b/sources/ewol/game/Camera.cpp index 7996ad8d..9155f1b3 100644 --- a/sources/ewol/game/Camera.cpp +++ b/sources/ewol/game/Camera.cpp @@ -21,6 +21,7 @@ void game::Camera::Update(void) m_matrix.Rotate(vec3(0,0,1), m_angles.z ); vec3 tmpp = m_position * -1; m_matrix.Translate(tmpp); + m_needUpdate = false; //EWOL_DEBUG("camera: pos=" << m_position << " angle=" << m_angles); } @@ -28,17 +29,26 @@ game::Camera::Camera(vec3 pos, vec3 angles) : m_position(pos), m_angles(angles) { - Update(); + m_needUpdate = true; } void game::Camera::SetPosition(vec3 pos) { + m_needUpdate = true; m_position = pos; - Update(); } void game::Camera::SetAngle(vec3 angles) { + m_needUpdate = true; m_angles = angles; - Update(); } + + +mat4& game::Camera::GetMatrix(void) +{ + if(m_needUpdate==true) { + Update(); + } + return m_matrix; +}; diff --git a/sources/ewol/game/Camera.h b/sources/ewol/game/Camera.h index a08fd5b5..7a0d28f4 100644 --- a/sources/ewol/game/Camera.h +++ b/sources/ewol/game/Camera.h @@ -19,9 +19,10 @@ namespace game class Camera { private: - vec3 m_position; //!< position of the camera. - vec3 m_angles; //!< Angles to the camera is seing. - mat4 m_matrix; //!< transformation matrix. + vec3 m_position; //!< position of the camera. + vec3 m_angles; //!< Angles to the camera is seing. + mat4 m_matrix; //!< transformation matrix. + bool m_needUpdate; //!< matrix is nor anymore correct... /** * @brief Update the matrix property */ @@ -56,7 +57,7 @@ namespace game * @brief Get the transformation matix for the camera. * @return the current transformation matrix */ - mat4& GetMatrix(void) { return m_matrix; }; + mat4& GetMatrix(void); }; }; diff --git a/sources/ewol/renderer/os/gui.X11.cpp b/sources/ewol/renderer/os/gui.X11.cpp index b33be3df..6b7666cf 100644 --- a/sources/ewol/renderer/os/gui.X11.cpp +++ b/sources/ewol/renderer/os/gui.X11.cpp @@ -103,9 +103,11 @@ int32_t m_originY = 0; int32_t m_cursorEventX = 0; int32_t m_cursorEventY = 0; int32_t m_currentHeight = 0; +int32_t m_currentWidth = 0; XVisualInfo * m_visual = NULL; bool m_doubleBuffered = 0; bool m_run = 0; +bool m_grabAllEvent = false; bool inputIsPressed[20]; @@ -685,6 +687,7 @@ void X11_Run(void) m_originX = event.xconfigure.x; m_originY = event.xconfigure.y; m_currentHeight = event.xconfigure.height; + m_currentWidth = event.xconfigure.width; eSystem::Resize(event.xconfigure.width, event.xconfigure.height); break; case ButtonPress: @@ -747,6 +750,22 @@ void X11_Run(void) 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; case FocusIn: #ifdef DEBUG_X11_EVENT @@ -1070,6 +1089,7 @@ void guiInterface::ChangeSize(ivec2 size) EWOL_INFO("X11: ChangeSize"); #endif m_currentHeight = size.y; + m_currentWidth = size.x; 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); } +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 @@ -1106,7 +1198,7 @@ int guiInterface::main(int argc, const char *argv[]) for (int32_t iii=0; iii " << angles); vec3 pos = m_camera.GetPosition(); // walk is 6 km/h - pos += angles*0.001666f/deltaTime; + pos += angles*3.333f*deltaTime; m_camera.SetPosition(pos); } else if ( (m_walk&WALK_FLAG_BACK)!=0) { vec3 angles = m_camera.GetAngle(); - angles.x = cosf(angles.z); + angles.x = -cosf(angles.z); angles.y = sinf(angles.z); angles.z = 0; + //EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles); vec3 pos = m_camera.GetPosition(); // walk is 6 km/h - pos -= angles*0.001666f/deltaTime; + pos += angles*3.333f*deltaTime; 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 .... } else if ( (m_walk&WALK_FLAG_LEFT)!=0) { vec3 angles = m_camera.GetAngle(); - angles.x = cosf(angles.z+M_PI/2.0); - angles.y = sinf(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.z = 0; + //EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles); vec3 pos = m_camera.GetPosition(); // lateral walk is 4 km/h - pos += angles*0.0011f/deltaTime; + pos += angles*2.2f*deltaTime; m_camera.SetPosition(pos); } else if ( (m_walk&WALK_FLAG_RIGHT)!=0) { vec3 angles = m_camera.GetAngle(); - angles.x = cosf(angles.z+M_PI/2.0); - angles.y = sinf(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.z = 0; + //EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles); vec3 pos = m_camera.GetPosition(); // lateral walk is 4 km/h - pos -= angles*0.0011f/deltaTime; + pos += angles*2.2f*deltaTime; m_camera.SetPosition(pos); } } @@ -174,7 +177,7 @@ void widget::Scene::GenDraw(ewol::DrawProperty displayProp) m_size.y); float ratio = m_size.x / m_size.y; //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()); //mat4 tmpMat = tmpProjection * m_camera.GetMatrix(); // set internal matrix system :