CVideo: add get_pixel_scale() to return the active pixel scale.

Multiply font sizes by this to create high-dpi font textures.
This commit is contained in:
Tommy 2022-05-10 17:35:21 +12:00 committed by Charles Dang
parent c028dd7cf6
commit 58c9d4feae
2 changed files with 16 additions and 0 deletions

View File

@ -103,6 +103,7 @@ CVideo::CVideo(FAKE_TYPES type)
, refresh_rate_(0)
, offset_x_(0)
, offset_y_(0)
, pixel_scale_(1)
{
assert(!singleton_);
singleton_ = this;
@ -278,6 +279,8 @@ void CVideo::update_framebuffer()
} else {
scale = std::min(max_scale, preferences::pixel_scale());
}
// Cache it for easy access.
pixel_scale_ = scale;
// Update logical size if it doesn't match the current resolution and scale.
point lsize(window->get_logical_size());

View File

@ -178,6 +178,18 @@ public:
*/
int get_height() const;
/**
* Get the current active pixel scale multiplier.
* This is equal to output_size() / draw_area().
* Currently it is always integer, and the same in both dimensions.
*
* This may differ from preferences::pixel_scale() in some cases,
* For example if the window is too small to fit the desired scale.
*
* @returns The currently active pixel scale multiplier.
*/
int get_pixel_scale() const { return pixel_scale_; }
/** The current game screen dpi. */
std::pair<float, float> get_dpi() const;
@ -512,6 +524,7 @@ private:
int flip_locked_;
int refresh_rate_;
int offset_x_, offset_y_;
int pixel_scale_;
};
/** An object which will lock the display for the duration of its lifetime. */