From b71c31f15013e1717ddbd46e10dfa6abc79139ad Mon Sep 17 00:00:00 2001
From: user <user@user-ThinkPad-X60.(none)>
Date: Sun, 24 May 2015 23:34:49 -0400
Subject: [PATCH] added font dialog

---
 pd/nw/dialog_font.html            | 208 ++++++++++++++++++++++++++++++
 pd/nw/locales/en/translation.json |  11 ++
 pd/nw/pd_canvas.html              |   4 +-
 pd/nw/pdgui.js                    |   6 +
 pd/src/g_editor.c                 |   8 +-
 5 files changed, 234 insertions(+), 3 deletions(-)
 create mode 100644 pd/nw/dialog_font.html

diff --git a/pd/nw/dialog_font.html b/pd/nw/dialog_font.html
new file mode 100644
index 000000000..f7badd79d
--- /dev/null
+++ b/pd/nw/dialog_font.html
@@ -0,0 +1,208 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <link id="page_style" rel="stylesheet" type="text/css" href="css/default.css">
+  </head>
+  <body id="iemgui_dialog_body">
+    <div class="container">
+    <form> 
+      <fieldset> 
+        <legend data-i18n="font.prop.size"></legend> 
+
+        <label>
+          <input type="radio"
+                 id="8"
+                 value="8"
+                 name="font_size"
+                 onchange="change_size();">
+          <span data-i18n="font.prop.8"></span>
+        </label>
+
+        <br/>
+
+        <label>
+          <input type="radio"
+                 id="10"
+                 value="10"
+                 name="font_size"
+                 onchange="change_size();">
+          <span data-i18n="font.prop.10"></span>
+        </label>
+
+        <br/>
+
+        <label>
+          <input type="radio"
+                 id="12"
+                 value="12"
+                 name="font_size"
+                 onchange="change_size();">
+          <span data-i18n="font.prop.12"></span>
+        </label>
+
+        <br/>
+
+        <label>
+          <input type="radio"
+                 id="16"
+                 value="16"
+                 name="font_size"
+                 onchange="change_size();">
+          <span data-i18n="font.prop.16"></span>
+        </label>
+
+        <br/>
+
+        <label>
+          <input type="radio"
+                 id="24"
+                 value="24"
+                 name="font_size"
+                 onchange="change_size();">
+          <span data-i18n="font.prop.24"></span>
+        </label>
+
+        <br/>
+
+        <label>
+          <input type="radio"
+                 id="36"
+                 value="36"
+                 name="font_size"
+                 onchange="change_size();">
+          <span data-i18n="font.prop.36"></span>
+        </label>
+
+        <br/>
+
+      </fieldset> 
+
+    <div class="submit_buttons">
+      <button type="button" onClick="ok()" data-i18n="[title]iem.prop.ok_tt">
+        <span data-i18n="iem.prop.ok"></span>
+      </button>
+      <button type="button" onClick="apply()" data-i18n="[title]iem.prop.apply_tt">
+        <span data-i18n="iem.prop.apply"></span>
+      </button>
+      <button type="button" onClick="cancel()" data-i18n="[title]iem.prop.cancel_tt">
+        <span data-i18n="iem.prop.cancel"></span>
+      </button>
+    </div>
+
+  </form> 
+  </div>      
+
+  <script>
+    'use strict';
+    var nw = require('nw.gui'); 
+    var pdgui = require('./pdgui.js');
+
+    // For translations
+    var l = pdgui.get_local_string;
+
+    console.log("my working dire is " + pdgui.get_pwd());
+
+    pdgui.skin.apply(this);
+
+    var pd_object_callback;
+
+    function ok() {
+        apply();
+        cancel();
+    }
+
+function change_size() {
+    pdgui.gui_post("changing the size");
+}
+
+function apply() {
+        pdgui.gui_post("we're applying shits!");
+
+/*
+    set cmd [concat $id param \
+        $::dialog($vid:width) $::dialog($vid:lo) $::dialog($vid:hi) \
+        [gatom_escape $::dialog($vid:label)] $::dialog($vid:wherelabel) \
+        [gatom_escape $::dialog($vid:symfrom)] \
+        [gatom_escape $::dialog($vid:symto)] \;]
+*/
+ 
+    pdgui.pdsend([pd_object_callback, 'param', 
+        +document.getElementById('width').value,
+        +document.getElementById('minimum-range').value,
+        +document.getElementById('maximum-range').value,
+        gatom_escape(document.getElementById('label').value),
+        document.querySelector('input[name="labelpos"]:checked').value,
+        gatom_escape(document.getElementById('receive-symbol').value),
+        gatom_escape(document.getElementById('send-symbol').value)
+    ].join(' '));
+}
+
+    function cancel() {
+        pdgui.gui_post("closing the window at this point");
+//        window.close(true);
+        pdgui.pdsend(pd_object_callback + " cancel");
+    }
+
+    // This gets called from the nw_create_window function in index.html
+    // It provides us with our window id from the C side.  Once we have it
+    // we can create the menu and register event callbacks
+    function register_canvas_id(gfxstub, attrs) {
+        pd_object_callback = gfxstub;
+
+        console.log('attrs are ' + attrs.toString());
+        add_events(gfxstub);
+        // not sure that we need this for properties windows
+//        pdgui.canvas_map(gfxstub);
+        translate_form();
+        populate_form(attrs);
+        // We don't turn on rendering of the "container" div until
+        // We've finished displaying all the spans and populating the
+        // labels and form elements.  That makes it more efficient and
+        // snappier, at least on older machines.
+        document.getElementsByClassName('container')[0].style.setProperty('display', 'inline');
+//        document.getElementsByClass("fumbles")[0].setAttribute('style', 'display: inline;');
+    }
+
+// Stop-gap translator
+function translate_form() {
+    var i
+    var elements = document.querySelectorAll('[data-i18n]');
+    for (i = 0; i < elements.length; i++) {
+        var data = elements[i].dataset.i18n;
+        if (data.slice(0,7) === '[title]') {
+            elements[i].title = l(data.slice(7));
+        } else {
+            elements[i].textContent = l(data);
+        }
+    }
+}
+
+function get_attr(name, attrs) {
+    return attrs[attrs.indexOf(name)+1];
+}
+
+function get_elem(name) {
+    return document.getElementById(name);
+}
+
+function populate_form(attrs) {
+    get_elem(attrs.font_size).checked = true;
+}
+
+function add_events(name) {
+    // let's handle some events for this window...
+
+    // closing the Window
+    nw.Window.get().on("close", function() {
+        // this needs to do whatever the "cancel" button does
+//        pdgui.pdsend(name + " menuclose 0");
+//        cancel();
+        pdgui.remove_dialogwin(pd_object_callback);
+        this.close(true);
+    });
+
+}
+
+  </script>
+  </body>
+</html>
diff --git a/pd/nw/locales/en/translation.json b/pd/nw/locales/en/translation.json
index ccb0e46f6..9548c2521 100644
--- a/pd/nw/locales/en/translation.json
+++ b/pd/nw/locales/en/translation.json
@@ -319,5 +319,16 @@
     "apply_tt": "Update audio properties without closing this dialog",
     "cancel": "cancel",
     "cancel_tt": "Cancel updating the properties"
