mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-15 16:58:01 +00:00
SHERLOCK: RT: Generalise code for joining cursor and images as a cursor
This commit is contained in:
parent
cb9aab65b0
commit
9e545df252
@ -101,36 +101,48 @@ void Events::setCursor(const Graphics::Surface &src, int hotspotX, int hotspotY)
|
||||
showCursor();
|
||||
}
|
||||
|
||||
void Events::setCursor(CursorId cursorId, const Graphics::Surface &surface) {
|
||||
void Events::setCursor(CursorId cursorId, const Common::Point &cursorPos, const Graphics::Surface &surface) {
|
||||
_cursorId = cursorId;
|
||||
|
||||
int hotspotX, hotspotY;
|
||||
if (cursorId == MAGNIFY) {
|
||||
hotspotX = 8;
|
||||
hotspotY = 8;
|
||||
} else {
|
||||
hotspotX = 0;
|
||||
hotspotY = 0;
|
||||
}
|
||||
|
||||
// Get the standard cursor frame
|
||||
Graphics::Surface &surface2 = (*_cursorImages)[cursorId]._frame;
|
||||
Graphics::Surface &cursorImg = (*_cursorImages)[cursorId]._frame;
|
||||
|
||||
// If the X pos for the cursor image is -100, this is a special value to indicate
|
||||
// the cursor should be horizontally centered
|
||||
Common::Point cursorPt = cursorPos;
|
||||
if (cursorPos.x == -100)
|
||||
cursorPt.x = (surface.w - cursorImg.w) / 2;
|
||||
|
||||
// Figure total bounds needed for cursor image and passed image
|
||||
Common::Rect bounds(surface.w, surface.h);
|
||||
bounds.extend(Common::Rect(cursorPt.x, cursorPt.y, cursorPt.x + cursorImg.w, cursorPt.y + cursorImg.h));
|
||||
Common::Rect r = bounds;
|
||||
r.moveTo(0, 0);
|
||||
|
||||
// Form a single surface containing both frames
|
||||
int maxWidth = MAX(surface.w, surface2.w);
|
||||
Graphics::Surface s;
|
||||
s.create(maxWidth, surface.h + surface2.h, Graphics::PixelFormat::createFormatCLUT8());
|
||||
s.fillRect(Common::Rect(0, 0, maxWidth, surface.h + surface2.h), TRANSPARENCY);
|
||||
s.create(r.width(), r.height(), Graphics::PixelFormat::createFormatCLUT8());
|
||||
s.fillRect(r, TRANSPARENCY);
|
||||
|
||||
s.copyRectToSurface(surface, (maxWidth - surface.w) / 2, 0, Common::Rect(0, 0, surface.w, surface.h));
|
||||
s.copyRectToSurface(surface2, (maxWidth - surface2.w) / 2, surface.h, Common::Rect(0, 0, surface2.w, surface2.h));
|
||||
// Draw the passed image
|
||||
Common::Point drawPos;
|
||||
if (cursorPt.x < 0)
|
||||
drawPos.x = -cursorPt.x;
|
||||
if (cursorPt.y < 0)
|
||||
drawPos.y = -cursorPt.y;
|
||||
s.copyRectToSurface(surface, drawPos.x, drawPos.y, Common::Rect(0, 0, surface.w, surface.h));
|
||||
|
||||
// Adjust hotspot position
|
||||
hotspotX += (maxWidth - surface2.w) / 2;
|
||||
hotspotY += surface.h;
|
||||
// Draw the cursor image
|
||||
drawPos = Common::Point(MAX(cursorPt.x, (int16)0), MAX(cursorPt.y, (int16)0));
|
||||
s.copyRectToSurface(cursorImg, drawPos.x, drawPos.y, Common::Rect(0, 0, cursorImg.w, cursorImg.h));
|
||||
|
||||
// Set up hotspot position for cursor, adjusting for cursor image's position within the surface
|
||||
Common::Point hotspot;
|
||||
if (cursorId == MAGNIFY)
|
||||
hotspot = Common::Point(8, 8);
|
||||
hotspot += drawPos;
|
||||
// Set the cursor
|
||||
setCursor(s, hotspotX, hotspotY);
|
||||
setCursor(s, hotspot.x, hotspot.y);
|
||||
}
|
||||
|
||||
void Events::animateCursorIfNeeded() {
|
||||
@ -140,7 +152,6 @@ void Events::animateCursorIfNeeded() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Events::showCursor() {
|
||||
CursorMan.showMouse(true);
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
/**
|
||||
* Set both a standard cursor as well as an inventory item above it
|
||||
*/
|
||||
void setCursor(CursorId cursorId, const Graphics::Surface &surface);
|
||||
void setCursor(CursorId cursorId, const Common::Point &cursorPos, const Graphics::Surface &surface);
|
||||
|
||||
/**
|
||||
* Animates the mouse cursor if the Wait cursor is showing
|
||||
|
@ -428,7 +428,7 @@ void WidgetInventoryVerbs::handleEvents() {
|
||||
if (ui._menuMode == INV_MODE) {
|
||||
// Add the inventory item to the cursor
|
||||
ImageFrame &imgFrame = (*inv._invShapes[_owner->_invSelect - inv._invIndex])[0];
|
||||
events.setCursor(ARROW, imgFrame._frame);
|
||||
events.setCursor(ARROW, Common::Point(-100, imgFrame._height), imgFrame._frame);
|
||||
|
||||
// Close the inventory dialog without banishing it, so it can keep getting events
|
||||
// to handle tooltips and actually making the selection of what object to use them item on
|
||||
|
@ -42,6 +42,8 @@ void WidgetLab::handleEvents() {
|
||||
Events &events = *_vm->_events;
|
||||
Scene &scene = *_vm->_scene;
|
||||
TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
|
||||
Common::Point mousePos = events.mousePos();
|
||||
|
||||
WidgetBase::handleEvents();
|
||||
bool noDesc = false;
|
||||
|
||||
@ -146,7 +148,9 @@ void WidgetLab::handleEvents() {
|
||||
|
||||
// Set the mouse cursor to the object
|
||||
Graphics::Surface &img = _labObject->_imageFrame->_frame;
|
||||
events.setCursor(img, img.w / 2, img.h / 2);
|
||||
Common::Point cursorOffset = mousePos - _labObject->_position;
|
||||
events.setCursor(ARROW, cursorOffset, img);
|
||||
warning("%d,%d", cursorOffset.x, cursorOffset.y);//**DEBUG****
|
||||
|
||||
// Hide this object until they are done with it (releasing it)
|
||||
_labObject->toggleHidden();
|
||||
|
Loading…
x
Reference in New Issue
Block a user