Skip to content

Commit

Permalink
Enabled drawing of minimap in-game
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jul 9, 2017
1 parent b55ac52 commit 0ca1a93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
5 changes: 1 addition & 4 deletions src/display.cpp
Expand Up @@ -1769,11 +1769,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;
Expand Down
24 changes: 14 additions & 10 deletions src/sdl/utils.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/sdl/utils.hpp
Expand Up @@ -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);

0 comments on commit 0ca1a93

Please sign in to comment.