From 82a9f90bb525e91e11cc192aa5c206e5c193df6a Mon Sep 17 00:00:00 2001
From: Mathieu L Bouchard <matju@artengine.ca>
Date: Fri, 15 Aug 2014 17:24:25 -0400
Subject: [PATCH] fix some problems with drawing inlets/outlets in iemgui

---
 pd/src/g_all_guis.c | 33 ++++++++++++++++-----------------
 pd/src/g_all_guis.h | 25 +------------------------
 pd/src/g_bang.c     |  5 ++---
 pd/src/g_mycanvas.c |  5 +++--
 pd/src/g_numbox.c   |  7 +++----
 pd/src/g_radio.c    |  5 ++---
 pd/src/g_slider.c   |  6 ++----
 pd/src/g_toggle.c   |  5 ++---
 8 files changed, 31 insertions(+), 60 deletions(-)

diff --git a/pd/src/g_all_guis.c b/pd/src/g_all_guis.c
index 5a70620a7..02536823b 100644
--- a/pd/src/g_all_guis.c
+++ b/pd/src/g_all_guis.c
@@ -30,6 +30,7 @@ int iemgui_clip_font(int size) {return maxi(size,IEM_FONT_MINSIZE);}
 
 static int iemgui_modulo_color(int col)
 {
+    const int IEM_GUI_MAX_COLOR = 30;
     col %= IEM_GUI_MAX_COLOR;
     if (col<0) col += IEM_GUI_MAX_COLOR;
     return col;
@@ -184,7 +185,7 @@ void iemgui_send(t_iemgui *x, t_symbol *s)
     x->x_snd_unexpanded = snd;
     x->x_snd = snd = canvas_realizedollar(x->x_glist, snd);
     iemgui_verify_snd_ne_rcv(x);
-    iemgui_draw_io(x, x->x_glist, IEM_GUI_DRAW_MODE_IO + oldsndrcvable);
+    iemgui_draw_io(x, x->x_glist, oldsndrcvable);
 }
 
 void iemgui_receive(t_iemgui *x, t_symbol *s)
@@ -213,7 +214,7 @@ void iemgui_receive(t_iemgui *x, t_symbol *s)
         x->x_rcv = rcv;
     }
     iemgui_verify_snd_ne_rcv(x);
-    iemgui_draw_io(x, x->x_glist, IEM_GUI_DRAW_MODE_IO + oldsndrcvable);
+    iemgui_draw_io(x, x->x_glist, oldsndrcvable);
 }
 
 void iemgui_label(t_iemgui *x, t_symbol *s)
@@ -547,8 +548,9 @@ void iemgui_properties(t_iemgui *x, t_symbol **srl)
     srl[2] = iemgui_dollar2raute(srl[2]);
 }
 
-int iemgui_dialog(t_iemgui *x, t_symbol **srl, int argc, t_atom *argv)
+int iemgui_dialog(t_iemgui *x, int argc, t_atom *argv)
 {
+    t_symbol *srl[3];
     x->x_loadinit = !!atom_getintarg(5, argc, argv);
     srl[0] = iemgui_getfloatsymarg(7,argc,argv);
     srl[1] = iemgui_getfloatsymarg(8,argc,argv);
@@ -561,8 +563,8 @@ int iemgui_dialog(t_iemgui *x, t_symbol **srl, int argc, t_atom *argv)
     x->x_fcol = atom_getintarg(15, argc, argv) & 0xffffff;
     x->x_lcol = atom_getintarg(16, argc, argv) & 0xffffff;
     int oldsndrcvable=0;
-    if(iemgui_has_rcv(x)) oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
-    if(iemgui_has_snd(x)) oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
+    if(iemgui_has_rcv(x)) oldsndrcvable |= IEM_GUI_OLD_RCV_FLAG;
+    if(iemgui_has_snd(x)) oldsndrcvable |= IEM_GUI_OLD_SND_FLAG;
     iemgui_all_raute2dollar(srl);
     x->x_snd_unexpanded=srl[0]; srl[0]=canvas_realizedollar(x->x_glist, srl[0]);
     x->x_rcv_unexpanded=srl[1]; srl[1]=canvas_realizedollar(x->x_glist, srl[1]);
@@ -580,7 +582,7 @@ int iemgui_dialog(t_iemgui *x, t_symbol **srl, int argc, t_atom *argv)
     x->x_font_style = f;
     iemgui_verify_snd_ne_rcv(x);
     canvas_dirty(x->x_glist, 1);
-    return(oldsndrcvable);
+    return oldsndrcvable;
 }
 
 void iem_inttosymargs(t_iemgui *x, int n)
