[PD-dev] much better scrolling algorithm (pd-extended 0.42.5)

Hans-Christoph Steiner hans at at.or.at
Sat Oct 31 22:18:04 CET 2009


Hey Ivica,

I rewrote the scrollbar logic in 0.43 and its working well, as far as  
I can tell.  Have you tried it out?  I think its a similar approach,  
but the difference is that my code tries to keep things at 0,0 since  
Pd has a historical preference for patches having 0,0 as the upper left.

.hc

On Oct 31, 2009, at 3:34 PM, Ivica Ico Bukvic wrote:

> Below is relevant excerpt that IMHO is much better scrolling  
> algorithm.
> It has been tested only on Linux so far but there is no reason why it
> should not work on other platforms. Basically, now the whole canvas
> translates as necessary. Therefore,
>
> 1) dragging a single object away from 0 0 coordinates will never  
> spawn a
> scrollbar (since we don't care how far someone goes away from
> center--theoretically their whole patch could be at -30000 to -29800  
> (x1
> x2). That said, I am not sure if the thing will crash if you go beyond
> 1.0e30 either direction but I suspect it will take a long while before
> you get there :-)
> 2) scrollbars appear/disappear logically, (e.g. only when two or more
> objects are far enough from each other not to fit on the visible  
> portion
> of the canvas)
> 3) and perhaps most importantly since text (particularly larger text
> commonly used for iemlib gui elements) generates incorrect reports  
> from
> the "bbox all" call (e.g. try creating a number2 with a height 80 and
> notice how you are never able to drag it all the way to the top of the
> canvas without invoking the Y-axis scrollbar even though your text  
> might
> be font 10; larger font sizes make things even worse). So now  
> finally I
> can create compact windows without scrollbars using iemlib objects.
>
> Optionally, if you wish to use hacked pd.tk version (made for
> pd-extended 0.42.5). You will also have an option to disable  
> scrollbars,
> menu, alter background color, toggle ontop, and disable resize, *per
> patcher*. I found this to be also rather useful for GUI creation.
> Attached with the new pd.tk are supporting abstractions.
>
> Below is relevant code for points 1-3 from the current pd.tk in hope  
> it
> will find its way into 0.43 gui rewrite.
>
> proc pdtk_canvas_getscroll {name} {
>    global pdtk_canvas_mouseup_name
>    global pdtk_canvas_mouseup_xminval
>    global pdtk_canvas_mouseup_xmaxval
>    global pdtk_canvas_mouseup_yminval
>    global pdtk_canvas_mouseup_ymaxval
>
> 	#bbox all is not accurate enough
> 	#particularly when using large iemlib objects
> 	#so we calculate canvas size manually
>    #set size [$name bbox all]
>
> 	#borrowed from http://wiki.tcl.tk/4844
> 	set x1 1.0e30; set x2 -1.0e30 ;
> 	set y1 1.0e30; set y2 -1.0e30 ;
> 	foreach item [$name find all] {
> 	    switch -exact [$name type $item] {
> 			"arc" -
> 			"line" -
> 			"oval" -
> 			"polygon" -
> 			"rectangle" {
> 				set coords [$name coords $item]
> 				foreach {x y} $coords {
> 					if { $x < $x1 } {set x1 $x}
> 					if { $x > $x2 } {set x2 $x}
> 					if { $y < $y1 } {set y1 $y}
> 					if { $y > $y2 } {set y2 $y}
> 				}
> 			}
> 	    }
> 	}
> 	
> 	if {$x1 != 1.0e30} {
>
> 		set xminval 0
> 		set yminval 0
> 		set xmaxval 100
> 		set ymaxval 20
> 		#set x1 [lindex $size 0]
> 		#set x2 [lindex $size 2]
> 		#set y1 [lindex $size 1]
> 		#set y2 [lindex $size 3]
>
> 		#pdtk_post "bbox all: $x1 $x2 $y1 $y2\n"
> 		#pdtk_post "new bbox all: $xbox1 $xbox2 $ybox1 $ybox2\n"
>
> 		#these work much better than the ones below
> 		#they allow for intelligent translation of the canvas
> 		#rather than introducing redundant scrollbars
> 		set xminval $x1
> 		set yminval $y1
>
> 		set xmaxval [expr $x1+($x2-$x1)]
> 		set ymaxval [expr $y1+($y2-$y1)]
>
> 		#if {$x1 < $xminval} {set xminval $x1}
> 		#if {$y1 < $yminval} {set yminval $y1}
>
> 		#if {$x2 > $xmaxval} {set xmaxval $x2}
> 		#if {$y2 > $ymaxval} {set ymaxval $y2}
>
> 		#pdtk_post "$xminval $xmaxval $yminval $ymaxval\n"
>
> 		set parentname [winfo parent $name]
> 		set winwidth [winfo width $parentname]
> 		set winheight [winfo height $parentname]
>
> 		set canvaswidth [ expr {abs($xmaxval-$xminval)} ]
> 		set canvasheight [ expr {abs($ymaxval-$yminval)} ]
> 		#set canvaswidth [ expr {abs($xminval)+$xmaxval} ]
> 		#set canvasheight [ expr {abs($yminval)+$ymaxval} ]
>
> 		#pdtk_post "$canvaswidth $canvasheight\n"
>
> 		#pdtk_post "$parentname [$parentname.scroll cget -state]\n"
> 		if {$::scroll($parentname) == 1} {
> 			#pdtk_post "scroll=yes $winwidth $canvaswidth\n"
> 			if {$winwidth > $canvaswidth} {pack forget $parentname.scrollhort}
> 			if {$winheight > $canvasheight} {pack forget  
> $parentname.scrollvert}
> 			if {$winwidth < $canvaswidth} {pack $parentname.scrollhort -fill  
> x \
> 					                           -side bottom -before $parentname.c}
> 			if {$winheight < $canvasheight} {pack $parentname.scrollvert - 
> fill y
> \
> 					                             -side right -before $parentname.c}
> 		}
> 	
> 		if {$pdtk_canvas_mouseup_name != $name || \
> 				$pdtk_canvas_mouseup_xminval != $xminval || \
> 				$pdtk_canvas_mouseup_xmaxval != $xmaxval || \
> 				$pdtk_canvas_mouseup_yminval != $yminval || \
> 				$pdtk_canvas_mouseup_ymaxval != $ymaxval } {
> 		
> 			set newsize "$xminval $yminval $xmaxval $ymaxval"
> 			$name configure -scrollregion $newsize
> 			set pdtk_canvas_mouseup_name $name
> 			set pdtk_canvas_mouseup_xminval $xminval
> 			set pdtk_canvas_mouseup_xmaxval $xmaxval
> 			set pdtk_canvas_mouseup_yminval $yminval
> 			set pdtk_canvas_mouseup_ymaxval $ymaxval
> 		}
> 	}
>    pdtk_canvas_checkgeometry [canvastosym $name]
> }
>
> Best wishes,
>
> Ico
> <pd.tk_and_abstractions.tar.gz>


----------------------------------------------------------------------------

I hate it when they say, "He gave his life for his country."  Nobody  
gives their life for anything.  We steal the lives of these kids.  - 
Admiral Gene LeRocque





More information about the Pd-dev mailing list