From 3365ff02006a5d688dbad45283b68075fb483eef Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 21 Nov 2017 21:44:29 -0500 Subject: [PATCH] Adds type recipient as a dynamic type, and accepts paste and fullscreen toggle in SDL. --- Machines/Utility/MachineForTarget.cpp | 4 ++++ Machines/Utility/MachineForTarget.hpp | 2 ++ OSBindings/SDL/main.cpp | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/Machines/Utility/MachineForTarget.cpp b/Machines/Utility/MachineForTarget.cpp index b92b4fd33..72fa8b3dd 100644 --- a/Machines/Utility/MachineForTarget.cpp +++ b/Machines/Utility/MachineForTarget.cpp @@ -41,6 +41,10 @@ template class TypedDynamicMachine: public ::Machine::DynamicMachine return get(); } + Utility::TypeRecipient *type_recipient() override { + return get(); + } + private: template Class *get() { return dynamic_cast(machine_.get()); diff --git a/Machines/Utility/MachineForTarget.hpp b/Machines/Utility/MachineForTarget.hpp index 1932ec73e..01f2c326a 100644 --- a/Machines/Utility/MachineForTarget.hpp +++ b/Machines/Utility/MachineForTarget.hpp @@ -16,6 +16,7 @@ #include "../CRTMachine.hpp" #include "../JoystickMachine.hpp" #include "../KeyboardMachine.hpp" +#include "Typer.hpp" #include #include @@ -32,6 +33,7 @@ struct DynamicMachine { virtual JoystickMachine::Machine *joystick_machine() = 0; virtual KeyboardMachine::Machine *keyboard_machine() = 0; virtual Configurable::Device *configurable_device() = 0; + virtual Utility::TypeRecipient *type_recipient() = 0; }; /*! diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index 0f083c566..a5a9ebddc 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -382,6 +382,7 @@ int main(int argc, char *argv[]) { // Run the main event loop until the OS tells us to quit. bool should_quit = false; + Uint32 fullscreen_mode = 0; while(!should_quit) { // Process all pending events. SDL_Event event; @@ -408,6 +409,23 @@ int main(int argc, char *argv[]) { } break; case SDL_KEYDOWN: + // Syphon off the key-press if it's control+shift+V (paste). + if(event.key.keysym.sym == SDLK_v && (SDL_GetModState()&KMOD_CTRL) && (SDL_GetModState()&KMOD_SHIFT)) { + Utility::TypeRecipient *type_recipient = machine->type_recipient(); + if(type_recipient) { + type_recipient->set_typer_for_string(SDL_GetClipboardText()); + break; + } + } + + // Also syphon off alt+enter (toggle full-screen). + if(event.key.keysym.sym == SDLK_RETURN && (SDL_GetModState()&KMOD_ALT)) { + fullscreen_mode ^= SDL_WINDOW_FULLSCREEN_DESKTOP; + SDL_SetWindowFullscreen(window, fullscreen_mode); + break; + } + + // deliberate fallthrough... case SDL_KEYUP: { KeyboardMachine::Machine *keyboard_machine = machine->keyboard_machine(); if(!keyboard_machine) break;