Update of /cvsroot/pure-data/externals/bbogart/entry In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3948
Modified Files: entry.c Log Message:
- cleaned up cruft, including the x_rect_* stuff
- got smooth resizing working, doesn't lose state
Index: entry.c =================================================================== RCS file: /cvsroot/pure-data/externals/bbogart/entry/entry.c,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** entry.c 13 Nov 2007 17:01:39 -0000 1.31 --- entry.c 13 Nov 2007 20:20:54 -0000 1.32 *************** *** 41,57 **** #endif
! #define BACKGROUNDCOLOR "grey70"
! #define TKW_HANDLE_HEIGHT 15 ! #define TKW_HANDLE_WIDTH 15
! #define SCOPE_SELBDWIDTH 3.0 ! #define SCOPE_DEFWIDTH 130 /* CHECKED */ ! #define SCOPE_MINWIDTH 66 ! #define SCOPE_DEFHEIGHT 130 /* CHECKED */ ! #define SCOPE_MINHEIGHT 34
! #define TOTAL_INLETS 1 ! #define TOTAL_OUTLETS 2
#define DEBUG(x) x --- 41,57 ---- #endif
! #define BACKGROUNDCOLOR "grey70"
! #define TKW_HANDLE_HEIGHT 15 ! #define TKW_HANDLE_WIDTH 15
! #define TKW_HANDLE_INSET -2 ! #define ENTRY_DEFAULT_WIDTH 130 ! #define ENTRY_DEFAULT_HEIGHT 130 ! #define ENTRY_MIN_WIDTH 66 ! #define ENTRY_MIN_HEIGHT 34
! #define TOTAL_INLETS 1 ! #define TOTAL_OUTLETS 2
#define DEBUG(x) x *************** *** 59,89 **** typedef struct _entry { ! t_object x_obj; ! t_canvas *x_canvas; ! t_glist *x_glist; ! ! int x_rect_width; ! int x_rect_height; ! t_symbol* x_receive_name;
int x_resizing; int x_resize_x; int x_resize_y;
! /* TODO: these all should be settable by messages */ ! int x_height; ! int x_width; ! ! t_symbol* x_bgcolour; ! t_symbol* x_fgcolour;
! t_symbol *x_font_face; ! t_int x_font_size; ! t_symbol *x_font_weight;
! t_float x_border; ! t_symbol *x_relief; ! t_int x_have_scrollbar; ! t_int x_selected;
/* IDs for Tk widgets */ --- 59,85 ---- typedef struct _entry { ! t_object x_obj; ! t_canvas *x_canvas; ! t_glist *x_glist;
+ t_symbol *x_receive_name; + + int x_height; + int x_width; int x_resizing; int x_resize_x; int x_resize_y;
! t_symbol *x_bgcolour; ! t_symbol *x_fgcolour;
! t_symbol *x_font_face; ! t_int x_font_size; ! t_symbol *x_font_weight;
! t_float x_border; ! t_symbol *x_relief; ! t_int x_have_scrollbar; ! t_int x_selected;
/* IDs for Tk widgets */ *************** *** 123,127 **** static void entry_delete(t_gobj *z, t_glist *glist); static void entry_vis(t_gobj *z, t_glist *glist, int vis); ! //static int entry_click(t_gobj *x, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit); static void entry_save(t_gobj *z, t_binbuf *b);
--- 119,123 ---- static void entry_delete(t_gobj *z, t_glist *glist); static void entry_vis(t_gobj *z, t_glist *glist, int vis); ! //static int entry_click(t_gobj *z, t_glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit); static void entry_save(t_gobj *z, t_binbuf *b);
*************** *** 188,194 **** { post("calculate_onset"); ! post("x_rect_width: %d x_width: %d", x->x_rect_width, x->x_width); ! post("x_rect_height: %d x_height: %d", x->x_rect_height, x->x_height); ! return(text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) \ * current_iolet / (total_iolets == 1 ? 1 : total_iolets - 1)); } --- 184,188 ---- { post("calculate_onset"); ! return(text_xpix(&x->x_obj, glist) + (x->x_width - IOWIDTH) \ * current_iolet / (total_iolets == 1 ? 1 : total_iolets - 1)); } *************** *** 208,221 **** { sys_vgui("%s create rectangle %d %d %d %d -tags {%xi%d %xi %s}\n", ! x->canvas_id, onset, text_ypix(&x->x_obj, glist) - 1, onset + IOWIDTH, text_ypix(&x->x_obj, glist), x, i, x, x->all_tag); } - /* else - { - sys_vgui("%s coords %xi%d %d %d %d %d\n", - x->canvas_id, x, i, onset, text_ypix(&x->x_obj, glist) - 1, - onset + IOWIDTH, text_ypix(&x->x_obj, glist)); - }*/ } for (i = 0; i < total_outlets; i++) /* outlets */ --- 202,209 ---- { sys_vgui("%s create rectangle %d %d %d %d -tags {%xi%d %xi %s}\n", ! x->canvas_id, onset, text_ypix(&x->x_obj, glist) - 2, onset + IOWIDTH, text_ypix(&x->x_obj, glist), x, i, x, x->all_tag); } } for (i = 0; i < total_outlets; i++) /* outlets */ *************** *** 225,239 **** { sys_vgui("%s create rectangle %d %d %d %d -tags {%xo%d %xo %s}\n", ! x->canvas_id, onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1, ! onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height, x, i, x, x->all_tag); } - /* else - { - sys_vgui("%s coords %xo%d %d %d %d %d\n", - x->canvas_id, x, i, - onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1, - onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height); - }*/ } DEBUG(post("draw inlet end");); --- 213,220 ---- { sys_vgui("%s create rectangle %d %d %d %d -tags {%xo%d %xo %s}\n", ! x->canvas_id, onset, text_ypix(&x->x_obj, glist) + x->x_height, ! onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_height + 2, x, i, x, x->all_tag); } } DEBUG(post("draw inlet end");); *************** *** 243,252 **** { DEBUG(post("erase_inlets");); ! /* Added tag for all inlets of one instance */ sys_vgui("%s delete %xi\n", x->canvas_id, x); sys_vgui("%s delete %xo\n", x->canvas_id, x); ! /* Added tag for all outlets of one instance */ ! sys_vgui("%s delete %xhandle\n", x->canvas_id, x); ! /* TODO are the above even active? */ }
--- 224,231 ---- { DEBUG(post("erase_inlets");); ! /* Added tag for all inlets/outlets of one instance */ sys_vgui("%s delete %xi\n", x->canvas_id, x); sys_vgui("%s delete %xo\n", x->canvas_id, x); ! }
*************** *** 318,325 **** DEBUG(post("create_widget");); /* I guess this is for fine-tuning of the rect size based on width and height? */ - post("x_rect_width: %d x_width: %d", x->x_rect_width, x->x_width); - post("x_rect_height: %d x_height: %d", x->x_rect_height, x->x_height); - x->x_rect_width = x->x_width; - x->x_rect_height = x->x_height+2;
sys_vgui("namespace eval entry%lx {} \n", x); --- 297,300 ---- *************** *** 352,358 **** if (firsttime) { - post("x_rect_width: %d x_width: %d", x->x_rect_width, x->x_width); - post("x_rect_height: %d x_height: %d", x->x_rect_height, x->x_height); create_widget(x); if(x->x_have_scrollbar) draw_scrollbar(x); sys_vgui("%s create window %d %d -anchor nw -window %s \ --- 327,332 ---- if (firsttime) { create_widget(x); + draw_inlets(x, glist, firsttime, TOTAL_INLETS, TOTAL_OUTLETS); if(x->x_have_scrollbar) draw_scrollbar(x); sys_vgui("%s create window %d %d -anchor nw -window %s \ *************** *** 367,375 **** // text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)); } - if(glist->gl_edit) /* this is buggy logic */ - draw_inlets(x, glist, firsttime, TOTAL_INLETS, TOTAL_OUTLETS); - else - erase_inlets(x); - // glist_drawiofor(glist, x->x_obj, firsttime, ); }
--- 341,344 ---- *************** *** 380,384 ****
set_tk_widget_ids(x,glist_getcanvas(glist)); ! // erase_inlets(x); sys_vgui("destroy %s\n", x->frame_id); sys_vgui("%s delete %s\n", x->canvas_id, x->all_tag); --- 349,353 ----
set_tk_widget_ids(x,glist_getcanvas(glist)); ! erase_inlets(x); sys_vgui("destroy %s\n", x->frame_id); sys_vgui("%s delete %s\n", x->canvas_id, x->all_tag); *************** *** 395,403 **** // DEBUG(post("entry_getrect");); /* this one is very chatty :D */ t_entry *x = (t_entry*)z; - *xp1 = text_xpix(&x->x_obj, owner); *yp1 = text_ypix(&x->x_obj, owner); ! *xp2 = *xp1 + x->x_rect_width; ! *yp2 = *yp1 + x->x_rect_height; }
--- 364,371 ---- // DEBUG(post("entry_getrect");); /* this one is very chatty :D */ t_entry *x = (t_entry*)z; *xp1 = text_xpix(&x->x_obj, owner); *yp1 = text_ypix(&x->x_obj, owner); ! *xp2 = *xp1 + x->x_width; ! *yp2 = *yp1 + x->x_height + 2; // add 2 to give space for outlets }
*************** *** 414,419 **** /* sys_vgui("%s coords %s %d %d %d %d\n", x->canvas_id, x->all_tag, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)-1, ! text_xpix(&x->x_obj, glist) + x->x_rect_width, ! text_ypix(&x->x_obj, glist) + x->x_rect_height-2);*/ // entry_drawme(x, glist, 0); canvas_fixlinesfor(glist_getcanvas(glist), (t_text*) x); --- 382,387 ---- /* sys_vgui("%s coords %s %d %d %d %d\n", x->canvas_id, x->all_tag, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)-1, ! text_xpix(&x->x_obj, glist) + x->x_width, ! text_ypix(&x->x_obj, glist) + x->x_height-2);*/ // entry_drawme(x, glist, 0); canvas_fixlinesfor(glist_getcanvas(glist), (t_text*) x); *************** *** 431,449 **** if( (state) && (!x->x_selected)) { ! entry_getrect(z, glist, &x1, &y1, &x2, &y2); ! sys_vgui("%s configure -bg #bdbddd -state disabled\n", x->text_id); ! /* */ ! /* sys_vgui("%s create rectangle %d %d %d %d -tags {%xSEL %s} -outline blue -width 2\n", ! x->canvas_id, ! text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)-1, ! text_xpix(&x->x_obj, glist) + x->x_rect_width, ! text_ypix(&x->x_obj, glist) + x->x_rect_height-2, ! x, x->all_tag);*/ x->x_selected = 1; } else if (!state) { ! sys_vgui("%s configure -bg grey -state normal\n", x->text_id); ! // sys_vgui("%s delete %xSEL\n", x->canvas_id, x); /* activatefn never gets called with 0, so destroy here */ sys_vgui("destroy %s\n", x->handle_id); --- 399,411 ---- if( (state) && (!x->x_selected)) { ! // entry_getrect(z, glist, &x1, &y1, &x2, &y2); ! sys_vgui("%s configure -bg #bdbddd -state disabled -cursor $cursor_editmode_nothing\n", ! x->text_id); x->x_selected = 1; } else if (!state) { ! sys_vgui("%s configure -bg grey -state normal -cursor xterm\n", ! x->text_id); /* activatefn never gets called with 0, so destroy here */ sys_vgui("destroy %s\n", x->handle_id); *************** *** 461,469 **** { entry_getrect(z, glist, &x1, &y1, &x2, &y2); ! sys_vgui("canvas %s -width %d -height %d -bg #fedc00 -bd 0 -cursor top_left_arrow\n", x->handle_id, TKW_HANDLE_WIDTH, TKW_HANDLE_HEIGHT); ! sys_vgui("%s create window %f %f -anchor nw -width %d -height %d -window %s -tags RSZ\n", ! x->canvas_id, x2 - (TKW_HANDLE_WIDTH - SCOPE_SELBDWIDTH), ! y2 - (TKW_HANDLE_HEIGHT - SCOPE_SELBDWIDTH), TKW_HANDLE_WIDTH, TKW_HANDLE_HEIGHT, x->handle_id, x->all_tag); --- 423,438 ---- { entry_getrect(z, glist, &x1, &y1, &x2, &y2); ! sys_vgui("canvas %s -width %d -height %d -bg #ddd -bd 0 \ ! -highlightthickness 3 -highlightcolor {#f00} -cursor bottom_right_corner\n", x->handle_id, TKW_HANDLE_WIDTH, TKW_HANDLE_HEIGHT); ! int handle_x1 = x2 - TKW_HANDLE_WIDTH; ! int handle_y1 = y2 - (TKW_HANDLE_HEIGHT - TKW_HANDLE_INSET); ! int handle_x2 = x2; ! int handle_y2 = y2 - TKW_HANDLE_INSET; ! /* no worky */ ! /* sys_vgui("%s create line %d %d %d %d -fill black -tags RESIZE_LINES\n", */ ! /* x->handle_id, handle_x2, handle_y1, handle_x1, handle_y2); */ ! sys_vgui("%s create window %d %d -anchor nw -width %d -height %d -window %s -tags RSZ\n", ! x->canvas_id, handle_x1, handle_y1, TKW_HANDLE_WIDTH, TKW_HANDLE_HEIGHT, x->handle_id, x->all_tag); *************** *** 476,482 **** x->handle_id, x->x_receive_name->s_name); } - else - { - } }
--- 445,448 ---- *************** *** 506,514 ****
/* ! static int entry_click(t_gobj *x, t_glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit) { ! DEBUG(post("entry_click x:%d y:%d ", xpix, ypix);); ! // this is currently unused return 0; } --- 472,480 ----
/* ! static int entry_click(t_gobj *z, t_glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit) { ! t_entry *x = (t_entry *)z; ! DEBUG(post("entry_click x:%d y:%d edit: %d", xpix, ypix, x->x_canvas->gl_edit);); return 0; } *************** *** 659,663 **** atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), x->x_width, x->x_height, x->x_bgcolour, x->x_fgcolour); - /* binbuf_addv(b, ";"); */ }
--- 625,628 ---- *************** *** 738,745 **** x->x_width = width; // sys_vgui("%s configure -width %d -height %d \n", x->text_id, (int)width, (int)height); ! sys_vgui("%s itemconfigure %s -width %d -height %d \n", ! x->canvas_id, x->all_tag, (int)width, (int)height); ! entry_vis((t_gobj *)x, x->x_canvas, 0); ! entry_vis((t_gobj *)x, x->x_canvas, 1); }
--- 703,716 ---- x->x_width = width; // sys_vgui("%s configure -width %d -height %d \n", x->text_id, (int)width, (int)height); ! if(glist_isvisible(x->x_glist)) ! { ! sys_vgui("%s itemconfigure %s -width %d -height %d\n", ! x->canvas_id, x->window_tag, x->x_width, x->x_height); ! canvas_fixlinesfor(x->x_glist, (t_text *)x); // 2nd inlet ! /* sys_vgui("%s itemconfigure %s -width %d -height %d \n", */ ! /* x->canvas_id, x->all_tag, (int)width, (int)height); */ ! /* entry_vis((t_gobj *)x, x->x_canvas, 0); */ ! /* entry_vis((t_gobj *)x, x->x_canvas, 1); */ ! } }
*************** *** 763,769 **** if (canvas) { ! sys_vgui("destroy %s\n", x->handle_id); ! entry_select((t_gobj *)x, x->x_glist, 1); ! entry_activate((t_gobj *)x, x->x_glist, 1); canvas_fixlinesfor(x->x_glist, (t_text *)x); // 2nd inlet } --- 734,738 ---- if (canvas) { ! draw_inlets(x, canvas, 1, TOTAL_INLETS, TOTAL_OUTLETS); canvas_fixlinesfor(x->x_glist, (t_text *)x); // 2nd inlet } *************** *** 771,779 **** else if (!x->x_resizing && newstate) { ! if (canvas) ! { ! int x1, y1, x2, y2; ! entry_getrect((t_gobj *)x, x->x_glist, &x1, &y1, &x2, &y2); ! } x->x_resize_x = 0; x->x_resize_y = 0; --- 740,750 ---- else if (!x->x_resizing && newstate) { ! /* TODO I think this is not used */ ! /* if (canvas) */ ! /* { */ ! /* int x1, y1, x2, y2; */ ! /* entry_getrect((t_gobj *)x, x->x_glist, &x1, &y1, &x2, &y2); */ ! /* } */ ! erase_inlets(x); x->x_resize_x = 0; x->x_resize_y = 0; *************** *** 792,796 **** newx = x2 + dx; newy = y2 + dy; ! if (newx > x1 + SCOPE_MINWIDTH && newy > y1 + SCOPE_MINHEIGHT) { if (glist_isvisible(x->x_glist)) --- 763,767 ---- newx = x2 + dx; newy = y2 + dy; ! if (newx > x1 + ENTRY_MIN_WIDTH && newy > y1 + ENTRY_MIN_HEIGHT) { if (glist_isvisible(x->x_glist)) *************** *** 829,834 **** { post("entry: You must enter at least 4 arguments. Default values used."); ! x->x_width = 124; ! x->x_height = 100; x->x_bgcolour = gensym("grey70"); x->x_fgcolour = gensym("black"); --- 800,805 ---- { post("entry: You must enter at least 4 arguments. Default values used."); ! x->x_width = ENTRY_DEFAULT_WIDTH; ! x->x_height = ENTRY_DEFAULT_HEIGHT; x->x_bgcolour = gensym("grey70"); x->x_fgcolour = gensym("black");