diff options
author | Filippos Karapetis | 2009-10-07 21:29:47 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-10-07 21:29:47 +0000 |
commit | 1562add63191c482acf99da61d6d8d1e2bf8903d (patch) | |
tree | 68d36e8e9219837a9febdb7791b572da9e7f3ed6 /engines/sci | |
parent | 80d136a362e667d4e8ff0754fe634eba30e0590a (diff) | |
download | scummvm-rg350-1562add63191c482acf99da61d6d8d1e2bf8903d.tar.gz scummvm-rg350-1562add63191c482acf99da61d6d8d1e2bf8903d.tar.bz2 scummvm-rg350-1562add63191c482acf99da61d6d8d1e2bf8903d.zip |
- Cleaned up the cursor code
- Renamed gui -> _gui in EngineState, for consistency
- Added a reference to SciGuiCursor in EngineState, to be used by current code
- Renamed setCursorHide -> hideCursor, setCursorShow -> showCursor
- Moved the cursor zone limiting code inside SciGuiCursor. This code is currently not functioning, as we need to call refreshPosition() before each updateScreen() call to limit the cursor position.
svn-id: r44760
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/console.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/game.cpp | 3 | ||||
-rw-r--r-- | engines/sci/engine/kevent.cpp | 23 | ||||
-rw-r--r-- | engines/sci/engine/kgraphics.cpp | 75 | ||||
-rw-r--r-- | engines/sci/engine/kmenu.cpp | 18 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/state.h | 6 | ||||
-rw-r--r-- | engines/sci/gfx/gfx_driver.cpp | 1 | ||||
-rw-r--r-- | engines/sci/gfx/operations.cpp | 50 | ||||
-rw-r--r-- | engines/sci/gfx/operations.h | 11 | ||||
-rw-r--r-- | engines/sci/gui/gui.cpp | 4 | ||||
-rw-r--r-- | engines/sci/gui/gui.h | 4 | ||||
-rw-r--r-- | engines/sci/gui/gui_cursor.cpp | 44 | ||||
-rw-r--r-- | engines/sci/gui/gui_cursor.h | 16 | ||||
-rw-r--r-- | engines/sci/gui32/gui32.cpp | 4 | ||||
-rw-r--r-- | engines/sci/gui32/gui32.h | 4 | ||||
-rw-r--r-- | engines/sci/sci.cpp | 14 |
18 files changed, 139 insertions, 148 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 7f6043d1f9..718953f8ac 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -1498,7 +1498,7 @@ bool Console::cmdShowMap(int argc, const char **argv) { case 1: case 2: case 3: - return _vm->_gamestate->gui->debugShowMap(map); + return _vm->_gamestate->_gui->debugShowMap(map); break; default: diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 43fe120db5..aa0a0dea14 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -279,9 +279,6 @@ int _reset_graphics_input(EngineState *s) { s->titlebar_port->_bgcolor.priority = 11; // Standard priority for the titlebar port #endif - Common::Point mousePos(160, 150); - s->gui->moveCursor(mousePos); - return 0; } diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index b8af6f0ab0..33a0103d6f 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -31,6 +31,7 @@ #include "sci/console.h" #include "sci/debug.h" // for g_debug_simulated_key #include "sci/gui/gui.h" +#include "sci/gui/gui_cursor.h" namespace Sci { @@ -43,6 +44,7 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { int oldx, oldy; int modifier_mask = getSciVersion() <= SCI_VERSION_01 ? SCI_EVM_ALL : SCI_EVM_NO_FOOLOCK; SegManager *segMan = s->_segMan; + Common::Point mousePos = s->_cursor->getPosition(); // If there's a simkey pending, and the game wants a keyboard event, use the // simkey instead of a normal event @@ -50,22 +52,22 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { PUT_SEL32V(obj, type, SCI_EVT_KEYBOARD); // Keyboard event PUT_SEL32V(obj, message, g_debug_simulated_key); PUT_SEL32V(obj, modifiers, SCI_EVM_NUMLOCK); // Numlock on - PUT_SEL32V(obj, x, s->gfx_state->pointer_pos.x); - PUT_SEL32V(obj, y, s->gfx_state->pointer_pos.y); + PUT_SEL32V(obj, x, mousePos.x); + PUT_SEL32V(obj, y, mousePos.y); g_debug_simulated_key = 0; return make_reg(0, 1); } - oldx = s->gfx_state->pointer_pos.x; - oldy = s->gfx_state->pointer_pos.y; + oldx = mousePos.x; + oldy = mousePos.y; e = gfxop_get_event(s->gfx_state, mask); s->parser_event = NULL_REG; // Invalidate parser event - PUT_SEL32V(obj, x, s->gfx_state->pointer_pos.x); - PUT_SEL32V(obj, y, s->gfx_state->pointer_pos.y); + PUT_SEL32V(obj, x, mousePos.x); + PUT_SEL32V(obj, y, mousePos.y); - //s->gui->moveCursor(s->gfx_state->pointer_pos.x, s->gfx_state->pointer_pos.y); + //s->_gui->moveCursor(s->gfx_state->pointer_pos.x, s->gfx_state->pointer_pos.y); switch (e.type) { case SCI_EVT_QUIT: @@ -94,11 +96,12 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { case SCI_EVT_MOUSE_RELEASE: case SCI_EVT_MOUSE_PRESS: { int extra_bits = 0; + Common::Point mousePos = s->_cursor->getPosition(); // track left buttton clicks, if requested if (e.type == SCI_EVT_MOUSE_PRESS && e.data == 1 && g_debug_track_mouse_clicks) { ((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf("Mouse clicked at %d, %d\n", - s->gfx_state->pointer_pos.x, s->gfx_state->pointer_pos.y); + mousePos.x, mousePos.y); } if (mask & e.type) { @@ -210,7 +213,7 @@ reg_t kGlobalToLocal(EngineState *s, int argc, reg_t *argv) { int16 x = GET_SEL32V(obj, x); int16 y = GET_SEL32V(obj, y); - s->gui->globalToLocal(&x, &y); + s->_gui->globalToLocal(&x, &y); PUT_SEL32V(obj, x, x); PUT_SEL32V(obj, y, y); @@ -228,7 +231,7 @@ reg_t kLocalToGlobal(EngineState *s, int argc, reg_t *argv) { int16 x = GET_SEL32V(obj, x); int16 y = GET_SEL32V(obj, y); - s->gui->localToGlobal(&x, &y); + s->_gui->localToGlobal(&x, &y); PUT_SEL32V(obj, x, x); PUT_SEL32V(obj, y, y); diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index b71f3b6462..65965a04b9 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -39,6 +39,7 @@ #include "sci/gfx/gfx_state_internal.h" // required for GfxContainer, GfxPort, GfxVisual #include "sci/gfx/seq_decoder.h" #include "sci/gui/gui.h" +#include "sci/gui/gui_cursor.h" namespace Sci { @@ -275,14 +276,14 @@ static reg_t kSetCursorSci0(EngineState *s, int argc, reg_t *argv) { if (argc >= 4) { pos.y = argv[3].toSint16(); pos.x = argv[2].toSint16(); - s->gui->setCursorPos(pos); + s->_gui->setCursorPos(pos); } if ((argc >= 2) && (argv[1].toSint16() == 0)) { cursorId = -1; } - s->gui->setCursorShape(cursorId); + s->_gui->setCursorShape(cursorId); return s->r_acc; } @@ -293,14 +294,14 @@ static reg_t kSetCursorSci11(EngineState *s, int argc, reg_t *argv) { switch (argc) { case 1: if (argv[0].isNull()) - s->gui->setCursorHide(); + s->_gui->hideCursor(); else - s->gui->setCursorShow(); + s->_gui->showCursor(); break; case 2: pos.y = argv[1].toSint16(); pos.x = argv[0].toSint16(); - s->gui->setCursorPos(pos); + s->_gui->setCursorPos(pos); break; case 4: { int16 top = argv[0].toSint16(); @@ -310,7 +311,7 @@ static reg_t kSetCursorSci11(EngineState *s, int argc, reg_t *argv) { if ((right >= left) && (bottom >= top)) { Common::Rect rect = Common::Rect(left, top, right, bottom); - gfxop_set_pointer_zone(s->gfx_state, rect); + s->_cursor->setMoveZone(rect); } else { warning("kSetCursor: Ignoring invalid mouse zone (%i, %i)-(%i, %i)", left, top, right, bottom); } @@ -349,7 +350,7 @@ reg_t kMoveCursor(EngineState *s, int argc, reg_t *argv) { if (argc == 2) { pos.y = argv[1].toSint16(); pos.x = argv[0].toSint16(); - s->gui->moveCursor(pos); + s->_gui->moveCursor(pos); } return s->r_acc; } @@ -448,27 +449,27 @@ reg_t kGraph(EngineState *s, int argc, reg_t *argv) { color = argv[5].toSint16(); // FIXME: rect must be changed to 2 Common::Point - s->gui->graphDrawLine(Common::Point(x, y), Common::Point(x1, y1), color, priority, control); + s->_gui->graphDrawLine(Common::Point(x, y), Common::Point(x1, y1), color, priority, control); break; case K_GRAPH_SAVE_BOX: rect = Common::Rect(x, y, x1, y1); flags = (argc > 5) ? argv[5].toUint16() : 0; - return s->gui->graphSaveBox(rect, flags); + return s->_gui->graphSaveBox(rect, flags); break; case K_GRAPH_RESTORE_BOX: - s->gui->graphRestoreBox(argv[1]); + s->_gui->graphRestoreBox(argv[1]); break; case K_GRAPH_FILL_BOX_BACKGROUND: rect = Common::Rect(x, y, x1, y1); - s->gui->graphFillBoxBackground(rect); + s->_gui->graphFillBoxBackground(rect); break; case K_GRAPH_FILL_BOX_FOREGROUND: rect = Common::Rect(x, y, x1, y1); - s->gui->graphFillBoxForeground(rect); + s->_gui->graphFillBoxForeground(rect); break; case K_GRAPH_FILL_BOX_ANY: @@ -478,7 +479,7 @@ reg_t kGraph(EngineState *s, int argc, reg_t *argv) { colorMask = argv[5].toUint16(); rect = Common::Rect(x, y, x1, y1); - s->gui->graphFillBox(rect, colorMask, color, priority, control); + s->_gui->graphFillBox(rect, colorMask, color, priority, control); break; case K_GRAPH_UPDATE_BOX: { @@ -551,7 +552,7 @@ reg_t kTextSize(EngineState *s, int argc, reg_t *argv) { } textWidth = dest[3].toUint16(); textHeight = dest[2].toUint16(); - s->gui->textSize(s->strSplit(text.c_str(), sep).c_str(), font_nr, maxwidth, &textWidth, &textHeight); + s->_gui->textSize(s->strSplit(text.c_str(), sep).c_str(), font_nr, maxwidth, &textWidth, &textHeight); debugC(2, kDebugLevelStrings, "GetTextSize '%s' -> %dx%d\n", text.c_str(), textWidth, textHeight); dest[2] = make_reg(0, textHeight); @@ -578,7 +579,7 @@ reg_t kWait(EngineState *s, int argc, reg_t *argv) { // FIXME: we should not be asking from the GUI to wait. The kernel sounds // like a better place - s->gui->wait(sleep_time); + s->_gui->wait(sleep_time); return s->r_acc; } @@ -897,7 +898,7 @@ reg_t kOnControl(EngineState *s, int argc, reg_t *argv) { rect.right = rect.left + 1; rect.bottom = rect.top + 1; } - return make_reg(0, s->gui->onControl(screenMask, rect)); + return make_reg(0, s->_gui->onControl(screenMask, rect)); } void _k_view_list_free_backgrounds(EngineState *s, ViewObject *list, int list_nr); @@ -928,7 +929,7 @@ reg_t kDrawPic(EngineState *s, int argc, reg_t *argv) { if (argc >= 4) EGApaletteNo = argv[3].toUint16(); - s->gui->drawPicture(pictureId, animationNr, mirroredFlag, addToFlag, EGApaletteNo); + s->_gui->drawPicture(pictureId, animationNr, mirroredFlag, addToFlag, EGApaletteNo); return s->r_acc; } @@ -1096,7 +1097,7 @@ Common::Rect get_nsrect(EngineState *s, reg_t object, byte clip) { } reg_t kSetNowSeen(EngineState *s, int argc, reg_t *argv) { - s->gui->setNowSeen(argv[0]); + s->_gui->setNowSeen(argv[0]); return s->r_acc; } @@ -1107,7 +1108,7 @@ reg_t kPalette(EngineState *s, int argc, reg_t *argv) { if (argc==3) { int resourceNo = argv[1].toUint16(); int flags = argv[2].toUint16(); - s->gui->paletteSet(resourceNo, flags); + s->_gui->paletteSet(resourceNo, flags); } break; case 2: @@ -1123,7 +1124,7 @@ reg_t kPalette(EngineState *s, int argc, reg_t *argv) { int intensity = argv[3].toUint16(); bool setPalette = (argc < 5) ? true : (argv[5].isNull()) ? true : false; - s->gui->paletteSetIntensity(fromColor, toColor, intensity, setPalette); + s->_gui->paletteSetIntensity(fromColor, toColor, intensity, setPalette); } break; } @@ -1132,14 +1133,14 @@ reg_t kPalette(EngineState *s, int argc, reg_t *argv) { int g = argv[2].toUint16(); int b = argv[3].toUint16(); - return make_reg(0, s->gui->paletteFind(r, g, b)); + return make_reg(0, s->_gui->paletteFind(r, g, b)); } case 6: if (argc==4) { int fromColor = argv[1].toUint16(); int toColor = argv[2].toUint16(); int speed = argv[3].toSint16(); - s->gui->paletteAnimate(fromColor, toColor, speed); + s->_gui->paletteAnimate(fromColor, toColor, speed); } break; case 7: @@ -1444,13 +1445,13 @@ static void _k_draw_control(EngineState *s, reg_t obj, bool hilite) { switch (type) { case K_CONTROL_BUTTON: debugC(2, kDebugLevelGraphics, "drawing button %04x:%04x to %d,%d\n", PRINT_REG(obj), x, y); - s->gui->drawControlButton(rect, obj, s->strSplit(text.c_str(), NULL).c_str(), font_nr, state, hilite); + s->_gui->drawControlButton(rect, obj, s->strSplit(text.c_str(), NULL).c_str(), font_nr, state, hilite); return; case K_CONTROL_TEXT: mode = (gfx_alignment_t) GET_SEL32V(obj, mode); debugC(2, kDebugLevelGraphics, "drawing text %04x:%04x ('%s') to %d,%d, mode=%d\n", PRINT_REG(obj), text.c_str(), x, y, mode); - s->gui->drawControlText(rect, obj, s->strSplit(text.c_str(), NULL).c_str(), font_nr, mode, state, hilite); + s->_gui->drawControlText(rect, obj, s->strSplit(text.c_str(), NULL).c_str(), font_nr, mode, state, hilite); return; case K_CONTROL_EDIT: @@ -1468,7 +1469,7 @@ static void _k_draw_control(EngineState *s, reg_t obj, bool hilite) { case K_CONTROL_ICON: debugC(2, kDebugLevelGraphics, "drawing icon control %04x:%04x to %d,%d\n", PRINT_REG(obj), x, y - 1); - s->gui->drawControlIcon(rect, obj, view, loop, cel, state, hilite); + s->_gui->drawControlIcon(rect, obj, view, loop, cel, state, hilite); return; case K_CONTROL_CONTROL: @@ -1572,7 +1573,7 @@ reg_t kAddToPic(EngineState *s, int argc, reg_t *argv) { case 0: break; case 1: - s->gui->addToPicList(argv[0], argc, argv); + s->_gui->addToPicList(argv[0], argc, argv); break; case 7: viewId = argv[0].toUint16(); @@ -1582,7 +1583,7 @@ reg_t kAddToPic(EngineState *s, int argc, reg_t *argv) { topPos = argv[4].toSint16(); priority = argv[5].toSint16(); control = argv[6].toSint16(); - s->gui->addToPicView(viewId, loopNo, celNo, leftPos, topPos, priority, control); + s->_gui->addToPicView(viewId, loopNo, celNo, leftPos, topPos, priority, control); break; default: error("kAddToPic with unsupported parameter count %d", argc); @@ -1591,7 +1592,7 @@ reg_t kAddToPic(EngineState *s, int argc, reg_t *argv) { } reg_t kGetPort(EngineState *s, int argc, reg_t *argv) { - return s->gui->getPort(); + return s->_gui->getPort(); } reg_t kSetPort(EngineState *s, int argc, reg_t *argv) { @@ -1602,7 +1603,7 @@ reg_t kSetPort(EngineState *s, int argc, reg_t *argv) { switch (argc) { case 1: portPtr = argv[0].toSint16(); - s->gui->setPort(portPtr); + s->_gui->setPort(portPtr); break; case 6: @@ -1612,7 +1613,7 @@ reg_t kSetPort(EngineState *s, int argc, reg_t *argv) { picRect.right = argv[3].toSint16(); picTop = argv[4].toSint16(); picLeft = argv[5].toSint16(); - s->gui->setPortPic(picRect, picTop, picLeft); + s->_gui->setPortPic(picRect, picTop, picLeft); break; default: @@ -1631,7 +1632,7 @@ reg_t kDrawCel(EngineState *s, int argc, reg_t *argv) { int priority = (argc > 5) ? argv[5].toUint16() : -1; int paletteNo = (argc > 6) ? argv[6].toSint16() : 0; - s->gui->drawCel(viewId, loopNo, celNo, x, y, priority, paletteNo); + s->_gui->drawCel(viewId, loopNo, celNo, x, y, priority, paletteNo); return s->r_acc; } @@ -1640,7 +1641,7 @@ reg_t kDisposeWindow(EngineState *s, int argc, reg_t *argv) { int goner_nr = argv[0].toSint16(); int arg2 = (argc != 2 || argv[2].toUint16() == 0 ? 0 : 1); - s->gui->disposeWindow(goner_nr, arg2); + s->_gui->disposeWindow(goner_nr, arg2); return s->r_acc; } @@ -1664,14 +1665,14 @@ reg_t kNewWindow(EngineState *s, int argc, reg_t *argv) { title = s->strSplit(title.c_str(), NULL); } - return s->gui->newWindow(rect1, rect2, style, priority, colorPen, colorBack, title.c_str()); + return s->_gui->newWindow(rect1, rect2, style, priority, colorPen, colorBack, title.c_str()); } reg_t kAnimate(EngineState *s, int argc, reg_t *argv) { reg_t castListReference = (argc > 0) ? argv[0] : NULL_REG; bool cycle = (argc > 1) ? ((argv[1].toUint16()) ? true : false) : false; - s->gui->animate(castListReference, cycle, argc, argv); + s->_gui->animate(castListReference, cycle, argc, argv); return s->r_acc; } @@ -1729,7 +1730,7 @@ reg_t kDisplay(EngineState *s, int argc, reg_t *argv) { text = kernel_lookup_text(s, textp, index); } - s->gui->display(s->strSplit(text.c_str()).c_str(), argc, argv); + s->_gui->display(s->strSplit(text.c_str()).c_str(), argc, argv); return s->r_acc; } @@ -1889,12 +1890,12 @@ reg_t kSetVideoMode(EngineState *s, int argc, reg_t *argv) { // New calls for SCI11. Using those is only needed when using text-codes so that one is able to change // font and/or color multiple times during kDisplay and kDrawControl reg_t kTextFonts(EngineState *s, int argc, reg_t *argv) { - s->gui->textFonts(argc, argv); + s->_gui->textFonts(argc, argv); return s->r_acc; } reg_t kTextColors(EngineState *s, int argc, reg_t *argv) { - s->gui->textColors(argc, argv); + s->_gui->textColors(argc, argv); return s->r_acc; } diff --git a/engines/sci/engine/kmenu.cpp b/engines/sci/engine/kmenu.cpp index 3a46f228a9..bde0f9e4cf 100644 --- a/engines/sci/engine/kmenu.cpp +++ b/engines/sci/engine/kmenu.cpp @@ -31,6 +31,7 @@ #include "sci/gfx/menubar.h" #include "sci/gfx/gfx_state_internal.h" // required for GfxPort, GfxVisual #include "sci/gui/gui.h" +#include "sci/gui/gui_cursor.h" namespace Sci { @@ -75,7 +76,7 @@ reg_t kDrawStatus(EngineState *s, int argc, reg_t *argv) { // Sometimes this is called without giving text, if thats the case dont process it text = s->_segMan->getString(textReference); - s->gui->drawStatus(s->strSplit(text.c_str(), NULL).c_str(), colorPen, colorBack); + s->_gui->drawStatus(s->strSplit(text.c_str(), NULL).c_str(), colorPen, colorBack); } return s->r_acc; } @@ -174,7 +175,9 @@ reg_t kMenuSelect(EngineState *s, int argc, reg_t *argv) { } } - if ((type == SCI_EVT_MOUSE_PRESS) && (s->gfx_state->pointer_pos.y < 10)) { + Common::Point cursorPos = s->_cursor->getPosition(); + + if ((type == SCI_EVT_MOUSE_PRESS) && (cursorPos.y < 10)) { menu_mode = 1; mouse_down = 1; } @@ -188,7 +191,7 @@ reg_t kMenuSelect(EngineState *s, int argc, reg_t *argv) { /* Default to menu 0, unless the mouse was used to generate this effect */ if (mouse_down) - s->_menubar->mapPointer(s->gfx_state->pointer_pos, menu_nr, item_nr, port); + s->_menubar->mapPointer(cursorPos, menu_nr, item_nr, port); else menu_nr = 0; @@ -261,9 +264,12 @@ reg_t kMenuSelect(EngineState *s, int argc, reg_t *argv) { break; case SCI_EVT_MOUSE_RELEASE: - menu_mode = (s->gfx_state->pointer_pos.y < 10); - claimed = !menu_mode && !s->_menubar->mapPointer(s->gfx_state->pointer_pos, menu_nr, item_nr, port); + { + Common::Point curMousePos = s->_cursor->getPosition(); + menu_mode = (curMousePos.y < 10); + claimed = !menu_mode && !s->_menubar->mapPointer(curMousePos, menu_nr, item_nr, port); mouse_down = 0; + } break; case SCI_EVT_MOUSE_PRESS: @@ -276,7 +282,7 @@ reg_t kMenuSelect(EngineState *s, int argc, reg_t *argv) { } if (mouse_down) - s->_menubar->mapPointer(s->gfx_state->pointer_pos, menu_nr, item_nr, port); + s->_menubar->mapPointer(s->_cursor->getPosition(), menu_nr, item_nr, port); if ((item_nr > -1 && old_item == -1) || (menu_nr != old_menu)) { /* Update menu */ diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 2e54b00d77..46b2fa94c2 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -737,7 +737,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { } // FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch. - retval = new EngineState(s->resMan, s->_kernel, s->_voc, s->_flags); + retval = new EngineState(s->resMan, s->_kernel, s->_voc, s->_gui, s->_cursor, s->_flags); // Copy some old data retval->gfx_state = s->gfx_state; @@ -797,8 +797,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { // Message state: retval->_msgState = s->_msgState; - retval->gui = s->gui; - return retval; } diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index 4e7d0944e1..96a99e1ea0 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -29,8 +29,8 @@ namespace Sci { -EngineState::EngineState(ResourceManager *res, Kernel *kernel, Vocabulary *voc, uint32 flags) -: resMan(res), _kernel(kernel), _voc(voc), _flags(flags), _dirseeker(this) { +EngineState::EngineState(ResourceManager *res, Kernel *kernel, Vocabulary *voc, SciGui *gui, SciGuiCursor *cursor, uint32 flags) +: resMan(res), _kernel(kernel), _voc(voc), _gui(gui), _cursor(cursor), _flags(flags), _dirseeker(this) { gfx_state = 0; old_screen = 0; diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index ae1f4184d3..fd7ba3cbc2 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -49,6 +49,7 @@ namespace Sci { class Menubar; class SciGui; +class SciGuiCursor; struct GfxState; struct GfxPort; @@ -159,7 +160,7 @@ private: struct EngineState : public Common::Serializable { public: - EngineState(ResourceManager *res, Kernel *kernel, Vocabulary *voc, uint32 flags); + EngineState(ResourceManager *res, Kernel *kernel, Vocabulary *voc, SciGui *gui, SciGuiCursor *cursor, uint32 flags); virtual ~EngineState(); virtual void saveLoadWithSerializer(Common::Serializer &ser); @@ -176,7 +177,8 @@ public: /* Non-VM information */ - SciGui *gui; /* Currently active Gui */ + SciGui *_gui; /* Currently active Gui */ + SciGuiCursor *_cursor; /* Cursor functions */ GfxState *gfx_state; /**< Graphics state and driver */ gfx_pixmap_t *old_screen; /**< Old screen content: Stored during kDrawPic() for kAnimate() */ diff --git a/engines/sci/gfx/gfx_driver.cpp b/engines/sci/gfx/gfx_driver.cpp index 0010983779..803d29f4f9 100644 --- a/engines/sci/gfx/gfx_driver.cpp +++ b/engines/sci/gfx/gfx_driver.cpp @@ -168,6 +168,7 @@ void GfxDriver::update(rect_t src, Common::Point dest, gfx_buffer_t buffer) { } break; case GFX_BUFFER_FRONT: { + // TODO: we need to call SciGuiCursor::refreshPosition() before each screen update to limit the mouse cursor position g_system->copyRectToScreen(_screen->_displayScreen + (src.x + src.y * _mode->xsize), _mode->xsize, dest.x, dest.y, src.width, src.height); g_system->updateScreen(); break; diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp index 67fa522be5..8401b6e2b2 100644 --- a/engines/sci/gfx/operations.cpp +++ b/engines/sci/gfx/operations.cpp @@ -249,35 +249,6 @@ static void _gfxop_draw_pixmap(GfxDriver *driver, gfx_pixmap_t *pxm, int priorit driver->drawPixmap(pxm, priority, src, clipped_dest, static_buf ? GFX_BUFFER_STATIC : GFX_BUFFER_BACK); } -static void _gfxop_full_pointer_refresh(GfxState *state) { - bool clipped = false; - Common::Point mousePoint = g_system->getEventManager()->getMousePos(); - - state->pointer_pos.x = mousePoint.x / state->driver->getMode()->scaleFactor; - state->pointer_pos.y = mousePoint.y / state->driver->getMode()->scaleFactor; - - if (state->pointer_pos.x < state->pointerZone.left) { - state->pointer_pos.x = state->pointerZone.left; - clipped = true; - } else if (state->pointer_pos.x >= state->pointerZone.right) { - state->pointer_pos.x = state->pointerZone.right - 1; - clipped = true; - } - - if (state->pointer_pos.y < state->pointerZone.top) { - state->pointer_pos.y = state->pointerZone.top; - clipped = true; - } else if (state->pointer_pos.y >= state->pointerZone.bottom) { - state->pointer_pos.y = state->pointerZone.bottom - 1; - clipped = true; - } - - // FIXME: Do this only when mouse is grabbed? - if (clipped) - g_system->warpMouse(state->pointer_pos.x * state->driver->getMode()->scaleFactor, - state->pointer_pos.y * state->driver->getMode()->scaleFactor); -} - static void _gfxop_buffer_propagate_box(GfxState *state, rect_t box, gfx_buffer_t buffer); gfx_pixmap_t *_gfxr_get_cel(GfxState *state, int nr, int *loop, int *cel, int palette) { @@ -404,7 +375,6 @@ void gfxop_init(GfxState *state, state->gfxResMan = new GfxResManager(state->options, state->driver, resMan, screen, palette); gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200)); - state->pointerZone = Common::Rect(0, 0, 320, 200); init_aux_pixmap(&(state->control_map)); init_aux_pixmap(&(state->priority_map)); @@ -720,8 +690,6 @@ static void _gfxop_draw_line_clipped(GfxState *state, Common::Point start, Commo gfx_line_style_t line_style) { int skipone = (start.x ^ end.y) & 1; // Used for simulated line stippling - _gfxop_full_pointer_refresh(state); - // First, make sure that the line is normalized if (start.y > end.y) { Common::Point swap = start; @@ -778,8 +746,6 @@ void gfxop_draw_rectangle(GfxState *state, rect_t rect, gfx_color_t color, gfx_l Common::Point upper_left_u, upper_right_u, lower_left_u, lower_right_u; Common::Point upper_left, upper_right, lower_left, lower_right; - _gfxop_full_pointer_refresh(state); - xfact = state->driver->getMode()->scaleFactor; yfact = state->driver->getMode()->scaleFactor; @@ -820,11 +786,8 @@ void gfxop_draw_box(GfxState *state, rect_t box, gfx_color_t color1, gfx_color_t gfx_rectangle_fill_t driver_shade_type; rect_t new_box; - _gfxop_full_pointer_refresh(state); - shade_type = GFX_BOX_SHADE_FLAT; - _gfxop_add_dirty(state, box); if (color1.mask & GFX_MASK_CONTROL) { @@ -904,7 +867,6 @@ static void _gfxop_buffer_propagate_box(GfxState *state, rect_t box, gfx_buffer_ extern int sci0_palette; void gfxop_clear_box(GfxState *state, rect_t box) { - _gfxop_full_pointer_refresh(state); _gfxop_add_dirty(state, box); DDIRTY(stderr, "[] clearing box %d %d %d %d\n", GFX_PRINT_RECT(box)); @@ -991,6 +953,7 @@ void gfxop_sleep(GfxState *state, uint32 msecs) { while (true) { // let backend process events and update the screen gfxop_get_event(state, SCI_EVT_PEEK); + // TODO: we need to call SciGuiCursor::refreshPosition() before each screen update to limit the mouse cursor position g_system->updateScreen(); time = g_system->getMillis(); if (time + 10 < wakeup_time) { @@ -1040,10 +1003,6 @@ void gfxop_set_pointer_view(GfxState *state, int nr, int loop, int cel, Common:: } } -void gfxop_set_pointer_zone(GfxState *state, Common::Rect rect) { - state->pointerZone = rect; -} - #define SCANCODE_ROWS_NR 3 struct scancode_row { @@ -1359,7 +1318,7 @@ sci_event_t gfxop_get_event(GfxState *state, unsigned int mask) { //sci_event_t error_event = { SCI_EVT_ERROR, 0, 0, 0 }; sci_event_t event = { 0, 0, 0, 0 }; - _gfxop_full_pointer_refresh(state); + // TODO: we need to call SciGuiCursor::refreshPosition() before each screen update to limit the mouse cursor position // Update the screen here, since it's called very often g_system->updateScreen(); @@ -1391,8 +1350,6 @@ sci_event_t gfxop_get_event(GfxState *state, unsigned int mask) { // there is no need to change it. } - _gfxop_full_pointer_refresh(state); - if (event.type == SCI_EVT_KEYBOARD) { // Do we still have to translate the key? @@ -1719,7 +1676,6 @@ TextHandle::~TextHandle() { void gfxop_draw_text(GfxState *state, TextHandle *handle, rect_t zone) { int line_height; rect_t pos; - _gfxop_full_pointer_refresh(state); if (!handle) error("Attempt to draw text with NULL handle"); @@ -1795,7 +1751,6 @@ void gfxop_draw_text(GfxState *state, TextHandle *handle, rect_t zone) { gfx_pixmap_t *gfxop_grab_pixmap(GfxState *state, rect_t area) { gfx_pixmap_t *pixmap = NULL; rect_t resultzone; // Ignored for this application - _gfxop_full_pointer_refresh(state); _gfxop_scale_rect(&area, state->driver->getMode()); _gfxop_grab_pixmap(state, &pixmap, area.x, area.y, area.width, area.height, 0, &resultzone); @@ -1809,7 +1764,6 @@ void gfxop_draw_pixmap(GfxState *state, gfx_pixmap_t *pxm, rect_t zone, Common:: if (!pxm) error("Attempt to draw NULL pixmap"); - _gfxop_full_pointer_refresh(state); _gfxop_add_dirty(state, target); _gfxop_scale_rect(&zone, state->driver->getMode()); diff --git a/engines/sci/gfx/operations.h b/engines/sci/gfx/operations.h index 15f0aeec17..d079174672 100644 --- a/engines/sci/gfx/operations.h +++ b/engines/sci/gfx/operations.h @@ -93,9 +93,6 @@ typedef Common::List<rect_t> DirtyRectList; struct GfxState { gfx_options_t *options; - Common::Point pointer_pos; /**< Mouse pointer coordinates */ - Common::Rect pointerZone; /**< Rectangle in which the pointer can move */ - rect_t clip_zone_unscaled; /**< The current UNSCALED clipping zone */ rect_t clip_zone; /**< The current SCALED clipping zone; a cached scaled version of clip_zone_unscaled */ @@ -388,14 +385,6 @@ void gfxop_set_pointer_cursor(GfxState *state, int nr); void gfxop_set_pointer_view(GfxState *state, int nr, int loop, int cel, Common::Point *hotspot); /** - * Limits the mouse movement to a given rectangle. - * - * @param[in] state The affected state - * @param[in] rect The rectangle - */ -void gfxop_set_pointer_zone(GfxState *state, Common::Rect rect); - -/** * Retrieves the next input event from the driver. * * @param[in] state The affected state diff --git a/engines/sci/gui/gui.cpp b/engines/sci/gui/gui.cpp index c3ca647e80..331666edff 100644 --- a/engines/sci/gui/gui.cpp +++ b/engines/sci/gui/gui.cpp @@ -460,11 +460,11 @@ void SciGui::setNowSeen(reg_t objectReference) { _gfx->SetNowSeen(objectReference); } -void SciGui::setCursorHide() { +void SciGui::hideCursor() { _cursor->hide(); } -void SciGui::setCursorShow() { +void SciGui::showCursor() { _cursor->show(); } diff --git a/engines/sci/gui/gui.h b/engines/sci/gui/gui.h index ee32d66e9f..33a945a634 100644 --- a/engines/sci/gui/gui.h +++ b/engines/sci/gui/gui.h @@ -84,8 +84,8 @@ public: virtual void addToPicView(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control); virtual void setNowSeen(reg_t objectReference); - virtual void setCursorHide(); - virtual void setCursorShow(); + virtual void hideCursor(); + virtual void showCursor(); virtual void setCursorShape(GuiResourceId cursorId); virtual void setCursorPos(Common::Point pos); virtual void moveCursor(Common::Point pos); diff --git a/engines/sci/gui/gui_cursor.cpp b/engines/sci/gui/gui_cursor.cpp index baf2be01f8..25ba1b9416 100644 --- a/engines/sci/gui/gui_cursor.cpp +++ b/engines/sci/gui/gui_cursor.cpp @@ -25,6 +25,7 @@ #include "graphics/cursorman.h" #include "common/util.h" +#include "common/events.h" #include "sci/sci.h" #include "sci/engine/state.h" @@ -35,16 +36,14 @@ namespace Sci { -SciGuiCursor::SciGuiCursor(EngineState *state, SciGuiPalette *palette) - : _s(state), _palette(palette) { - init(); -} +SciGuiCursor::SciGuiCursor(ResourceManager *resMan, SciGuiPalette *palette) + : _resMan(resMan), _palette(palette) { + _rawBitmap = NULL; -SciGuiCursor::~SciGuiCursor() { + setPosition(Common::Point(160, 150)); // TODO: how is that different in 640x400 games? } -void SciGuiCursor::init() { - _rawBitmap = NULL; +SciGuiCursor::~SciGuiCursor() { } void SciGuiCursor::show() { @@ -72,7 +71,7 @@ void SciGuiCursor::setShape(GuiResourceId resourceId) { } // Load cursor resource... - resource = _s->resMan->findResource(ResourceId(kResourceTypeCursor, resourceId), false); + resource = _resMan->findResource(ResourceId(kResourceTypeCursor, resourceId), false); if (!resource) error("cursor resource %d not found", resourceId); if (resource->size != SCI_CURSOR_SCI0_RESOURCESIZE) @@ -117,4 +116,33 @@ void SciGuiCursor::setPosition(Common::Point pos) { g_system->warpMouse(pos.x, pos.y); } +Common::Point SciGuiCursor::getPosition() { + return g_system->getEventManager()->getMousePos(); +} + +void SciGuiCursor::refreshPosition() { + bool clipped = false; + Common::Point mousePoint = getPosition(); + + if (mousePoint.x < _moveZone.left) { + mousePoint.x = _moveZone.left; + clipped = true; + } else if (mousePoint.x >= _moveZone.right) { + mousePoint.x = _moveZone.right - 1; + clipped = true; + } + + if (mousePoint.y < _moveZone.top) { + mousePoint.y = _moveZone.top; + clipped = true; + } else if (mousePoint.y >= _moveZone.bottom) { + mousePoint.y = _moveZone.bottom - 1; + clipped = true; + } + + // FIXME: Do this only when mouse is grabbed? + if (clipped) + g_system->warpMouse(mousePoint.x, mousePoint.y); +} + } // End of namespace Sci diff --git a/engines/sci/gui/gui_cursor.h b/engines/sci/gui/gui_cursor.h index 2a14f9e5e5..98ca7109a6 100644 --- a/engines/sci/gui/gui_cursor.h +++ b/engines/sci/gui/gui_cursor.h @@ -39,22 +39,30 @@ class SciGuiView; class SciGuiPalette; class SciGuiCursor { public: - SciGuiCursor(EngineState *state, SciGuiPalette *palette); + SciGuiCursor(ResourceManager *resMan, SciGuiPalette *palette); ~SciGuiCursor(); void show(); void hide(); void setShape(GuiResourceId resourceId); void setPosition(Common::Point pos); + Common::Point getPosition(); + void refreshPosition(); -private: - void init(); + /** + * Limits the mouse movement to a given rectangle. + * + * @param[in] rect The rectangle + */ + void setMoveZone(Common::Rect zone) { _moveZone = zone; } - EngineState *_s; +private: + ResourceManager *_resMan; SciGuiScreen *_screen; SciGuiPalette *_palette; byte *_rawBitmap; + Common::Rect _moveZone; // Rectangle in which the pointer can move }; } // End of namespace Sci diff --git a/engines/sci/gui32/gui32.cpp b/engines/sci/gui32/gui32.cpp index 329d55db28..1d831273f4 100644 --- a/engines/sci/gui32/gui32.cpp +++ b/engines/sci/gui32/gui32.cpp @@ -2002,11 +2002,11 @@ void SciGui32::setNowSeen(reg_t objectReference) { _k_set_now_seen(objectReference); } -void SciGui32::setCursorHide() { +void SciGui32::hideCursor() { CursorMan.showMouse(false); } -void SciGui32::setCursorShow() { +void SciGui32::showCursor() { CursorMan.showMouse(true); } diff --git a/engines/sci/gui32/gui32.h b/engines/sci/gui32/gui32.h index f134e86fba..b944f44723 100644 --- a/engines/sci/gui32/gui32.h +++ b/engines/sci/gui32/gui32.h @@ -77,8 +77,8 @@ public: void addToPicView(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control); void setNowSeen(reg_t objectReference); - void setCursorHide(); - void setCursorShow(); + void hideCursor(); + void showCursor(); void setCursorShape(GuiResourceId cursorId); void setCursorPos(Common::Point pos); void moveCursor(Common::Point pos); diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index 9ffbb4cee2..28172f1915 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -137,7 +137,8 @@ Common::Error SciEngine::run() { _kernel = new Kernel(_resMan); _vocabulary = new Vocabulary(_resMan); - _gamestate = new EngineState(_resMan, _kernel, _vocabulary, flags); + // we'll set the gui and cursor below + _gamestate = new EngineState(_resMan, _kernel, _vocabulary, NULL, NULL, flags); if (script_init_engine(_gamestate)) return Common::kUnknownError; @@ -159,11 +160,14 @@ Common::Error SciEngine::run() { SciGuiScreen *screen = new SciGuiScreen(); SciGuiPalette *palette = new SciGuiPalette(_gamestate, screen); - SciGuiCursor *cursor = new SciGuiCursor(_gamestate, palette); + SciGuiCursor *cursor = new SciGuiCursor(_resMan, palette); + + _gamestate->_cursor = cursor; + _gamestate->_cursor->setMoveZone(Common::Rect(0, 0, 320, 200)); // Gui change - //_gamestate->gui = new SciGui(_gamestate, screen, palette, cursor); // new - _gamestate->gui = new SciGui32(_gamestate, screen, palette, cursor); // old + //_gamestate->_gui = new SciGui(_gamestate, screen, palette, cursor); // new + _gamestate->_gui = new SciGui32(_gamestate, screen, palette, cursor); // old // Assign default values to the config manager, in case settings are missing ConfMan.registerDefault("dither_mode", "0"); @@ -196,7 +200,7 @@ Common::Error SciEngine::run() { return Common::kUnknownError; } - _gamestate->gui->init(_kernel->usesOldGfxFunctions()); + _gamestate->_gui->init(_kernel->usesOldGfxFunctions()); printf("Emulating SCI version %s\n", getSciVersionDesc(getSciVersion()).c_str()); |