1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "graphics/cursorman.h"
#include "prince/prince.h"
#include "prince/cursor.h"
#include "prince/debugger.h"
#include "prince/script.h"
#include "common/debug.h"
namespace Prince {
Cursor::Cursor() : _surface(nullptr) {
}
Cursor::~Cursor() {
if (_surface != nullptr) {
_surface->free();
delete _surface;
_surface = nullptr;
}
}
bool Cursor::loadStream(Common::SeekableReadStream &stream) {
stream.skip(4);
uint16 width = stream.readUint16LE();
uint16 height = stream.readUint16LE();
_surface = new Graphics::Surface();
_surface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
for (int h = 0; h < height; h++) {
stream.read(_surface->getBasePtr(0, h), width);
}
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
|