From 32854e22467fa9122e6c1225a1e489db8e0cab4b Mon Sep 17 00:00:00 2001 From: Brad Grantham Date: Sat, 19 Nov 2016 00:45:39 -0800 Subject: [PATCH] implement paste through interface --- apple2e.cpp | 7 +++++++ interface.cpp | 29 +++++++++++++---------------- interface.h | 8 +++++--- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/apple2e.cpp b/apple2e.cpp index 664ae6b..a93eaa1 100644 --- a/apple2e.cpp +++ b/apple2e.cpp @@ -1533,6 +1533,13 @@ enum APPLE2Einterface::EventType keyboard_to_mainboard(MAINboard *board) APPLE2Einterface::event e = APPLE2Einterface::dequeue_event(); if(e.type == APPLE2Einterface::QUIT) { return APPLE2Einterface::QUIT; + } else if(e.type == APPLE2Einterface::PASTE) { + for(int i = 0; i < strlen(e.str); i++) + if(e.str[i] == '\n') + board->enqueue_key('\r'); + else + board->enqueue_key(e.str[i]); + free(e.str); } else if(e.type == APPLE2Einterface::KEYDOWN) { if((e.value == APPLE2Einterface::LEFT_SHIFT) || (e.value == APPLE2Einterface::RIGHT_SHIFT)) shift_down = true; diff --git a/interface.cpp b/interface.cpp index 5d8f6f3..38e8399 100644 --- a/interface.cpp +++ b/interface.cpp @@ -48,7 +48,7 @@ event dequeue_event() { if(event_waiting()) { event e = event_queue.front(); - event_queue.pop_back(); + event_queue.pop_front(); return e; } else return {NONE, 0}; @@ -454,17 +454,6 @@ static void redraw(GLFWwindow *window) CheckOpenGL(__FILE__, __LINE__); - if(0) if(mode == TEXT) { - printf("------------------------------------------\n"); - for(int row = 0; row < 24; row++) { - printf("|"); - for(int col = 0; col < 24; col++) - fputc(textport[display_page][row][col] & 0x7F, stdout); - printf("|\n"); - } - printf("------------------------------------------\n"); - } - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(mode == HIRES) { @@ -512,9 +501,6 @@ static void redraw(GLFWwindow *window) glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_RECTANGLE, font_texture); glUniform1i(font_texture_location, 1); - cout << elapsed_millis << endl; - cout << elapsed_millis /1870 << endl; - cout << (elapsed_millis /1870) % 2 << endl; glUniform1i(blink_location, (elapsed_millis / 1870) % 2); } else if(mode == LORES) { @@ -549,9 +535,20 @@ static void error_callback(int error, const char* description) static void key(GLFWwindow *window, int key, int scancode, int action, int mods) { + static bool super_down = false; + if(action == GLFW_PRESS) { - event_queue.push_back({KEYDOWN, key}); + if(key == GLFW_KEY_RIGHT_SUPER) + super_down = true; + else if(key == GLFW_KEY_V) { + const char* text = glfwGetClipboardString(window); + if (text) + event_queue.push_back({PASTE, 0, strdup(text)}); + } else + event_queue.push_back({KEYDOWN, key}); } else if(action == GLFW_RELEASE) { + if(key == GLFW_KEY_RIGHT_SUPER) + super_down = false; event_queue.push_back({KEYUP, key}); } } diff --git a/interface.h b/interface.h index 50cf6b5..d0c26b4 100644 --- a/interface.h +++ b/interface.h @@ -2,7 +2,7 @@ namespace APPLE2Einterface { -enum EventType {NONE, KEYDOWN, KEYUP, RESET, REBOOT, QUIT}; +enum EventType {NONE, KEYDOWN, KEYUP, RESET, REBOOT, PASTE, QUIT}; const int LEFT_SHIFT = 340; const int LEFT_CONTROL = 341; @@ -31,9 +31,11 @@ const int CAPS_LOCK = 280; struct event { EventType type; int value; - event(EventType type_, int value_) : + char *str; + event(EventType type_, int value_, char *str_ = NULL) : type(type_), - value(value_) + value(value_), + str(str_) {} };