diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/cge2/cge2.h | 1 | ||||
-rw-r--r-- | engines/cge2/events.cpp | 55 | ||||
-rw-r--r-- | engines/cge2/events.h | 2 | ||||
-rw-r--r-- | engines/cge2/talk.cpp | 14 |
4 files changed, 37 insertions, 35 deletions
diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 968fe2bb41..611976819b 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -139,6 +139,7 @@ public: long det(const V2D &a, const V2D &b, const V2D &c); int sgn(long n); int mapCross(const V2D &a, const V2D &b); + Sprite *spriteAt(V2D pos); void setEye(const V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index a143c77a7d..79455aff66 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -62,7 +62,7 @@ void Keyboard::newKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ -Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { +Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(NULL), _hold(NULL), _hx(0), _point(_vm), _vm(vm) { _hold = NULL; _hx = 0; _hy = 0; @@ -181,42 +181,31 @@ void EventManager::poll() { void EventManager::handleEvents() { while (_eventQueueTail != _eventQueueHead) { CGE2Event e = _eventQueue[_eventQueueTail]; + _vm->_mouse->_point = V2D(_vm, e._x, e._y); if (e._mask) { - if (_vm->_mouse->_hold && e._spritePtr != _vm->_mouse->_hold) - _vm->_mouse->_hold->touch(e._mask | kEventAttn, e._x - _vm->_mouse->_hold->_pos2D.x, e._y - _vm->_mouse->_hold->_pos2D.y, e._keyCode); - - // update mouse cursor position - if (e._mask & kMouseRoll) - _vm->_mouse->gotoxyz(e._x, e._y); + if (e._mask & kMouseMask) { + e._spritePtr = _vm->spriteAt(_vm->_mouse->_point); + e._x += (_vm->_mouse->_siz.x >> 1); + e._y -= _vm->_mouse->_siz.y; + if (_vm->_mouse->_hold && e._spritePtr != _vm->_mouse->_hold) { + _vm->_mouse->_hold->touch(e._mask | kEventAttn, + e._x - _vm->_mouse->_hold->_pos2D.x, e._y - _vm->_mouse->_hold->_pos2D.y, e._keyCode); + } + // update mouse cursor position + if (e._mask & kMouseRoll) + _vm->_mouse->gotoxyz(V2D(_vm, e._x, e._y)); + } // activate current touched SPRITE if (e._spritePtr) { if (e._mask & kEventKeyb) - e._spritePtr->touch(e._mask, e._x, e._y, e._keyCode); - else - e._spritePtr->touch(e._mask, e._x - e._spritePtr->_pos2D.x, e._y - e._spritePtr->_pos2D.y, e._keyCode); - } else if (_vm->_sys) - _vm->_sys->touch(e._mask, V2D(_vm, e._x, e._y), e._keyCode); - - if (e._mask & kMouseLeftDown) { - _vm->_mouse->_hold = e._spritePtr; - if (_vm->_mouse->_hold) { - _vm->_mouse->_hold->_flags._hold = true; - - if (_vm->_mouse->_hold->_flags._drag) { - _vm->_mouse->_hx = e._x - _vm->_mouse->_hold->_pos2D.x; - _vm->_mouse->_hy = e._y - _vm->_mouse->_hold->_pos2D.y; - } + e._spritePtr->touch(e._mask, _vm->_mouse->_point.x, _vm->_mouse->_point.y, e._keyCode); + else { + V2D temp = _vm->_mouse->_point - e._spritePtr->_pos2D; + e._spritePtr->touch(e._mask, temp.x, temp.y, e._keyCode); } - } - - if (e._mask & kMouseLeftUp) { - if (_vm->_mouse->_hold) { - _vm->_mouse->_hold->_flags._hold = false; - _vm->_mouse->_hold = NULL; - } - } - ///Touched = e.Ptr; + } else if (_vm->_sys) + _vm->_sys->touch(e._mask, _vm->_mouse->_point, e._keyCode); // discard Text if button released if (e._mask & (kMouseLeftUp | kMouseRightUp)) @@ -224,10 +213,6 @@ void EventManager::handleEvents() { } _eventQueueTail = (_eventQueueTail + 1) % kEventMax; } - if (_vm->_mouse->_hold) { - if (_vm->_mouse->_hold->_flags._drag) - _vm->_mouse->_hold->gotoxyz(_vm->_mouse->_pos2D.x - _vm->_mouse->_hx, kWorldHeight - _vm->_mouse->_pos2D.y - _vm->_mouse->_hy); - } } void EventManager::clearEvent(Sprite *spr) { diff --git a/engines/cge2/events.h b/engines/cge2/events.h index 39fbf536b9..2522c34049 100644 --- a/engines/cge2/events.h +++ b/engines/cge2/events.h @@ -45,6 +45,7 @@ enum EventMask { kMouseRightDown = 1 << 3, kMouseRightUp = 1 << 4, kEventAttn = 1 << 5, + kMouseMask = (kMouseRoll | kMouseLeftDown | kMouseLeftUp | kMouseRightDown | kMouseRightUp), kEventKeyb = 1 << 7 }; @@ -75,6 +76,7 @@ struct CGE2Event { class Mouse : public Sprite { public: + V2D _point; Sprite *_hold; bool _active; int _hx; diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index a6d9945665..54e9ea3764 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -34,6 +34,20 @@ void CGE2Engine::setAutoColors() { warning("STUB: CGE2Engine::setAutoColors()"); } +Sprite *CGE2Engine::spriteAt(V2D pos) { + Sprite *spr; + + for (spr = _vga->_showQ->last(); spr; spr = spr->_prev) { + if (!spr->_flags._hide && !spr->_flags._tran) { + V2D temp = pos - spr->_pos2D; + if (spr->getShp()->solidAt(temp.x, temp.y)) + break; + } + } + + return spr; +} + Font::Font(CGE2Engine *vm) : _vm(vm) { _map = new uint8[kMapSize]; _pos = new uint16[kPosSize]; |