Skip to content

Commit

Permalink
added keyboard and controller support for image zooming
Browse files Browse the repository at this point in the history
  • Loading branch information
thrust26 committed Aug 31, 2023
1 parent 065c024 commit caa8cb7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
9 changes: 7 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2082,15 +2082,20 @@ <h2><b><a name="Hotkeys">Hotkeys</a></b></h2>
<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>
Expand Down
2 changes: 2 additions & 0 deletions src/common/PJoystickHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
9 changes: 9 additions & 0 deletions src/gui/LauncherDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
36 changes: 25 additions & 11 deletions src/gui/RomImageWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void RomImageWidget::parseProperties(const FSNode& node, bool full)
});
}

myZoomMode = false;
#ifdef IMAGE_SUPPORT
if(!full)
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -521,7 +535,7 @@ void RomImageWidget::drawWidget(bool hilite)
if(mySurfaceIsValid)
{
s.fillRect(_x, _y, _w, myImageHeight, 0);
posSurfaces();
positionSurfaces();
}
else if(!mySurfaceErrorMsg.empty())
{
Expand Down
9 changes: 7 additions & 2 deletions src/gui/RomImageWidget.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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
Expand Down Expand Up @@ -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};

Expand Down

0 comments on commit caa8cb7

Please sign in to comment.