1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-17 06:29:28 +00:00

Takes a first stab at mouse input support from SDL.

There seems to be something odd going on with mouse buttons though; I'm going to test elsewhere.
This commit is contained in:
Thomas Harte 2019-07-08 17:36:55 -04:00
parent 6e7a733c3c
commit 2651b15db1
3 changed files with 32 additions and 2 deletions

View File

@ -61,7 +61,7 @@ class QuadratureMouse: public Mouse {
if(!axis_value) continue;
primaries_[axis] ^= 1;
secondaries_[axis] = primaries_[axis];
secondaries_[axis] = primaries_[axis] ^ axis;
if(axis_value > 0) {
-- axes_[axis];
secondaries_[axis] ^= 1;

View File

@ -447,7 +447,7 @@ struct ActivityObserver: public Activity::Observer {
auto mouse_machine = _machine->mouse_machine();
if(mouse_machine) {
@synchronized(self) {
mouse_machine->get_mouse().move(int(deltaX), -int(deltaY));
mouse_machine->get_mouse().move(int(deltaX), int(deltaY));
}
}
}

View File

@ -583,6 +583,7 @@ int main(int argc, char *argv[]) {
}
// Run the main event loop until the OS tells us to quit.
const bool uses_mouse = !!machine->mouse_machine();
bool should_quit = false;
Uint32 fullscreen_mode = 0;
while(!should_quit) {
@ -621,6 +622,11 @@ int main(int argc, char *argv[]) {
}
}
// Use ctrl+escape to release the mouse (if captured).
if(event.key.keysym.sym == SDLK_ESCAPE && (SDL_GetModState()&KMOD_CTRL)) {
SDL_SetRelativeMouseMode(SDL_FALSE);
}
// Capture ctrl+shift+d as a take-a-screenshot command.
if(event.key.keysym.sym == SDLK_d && (SDL_GetModState()&KMOD_CTRL) && (SDL_GetModState()&KMOD_SHIFT)) {
// Grab the screen buffer.
@ -722,6 +728,30 @@ int main(int argc, char *argv[]) {
}
} break;
case SDL_MOUSEBUTTONDOWN:
if(uses_mouse && !SDL_GetRelativeMouseMode()) {
SDL_SetRelativeMouseMode(SDL_TRUE);
break;
}
case SDL_MOUSEBUTTONUP: {
const auto mouse_machine = machine->mouse_machine();
if(mouse_machine) {
printf("%d %s\n", event.button.button, (event.type == SDL_PRESSED) ? "pressed" : "released");
mouse_machine->get_mouse().set_button_pressed(
event.button.button % mouse_machine->get_mouse().get_number_of_buttons(),
event.type == SDL_PRESSED);
}
} break;
case SDL_MOUSEMOTION: {
if(SDL_GetRelativeMouseMode()) {
const auto mouse_machine = machine->mouse_machine();
if(mouse_machine) {
mouse_machine->get_mouse().move(event.motion.xrel, event.motion.yrel);
}
}
} break;
default: break;
}
}