[gnome-games/wip/exalm/ds: 7/9] nintendo-ds: Add NintendoDsLayoutSwitcher



commit d25520e28b83908e38b2db3958450aef353dd4a9
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Jan 6 20:48:44 2019 +0500

    nintendo-ds: Add NintendoDsLayoutSwitcher

 plugins/nintendo-ds/data/nintendo-ds.gresource.xml |  1 +
 .../data/ui/nintendo-ds-layout-switcher.ui         | 34 +++++++++
 plugins/nintendo-ds/src/meson.build                |  1 +
 .../src/nintendo-ds-layout-switcher.vala           | 82 ++++++++++++++++++++++
 4 files changed, 118 insertions(+)
---
diff --git a/plugins/nintendo-ds/data/nintendo-ds.gresource.xml 
b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
index 8a9a07e0..c54dc5b5 100644
--- a/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
+++ b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/org/gnome/Games/plugins/nintendo-ds">
     <file>ui/nintendo-ds-layout-item.ui</file>
+    <file>ui/nintendo-ds-layout-switcher.ui</file>
   </gresource>
 </gresources>
diff --git a/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui 
b/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui
new file mode 100644
index 00000000..882d828e
--- /dev/null
+++ b/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GamesNintendoDsLayoutSwitcher" parent="GtkMenuButton">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="popover">layout_popover</property>
+    <style>
+      <class name="image-button"/>
+    </style>
+    <child internal-child="accessible">
+      <object class="AtkObject" id="a11y-display-discs">
+        <property name="accessible-name" translatable="yes">Screen Layout</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkImage" id="layout_image">
+        <property name="visible">True</property>
+      </object>
+    </child>
+  </template>
+  <object class="GtkPopover" id="layout_popover">
+    <property name="visible">False</property>
+    <child>
+      <object class="GtkFlowBox" id="flow_box">
+        <property name="visible">True</property>
+        <property name="margin">6</property>
+        <property name="homogeneous">True</property>
+        <property name="max-children-per-line">2</property>
+        <signal name="child-activated" handler="on_item_activated"/>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/plugins/nintendo-ds/src/meson.build b/plugins/nintendo-ds/src/meson.build
index 358c0f46..a8713655 100644
--- a/plugins/nintendo-ds/src/meson.build
+++ b/plugins/nintendo-ds/src/meson.build
@@ -1,6 +1,7 @@
 vala_sources = [
   'nintendo-ds-icon.vala',
   'nintendo-ds-layout-item.vala',
+  'nintendo-ds-layout-switcher.vala',
   'nintendo-ds-plugin.vala',
 ]
 
diff --git a/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala 
b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
new file mode 100644
index 00000000..c23d4145
--- /dev/null
+++ b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
@@ -0,0 +1,82 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/plugins/nintendo-ds/ui/nintendo-ds-layout-switcher.ui")]
+private class Games.NintendoDsLayoutSwitcher : Gtk.MenuButton {
+       [GtkChild]
+       private Gtk.Image layout_image;
+       [GtkChild]
+       private Gtk.Popover layout_popover;
+       [GtkChild]
+       private Gtk.FlowBox flow_box;
+
+       private Settings settings;
+       private HashTable<string, NintendoDsLayoutItem> items;
+
+       private string[] LAYOUTS = {
+               "top/bottom",
+               "left/right",
+       };
+
+       construct {
+               items = new HashTable<string, NintendoDsLayoutItem> (str_hash, str_equal);
+               foreach (string layout in LAYOUTS) {
+                       string name = get_layout_name (layout);
+                       string icon = get_layout_icon (layout);
+
+                       var item = new NintendoDsLayoutItem (layout, name, icon);
+                       items[layout] = item;
+
+                       flow_box.add (item);
+               }
+
+               settings = new Settings ("org.gnome.Games.plugins.nintendo-ds");
+               settings.changed.connect (update_ui);
+
+               layout_popover.show.connect (update_ui);
+
+               update_ui ();
+       }
+
+       private void update_ui () {
+               var layout = settings.get_string ("screen-layout");
+
+               layout_image.icon_name = get_layout_icon (layout);
+
+               var item = items[layout];
+
+               flow_box.select_child (item);
+       }
+
+       [GtkCallback]
+       private void on_item_activated (Gtk.FlowBoxChild child) {
+               var layout_item = child as NintendoDsLayoutItem;
+
+               var layout = layout_item.get_layout ();
+
+               settings.set_string ("screen-layout", layout);
+       }
+
+       private string get_layout_icon (string layout) {
+               switch (layout) {
+               case "top/bottom":
+                       return "go-up-symbolic";
+
+               case "left/right":
+                       return "go-previous-symbolic";
+               }
+
+               return "video-display-symbolic";
+       }
+
+       private string get_layout_name (string layout) {
+               switch (layout) {
+               case "top/bottom":
+                       return _("Vertical");
+
+               case "left/right":
+                       return _("Horizontal");
+               }
+
+               return _("Unknown");
+       }
+}


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