Skip to content

Commit ffa78c5

Browse files
committed
improve scope~ resize handle and add Pd's colors
1 parent 03d68e2 commit ffa78c5

File tree

1 file changed

+30
-24
lines changed
  • cyclone_objects/binaries/audio

1 file changed

+30
-24
lines changed

cyclone_objects/binaries/audio/scope.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ static void scope_draw_handle(t_scope *x, int state){
9797
// always destroy (otherwise it may already exist)
9898
sys_vgui("destroy %s\n", sh->h_pathname);
9999
if(state){
100-
sys_vgui("canvas %s -width %d -height %d -bg blue -highlightthickness %d -cursor bottom_right_corner\n",
101-
sh->h_pathname, HANDLE_SIZE, HANDLE_SIZE, 2*x->x_zoom);
100+
sys_vgui("canvas %s -width %d -height %d -bg %s -highlightthickness %d -cursor bottom_right_corner\n",
101+
sh->h_pathname, HANDLE_SIZE, HANDLE_SIZE,
102+
THISGUI->i_selectcolor->s_name, 2*x->x_zoom);
102103
int x1, y1, x2, y2;
103104
scope_getrect((t_gobj *)x, x->x_glist, &x1, &y1, &x2, &y2);
104105
sys_vgui(".x%lx.c create window %d %d -anchor nw -width %d -height %d -window %s -tags all%lx\n",
@@ -168,34 +169,36 @@ static void scope_drawfg(t_scope *x, t_canvas *cv, int x1, int y1, int x2, int y
168169
}
169170
sys_vgui("%d %d \\\n", (int)xx, (int)yy);
170171
}
171-
sys_vgui("-fill #%2.2x%2.2x%2.2x -width %d -tags {fg%lx all%lx}\n",
172+
sys_vgui("-fill #%.2x%.2x%.2x -width %d -tags {fg%lx all%lx}\n",
172173
x->x_fg[0], x->x_fg[1], x->x_fg[2], x->x_zoom, x, x);
173174
}
174175

175176
static void scope_draw_grid(t_scope *x, t_canvas *cv, int x1, int y1, int x2, int y2){
176177
float dx = (x2-x1)*0.125, dy = (y2-y1)*0.25, xx, yy;
177178
int i;
178179
for(i = 0, xx = x1 + dx; i < 7; i++, xx += dx)
179-
sys_vgui(".x%lx.c create line %f %d %f %d -width %d -tags {gr%lx all%lx} -fill #%2.2x%2.2x%2.2x\n",
180+
sys_vgui(".x%lx.c create line %f %d %f %d -width %d -tags {gr%lx all%lx} -fill #%.2x%.2x%.2x\n",
180181
cv, xx, y1, xx, y2, x->x_zoom, x, x, x->x_gg[0], x->x_gg[1], x->x_gg[2]);
181182
for(i = 0, yy = y1 + dy; i < 3; i++, yy += dy)
182-
sys_vgui(".x%lx.c create line %d %f %d %f -width %d -tags {gr%lx all%lx} -fill #%2.2x%2.2x%2.2x\n",
183+
sys_vgui(".x%lx.c create line %d %f %d %f -width %d -tags {gr%lx all%lx} -fill #%.2x%.2x%.2x\n",
183184
cv, x1, yy, x2, yy, x->x_zoom, x, x, x->x_gg[0], x->x_gg[1], x->x_gg[2]);
184185
}
185186

186187
static void scope_draw_bg(t_scope *x, t_canvas *cv, int x1, int y1, int x2, int y2){
187-
sys_vgui(".x%lx.c create rectangle %d %d %d %d -outline #%2.2x%2.2x%2.2x -fill #%2.2x%2.2x%2.2x -width %d -tags {bg%lx all%lx}\n",
188+
sys_vgui(".x%lx.c create rectangle %d %d %d %d -outline #%.2x%.2x%.2x -fill #%.2x%.2x%.2x -width %d -tags {bg%lx all%lx}\n",
188189
cv, x1, y1, x2, y2, x->x_bg[0], x->x_bg[1], x->x_bg[2], x->x_bg[0], x->x_bg[1], x->x_bg[2], x->x_zoom, x, x);
189190
}
190191

191192
static void scope_draw_inlets(t_scope *x){
192193
if(x->x_edit && x->x_receive == &s_){
193194
t_canvas *cv = glist_getcanvas(x->x_glist);
194195
int xpos = text_xpix(&x->x_obj, x->x_glist), ypos = text_ypix(&x->x_obj, x->x_glist);
195-
sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill black -tags {%lx_in1 inlets%lx all%lx}\n",
196-
cv, xpos, ypos, xpos+(IOWIDTH*x->x_zoom), ypos+(IHEIGHT*x->x_zoom), x, x, x);
197-
sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill black -tags {%lx_in2 inlets%lx all%lx}\n",
198-
cv, xpos+x->x_width, ypos, xpos+x->x_width-(IOWIDTH*x->x_zoom), ypos+(IHEIGHT*x->x_zoom), x, x, x);
196+
sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill %s -tags {%lx_in1 inlets%lx all%lx}\n",
197+
cv, xpos, ypos, xpos+(IOWIDTH*x->x_zoom), ypos+(IHEIGHT*x->x_zoom),
198+
THISGUI->i_foregroundcolor->s_name, x, x, x);
199+
sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill %s -tags {%lx_in2 inlets%lx all%lx}\n",
200+
cv, xpos+x->x_width, ypos, xpos+x->x_width-(IOWIDTH*x->x_zoom), ypos+(IHEIGHT*x->x_zoom),
201+
THISGUI->i_foregroundcolor->s_name, x, x, x);
199202
}
200203
}
201204

@@ -333,11 +336,12 @@ static void scope_select(t_gobj *z, t_glist *glist, int state){
333336
t_canvas *cv = glist_getcanvas(glist);
334337
x->x_select = state;
335338
if(state)
336-
sys_vgui(".x%lx.c itemconfigure bg%lx -outline blue -width %d -fill #%2.2x%2.2x%2.2x\n",
337-
cv, x, SCOPE_SELBDWIDTH * x->x_zoom, x->x_bg[0], x->x_bg[1], x->x_bg[2]);
339+
sys_vgui(".x%lx.c itemconfigure bg%lx -outline %s -width %d -fill #%.2x%.2x%.2x\n",
340+
cv, x, THISGUI->i_selectcolor->s_name, x->x_zoom, x->x_bg[0], x->x_bg[1], x->x_bg[2]);
338341
else
339-
sys_vgui(".x%lx.c itemconfigure bg%lx -outline #%2.2x%2.2x%2.2x -width %d -fill #%2.2x%2.2x%2.2x\n",
340-
cv, x, x->x_bg[0], x->x_bg[1], x->x_bg[2], x->x_zoom, x->x_bg[0], x->x_bg[1], x->x_bg[2]);
342+
sys_vgui(".x%lx.c itemconfigure bg%lx -outline %s -width %d -fill #%.2x%.2x%.2x\n",
343+
cv, x, THISGUI->i_foregroundcolor->s_name,
344+
x->x_zoom, x->x_bg[0], x->x_bg[1], x->x_bg[2]);
341345
}
342346

343347
static void scope_delete(t_gobj *z, t_glist *glist){
@@ -453,7 +457,7 @@ static void scope_fgcolor(t_scope *x, t_floatarg r, t_floatarg g, t_floatarg b){
453457
if(x->x_fg[0] != red || x->x_fg[1] != green || x->x_fg[2] != blue){
454458
x->x_fg[0] = red, x->x_fg[1] = green, x->x_fg[2] = blue;
455459
if(gobj_shouldvis((t_gobj *)x, x->x_glist) && glist_isvisible(x->x_glist))
456-
sys_vgui(".x%lx.c itemconfigure fg%lx -fill #%2.2x%2.2x%2.2x\n",
460+
sys_vgui(".x%lx.c itemconfigure fg%lx -fill #%.2x%.2x%.2x\n",
457461
glist_getcanvas(x->x_glist), x, x->x_fg[0], x->x_fg[1], x->x_fg[2]);
458462
}
459463
}
@@ -465,7 +469,7 @@ static void scope_frgb(t_scope *x, t_float r, t_float g, t_float b){ // scale is
465469
if(x->x_fg[0] != red || x->x_fg[1] != green || x->x_fg[2] != blue){
466470
x->x_fg[0] = red, x->x_fg[1] = green, x->x_fg[2] = blue;
467471
if(glist_isvisible(x->x_glist) && gobj_shouldvis((t_gobj *)x, x->x_glist))
468-
sys_vgui(".x%lx.c itemconfigure fg%lx -fill #%2.2x%2.2x%2.2x\n",
472+
sys_vgui(".x%lx.c itemconfigure fg%lx -fill #%.2x%.2x%.2x\n",
469473
glist_getcanvas(x->x_glist), x, x->x_fg[0], x->x_fg[1], x->x_fg[2]);
470474
}
471475
}
@@ -477,7 +481,7 @@ static void scope_bgcolor(t_scope *x, t_float r, t_float g, t_float b){ // scale
477481
if(x->x_bg[0] != red || x->x_bg[1] != green || x->x_bg[2] != blue){
478482
x->x_bg[0] = red, x->x_bg[1] = green, x->x_bg[2] = blue;
479483
if(glist_isvisible(x->x_glist) && gobj_shouldvis((t_gobj *)x, x->x_glist))
480-
sys_vgui(".x%lx.c itemconfigure bg%lx -fill #%2.2x%2.2x%2.2x\n",
484+
sys_vgui(".x%lx.c itemconfigure bg%lx -fill #%.2x%.2x%.2x\n",
481485
glist_getcanvas(x->x_glist), x, x->x_bg[0], x->x_bg[1], x->x_bg[2]);
482486
}
483487
}
@@ -489,7 +493,7 @@ static void scope_brgb(t_scope *x, t_float r, t_float g, t_float b){ // scale: 0
489493
if(x->x_bg[0] != red || x->x_bg[1] != green || x->x_bg[2] != blue){
490494
x->x_bg[0] = red, x->x_bg[1] = green, x->x_bg[2] = blue;
491495
if(glist_isvisible(x->x_glist) && gobj_shouldvis((t_gobj *)x, x->x_glist))
492-
sys_vgui(".x%lx.c itemconfigure bg%lx -fill #%2.2x%2.2x%2.2x\n",
496+
sys_vgui(".x%lx.c itemconfigure bg%lx -fill #%.2x%.2x%.2x\n",
493497
glist_getcanvas(x->x_glist), x, x->x_bg[0], x->x_bg[1], x->x_bg[2]);
494498
}
495499
}
@@ -501,7 +505,7 @@ static void scope_gridcolor(t_scope *x, t_float r, t_float g, t_float b){ // sca
501505
if(x->x_gg[0] != red || x->x_gg[1] != green || x->x_gg[2] != blue){
502506
x->x_gg[0] = red, x->x_gg[1] = green, x->x_gg[2] = blue;
503507
if(glist_isvisible(x->x_glist) && gobj_shouldvis((t_gobj *)x, x->x_glist))
504-
sys_vgui(".x%lx.c itemconfigure gr%lx -fill #%2.2x%2.2x%2.2x\n",
508+
sys_vgui(".x%lx.c itemconfigure gr%lx -fill #%.2x%.2x%.2x\n",
505509
glist_getcanvas(x->x_glist), x, x->x_gg[0], x->x_gg[1], x->x_gg[2]);
506510
}
507511
}
@@ -513,7 +517,7 @@ static void scope_grgb(t_scope *x, t_float r, t_float g, t_float b){ // scale: 0
513517
if(x->x_gg[0] != red || x->x_gg[1] != green || x->x_gg[2] != blue){
514518
x->x_gg[0] = red, x->x_gg[1] = green, x->x_gg[2] = blue;
515519
if(glist_isvisible(x->x_glist) && gobj_shouldvis((t_gobj *)x, x->x_glist))
516-
sys_vgui(".x%lx.c itemconfigure gr%lx -fill #%2.2x%2.2x%2.2x\n",
520+
sys_vgui(".x%lx.c itemconfigure gr%lx -fill #%.2x%.2x%.2x\n",
517521
glist_getcanvas(x->x_glist), x, x->x_gg[0], x->x_gg[1], x->x_gg[2]);
518522
}
519523
}
@@ -614,8 +618,9 @@ static void handle__click_callback(t_handle *sh, t_floatarg f){
614618
else if(!sh->h_dragon && click){
615619
int x1, y1, x2, y2;
616620
scope_getrect((t_gobj *)x, x->x_glist, &x1, &y1, &x2, &y2);
617-
sys_vgui(".x%lx.c create rectangle %d %d %d %d -outline blue -width %d -tags %s\n",
618-
x->x_cv, x1, y1, x2, y2, SCOPE_SELBDWIDTH, sh->h_outlinetag);
621+
sys_vgui(".x%lx.c create rectangle %d %d %d %d -outline %s -width %d -tags %s\n",
622+
x->x_cv, x1, y1, x2, y2, THISGUI->i_selectcolor->s_name,
623+
SCOPE_SELBDWIDTH*x->x_zoom, sh->h_outlinetag);
619624
sh->h_dragx = sh->h_dragy = 0;
620625
}
621626
sh->h_dragon = click;
@@ -624,9 +629,10 @@ static void handle__click_callback(t_handle *sh, t_floatarg f){
624629
static void handle__motion_callback(t_handle *sh, t_floatarg f1, t_floatarg f2){
625630
if(sh->h_dragon){
626631
t_scope *x = sh->h_master;
627-
int dx = (int)f1, dy = (int)f2, x1, y1, x2, y2, newx, newy;
632+
int dx = (int)f1 - HANDLE_SIZE, dy = (int)f2 - HANDLE_SIZE;
633+
int x1, y1, x2, y2;
628634
scope_getrect((t_gobj *)x, x->x_glist, &x1, &y1, &x2, &y2);
629-
newx = x2 + dx, newy = y2 + dy;
635+
int newx = x2 + dx, newy = y2 + dy;
630636
if(newx < x1 + SCOPE_MINSIZE*x->x_zoom)
631637
newx = x1 + SCOPE_MINSIZE*x->x_zoom;
632638
if(newy < y1 + SCOPE_MINSIZE*x->x_zoom)

0 commit comments

Comments
 (0)