stella/src/common/VideoModeHandler.hxx

135 lines
4.7 KiB
C++
Raw Normal View History

//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2023 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#ifndef VIDEO_MODE_HANDLER_HXX
#define VIDEO_MODE_HANDLER_HXX
class Settings;
#include "Rect.hxx"
#include "bspf.hxx"
class VideoModeHandler
{
public:
// Contains all relevant info for the dimensions of a video screen
// Also takes care of the case when the image should be 'centered'
// within the given screen:
// 'image' is the image dimensions into the screen
// 'screen' are the dimensions of the screen itself
struct Mode
{
enum class Stretch {
Preserve, // Stretch to fill all available space; preserve aspect ratio
Fill, // Stretch to fill all available space
None // No stretching (1x zoom)
};
2023-08-23 15:47:58 +00:00
struct BezelInfo
{
bool enabled{false};
bool windowedMode{false};
uInt32 topBorder{0};
uInt32 bottomBorder{0};
BezelInfo() = default;
BezelInfo(bool _enabled, bool _windowedMode, uInt32 _topBorder, uInt32 _bottomBorder)
: enabled{_enabled}, windowedMode{_windowedMode},
topBorder{_topBorder}, bottomBorder(_bottomBorder) { }
uInt32 vBorder() { return topBorder + bottomBorder; }
uInt32 hBorder() { return (topBorder + bottomBorder) * 4.F / 3.F; }
// Scale width from 4:3 into 16:9
float scaleW(float width = 1.F) { return width * (16.F / 9.F) / (4.F / 3.F); }
};
Common::Rect imageR;
Common::Rect screenR;
Common::Size screenS;
Stretch stretch{Mode::Stretch::None};
string description;
float zoom{1.F};
Int32 fsIndex{-1}; // -1 indicates windowed mode
Mode() = default;
Mode(uInt32 iw, uInt32 ih, uInt32 sw, uInt32 sh, Stretch smode,
Int32 fsindex = -1, string_view desc = "",
2023-08-23 15:47:58 +00:00
float zoomLevel = 1.F, float overscan = 1.F,
BezelInfo bezelInfo = BezelInfo());
//bool showBezel = false, Int32 bezelBorder = 0);
Mode(uInt32 iw, uInt32 ih, Stretch smode, Int32 fsindex = -1,
2023-08-23 15:47:58 +00:00
string_view desc = "", float zoomLevel = 1.F,
BezelInfo bezelInfo = BezelInfo());
//bool showBezel = false, Int32 bezelBorder = 0);
friend ostream& operator<<(ostream& os, const Mode& vm)
{
os << "image=" << vm.imageR << " screen=" << vm.screenS
<< " stretch=" << (vm.stretch == Stretch::Preserve ? "preserve" :
vm.stretch == Stretch::Fill ? "fill" : "none")
<< " desc=" << vm.description << " zoom=" << vm.zoom
<< " fsIndex= " << vm.fsIndex;
return os;
}
};
public:
VideoModeHandler() = default;
/**
Set the base size of the image. Scaling can be applied to this,
which will change the effective size.
@param image The base dimensions of the image
*/
void setImageSize(const Common::Size& image);
/**
Set the size of the display. This could be either the desktop size,
or the size of the monitor currently active.
@param display The dimensions of the enclosing display
@param fsIndex Fullscreen mode in use (-1 indicates windowed mode)
*/
void setDisplaySize(const Common::Size& display, Int32 fsIndex = -1);
/**
Build a video mode based on the given parameters, assuming that
setImageSize and setDisplaySize have been previously called.
@param settings Used to query various options that affect video mode
@param inTIAMode Whether the video mode is being used for TIA emulation
@return A video mode based on the given criteria
*/
2023-08-23 15:47:58 +00:00
const VideoModeHandler::Mode& buildMode(const Settings& settings, bool inTIAMode,
Mode::BezelInfo bezelInfo = Mode::BezelInfo());
private:
Common::Size myImage, myDisplay;
Int32 myFSIndex{-1};
Mode myMode;
private:
VideoModeHandler(const VideoModeHandler&) = delete;
VideoModeHandler(VideoModeHandler&&) = delete;
VideoModeHandler& operator=(const VideoModeHandler&) = delete;
VideoModeHandler& operator=(const VideoModeHandler&&) = delete;
};
#endif // VIDEO_MODE_HANDLER_HXX