Commit b7e28996 authored by AndreiLisita's avatar AndreiLisita 🎮 Committed by Alexander Mikhaylenko

ui: Add FlashBox

A class that implements a flash effect which will be used when
creating new savestates.
parent de9c97f2
......@@ -53,6 +53,10 @@ gamescollectioniconview.large flowboxchild {
min-width: 256px;
}
gamesflashbox {
background: rgba (255, 255, 255, 0.5);
}
/* Styles from libhandy example, this should be kept in sync with this:
* https://source.puri.sm/Librem5/libhandy/blob/master/examples/style.css
*/
......
......@@ -146,6 +146,7 @@ vala_sources = [
'ui/empty-collection.vala',
'ui/error-display.vala',
'ui/error-info-bar.vala',
'ui/flash-box.vala',
'ui/fullscreen-box.vala',
'ui/gamepad-browse.vala',
'ui/gamepad-mapper.vala',
......
// This file is part of GNOME Games. License: GPL-3.0+.
private class Games.FlashBox : Gtk.Widget {
private const int64 FLASH_DURATION = 500; //milliseconds
static construct {
set_css_name ("gamesflashbox");
}
construct {
set_has_window (false);
opacity = 0;
}
private int64 flash_start_time;
private uint tick_callback_id;
public override bool draw (Cairo.Context cr) {
var width = get_allocated_width ();
var height = get_allocated_height ();
get_style_context ().render_background (cr, 0, 0, width, height);
return true;
}
public void flash () {
if (tick_callback_id == 0) {
tick_callback_id = add_tick_callback (on_tick);
visible = true;
}
flash_start_time = get_frame_clock ().get_frame_time () / 1000;
opacity = 1;
}
private bool on_tick (Gtk.Widget widget, Gdk.FrameClock frame_clock) {
var frame_time = frame_clock.get_frame_time () / 1000;
var t = (double) (frame_time - flash_start_time) / FLASH_DURATION;
opacity = 1 - ease_out_quad (t);
if (t >= 1) {
opacity = 0;
visible = false;
tick_callback_id = 0;
return false;
}
return true;
}
private double ease_out_quad (double t) {
return t * (2 - t);
}
public override void destroy () {
if (tick_callback_id != 0)
remove_tick_callback (tick_callback_id);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment