aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjörn Andersson2005-02-28 14:03:53 +0000
committerTorbjörn Andersson2005-02-28 14:03:53 +0000
commit58dc309969ff0cc36a86772ea8707f2af78909e2 (patch)
treec33308dd38a371ef1a927d3a479bc429d195ec26
parente50aca32a843f4a28a0353b841abc339e24c7fa0 (diff)
downloadscummvm-rg350-58dc309969ff0cc36a86772ea8707f2af78909e2.tar.gz
scummvm-rg350-58dc309969ff0cc36a86772ea8707f2af78909e2.tar.bz2
scummvm-rg350-58dc309969ff0cc36a86772ea8707f2af78909e2.zip
And, finally, the change I meant to before I got side-tracked: Use
ScummVM's "Rect" data type in the mouse list. The benefit of this is that we can then use the contains() function in checkMouseList(), which makes the code a bit less eye-watering. svn-id: r16961
-rw-r--r--sword2/mouse.cpp40
-rw-r--r--sword2/mouse.h24
2 files changed, 23 insertions, 41 deletions
diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp
index 0bfe918f2e..6254642c64 100644
--- a/sword2/mouse.cpp
+++ b/sword2/mouse.cpp
@@ -132,20 +132,27 @@ void Mouse::registerMouse(ObjectMouse *ob_mouse, BuildUnit *build_unit) {
assert(_curMouse < TOTAL_mouse_list);
if (build_unit) {
- _mouseList[_curMouse].x1 = build_unit->x;
- _mouseList[_curMouse].y1 = build_unit->y;
- _mouseList[_curMouse].x2 = build_unit->x + build_unit->scaled_width;
- _mouseList[_curMouse].y2 = build_unit->y + build_unit->scaled_height;
+ _mouseList[_curMouse].rect.left = build_unit->x;
+ _mouseList[_curMouse].rect.top = build_unit->y;
+ _mouseList[_curMouse].rect.right = 1 + build_unit->x + build_unit->scaled_width;
+ _mouseList[_curMouse].rect.bottom = 1 + build_unit->y + build_unit->scaled_height;
} else {
- _mouseList[_curMouse].x1 = ob_mouse->x1;
- _mouseList[_curMouse].y1 = ob_mouse->y1;
- _mouseList[_curMouse].x2 = ob_mouse->x2;
- _mouseList[_curMouse].y2 = ob_mouse->y2;
+ _mouseList[_curMouse].rect.left = ob_mouse->x1;
+ _mouseList[_curMouse].rect.top = ob_mouse->y1;
+ _mouseList[_curMouse].rect.right = 1 + ob_mouse->x2;
+ _mouseList[_curMouse].rect.bottom = 1 + ob_mouse->y2;
}
_mouseList[_curMouse].priority = ob_mouse->priority;
_mouseList[_curMouse].pointer = ob_mouse->pointer;
+ // Change all COGS pointers to CROSHAIR. I'm guessing that this was a
+ // design decision made in mid-development and they didn't want to go
+ // back and re-generate the resource files.
+
+ if (_mouseList[_curMouse].pointer == USE)
+ _mouseList[_curMouse].pointer = CROSHAIR;
+
// Check if pointer text field is set due to previous object using this
// slot (ie. not correct for this one)
@@ -158,11 +165,6 @@ void Mouse::registerMouse(ObjectMouse *ob_mouse, BuildUnit *build_unit) {
// Get id from system variable 'id' which is correct for current object
_mouseList[_curMouse].id = Logic::_scriptVars[ID];
- // Not using sprite as detection mask - this is only done from
- // fnRegisterFrame()
- _mouseList[_curMouse].anim_resource = 0;
- _mouseList[_curMouse].anim_pc = 0;
-
_curMouse++;
}
@@ -966,24 +968,18 @@ void Mouse::setObjectHeld(uint32 res) {
uint32 Mouse::checkMouseList() {
ScreenInfo *screenInfo = _vm->_screen->getScreenInfo();
+ Common::Point mousePos(_pos.x + screenInfo->scroll_offset_x, _pos.y + screenInfo->scroll_offset_y);
+
// Number of priorities subject to implementation needs
for (int priority = 0; priority < 10; priority++) {
for (uint i = 0; i < _curMouse; i++) {
// If the mouse pointer is over this
// mouse-detection-box
- if (_mouseList[i].priority == priority &&
- _pos.x + screenInfo->scroll_offset_x >= _mouseList[i].x1 &&
- _pos.x + screenInfo->scroll_offset_x <= _mouseList[i].x2 &&
- _pos.y + screenInfo->scroll_offset_y >= _mouseList[i].y1 &&
- _pos.y + screenInfo->scroll_offset_y <= _mouseList[i].y2) {
+ if (_mouseList[i].priority == priority && _mouseList[i].rect.contains(mousePos)) {
// Record id
_mouseTouching = _mouseList[i].id;
- // Change all COGS pointers to CROSHAIR
- if (_mouseList[i].pointer == USE)
- _mouseList[i].pointer = CROSHAIR;
-
createPointerText(_mouseList[i].pointer_text, _mouseList[i].pointer);
// Return pointer type
diff --git a/sword2/mouse.h b/sword2/mouse.h
index a3d55d278b..54ead36198 100644
--- a/sword2/mouse.h
+++ b/sword2/mouse.h
@@ -85,31 +85,17 @@ struct MouseAnim {
// sprite is to act as mouse detection mask)
struct MouseUnit {
- // Top-left and bottom-right of mouse area. These coords are inclusive
- int32 x1;
- int32 y1;
- int32 x2;
- int32 y2;
+ // Basically the same information as in ObjectMouse, except the
+ // coordinates are adjusted to conform to standard ScummVM usage.
+ Common::Rect rect;
int32 priority;
-
- // type (or resource id?) of pointer used over this area
int32 pointer;
- // up to here, this is basically a copy of the ObjectMouse
- // structure, but then we have...
+ // In addition, we need an id when checking the mouse list, and a
+ // text id for mouse-overs.
- // object id, used when checking mouse list
int32 id;
-
- // resource id of animation file (if sprite to be used as mask) -
- // otherwise 0
- int32 anim_resource;
-
- // current frame number of animation
- int32 anim_pc;
-
- // local id of text line to print when pointer highlights an object
int32 pointer_text;
};