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)
|
||||
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)
|
||||
option(USE_WAYLAND_API "Build the project using wayland API code" OFF)
|
||||
if(NOT USE_WAYLAND_API)
|
||||
@ -180,6 +181,10 @@ elseif(APPLE)
|
||||
add_definitions(-DUSE_METAL_API)
|
||||
endif()
|
||||
|
||||
if(USE_INVERTED_Y_ON_MACOS)
|
||||
add_definitions(-DUSE_INVERTED_Y_ON_MACOS)
|
||||
endif()
|
||||
|
||||
list(APPEND SrcLib ${SrcMacOSX})
|
||||
|
||||
elseif(UNIX)
|
||||
|
14
README.md
14
README.md
@ -186,6 +186,20 @@ cd build
|
||||
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**:
|
||||
|
||||
```
|
||||
|
@ -186,8 +186,12 @@
|
||||
NSPoint point = [event locationInWindow];
|
||||
//NSPoint localPoint = [self convertPoint:point fromView:nil];
|
||||
window_data->mouse_pos_x = point.x;
|
||||
#if defined(USE_INVERTED_Y_ON_MACOS)
|
||||
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