diff --git a/changelog b/changelog index 5cf7bff72c0..ca0d91e0c51 100644 --- a/changelog +++ b/changelog @@ -35,6 +35,8 @@ Version 1.3-svn: * star shaped "ellipses" for leaders and hero units * crown icons for heros and expendable allied leaders. * item graphic improvements including animate-able campfire. + * added the option to draw overlays on terrains filter by + location, selected and mouseover hex * terrain * added peaks to the impassable mountains * added bridges crossing swamp and deep water diff --git a/src/display.cpp b/src/display.cpp index d86e69e7989..261b6181f76 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1551,6 +1551,25 @@ void display::draw_tile(const gamemap::location &loc, const SDL_Rect &clip_rect) } } + // Add the top layer overlay surfaces + if(! hex_overlay_.empty()) { + std::map::const_iterator itor = hex_overlay_.find(loc); + if(itor != hex_overlay_.end()) { + SDL_Rect dstrect = { xpos, ypos, 0, 0 }; + SDL_BlitSurface(itor->second,NULL,dst,&dstrect); + } + } + + if(loc == selectedHex_ && map_.on_board(selectedHex_) && selected_hex_overlay_ != NULL) { + SDL_Rect dstrect = { xpos, ypos, 0, 0 }; + SDL_BlitSurface(selected_hex_overlay_,NULL,dst,&dstrect); + } + + if(loc == mouseoverHex_ && map_.on_board(mouseoverHex_) && mouseover_hex_overlay_ != NULL) { + SDL_Rect dstrect = { xpos, ypos, 0, 0 }; + SDL_BlitSurface(mouseover_hex_overlay_,NULL,dst,&dstrect); + } + update_rect(xpos,ypos,zoom_,zoom_); } @@ -2003,6 +2022,16 @@ void display::float_label(const gamemap::location& loc, const std::string& text, 0,-2,60,screen_area(),font::CENTER_ALIGN,NULL,0,font::ANCHOR_LABEL_MAP); } +void display::clear_hex_overlay(const gamemap::location& loc) +{ + if(! hex_overlay_.empty()) { + std::map::iterator itor = hex_overlay_.find(loc); + if(itor != hex_overlay_.end()) { + hex_overlay_.erase(itor); + } + } +} + void display::draw_unit(int x, int y, surface image, bool upside_down, fixed_t alpha, Uint32 blendto, double blend_ratio, double submerged, surface ellipse_back, surface ellipse_front) diff --git a/src/display.hpp b/src/display.hpp index b7f6dc92be7..5c46d2c8ca2 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -195,6 +195,24 @@ public: int red, int green, int blue); const gamemap& get_map()const { return map_;} + + // The last action in drawing a tile is adding the overlays + // these overlays are drawn in the following order + // hex_overlay_ if the drawn location is in the map + // selected_hex_overlay_ if the drawn location is selected + // mouseover_hex_overlay_ if the drawn location is underneath the mouse + // + // These functions require a prerendered surface since they are + // drawn at the top, they are not influenced by TOD, shroud etc + void set_hex_overlay(const gamemap::location& loc, surface image) { hex_overlay_[loc] = image; } + void clear_hex_overlay(const gamemap::location& loc); + + void set_selected_hex_overlay(const surface& image) { selected_hex_overlay_ = image; } + void clear_selected_hex_overlay() { selected_hex_overlay_ = NULL; } + + void set_mouseover_hex_overlay(const surface& image) { mouseover_hex_overlay_ = image; } + void clear_mouseover_hex_overlay() { mouseover_hex_overlay_ = NULL; } + private: enum ADJACENT_TERRAIN_TYPE { ADJACENT_BACKGROUND, ADJACENT_FOREGROUND, ADJACENT_FOGSHROUD }; @@ -419,6 +437,10 @@ private: int xpos_, ypos_, zoom_; const gamemap& map_; + std::map hex_overlay_; + surface selected_hex_overlay_; + surface mouseover_hex_overlay_; + gamemap::location selectedHex_; gamemap::location mouseoverHex_; @@ -457,7 +479,7 @@ private: struct overlay { overlay(const std::string& img, const std::string& halo_img, int handle) : image(img), halo(halo_img), - halo_handle(handle) {} + halo_handle(handle) {} std::string image; std::string halo; int halo_handle;