aboutsummaryrefslogtreecommitdiff
path: root/engines/prince/cursor.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2018-05-04 10:17:43 +0200
committerEugene Sandulenko2018-05-05 23:17:34 +0200
commit951c365591bd75e8b2a16eb96c32a24c232153d4 (patch)
tree42b545bb8ca8868c8d5c2bc584976ceb33790ab7 /engines/prince/cursor.cpp
parentfaf579c48ffe7dfb8f49130cf30b47f27156acc3 (diff)
downloadscummvm-rg350-951c365591bd75e8b2a16eb96c32a24c232153d4.tar.gz
scummvm-rg350-951c365591bd75e8b2a16eb96c32a24c232153d4.tar.bz2
scummvm-rg350-951c365591bd75e8b2a16eb96c32a24c232153d4.zip
PRINCE: Move cursor manipulation to cursor.cpp
Diffstat (limited to 'engines/prince/cursor.cpp')
-rw-r--r--engines/prince/cursor.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/engines/prince/cursor.cpp b/engines/prince/cursor.cpp
index ab3a52eaa2..a4e58dc4a2 100644
--- a/engines/prince/cursor.cpp
+++ b/engines/prince/cursor.cpp
@@ -20,7 +20,12 @@
*
*/
+#include "graphics/cursorman.h"
+
+#include "prince/prince.h"
#include "prince/cursor.h"
+#include "prince/debugger.h"
+#include "prince/script.h"
#include "common/debug.h"
@@ -51,4 +56,98 @@ bool Cursor::loadStream(Common::SeekableReadStream &stream) {
return true;
}
+void PrinceEngine::changeCursor(uint16 curId) {
+ _debugger->_cursorNr = curId;
+ _mouseFlag = curId;
+ _flags->setFlagValue(Flags::MOUSEENABLED, curId);
+
+ const Graphics::Surface *curSurface = nullptr;
+
+ switch (curId) {
+ default:
+ error("Unknown cursor Id: %d", curId);
+ case 0:
+ CursorMan.showMouse(false);
+ _optionsFlag = 0;
+ _selectedMob = -1;
+ return;
+ case 1:
+ curSurface = _cursor1->getSurface();
+ break;
+ case 2:
+ curSurface = _cursor2;
+ break;
+ case 3:
+ curSurface = _cursor3->getSurface();
+ Common::Point mousePos = _system->getEventManager()->getMousePos();
+ mousePos.x = CLIP(mousePos.x, (int16) 315, (int16) 639);
+ mousePos.y = CLIP(mousePos.y, (int16) 0, (int16) 170);
+ _system->warpMouse(mousePos.x, mousePos.y);
+ break;
+ }
+
+ CursorMan.replaceCursorPalette(_roomBmp->getPalette(), 0, 255);
+ CursorMan.replaceCursor(
+ curSurface->getBasePtr(0, 0),
+ curSurface->w, curSurface->h,
+ 0, 0,
+ 255, false,
+ &curSurface->format
+ );
+ CursorMan.showMouse(true);
+}
+
+void PrinceEngine::makeInvCursor(int itemNr) {
+ const Graphics::Surface *cur1Surface = _cursor1->getSurface();
+ int cur1W = cur1Surface->w;
+ int cur1H = cur1Surface->h;
+ const Common::Rect cur1Rect(0, 0, cur1W, cur1H);
+
+ const Graphics::Surface *itemSurface = _allInvList[itemNr].getSurface();
+ int itemW = itemSurface->w;
+ int itemH = itemSurface->h;
+
+ int cur2W = cur1W + itemW / 2;
+ int cur2H = cur1H + itemH / 2;
+
+ if (_cursor2 != nullptr) {
+ _cursor2->free();
+ delete _cursor2;
+ }
+ _cursor2 = new Graphics::Surface();
+ _cursor2->create(cur2W, cur2H, Graphics::PixelFormat::createFormatCLUT8());
+ Common::Rect cur2Rect(0, 0, cur2W, cur2H);
+ _cursor2->fillRect(cur2Rect, 255);
+ _cursor2->copyRectToSurface(*cur1Surface, 0, 0, cur1Rect);
+
+ const byte *src1 = (const byte *)itemSurface->getBasePtr(0, 0);
+ byte *dst1 = (byte *)_cursor2->getBasePtr(cur1W, cur1H);
+
+ if (itemH % 2) {
+ itemH--;
+ }
+ if (itemW % 2) {
+ itemW--;
+ }
+
+ for (int y = 0; y < itemH; y++) {
+ const byte *src2 = src1;
+ byte *dst2 = dst1;
+ if (y % 2 == 0) {
+ for (int x = 0; x < itemW; x++, src2++) {
+ if (x % 2 == 0) {
+ if (*src2) {
+ *dst2 = *src2;
+ } else {
+ *dst2 = 255;
+ }
+ dst2++;
+ }
+ }
+ dst1 += _cursor2->pitch;
+ }
+ src1 += itemSurface->pitch;
+ }
+}
+
} // End of namespace Prince