[gnome-games/wip/exalm/ds: 1/3] nintendo-ds: Add NintendoDsLayoutSwitcher



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

    nintendo-ds: Add NintendoDsLayoutSwitcher

 .../icons/screen-layout-left-right-symbolic.svg    | 65 ++++++++++++++++
 .../icons/screen-layout-top-bottom-symbolic.svg    | 65 ++++++++++++++++
 plugins/nintendo-ds/data/nintendo-ds.gresource.xml |  3 +
 .../data/ui/nintendo-ds-layout-switcher.ui         | 34 +++++++++
 plugins/nintendo-ds/src/meson.build                |  1 +
 .../src/nintendo-ds-layout-switcher.vala           | 87 ++++++++++++++++++++++
 6 files changed, 255 insertions(+)
---
diff --git a/plugins/nintendo-ds/data/icons/screen-layout-left-right-symbolic.svg 
b/plugins/nintendo-ds/data/icons/screen-layout-left-right-symbolic.svg
new file mode 100644
index 00000000..7672dca0
--- /dev/null
+++ b/plugins/nintendo-ds/data/icons/screen-layout-left-right-symbolic.svg
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/";
+   xmlns:cc="http://creativecommons.org/ns#";
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+   xmlns:svg="http://www.w3.org/2000/svg";
+   xmlns="http://www.w3.org/2000/svg";
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
+   width="16"
+   height="16"
+   version="1.1"
+   id="svg6"
+   sodipodi:docname="screen-layout-left-right-symbolic.svg"
+   inkscape:version="0.92.2 2405546, 2018-03-11">
+  <metadata
+     id="metadata12">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage"; />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <defs
+     id="defs10" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1920"
+     inkscape:window-height="1016"
+     id="namedview8"
+     showgrid="false"
+     showguides="false"
+     inkscape:zoom="29.5"
+     inkscape:cx="10.229323"
+     inkscape:cy="5.4519204"
+     inkscape:window-x="0"
+     inkscape:window-y="27"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="svg6" />
+  <path
+     inkscape:connector-curvature="0"
+     id="path2"
+     overflow="visible"
+     style="color:#000000;overflow:visible;opacity:0.5;fill:#474747;marker:none"
+     d="m 16.00025,4.384 v 7.2315 c 0,0.213 -0.226442,0.421768 -0.502,0.385 L 8,12.00025 v -8 L 15.49825,4 c 
0.278,-9.3e-6 0.502,0.17 0.502,0.384 z"
+     sodipodi:nodetypes="sssccss" />
+  <path
+     sodipodi:nodetypes="csssscc"
+     d="m 8,12.00025 -7.49825,2.5e-4 c -0.27800049,9e-6 -0.502,-0.172 -0.502,-0.385 v -7.231 c 0,-0.215 
0.224,-0.385 0.502,-0.385 C 2.83375,3.9995 8,3.99975 8,3.99975 Z"
+     style="color:#000000;overflow:visible;fill:#474747;marker:none"
+     overflow="visible"
+     id="path823"
+     inkscape:connector-curvature="0" />
+</svg>
diff --git a/plugins/nintendo-ds/data/icons/screen-layout-top-bottom-symbolic.svg 
b/plugins/nintendo-ds/data/icons/screen-layout-top-bottom-symbolic.svg
new file mode 100644
index 00000000..604064c8
--- /dev/null
+++ b/plugins/nintendo-ds/data/icons/screen-layout-top-bottom-symbolic.svg
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/";
+   xmlns:cc="http://creativecommons.org/ns#";
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+   xmlns:svg="http://www.w3.org/2000/svg";
+   xmlns="http://www.w3.org/2000/svg";
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
+   width="16"
+   height="16"
+   version="1.1"
+   id="svg6"
+   sodipodi:docname="screen-layout-top-bottom-symbolic.svg"
+   inkscape:version="0.92.2 2405546, 2018-03-11">
+  <metadata
+     id="metadata12">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage"; />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <defs
+     id="defs10" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1920"
+     inkscape:window-height="1016"
+     id="namedview8"
+     showgrid="false"
+     showguides="true"
+     inkscape:zoom="29.5"
+     inkscape:cx="0.69365193"
+     inkscape:cy="5.5990053"
+     inkscape:window-x="0"
+     inkscape:window-y="27"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="svg6" />
+  <path
+     inkscape:connector-curvature="0"
+     id="path2"
+     overflow="visible"
+     style="color:#000000;overflow:visible;opacity:0.5;fill:#474747;marker:none"
+     d="m 14,14.6155 c 0,0.213 -0.224,0.385 -0.502,0.385 H 2.502 C 2.224,15.0005 1.9383611,14.819386 
2,14.6155 V 8 h 12 z"
+     sodipodi:nodetypes="ssssccs" />
+  <path
+     sodipodi:nodetypes="sccssss"
+     d="M 14,1.3835 V 8 H 2 V 1.3845 c 0,-0.215 0.224,-0.385 0.502,-0.385 h 10.996 c 0.278,0 
0.56392,0.1791539 0.502,0.384 z"
+     style="color:#000000;overflow:visible;fill:#474747;marker:none"
+     overflow="visible"
+     id="path823"
+     inkscape:connector-curvature="0" />
+</svg>
diff --git a/plugins/nintendo-ds/data/nintendo-ds.gresource.xml 
b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
index 8a9a07e0..f08ef338 100644
--- a/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
+++ b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
@@ -2,5 +2,8 @@
 <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>
+    <file>icons/screen-layout-left-right-symbolic.svg</file>
+    <file>icons/screen-layout-top-bottom-symbolic.svg</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..9bd2d35e
--- /dev/null
+++ b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
@@ -0,0 +1,87 @@
+// 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",
+       };
+
+       static construct {
+               var icon_theme = Gtk.IconTheme.get_default ();
+               icon_theme.add_resource_path ("/org/gnome/Games/plugins/nintendo-ds/icons");
+       }
+
+       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 "screen-layout-top-bottom-symbolic";
+
+               case "left/right":
+                       return "screen-layout-left-right-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]