Merge pull request #22 from procedural/hide-mouse
Functions to show and hide mouse cursor at runtime
This commit is contained in:
commit
47827ddda1
2 changed files with 45 additions and 0 deletions
42
src/core.c
42
src/core.c
|
@ -52,6 +52,11 @@
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
||||||
|
#ifdef __linux
|
||||||
|
#define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting
|
||||||
|
#define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window
|
||||||
|
#include <GLFW/glfw3native.h> // which are required for hiding mouse
|
||||||
|
#endif
|
||||||
//#include <GL/gl.h> // OpenGL functions (GLFW3 already includes gl.h)
|
//#include <GL/gl.h> // OpenGL functions (GLFW3 already includes gl.h)
|
||||||
//#define GLFW_DLL // Using GLFW DLL on Windows -> No, we use static version!
|
//#define GLFW_DLL // Using GLFW DLL on Windows -> No, we use static version!
|
||||||
#endif
|
#endif
|
||||||
|
@ -215,6 +220,7 @@ static bool cursorOnScreen = false; // Tracks if cursor is inside client
|
||||||
static Texture2D cursor; // Cursor texture
|
static Texture2D cursor; // Cursor texture
|
||||||
|
|
||||||
static Vector2 mousePosition;
|
static Vector2 mousePosition;
|
||||||
|
static bool mouseHidden;
|
||||||
|
|
||||||
static char previousKeyState[512] = { 0 }; // Required to check if key pressed/released once
|
static char previousKeyState[512] = { 0 }; // Required to check if key pressed/released once
|
||||||
static char currentKeyState[512] = { 0 }; // Required to check if key pressed/released once
|
static char currentKeyState[512] = { 0 }; // Required to check if key pressed/released once
|
||||||
|
@ -826,6 +832,42 @@ int GetMouseWheelMove(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void HideMouse()
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
#ifdef __linux
|
||||||
|
XColor Col;
|
||||||
|
const char Nil[] = {0};
|
||||||
|
|
||||||
|
Pixmap Pix = XCreateBitmapFromData(glfwGetX11Display(), glfwGetX11Window(window), Nil, 1, 1);
|
||||||
|
Cursor Cur = XCreatePixmapCursor(glfwGetX11Display(), Pix, Pix, &Col, &Col, 0, 0);
|
||||||
|
|
||||||
|
XDefineCursor(glfwGetX11Display(), glfwGetX11Window(window), Cur);
|
||||||
|
XFreeCursor(glfwGetX11Display(), Cur);
|
||||||
|
#else
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
mouseHidden = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowMouse()
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
#ifdef __linux
|
||||||
|
XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window));
|
||||||
|
#else
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
mouseHidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsMouseHidden()
|
||||||
|
{
|
||||||
|
return mouseHidden;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Enable gamepad usage on Rapsberry Pi
|
// TODO: Enable gamepad usage on Rapsberry Pi
|
||||||
// NOTE: emscripten not implemented
|
// NOTE: emscripten not implemented
|
||||||
#if defined(PLATFORM_DESKTOP)
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
|
|
@ -368,6 +368,9 @@ int GetMouseY(void); // Returns mouse positio
|
||||||
Vector2 GetMousePosition(void); // Returns mouse position XY
|
Vector2 GetMousePosition(void); // Returns mouse position XY
|
||||||
void SetMousePosition(Vector2 position); // Set mouse position XY
|
void SetMousePosition(Vector2 position); // Set mouse position XY
|
||||||
int GetMouseWheelMove(void); // Returns mouse wheel movement Y
|
int GetMouseWheelMove(void); // Returns mouse wheel movement Y
|
||||||
|
void ShowMouse(void); // Shows mouse cursor
|
||||||
|
void HideMouse(void); // Hides mouse cursor
|
||||||
|
bool IsMouseHidden(void); // Returns true if mouse cursor is not visible
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP)
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue