aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2009-04-12 03:47:04 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2009-04-12 03:47:04 +0000
commite805ba010560231b11291a5376d5e72ddfcc5378 (patch)
tree67ad9ad82203953528b6e3d83271e7f962a77570
parentb4e8d4bc3dd9f750fe737cf394b0cc17a1a63d5c (diff)
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
-rw-r--r--screensize-help.pd9
-rw-r--r--screensize.c60
2 files changed, 69 insertions, 0 deletions
diff --git a/screensize-help.pd b/screensize-help.pd
new file mode 100644
index 0000000..8a7117e
--- /dev/null
+++ b/screensize-help.pd
@@ -0,0 +1,9 @@
+#N canvas 341 296 450 300 10;
+#X msg 184 101 bang;
+#X floatatom 184 170 5 0 0 0 width - -;
+#X floatatom 241 170 5 0 0 1 height - -;
+#X text 111 47 get the current screen resolution;
+#X obj 184 138 screensize;
+#X connect 0 0 4 0;
+#X connect 4 0 1 0;
+#X connect 4 1 2 0;
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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <m_pd.h>
+#include <g_canvas.h>
+
+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);
+}