1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Moved SDL-specific code to SDL_Extensions

This commit is contained in:
Ivan Savenko 2023-02-02 22:42:15 +02:00
parent 01322aa4c5
commit 70c0937972
4 changed files with 46 additions and 33 deletions

View File

@ -891,7 +891,42 @@ void CSDL_Ext::getClipRect(SDL_Surface * src, Rect & other)
other = CSDL_Ext::fromSDL(rect);
}
bool CSDL_Ext::isResolutionSupported(const std::vector<Point> & resolutions, const Point toTest )
{
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
// ios can use any resolution
// presumably, same goes for Android
return true;
#else
// in fullscreen only resolutions supported by monitor can be used
return vstd::contains(resolutions, toTest);
#endif
}
std::vector<Point> CSDL_Ext::getSupportedResolutions()
{
int displayID = SDL_GetWindowDisplayIndex(mainWindow);
return getSupportedResolutions(displayID);
}
std::vector<Point> CSDL_Ext::getSupportedResolutions( int displayIndex)
{
std::vector<Point> result;
int modesCount = SDL_GetNumDisplayModes(displayIndex);
for (int i =0; i < modesCount; ++i)
{
SDL_DisplayMode mode;
if (SDL_GetDisplayMode(displayIndex, i, &mode) != 0)
continue;
Point resolution(mode.w, mode.h);
result.push_back(resolution);
}
return result;
}
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<2>(int, int);
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<3>(int, int);

View File

@ -130,6 +130,11 @@ typedef void (*TColorPutterAlpha)(uint8_t *&ptr, const uint8_t & R, const uint8_
void applyEffectBpp( SDL_Surface * surf, const Rect & rect, int mode );
void applyEffect(SDL_Surface * surf, const Rect & rect, int mode); //mode: 0 - sepia, 1 - grayscale
bool isResolutionSupported(const std::vector<Point> & resolutions, const Point toTest );
std::vector<Point> getSupportedResolutions();
std::vector<Point> getSupportedResolutions( int displayIndex);
void setColorKey(SDL_Surface * surface, SDL_Color color);
///set key-color to 0,255,255

View File

@ -63,6 +63,8 @@
#include "../lib/NetPacksBase.h"
#include "../lib/StartInfo.h"
#include <SDL_surface.h>
CRecruitmentWindow::CCreatureCard::CCreatureCard(CRecruitmentWindow * window, const CCreature * crea, int totalAmount)
: CIntObject(LCLICK | RCLICK),
parent(window),
@ -582,30 +584,8 @@ void CSystemOptionsWindow::setFullscreenMode( bool on)
}
}
void CSystemOptionsWindow::fillSupportedResolutions()
{
supportedResolutions.clear();
// in game we can only change resolution, display is fixed
int displayID = SDL_GetWindowDisplayIndex(mainWindow);
int modesCount = SDL_GetNumDisplayModes(displayID);
for (int i =0; i < modesCount; ++i)
{
SDL_DisplayMode mode;
if (SDL_GetDisplayMode(displayID, i, &mode) != 0)
continue;
Point resolution(mode.w, mode.h);
supportedResolutions.push_back(resolution);
}
}
void CSystemOptionsWindow::fillSelectableResolutions()
{
fillSupportedResolutions();
selectableResolutions.clear();
for(const auto & it : conf.guiOptions)
@ -629,18 +609,12 @@ bool CSystemOptionsWindow::isResolutionSupported(const Point & resolution)
bool CSystemOptionsWindow::isResolutionSupported(const Point & resolution, bool fullscreen)
{
#ifdef VCMI_IOS
// ios can use any resolution
bool canUseAllResolutions = true;
#else
// in fullscreen only resolutions supported by monitor can be used
bool canUseAllResolutions = (fullscreen == false);
#endif
if (canUseAllResolutions)
if (!fullscreen)
return true;
return vstd::contains(supportedResolutions, resolution);
auto supportedList = CSDL_Ext::getSupportedResolutions();
return CSDL_Ext::isResolutionSupported(supportedList, resolution);
}
void CSystemOptionsWindow::selectGameRes()

View File

@ -238,7 +238,6 @@ private:
void bmainmenuf(); //return to main menu
void setFullscreenMode( bool on);
void fillSupportedResolutions();
void fillSelectableResolutions();
bool isResolutionSupported(const Point & resolution);
bool isResolutionSupported(const Point & resolution, bool fullscreen);