@@ -904,8 +906,10 @@ void iemgui_label_draw_select(t_iemgui *x, t_glist *canvas) {
 }
 
 extern t_class *vu_class;
-void iemgui_io_draw(t_iemgui *x, t_glist *canvas, int old_sr_flags) {
-	if (x->x_glist != canvas) return; // is gop
+void iemgui_draw_io(t_iemgui *x, t_glist *glist, int old_sr_flags)
+{
+    t_canvas *canvas=glist_getcanvas(glist);
+    if (x->x_glist != canvas) return; // is gop
     t_class *c = pd_class((t_pd *)x);
 
     if (!(old_sr_flags&4) && (!glist_isvisible(canvas) || !(canvas == x->x_glist))) {
@@ -920,7 +924,7 @@ void iemgui_io_draw(t_iemgui *x, t_glist *canvas, int old_sr_flags) {
 
     int a=old_sr_flags&IEM_GUI_OLD_SND_FLAG;
     int b=x->x_snd!=s_empty;
-    fprintf(stderr,"%lx SND: old_sr_flags=%d SND_FLAG=%d || OUTCOME: OLD_SND_FLAG=%d not_empty=%d\n", (t_int)x, old_sr_flags, IEM_GUI_OLD_SND_FLAG, a, b);
+    //fprintf(stderr,"%lx SND: old_sr_flags=%d SND_FLAG=%d || OUTCOME: OLD_SND_FLAG=%d not_empty=%d\n", (t_int)x, old_sr_flags, IEM_GUI_OLD_SND_FLAG, a, b);
     
     if(a && !b) for (i=0; i<n; i++)
         sys_vgui(".x%lx.c create prect %d %d %d %d "
@@ -929,11 +933,11 @@ void iemgui_io_draw(t_iemgui *x, t_glist *canvas, int old_sr_flags) {
              canvas, x1+i*k, y2-1, x1+i*k + IOWIDTH, y2,
              x, i, x);
     if(!a && b) for (i=0; i<n; i++)
-        sys_vgui(".x%lx.c delete x%lxo%d\n", canvas, x, 0);
+        sys_vgui(".x%lx.c delete x%lxo%d\n", canvas, x, i);
 
     a=old_sr_flags&IEM_GUI_OLD_RCV_FLAG;
     b=x->x_rcv!=s_empty;
-    fprintf(stderr,"%lx RCV: old_sr_flags=%d RCV_FLAG=%d || OUTCOME: OLD_RCV_FLAG=%d not_empty=%d\n", (t_int)x, old_sr_flags, IEM_GUI_OLD_RCV_FLAG, a, b);
+    //fprintf(stderr,"%lx RCV: old_sr_flags=%d RCV_FLAG=%d || OUTCOME: OLD_RCV_FLAG=%d not_empty=%d\n", (t_int)x, old_sr_flags, IEM_GUI_OLD_RCV_FLAG, a, b);
     if(a && !b) for (i=0; i<n; i++)
         sys_vgui(".x%lx.c create prect %d %d %d %d "
                  "-stroke $pd_colors(iemgui_nlet) "
@@ -941,7 +945,7 @@ void iemgui_io_draw(t_iemgui *x, t_glist *canvas, int old_sr_flags) {
              canvas, x1+i*k, y1, x1+i*k + IOWIDTH, y1+1,
              x, i, x);
     if(!a && b) for (i=0; i<n; i++)
-        sys_vgui(".x%lx.c delete x%lxi%d\n", canvas, x, 0);
+        sys_vgui(".x%lx.c delete x%lxi%d\n", canvas, x, i);
 }
 
 void iemgui_io_draw_move(t_iemgui *x, t_glist *canvas) {
@@ -988,11 +992,6 @@ void iemgui_draw_new(t_iemgui *x, t_glist *glist) {
     iemgui_draw_io(x,glist,7);
     canvas_raise_all_cords(glist_getcanvas(x->x_glist)); // used to be inside x_draw
 }
-void iemgui_draw_io(t_iemgui *x, t_glist *glist, int old_sr_flags)
-{
-    t_canvas *canvas=glist_getcanvas(glist);
-    iemgui_io_draw(x,glist_getcanvas(canvas),old_sr_flags);
-}
 void iemgui_draw_erase(t_iemgui *x, t_glist *glist) {
     t_canvas *canvas=glist_getcanvas(glist);
     sys_vgui(".x%lx.c delete x%lx\n", canvas, x);
diff --git a/pd/src/g_all_guis.h b/pd/src/g_all_guis.h
index 4ffa5e50e..ea46360a0 100644
--- a/pd/src/g_all_guis.h
+++ b/pd/src/g_all_guis.h
@@ -3,25 +3,8 @@
 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
 /* g_7_guis.h written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
 
-
-// the three used by any externals ([room_sim_2d] [room_sim_3d] [cube_sphere])
-// the other colours still exist in the array but are not referred by name.
-#define IEM_GUI_COLNR_GREEN          16
-#define IEM_GUI_COLNR_L_GREY         20
-#define IEM_GUI_COLNR_D_ORANGE       24
-
-/* deprecated in favor of the global iemgui_select var
-   left here for legacy externals that may rely upon this */
-#define IEM_GUI_COLOR_SELECTED       16749334
-/* end deprecated */
-
-#define IEM_GUI_COLOR_NORMAL         "$pd_colors(iemgui_border)"
-
-#define IEM_GUI_MAX_COLOR            30
-
 #define IEM_GUI_DEFAULTSIZE 15
 #define IEM_GUI_MINSIZE 8
-#define IEM_GUI_MAXSIZE 1000
 #define IEM_SL_DEFAULTSIZE 128
 #define IEM_SL_MINSIZE 2
 #define IEM_FONT_MINSIZE 4
@@ -30,16 +13,11 @@
 #define IEM_GUI_DRAW_MODE_MOVE   1
 #define IEM_GUI_DRAW_MODE_NEW    2
 #define IEM_GUI_DRAW_MODE_SELECT 3
-#define IEM_GUI_DRAW_MODE_ERASE  4 // obsolete since 2014.08
 #define IEM_GUI_DRAW_MODE_CONFIG 5
-#define IEM_GUI_DRAW_MODE_IO     6 /* also reserves 7,8,9 by adding old_sr_flags */
 
 #define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT)
 #define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL)
 
-#define IEM_FSTYLE_FLAGS_ALL 0x007fffff
-#define IEM_INIT_ARGS_ALL    0x01ffffff
-
 #define IEM_GUI_OLD_SND_FLAG 1
 #define IEM_GUI_OLD_RCV_FLAG 2
 
@@ -231,7 +209,7 @@ EXTERN void iemgui_delete(t_gobj *z, t_glist *glist);
 EXTERN void iemgui_vis(t_gobj *z, t_glist *glist, int vis);
 EXTERN void iemgui_save(t_iemgui *x, t_symbol **srl, int *bflcol);
 EXTERN void iemgui_properties(t_iemgui *x, t_symbol **srl);
-EXTERN int iemgui_dialog(t_iemgui *x, t_symbol **srl, int argc, t_atom *argv);
+EXTERN int iemgui_dialog(t_iemgui *x, int argc, t_atom *argv);
 
 EXTERN void iem_inttosymargs(t_iemgui *x, int n);
 EXTERN int iem_symargstoint(t_iemgui *x);
@@ -269,7 +247,6 @@ EXTERN void iemgui_label_draw_new(   t_iemgui *x, t_glist *canvas);
 EXTERN void iemgui_label_draw_move(  t_iemgui *x, t_glist *canvas);
 EXTERN void iemgui_label_draw_config(t_iemgui *x, t_glist *canvas);
 EXTERN void iemgui_label_draw_select(t_iemgui *x, t_glist *canvas);
-EXTERN void iemgui_io_draw(t_iemgui *x, t_glist *canvas, int old_sr_flags);
 EXTERN void iemgui_io_draw_move(t_iemgui *x, t_glist *canvas);
 EXTERN void iemgui_draw_io(t_iemgui *x, t_glist *glist, int old_sr_flags);
 EXTERN void iemgui_base_draw_new(t_iemgui *x, t_glist *canvas);
diff --git a/pd/src/g_bang.c b/pd/src/g_bang.c
index 9eb90583e..0fe25302f 100644
--- a/pd/src/g_bang.c
+++ b/pd/src/g_bang.c
@@ -238,14 +238,13 @@ static void bng_bang2(t_bng *x)/*wird immer gesendet, wenn moeglich*/
 static void bng_dialog(t_bng *x, t_symbol *s, int argc, t_atom *argv)
 {
     canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
-    t_symbol *srl[3];
     x->x_gui.x_h = x->x_gui.x_w = atom_getintarg(0, argc, argv);
     int fthold = atom_getintarg(2, argc, argv);
     int ftbreak = atom_getintarg(3, argc, argv);
-    int sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
+    int sr_flags = iemgui_dialog(&x->x_gui, argc, argv);
     bng_check_minmax(x, ftbreak, fthold);
     x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
-    iemgui_draw_io(&x->x_gui, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
+    iemgui_draw_io(&x->x_gui, x->x_gui.x_glist, sr_flags);
     iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_MOVE);
     scalehandle_draw(&x->x_gui, x->x_gui.x_glist);
     scrollbar_update(x->x_gui.x_glist);
diff --git a/pd/src/g_mycanvas.c b/pd/src/g_mycanvas.c
index 6fa411549..fdce53864 100644
--- a/pd/src/g_mycanvas.c
+++ b/pd/src/g_mycanvas.c
@@ -207,13 +207,14 @@ static void my_canvas_get_pos(t_my_canvas *x)
 
 static void my_canvas_dialog(t_my_canvas *x, t_symbol *s, int argc, t_atom *argv)
 {
+    printf("cnv_dialog: selected=%d\n",x->x_gui.x_selected);
     canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
-    t_symbol *srl[3];
+    printf("cnv_dialog: selected=%d\n",x->x_gui.x_selected);
     x->x_gui.x_h =
     x->x_gui.x_w = maxi(atom_getintarg(0, argc, argv),1);
     x->x_vis_w = maxi(atom_getintarg(2, argc, argv),1);
     x->x_vis_h = maxi(atom_getintarg(3, argc, argv),1);
-    iemgui_dialog(&x->x_gui, srl, argc, argv);
+    iemgui_dialog(&x->x_gui, argc, argv);
     x->x_gui.x_loadinit = 0;
     x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
     iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_MOVE);
diff --git a/pd/src/g_numbox.c b/pd/src/g_numbox.c
index 3562da3df..eec27a08c 100644
--- a/pd/src/g_numbox.c
+++ b/pd/src/g_numbox.c
@@ -159,7 +159,7 @@ static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist)
         ".x%lx.c create ppolygon %d %d %d %d %d %d %d %d %d %d -stroke %s"
         " -fill %s -tags {%lxBASE1 x%lx text iemgui}\n",
         canvas, x1, y1, x2-4, y1, x2, y1+4, x2, y2, x1, y2,
-        x->x_hide_frame <= 1 ? IEM_GUI_COLOR_NORMAL : bcol,
+        x->x_hide_frame <= 1 ? "$pd_colors(iemgui_border)" : bcol,
         bcol, x, x);
 
     if (x->x_hide_frame <= 1) iemgui_draw_io(&x->x_gui,glist,7);
@@ -224,7 +224,7 @@ static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist)
     char fcol[8]; sprintf(fcol, "#%6.6x", x->x_gui.x_fcol);
     char bcol[8]; sprintf(bcol, "#%6.6x", x->x_gui.x_bcol);
     sys_vgui(".x%lx.c itemconfigure %lxBASE1 -stroke %s\n", canvas, x,
-        issel ? selection_color : x->x_hide_frame <= 1 ? IEM_GUI_COLOR_NORMAL : bcol);
+        issel ? selection_color : x->x_hide_frame <= 1 ? "$pd_colors(iemgui_border)" : bcol);
     sys_vgui(".x%lx.c itemconfigure %lxBASE2 -stroke %s\n", canvas, x,
         issel ? selection_color : fcol);
     sys_vgui(".x%lx.c itemconfigure %lxNUMBER -fill %s\n", canvas, x,
@@ -463,7 +463,6 @@ static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc,
     t_atom *argv)
 {
     canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
-    t_symbol *srl[3];
     x->x_gui.x_w = maxi(atom_getintarg(0, argc, argv),1);
     x->x_gui.x_h = maxi(atom_getintarg(1, argc, argv),8);
     double min = atom_getfloatarg(2, argc, argv);
@@ -472,7 +471,7 @@ static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc,
     x->x_log_height = maxi(atom_getintarg(6, argc, argv),10);
     if (argc > 17)
         x->x_hide_frame = (int)atom_getintarg(18, argc, argv);
-    iemgui_dialog(&x->x_gui, srl, argc, argv);
+    iemgui_dialog(&x->x_gui, argc, argv);
     x->x_numwidth = my_numbox_calc_fontwidth(x);
     my_numbox_check_minmax(x, min, max);
     iemgui_draw_erase(&x->x_gui, x->x_gui.x_glist);
diff --git a/pd/src/g_radio.c b/pd/src/g_radio.c
index 7824c05d4..886b0f157 100644
--- a/pd/src/g_radio.c
+++ b/pd/src/g_radio.c
@@ -243,12 +243,11 @@ static void radio_properties(t_gobj *z, t_glist *owner)
 static void radio_dialog(t_radio *x, t_symbol *s, int argc, t_atom *argv)
 {
     canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
-    t_symbol *srl[3];
     x->x_gui.x_h =
     x->x_gui.x_w = iemgui_clip_size(atom_getintarg(0, argc, argv));
     x->x_change = !!atom_getintarg(4, argc, argv);
     int num = atom_getintarg(6, argc, argv);
-    int sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
+    int sr_flags = iemgui_dialog(&x->x_gui, argc, argv);
     if(x->x_number != num)
     {
         iemgui_draw_erase(&x->x_gui, x->x_gui.x_glist);
@@ -263,7 +262,7 @@ static void radio_dialog(t_radio *x, t_symbol *s, int argc, t_atom *argv)
     else
     {
         x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
-        iemgui_draw_io(&x->x_gui, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
+        iemgui_draw_io(&x->x_gui, x->x_gui.x_glist, sr_flags);
         iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_MOVE);
     }
     scalehandle_draw(&x->x_gui, x->x_gui.x_glist);
diff --git a/pd/src/g_slider.c b/pd/src/g_slider.c
index d8b3cd9df..7b2e016cf 100644
--- a/pd/src/g_slider.c
+++ b/pd/src/g_slider.c
@@ -294,15 +294,13 @@ static void slider_bang(t_slider *x)
 static void slider_dialog(t_slider *x, t_symbol *s, int argc, t_atom *argv)
 {
     canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
-
-    t_symbol *srl[3];
     int w = atom_getintarg(0, argc, argv);
     int h = atom_getintarg(1, argc, argv);
     double min = atom_getfloatarg(2, argc, argv);
     double max = atom_getfloatarg(3, argc, argv);
     x->x_lin0_log1 = !!atom_getintarg(4, argc, argv);
     x->x_steady = !!atom_getintarg(17, argc, argv);
-    int sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
+    int sr_flags = iemgui_dialog(&x->x_gui, argc, argv);
     if (x->x_orient) {
         x->x_gui.x_w = iemgui_clip_size(w);
         int oldl = x->x_gui.x_h;
@@ -318,7 +316,7 @@ static void slider_dialog(t_slider *x, t_symbol *s, int argc, t_atom *argv)
     }
     slider_check_minmax(x, min, max);
     x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
-    iemgui_draw_io(&x->x_gui, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
+    iemgui_draw_io(&x->x_gui, x->x_gui.x_glist, sr_flags);
     iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_MOVE);
     scalehandle_draw(&x->x_gui, x->x_gui.x_glist);
     scrollbar_update(x->x_gui.x_glist);
diff --git a/pd/src/g_toggle.c b/pd/src/g_toggle.c
index d5a54f097..6e241b457 100644
--- a/pd/src/g_toggle.c
+++ b/pd/src/g_toggle.c
@@ -194,7 +194,6 @@ static void toggle_bang(t_toggle *x)
 static void toggle_dialog(t_toggle *x, t_symbol *s, int argc, t_atom *argv)
 {
     canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
-    t_symbol *srl[3];
     x->x_gui.x_h =
     x->x_gui.x_w = iemgui_clip_size(atom_getintarg(0, argc, argv));
     t_float nonzero = atom_getfloatarg(2, argc, argv);
@@ -203,9 +202,9 @@ static void toggle_dialog(t_toggle *x, t_symbol *s, int argc, t_atom *argv)
     x->x_nonzero = nonzero;
     if(x->x_on != 0.0)
         x->x_on = x->x_nonzero;
-    int sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
+    int sr_flags = iemgui_dialog(&x->x_gui, argc, argv);
     x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
-    iemgui_draw_io(&x->x_gui, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
+    iemgui_draw_io(&x->x_gui, x->x_gui.x_glist, sr_flags);
     iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_MOVE);
     scalehandle_draw(&x->x_gui, x->x_gui.x_glist);
     scrollbar_update(x->x_gui.x_glist);
-- 
GitLab