mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-04 21:30:24 +00:00
display: Add the capability to fade the game display to a solid colour
Currently this is simply display.fade_to(colour, fade_time).
This commit is contained in:
parent
d9acaf3c71
commit
859f10a232
@ -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?
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user