added keyboard and controller support for image zooming

This commit is contained in:
thrust26 2023-08-31 19:57:45 +02:00
parent 065c0243d6
commit caa8cb72c0
5 changed files with 50 additions and 15 deletions

View File

@ -2082,15 +2082,20 @@
<td>Backspace, Alt + Up arrow</td> <td>Backspace, Alt + Up arrow</td>
</tr> </tr>
<tr> <tr>
<td>Select previous snapshot</td> <td>Select previous image</td>
<td>Control + Left arrow</td> <td>Control + Left arrow</td>
<td>Control + Left arrow</td> <td>Control + Left arrow</td>
</tr> </tr>
<tr> <tr>
<td>Select next snapshot</td> <td>Select next image</td>
<td>Control + Right arrow</td> <td>Control + Right arrow</td>
<td>Control + Right arrow</td> <td>Control + Right arrow</td>
</tr> </tr>
<tr>
<td>Toogle image zoom</td>
<td>Control + Return</td>
<td>Control + Return</td>
</tr>
<tr> <tr>
<td>Remove from 'Recently Played' or 'Most Popular' folder</td> <td>Remove from 'Recently Played' or 'Most Popular' folder</td>
<td>Control + X</td> <td>Control + X</td>

View File

@ -1520,7 +1520,9 @@ PhysicalJoystickHandler::DefaultMenuMapping = {
{Event::UINavNext, JOY_CTRL_NONE, JoyAxis::X, JoyDir::POS}, {Event::UINavNext, JOY_CTRL_NONE, JoyAxis::X, JoyDir::POS},
{Event::UITabNext, 0, JoyAxis::X, JoyDir::POS}, {Event::UITabNext, 0, JoyAxis::X, JoyDir::POS},
{Event::UIUp, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG}, {Event::UIUp, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG},
{Event::UIOK, 0 , JoyAxis::Y, JoyDir::NEG},
{Event::UIDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS}, {Event::UIDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS},
{Event::UICancel, 0 , JoyAxis::Y, JoyDir::POS},
{Event::UINavPrev, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::LEFT}, {Event::UINavPrev, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::LEFT},
{Event::UINavNext, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::RIGHT}, {Event::UINavNext, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::RIGHT},

View File

@ -839,6 +839,10 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
myRomImageWidget->changeImage(1); myRomImageWidget->changeImage(1);
break; break;
case KBDK_RETURN:
myRomImageWidget->toggleImageZoom();
break;
default: default:
handled = false; handled = false;
break; break;
@ -932,6 +936,11 @@ Event::Type LauncherDialog::getJoyAxisEvent(int stick, JoyAxis axis, JoyDir adir
myEventHandled = true; myEventHandled = true;
break; break;
case Event::UIOK:
myRomImageWidget->toggleImageZoom();
myEventHandled = true;
break;
default: default:
break; break;
} }

View File

