[gnome-games] ui: Add FlashBox



commit b7e2899674d6e925512db009558cb9ae6efa7615
Author: Yetizone <andreii lisita gmail com>
Date:   Thu Aug 15 23:59:43 2019 +0300

    ui: Add FlashBox
    
    A class that implements a flash effect which will be used when
    creating new savestates.

 data/gtk-style.css    |  4 ++++
 src/meson.build       |  1 +
 src/ui/flash-box.vala | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+)
---
diff --git a/data/gtk-style.css b/data/gtk-style.css
index e0e212ac..602f05e4 100644
--- a/data/gtk-style.css
+++ b/data/gtk-style.css
@@ -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
  */
diff --git a/src/meson.build b/src/meson.build
index 358bc8e3..86696c50 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -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',
diff --git a/src/ui/flash-box.vala b/src/ui/flash-box.vala
new file mode 100644
index 00000000..f7d9f144
--- /dev/null
+++ b/src/ui/flash-box.vala
@@ -0,0 +1,62 @@
+// 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);
+       }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]