Skip to content

Commit 21bb894

Browse files
authored
Support raw mouse motion (#149)
- Added API binding to glfwRawMouseMotionSupported - Added a window procedure to enable/disable raw mouse motion - Split Input_Toggle into two distinct types (Cursor_Input_Toggle, Bool_Input_Toggle) Requires Glfw 3.3 or higher.
1 parent 91f12a2 commit 21bb894

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

opengl-glfw/src/glfw-api.ads

+10-3
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ private package Glfw.API is
372372
-----------------------------------------------------------------------------
373373

374374
function Get_Input_Mode (Window : System.Address;
375-
Mode : Enums.Input_Toggle) return Bool;
375+
Mode : Enums.Bool_Input_Toggle) return Bool;
376376
function Get_Input_Mode (Window : System.Address;
377-
Mode : Enums.Input_Toggle)
377+
Mode : Enums.Cursor_Input_Toggle)
378378
return Input.Mouse.Cursor_Mode;
379379
pragma Import (Convention => C, Entity => Get_Input_Mode,
380380
External_Name => "glfwGetInputMode");
@@ -383,11 +383,18 @@ private package Glfw.API is
383383
Mode : Input.Sticky_Toggle;
384384
Value : Bool);
385385
procedure Set_Input_Mode (Window : System.Address;
386-
Mode : Enums.Input_Toggle;
386+
Mode : Enums.Cursor_Input_Toggle;
387387
Value : Input.Mouse.Cursor_Mode);
388+
procedure Set_Input_Mode (Window : System.Address;
389+
Mode : Enums.Bool_Input_Toggle;
390+
Value : Bool);
388391
pragma Import (Convention => C, Entity => Set_Input_Mode,
389392
External_Name => "glfwSetInputMode");
390393

394+
function Raw_Mouse_Motion_Supported return Bool;
395+
pragma Import (Convention => C, Entity => Raw_Mouse_Motion_Supported,
396+
External_Name => "glfwRawMouseMotionSupported");
397+
391398
function Get_Key (Window : System.Address; Key : Input.Keys.Key)
392399
return Input.Button_State;
393400
pragma Import (Convention => C, Entity => Get_Key,

opengl-glfw/src/glfw-enums.ads

+7-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ private package Glfw.Enums is
5656
Scale_To_Monitor => 16#2200C#);
5757
for Window_Info'Size use Interfaces.C.int'Size;
5858

59-
type Input_Toggle is (Mouse_Cursor);
60-
for Input_Toggle use (Mouse_Cursor => 16#33001#);
61-
for Input_Toggle'Size use Interfaces.C.int'Size;
59+
type Cursor_Input_Toggle is (Mouse_Cursor);
60+
for Cursor_Input_Toggle use (Mouse_Cursor => 16#33001#);
61+
for Cursor_Input_Toggle'Size use Interfaces.C.int'Size;
62+
63+
type Bool_Input_Toggle is (Raw_Mouse_Motion);
64+
for Bool_Input_Toggle use (Raw_Mouse_Motion => 16#33005#);
65+
for Bool_Input_Toggle'Size use Interfaces.C.int'Size;
6266

6367
type Joystick_ID is (
6468
Joystick_1, Joystick_2, Joystick_3, Joystick_4, Joystick_5,

opengl-glfw/src/glfw-input-mouse.adb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- part of OpenGLAda, (c) 2017 Felix Krause
2+
-- released under the terms of the MIT license, see the file "COPYING"
3+
4+
with Glfw.API;
5+
6+
package body Glfw.Input.Mouse is
7+
8+
function Raw_Motion_Supported return Boolean is
9+
begin
10+
return Boolean (API.Raw_Mouse_Motion_Supported);
11+
end Raw_Motion_Supported;
12+
13+
end Glfw.Input.Mouse;

opengl-glfw/src/glfw-input-mouse.ads

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ package Glfw.Input.Mouse is
1616
subtype Coordinate is Interfaces.C.double;
1717
subtype Scroll_Offset is Interfaces.C.double;
1818

19+
function Raw_Motion_Supported return Boolean;
20+
1921
private
2022
for Button'Size use Interfaces.C.int'Size;
2123

opengl-glfw/src/glfw-windows.adb

+6
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ package body Glfw.Windows is
246246
API.Set_Cursor_Pos (Object.Handle, X, Y);
247247
end Set_Cursor_Pos;
248248

249+
procedure Set_Raw_Mouse_Motion (Object : not null access Window;
250+
Value : Boolean) is
251+
begin
252+
API.Set_Input_Mode (Object.Handle, Enums.Raw_Mouse_Motion, Bool (Value));
253+
end Set_Raw_Mouse_Motion;
254+
249255
procedure Get_Position (Object : not null access Window;
250256
X, Y : out Coordinate) is
251257
begin

opengl-glfw/src/glfw-windows.ads

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ package Glfw.Windows is
5959
procedure Set_Cursor_Mode (Object : not null access Window;
6060
Mode : Input.Mouse.Cursor_Mode);
6161

62+
procedure Set_Raw_Mouse_Motion (Object : not null access Window;
63+
Value : Boolean);
64+
6265
procedure Get_Cursor_Pos (Object : not null access Window;
6366
X, Y : out Input.Mouse.Coordinate);
6467
procedure Set_Cursor_Pos (Object : not null access Window;

0 commit comments

Comments
 (0)