From 446ed4447075d0f364f481369cca646601c9bdcc Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 31 Oct 2011 21:14:16 +0200 Subject: [PATCH] Move mouse compensation code to generic window code --- generic/window.cpp | 14 ++++++++++++++ generic/window.hpp | 30 +++++++++++++++++------------- platform/SDL/window-sdl.cpp | 17 ++--------------- platform/dummy/window-dummy.cpp | 7 ------- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/generic/window.cpp b/generic/window.cpp index 5c52e0b2..c99f2993 100644 --- a/generic/window.cpp +++ b/generic/window.cpp @@ -118,6 +118,10 @@ namespace }; window_callback* wcb = NULL; + uint32_t vc_xoffset; + uint32_t vc_yoffset; + uint32_t vc_hscl = 1; + uint32_t vc_vscl = 1; } std::map& window::get_emustatus() throw() @@ -148,6 +152,14 @@ std::ostream& window::out() throw(std::bad_alloc) return *cached; } +void window::set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl) +{ + vc_xoffset = xoffset; + vc_yoffset = yoffset; + vc_hscl = hscl; + vc_vscl = vscl; +} + window_callback::~window_callback() throw() { } @@ -168,6 +180,8 @@ void window_callback::do_close() throw() void window_callback::do_click(int32_t x, int32_t y, uint32_t buttonmask) throw() { + x = (x - vc_xoffset) / vc_hscl; + y = (y - vc_yoffset) / vc_vscl; if(wcb) wcb->on_click(x, y, buttonmask); } diff --git a/generic/window.hpp b/generic/window.hpp index 3bea5dac..c9e0703b 100644 --- a/generic/window.hpp +++ b/generic/window.hpp @@ -101,6 +101,19 @@ public: */ static std::map& get_emustatus() throw(); +/** + * Set window main screen compensation parameters. This is used for mouse click reporting. + * + * Implemented by the generic window code. + * + * parameter xoffset: X coordinate of origin. + * parameter yoffset: Y coordinate of origin. + * parameter hscl: Horizontal scaling factor. + * parameter vscl: Vertical scaling factor. + */ + static void set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl); + +/******************************** GRAPHICS PLUGIN **********************************/ /** * Adds a messages to mesage queue to be shown. * @@ -133,7 +146,7 @@ public: /** * Processes inputs. If in non-modal mode (normal mode without pause), this returns quickly. Otherwise it waits - * for modal mode to exit. Also needs to call poll_joysticks(). + * for modal mode to exit. Also needs to call window::poll_joysticks(). * * Needs to be implemented by the graphics plugin. * @@ -185,18 +198,7 @@ public: */ static void cancel_wait() throw(); -/** - * Set window main screen compensation parameters. This is used for mouse click reporting. - * - * Needs to be implemented by the graphics plugin. - * - * parameter xoffset: X coordinate of origin. - * parameter yoffset: Y coordinate of origin. - * parameter hscl: Horizontal scaling factor. - * parameter vscl: Vertical scaling factor. - */ - static void set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl); - +/******************************** SOUND PLUGIN **********************************/ /** * Enable or disable sound. * @@ -253,6 +255,8 @@ public: * Needs to be implemented by the sound plugin. */ static std::map get_sound_devices(); + +/******************************** JOYSTICK PLUGIN **********************************/ /** * Poll joysticks. * diff --git a/platform/SDL/window-sdl.cpp b/platform/SDL/window-sdl.cpp index 203de631..fd7d94fb 100644 --- a/platform/SDL/window-sdl.cpp +++ b/platform/SDL/window-sdl.cpp @@ -460,10 +460,6 @@ namespace { bool SDL_initialized = false; uint32_t mouse_mask = 0; - uint32_t vc_xoffset; - uint32_t vc_yoffset; - uint32_t vc_hscl = 1; - uint32_t vc_vscl = 1; bool sdl_init; bool modconfirm; bool modal_return_flag; @@ -872,8 +868,8 @@ namespace if(e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) { int32_t xc = e.button.x; int32_t yc = e.button.y; - xc = (xc - 6 - vc_xoffset) / vc_hscl; - yc = (yc - 6 - vc_yoffset) / vc_vscl; + xc -= 6; + yc -= 6; if(e.button.button == SDL_BUTTON_LEFT) { if(e.button.state == SDL_PRESSED) mouse_mask |= 1; @@ -1468,13 +1464,4 @@ void window::cancel_wait() throw() wait_canceled = true; } -void window::set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl) -{ - vc_xoffset = xoffset; - vc_yoffset = yoffset; - vc_hscl = hscl; - vc_vscl = vscl; -} - - const char* graphics_plugin_name = "SDL graphics plugin"; diff --git a/platform/dummy/window-dummy.cpp b/platform/dummy/window-dummy.cpp index f1681dd4..a4125750 100644 --- a/platform/dummy/window-dummy.cpp +++ b/platform/dummy/window-dummy.cpp @@ -10,7 +10,6 @@ void window::set_main_surface(screen& scr) throw() {} void window::paused(bool enable) throw() {} void window::wait_usec(uint64_t usec) throw(std::bad_alloc) {} void window::cancel_wait() throw() {} -void window::set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl) {} bool window::modal_message(const std::string& msg, bool confirm) throw(std::bad_alloc) { @@ -32,10 +31,4 @@ void window::message(const std::string& msg) throw(std::bad_alloc) std::cout << msg << std::endl; } -uint64_t get_ticks_msec() throw() -{ - static uint64_t c = 0; - return c++; -} - const char* graphics_plugin_name = "Dummy graphics plugin";