+  },
+  "font": {
+    "prop": {
+      "size": "font size",
+      "8": "8",
+      "10": "10",
+      "12": "12",
+      "16": "16",
+      "24": "24",
+      "36": "36"
+    }
   }
 }
diff --git a/pd/nw/pd_canvas.html b/pd/nw/pd_canvas.html
index 412024500..922f37aa3 100644
--- a/pd/nw/pd_canvas.html
+++ b/pd/nw/pd_canvas.html
@@ -694,7 +694,9 @@ function nw_create_patch_window_menus (name) {
 
     editMenu.append(new nw.MenuItem({
         label: l('menu.font'),
-        click: menu_generic,
+        click: function () {
+            pdgui.pdsend(name + " menufont");
+        },
 //        key: 'a',
         modifiers: "ctrl",
         tooltip: l('menu.font_tt'),
diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index 09622bee3..2f8bac47b 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -3318,6 +3318,12 @@ gui_post("did is " + did + " and dialogwin[did] is " + dialogwin[did]);
     }
 }
 
+function gui_font_dialog(cid, gfxstub, font_size) {
+    var attrs = { canvas: cid, font_size: font_size };
+    dialogwin[gfxstub] = nw_create_window(gfxstub, 'font', 265, 540, 20, 20, 0,
+        0, 1, 'white', 'Properties', '', 0, null, attrs);
+}
+
 // Global settings
 
 function gui_pd_dsp(state) {
diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c
index 6bf045f70..c56ce0bc5 100644
--- a/pd/src/g_editor.c
+++ b/pd/src/g_editor.c
@@ -5609,8 +5609,12 @@ static void canvas_menufont(t_canvas *x)
     char buf[80];
     t_canvas *x2 = canvas_getrootfor(x);
     gfxstub_deleteforkey(x2);
-    sprintf(buf, "pdtk_canvas_dofont %%s .x%lx %d\n", (t_int)x2, x2->gl_font);
-    gfxstub_new(&x2->gl_pd, &x2->gl_pd, buf);
+//    sprintf(buf, "pdtk_canvas_dofont %%s .x%lx %d\n", (t_int)x2, x2->gl_font);
+    char *gfxstub = gfxstub_new2(&x2->gl_pd, &x2->gl_pd);
+    gui_vmess("gui_font_dialog", "xsi",
+        x2,
+        gfxstub,
+        x2->gl_font);
 }
 
 static int canvas_find_index1, canvas_find_index2, canvas_find_wholeword;
-- 
GitLab