[PD-cvs] externals/tkwidgets frosch.gif, NONE, 1.1 photo-help.pd, NONE, 1.1 photo.c, NONE, 1.1 volga.gif, NONE, 1.1 text.c, 1.1, 1.2

Hans-Christoph Steiner eighthave at users.sourceforge.net
Wed Nov 14 04:51:37 CET 2007


Update of /cvsroot/pure-data/externals/tkwidgets
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6801

Modified Files:
	text.c 
Added Files:
	frosch.gif photo-help.pd photo.c volga.gif 
Log Message:
got a quick working example pretty much straight from ggee's image.c; I need to get the shared dylib working before working on a new objectclass

--- NEW FILE: frosch.gif ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: volga.gif ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: photo.c ---
/* [photo] object for dislaying images in a patch

   Copyright (C) 2002-2004 Guenter Geiger
   Copyright (C) 2007 Hans-Christoph Steiner <hans at at.or.at>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

   This is part of the tkwidgets library for Pd.

*/

#include "shared/tkwidgets.h"

/* ------------------------ photo ----------------------------- */

static t_class *photo_class;

typedef struct _photo
{
    t_object     x_obj;
    t_glist*     x_glist;
    t_symbol*    receive_name;
    int          x_width;
    int          x_height;
    t_symbol*    filename;
} t_photo;

static char *photo_tk_options[] = {
    "activeimage",
    "disabledimage",
    "gamma",
    "image",
    "state"
};

/* widget helper functions */

    void photo_drawme(t_photo *x, t_glist *glist, int firsttime)
{
	if (firsttime) 
    {
		char fname[MAXPDSTRING];
		canvas_makefilename(glist_getcanvas(x->x_glist), x->filename->s_name,
							fname, MAXPDSTRING);

        sys_vgui("image create photo img%x -file {%s}\n", x, fname);
        sys_vgui(".x%x.c create image %d %d -image img%x -anchor nw -tags %xS\n", 
                 glist_getcanvas(glist),text_xpix(&x->x_obj, glist), 
                 text_ypix(&x->x_obj, glist),x,x);

        /* TODO callback from gui
           sys_vgui("photo_size logo");
        */
    }     
    else 
    {
        sys_vgui(".x%x.c coords %xS %d %d\n",
                 glist_getcanvas(glist), x,
                 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
    }
	
}


void photo_erase(t_photo* x,t_glist* glist)
{
    int n;
    sys_vgui(".x%x.c delete %xS\n",
             glist_getcanvas(glist), x);

}
	


/* ------------------------ photo widgetbehaviour----------------------------- */


static void photo_getrect(t_gobj *z, t_glist *glist,
                          int *xp1, int *yp1, int *xp2, int *yp2)
{
    t_photo* x = (t_photo*)z;

    *xp1 = text_xpix(&x->x_obj, glist);
    *yp1 = text_ypix(&x->x_obj, glist);
    *xp2 = text_xpix(&x->x_obj, glist) + x->x_width;
    *yp2 = text_ypix(&x->x_obj, glist) + x->x_height;
}

static void photo_displace(t_gobj *z, t_glist *glist,
                           int dx, int dy)
{
    t_photo *x = (t_photo *)z;
    x->x_obj.te_xpix += dx;
    x->x_obj.te_ypix += dy;
    sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
             glist_getcanvas(glist), x,
             text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
             text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height);

    photo_drawme(x, glist, 0);
    canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
}

static void photo_select(t_gobj *z, t_glist *glist, int state)
{
    t_photo *x = (t_photo *)z;
    if (state) {
        sys_vgui(".x%x.c create rectangle \
%d %d %d %d -tags %xSEL -outline blue\n",
                 glist_getcanvas(glist),
                 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
                 text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
                 x);
    }
    else 
    {
        sys_vgui(".x%x.c delete %xSEL\n",
                 glist_getcanvas(glist), x);
    }
}


static void photo_activate(t_gobj *z, t_glist *glist, int state)
{
/*    t_text *x = (t_text *)z;
      t_rtext *y = glist_findrtext(glist, x);
      if (z->g_pd != gatom_class) rtext_activate(y, state);*/
}

