aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/event.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/event.cpp')
-rw-r--r--engines/sci/event.cpp113
1 files changed, 89 insertions, 24 deletions
diff --git a/engines/sci/event.cpp b/engines/sci/event.cpp
index 9a87c6de0b..e365296914 100644
--- a/engines/sci/event.cpp
+++ b/engines/sci/event.cpp
@@ -29,6 +29,10 @@
#include "sci/console.h"
#include "sci/engine/state.h"
#include "sci/engine/kernel.h"
+#ifdef ENABLE_SCI32
+#include "sci/graphics/cursor32.h"
+#include "sci/graphics/frameout.h"
+#endif
#include "sci/graphics/screen.h"
namespace Sci {
@@ -105,8 +109,12 @@ static const MouseEventConversion mouseEventMappings[] = {
{ Common::EVENT_MBUTTONUP, SCI_EVENT_MOUSE_RELEASE }
};
-EventManager::EventManager(bool fontIsExtended) : _fontIsExtended(fontIsExtended) {
-}
+EventManager::EventManager(bool fontIsExtended) :
+ _fontIsExtended(fontIsExtended)
+#ifdef ENABLE_SCI32
+ , _hotRectanglesActive(false)
+#endif
+ {}
EventManager::~EventManager() {
}
@@ -133,8 +141,13 @@ static int altify(int ch) {
}
SciEvent EventManager::getScummVMEvent() {
- SciEvent input = { SCI_EVENT_NONE, 0, 0, Common::Point(0, 0) };
- SciEvent noEvent = { SCI_EVENT_NONE, 0, 0, Common::Point(0, 0) };
+#ifdef ENABLE_SCI32
+ SciEvent input = { SCI_EVENT_NONE, 0, 0, Common::Point(), Common::Point(), -1 };
+ SciEvent noEvent = { SCI_EVENT_NONE, 0, 0, Common::Point(), Common::Point(), -1 };
+#else
+ SciEvent input = { SCI_EVENT_NONE, 0, 0, Common::Point() };
+ SciEvent noEvent = { SCI_EVENT_NONE, 0, 0, Common::Point() };
+#endif
Common::EventManager *em = g_system->getEventManager();
Common::Event ev;
@@ -155,7 +168,29 @@ SciEvent EventManager::getScummVMEvent() {
// via pollEvent.
// We also adjust the position based on the scaling of the screen.
Common::Point mousePos = em->getMousePos();
- g_sci->_gfxScreen->adjustBackUpscaledCoordinates(mousePos.y, mousePos.x);
+
+#if ENABLE_SCI32
+ if (getSciVersion() >= SCI_VERSION_2) {
+ const Buffer &screen = g_sci->_gfxFrameout->getCurrentBuffer();
+
+ // This will clamp `mousePos` according to the restricted zone,
+ // so any cursor or screen item associated with the mouse position
+ // does not bounce when it hits the edge (or ignore the edge)
+ g_sci->_gfxCursor32->deviceMoved(mousePos);
+
+ Common::Point mousePosSci = mousePos;
+ mulru(mousePosSci, Ratio(screen.scriptWidth, screen.screenWidth), Ratio(screen.scriptHeight, screen.screenHeight));
+ noEvent.mousePosSci = input.mousePosSci = mousePosSci;
+
+ if (_hotRectanglesActive) {
+ checkHotRectangles(mousePosSci);
+ }
+ } else {
+#endif
+ g_sci->_gfxScreen->adjustBackUpscaledCoordinates(mousePos.y, mousePos.x);
+#if ENABLE_SCI32
+ }
+#endif
noEvent.mousePos = input.mousePos = mousePos;
@@ -168,7 +203,7 @@ SciEvent EventManager::getScummVMEvent() {
return noEvent;
}
- if (ev.type == Common::EVENT_QUIT) {
+ if (ev.type == Common::EVENT_QUIT || ev.type == Common::EVENT_RTL) {
input.type = SCI_EVENT_QUIT;
return input;
}
@@ -302,6 +337,11 @@ SciEvent EventManager::getScummVMEvent() {
input.character = altify(input.character);
if (getSciVersion() <= SCI_VERSION_1_MIDDLE && (scummVMKeyFlags & Common::KBD_CTRL) && input.character > 0 && input.character < 27)
input.character += 96; // 0x01 -> 'a'
+#ifdef ENABLE_SCI32
+ if (getSciVersion() >= SCI_VERSION_2 && (scummVMKeyFlags & Common::KBD_CTRL) && input.character == 'c') {
+ input.character = SCI_KEY_ETX;
+ }
+#endif
// If no actual key was pressed (e.g. if only a modifier key was pressed),
// ignore the event
@@ -328,10 +368,16 @@ void EventManager::updateScreen() {
}
}
-SciEvent EventManager::getSciEvent(unsigned int mask) {
- SciEvent event = { SCI_EVENT_NONE, 0, 0, Common::Point(0, 0) };
+SciEvent EventManager::getSciEvent(uint32 mask) {
+#ifdef ENABLE_SCI32
+ SciEvent event = { SCI_EVENT_NONE, 0, 0, Common::Point(), Common::Point(), -1 };
+#else
+ SciEvent event = { SCI_EVENT_NONE, 0, 0, Common::Point() };
+#endif
- EventManager::updateScreen();
+ if (getSciVersion() < SCI_VERSION_2) {
+ updateScreen();
+ }
// Get all queued events from graphics driver
do {
@@ -362,24 +408,43 @@ SciEvent EventManager::getSciEvent(unsigned int mask) {
return event;
}
-void SciEngine::sleep(uint32 msecs) {
- uint32 time;
- const uint32 wakeUpTime = g_system->getMillis() + msecs;
-
- while (true) {
- // let backend process events and update the screen
- _eventMan->getSciEvent(SCI_EVENT_PEEK);
- time = g_system->getMillis();
- if (time + 10 < wakeUpTime) {
- g_system->delayMillis(10);
- } else {
- if (time < wakeUpTime)
- g_system->delayMillis(wakeUpTime - time);
- break;
+#ifdef ENABLE_SCI32
+void EventManager::setHotRectanglesActive(const bool active) {
+ _hotRectanglesActive = active;
+}
+
+void EventManager::setHotRectangles(const Common::Array<Common::Rect> &rects) {
+ _hotRects = rects;
+ _activeRectIndex = -1;
+}
+
+void EventManager::checkHotRectangles(const Common::Point &mousePosition) {
+ int lastActiveRectIndex = _activeRectIndex;
+ _activeRectIndex = -1;
+
+ for (int16 i = 0; i < (int16)_hotRects.size(); ++i) {
+ if (_hotRects[i].contains(mousePosition)) {
+ _activeRectIndex = i;
+ if (i != lastActiveRectIndex) {
+ SciEvent hotRectEvent;
+ hotRectEvent.type = SCI_EVENT_HOT_RECTANGLE;
+ hotRectEvent.hotRectangleIndex = i;
+ _events.push_front(hotRectEvent);
+ break;
+ }
+
+ lastActiveRectIndex = _activeRectIndex;
}
+ }
+ if (lastActiveRectIndex != _activeRectIndex && lastActiveRectIndex != -1) {
+ _activeRectIndex = -1;
+ SciEvent hotRectEvent;
+ hotRectEvent.type = SCI_EVENT_HOT_RECTANGLE;
+ hotRectEvent.hotRectangleIndex = -1;
+ _events.push_front(hotRectEvent);
}
}
-
+#endif
} // End of namespace Sci