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

quick implementation of hcs/colorpanel using stock HTML5 color input

parent 1a69dbb7
......@@ -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",
//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);
......@@ -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");"position", "absolute");"left", "-10000px");"right", "0px");"width", "1px");"height", "1px");"overflow", "hidden");
// 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);
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