Commit 8c3d6008 authored by Jonathan Wilkes's avatar Jonathan Wilkes

quick implementation of hcs/colorpanel using stock HTML5 color input

parent 1a69dbb7
Pipeline #1628 passed with stage
in 719 minutes and 31 seconds
......@@ -9,14 +9,19 @@ static t_class *colorpanel_class;
typedef struct _colorpanel
{
t_object x_obj;
t_glist *x_glist;
t_symbol *x_s;
char current_color[MAXPDSTRING];
} t_colorpanel;
static void colorpanel_bang(t_colorpanel *x)
{
sys_vgui("after idle [list after 100 ::hcs::colorpanel::open %s %s]\n",
x->x_s->s_name, x->current_color);
gui_vmess("gui_show_color_dialog", "xss",
x->x_glist,
x->x_s->s_name,
x->current_color);
//sys_vgui("after idle [list after 100 ::hcs::colorpanel::open %s %s]\n",
// x->x_s->s_name, x->current_color);
}
static void colorpanel_symbol(t_colorpanel *x, t_symbol *s)
......@@ -82,6 +87,7 @@ static void *colorpanel_new( void)
t_colorpanel *x = (t_colorpanel *)pd_new(colorpanel_class);
sprintf(buf, "#%lx", (t_int)x);
x->x_s = gensym(buf);
x->x_glist = canvas_getcurrent();
pd_bind(&x->x_obj.ob_pd, x->x_s);
outlet_new(&x->x_obj, &s_list);
strcpy(x->current_color,"#ffffff");
......
......@@ -5892,3 +5892,42 @@ function gui_pddplink_open(filename, dir) {
post("pddplink: error: file not found: " + filename);
}
}
// hcs/colorpanel
function gui_show_color_dialog(cid, callback_tag, color) {
var id = "hcs_colorpanel_elem";
// create one if it doesn't exist
// These are per window. Unfortunately, the HTML5 spec doesn't
// give us an event when the color dialog is closed so we can't
// garbage collect it-- instead it will remain in a position outside
// the viewport until the window is closed.
gui(cid).get_elem("patchsvg", function(svg_elem, w) {
var e = svg_elem.querySelector(id);
if (!e) {
e = w.document.createElement("input");
e.setAttribute("id", id);
e.setAttribute("type", "color");
e.style.setProperty("position", "absolute");
e.style.setProperty("left", "-10000px");
e.style.setProperty("right", "0px");
e.style.setProperty("width", "1px");
e.style.setProperty("height", "1px");
e.style.setProperty("overflow", "hidden");
w.document.body.appendChild(e);
}
});
// Now fetch the element and set a callback for the one that was
// just clicked. I guess we should check for multiple calls coming
// from the backend here...
gui(cid).get_elem(id, function(e) {
e.setAttribute("value", color);
e.oninput = function() {
//post("did it! value is " + e.value + ". Sending...");
pdsend(callback_tag, "callback", e.value);
};
e.focus();
e.click();
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment