aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-03-07 19:23:32 +0000
committerMax Horn2009-03-07 19:23:32 +0000
commit0a99cfb4ed12338a643368ab312d1307b4207c5f (patch)
treed3fa63a2d1b8d7c5c4816cda76dab97db564c0b9
parent5c8ea3ccf4a5c587c4e6a9ad007a0b814a0ef1f4 (diff)
downloadscummvm-rg350-0a99cfb4ed12338a643368ab312d1307b4207c5f.tar.gz
scummvm-rg350-0a99cfb4ed12338a643368ab312d1307b4207c5f.tar.bz2
scummvm-rg350-0a99cfb4ed12338a643368ab312d1307b4207c5f.zip
SCI: Moved scummvm_get_event to operations.cpp (the only place where it is used), to ease future refactoring of the event handling code
svn-id: r39201
-rw-r--r--engines/sci/gfx/gfx_driver.cpp217
-rw-r--r--engines/sci/gfx/gfx_driver.h9
-rw-r--r--engines/sci/gfx/gfx_support.cpp3
-rw-r--r--engines/sci/gfx/gfx_tools.h15
-rw-r--r--engines/sci/gfx/operations.cpp214
-rw-r--r--engines/sci/gfx/operations.h2
6 files changed, 209 insertions, 251 deletions
diff --git a/engines/sci/gfx/gfx_driver.cpp b/engines/sci/gfx/gfx_driver.cpp
index 7b9c890a05..51067b8604 100644
--- a/engines/sci/gfx/gfx_driver.cpp
+++ b/engines/sci/gfx/gfx_driver.cpp
@@ -25,7 +25,6 @@
#include "common/scummsys.h"
#include "common/system.h"
-#include "common/events.h"
#include "graphics/primitives.h"
#include "sci/sci.h"
@@ -43,8 +42,6 @@ struct _scummvm_driver_state {
#define S ((struct _scummvm_driver_state *)(drv->state))
-int _modifierStates;
-
static int scummvm_init_specific(gfx_driver_t *drv, int xfact, int yfact, int bytespp) {
int i;
@@ -84,7 +81,6 @@ static int scummvm_init_specific(gfx_driver_t *drv, int xfact, int yfact, int by
}
static int scummvm_init(gfx_driver_t *drv) {
- _modifierStates = 0;
return scummvm_init_specific(drv, 1, 1, GFX_COLOR_MODE_INDEX);
}
@@ -312,218 +308,6 @@ static int scummvm_set_palette(gfx_driver_t *drv, int index, byte red, byte gree
return GFX_OK;
}
-// Event management
-
-static sci_event_t scummvm_get_event(gfx_driver_t *drv) {
- sci_event_t input = { SCI_EVT_NONE, 0, 0, 0 };
-
- Common::EventManager *em = g_system->getEventManager();
- Common::Event ev;
-
- bool found = em->pollEvent(ev);
- Common::Point p = ev.mouse;
-
- // Don't generate events for mouse movement
- while (found && ev.type == Common::EVENT_MOUSEMOVE) {
- drv->pointer_x = ev.mouse.x;
- drv->pointer_y = ev.mouse.y;
- found = em->pollEvent(ev);
- }
-
- if (found && !ev.synthetic && ev.type != Common::EVENT_MOUSEMOVE) {
- int modifiers = em->getModifierState();
-
- // We add the modifier key status to buckybits
- // SDL sends a keydown event if a modifier key is turned on and a keyup event if it's off
- //
- // FIXME: This code is semi-bogus. It only records the modifier key being *pressed*.
- // It does not track correctly whether capslock etc. is active. To do that, we
- // would have to record the fact that the modifier was pressed in global var,
- // and also watch for Common::EVENT_KEYUP events.
- // But this is still not quite good enough, because not all events might
- // pass through here (e.g. the GUI might be running with its own event loop).
- //
- // The best solution likely would be to add code to the EventManager class
- // for tracking which keys are pressed and which are not...
- if (ev.type == Common::EVENT_KEYDOWN || ev.type == Common::EVENT_KEYUP) {
- switch (ev.kbd.keycode) {
- case Common::KEYCODE_CAPSLOCK:
- if (ev.type == Common::EVENT_KEYDOWN) {
- _modifierStates |= SCI_EVM_CAPSLOCK;
- } else {
- _modifierStates &= ~SCI_EVM_CAPSLOCK;
- }
- break;
- case Common::KEYCODE_NUMLOCK:
- if (ev.type == Common::EVENT_KEYDOWN) {
- _modifierStates |= SCI_EVM_NUMLOCK;
- } else {
- _modifierStates &= ~SCI_EVM_NUMLOCK;
- }
- break;
- case Common::KEYCODE_SCROLLOCK:
- if (ev.type == Common::EVENT_KEYDOWN) {
- _modifierStates |= SCI_EVM_SCRLOCK;
- } else {
- _modifierStates &= ~SCI_EVM_SCRLOCK;
- }
- break;
- default:
- break;
- }
- }
- //TODO: SCI_EVM_INSERT
-
- input.buckybits =
- ((modifiers & Common::KBD_ALT) ? SCI_EVM_ALT : 0) |
- ((modifiers & Common::KBD_CTRL) ? SCI_EVM_CTRL : 0) |
- ((modifiers & Common::KBD_SHIFT) ? SCI_EVM_LSHIFT | SCI_EVM_RSHIFT : 0) |
- _modifierStates;
-
- switch (ev.type) {
- // Keyboard events
- case Common::EVENT_KEYDOWN:
- input.data = ev.kbd.keycode;
- input.character = ev.kbd.ascii;
-
- // Debug console
- if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) {
-
- ((Sci::SciEngine*)g_engine)->_console->attach();
- ((Sci::SciEngine*)g_engine)->_console->onFrame();
-
- // Clear keyboard event
- input.type = SCI_EVT_NONE;
- input.character = 0;
- input.data = 0;
- input.buckybits = 0;
-
- return input;
- }
-
- if (!(input.data & 0xFF00)) {
- // Directly accept most common keys without conversion
- input.type = SCI_EVT_KEYBOARD;
- if (input.data == Common::KEYCODE_TAB) {
- // Tab
- input.type = SCI_EVT_KEYBOARD;
- input.data = SCI_K_TAB;
- if (input.buckybits & (SCI_EVM_LSHIFT | SCI_EVM_RSHIFT))
- input.character = SCI_K_SHIFT_TAB;
- else
- input.character = SCI_K_TAB;
- }
- } else if ((input.data >= Common::KEYCODE_F1) && input.data <= Common::KEYCODE_F10) {
- // F1-F10
- input.type = SCI_EVT_KEYBOARD;
- // SCI_K_F1 == 59 << 8
- // SCI_K_SHIFT_F1 == 84 << 8
- input.data = SCI_K_F1 + ((input.data - Common::KEYCODE_F1)<<8);
- if (input.buckybits & (SCI_EVM_LSHIFT | SCI_EVM_RSHIFT))
- input.character = input.data + SCI_K_SHIFT_F1 - SCI_K_F1;
- else
- input.character = input.data;
- } else {
- // Special keys that need conversion
- input.type = SCI_EVT_KEYBOARD;
- switch (ev.kbd.keycode) {
- case Common::KEYCODE_UP:
- input.data = SCI_K_UP;
- break;
- case Common::KEYCODE_DOWN:
- input.data = SCI_K_DOWN;
- break;
- case Common::KEYCODE_RIGHT:
- input.data = SCI_K_RIGHT;
- break;
- case Common::KEYCODE_LEFT:
- input.data = SCI_K_LEFT;
- break;
- case Common::KEYCODE_INSERT:
- input.data = SCI_K_INSERT;
- break;
- case Common::KEYCODE_HOME:
- input.data = SCI_K_HOME;
- break;
- case Common::KEYCODE_END:
- input.data = SCI_K_END;
- break;
- case Common::KEYCODE_PAGEUP:
- input.data = SCI_K_PGUP;
- break;
- case Common::KEYCODE_PAGEDOWN:
- input.data = SCI_K_PGDOWN;
- break;
- case Common::KEYCODE_DELETE:
- input.data = SCI_K_DELETE;
- break;
- // Keypad keys
- case Common::KEYCODE_KP8: // up
- if (!(_modifierStates & SCI_EVM_NUMLOCK))
- input.data = SCI_K_UP;
- break;
- case Common::KEYCODE_KP2: // down
- if (!(_modifierStates & SCI_EVM_NUMLOCK))
- input.data = SCI_K_DOWN;
- break;
- case Common::KEYCODE_KP6: // right
- if (!(_modifierStates & SCI_EVM_NUMLOCK))
- input.data = SCI_K_RIGHT;
- break;
- case Common::KEYCODE_KP4: // left
- if (!(_modifierStates & SCI_EVM_NUMLOCK))
- input.data = SCI_K_LEFT;
- break;
- case Common::KEYCODE_KP5: // center
- if (!(_modifierStates & SCI_EVM_NUMLOCK))
- input.data = SCI_K_CENTER;
- break;
- default:
- input.type = SCI_EVT_NONE;
- break;
- }
- input.character = input.data;
- }
- break;
-
- // Mouse events
- case Common::EVENT_LBUTTONDOWN:
- input.type = SCI_EVT_MOUSE_PRESS;
- input.data = 1;
- drv->pointer_x = p.x;
- drv->pointer_y = p.y;
- break;
- case Common::EVENT_RBUTTONDOWN:
- input.type = SCI_EVT_MOUSE_PRESS;
- input.data = 2;
- drv->pointer_x = p.x;
- drv->pointer_y = p.y;
- break;
- case Common::EVENT_LBUTTONUP:
- input.type = SCI_EVT_MOUSE_RELEASE;
- input.data = 1;
- drv->pointer_x = p.x;
- drv->pointer_y = p.y;
- break;
- case Common::EVENT_RBUTTONUP:
- input.type = SCI_EVT_MOUSE_RELEASE;
- input.data = 2;
- drv->pointer_x = p.x;
- drv->pointer_y = p.y;
- break;
-
- // Misc events
- case Common::EVENT_QUIT:
- input.type = SCI_EVT_QUIT;
- break;
-
- default:
- break;
- }
- }
-
- return input;
-}
gfx_driver_t gfx_driver_scummvm = {
NULL,
@@ -542,7 +326,6 @@ gfx_driver_t gfx_driver_scummvm = {
scummvm_set_static_buffer,
scummvm_set_pointer,
scummvm_set_palette,
- scummvm_get_event,
NULL
};
diff --git a/engines/sci/gfx/gfx_driver.h b/engines/sci/gfx/gfx_driver.h
index 38451ad3ef..4221e4b689 100644
--- a/engines/sci/gfx/gfx_driver.h
+++ b/engines/sci/gfx/gfx_driver.h
@@ -294,15 +294,6 @@ struct gfx_driver_t { /* Graphics driver */
*/
- /*** Event management ***/
-
- sci_event_t (*get_event)(gfx_driver_t *drv);
- /* Returns the next event in the event queue for this driver
- ** Parameters: (gfx_driver_t *) drv: The driver to query
- ** Returns : (sci_event_t) The oldest event still in the driver's event
- ** queue, or the null event if there is none.
- */
-
void *state; /* Reserved for internal use */
};
diff --git a/engines/sci/gfx/gfx_support.cpp b/engines/sci/gfx/gfx_support.cpp
index e3b36b9616..1cc4a4983e 100644
--- a/engines/sci/gfx/gfx_support.cpp
+++ b/engines/sci/gfx/gfx_support.cpp
@@ -36,7 +36,8 @@ namespace Sci {
int gfx_crossblit_alpha_threshold = 128;
-inline void gfx_draw_line_buffer(byte *buffer, int linewidth, int pixelwidth, Common::Point start, Common::Point end, unsigned int color) {
+static void gfx_draw_line_buffer(byte *buffer, int linewidth, int pixelwidth,
+ Common::Point start, Common::Point end, unsigned int color) {
switch (pixelwidth) {
case 1:
diff --git a/engines/sci/gfx/gfx_tools.h b/engines/sci/gfx/gfx_tools.h
index 97451196e1..63f4d441f4 100644
--- a/engines/sci/gfx/gfx_tools.h
+++ b/engines/sci/gfx/gfx_tools.h
@@ -136,21 +136,6 @@ void gfx_draw_line_pixmap_i(gfx_pixmap_t *pxm, Common::Point start, Common::Poin
** The line is not clipped. Invalid x, y, x1, y1 values will result in memory corruption.
*/
-void gfx_draw_line_buffer(byte *buffer, int linewidth, int pixelwidth,
- Common::Point start, Common::Point end, unsigned int color);
-/* Draws a line to a linear pixel buffer
-** Parameters: (byte *) buffer: Pointer to the start of the buffer to draw to
-** (int) linewidth: Number of bytes per pixel line in the buffer
-** (int) pixelwidth: Number of bytes per pixel
-** (Common::Point) start: Starting point of the line to draw
-** (Common::Point) end: End point of the line to draw
-** (rect_t) Coordinates: the line should be drawn to (must be clipped already)
-** xl and yl describe relative offsets, as usual.
-** (unsigned int) color: The color to draw (only the lowest 8 * pixelwidth bits are relevant)
-** Returns : (void)
-** This function assumes 1 <= pixelwidth <= 4
-*/
-
void gfx_draw_box_pixmap_i(gfx_pixmap_t *pxm, rect_t box, int color);
/* Draws a filled rectangular area to a pixmap's index buffer
** Parameters: (gfx_pixmap_t *) pxm: The pixmap to draw to
diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp
index f54ed539f5..f92c3b9226 100644
--- a/engines/sci/gfx/operations.cpp
+++ b/engines/sci/gfx/operations.cpp
@@ -29,6 +29,7 @@
#include "sci/gfx/operations.h"
#include "common/system.h"
+#include "common/events.h"
namespace Sci {
@@ -463,7 +464,7 @@ static int _gfxop_init_common(gfx_state_t *state, gfx_options_t *options, void *
state->options = options;
state->disable_dirty = 0;
- state->events.clear();
+ state->_events.clear();
state->pic = state->pic_unscaled = NULL;
@@ -1472,6 +1473,203 @@ static int _gfxop_numlockify(int c) {
}
}
+static sci_event_t scummvm_get_event(gfx_driver_t *drv) {
+ static int _modifierStates = 0; // FIXME: EVIL HACK
+ sci_event_t input = { SCI_EVT_NONE, 0, 0, 0 };
+
+ Common::EventManager *em = g_system->getEventManager();
+ Common::Event ev;
+
+ bool found = em->pollEvent(ev);
+ Common::Point p = ev.mouse;
+
+ // Don't generate events for mouse movement
+ while (found && ev.type == Common::EVENT_MOUSEMOVE) {
+ drv->pointer_x = ev.mouse.x;
+ drv->pointer_y = ev.mouse.y;
+ found = em->pollEvent(ev);
+ }
+
+ if (found && !ev.synthetic && ev.type != Common::EVENT_MOUSEMOVE) {
+ int modifiers = em->getModifierState();
+
+ // We add the modifier key status to buckybits
+ // SDL sends a keydown event if a modifier key is turned on and a keyup event if it's off
+ //
+ // FIXME: This code is semi-bogus. It only records the modifier key being *pressed*.
+ // It does not track correctly whether capslock etc. is active. To do that, we
+ // would have to record the fact that the modifier was pressed in global var,
+ // and also watch for Common::EVENT_KEYUP events.
+ // But this is still not quite good enough, because not all events might
+ // pass through here (e.g. the GUI might be running with its own event loop).
+ //
+ // The best solution likely would be to add code to the EventManager class
+ // for tracking which keys are pressed and which are not...
+ if (ev.type == Common::EVENT_KEYDOWN || ev.type == Common::EVENT_KEYUP) {
+ switch (ev.kbd.keycode) {
+ case Common::KEYCODE_CAPSLOCK:
+ if (ev.type == Common::EVENT_KEYDOWN) {
+ _modifierStates |= SCI_EVM_CAPSLOCK;
+ } else {
+ _modifierStates &= ~SCI_EVM_CAPSLOCK;
+ }
+ break;
+ case Common::KEYCODE_NUMLOCK:
+ if (ev.type == Common::EVENT_KEYDOWN) {
+ _modifierStates |= SCI_EVM_NUMLOCK;
+ } else {
+ _modifierStates &= ~SCI_EVM_NUMLOCK;
+ }
+ break;
+ case Common::KEYCODE_SCROLLOCK:
+ if (ev.type == Common::EVENT_KEYDOWN) {
+ _modifierStates |= SCI_EVM_SCRLOCK;
+ } else {
+ _modifierStates &= ~SCI_EVM_SCRLOCK;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ //TODO: SCI_EVM_INSERT
+
+ input.buckybits =
+ ((modifiers & Common::KBD_ALT) ? SCI_EVM_ALT : 0) |
+ ((modifiers & Common::KBD_CTRL) ? SCI_EVM_CTRL : 0) |
+ ((modifiers & Common::KBD_SHIFT) ? SCI_EVM_LSHIFT | SCI_EVM_RSHIFT : 0) |
+ _modifierStates;
+
+ switch (ev.type) {
+ // Keyboard events
+ case Common::EVENT_KEYDOWN:
+ input.data = ev.kbd.keycode;
+ input.character = ev.kbd.ascii;
+
+ if (!(input.data & 0xFF00)) {
+ // Directly accept most common keys without conversion
+ input.type = SCI_EVT_KEYBOARD;
+ if (input.data == Common::KEYCODE_TAB) {
+ // Tab
+ input.type = SCI_EVT_KEYBOARD;
+ input.data = SCI_K_TAB;
+ if (input.buckybits & (SCI_EVM_LSHIFT | SCI_EVM_RSHIFT))
+ input.character = SCI_K_SHIFT_TAB;
+ else
+ input.character = SCI_K_TAB;
+ }
+ } else if ((input.data >= Common::KEYCODE_F1) && input.data <= Common::KEYCODE_F10) {
+ // F1-F10
+ input.type = SCI_EVT_KEYBOARD;
+ // SCI_K_F1 == 59 << 8
+ // SCI_K_SHIFT_F1 == 84 << 8
+ input.data = SCI_K_F1 + ((input.data - Common::KEYCODE_F1)<<8);
+ if (input.buckybits & (SCI_EVM_LSHIFT | SCI_EVM_RSHIFT))
+ input.character = input.data + SCI_K_SHIFT_F1 - SCI_K_F1;
+ else
+ input.character = input.data;
+ } else {
+ // Special keys that need conversion
+ input.type = SCI_EVT_KEYBOARD;
+ switch (ev.kbd.keycode) {
+ case Common::KEYCODE_UP:
+ input.data = SCI_K_UP;
+ break;
+ case Common::KEYCODE_DOWN:
+ input.data = SCI_K_DOWN;
+ break;
+ case Common::KEYCODE_RIGHT:
+ input.data = SCI_K_RIGHT;
+ break;
+ case Common::KEYCODE_LEFT:
+ input.data = SCI_K_LEFT;
+ break;
+ case Common::KEYCODE_INSERT:
+ input.data = SCI_K_INSERT;
+ break;
+ case Common::KEYCODE_HOME:
+ input.data = SCI_K_HOME;
+ break;
+ case Common::KEYCODE_END:
+ input.data = SCI_K_END;
+ break;
+ case Common::KEYCODE_PAGEUP:
+ input.data = SCI_K_PGUP;
+ break;
+ case Common::KEYCODE_PAGEDOWN:
+ input.data = SCI_K_PGDOWN;
+ break;
+ case Common::KEYCODE_DELETE:
+ input.data = SCI_K_DELETE;
+ break;
+ // Keypad keys
+ case Common::KEYCODE_KP8: // up
+ if (!(_modifierStates & SCI_EVM_NUMLOCK))
+ input.data = SCI_K_UP;
+ break;
+ case Common::KEYCODE_KP2: // down
+ if (!(_modifierStates & SCI_EVM_NUMLOCK))
+ input.data = SCI_K_DOWN;
+ break;
+ case Common::KEYCODE_KP6: // right
+ if (!(_modifierStates & SCI_EVM_NUMLOCK))
+ input.data = SCI_K_RIGHT;
+ break;
+ case Common::KEYCODE_KP4: // left
+ if (!(_modifierStates & SCI_EVM_NUMLOCK))
+ input.data = SCI_K_LEFT;
+ break;
+ case Common::KEYCODE_KP5: // center
+ if (!(_modifierStates & SCI_EVM_NUMLOCK))
+ input.data = SCI_K_CENTER;
+ break;
+ default:
+ input.type = SCI_EVT_NONE;
+ break;
+ }
+ input.character = input.data;
+ }
+ break;
+
+ // Mouse events
+ case Common::EVENT_LBUTTONDOWN:
+ input.type = SCI_EVT_MOUSE_PRESS;
+ input.data = 1;
+ drv->pointer_x = p.x;
+ drv->pointer_y = p.y;
+ break;
+ case Common::EVENT_RBUTTONDOWN:
+ input.type = SCI_EVT_MOUSE_PRESS;
+ input.data = 2;
+ drv->pointer_x = p.x;
+ drv->pointer_y = p.y;
+ break;
+ case Common::EVENT_LBUTTONUP:
+ input.type = SCI_EVT_MOUSE_RELEASE;
+ input.data = 1;
+ drv->pointer_x = p.x;
+ drv->pointer_y = p.y;
+ break;
+ case Common::EVENT_RBUTTONUP:
+ input.type = SCI_EVT_MOUSE_RELEASE;
+ input.data = 2;
+ drv->pointer_x = p.x;
+ drv->pointer_y = p.y;
+ break;
+
+ // Misc events
+ case Common::EVENT_QUIT:
+ input.type = SCI_EVT_QUIT;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return input;
+}
+
sci_event_t gfxop_get_event(gfx_state_t *state, unsigned int mask) {
sci_event_t error_event = { SCI_EVT_ERROR, 0, 0, 0 };
sci_event_t event = { 0, 0, 0, 0 };
@@ -1484,23 +1682,23 @@ sci_event_t gfxop_get_event(gfx_state_t *state, unsigned int mask) {
// Get all queued events from graphics driver
do {
- event = state->driver->get_event(state->driver);
- if (event.type)
- state->events.push_back(event);
+ event = scummvm_get_event(state->driver);
+ if (event.type != SCI_EVT_NONE)
+ state->_events.push_back(event);
} while (event.type != SCI_EVT_NONE);
// Search for matching event in queue
- Common::List<sci_event_t>::iterator iter = state->events.begin();
- while (iter != state->events.end() && !((*iter).type & mask))
+ Common::List<sci_event_t>::iterator iter = state->_events.begin();
+ while (iter != state->_events.end() && !((*iter).type & mask))
++iter;
- if (iter != state->events.end()) {
+ if (iter != state->_events.end()) {
// Event found
event = *iter;
// If not peeking at the queue, remove the event
if (!(mask & SCI_EVT_PEEK)) {
- state->events.erase(iter);
+ state->_events.erase(iter);
}
} else {
// No event found: we must return a SCI_EVT_NONE event.
diff --git a/engines/sci/gfx/operations.h b/engines/sci/gfx/operations.h
index 1928baf3a3..ad8372c510 100644
--- a/engines/sci/gfx/operations.h
+++ b/engines/sci/gfx/operations.h
@@ -122,7 +122,7 @@ struct gfx_state_t {
int pic_nr; /* Number of the current pic */
int palette_nr; /* Palette number of the current pic */
- Common::List<sci_event_t> events;
+ Common::List<sci_event_t> _events;
gfx_pixmap_t *fullscreen_override; /* An optional override picture which must have unscaled
** full-screen size, which overrides all other visibility, and