diff --git a/changelog b/changelog index 2e65c7eddf8..8fa75a7143f 100644 --- a/changelog +++ b/changelog @@ -43,6 +43,7 @@ Version 1.13.1+dev: Windows now display console output directly instead of using stdout.txt and stderr.txt. * Remember last selected modifications separately for single and multiplayer. + * Fixed SDL2 compilation issues. Version 1.13.1: * Security fixes: diff --git a/data/core/about.cfg b/data/core/about.cfg index 32df940e230..3232c229ef1 100644 --- a/data/core/about.cfg +++ b/data/core/about.cfg @@ -984,6 +984,9 @@ [entry] name = "Andrea Palmatè (afxgroup)" [/entry] + [entry] + name = "Andreas Löf (Aginor)" + [/entry] [entry] name = "Andrius Šilinskas (thunderstruck)" [/entry] diff --git a/src/attack_prediction_display.cpp b/src/attack_prediction_display.cpp index 6a3dd39f3e8..02562e81448 100644 --- a/src/attack_prediction_display.cpp +++ b/src/attack_prediction_display.cpp @@ -504,17 +504,31 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector(static_cast((prob * (bar_space - 4)) + 0.5), 2); +#if SDL_VERSION_ATLEAST(2,0,0) SDL_Rect bar_rect_1 = sdl::create_rect(hp_sep + 4, 6 + (fs + 2) * i, bar_len, 8); - sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 100)); + sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 100)); SDL_Rect bar_rect_2 = sdl::create_rect(hp_sep + 4, 7 + (fs + 2) * i, bar_len, 6); - sdl::fill_rect(surf, &bar_rect_2, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 66)); + sdl::fill_rect(surf, &bar_rect_2, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 66)); SDL_Rect bar_rect_3 = sdl::create_rect(hp_sep + 4, 8 + (fs + 2) * i, bar_len, 4); - sdl::fill_rect(surf, &bar_rect_3, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 33)); + sdl::fill_rect(surf, &bar_rect_3, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 33)); SDL_Rect bar_rect_4 = sdl::create_rect(hp_sep + 4, 9 + (fs + 2) * i, bar_len, 2); - sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 0)); + sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 0)); +#else + SDL_Rect bar_rect_1 = sdl::create_rect(hp_sep + 4, 6 + (fs + 2) * i, bar_len, 8); + sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 100)); + + SDL_Rect bar_rect_2 = sdl::create_rect(hp_sep + 4, 7 + (fs + 2) * i, bar_len, 6); + sdl::fill_rect(surf, &bar_rect_2, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 66)); + + SDL_Rect bar_rect_3 = sdl::create_rect(hp_sep + 4, 8 + (fs + 2) * i, bar_len, 4); + sdl::fill_rect(surf, &bar_rect_3, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 33)); + + SDL_Rect bar_rect_4 = sdl::create_rect(hp_sep + 4, 9 + (fs + 2) * i, bar_len, 2); + sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 0)); +#endif // Draw probability percentage, aligned right. format_prob(str_buf, prob); diff --git a/src/build_info.cpp b/src/build_info.cpp index 6a303a15a26..15caeaebbd9 100644 --- a/src/build_info.cpp +++ b/src/build_info.cpp @@ -73,6 +73,7 @@ version_table_manager::version_table_manager() SDL_version sdl_version; const SDL_version* sdl_rt_version = NULL; + // // SDL // @@ -80,10 +81,15 @@ version_table_manager::version_table_manager() SDL_VERSION(&sdl_version); compiled[LIB_SDL] = format_version(sdl_version); +#if SDL_VERSION_ATLEAST(2,0,0) + SDL_GetVersion(&sdl_version); + linked[LIB_SDL] = format_version(sdl_version); +#else sdl_rt_version = SDL_Linked_Version(); if(sdl_rt_version) { linked[LIB_SDL] = format_version(*sdl_rt_version); } +#endif names[LIB_SDL] = "SDL"; diff --git a/src/desktop/clipboard.cpp b/src/desktop/clipboard.cpp index 2b7eadfc735..d624690413e 100644 --- a/src/desktop/clipboard.cpp +++ b/src/desktop/clipboard.cpp @@ -59,6 +59,11 @@ void handle_system_event(const SDL_Event& /*event*/) { } +bool available() +{ + return false; +} + } // end namespace clipboard } // end namespace desktop diff --git a/src/filesystem_common.cpp b/src/filesystem_common.cpp index 2a0b03a40c2..cdcb265e6d3 100644 --- a/src/filesystem_common.cpp +++ b/src/filesystem_common.cpp @@ -201,15 +201,25 @@ const file_tree_checksum& data_tree_checksum(bool reset) return checksum; } - +#if SDL_VERSION_ATLEAST(2,0,0) +static Sint64 ifs_size (struct SDL_RWops * context); +static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence); +static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum); +static size_t SDLCALL ifs_write(struct SDL_RWops *context, const void *ptr, size_t size, size_t num); +static int SDLCALL ifs_close(struct SDL_RWops *context); +#else static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence); static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int maxnum); static int SDLCALL ifs_write(struct SDL_RWops *context, const void *ptr, int size, int num); static int SDLCALL ifs_close(struct SDL_RWops *context); +#endif SDL_RWops* load_RWops(const std::string &path) { SDL_RWops *rw = SDL_AllocRW(); +#if SDL_VERSION_ATLEAST(2,0,0) + rw->size = &ifs_size; +#endif rw->seek = &ifs_seek; rw->read = &ifs_read; rw->write = &ifs_write; @@ -228,7 +238,29 @@ SDL_RWops* load_RWops(const std::string &path) { return rw; } + +#if SDL_VERSION_ATLEAST(2,0,0) +static Sint64 ifs_size (struct SDL_RWops * context) { + std::istream *ifs = static_cast(context->hidden.unknown.data1); + std::streampos orig = ifs->tellg(); + + ifs->seekg(0, std::ios::end); + + std::streampos len = ifs->tellg(); + + ifs->seekg(orig); + + return len; + +} +#endif + +#if SDL_VERSION_ATLEAST(2,0,0) +static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence) { +#else static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence) { +#endif + std::ios_base::seekdir seekdir; switch(whence){ case RW_SEEK_SET: @@ -261,7 +293,12 @@ static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence) { std::streamsize pos = ifs->tellg(); return static_cast(pos); } + +#if SDL_VERSION_ATLEAST(2,0,0) +static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum) { +#else static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int maxnum) { +#endif std::istream *ifs = static_cast(context->hidden.unknown.data1); // This seems overly simplistic, but it's the same as mem_read's implementation @@ -274,7 +311,12 @@ static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int return static_cast(num); } + +#if SDL_VERSION_ATLEAST(2,0,0) +static size_t SDLCALL ifs_write(struct SDL_RWops * /*context*/, const void * /*ptr*/, size_t /*size*/, size_t /*num*/) { +#else static int SDLCALL ifs_write(struct SDL_RWops * /*context*/, const void * /*ptr*/, int /*size*/, int /*num*/) { +#endif SDL_SetError("Writing not implemented"); return 0; } diff --git a/src/floating_label.cpp b/src/floating_label.cpp index 93d7e1f864d..54add8529a5 100644 --- a/src/floating_label.cpp +++ b/src/floating_label.cpp @@ -23,6 +23,10 @@ #include #include +#if SDL_VERSION_ATLEAST(2,0,0) +#include "sdl/alpha.hpp" +#endif + static lg::log_domain log_font("font"); #define DBG_FT LOG_STREAM(debug, log_font) #define LOG_FT LOG_STREAM(info, log_font) diff --git a/src/loadscreen.cpp b/src/loadscreen.cpp index e89af97986c..b049bcfed1b 100644 --- a/src/loadscreen.cpp +++ b/src/loadscreen.cpp @@ -205,7 +205,13 @@ void loadscreen::draw_screen(const std::string &text) // Pump events and make sure to redraw the logo if there's a chance that it's been obscured SDL_Event ev; while(SDL_PollEvent(&ev)) { +#if SDL_VERSION_ATLEAST(2,0,0) + if (ev.type == SDL_WINDOWEVENT && + (ev.window.type == SDL_WINDOWEVENT_RESIZED || + ev.window.type == SDL_WINDOWEVENT_EXPOSED)) +#else if(ev.type == SDL_VIDEORESIZE || ev.type == SDL_VIDEOEXPOSE) +#endif { logo_drawn_ = false; } diff --git a/src/sdl/window.cpp b/src/sdl/window.cpp index 2d5b1c203ed..05a13f655dd 100644 --- a/src/sdl/window.cpp +++ b/src/sdl/window.cpp @@ -99,6 +99,7 @@ void twindow::set_icon(const surface& icon) SDL_SetWindowIcon(window_, icon); } +#if TTEXTURE ttexture twindow::create_texture(const int access, const int w, const int h) { return ttexture(*SDL_GetRenderer(window_), pixel_format_, access, w, h); @@ -119,6 +120,7 @@ void twindow::draw(ttexture& texture, const int x, const int y) { texture.draw(*SDL_GetRenderer(window_), x, y); } +#endif twindow::operator SDL_Window*() { diff --git a/src/sdl/window.hpp b/src/sdl/window.hpp index 2831c4a971b..373b0fb6f38 100644 --- a/src/sdl/window.hpp +++ b/src/sdl/window.hpp @@ -38,7 +38,9 @@ struct SDL_Renderer; namespace sdl { +#if TTEXTURE class ttexture; +#endif /** * The wrapper class for the @ref SDL_Window class. @@ -131,6 +133,7 @@ public: */ void set_icon(const surface& icon); +#if TTEXTURE /** * Creates a texture for the renderer of this object. * @@ -179,7 +182,7 @@ public: * @param y Forwarded to @ref ttexture::draw. */ void draw(ttexture& texture, const int x, const int y); - +#endif /***** ***** ***** Conversion operators. ***** ***** *****/ diff --git a/src/storyscreen/render.cpp b/src/storyscreen/render.cpp index 9065a642f2a..0c09373126d 100644 --- a/src/storyscreen/render.cpp +++ b/src/storyscreen/render.cpp @@ -315,6 +315,12 @@ void part_ui::prepare_floating_images() void part_ui::render_background() { #if SDL_VERSION_ATLEAST(2,0,0) + sdl::draw_solid_tinted_rectangle( + 0, 0, video_.getx(), video_.gety(), 0, 0, 0, 1.0, + video_.getSurface() + ); + sdl_blit(background_, NULL, video_.getSurface(), NULL); +#if 0 sdl::twindow *wnd = CVideo::get_window(); wnd->fill(0, 0, 0); for (size_t i = 0; idraw(background_images_[i], x, y); } +#endif #else #ifdef SDL_GPU GPU_Target *target = get_render_target(); diff --git a/src/text.hpp b/src/text.hpp index d878553878b..3dfa5cfbdf0 100644 --- a/src/text.hpp +++ b/src/text.hpp @@ -258,13 +258,8 @@ private: /** The surface to render upon used as a cache. */ mutable surface surface_; -#if SDL_VERSION_ATLEAST(2,0,0) - /** The texture to render upon used as a cache. */ - mutable sdl::ttexture texture_; -#else #ifdef SDL_GPU mutable sdl::timage texture_; -#endif #endif /** The text to draw (stored as UTF-8). */