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!

Zooming In on a Canvas (Line) Item

Status
Not open for further replies.

cptk

Technical User
Mar 18, 2003
305
US
I'd like to zoom (and out) on a canvas line drawing by "panning" an area, then zoom in?

Is this doable?

I'm starting off displaying a large map, but I then want the feature of being able to zoom in on a particular spot on the map which will then display more detail.

I've located a method of applying a enlarge "factor" to my coordinates by using the canvas's bbox and scale methods, but I was wondering if there's another easier way.
 
Sorry to not be able to help (I'ld do what you suggested).
Hope someone can hepl you.

ulis
 
Thanks for acknowledging my question.

Since my initial post, I've been thinking of just using BLT, however, I'm reluctant to use BLT only because ultimately I'd like to Prowrap my application but so far haven't been able to figure out a way to Prowrap with BLT (I have posted previously with this problem).
 
The canvas is an incredible widget, with more fascinating features than most people are aware of. However, it does have some limitations, and an easy method for "zooming" the view without actually scaling all the objects is one of them. (The ability to rotate objects is another big missing feature.)

The strategy you came up with is the standard method of emulating a "zoom" feature. Keep in mind that one limitation of this approach is that the canvas's scale operation basically scales object coordinates. It doesn't scale other object attributes, such as width or the font size of text objects. It also doesn't scale bitmaps or embedded images.

Here's a simple procedure called zoom that might help to get you started. Not only does it scale all of the objects on a canvas by a given scaling factor, but it also resizes font size for text objects:

Code:
proc zoom {canvas scale} {
  $canvas scale all 0 0 $scale $scale
  foreach item [$canvas find all] {
    if {[$canvas type $item] == "text"} {
      set font [font actual [$canvas itemcget $item -font]]
      set index [lsearch -exact $font -size]
      incr index
      set size [lindex $font $index]
      set size [expr {round($size * $scale)}]
      set font [lreplace $font $index $index $size]
      $canvas itemconfigure $item -font $font
    }
  }
  
  $canvas configure -scrollregion [$canvas bbox all]
}

Note the use of the font actual command in there. It returns a full font specification of the font given as an argument. You need because if you use a "short form" font specification like "helvetica 16 bold", that's exactly what you'd get back when you queried the item's font value. I need the full specification so that I can search for the "-size".

Also note that when computing the new font size, I had to round it to the nearest integer value. Tcl doesn't support fractional font sizes.

A better approach would be to create named font "styles" with the font create command and use these named styles for all text that you place on the canvas. Then, when you want to scale the font size, just modify the definitions of the font styles and those chages are automatically applied to all text using those styles. For example:

Code:
font create title -family gillsans -size 14 -weight bold
font create body -family {Lucida Sans} -size 10
canvas .c
pack .c
.c create text 50 50 -anchor nw -text "Avia Training" -font title
.c create text 50 100 -anchor nw -text "and Consulting" -font body

# Later on, when you want to scale the size

set size [font configure title -size]
set size [expr {round($size * 0.8)}]
font configure title -size $size

set size [font configure body -size]
set size [expr {round($size * 0.8)}]
font configure body -size $size

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Again, as always thanks Ken.

But, now I'm adding another level of complexity to
my original inquiry.

I would like to do more than a simple x y graph -
actually I'd like to create double x axis or y axis
graphs - can this be done in plain tcl?
 
Sorry - I wasn't thinking (it's late) ...
BLT does handle double x or y axis ...
 
Ah. Now I see your dilemma. For all but the most simple of cases, I wouldn't try to replicate BLT's graphing features with the canvas if at all possible. But yes, using Prowrap with BLT is quite problematic. I see at least three possible ways to approach this:

[ol][li]Use TclKit technology instead of Prowrap. Wojciech Kocjan has created something called dqkit, which is based on a standard TclKit, but also includes support for BLT and a few other extensions not lumped into the stock TclKit. You can find out more information about it on the Tcl'ers Wiki ( on the page "dqkit," [/li]

[li]If you're willing to use Freewrap instead of Prowrap and if you're deploying only on Linux systems, you can get a Linux version of Freewrap that includes BLT support. Freewrap is quite similar to Prowrap, but is being actively maintained. You can find out more information about Freewrap at and [/li]

[li]If you really want to stick with Prowrap, you'll need to use a custom, Prowrap-compatible Tcl interpreter statically compiled with BLT. It's been a long time since I've fiddled about with trying to use a custom interpreter with Prowrap, so I don't really have any handy tips for you regarding this. All I can say is read the read the TclPro documentation.[/li][/ol]

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thanks for the direction Ken ...I'd like to explore your option 1.

However, more questions ...
(NOTE: I'm on a unix Solaris system)

When I checked out the link for your option 1 (dqkit), I noticed two choices:
1.) dqkit-sources-0.4-core.tar.gz 9402730 Platform-Ind
2.) dqkit-sources-0.4.tar.gz 16784695 Platform-Ind

Q1.) What's the diff. betw. the two?
Q2.) Do I also need the Tclkit?
...and while I'm at it, was does "stubs" mean?

...thanks!!!
 
Just an update ...

I'm using BLT for my graphing and zooming (instead of a canvas)

However, so far I can't get to my ultimate goal - a single executable!!

1.) Can't build dqkit on solaris sparc
2.) There's no FreewrapBLT version for solaris
3.) Prowrap - I haven't figured out how to create a custom interpreter to statically include BLT ... It doesn't seem possible nor intuititive enough (via the manual instructions).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top