[gnome-games] ui: Add InputModeSwitcher



commit b4b20af866a4f0282cbf1c6d292e2ce7324adcb6
Author: Yetizone <andreii lisita gmail com>
Date:   Wed Nov 7 20:04:58 2018 +0200

    ui: Add InputModeSwitcher

 data/org.gnome.Games.gresource.xml |  1 +
 data/ui/input-mode-switcher.ui     | 48 +++++++++++++++++++++++++++++++++++
 src/meson.build                    |  1 +
 src/ui/input-mode-switcher.vala    | 51 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 101 insertions(+)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index fdde9da8..9cf2e1bc 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -26,6 +26,7 @@
     <file preprocess="xml-stripblanks">ui/gamepad-mapper.ui</file>
     <file preprocess="xml-stripblanks">ui/gamepad-tester.ui</file>
     <file preprocess="xml-stripblanks">ui/game-icon-view.ui</file>
+    <file preprocess="xml-stripblanks">ui/input-mode-switcher.ui</file>
     <file preprocess="xml-stripblanks">ui/keyboard-mapper.ui</file>
     <file preprocess="xml-stripblanks">ui/keyboard-tester.ui</file>
     <file preprocess="xml-stripblanks">ui/media-menu-button.ui</file>
diff --git a/data/ui/input-mode-switcher.ui b/data/ui/input-mode-switcher.ui
new file mode 100644
index 00000000..12270121
--- /dev/null
+++ b/data/ui/input-mode-switcher.ui
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GamesInputModeSwitcher" parent="GtkBox">
+    <style>
+      <class name="linked"/>
+    </style>
+    <child>
+      <object class="GtkRadioButton" id="gamepad_mode">
+        <property name="visible">True</property>
+        <property name="draw-indicator">False</property>
+        <property name="can-focus">False</property>
+        <signal name="toggled" handler="on_gamepad_button_toggled"/>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="a11y-gamepad-input">
+            <property name="accessible-name" translatable="yes">Gamepad Input</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage" id="gamepad_image">
+            <property name="visible">True</property>
+            <property name="icon-name">input-gaming-symbolic</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkRadioButton" id="keyboard_mode">
+        <property name="visible">True</property>
+        <property name="draw-indicator">False</property>
+        <property name="can-focus">False</property>
+        <property name="group">gamepad_mode</property>
+        <signal name="toggled" handler="on_keyboard_button_toggled"/>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="a11y-keyboard-input">
+            <property name="accessible-name" translatable="yes">Keyboard Input</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage" id="keyboard_image">
+            <property name="visible">True</property>
+            <property name="icon-name">input-keyboard-symbolic</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/meson.build b/src/meson.build
index 1511d0f8..88beca3b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -146,6 +146,7 @@ vala_sources = [
   'ui/game-icon-view.vala',
   'ui/game-thumbnail.vala',
   'ui/gamepad-view-configuration.vala',
+  'ui/input-mode-switcher.vala',
   'ui/keyboard-mapper.vala',
   'ui/keyboard-tester.vala',
   'ui/konami-code.vala',
diff --git a/src/ui/input-mode-switcher.vala b/src/ui/input-mode-switcher.vala
new file mode 100644
index 00000000..68e31091
--- /dev/null
+++ b/src/ui/input-mode-switcher.vala
@@ -0,0 +1,51 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/input-mode-switcher.ui")]
+private class Games.InputModeSwitcher : Gtk.Box {
+       private Runner _runner;
+       public Runner runner {
+               get { return _runner; }
+               set {
+                       _runner = value;
+
+                       if (value == null) {
+                               visible = false;
+                               return;
+                       }
+
+                       runner.notify["input-mode"].connect (on_input_mode_changed);
+                       visible = (value.get_available_input_modes ().length >= 2);
+                       on_input_mode_changed ();
+               }
+       }
+
+       private void on_input_mode_changed () {
+               switch (runner.input_mode) {
+               case InputMode.GAMEPAD:
+                       gamepad_mode.active = true;
+
+                       break;
+               case InputMode.KEYBOARD:
+                       keyboard_mode.active = true;
+
+                       break;
+               }
+       }
+
+       [GtkChild]
+       private Gtk.RadioButton keyboard_mode;
+       [GtkChild]
+       private Gtk.RadioButton gamepad_mode;
+
+       [GtkCallback]
+       private void on_keyboard_button_toggled () {
+               if (keyboard_mode.active)
+                       runner.input_mode = InputMode.KEYBOARD;
+       }
+
+       [GtkCallback]
+       private void on_gamepad_button_toggled () {
+               if (gamepad_mode.active)
+                       runner.input_mode = InputMode.GAMEPAD;
+       }
+}


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