From b97a20b059271c419492122b35472d897e258166 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sat, 10 Dec 2016 22:35:46 +1100 Subject: [PATCH] Split SDL_Surface wrapper class and related helper struts into their own file This (should) allow sdl/utils.hpp to be modified without a huge rebuild, since a number of widely used headers included that file simply for the surface class type. --- src/CMakeLists.txt | 1 + src/SConscript | 1 + src/construct_dialog.cpp | 2 +- src/floating_label.hpp | 2 +- src/font/marked-up_text.cpp | 2 +- src/font/sdl_ttf.cpp | 2 +- src/font/text.hpp | 1 + src/font/text_cache.cpp | 2 +- src/font/text_surface.cpp | 2 +- src/game_launcher.cpp | 2 +- src/gui/core/canvas.hpp | 2 +- src/gui/widgets/window.cpp | 2 +- src/help/help.cpp | 2 +- src/help/help_impl.cpp | 2 +- src/help/help_text_area.hpp | 2 +- src/hotkey/hotkey_item.cpp | 2 +- src/image_modifications.hpp | 1 + src/joystick.cpp | 3 +- src/minimap.cpp | 2 +- src/scripting/game_lua_kernel.cpp | 2 +- src/sdl/rect.cpp | 2 +- src/sdl/surface.cpp | 111 ++++++++++++++++++++ src/sdl/surface.hpp | 163 ++++++++++++++++++++++++++++++ src/sdl/utils.cpp | 78 -------------- src/sdl/utils.hpp | 140 +------------------------ src/sdl/window.cpp | 2 +- src/storyscreen/part.cpp | 1 + src/storyscreen/part.hpp | 2 +- src/tests/test_sdl_utils.hpp | 2 +- src/tools/exploder_cutter.hpp | 2 +- src/tools/exploder_utils.hpp | 2 +- src/tooltips.hpp | 2 +- src/units/drawer.cpp | 2 +- src/wesmage/filter.hpp | 2 +- src/widgets/menu.hpp | 1 + src/widgets/menu_style.cpp | 1 + src/widgets/scrollpane.hpp | 2 +- src/widgets/slider.hpp | 1 + src/widgets/widget.hpp | 2 +- 39 files changed, 311 insertions(+), 244 deletions(-) create mode 100644 src/sdl/surface.cpp create mode 100644 src/sdl/surface.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dbeb6bdd513..de934a2d960 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -365,6 +365,7 @@ set_target_properties(wesnoth-lua set(wesnoth-sdl_SRC sdl/exception.cpp sdl/rect.cpp + sdl/surface.cpp sdl/window.cpp sdl/utils.cpp xBRZ/xbrz.cpp diff --git a/src/SConscript b/src/SConscript index f2dd782103d..e7e2146d48d 100644 --- a/src/SConscript +++ b/src/SConscript @@ -157,6 +157,7 @@ libcampaignd = env.Library("campaignd", libcampaignd_sources, OBJPREFIX = "campa libwesnoth_sdl_sources = Split(""" sdl/exception.cpp sdl/rect.cpp + sdl/surface.cpp sdl/utils.cpp sdl/window.cpp tracer.cpp diff --git a/src/construct_dialog.cpp b/src/construct_dialog.cpp index 46915c2960e..51a31b70834 100644 --- a/src/construct_dialog.cpp +++ b/src/construct_dialog.cpp @@ -27,7 +27,7 @@ #include "font/standard_colors.hpp" #include "scripting/plugins/context.hpp" #include "scripting/plugins/manager.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "sdl/rect.hpp" #include "utils/functional.hpp" diff --git a/src/floating_label.hpp b/src/floating_label.hpp index 8c994136c1b..8d7b7199fbe 100644 --- a/src/floating_label.hpp +++ b/src/floating_label.hpp @@ -15,7 +15,7 @@ #pragma once #include "color.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include namespace font { diff --git a/src/font/marked-up_text.cpp b/src/font/marked-up_text.cpp index c554514bc8a..fed7cb59999 100644 --- a/src/font/marked-up_text.cpp +++ b/src/font/marked-up_text.cpp @@ -26,7 +26,7 @@ #include "gettext.hpp" #include "font/marked-up_text.hpp" #include "font/standard_colors.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "serialization/string_utils.hpp" #include "serialization/unicode.hpp" #include "video.hpp" diff --git a/src/font/sdl_ttf.cpp b/src/font/sdl_ttf.cpp index 39ac6081a68..0c0f84bbfc8 100644 --- a/src/font/sdl_ttf.cpp +++ b/src/font/sdl_ttf.cpp @@ -28,7 +28,7 @@ #include "tooltips.hpp" #include "sdl/rect.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "serialization/unicode.hpp" #include diff --git a/src/font/text.hpp b/src/font/text.hpp index aa00688015f..3ff50179b8c 100644 --- a/src/font/text.hpp +++ b/src/font/text.hpp @@ -17,6 +17,7 @@ #include "font/font_options.hpp" #include "color.hpp" +#include "sdl/surface.hpp" #include "sdl/utils.hpp" #include "serialization/unicode_types.hpp" diff --git a/src/font/text_cache.cpp b/src/font/text_cache.cpp index 1939035d21c..dc35e6da53a 100644 --- a/src/font/text_cache.cpp +++ b/src/font/text_cache.cpp @@ -13,7 +13,7 @@ */ #include "font/text_cache.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include diff --git a/src/font/text_surface.cpp b/src/font/text_surface.cpp index bb139735372..9b02c66ef1e 100644 --- a/src/font/text_surface.cpp +++ b/src/font/text_surface.cpp @@ -16,7 +16,7 @@ #include "font/sdl_ttf.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "log.hpp" diff --git a/src/game_launcher.cpp b/src/game_launcher.cpp index 8f4f846297c..bf4f85a23e6 100644 --- a/src/game_launcher.cpp +++ b/src/game_launcher.cpp @@ -51,7 +51,7 @@ #include "preferences_display.hpp" #include "savegame.hpp" // for clean_saves, etc #include "scripting/application_lua_kernel.hpp" -#include "sdl/utils.hpp" // for surface +#include "sdl/surface.hpp" // for surface #include "serialization/compression.hpp" // for format::NONE #include "serialization/string_utils.hpp" // for split #include "game_initialization/singleplayer.hpp" // for sp_create_mode diff --git a/src/gui/core/canvas.hpp b/src/gui/core/canvas.hpp index d8d810c1cef..a1ca054c1a4 100644 --- a/src/gui/core/canvas.hpp +++ b/src/gui/core/canvas.hpp @@ -22,7 +22,7 @@ #define GUI_AUXILIARY_CANVAS_HPP_INCLUDED #include "formula/callable.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" class config; class variant; diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 61e035506d7..7eac195a4e6 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -55,7 +55,7 @@ #include "preferences.hpp" #include "preferences_display.hpp" #include "sdl/rect.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "tstring.hpp" #include "formula/variant.hpp" #include "video.hpp" diff --git a/src/help/help.cpp b/src/help/help.cpp index 8e9f5b06ba2..c242a715bef 100644 --- a/src/help/help.cpp +++ b/src/help/help.cpp @@ -32,7 +32,7 @@ #include "help/help_impl.hpp" // for hidden_symbol, toplevel, etc #include "key.hpp" // for CKey #include "log.hpp" // for LOG_STREAM, log_domain -#include "sdl/utils.hpp" // for surface +#include "sdl/surface.hpp" // for surface #include "show_dialog.hpp" // for dialog_frame, etc #include "terrain/terrain.hpp" // for terrain_type #include "units/unit.hpp" // for unit diff --git a/src/help/help_impl.cpp b/src/help/help_impl.cpp index e5075f65424..4a889a89421 100644 --- a/src/help/help_impl.cpp +++ b/src/help/help_impl.cpp @@ -31,7 +31,7 @@ #include "font/standard_colors.hpp" // for NORMAL_COLOR #include "units/race.hpp" // for unit_race, etc #include "resources.hpp" // for tod_manager, config_manager -#include "sdl/utils.hpp" // for surface +#include "sdl/surface.hpp" // for surface #include "serialization/string_utils.hpp" // for split, quoted_split, etc #include "serialization/unicode_cast.hpp" // for unicode_cast #include "serialization/unicode_types.hpp" // for char_t, etc diff --git a/src/help/help_text_area.hpp b/src/help/help_text_area.hpp index f569390651a..25dfadfadbf 100644 --- a/src/help/help_text_area.hpp +++ b/src/help/help_text_area.hpp @@ -19,7 +19,7 @@ #include // for string #include // for pair #include "font/standard_colors.hpp" // for NORMAL_COLOR -#include "sdl/utils.hpp" // for surface +#include "sdl/surface.hpp" // for surface #include "widgets/scrollarea.hpp" // for scrollarea class CVideo; class config; diff --git a/src/hotkey/hotkey_item.cpp b/src/hotkey/hotkey_item.cpp index 9964cb187f1..8cbd037e219 100644 --- a/src/hotkey/hotkey_item.cpp +++ b/src/hotkey/hotkey_item.cpp @@ -22,7 +22,7 @@ #include "gettext.hpp" #include "serialization/unicode.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include #include diff --git a/src/image_modifications.hpp b/src/image_modifications.hpp index ebecc34eb8b..a7095d97957 100644 --- a/src/image_modifications.hpp +++ b/src/image_modifications.hpp @@ -19,6 +19,7 @@ #include "color_range.hpp" #include "lua_jailbreak_exception.hpp" +#include "sdl/surface.hpp" #include "sdl/utils.hpp" #include diff --git a/src/joystick.cpp b/src/joystick.cpp index 7044c1b902f..5db5fd4b389 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -15,7 +15,8 @@ #include "joystick.hpp" #include "preferences.hpp" #include "log.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" +#include "util.hpp" #include using namespace boost::math::constants; diff --git a/src/minimap.cpp b/src/minimap.cpp index 8de0891b51f..9a9749adc03 100644 --- a/src/minimap.cpp +++ b/src/minimap.cpp @@ -24,7 +24,7 @@ #include "map/map.hpp" #include "resources.hpp" #include "color.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "team.hpp" #include "terrain/type_data.hpp" #include "wml_exception.hpp" diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index b3c5a4375a9..ea7ba3d5701 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -83,7 +83,7 @@ #include "scripting/lua_unit_type.hpp" #include "scripting/push_check.hpp" #include "color.hpp" // for surface -#include "sdl/utils.hpp" // for surface +#include "sdl/surface.hpp" // for surface #include "side_filter.hpp" // for side_filter #include "sound.hpp" // for commit_music_changes, etc #include "soundsource.hpp" diff --git a/src/sdl/rect.cpp b/src/sdl/rect.cpp index a5a76b22f33..827d585cb28 100644 --- a/src/sdl/rect.cpp +++ b/src/sdl/rect.cpp @@ -14,7 +14,7 @@ #include "gui/core/point.hpp" #include "sdl/rect.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" namespace sdl { diff --git a/src/sdl/surface.cpp b/src/sdl/surface.cpp new file mode 100644 index 00000000000..bf68fa803fe --- /dev/null +++ b/src/sdl/surface.cpp @@ -0,0 +1,111 @@ +/* + Copyright (C) 2003 - 2016 the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#include "sdl/surface.hpp" + +#include "sdl/rect.hpp" +#include "video.hpp" + +surface_restorer::surface_restorer() + : target_(nullptr) + , rect_(sdl::empty_rect) + , surface_(nullptr) +{ +} + +surface_restorer::surface_restorer(CVideo* target, const SDL_Rect& rect) + : target_(target) + , rect_(rect) + , surface_(nullptr) +{ + update(); +} + +surface_restorer::~surface_restorer() +{ + restore(); +} + +void surface_restorer::restore(SDL_Rect const &dst) const +{ + if(surface_.null()) { + return; + } + + SDL_Rect dst2 = sdl::intersect_rects(dst, rect_); + if(dst2.w == 0 || dst2.h == 0) { + return; + } + + SDL_Rect src = dst2; + src.x -= rect_.x; + src.y -= rect_.y; + sdl_blit(surface_, &src, target_->getSurface(), &dst2); +} + +void surface_restorer::restore() const +{ + if(surface_.null()) { + return; + } + + SDL_Rect dst = rect_; + sdl_blit(surface_, nullptr, target_->getSurface(), &dst); +} + +void surface_restorer::update() +{ + if(rect_.w <= 0 || rect_.h <= 0) { + surface_.assign(nullptr); + } else { + surface_.assign(::get_surface_portion(target_->getSurface(),rect_)); + } +} + +void surface_restorer::cancel() +{ + surface_.assign(nullptr); +} + +surface_lock::surface_lock(surface &surf) : surface_(surf), locked_(false) +{ + if(SDL_MUSTLOCK(surface_)) { + locked_ = SDL_LockSurface(surface_) == 0; + } +} + +surface_lock::~surface_lock() +{ + if(locked_) { + SDL_UnlockSurface(surface_); + } +} + +const_surface_lock::const_surface_lock(const surface &surf) : surface_(surf), locked_(false) +{ + if(SDL_MUSTLOCK(surface_)) { + locked_ = SDL_LockSurface(surface_) == 0; + } +} + +const_surface_lock::~const_surface_lock() +{ + if(locked_) { + SDL_UnlockSurface(surface_); + } +} + +bool operator<(const surface& a, const surface& b) +{ + return a.get() < b.get(); +} diff --git a/src/sdl/surface.hpp b/src/sdl/surface.hpp new file mode 100644 index 00000000000..f759f65b33e --- /dev/null +++ b/src/sdl/surface.hpp @@ -0,0 +1,163 @@ +/* + Copyright (C) 2003 - 2016 the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#ifndef SDL_SURFACE_HEADER_INCLUDED +#define SDL_SURFACE_HEADER_INCLUDED + +#include + +class CVideo; + +class surface +{ +public: + surface() : surface_(nullptr) + {} + + surface(SDL_Surface* surf) : surface_(surf) + {} + + surface(const surface& s) : surface_(s.get()) + { + add_surface_ref(surface_); + } + + ~surface() + { + free_surface(); + } + + void assign(SDL_Surface* surf) + { + assign_surface_internal(surf); + } + + void assign(const surface& s) + { + assign_surface_internal(s.get()); + } + + surface& operator=(const surface& s) + { + assign(s); + return *this; + } + + operator SDL_Surface*() const { return surface_; } + + SDL_Surface* get() const { return surface_; } + + SDL_Surface* operator->() const { return surface_; } + + bool null() const { return surface_ == nullptr; } + +private: + static void add_surface_ref(SDL_Surface* surf) + { + if(surf) { + ++surf->refcount; + } + } + + void assign_surface_internal(SDL_Surface* surf) + { + add_surface_ref(surf); // Needs to be done before assignment to avoid corruption on "a = a;" + free_surface(); + surface_ = surf; + } + + void free_surface() + { + if(surface_) { + SDL_FreeSurface(surface_); + } + } + + SDL_Surface* surface_; +}; + +bool operator<(const surface& a, const surface& b); + +struct surface_restorer +{ + surface_restorer(); + surface_restorer(class CVideo* target, const SDL_Rect& rect); + ~surface_restorer(); + + void restore() const; + void restore(SDL_Rect const &dst) const; + void update(); + void cancel(); + + const SDL_Rect& area() const { return rect_; } + +private: + class CVideo* target_; + SDL_Rect rect_; + surface surface_; +}; + +/** + * Helper class for pinning SDL surfaces into memory. + * @note This class should be used only with neutral surfaces, so that + * the pointer returned by #pixels is meaningful. + */ +struct surface_lock +{ + surface_lock(surface &surf); + ~surface_lock(); + + Uint32* pixels() { return reinterpret_cast(surface_->pixels); } + +private: + surface& surface_; + bool locked_; +}; + +struct const_surface_lock +{ + const_surface_lock(const surface &surf); + ~const_surface_lock(); + + const Uint32* pixels() const { return reinterpret_cast(surface_->pixels); } + +private: + const surface& surface_; + bool locked_; +}; + +struct clip_rect_setter +{ + // if r is nullptr, clip to the full size of the surface. + clip_rect_setter(const surface &surf, const SDL_Rect* r, bool operate = true) : surface_(surf), rect_(), operate_(operate) + { + if(operate_){ + SDL_GetClipRect(surface_, &rect_); + SDL_SetClipRect(surface_, r); + } + } + + ~clip_rect_setter() + { + if(operate_) { + SDL_SetClipRect(surface_, &rect_); + } + } + +private: + surface surface_; + SDL_Rect rect_; + const bool operate_; +}; + +#endif diff --git a/src/sdl/utils.cpp b/src/sdl/utils.cpp index 43ddfc2a7ce..7f701afe4a1 100644 --- a/src/sdl/utils.cpp +++ b/src/sdl/utils.cpp @@ -37,40 +37,11 @@ #include -surface_lock::surface_lock(surface &surf) : surface_(surf), locked_(false) -{ - if (SDL_MUSTLOCK(surface_)) - locked_ = SDL_LockSurface(surface_) == 0; -} - -surface_lock::~surface_lock() -{ - if (locked_) - SDL_UnlockSurface(surface_); -} - -const_surface_lock::const_surface_lock(const surface &surf) : surface_(surf), locked_(false) -{ - if (SDL_MUSTLOCK(surface_)) - locked_ = SDL_LockSurface(surface_) == 0; -} - -const_surface_lock::~const_surface_lock() -{ - if (locked_) - SDL_UnlockSurface(surface_); -} - SDL_Keycode sdl_keysym_from_name(const std::string& keyname) { return SDL_GetKeyFromName(keyname.c_str()); } -bool operator<(const surface& a, const surface& b) -{ - return a.get() < b.get(); -} - bool is_neutral(const surface& surf) { return (surf->format->BytesPerPixel == 4 && @@ -2462,55 +2433,6 @@ SDL_Rect get_non_transparent_portion(const surface &surf) return res; } -surface_restorer::surface_restorer() : target_(nullptr), rect_(sdl::empty_rect), surface_(nullptr) -{ -} - -surface_restorer::surface_restorer(CVideo* target, const SDL_Rect& rect) -: target_(target), rect_(rect), surface_(nullptr) -{ - update(); -} - -surface_restorer::~surface_restorer() -{ - restore(); -} - -void surface_restorer::restore(SDL_Rect const &dst) const -{ - if (surface_.null()) - return; - SDL_Rect dst2 = sdl::intersect_rects(dst, rect_); - if (dst2.w == 0 || dst2.h == 0) - return; - SDL_Rect src = dst2; - src.x -= rect_.x; - src.y -= rect_.y; - sdl_blit(surface_, &src, target_->getSurface(), &dst2); -} - -void surface_restorer::restore() const -{ - if (surface_.null()) - return; - SDL_Rect dst = rect_; - sdl_blit(surface_, nullptr, target_->getSurface(), &dst); -} - -void surface_restorer::update() -{ - if(rect_.w <= 0 || rect_.h <= 0) - surface_.assign(nullptr); - else - surface_.assign(::get_surface_portion(target_->getSurface(),rect_)); -} - -void surface_restorer::cancel() -{ - surface_.assign(nullptr); -} - void draw_centered_on_background(surface surf, const SDL_Rect& rect, const color_t& color, surface target) { clip_rect_setter clip_setter(target, &rect); diff --git a/src/sdl/utils.hpp b/src/sdl/utils.hpp index da31e430ac2..01343119bc2 100644 --- a/src/sdl/utils.hpp +++ b/src/sdl/utils.hpp @@ -19,87 +19,17 @@ #include "color_range.hpp" #include "color.hpp" +#include "sdl/surface.hpp" #include "util.hpp" #include #include -#include #include #include SDL_Keycode sdl_keysym_from_name(const std::string& keyname); -class surface -{ -public: - surface() : surface_(nullptr) - {} - - surface(SDL_Surface* surf) : surface_(surf) - {} - - surface(const surface& s) : surface_(s.get()) - { - add_surface_ref(surface_); - } - - ~surface() - { - free_surface(); - } - - void assign(SDL_Surface* surf) - { - assign_surface_internal(surf); - } - - void assign(const surface& s) - { - assign_surface_internal(s.get()); - } - - surface& operator=(const surface& s) - { - assign(s); - return *this; - } - - operator SDL_Surface*() const { return surface_; } - - SDL_Surface* get() const { return surface_; } - - SDL_Surface* operator->() const { return surface_; } - - bool null() const { return surface_ == nullptr; } - -private: - static void add_surface_ref(SDL_Surface* surf) - { - if(surf) { - ++surf->refcount; - } - } - - void assign_surface_internal(SDL_Surface* surf) - { - add_surface_ref(surf); // Needs to be done before assignment to avoid corruption on "a = a;" - free_surface(); - surface_ = surf; - } - - void free_surface() - { - if(surface_) { - SDL_FreeSurface(surface_); - } - } - - SDL_Surface* surface_; -}; - -bool operator<(const surface& a, const surface& b); - inline void sdl_blit(const surface& src, SDL_Rect* src_rect, surface& dst, SDL_Rect* dst_rect){ SDL_BlitSurface(src, src_rect, dst, dst_rect); } @@ -409,33 +339,6 @@ void blit_surface(const surface& src, SDL_Rect get_non_transparent_portion(const surface &surf); -/** - * Helper class for pinning SDL surfaces into memory. - * @note This class should be used only with neutral surfaces, so that - * the pointer returned by #pixels is meaningful. - */ -struct surface_lock -{ - surface_lock(surface &surf); - ~surface_lock(); - - Uint32* pixels() { return reinterpret_cast(surface_->pixels); } -private: - surface& surface_; - bool locked_; -}; - -struct const_surface_lock -{ - const_surface_lock(const surface &surf); - ~const_surface_lock(); - - const Uint32* pixels() const { return reinterpret_cast(surface_->pixels); } -private: - const surface& surface_; - bool locked_; -}; - /** * Helper methods for setting/getting a single pixel in an image. * Lifted from http://sdl.beuc.net/sdl.wiki/Pixel_Access @@ -448,47 +351,6 @@ private: void put_pixel(const surface& surf, surface_lock& surf_lock, int x, int y, Uint32 pixel); Uint32 get_pixel(const surface& surf, const const_surface_lock& surf_lock, int x, int y); -struct surface_restorer -{ - surface_restorer(); - surface_restorer(class CVideo* target, const SDL_Rect& rect); - ~surface_restorer(); - - void restore() const; - void restore(SDL_Rect const &dst) const; - void update(); - void cancel(); - - const SDL_Rect& area() const { return rect_; } - -private: - class CVideo* target_; - SDL_Rect rect_; - surface surface_; -}; - -struct clip_rect_setter -{ - // if r is nullptr, clip to the full size of the surface. - clip_rect_setter(const surface &surf, const SDL_Rect* r, bool operate = true) : surface_(surf), rect_(), operate_(operate) - { - if(operate_){ - SDL_GetClipRect(surface_, &rect_); - SDL_SetClipRect(surface_, r); - } - } - - ~clip_rect_setter() { - if (operate_) - SDL_SetClipRect(surface_, &rect_); - } - -private: - surface surface_; - SDL_Rect rect_; - const bool operate_; -}; - // blit the image on the center of the rectangle // and a add a colored background void draw_centered_on_background(surface surf, const SDL_Rect& rect, diff --git a/src/sdl/window.cpp b/src/sdl/window.cpp index 236d56400fa..2a2ee4085b6 100644 --- a/src/sdl/window.cpp +++ b/src/sdl/window.cpp @@ -12,7 +12,7 @@ See the COPYING file for more details. */ -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "sdl/window.hpp" #include "sdl/exception.hpp" diff --git a/src/storyscreen/part.cpp b/src/storyscreen/part.cpp index 1f350cbc722..ba01079ffdd 100644 --- a/src/storyscreen/part.cpp +++ b/src/storyscreen/part.cpp @@ -29,6 +29,7 @@ #include "game_events/pump.hpp" #include "image.hpp" #include "serialization/string_utils.hpp" +#include "sdl/utils.hpp" #include "variable.hpp" namespace storyscreen { diff --git a/src/storyscreen/part.hpp b/src/storyscreen/part.hpp index 276bf9fbe4f..69b628901a5 100644 --- a/src/storyscreen/part.hpp +++ b/src/storyscreen/part.hpp @@ -24,7 +24,7 @@ #include #include -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" class config; class vconfig; diff --git a/src/tests/test_sdl_utils.hpp b/src/tests/test_sdl_utils.hpp index 96564b22573..6874321a8f5 100644 --- a/src/tests/test_sdl_utils.hpp +++ b/src/tests/test_sdl_utils.hpp @@ -15,7 +15,7 @@ #ifndef TESTS_TEST_SDL_UTILS_HPP_INCLUDED #define TESTS_TEST_SDL_UTILS_HPP_INCLUDED -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "utils/functional.hpp" diff --git a/src/tools/exploder_cutter.hpp b/src/tools/exploder_cutter.hpp index 604bf741866..95c2c20f711 100644 --- a/src/tools/exploder_cutter.hpp +++ b/src/tools/exploder_cutter.hpp @@ -15,7 +15,7 @@ #ifndef EXPLODER_CUTTER_HPP_INCLUDED #define EXPLODER_CUTTER_HPP_INCLUDED -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "config.hpp" #include "exploder_utils.hpp" diff --git a/src/tools/exploder_utils.hpp b/src/tools/exploder_utils.hpp index 749cad5a0e0..8550a662a43 100644 --- a/src/tools/exploder_utils.hpp +++ b/src/tools/exploder_utils.hpp @@ -15,7 +15,7 @@ #ifndef EXPLODER_UTILS_HPP_INCLUDED #define EXPLODER_UTILS_HPP_INCLUDED -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include struct exploder_failure diff --git a/src/tooltips.hpp b/src/tooltips.hpp index 66a5296c33a..02ce4d5140d 100644 --- a/src/tooltips.hpp +++ b/src/tooltips.hpp @@ -16,7 +16,7 @@ #define TOOLTIPS_HPP_INCLUDED #include -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" class CVideo; struct SDL_Rect; diff --git a/src/units/drawer.cpp b/src/units/drawer.cpp index 9ecfd624423..44ff9167ba5 100644 --- a/src/units/drawer.cpp +++ b/src/units/drawer.cpp @@ -22,7 +22,7 @@ #include "map/map.hpp" #include "map/location.hpp" #include "color.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "team.hpp" #include "units/unit.hpp" #include "units/animation.hpp" diff --git a/src/wesmage/filter.hpp b/src/wesmage/filter.hpp index e62b0a3fd04..4034dbffaf1 100644 --- a/src/wesmage/filter.hpp +++ b/src/wesmage/filter.hpp @@ -20,7 +20,7 @@ #ifndef WESMAGE_FILTER_HPP_INCLUDED #define WESMAGE_FILTER_HPP_INCLUDED -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include #include diff --git a/src/widgets/menu.hpp b/src/widgets/menu.hpp index 5e2e1bd1d43..3f2e3fa49ec 100644 --- a/src/widgets/menu.hpp +++ b/src/widgets/menu.hpp @@ -15,6 +15,7 @@ #ifndef WIDGET_MENU_HPP_INCLUDED #define WIDGET_MENU_HPP_INCLUDED +#include #include #include "scrollarea.hpp" diff --git a/src/widgets/menu_style.cpp b/src/widgets/menu_style.cpp index 765fa6330d9..8e646b2338b 100644 --- a/src/widgets/menu_style.cpp +++ b/src/widgets/menu_style.cpp @@ -21,6 +21,7 @@ #include "font/sdl_ttf.hpp" #include "image.hpp" +#include "sdl/utils.hpp" #include "video.hpp" namespace gui { diff --git a/src/widgets/scrollpane.hpp b/src/widgets/scrollpane.hpp index 85509dcbe95..9a7404bbe31 100644 --- a/src/widgets/scrollpane.hpp +++ b/src/widgets/scrollpane.hpp @@ -21,7 +21,7 @@ #include #include -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" #include "scrollarea.hpp" namespace gui { diff --git a/src/widgets/slider.hpp b/src/widgets/slider.hpp index 7c61dc41a62..c767dbd7347 100644 --- a/src/widgets/slider.hpp +++ b/src/widgets/slider.hpp @@ -16,6 +16,7 @@ #include +#include "color.hpp" #include "widget.hpp" #include diff --git a/src/widgets/widget.hpp b/src/widgets/widget.hpp index f4fc9342071..5065fd20dcd 100644 --- a/src/widgets/widget.hpp +++ b/src/widgets/widget.hpp @@ -16,7 +16,7 @@ #define WIDGET_HPP_INCLUDED #include "events.hpp" -#include "sdl/utils.hpp" +#include "sdl/surface.hpp" class CVideo;