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



commit bd3112aa49b302ec557e379a24bd955eac3000a5
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    | 70 ++++++++++++++++
 .../icons/screen-layout-right-left-symbolic.svg    | 71 ++++++++++++++++
 .../icons/screen-layout-top-bottom-symbolic.svg    | 71 ++++++++++++++++
 plugins/nintendo-ds/data/nintendo-ds.gresource.xml |  4 +
 .../data/ui/nintendo-ds-layout-switcher.ui         | 34 ++++++++
 plugins/nintendo-ds/src/meson.build                |  1 +
 .../src/nintendo-ds-layout-switcher.vala           | 94 ++++++++++++++++++++++
 7 files changed, 345 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..66c963f4
--- /dev/null
+++ b/plugins/nintendo-ds/data/icons/screen-layout-left-right-symbolic.svg
@@ -0,0 +1,70 @@
+<?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="svg8"
+   sodipodi:docname="ds-touchscreen-right.svg"
+   inkscape:version="0.92.2 2405546, 2018-03-11">
+  <metadata
+     id="metadata14">
+    <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="defs12" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="2560"
+     inkscape:window-height="1376"
+     id="namedview10"
+     showgrid="true"
+     inkscape:zoom="64"
+     inkscape:cx="3.6767386"
+     inkscape:cy="8.1664307"
+     inkscape:window-x="0"
+     inkscape:window-y="27"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="svg8">
+    <inkscape:grid
+       type="xygrid"
+       id="grid4526" />
+  </sodipodi:namedview>
+  <g
+     id="g873">
+    <rect
+       y="5.5"
+       x="7.5"
+       height="6"
+       width="6"
+       id="rect869"
+       
style="opacity:0.5;fill:#474747;fill-opacity:1;stroke:none;stroke-width:1.2544198;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
 />
+    <path
+       sodipodi:nodetypes="ssssssssscccccccccc"
+       inkscape:connector-curvature="0"
+       id="path4659-5"
+       d="M 15,6 C 15,5.057191 13.942809,4 13,4 H 2 C 1.057191,4 0,5.057191 0,6 v 5 c 0,0.942809 1.057191,2 
2,2 h 11 c 0.942809,0 2,-1.057191 2,-2 z m -2,0 v 5 H 8 V 6 Z M 7,6 v 5 H 2 V 6 Z"
+       
style="fill:#474747;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
 />
+  </g>
+</svg>
diff --git a/plugins/nintendo-ds/data/icons/screen-layout-right-left-symbolic.svg 
b/plugins/nintendo-ds/data/icons/screen-layout-right-left-symbolic.svg
new file mode 100644
index 00000000..0219572b
--- /dev/null
+++ b/plugins/nintendo-ds/data/icons/screen-layout-right-left-symbolic.svg
@@ -0,0 +1,71 @@
+<?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="svg8"
+   sodipodi:docname="ds-touchscreen-left.svg"
+   inkscape:version="0.92.2 2405546, 2018-03-11">
+  <metadata
+     id="metadata14">
+    <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="defs12" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="2560"
+     inkscape:window-height="1376"
+     id="namedview10"
+     showgrid="true"
+     inkscape:zoom="64"
+     inkscape:cx="3.6767386"
+     inkscape:cy="8.1664307"
+     inkscape:window-x="0"
+     inkscape:window-y="27"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="svg8">
+    <inkscape:grid
+       type="xygrid"
+       id="grid4526" />
+  </sodipodi:namedview>
+  <g
+     id="g873"
+     transform="matrix(-1,0,0,1,15,0)">
+    <rect
+       y="5.5"
+       x="7.5"
+       height="6"
+       width="6"
+       id="rect869"
+       
style="opacity:0.5;fill:#474747;fill-opacity:1;stroke:none;stroke-width:1.2544198;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
 />
+    <path
+       sodipodi:nodetypes="ssssssssscccccccccc"
+       inkscape:connector-curvature="0"
+       id="path4659-5"
+       d="M 15,6 C 15,5.057191 13.942809,4 13,4 H 2 C 1.057191,4 0,5.057191 0,6 v 5 c 0,0.942809 1.057191,2 
2,2 h 11 c 0.942809,0 2,-1.057191 2,-2 z m -2,0 v 5 H 8 V 6 Z M 7,6 v 5 H 2 V 6 Z"
+       
style="fill:#474747;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
 />
+  </g>
+</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..5f633d76
--- /dev/null
+++ b/plugins/nintendo-ds/data/icons/screen-layout-top-bottom-symbolic.svg
@@ -0,0 +1,71 @@
+<?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="svg8"
+   sodipodi:docname="ds-touchscreen-bottom.svg"
+   inkscape:version="0.92.2 2405546, 2018-03-11">
+  <metadata
+     id="metadata14">
+    <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="defs12" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="2560"
+     inkscape:window-height="1376"
+     id="namedview10"
+     showgrid="true"
+     inkscape:zoom="64"
+     inkscape:cx="3.6767386"
+     inkscape:cy="8.1664307"
+     inkscape:window-x="0"
+     inkscape:window-y="27"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="svg8">
+    <inkscape:grid
+       type="xygrid"
+       id="grid4526" />
+  </sodipodi:namedview>
+  <g
+     id="g873"
+     transform="matrix(0,1,1,0,-1,0)">
+    <rect
+       y="5.5"
+       x="7.5"
+       height="6"
+       width="6"
+       id="rect869"
+       
style="opacity:0.5;fill:#474747;fill-opacity:1;stroke:none;stroke-width:1.2544198;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
 />
+    <path
+       sodipodi:nodetypes="ssssssssscccccccccc"
+       inkscape:connector-curvature="0"
+       id="path4659-5"
+       d="M 15,6 C 15,5.057191 13.942809,4 13,4 H 2 C 1.057191,4 0,5.057191 0,6 v 5 c 0,0.942809 1.057191,2 
2,2 h 11 c 0.942809,0 2,-1.057191 2,-2 z m -2,0 v 5 H 8 V 6 Z M 7,6 v 5 H 2 V 6 Z"
+       
style="fill:#474747;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
 />
+  </g>
+</svg>
diff --git a/plugins/nintendo-ds/data/nintendo-ds.gresource.xml 
b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
index 8a9a07e0..a4f29c75 100644
--- a/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
+++ b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
@@ -2,5 +2,9 @@
 <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-right-left-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..df0472dd
--- /dev/null
+++ b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
@@ -0,0 +1,94 @@
+// 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",
+               "right/left",
+       };
+
+       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";
+
+               case "right/left":
+                       return "screen-layout-right/left-symbolic";
+               }
+
+               return "video-display-symbolic";
+       }
+
+       private string get_layout_name (string layout) {
+               switch (layout) {
+               case "top/bottom":
+                       return _("Top/Bottom");
+
+               case "left/right":
+                       return _("Left/Right");
+
+               case "right/left":
+                       return _("Right/Left");
+               }
+
+               return _("Unknown");
+       }
+}


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