Add option to invert the Mouse Y coordinate on MacOS
This commit is contained in:
parent
44cdecae60
commit
11151ca6f0
@ -104,6 +104,7 @@ option(MINIFB_BUILD_EXAMPLES "Build minifb example programs" TRUE)
|
|||||||
|
|
||||||
if(APPLE AND NOT IOS)
|
if(APPLE AND NOT IOS)
|
||||||
option(USE_METAL_API "Build the project using metal API code" ON)
|
option(USE_METAL_API "Build the project using metal API code" ON)
|
||||||
|
option(USE_INVERTED_Y_ON_MACOS "Use default mouse position: (0, 0) at (left, down)" OFF)
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
option(USE_WAYLAND_API "Build the project using wayland API code" OFF)
|
option(USE_WAYLAND_API "Build the project using wayland API code" OFF)
|
||||||
if(NOT USE_WAYLAND_API)
|
if(NOT USE_WAYLAND_API)
|
||||||
@ -180,6 +181,10 @@ elseif(APPLE)
|
|||||||
add_definitions(-DUSE_METAL_API)
|
add_definitions(-DUSE_METAL_API)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(USE_INVERTED_Y_ON_MACOS)
|
||||||
|
add_definitions(-DUSE_INVERTED_Y_ON_MACOS)
|
||||||
|
endif()
|
||||||
|
|
||||||
list(APPEND SrcLib ${SrcMacOSX})
|
list(APPEND SrcLib ${SrcMacOSX})
|
||||||
|
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
|
14
README.md
14
README.md
@ -186,6 +186,20 @@ cd build
|
|||||||
cmake .. -DUSE_METAL_API=OFF
|
cmake .. -DUSE_METAL_API=OFF
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Coordinate system
|
||||||
|
|
||||||
|
On MacOS, the default mouse coordinate system is (0, 0) -> (left, bottom). But as we want to create a multiplatform library we inverted the coordinates in such a way that now (0, 0) -> (left, top), like in the other platforms.
|
||||||
|
|
||||||
|
In any case, if you want to get the default coordinate system you can use the CMake flag: USE_INVERTED_Y_ON_MACOS=ON
|
||||||
|
|
||||||
|
```
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake .. -DUSE_INVERTED_Y_ON_MACOS=ON
|
||||||
|
```
|
||||||
|
|
||||||
|
_Note: In the future, we may use a global option so that all platforms behave in the same way. Probably: -DUSE_INVERTED_Y_
|
||||||
|
|
||||||
if you use **tundra**:
|
if you use **tundra**:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -186,8 +186,12 @@
|
|||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
//NSPoint localPoint = [self convertPoint:point fromView:nil];
|
//NSPoint localPoint = [self convertPoint:point fromView:nil];
|
||||||
window_data->mouse_pos_x = point.x;
|
window_data->mouse_pos_x = point.x;
|
||||||
|
#if defined(USE_INVERTED_Y_ON_MACOS)
|
||||||
window_data->mouse_pos_y = point.y;
|
window_data->mouse_pos_y = point.y;
|
||||||
kCall(mouse_move_func, point.x, point.y);
|
#else
|
||||||
|
window_data->mouse_pos_y = window_data->window_height - point.y;
|
||||||
|
#endif
|
||||||
|
kCall(mouse_move_func, window_data->mouse_pos_x, window_data->mouse_pos_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user