static void photo_delete(t_gobj *z, t_glist *glist)
{
    t_text *x = (t_text *)z;
    canvas_deletelinesfor(glist_getcanvas(glist), x);
}

       
static void photo_vis(t_gobj *z, t_glist *glist, int vis)
{
    t_photo* s = (t_photo*)z;
    if (vis)
        photo_drawme(s, glist, 1);
    else
        photo_erase(s,glist);
}

/* can we use the normal text save function ?? */

static void photo_save(t_gobj *z, t_binbuf *b)
{
    t_photo *x = (t_photo *)z;
    binbuf_addv(b, "ssiiss;", gensym("#X"), gensym("obj"),
                x->x_obj.te_xpix, x->x_obj.te_ypix,   
                atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
                x->filename);
}


void photo_size(t_photo* x,t_floatarg w,t_floatarg h) {
    x->x_width = w;
    x->x_height = h;
}

void photo_open(t_photo* x, t_symbol* fname)
{
    x->filename = fname;
    photo_erase(x, x->x_glist);
    photo_drawme(x, x->x_glist, 1);
}


static void photo_free(t_photo *x)
{
    pd_unbind(&x->x_obj.ob_pd, x->receive_name);
}

static void *photo_new(t_symbol* s)
{
    t_photo *x = (t_photo *)pd_new(photo_class);

    x->x_glist = (t_glist*) canvas_getcurrent();

    x->x_width = 15;
    x->x_height = 15;

    x->x_glist = canvas_getcurrent();

	x->filename = s;
    outlet_new(&x->x_obj, &s_float);
    return (x);
}


static t_widgetbehavior photo_widgetbehavior = {
w_getrectfn:	photo_getrect,
w_displacefn:	photo_displace,
w_selectfn:     photo_select,
w_activatefn:	photo_activate,
w_deletefn:	    photo_delete,
w_visfn:        photo_vis,
w_clickfn:      NULL,
};

void photo_setup(void)
{
    photo_class = class_new(gensym("photo"), (t_newmethod)photo_new, 
                            (t_method)photo_free, 
                            sizeof(t_photo), 0, A_DEFSYM,0);
    
    class_addmethod(photo_class, (t_method)photo_size, gensym("size"),
                    A_FLOAT, A_FLOAT, 0);

/*
  class_addmethod(photo_class, (t_method)photo_color, gensym("color"),
  A_SYMBOL, 0);
*/

    class_addmethod(photo_class, (t_method)photo_open, gensym("open"),
                    A_SYMBOL, 0);
	
    class_setwidget(photo_class, &photo_widgetbehavior);
    class_setsavefn(photo_class, &photo_save);
}



Index: text.c
===================================================================
RCS file: /cvsroot/pure-data/externals/tkwidgets/text.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** text.c	14 Nov 2007 02:53:03 -0000	1.1
--- text.c	14 Nov 2007 03:51:35 -0000	1.2
***************
*** 46,50 ****
      t_glist*   x_glist;
  
!     t_symbol*  x_receive_name;
  
      int        x_height;
--- 46,50 ----
      t_glist*   x_glist;
  
!     t_symbol*  receive_name;
  
      int        x_height;
***************
*** 77,81 ****
  static t_class *textwidget_class;
  
! static char *tk_options[] = {
      "autoseparators",
      "background",
--- 77,81 ----
  static t_class *textwidget_class;
  
! static char *textwidget_tk_options[] = {
      "autoseparators",
      "background",
***************
*** 309,313 ****
      bind_button_events(x);
      sys_vgui("bind %s <KeyRelease> {+pd %s keyup %%N \\;} \n", 
!              x->text_id, x->x_receive_name->s_name);
  }
  
--- 309,313 ----
      bind_button_events(x);
      sys_vgui("bind %s <KeyRelease> {+pd %s keyup %%N \\;} \n", 
!              x->text_id, x->receive_name->s_name);
  }
  
***************
*** 428,436 ****
          sys_vgui("raise %s\n", x->handle_id);
          sys_vgui("bind %s <Button> {pd [concat %s resize_click 1 \\;]}\n",
!                  x->handle_id, x->x_receive_name->s_name);
          sys_vgui("bind %s <ButtonRelease> {pd [concat %s resize_click 0 \\;]}\n",
!                  x->handle_id, x->x_receive_name->s_name);
          sys_vgui("bind %s <Motion> {pd [concat %s resize_motion %%x %%y \\;]}\n",
!                  x->handle_id, x->x_receive_name->s_name);
      }
  }
