From b225b8d658268d5c73bccc7e8ed3ab03912a37c8 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Thu, 8 Jun 2017 01:50:41 +1100 Subject: [PATCH] Enabled drawing of minimap in-game --- src/display.cpp | 5 +---- src/sdl/utils.cpp | 24 ++++++++++++++---------- src/sdl/utils.hpp | 8 ++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 1931d2f4ce0b9..ce4c0fc2244e9 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1779,11 +1779,8 @@ void display::draw_minimap() } } - const surface& screen(screen_.getSurface()); - clip_rect_setter clip_setter(screen, &area); - color_t back_color {31,31,23,SDL_ALPHA_OPAQUE}; - draw_centered_on_background(minimap_, area, back_color, screen); + draw_centered_on_background(minimap_, area, back_color); //update the minimap location for mouse and units functions minimap_location_.x = area.x + (area.w - minimap_->w) / 2; diff --git a/src/sdl/utils.cpp b/src/sdl/utils.cpp index 2a47667494a0b..99d2f82e7ae54 100644 --- a/src/sdl/utils.cpp +++ b/src/sdl/utils.cpp @@ -19,6 +19,7 @@ #include "sdl/utils.hpp" #include "sdl/rect.hpp" +#include "sdl/render_utils.hpp" #include "color.hpp" #include "serialization/string_utils.hpp" @@ -2339,19 +2340,22 @@ SDL_Rect get_non_transparent_portion(const surface &surf) return res; } -void draw_centered_on_background(surface surf, const SDL_Rect& rect, const color_t& color, surface target) +void draw_centered_on_background(surface surf, const SDL_Rect& rect, const color_t& color) { - clip_rect_setter clip_setter(target, &rect); - - Uint32 col = SDL_MapRGBA(target->format, color.r, color.g, color.b, color.a); - //TODO: only draw background outside the image SDL_Rect r = rect; - sdl::fill_surface_rect(target, &r, col); - if (surf != nullptr) { - r.x = rect.x + (rect.w-surf->w)/2; - r.y = rect.y + (rect.h-surf->h)/2; - sdl_blit(surf, nullptr, target, &r); + render_clip_rect_setter clip_setter(&r); + + sdl::fill_rectangle(r, color); + + if(surf != nullptr) { + r.x = rect.x + (rect.w - surf->w) / 2; + r.y = rect.y + (rect.h - surf->h) / 2; + r.w = surf->w; + r.h = surf->h; + + texture tex(surf); + CVideo::get_singleton().copy_to_screen(tex, nullptr, &r); } } diff --git a/src/sdl/utils.hpp b/src/sdl/utils.hpp index 5996e05dc9472..51b69170c8537 100644 --- a/src/sdl/utils.hpp +++ b/src/sdl/utils.hpp @@ -327,7 +327,7 @@ SDL_Rect get_non_transparent_portion(const surface &surf); 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); -// 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, - const color_t& color, surface target); +/** + * Fills the provided rect with the provided color and draws the given image in the center. + */ +void draw_centered_on_background(surface surf, const SDL_Rect& rect, const color_t& color);