aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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