mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-16 20:44:54 +00:00
CVideo: minor cleanup
- Removed overload of set_resolution taking two ints - Removed get_width and get_height in favor of draw_area - Removed some dead code - Minor formatting cleanup
This commit is contained in:
parent
bfef561071
commit
43a1ecc8bd
|
@ -572,7 +572,7 @@ list_formatter video_settings_report_internal(const std::string& heading = "")
|
||||||
fmt.insert("Window size", geometry_to_string(
|
fmt.insert("Window size", geometry_to_string(
|
||||||
video.current_resolution().x, video.current_resolution().y));
|
video.current_resolution().x, video.current_resolution().y));
|
||||||
fmt.insert("Game canvas size", geometry_to_string(
|
fmt.insert("Game canvas size", geometry_to_string(
|
||||||
video.get_width(), video.get_height()));
|
video.draw_area().w, video.draw_area().h));
|
||||||
fmt.insert("Final render target size", geometry_to_string(
|
fmt.insert("Final render target size", geometry_to_string(
|
||||||
video.output_size().x, video.output_size().y));
|
video.output_size().x, video.output_size().y));
|
||||||
fmt.insert("Screen refresh rate", std::to_string(video.current_refresh_rate()));
|
fmt.insert("Screen refresh rate", std::to_string(video.current_refresh_rate()));
|
||||||
|
|
|
@ -314,7 +314,7 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags)
|
||||||
dy -= scroll_amount;
|
dy -= scroll_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mousey > get_display().video().get_height() - scroll_threshold) {
|
if(mousey > get_display().video().draw_area().h - scroll_threshold) {
|
||||||
dy += scroll_amount;
|
dy += scroll_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags)
|
||||||
dx -= scroll_amount;
|
dx -= scroll_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mousex > get_display().video().get_width() - scroll_threshold) {
|
if(mousex > get_display().video().draw_area().w - scroll_threshold) {
|
||||||
dx += scroll_amount;
|
dx += scroll_amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -644,7 +644,7 @@ void canvas::blit(SDL_Rect rect)
|
||||||
// From those, as the first column is off-screen:
|
// From those, as the first column is off-screen:
|
||||||
// rect_clipped_to_parent={0, 2, 329, 440}
|
// rect_clipped_to_parent={0, 2, 329, 440}
|
||||||
// area_to_draw={1, 0, 329, 440}
|
// area_to_draw={1, 0, 329, 440}
|
||||||
SDL_Rect parent {0, 0, video.get_width(), video.get_height()};
|
SDL_Rect parent {0, 0, video.draw_area().w, video.draw_area().h};
|
||||||
SDL_Rect rect_clipped_to_parent;
|
SDL_Rect rect_clipped_to_parent;
|
||||||
if(!SDL_IntersectRect(&rect, &parent, &rect_clipped_to_parent)) {
|
if(!SDL_IntersectRect(&rect, &parent, &rect_clipped_to_parent)) {
|
||||||
DBG_GUI_D << "Area to draw is completely outside parent.\n";
|
DBG_GUI_D << "Area to draw is completely outside parent.\n";
|
||||||
|
|
|
@ -458,7 +458,7 @@ void sdl_event_handler::handle_event(const SDL_Event& event)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_WINDOWEVENT_RESIZED:
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
video_resize(point(video.get_width(), video.get_height()));
|
video_resize(point(video.draw_area().w, video.draw_area().h));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_WINDOWEVENT_ENTER:
|
case SDL_WINDOWEVENT_ENTER:
|
||||||
|
|
|
@ -293,7 +293,7 @@ std::string unit_topic_generator::operator()() const {
|
||||||
const unit_type& female_type = type_.get_gender_unit_type(unit_race::FEMALE);
|
const unit_type& female_type = type_.get_gender_unit_type(unit_race::FEMALE);
|
||||||
const unit_type& male_type = type_.get_gender_unit_type(unit_race::MALE);
|
const unit_type& male_type = type_.get_gender_unit_type(unit_race::MALE);
|
||||||
|
|
||||||
const int screen_width = CVideo::get_singleton().get_width();
|
const int screen_width = CVideo::get_singleton().draw_area().w;
|
||||||
|
|
||||||
ss << _("Level") << " " << type_.level();
|
ss << _("Level") << " " << type_.level();
|
||||||
ss << "\n\n";
|
ss << "\n\n";
|
||||||
|
|
|
@ -18,15 +18,15 @@
|
||||||
#include "display.hpp"
|
#include "display.hpp"
|
||||||
#include "floating_label.hpp"
|
#include "floating_label.hpp"
|
||||||
#include "font/sdl_ttf_compat.hpp"
|
#include "font/sdl_ttf_compat.hpp"
|
||||||
#include "picture.hpp"
|
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
|
#include "picture.hpp"
|
||||||
#include "preferences/general.hpp"
|
#include "preferences/general.hpp"
|
||||||
|
#include "sdl/input.hpp"
|
||||||
#include "sdl/point.hpp"
|
#include "sdl/point.hpp"
|
||||||
|
#include "sdl/texture.hpp"
|
||||||
#include "sdl/userevent.hpp"
|
#include "sdl/userevent.hpp"
|
||||||
#include "sdl/utils.hpp"
|
#include "sdl/utils.hpp"
|
||||||
#include "sdl/window.hpp"
|
#include "sdl/window.hpp"
|
||||||
#include "sdl/input.hpp"
|
|
||||||
#include "sdl/texture.hpp"
|
|
||||||
|
|
||||||
#ifdef TARGET_OS_OSX
|
#ifdef TARGET_OS_OSX
|
||||||
#include "desktop/apple_video.hpp"
|
#include "desktop/apple_video.hpp"
|
||||||
|
@ -44,8 +44,6 @@ static lg::log_domain log_display("display");
|
||||||
#define WRN_DP LOG_STREAM(warn, log_display)
|
#define WRN_DP LOG_STREAM(warn, log_display)
|
||||||
#define DBG_DP LOG_STREAM(debug, log_display)
|
#define DBG_DP LOG_STREAM(debug, log_display)
|
||||||
|
|
||||||
CVideo* CVideo::singleton_ = nullptr;
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
bool fake_interactive = false;
|
bool fake_interactive = false;
|
||||||
|
@ -96,7 +94,6 @@ void trigger_full_redraw()
|
||||||
|
|
||||||
CVideo::CVideo(FAKE_TYPES type)
|
CVideo::CVideo(FAKE_TYPES type)
|
||||||
: window()
|
: window()
|
||||||
, drawing_texture_(nullptr)
|
|
||||||
, render_texture_(nullptr)
|
, render_texture_(nullptr)
|
||||||
, fake_screen_(false)
|
, fake_screen_(false)
|
||||||
, help_string_(0)
|
, help_string_(0)
|
||||||
|
@ -127,9 +124,7 @@ CVideo::CVideo(FAKE_TYPES type)
|
||||||
|
|
||||||
void CVideo::initSDL()
|
void CVideo::initSDL()
|
||||||
{
|
{
|
||||||
const int res = SDL_InitSubSystem(SDL_INIT_VIDEO);
|
if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
|
||||||
|
|
||||||
if(res < 0) {
|
|
||||||
ERR_DP << "Could not initialize SDL_video: " << SDL_GetError() << std::endl;
|
ERR_DP << "Could not initialize SDL_video: " << SDL_GetError() << std::endl;
|
||||||
throw error("Video initialization failed");
|
throw error("Video initialization failed");
|
||||||
}
|
}
|
||||||
|
@ -189,7 +184,7 @@ void CVideo::make_test_fake(const unsigned width, const unsigned height)
|
||||||
refresh_rate_ = 1;
|
refresh_rate_ = 1;
|
||||||
|
|
||||||
if (window) {
|
if (window) {
|
||||||
set_resolution(width, height);
|
set_resolution({int(width), int(height)});
|
||||||
} else {
|
} else {
|
||||||
fake_size = {int(width), int(height)};
|
fake_size = {int(width), int(height)};
|
||||||
init_fake_window();
|
init_fake_window();
|
||||||
|
@ -408,7 +403,7 @@ void CVideo::init_window()
|
||||||
|
|
||||||
// It is assumed that this function is only ever called once.
|
// It is assumed that this function is only ever called once.
|
||||||
// If that is no longer true, then you should clean things up.
|
// If that is no longer true, then you should clean things up.
|
||||||
assert(!render_texture_ && !drawing_texture_);
|
assert(!render_texture_);
|
||||||
|
|
||||||
std::cerr << "Setting mode to " << w << "x" << h << std::endl;
|
std::cerr << "Setting mode to " << w << "x" << h << std::endl;
|
||||||
|
|
||||||
|
@ -500,16 +495,6 @@ SDL_Rect CVideo::input_area() const
|
||||||
return {0, 0, p.x, p.y};
|
return {0, 0, p.x, p.y};
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVideo::get_width() const
|
|
||||||
{
|
|
||||||
return logical_size_.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CVideo::get_height() const
|
|
||||||
{
|
|
||||||
return logical_size_.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CVideo::delay(unsigned int milliseconds)
|
void CVideo::delay(unsigned int milliseconds)
|
||||||
{
|
{
|
||||||
if(!game_config::no_delay) {
|
if(!game_config::no_delay) {
|
||||||
|
@ -529,7 +514,7 @@ void CVideo::force_render_target(SDL_Texture* t)
|
||||||
// so make sure it gets set back appropriately.
|
// so make sure it gets set back appropriately.
|
||||||
if (t == nullptr || t == render_texture_) {
|
if (t == nullptr || t == render_texture_) {
|
||||||
// TODO: highdpi - sort out who owns this
|
// TODO: highdpi - sort out who owns this
|
||||||
window->set_logical_size(get_width(), get_height());
|
window->set_logical_size(draw_area().w, draw_area().h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,7 +568,7 @@ void CVideo::render_screen()
|
||||||
|
|
||||||
// SDL resets the logical size when setting a render texture target,
|
// SDL resets the logical size when setting a render texture target,
|
||||||
// so we also have to reset that every time.
|
// so we also have to reset that every time.
|
||||||
window->set_logical_size(get_width(), get_height());
|
window->set_logical_size(draw_area().w, draw_area().h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,7 +635,7 @@ surface CVideo::read_pixels_low_res(SDL_Rect* r)
|
||||||
if(r) {
|
if(r) {
|
||||||
return scale_surface(s, r->w, r->h);
|
return scale_surface(s, r->w, r->h);
|
||||||
} else {
|
} else {
|
||||||
return scale_surface(s, get_width(), get_height());
|
return scale_surface(s, draw_area().w, draw_area().h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -687,11 +672,9 @@ void CVideo::set_window_icon(surface& icon)
|
||||||
|
|
||||||
void CVideo::clear_screen()
|
void CVideo::clear_screen()
|
||||||
{
|
{
|
||||||
if(!window) {
|
if(window) {
|
||||||
return;
|
window->fill(0, 0, 0, 255);;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->fill(0, 0, 0, 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sdl::window* CVideo::get_window()
|
sdl::window* CVideo::get_window()
|
||||||
|
@ -729,11 +712,7 @@ std::vector<std::string> CVideo::enumerate_drivers()
|
||||||
|
|
||||||
bool CVideo::window_has_flags(uint32_t flags) const
|
bool CVideo::window_has_flags(uint32_t flags) const
|
||||||
{
|
{
|
||||||
if(!window) {
|
return window && (window->get_flags() & flags) != 0;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (window->get_flags() & flags) != 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<point> CVideo::get_available_resolutions(const bool include_current)
|
std::vector<point> CVideo::get_available_resolutions(const bool include_current)
|
||||||
|
@ -754,11 +733,6 @@ std::vector<point> CVideo::get_available_resolutions(const bool include_current)
|
||||||
|
|
||||||
const point min_res(preferences::min_window_width, preferences::min_window_height);
|
const point min_res(preferences::min_window_width, preferences::min_window_height);
|
||||||
|
|
||||||
#if 0
|
|
||||||
// DPI scale factor.
|
|
||||||
auto [scale_h, scale_v] = get_dpi_scale_factor();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// The maximum size to which this window can be set. For some reason this won't
|
// The maximum size to which this window can be set. For some reason this won't
|
||||||
// pop up as a display mode of its own.
|
// pop up as a display mode of its own.
|
||||||
SDL_Rect bounds;
|
SDL_Rect bounds;
|
||||||
|
@ -824,7 +798,7 @@ int CVideo::set_help_string(const std::string& str)
|
||||||
int size = font::SIZE_LARGE;
|
int size = font::SIZE_LARGE;
|
||||||
|
|
||||||
while(size > 0) {
|
while(size > 0) {
|
||||||
if(font::pango_line_width(str, size) > get_width()) {
|
if(font::pango_line_width(str, size) > draw_area().w) {
|
||||||
size--;
|
size--;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -835,7 +809,7 @@ int CVideo::set_help_string(const std::string& str)
|
||||||
|
|
||||||
font::floating_label flabel(str);
|
font::floating_label flabel(str);
|
||||||
flabel.set_font_size(size);
|
flabel.set_font_size(size);
|
||||||
flabel.set_position(get_width() / 2, get_height());
|
flabel.set_position(draw_area().w / 2, draw_area().h);
|
||||||
flabel.set_bg_color(color);
|
flabel.set_bg_color(color);
|
||||||
flabel.set_border_size(border);
|
flabel.set_border_size(border);
|
||||||
|
|
||||||
|
@ -893,11 +867,6 @@ void CVideo::toggle_fullscreen()
|
||||||
set_fullscreen(!preferences::fullscreen());
|
set_fullscreen(!preferences::fullscreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CVideo::set_resolution(const unsigned width, const unsigned height)
|
|
||||||
{
|
|
||||||
return set_resolution(point(width, height));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CVideo::set_resolution(const point& resolution)
|
bool CVideo::set_resolution(const point& resolution)
|
||||||
{
|
{
|
||||||
if(resolution == current_resolution()) {
|
if(resolution == current_resolution()) {
|
||||||
|
|
|
@ -122,8 +122,6 @@ public:
|
||||||
|
|
||||||
bool supports_vsync() const;
|
bool supports_vsync() const;
|
||||||
|
|
||||||
bool set_resolution(const unsigned width, const unsigned height);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the window resolution.
|
* Set the window resolution.
|
||||||
*
|
*
|
||||||
|
@ -170,20 +168,6 @@ public:
|
||||||
*/
|
*/
|
||||||
SDL_Rect input_area() const;
|
SDL_Rect input_area() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the width of the drawing surface in pixels.
|
|
||||||
* Input coordinates are automatically scaled to correspond,
|
|
||||||
* so this also indicates the width of the input surface.
|
|
||||||
*/
|
|
||||||
int get_width() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the height of the drawing surface in pixels.
|
|
||||||
* Input coordinates are automatically scaled to correspond,
|
|
||||||
* so this also indicates the height of the input surface.
|
|
||||||
*/
|
|
||||||
int get_height() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current active pixel scale multiplier.
|
* Get the current active pixel scale multiplier.
|
||||||
* This is equal to output_size() / draw_area().
|
* This is equal to output_size() / draw_area().
|
||||||
|
@ -375,14 +359,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static CVideo* singleton_;
|
static inline CVideo* singleton_ = nullptr;
|
||||||
|
|
||||||
/** The SDL window object. */
|
/** The SDL window object. */
|
||||||
std::unique_ptr<sdl::window> window;
|
std::unique_ptr<sdl::window> window;
|
||||||
|
|
||||||
/** The drawing texture. */
|
|
||||||
SDL_Texture* drawing_texture_;
|
|
||||||
|
|
||||||
/** The current offscreen render target. */
|
/** The current offscreen render target. */
|
||||||
SDL_Texture* render_texture_;
|
SDL_Texture* render_texture_;
|
||||||
|
|
||||||
|
|
|
@ -441,7 +441,7 @@ std::size_t menu::max_items_onscreen() const
|
||||||
return std::size_t(max_items_);
|
return std::size_t(max_items_);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::size_t max_height = (max_height_ == -1 ? (video().get_height()*66)/100 : max_height_) - heading_height();
|
const std::size_t max_height = (max_height_ == -1 ? (video().draw_area().h*66)/100 : max_height_) - heading_height();
|
||||||
|
|
||||||
std::vector<int> heights;
|
std::vector<int> heights;
|
||||||
std::size_t n;
|
std::size_t n;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user