Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24132
Modified Files: Tag: impd_0_37 u_object.tk g_hslider.c Log Message: fixed some slider bugs
Index: g_hslider.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/g_hslider.c,v retrieving revision 1.1.1.3.2.2.2.23 retrieving revision 1.1.1.3.2.2.2.24 diff -C2 -d -r1.1.1.3.2.2.2.23 -r1.1.1.3.2.2.2.24 *** g_hslider.c 4 May 2004 07:15:49 -0000 1.1.1.3.2.2.2.23 --- g_hslider.c 7 May 2004 07:15:38 -0000 1.1.1.3.2.2.2.24 *************** *** 44,48 **** pd_upload((t_gobj *)x,glist); sys_mgui((t_iemgui *)x,"slider","draw",""); ! sys_mgui((t_iemgui *)x,"slider","set","i",x->x_val); } } --- 44,48 ---- pd_upload((t_gobj *)x,glist); sys_mgui((t_iemgui *)x,"slider","draw",""); ! // sys_mgui((t_iemgui *)x,"slider","set","i",x->x_val); } } *************** *** 87,92 **** }
! static void slider_check_minmax(t_slider *x, double min, double max) { double diff; if(x->x_gui.x_lin0_log1) { --- 87,93 ---- }
! static void slider_check_minmax(t_slider *x) { + double min=x->x_min, max=x->x_max; double diff; if(x->x_gui.x_lin0_log1) { *************** *** 97,104 **** x->x_min = min; x->x_max = max; ! diff = x->x_gui.x_lin0_log1 ? log(x->x_max/x->x_min) : (x->x_max - x->x_min); x->x_k = isvert(x) ? ! diff/(double)(x->x_gui.x_h - 1) : ! diff/(double)(x->x_gui.x_w - 1); }
--- 98,105 ---- x->x_min = min; x->x_max = max; ! diff = x->x_gui.x_lin0_log1 ? log(x->x_max/x->x_min) : (x->x_max-x->x_min); x->x_k = isvert(x) ? ! diff/(double)(x->x_gui.x_h-1) : ! diff/(double)(x->x_gui.x_w-1); }
*************** *** 127,166 **** }
- static void slider_motion(t_slider *x, t_floatarg dx, t_floatarg dy) - { - int old = x->x_val; - int l = isvert(x) ? x->x_gui.x_h : x->x_gui.x_w; - int m = (l-1)*100; - x->x_pos += (x->x_gui.x_finemoved?1:100)*(int)(isvert(x) ? -dy : dx); - x->x_val = x->x_pos; - if(x->x_val>m) {x->x_val=m; x->x_pos+=50; x->x_pos-=x->x_pos%100;} - if(x->x_val<0) {x->x_val=0; x->x_pos-=50; x->x_pos-=x->x_pos%100;} - if(old != x->x_val) { - x->x_gui.x_draw(x, x->x_gui.x_glist, 0); - slider_bang(x); - } - } - static void slider_size(t_slider *x, t_symbol *s, int ac, t_atom *av) { ! if (isvert(x)) { ! x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av)); ! if(ac > 1) slider_check_width(x, (int)atom_getintarg(1, ac, av)); ! }else{ ! slider_check_width(x, (int)atom_getintarg(0, ac, av)); ! if(ac > 1) x->x_gui.x_h = iemgui_clip_size((int)atom_getintarg(1, ac, av)); ! } iemgui_size((t_iemgui *)x); }
! static void slider_range(t_slider *x, t_symbol *s, int ac, t_atom *av) ! { ! slider_check_minmax(x, ! (double)atom_getfloatarg(0, ac, av), ! (double)atom_getfloatarg(1, ac, av)); ! }
! static void slider_lin(t_slider *x) {x->x_gui.x_lin0_log1 = 0; x->x_k = (x->x_max-x->x_min)/(double)((isvert(x)?x->x_gui.x_h:x->x_gui.x_w) - 1);} ! static void slider_log(t_slider *x) {x->x_gui.x_lin0_log1 = 1; slider_check_minmax(x, x->x_min, x->x_max);}
static void slider_init(t_slider *x, t_floatarg f) {x->x_gui.x_loadinit = !!f;} --- 128,148 ---- }
static void slider_size(t_slider *x, t_symbol *s, int ac, t_atom *av) { ! int a = atom_getintarg(0,ac,av); ! int b = ac>1 ? atom_getintarg(1,ac,av) : 0; ! if (isvert(x)) { ! x->x_gui.x_w = iemgui_clip_size(a); if(ac>1) slider_check_width(x,b); ! } else { ! slider_check_width(x,a); if(ac>1) x->x_gui.x_h = iemgui_clip_size(b); ! } iemgui_size((t_iemgui *)x); }
! static void slider_range(t_slider *x, t_float min, t_float max) ! {x->x_min = min; x->x_max = max; slider_check_minmax(x);}
! static void slider_lin(t_slider *x) {x->x_gui.x_lin0_log1 = 0; x->x_k = (x->x_max-x->x_min)/(double)((isvert(x)?x->x_gui.x_h:x->x_gui.x_w)-1);} ! static void slider_log(t_slider *x) {x->x_gui.x_lin0_log1 = 1; slider_check_minmax(x);}
static void slider_init(t_slider *x, t_floatarg f) {x->x_gui.x_loadinit = !!f;} *************** *** 170,189 **** { slider_set(x, f); ! if(x->x_gui.x_put_in2out) { ! double out = x->x_gui.x_lin0_log1 ? ! x->x_min*exp(x->x_k*(double)(x->x_val)*0.01) : ! (double)(x->x_val)*0.01*x->x_k + x->x_min; ! if (fabs(out) < 1.0e-10) out = 0.0; ! outlet_float(x->x_gui.x_obj.ob_outlet, out); ! if(x->x_gui.x_snd_able && x->x_gui.x_snd->s_thing) ! pd_float(x->x_gui.x_snd->s_thing, out); ! } }
static void slider_loadbang(t_slider *x) { ! if(!sys_noloadbang && x->x_gui.x_loadinit) ! { ! x->x_gui.x_draw(x, x->x_gui.x_glist, 0); slider_bang(x); } --- 152,163 ---- { slider_set(x, f); ! if(x->x_gui.x_put_in2out) slider_bang(x); }
static void slider_loadbang(t_slider *x) { ! t_iemgui *y = (t_iemgui *)x; ! if(!sys_noloadbang && y->x_loadinit) { ! y->x_draw(x,y->x_glist,0); slider_bang(x); } *************** *** 193,207 **** { t_iemgui *y = (t_iemgui *)x; ! int isa=0, lin0_log1=0, v=0, steady=1; if(!pd_scanargs(argc,argv,"iiddbiaaaiiiiccci;b", ! &y->x_w,&y->x_h,&x->x_min,&x->x_max,&lin0_log1,&isa,&y->x_snd,&y->x_rcv,&y->x_lab, &y->x_ldx,&y->x_ldy,&y->x_font_style,&y->x_fontsize, &y->x_bcol,&y->x_fcol,&y->x_lcol,&v,&steady)) return; ! iem_inttosymargs(&x->x_gui, isa); ! y->x_lin0_log1=lin0_log1; x->x_pos = x->x_val = y->x_loadinit ? v : 0; y->x_steady = steady; iemgui_constrain(y); ! slider_check_minmax(x, x->x_min, x->x_max); if (isvert(x)) slider_check_width(x, y->x_h); else slider_check_width(x, y->x_w); --- 167,182 ---- { t_iemgui *y = (t_iemgui *)x; ! int isa,v,steady,lilo; if(!pd_scanargs(argc,argv,"iiddbiaaaiiiiccci;b", ! &y->x_w,&y->x_h,&x->x_min,&x->x_max,&lilo,&isa, ! &y->x_snd,&y->x_rcv,&y->x_lab, &y->x_ldx,&y->x_ldy,&y->x_font_style,&y->x_fontsize, &y->x_bcol,&y->x_fcol,&y->x_lcol,&v,&steady)) return; ! iem_inttosymargs(y,isa); x->x_pos = x->x_val = y->x_loadinit ? v : 0; + y->x_lin0_log1 = lilo; y->x_steady = steady; iemgui_constrain(y); ! slider_check_minmax(x); if (isvert(x)) slider_check_width(x, y->x_h); else slider_check_width(x, y->x_w); *************** *** 246,254 **** class_addbang(c,slider_bang); class_addfloat(c,slider_float); - class_addmethod(c, (t_method)slider_motion, gensym("motion"), A_FLOAT, A_FLOAT, 0); class_addmethod(c, (t_method)slider_reload, gensym("reload"), A_GIMME, 0); class_addmethod(c, (t_method)slider_loadbang, gensym("loadbang"), 0); class_addmethod(c, (t_method)slider_set, gensym("set"), A_FLOAT, 0); class_addmethod(c, (t_method)slider_size, gensym("size"), A_GIMME, 0); class_addmethod(c, (t_method)slider_log, gensym("log"), 0); class_addmethod(c, (t_method)slider_lin, gensym("lin"), 0); --- 221,229 ---- class_addbang(c,slider_bang); class_addfloat(c,slider_float); class_addmethod(c, (t_method)slider_reload, gensym("reload"), A_GIMME, 0); class_addmethod(c, (t_method)slider_loadbang, gensym("loadbang"), 0); class_addmethod(c, (t_method)slider_set, gensym("set"), A_FLOAT, 0); class_addmethod(c, (t_method)slider_size, gensym("size"), A_GIMME, 0); + class_addmethod(c, (t_method)slider_range, gensym("range"), A_FLOAT, A_FLOAT, 0); class_addmethod(c, (t_method)slider_log, gensym("log"), 0); class_addmethod(c, (t_method)slider_lin, gensym("lin"), 0);
Index: u_object.tk =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/u_object.tk,v retrieving revision 1.1.2.38 retrieving revision 1.1.2.39 diff -C2 -d -r1.1.2.38 -r1.1.2.39 *** u_object.tk 7 May 2004 05:55:50 -0000 1.1.2.38 --- u_object.tk 7 May 2004 07:15:38 -0000 1.1.2.39 *************** *** 522,525 **** --- 522,529 ---- } numbox_draw $self $canvas + } elseif {$key==27} { + # Escape + set _($self:val) $_($self:oval) + canvas_ungrab $canvas } else { puts "numbox_keyevent $key" *************** *** 674,716 **** set _($self:unclickevent) slider_unclick set _($self:ungrabevent) slider_ungrab - return - #EXPERIMENTAL: (notches) - if {$orient} { - set thick [clamp [expr $xs/3] 1 5] - set x3 [expr $x1+$xs-$thick/2-2] - set eighth [expr round($ys/8-1)] - set coords [list $x3 $y1 $x3 [expr $y1+$ys]] - } else { - set thick [clamp [expr $ys/3] 1 5] - set y3 [expr $y1+$ys-$thick/2-2] - set eighth [expr $xs/8] - set coords [list $x1 $y3 [expr $x1+$xs] $y3] - } - $canvas create line $coords -dash [list 1 $eighth 1 $eighth] -width $thick -fill [darker $look(sliderbg)] - }
- proc slider_set {self canvas value} { - global _ set pos [$canvas coords ${self}BASE] - foreach {x1 y1} [object_xy $self $canvas] {} - set orient [slider_orient $self] set span [expr $_($self:max)-$_($self:min)] ! set _($self:value) [expr $value*$span/($orient?$_($self:h):$_($self:w))/100] if {$orient} { set size [expr [lindex $pos 2]-$x1] ! set y1 [expr [lindex $pos 3]-($value+50)/100-2] set y2 [expr $y1-2] $canvas coords ${self}KNOB \ ! [expr $x1+2] $y1 \ ! [expr $x1+$size-2] $y2 } { set size [expr [lindex $pos 3]-$y1] ! set x1 [expr $x1+($value+50)/100] set x2 [expr $x1+2] set y2 [expr $y1+$size] $canvas coords ${self}KNOB \ ! $x1 [expr $y1+2] \ ! $x2 [expr $y1+$size-2] } }
--- 678,717 ---- set _($self:unclickevent) slider_unclick set _($self:ungrabevent) slider_ungrab
set pos [$canvas coords ${self}BASE] set span [expr $_($self:max)-$_($self:min)] ! set l [expr $orient?$_($self:h):$_($self:w)] ! set value [expr $_($self:val)*$span/($l-1)/100] ! set _($self:value) $value if {$orient} { set size [expr [lindex $pos 2]-$x1] ! set y1 [expr [lindex $pos 3]-$value*($l-1)/$span-2] set y2 [expr $y1-2] $canvas coords ${self}KNOB \ ! [expr $x1+2] $y1 [expr $x1+$size-2] $y2 } { set size [expr [lindex $pos 3]-$y1] ! set x1 [expr $x1+$value*($l-1)/$span] set x2 [expr $x1+2] set y2 [expr $y1+$size] $canvas coords ${self}KNOB \ ! $x1 [expr $y1+2] $x2 [expr $y1+$size-2] ! } ! } ! ! # not used ! proc slider_draw_notches {self canvas} { ! if {$orient} { ! set thick [clamp [expr $xs/3] 1 5] ! set x3 [expr $x1+$xs-$thick/2-2] ! set eighth [expr round($ys/8-1)] ! set coords [list $x3 $y1 $x3 [expr $y1+$ys]] ! } else { ! set thick [clamp [expr $ys/3] 1 5] ! set y3 [expr $y1+$ys-$thick/2-2] ! set eighth [expr $xs/8] ! set coords [list $x1 $y3 [expr $x1+$xs] $y3] } + $canvas create line $coords -dash [list 1 $eighth 1 $eighth] -width $thick -fill [darker $look(sliderbg)] }
*************** *** 737,743 **** global _ set _($self:clicking) 0 ! if {$_($self:value)!=$_($self:ovalue)} { canvas_ungrab $canvas ! pd "x$self float $_($self:val) ;" } } --- 738,744 ---- global _ set _($self:clicking) 0 ! if {[lindex $_($self:first) 1] != $y} { canvas_ungrab $canvas ! pd "x$self float $_($self:value) ;" } }