Author Topic: [Suggestion] Smooth zoom in/out with mouse wheel or two fingers on mobile.  (Read 228 times)

Offline aceshigh

  • Sergeant
  • **
  • Posts: 48
    • View Profile
Since the game already allows 1x, 2x, 3x etc zoom being set through the options menu, wouldn´t it be possible to do a smooth zoom in/out directly from the Battlescape, by 0.1 increments, with the mouse wheel or "pinch" fingers on mobile phones/tablets? I mean, in theory, first thing would be to try to create options from 1 to 1.1, 1.2 all the way to 7.9x, 8x. If that works, seems it would be possible to just assign changing that on the fly, from inside the battlescape, assigning it to the mouse wheel, right?

zoom.cpp has the function Zoom::_zoomSurfaceY()
This function resizes an SDL_Surface (a bitmap in memory).
Currently, it only supports integer zoom factors (2x, 4x, etc.).
It calls different optimized scaling routines based on hardware.

Instead of checking for dst->w == src->w * 2 (for 2x zoom), allow any floating-point scale factor.

maybe if we changed
if (dst->w == src->w * 2 && dst->h == src->h * 2) return zoomSurface2X_64bit(src, dst);
else if (dst->w == src->w * 4 && dst->h == src->h * 4) return zoomSurface4X_64bit(src, dst);

to something like
float zoomFactorX = (float)dst->w / src->w;
float zoomFactorY = (float)dst->h / src->h;

if (zoomFactorX > 1.0f && zoomFactorY > 1.0f) {
    return zoomSurfaceDynamic(src, dst, zoomFactorX, zoomFactorY);
}


then create the zoomSurfaceDynamic() function
int zoomSurfaceDynamic(SDL_Surface *src, SDL_Surface *dst, float zoomX, float zoomY)
{
    int newWidth = (int)(src->w * zoomX);
    int newHeight = (int)(src->h * zoomY);

    SDL_Surface *scaledSurface = SDL_CreateRGBSurface(0, newWidth, newHeight, src->format->BitsPerPixel, 0, 0, 0, 0);

    SDL_SoftStretch(src, NULL, scaledSurface, NULL);  // SDL built-in resizer (supports non-integer scaling)

    SDL_BlitSurface(scaledSurface, NULL, dst, NULL);
    SDL_FreeSurface(scaledSurface);

    return 0;
}


it would use SDL_SoftStretch(), which supports non-integer zoom factors?
« Last Edit: February 04, 2025, 05:25:47 am by aceshigh »