Skip to content

Commit

Permalink
Split SDL_Surface wrapper class and related helper struts into their …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Vultraz committed Dec 10, 2016
1 parent 09e73db commit b97a20b
Show file tree
Hide file tree
Showing 39 changed files with 311 additions and 244 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/SConscript
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/construct_dialog.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/floating_label.hpp
Expand Up @@ -15,7 +15,7 @@
#pragma once

#include "color.hpp"
#include "sdl/utils.hpp"
#include "sdl/surface.hpp"
#include <string>

namespace font {
Expand Down
2 changes: 1 addition & 1 deletion src/font/marked-up_text.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/font/sdl_ttf.cpp
Expand Up @@ -28,7 +28,7 @@
#include "tooltips.hpp"

#include "sdl/rect.hpp"
#include "sdl/utils.hpp"
#include "sdl/surface.hpp"
#include "serialization/unicode.hpp"

#include <SDL_ttf.h>
Expand Down
1 change: 1 addition & 0 deletions src/font/text.hpp
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/font/text_cache.cpp
Expand Up @@ -13,7 +13,7 @@
*/

#include "font/text_cache.hpp"
#include "sdl/utils.hpp"
#include "sdl/surface.hpp"

#include <algorithm>

Expand Down
2 changes: 1 addition & 1 deletion src/font/text_surface.cpp
Expand Up @@ -16,7 +16,7 @@

#include "font/sdl_ttf.hpp"

#include "sdl/utils.hpp"
#include "sdl/surface.hpp"

#include "log.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/game_launcher.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/core/canvas.hpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/window.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/help/help.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/help/help_impl.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/help/help_text_area.hpp
Expand Up @@ -19,7 +19,7 @@
#include <string> // for string
#include <utility> // 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;
Expand Down
2 changes: 1 addition & 1 deletion src/hotkey/hotkey_item.cpp
Expand Up @@ -22,7 +22,7 @@

#include "gettext.hpp"
#include "serialization/unicode.hpp"
#include "sdl/utils.hpp"
#include "sdl/surface.hpp"

#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/image_modifications.hpp
Expand Up @@ -19,6 +19,7 @@

#include "color_range.hpp"
#include "lua_jailbreak_exception.hpp"
#include "sdl/surface.hpp"
#include "sdl/utils.hpp"
#include <queue>

Expand Down
3 changes: 2 additions & 1 deletion src/joystick.cpp
Expand Up @@ -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 <boost/math/constants/constants.hpp>
using namespace boost::math::constants;

Expand Down
2 changes: 1 addition & 1 deletion src/minimap.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/game_lua_kernel.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/sdl/rect.cpp
Expand Up @@ -14,7 +14,7 @@

#include "gui/core/point.hpp"
#include "sdl/rect.hpp"
#include "sdl/utils.hpp"
#include "sdl/surface.hpp"

namespace sdl
{
Expand Down
111 changes: 111 additions & 0 deletions 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();
}

0 comments on commit b97a20b

Please sign in to comment.