Move mouse compensation code to generic window code

This commit is contained in:
Ilari Liusvaara 2011-10-31 21:14:16 +02:00
parent 9433afa7a9
commit 446ed44470
4 changed files with 33 additions and 35 deletions

View file

@ -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<std::string, std::string>& 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);
}

View file

@ -101,6 +101,19 @@ public:
*/
static std::map<std::string, std::string>& 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<std::string, std::string> get_sound_devices();
/******************************** JOYSTICK PLUGIN **********************************/
/**
* Poll joysticks.
*

View file

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

View file

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