Refactored handling of window/renderer size getters
* Removed display::screen_area(), display::w(), and display::h().
* Moved the global screen_area() function into the CVideo class.
* Renamed CVideo::getx() and gety() to get_width() and get_height()
* Made those two functions return the result of screen_area() instead of the other way around.
* Added preliminary support for high-DPI rendering to screen_area()
Note on the last point: When I fixed bug #1772 (aa8f6c7e7
right now but will probably change with rebasing)
I noted that SDL_GetWindowSize and SDL_GetRendererOutputSize returned the same results for me (even with
Window's automatic scaling for non-high-DPI-enabled apps disabled) but that the SDL documentation stated the
former returned screen coordinates and the latter pixels. In that same commit I changed the dimension functions
to use SDL_GetWindowSize. I've now reversed that decision and gone back to using SDL_GetRendererOutputSize so
I can guarantee output in pixels. If use_pixels is false, the code will return coordinates in 96 DPI, so I need
to have pixel measurements for the calculations.
Again, though, I do not know if SDL_GetWindowSize returns a different value that pixel size (which it's said
to do) on macOS or iOS. I'll need to do some testing. It's possible on those platforms I won't need the 96 DPI
measurements, but it's also possible it will be needed on on platforms, since all of our code relies on pixel
measurements.
This commit is contained in:
parent
63398733b0
commit
8eba15bffc
4 changed files with 9 additions and 27 deletions
|
@ -145,7 +145,7 @@ display::display(const display_context * dc, std::weak_ptr<wb::manager> wb, repo
|
|||
, xpos_(0)
|
||||
, ypos_(0)
|
||||
, view_locked_(false)
|
||||
, theme_(theme_cfg, screen_.screen_area())
|
||||
, theme_(theme_cfg, video().screen_area())
|
||||
, zoom_index_(0)
|
||||
, fake_unit_man_(new fake_unit_manager(*this))
|
||||
, builder_(new terrain_builder(level, (dc_ ? &dc_->map() : nullptr), theme_.border().tile_image, theme_.border().show_border))
|
||||
|
@ -241,9 +241,7 @@ display::~display()
|
|||
}
|
||||
|
||||
void display::set_theme(config theme_cfg) {
|
||||
theme_ = theme(theme_cfg, screen_.screen_area());
|
||||
builder_->set_draw_border(theme_.border().show_border);
|
||||
menu_buttons_.clear();
|
||||
theme_ = theme(theme_cfg, video_.screen_area()); menu_buttons_.clear();
|
||||
action_buttons_.clear();
|
||||
create_buttons();
|
||||
}
|
||||
|
@ -795,7 +793,7 @@ void display::layout_buttons()
|
|||
for(const auto& menu : theme_.menus()) {
|
||||
std::shared_ptr<gui::button> b = find_menu_button(menu.get_id());
|
||||
if(b) {
|
||||
const SDL_Rect& loc = menu.location(screen_.screen_area());
|
||||
const SDL_Rect& loc = menu.location(video_.screen_area());
|
||||
b->set_location(loc);
|
||||
b->set_measurements(0,0);
|
||||
b->set_label(menu.title());
|
||||
|
@ -807,7 +805,7 @@ void display::layout_buttons()
|
|||
for(const auto& action : theme_.actions()) {
|
||||
std::shared_ptr<gui::button> b = find_action_button(action.get_id());
|
||||
if(b) {
|
||||
const SDL_Rect& loc = action.location(screen_.screen_area());
|
||||
const SDL_Rect& loc = action.location(video_.screen_area());
|
||||
b->set_location(loc);
|
||||
b->set_measurements(0,0);
|
||||
b->set_label(action.title());
|
||||
|
@ -1942,7 +1940,7 @@ void display::refresh_report(const std::string& report_name, const config * new_
|
|||
new_cfg = &generated_cfg;
|
||||
|
||||
SDL_Rect &rect = reportRects_[report_name];
|
||||
const SDL_Rect &new_rect = item->location(screen_.screen_area());
|
||||
const SDL_Rect &new_rect = item->location(video_.screen_area());
|
||||
surface &surf = reportSurfaces_[report_name];
|
||||
config &report = reports_[report_name];
|
||||
|
||||
|
@ -2260,7 +2258,7 @@ void display::redraw_everything()
|
|||
|
||||
tooltips::clear_tooltips();
|
||||
|
||||
theme_.set_resolution(screen_area());
|
||||
theme_.set_resolution(video_.screen_area());
|
||||
|
||||
if(!menu_buttons_.empty() || !action_buttons_.empty()) {
|
||||
create_buttons();
|
||||
|
|
|
@ -276,18 +276,6 @@ public:
|
|||
* Between mapx and x is the sidebar region.
|
||||
*/
|
||||
|
||||
/** Screen width */
|
||||
int w() const
|
||||
{
|
||||
return video_.get_width();
|
||||
}
|
||||
|
||||
/** Screen height */
|
||||
int h() const
|
||||
{
|
||||
return video_.get_hright();
|
||||
}
|
||||
|
||||
const SDL_Rect& minimap_area() const
|
||||
{
|
||||
return theme_.mini_map_location(video_.screen_area());
|
||||
|
@ -303,11 +291,6 @@ public:
|
|||
return theme_.unit_image_location(video_.screen_area());
|
||||
}
|
||||
|
||||
SDL_Rect screen_area() const
|
||||
{
|
||||
return {0, 0, w(), h()};
|
||||
}
|
||||
|
||||
/** Returns the maximum area used for the map regardless to resolution and view size */
|
||||
const SDL_Rect& max_map_area() const;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "sdl/render_utils.hpp"
|
||||
#include "sdl/surface.hpp"
|
||||
#include "utils/general.hpp"
|
||||
#include "video.hpp"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
|
@ -60,7 +61,7 @@ floating_label::floating_label(const std::string& text)
|
|||
, border_(0)
|
||||
, alpha_change_(0)
|
||||
, current_alpha_(255)
|
||||
, clip_rect_(screen_area())
|
||||
, clip_rect_(CVideo::get_singleton().screen_area())
|
||||
, align_(CENTER_ALIGN)
|
||||
, scroll_(ANCHOR_LABEL_SCREEN)
|
||||
, visible_(true)
|
||||
|
|
|
@ -321,7 +321,7 @@ void dialog_frame::draw_background()
|
|||
|
||||
SDL_Rect dialog_frame::draw_title(CVideo* video)
|
||||
{
|
||||
SDL_Rect rect = CVideo::get_singleton().screen_area();
|
||||
SDL_Rect rect = video->screen_area();
|
||||
return font::draw_text(video, rect, font::SIZE_TITLE, font::TITLE_COLOR,
|
||||
title_, dim_.title.x, dim_.title.y, false, TTF_STYLE_NORMAL);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue