aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWebFreak001 <gh@webfreak.org>2020-06-12 23:06:07 +0200
committerdec05eba <dec05eba@protonmail.com>2020-06-13 07:21:25 +0200
commitacf78efd44c8c15f5167f5436c7fa9295108382a (patch)
treede276cde90624639158dc86c823ea9b958b44626
parentfb6a408d2b6c925790d70ccfcf583398ea2add2b (diff)
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.
-rw-r--r--src/main.cpp43
1 files changed, 43 insertions, 0 deletions
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<float> &vertdata );
void AddCubeVertex( float fl0, float fl1, float fl2, float fl3, float fl4, std::vector<float> &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