diff --git a/src/display.cpp b/src/display.cpp index 00b6a12ed0e..1a889802869 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -2357,6 +2357,35 @@ double display::turbo_speed() const return 1.0; } +void display::fade_to(const color_t& c, int duration) +{ + uint32_t start = SDL_GetTicks(); + color_t fade_start = fade_color_; + + // If we started transparent, assume the same colour + if(fade_start.a == 0) { + fade_start.r = c.r; + fade_start.g = c.g; + fade_start.b = c.b; + } + + // Smoothly blend and display + for(uint32_t now = start; now < start + duration; now = SDL_GetTicks()) { + float prop_f = float(now - start) / float(duration); + uint8_t p = float_to_color(prop_f); + fade_color_ = fade_start.smooth_blend(c, p); + draw_manager::invalidate_region(map_outside_area()); + events::pump(); + events::raise_draw_event(); + } + fade_color_ = c; +} + +void display::set_fade(const color_t& c) +{ + fade_color_ = c; +} + void display::redraw_everything() { if(screen_.update_locked()) @@ -2562,6 +2591,11 @@ bool display::expose(const SDL_Rect& region) // TODO: draw_manager - hmm... buttons redraw over tooltips, because they are TLDs font::draw_floating_labels(); + // If there's a fade, apply it over everything + if(fade_color_.a) { + draw::fill(map_outside_area().intersect(region), fade_color_); + } + return true; // TODO: draw_manager - maybe don't flip yeah? } diff --git a/src/display.hpp b/src/display.hpp index 2aa451c33e4..e4136c033a7 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -563,6 +563,14 @@ public: /** Checks if location @a loc or one of the adjacent tiles is visible on screen. */ bool tile_nearly_on_screen(const map_location &loc) const; + /** Screen fade */ + void fade_to(const color_t& color, int duration); + void set_fade(const color_t& color); + +private: + color_t fade_color_ = {0,0,0,0}; + +public: /** * Draws invalidated items. * If update is true, will also copy the display to the frame buffer.