[gnome-games/wip/abhinavsingh/gamepad-config: 9/12] gamepad: Add GamepadView & its dependency librsvg



commit e846b56bc9571130ae392af9522343679ad95e2b
Author: theawless <theawless gmail com>
Date:   Sun May 28 13:16:32 2017 +0530

    gamepad: Add GamepadView & its dependency librsvg
    
    This highlights gamepad's individual inputs.

 configure.ac             |    1 +
 src/Makefile.am          |    2 +
 src/ui/gamepad-view.vala |   68 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5d95cf6..e049478 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ PKG_CHECK_MODULES(GNOME_GAMES, [
        glib-2.0 >= $GLIB_MIN_VERSION
        grilo-0.3
        gtk+-3.0
+       librsvg-2.0
        libsoup-2.4
        libxml-2.0
        retro-gtk-0.10
diff --git a/src/Makefile.am b/src/Makefile.am
index 60c68c8..fde9547 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -123,6 +123,7 @@ gnome_games_SOURCES = \
        ui/empty-collection.vala \
        ui/error-display.vala \
        ui/error-info-bar.vala \
+       ui/gamepad-view.vala \
        ui/game-icon-view.vala \
        ui/game-thumbnail.vala \
        ui/media-selector.vala \
@@ -186,6 +187,7 @@ gnome_games_VALAFLAGS = \
        --pkg glib-2.0 \
        --pkg grilo-0.3 \
        --pkg gtk+-3.0 \
+       --pkg librsvg-2.0 \
        --pkg libsoup-2.4 \
        --pkg libxml-2.0 \
        --pkg tracker-sparql-1.0 \
diff --git a/src/ui/gamepad-view.vala b/src/ui/gamepad-view.vala
new file mode 100644
index 0000000..3c6f1fa
--- /dev/null
+++ b/src/ui/gamepad-view.vala
@@ -0,0 +1,68 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.GamepadView : Gtk.DrawingArea {
+       private const string STANDARD_GAMEPAD_SVG_PATH = 
"resource:///org/gnome/Games/gamepads/standard-gamepad.svg";
+
+       private Rsvg.Handle handle;
+       private string[] highlight_paths = { "ellipse395", "ellipse393", "ellipse431", "ellipse389",
+                                            "ellipse385", "ellipse370",
+                                            "rect397", "rect211", "rect399", "rect217",
+                                            "rect415", "rect427", "rect429", "rect425",
+                                            "rect387", "ellipse391", "rect223",
+                                            "ellipse385", "ellipse370", "ellipse385", "ellipse370" };
+       private GamepadInput[] inputs;
+       private int current_input_index;
+
+       construct {
+               try {
+                       handle = new Rsvg.Handle.from_file (STANDARD_GAMEPAD_SVG_PATH);
+                       set_size_request (handle.width, handle.height);
+               }
+               catch (Error e) {
+                       warning (e.message);
+               }
+
+               inputs = GamepadInput.get_standard_inputs ();
+               current_input_index = -1;
+       }
+
+       public GamepadInput? highlight_next () {
+               current_input_index += 1;
+               queue_draw ();
+
+               if (current_input_index >= inputs.length)
+                       return null;
+
+               return inputs[current_input_index];
+       }
+
+       public override bool draw (Cairo.Context gamepad_context) {
+               var color = get_style_context ().get_color (Gtk.StateFlags.LINK);
+               gamepad_context.set_source_rgba (color.red, color.green, color.blue, color.alpha);
+
+               handle.render_cairo (gamepad_context);
+
+               var highlight_context = make_highlight_context (gamepad_context);
+               if (highlight_context == null)
+                       return false;
+
+               var highlight_surface = highlight_context.get_target ();
+               gamepad_context.mask_surface (highlight_surface, 0, 0);
+
+               return false;
+       }
+
+       private Cairo.Context? make_highlight_context (Cairo.Context gamepad_context) {
+               if (!(0 <= current_input_index && current_input_index < inputs.length))
+                       return null;
+
+               var gamepad_surface = gamepad_context.get_target ();
+               var highlight_surface = new Cairo.Surface.similar (gamepad_surface, Cairo.Content.COLOR_ALPHA,
+                                                                  handle.width, handle.height);
+               var highlight_context = new Cairo.Context (highlight_surface);
+               var highlight_path = "#" + highlight_paths[current_input_index];
+               handle.render_cairo_sub (highlight_context, highlight_path);
+
+               return highlight_context;
+       }
+}


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