--- 428,436 ----
          sys_vgui("raise %s\n", x->handle_id);
          sys_vgui("bind %s <Button> {pd [concat %s resize_click 1 \\;]}\n",
!                  x->handle_id, x->receive_name->s_name);
          sys_vgui("bind %s <ButtonRelease> {pd [concat %s resize_click 0 \\;]}\n",
!                  x->handle_id, x->receive_name->s_name);
          sys_vgui("bind %s <Motion> {pd [concat %s resize_motion %%x %%y \\;]}\n",
!                  x->handle_id, x->receive_name->s_name);
      }
  }
***************
*** 552,556 ****
      sys_vgui("pd [concat %s output [string map {\",\" \"\\\\,\" \";\" \"\\\\;\"} \
                [%s get 0.0 end]] \\;]\n", 
!              x->x_receive_name->s_name, x->text_id);
  }
  
--- 552,556 ----
      sys_vgui("pd [concat %s output [string map {\",\" \"\\\\,\" \";\" \"\\\\;\"} \
                [%s get 0.0 end]] \\;]\n", 
!              x->receive_name->s_name, x->text_id);
  }
  
***************
*** 719,723 ****
  static void textwidget_free(t_textwidget *x)
  {
!     pd_unbind(&x->x_obj.ob_pd, x->x_receive_name);
  }
  
--- 719,723 ----
  static void textwidget_free(t_textwidget *x)
  {
!     pd_unbind(&x->x_obj.ob_pd, x->receive_name);
  }
  
***************
*** 755,770 ****
  
      sprintf(buf,"#%s", x->tcl_namespace);
!     x->x_receive_name = gensym(buf);
!     pd_bind(&x->x_obj.ob_pd, x->x_receive_name);
  
      x->x_glist = canvas_getcurrent();
      set_tk_widget_ids(x, x->x_glist);
! 
      int i;
!     int option_argc = sizeof(tk_options)/sizeof(char *);
      post("total options: %d", option_argc);
      for(i = 0; i < option_argc; i++)
      {
!         post("option %d: %s", i, tk_options[i]);
      }
  
--- 755,770 ----
  
      sprintf(buf,"#%s", x->tcl_namespace);
!     x->receive_name = gensym(buf);
!     pd_bind(&x->x_obj.ob_pd, x->receive_name);
  
      x->x_glist = canvas_getcurrent();
      set_tk_widget_ids(x, x->x_glist);
!     
      int i;
!     int option_argc = sizeof(textwidget_tk_options)/sizeof(char *);
      post("total options: %d", option_argc);
      for(i = 0; i < option_argc; i++)
      {
!         post("option %d: %s", i, textwidget_tk_options[i]);
      }
  

--- NEW FILE: photo-help.pd ---
#N canvas 140 178 568 628 10;
#X text 19 18 Incorporate images. This is instantiated with;
#X msg 86 132 open \$1;
#X obj 86 88 bng 15 250 50 0 empty empty empty 0 -6 0 10 -4034 -1 -1
;
#X obj 86 109 openpanel;
#X obj 66 555 bng 15 250 50 0 empty empty empty 0 -6 0 10 -262144 -1
-1;
#X msg 265 152 size \$1 \$2;
#X obj 265 129 pack 0 0;
#X obj 313 106 hsl 128 15 0 127 0 0 empty empty y 7 7 0 10 -203904
-1 -1 0 1;
#X obj 263 88 hsl 128 15 0 127 0 0 empty empty x 7 7 0 10 -204800 -1
-1 0 1;
#X obj 309 337 photo frosch.gif;
#X obj 101 336 photo volga.gif;
#X text 19 34 [photo volga.gif];
#X text 17 57 [photo] works with .gif \, .ppm \, and .pgm image formats
only.;
#X connect 1 0 10 0;
#X connect 2 0 3 0;
#X connect 3 0 1 0;
#X connect 5 0 10 0;
#X connect 6 0 5 0;
#X connect 7 0 6 1;
#X connect 8 0 6 0;
#X connect 10 0 4 0;





More information about the Pd-cvs mailing list