@ -137,6 +137,7 @@ void RomImageWidget::parseProperties(const FSNode& node, bool full)
}); });
} }
myZoomMode = false;
#ifdef IMAGE_SUPPORT #ifdef IMAGE_SUPPORT
if(!full) if(!full)
{ {
@ -211,6 +212,17 @@ bool RomImageWidget::changeImage(int direction)
return false; return false;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomImageWidget::toggleImageZoom()
{
#ifdef IMAGE_SUPPORT
myMousePos = Common::Point(_w >> 1, myImageHeight >> 1);
myZoomMode = !myIsZoomed;
myZoomTimer = myZoomMode ? DELAY_TIME * REQUEST_SPEED : 0;
zoomSurfaces(!myIsZoomed);
#endif
}
#ifdef IMAGE_SUPPORT #ifdef IMAGE_SUPPORT
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RomImageWidget::getImageList(const string& propName, const string& romName, bool RomImageWidget::getImageList(const string& propName, const string& romName,
@ -282,13 +294,14 @@ bool RomImageWidget::loadImage(const string& fileName)
if(mySurfaceIsValid) if(mySurfaceIsValid)
{ {
mySrcRect = mySurface->srcRect(); mySrcRect = mySurface->srcRect();
zoomSurface(false, true); zoomSurfaces(false, true);
} }
if(mySurface) if(mySurface)
mySurface->setVisible(mySurfaceIsValid); mySurface->setVisible(mySurfaceIsValid);
myZoomTimer = 0; if (!myZoomMode)
myZoomTimer = 0;
setDirty(); setDirty();
return mySurfaceIsValid; return mySurfaceIsValid;
} }
@ -351,7 +364,7 @@ bool RomImageWidget::loadJpg(const string& fileName)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomImageWidget::zoomSurface(bool zoomed, bool force) void RomImageWidget::zoomSurfaces(bool zoomed, bool force)
{ {
if(zoomed != myIsZoomed || force) if(zoomed != myIsZoomed || force)
{ {
@ -395,15 +408,15 @@ void RomImageWidget::zoomSurface(bool zoomed, bool force)
myFrameSurface->setDstSize(w + b * 2, h + b * 2); myFrameSurface->setDstSize(w + b * 2, h + b * 2);
myFrameSurface->frameRect(0, 0, myFrameSurface->width(), myFrameSurface->height(), kColor); myFrameSurface->frameRect(0, 0, myFrameSurface->width(), myFrameSurface->height(), kColor);
myZoomTimer = DELAY_TIME * REQUEST_SPEED; myZoomTimer = DELAY_TIME * REQUEST_SPEED; // zoom immediately
} }
posSurfaces(); positionSurfaces();
setDirty(); setDirty();
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomImageWidget::posSurfaces() void RomImageWidget::positionSurfaces()
{ {
// Make sure when positioning the image surface that we take // Make sure when positioning the image surface that we take
// the dialog surface position into account // the dialog surface position into account
@ -460,7 +473,7 @@ void RomImageWidget::handleMouseUp(int x, int y, MouseButton b, int clickCount)
else if(myMouseArea == Area::RIGHT) else if(myMouseArea == Area::RIGHT)
changeImage(1); changeImage(1);
else else
zoomSurface(true); zoomSurfaces(true);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -469,6 +482,7 @@ void RomImageWidget::handleMouseMoved(int x, int y)
const Area oldArea = myMouseArea; const Area oldArea = myMouseArea;
myMousePos = Common::Point(x, y); myMousePos = Common::Point(x, y);
//myZoomMode = false;
if(myZoomRect.contains(x, y)) if(myZoomRect.contains(x, y))
myMouseArea = Area::ZOOM; myMouseArea = Area::ZOOM;
@ -484,15 +498,15 @@ void RomImageWidget::handleMouseMoved(int x, int y)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomImageWidget::tick() void RomImageWidget::tick()
{ {
if(myMouseArea == Area::ZOOM) if(myMouseArea == Area::ZOOM || myZoomMode)
{ {
myZoomTimer += REQUEST_SPEED; myZoomTimer += REQUEST_SPEED;
if(myZoomTimer >= DELAY_TIME * REQUEST_SPEED) if(myZoomTimer >= DELAY_TIME * REQUEST_SPEED)
zoomSurface(true); zoomSurfaces(true);
} }
else else
{ {
zoomSurface(false); zoomSurfaces(false);
if(myZoomTimer) if(myZoomTimer)
--myZoomTimer; --myZoomTimer;
} }
@ -521,7 +535,7 @@ void RomImageWidget::drawWidget(bool hilite)
if(mySurfaceIsValid) if(mySurfaceIsValid)
{ {
s.fillRect(_x, _y, _w, myImageHeight, 0); s.fillRect(_x, _y, _w, myImageHeight, 0);
posSurfaces(); positionSurfaces();
} }
else if(!mySurfaceErrorMsg.empty()) else if(!mySurfaceErrorMsg.empty())
{ {

View File

@ -40,6 +40,8 @@ class RomImageWidget : public Widget
void clearProperties(); void clearProperties();
void reloadProperties(const FSNode& node); void reloadProperties(const FSNode& node);
bool changeImage(int direction = 1); bool changeImage(int direction = 1);
// Toggle zoom via keyboard
void toggleImageZoom();
uInt64 pendingLoadTime() { return myMaxLoadTime * timeFactor; } uInt64 pendingLoadTime() { return myMaxLoadTime * timeFactor; }
@ -61,9 +63,9 @@ class RomImageWidget : public Widget
bool loadPng(const string& fileName); bool loadPng(const string& fileName);
bool loadJpg(const string& fileName); bool loadJpg(const string& fileName);
void zoomSurface(bool zoomed, bool force = false); void zoomSurfaces(bool zoomed, bool force = false);
void positionSurfaces();
#endif #endif
void posSurfaces();
private: private:
// Pending load time safety factor // Pending load time safety factor
@ -103,6 +105,9 @@ class RomImageWidget : public Widget
// Zoom icon rectangle // Zoom icon rectangle
Common::Rect myZoomRect; Common::Rect myZoomRect;
// True for keyboard zooming
bool myZoomMode{false};
// Surface zoom status // Surface zoom status
bool myIsZoomed{false}; bool myIsZoomed{false};