From acf78efd44c8c15f5167f5436c7fa9295108382a Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Fri, 12 Jun 2020 23:06:07 +0200 Subject: add APIs to control mouse cursor not currently used yet, but useful if we add VR controller support to point and click inside VR on the window. --- src/main.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index dab2156..0fae5c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,6 +109,9 @@ public: void RenderFrame(); void ResetRotation(); + void MoveCursor(float x, float y); + void MouseButton(int button, bool down); + void SetupScene(); void AddCubeToScene( const glm::mat4 &mat, std::vector &vertdata ); void AddCubeVertex( float fl0, float fl1, float fl2, float fl3, float fl4, std::vector &vertdata ); @@ -1101,6 +1104,46 @@ void CMainApplication::ResetRotation() m_bResetRotation = true; } +//----------------------------------------------------------------------------- +// Purpose: simulates user mouse movement. Called when pointing a controller at +// the window for example. +//----------------------------------------------------------------------------- +void CMainApplication::MoveCursor(float x, float y) +{ + int xi = (int)(x * window_width); + int yi = (int)(y * window_height); + XWarpPointer(x_display, None, src_window_id, + 0, 0, 0, 0, xi, yi); +} + +//----------------------------------------------------------------------------- +// Purpose: simulates user mouse clicking. Called when clicking a button on the +// controller for example. +//----------------------------------------------------------------------------- +void CMainApplication::MouseButton(int button, bool down) +{ + Window root = DefaultRootWindow(x_display); + + Window dummyW; + int dummyI; + + XButtonEvent xbpe; + xbpe.window = src_window_id; + xbpe.button = button; + xbpe.display = x_display; + xbpe.root = root; + xbpe.same_screen = True; + xbpe.subwindow = None; + xbpe.time = CurrentTime; + xbpe.type = (down ? ButtonPress : ButtonRelease); + + XQueryPointer(x_display, root, &dummyW, &dummyW, + &dummyI, &dummyI, &dummyI, &dummyI, &xbpe.state); + + XSendEvent(x_display, src_window_id, True, ButtonPressMask, (XEvent *)&xbpe); + XFlush(x_display); +} + //----------------------------------------------------------------------------- // Purpose: Compiles a GL shader program and returns the handle. Returns 0 if -- cgit v1.2.3