Tk::Canvas scale question 
Author Message
 Tk::Canvas scale question

Hi,

I am using  Tk800.024: I have a canvas for displaying some items. I want to
add zoom in/out function
to zoom around a point on the screen. The zoom function works as I intended.
My problem is; when I insert the same item after using the zoom, the new
item does not get
inserted at the same spot on the screen (I do adjusted the coordinates of
the object by the
zoom factor (multiply x & y by zoom factor)). Any suggestions on how to do
this

the piece of code I am using for the zoom:

my $x;
my $Y;
my $zoom_factor = 1;
my $zoom_multipler = 1.02;


                              my $e = $c->XEvent;
                              $X = $c->canvasx($e->x);
                              $Y = $c->canvasy($e->y);
                            });

my $zoom_up = $frm_mnu->Button
      ( -anchor => 'nw',
        -command => sub{ if( $zoom_factor < 1 ) { $zoom_factor =
1/$zoom_factor; }
                         else { $zoom_factor *= $zoom_multipler; }
                         $c->scale( "all", $X, $Y, $zoom_factor,
$zoom_factor );
                       },
        -relief => 'flat',
        -text => 'Z +',
        -width => 2,
      )->pack( -side => 'left' );

my $zoom_dn = $frm_mnu->Button
      ( -anchor => 'nw',
        -command => sub{ if( $zoom_factor > 1 ) { $zoom_factor =
1/$zoom_factor; }
                         else{ $zoom_factor /= $zoom_multipler; }
                         print"\ndn===>X=$X  Y=$Y
zoom_factor=$zoom_factor";
                         $c->scale( "all", $X, $Y, $zoom_factor,
$zoom_factor );
                       },
        -relief => 'flat',
        -text => 'Z -',
        -width => 2,
      )->pack( -side => 'left' );

and the code I am using for inserting items:

          $cc = $zoom_factor;
          my $w = $L[13]/2;
          my $l = $L[12]/2;

          my $x0 = ($L[10]-$l)*$cc . "i";
          my $y0 = ($L[11]-$w)*$cc . "i";
          my $x1 = ($L[10] +$l)*$cc . "i";
          my $y1 = ($L[11]+$w)*$cc . "i";
          $canvas->createRectangle( $x0, $y0 , $x1, $y1,
                                          -outline => 'green1',
                                  );

any help or suggestions

Thanks,

Shahriar Mokhtarzad
Pluris Inc.
10455 Bandley Drive
Cupertino, CA 95014
Tel: (408)861-4215

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Wed, 01 Sep 2004 02:09:58 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Canvas->Scale and Tk::Scale conflict?

2. Perl/TK scrolled canvas scale IMAGE function???

3. Perl/TK scrolled canvas scale zoom NOOP?

4. How to scale canvas coordinates?

5. scaling canvas items

6. Scaling text on a canvas

7. Zooming in a canvas with the scale method

8. Scaling in the canvas

9. Regarding Canvas and Scale widget

10. A little tutorial on Canvas scaling

11. Scaling fonts in Canvas again

12. Scaling a Canvas

 

 
Powered by phpBB® Forum Software