Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scroll canvas with thumbnails

Status
Not open for further replies.

eduardomp3

Programmer
Apr 28, 2004
2
BR
Hello,

I'm doing a complex software that need to display thumbnails.

My ideia was to create a big canvas and insert many little canvas (one for
each image/image label) in it.
Them, I would like to scroll the big canvas, automatically scrolling
all the images in it at the same time.

But it simply doesn't work.

Trying to discover why, I found a simply nice code at
that display only one
image with a good scroll.
Now I tryed to insert another one and scroll the big canvas that
contains both. Again, it doesn't work.

In the code above, the vertical bar scroll the image called map2, and
the horizontal scrolls the image map1.

What can I do to scroll both os them at the same time, just like all
thumbnails programs?

Thanks very much,

Eduardo

# globals
set image_num "0";

#callbacks
proc quit_proc {} {
destroy .x.baner .x .quit .scroll_y .scroll_x . exit 0; }

# Load map and get properties (used to center the image)
image create photo map -file test.gif;
image create photo map2 -file unicamp.gif;

set border 2

set max_x [image width map];
set max_y [image height map];

set max_x2 [image width map2];
set max_y2 [image height map2];

set pos_x [expr $max_x / 2 - [expr $border / 2]];
set pos_y [expr $max_y / 2 - [expr $border / 2]];


set pos_x2 [expr $max_x2 / 2 - [expr $border / 2]];
set pos_y2 [expr $max_y2 / 2 - [expr $border / 2]];

set canvas_width [expr $max_x + $max_x2 + 10 + [expr $border / 2]];
set canvas_height [expr $max_y + $max_y2 + 10 + [expr $border / 2]];
set Scrolling_Win "-30/-30/$canvas_width/$canvas_height"

# Create scrollbars and apply them to the canvas
scrollbar .scroll_x -command ".x.x1.baner xview" -orient horizontal;
scrollbar .scroll_y -command ".x.x1.baner2 yview" -orient vertical;

frame .x -width [expr $max_x + $max_x2 + 20 + 10] -height [expr $max_y + $max_y2 + 20 + 10]
canvas .x.x1 -relief sunken -borderwidth 10 -width [expr $max_x + $max_x2 + 10] -height [expr $max_y + $max_y2 + 10] -scrollregion [split $Scrolling_Win /] -xscrollcommand ".scroll_x set" -yscrollcommand ".scroll_y set";

canvas .x.x1.baner -relief sunken -borderwidth 2 -width [expr $max_x + 10] -height [expr $max_y + 10] -xscrollcommand ".scroll_x set" -yscrollcommand ".scroll_y set";
canvas .x.x1.baner2 -relief sunken -borderwidth 2 -width [expr $max_x2 + 10] -height [expr $max_y2 + 10] -xscrollcommand ".scroll_x set" -yscrollcommand ".scroll_y set";


# apply the map into the canvas
.x.x1.baner create image "$pos_x" "$pos_y" -image map -tag image_1;
.x.x1.baner2 create image "$pos_x2" "$pos_y2" -image map2 -tag image_2;

button .quit -text "quit" -command quit_proc;
label .hauteur -text "$max_x x $max_y";

pack .quit -side bottom;
pack .scroll_y -side right -fill y;
pack .scroll_x -fill x;
pack .hauteur;
pack .x
pack .x.x1.baner2;
pack .x.x1.baner;
pack .x.x1
 
look at the code for the demo, "A Simple Scrollable Canvas", that comes with the distribution.

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top