[gnome-games/wip/exalm/ds: 18/21] nintendo-ds: Add NintendoDsLayoutSwitcher



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

    nintendo-ds: Add NintendoDsLayoutSwitcher
    
    This widget allows to change screen-layout value in gsettings.
    
    Icons are by Adrien Plazas.

 .../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/meson.build               |  6 ++
 plugins/nintendo-ds/data/nintendo-ds.gresource.xml |  8 +++
 .../data/ui/nintendo-ds-layout-switcher.ui         | 70 +++++++++++++++++++++
 plugins/nintendo-ds/src/meson.build                |  3 +-
 .../src/nintendo-ds-layout-switcher.vala           | 69 +++++++++++++++++++++
 8 files changed, 367 insertions(+), 1 deletion(-)
---
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/meson.build b/plugins/nintendo-ds/data/meson.build
index 007c8981..0ce71cc2 100644
--- a/plugins/nintendo-ds/data/meson.build
+++ b/plugins/nintendo-ds/data/meson.build
@@ -1,5 +1,11 @@
 install_data (plugin_name + '.plugin', install_dir: plugins_dir)
 
+nintendo_ds_resources = gnome.compile_resources (
+  'nintendo-ds.gresource.xml',
+  'nintendo-ds.gresource.xml',
+  c_name: 'resources'
+)
+
 configure_file (
   input: 'org.gnome.Games.plugins.nintendo-ds.gschema.xml',
   output: 'org.gnome.Games.plugins.nintendo-ds.gschema.xml',
diff --git a/plugins/nintendo-ds/data/nintendo-ds.gresource.xml 
b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
new file mode 100644
index 00000000..481e1a75
--- /dev/null
+++ b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
@@ -0,0 +1,8 @@
+<gresources>
+  <gresource prefix="/org/gnome/Games/plugins/nintendo-ds">
+    <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..a7ea2538
--- /dev/null
+++ b/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GamesNintendoDsLayoutSwitcher" parent="GtkBox">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <style>
+      <class name="linked"/>
+    </style>
+    <child>
+      <object class="GtkRadioButton" id="left_right_button">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="draw-indicator">False</property>
+        <signal name="toggled" handler="on_layout_changed"/>
+        <child internal-child="accessible">
+          <object class="AtkObject">
+            <property name="accessible-name" translatable="yes">Left/Right</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="icon-name">screen-layout-left-right-symbolic</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkRadioButton" id="top_bottom_button">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="draw-indicator">False</property>
+        <property name="group">left_right_button</property>
+        <signal name="toggled" handler="on_layout_changed"/>
+        <child internal-child="accessible">
+          <object class="AtkObject">
+            <property name="accessible-name" translatable="yes">Vertical</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="icon-name">screen-layout-top-bottom-symbolic</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkRadioButton" id="right_left_button">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="draw-indicator">False</property>
+        <property name="group">left_right_button</property>
+        <signal name="toggled" handler="on_layout_changed"/>
+        <child internal-child="accessible">
+          <object class="AtkObject">
+            <property name="accessible-name" translatable="yes">Right/Left</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="icon-name">screen-layout-right-left-symbolic</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/plugins/nintendo-ds/src/meson.build b/plugins/nintendo-ds/src/meson.build
index 0313ac92..74730c77 100644
--- a/plugins/nintendo-ds/src/meson.build
+++ b/plugins/nintendo-ds/src/meson.build
@@ -1,5 +1,6 @@
 vala_sources = [
   'nintendo-ds-icon.vala',
+  'nintendo-ds-layout-switcher.vala',
   'nintendo-ds-plugin.vala',
 ]
 
@@ -13,7 +14,7 @@ c_args = [
 
 shared_module (
   'games-' + plugin_name + '-plugin',
-  vala_sources + c_sources,
+  vala_sources + c_sources + nintendo_ds_resources,
   dependencies: gnome_games_dep,
   c_args: c_args,
   install: true,
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..9ba4f74c
--- /dev/null
+++ b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
@@ -0,0 +1,69 @@
+// 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.Box {
+       [GtkChild]
+       private Gtk.RadioButton left_right_button;
+       [GtkChild]
+       private Gtk.RadioButton top_bottom_button;
+       [GtkChild]
+       private Gtk.RadioButton right_left_button;
+
+       private Settings settings;
+
+       static construct {
+               var icon_theme = Gtk.IconTheme.get_default ();
+               icon_theme.add_resource_path ("/org/gnome/Games/plugins/nintendo-ds/icons");
+       }
+
+       construct {
+               settings = new Settings ("org.gnome.Games.plugins.nintendo-ds");
+               settings.changed.connect (update_ui);
+
+               update_ui ();
+       }
+
+       private void update_ui () {
+               var button = get_current_button ();
+
+               if (button != null)
+                       button.active = true;
+       }
+
+       private Gtk.RadioButton? get_current_button () {
+               var layout = settings.get_string ("screen-layout");
+
+               switch (layout) {
+               case "top/bottom":
+                       return top_bottom_button;
+
+               case "left/right":
+                       return left_right_button;
+
+               case "right/left":
+                       return right_left_button;
+               }
+
+               return null;
+       }
+
+       private string get_current_layout () {
+               if (top_bottom_button.active)
+                       return "top/bottom";
+
+               if (left_right_button.active)
+                       return "left/right";
+
+               if (right_left_button.active)
+                       return "right/left";
+
+               return "";
+       }
+
+       [GtkCallback]
+       private void on_layout_changed (Gtk.ToggleButton button) {
+               var layout = get_current_layout ();
+
+               settings.set_string ("screen-layout", layout);
+       }
+}


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