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

Adds type recipient as a dynamic type, and accepts paste and fullscreen toggle in SDL.

This commit is contained in:
Thomas Harte 2017-11-21 21:44:29 -05:00
parent 89c3e2ba5a
commit 3365ff0200
3 changed files with 24 additions and 0 deletions

View File

@ -41,6 +41,10 @@ template<typename T> class TypedDynamicMachine: public ::Machine::DynamicMachine
return get<Configurable::Device>();
}
Utility::TypeRecipient *type_recipient() override {
return get<Utility::TypeRecipient>();
}
private:
template <typename Class> Class *get() {
return dynamic_cast<Class *>(machine_.get());

View File

@ -16,6 +16,7 @@
#include "../CRTMachine.hpp"
#include "../JoystickMachine.hpp"
#include "../KeyboardMachine.hpp"
#include "Typer.hpp"
#include <map>
#include <string>
@ -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;
};
/*!

View File

@ -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;