From e805ba010560231b11291a5376d5e72ddfcc5378 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sun, 12 Apr 2009 03:47:04 +0000 Subject: whipped out simple object that just asks Tcl for the screen resolution and outputs the numbers via two outlets svn path=/trunk/externals/hcs/; revision=11010 --- screensize.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 screensize.c (limited to 'screensize.c') diff --git a/screensize.c b/screensize.c new file mode 100644 index 0000000..c393f01 --- /dev/null +++ b/screensize.c @@ -0,0 +1,60 @@ +/* this object just asks Tcl for the screen resolution and outputs it */ +#include +#include +#include +#include +#include + +static t_class *screensize_class; + +typedef struct _screensize +{ + t_object x_obj; + t_symbol *receive_symbol; + t_outlet *width_outlet; + t_outlet *height_outlet; +} t_screensize; + +static void screensize_bang(t_screensize *x) +{ + sys_vgui("pd [concat %s screensize [winfo screenwidth .] [winfo screenheight .] \\;]\n", + x->receive_symbol->s_name); +} + +static void screensize_callback(t_screensize *x, t_float width, t_float height) +{ + outlet_float(x->height_outlet, height); + outlet_float(x->width_outlet, width); +} + +static void *screensize_new(void) +{ + char buf[MAXPDSTRING]; + t_screensize *x = (t_screensize *)pd_new(screensize_class); + + sprintf(buf, "#%lx", (t_int)x); + x->receive_symbol = gensym(buf); + pd_bind(&x->x_obj.ob_pd, x->receive_symbol); + + x->width_outlet = outlet_new(&x->x_obj, 0); + x->height_outlet = outlet_new(&x->x_obj, 0); + + return(x); +} + +static void screensize_free(t_screensize *x) +{ + pd_unbind(&x->x_obj.ob_pd, x->receive_symbol); +} + +void screensize_setup(void) +{ + screensize_class = class_new(gensym("screensize"), + (t_newmethod)screensize_new, (t_method)screensize_free, + sizeof(t_screensize), 0, 0); + + class_addbang(screensize_class, (t_method)screensize_bang); + + class_addmethod(screensize_class, (t_method)screensize_callback, + gensym("screensize"), A_DEFFLOAT, A_DEFFLOAT, 0); +} -- cgit v1.2.1