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>
</tr>
<tr>
<td>Select previous snapshot</td>
<td>Select previous image</td>
<td>Control + Left arrow</td>
<td>Control + Left arrow</td>
</tr>
<tr>
<td>Select next snapshot</td>
<td>Select next image</td>
<td>Control + Right arrow</td>
<td>Control + Right arrow</td>
</tr>
<tr>
<td>Toogle image zoom</td>
<td>Control + Return</td>
<td>Control + Return</td>
</tr>
<tr>
<td>Remove from 'Recently Played' or 'Most Popular' folder</td>
<td>Control + X</td>

View File

@ -1520,7 +1520,9 @@ PhysicalJoystickHandler::DefaultMenuMapping = {
{Event::UINavNext, JOY_CTRL_NONE, JoyAxis::X, JoyDir::POS},
{Event::UITabNext, 0, JoyAxis::X, JoyDir::POS},
{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::UICancel, 0 , JoyAxis::Y, JoyDir::POS},
{Event::UINavPrev, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::LEFT},
{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);
break;
case KBDK_RETURN:
myRomImageWidget->toggleImageZoom();
break;
default:
handled = false;
break;
@ -932,6 +936,11 @@ Event::Type LauncherDialog::getJoyAxisEvent(int stick, JoyAxis axis, JoyDir adir
myEventHandled = true;
break;
case Event::UIOK:
myRomImageWidget->toggleImageZoom();
myEventHandled = true;
break;
default:
break;
}

View File

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

View File

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