Scaling in the canvas 
Author Message
 Scaling in the canvas

I am using the Scrolled canvas widget and when I use the scale method of
canvas, the scrollbars do not change to reflect the new scaling. Any
help will be greatly appreciated? Thanks.

Code -----
use Tk;
$top = MainWindow->new();
$canvas = $top->Scrolled('Canvas', -scrollbars => 'se', scrollregion =>
[0, 0, 50, 50])->pack();
$id2 = $canvas->createRectangle(20, 20, 40, 40, fill => "green", tag =>
'rect');
$button = $top->Button(-text=> 'Zoom In',
                                      -command => sub {

$canvas->scale('all', 0, 0, 2, 2);
                                                                    }
                                      )->pack();
MainLoop;

-------
Behavior: When the canvas scales the rectangle becomes 2 times as big,
the scrollbars do not change to reflect the new scaling and consequently
some parts of the image go "outside" and cannot be viewed.

Regards,
Rajeev



Fri, 09 Jan 2004 23:59:05 GMT  
 Scaling in the canvas

Quote:

> I am using the Scrolled canvas widget and when I use the scale method of
> canvas, the scrollbars do not change to reflect the new scaling. Any
> help will be greatly appreciated? Thanks.

> Code -----
> use Tk;
> $top = MainWindow->new();
> $canvas = $top->Scrolled('Canvas', -scrollbars => 'se', scrollregion =>
> [0, 0, 50, 50])->pack();
> $id2 = $canvas->createRectangle(20, 20, 40, 40, fill => "green", tag =>
> 'rect');
> $button = $top->Button(-text=> 'Zoom In',
>                                       -command => sub {

> $canvas->scale('all', 0, 0, 2, 2);
>                                                                     }
>                                       )->pack();
> MainLoop;

> -------
> Behavior: When the canvas scales the rectangle becomes 2 times as big,
> the scrollbars do not change to reflect the new scaling and consequently
> some parts of the image go "outside" and cannot be viewed.

You have to adjust the -scrollregion (please note the leading "-"!)
manually. There are many other things, Tk's scale doesn't do like
rescaling text size, images etc.

Regards,
        Slaven

--

    tkrevdiff - graphical display of diffs between revisions (RCS or CVS)
    http://ptktools.sourceforge.net/#tkrevdiff



Sat, 10 Jan 2004 04:47:21 GMT  
 Scaling in the canvas

Quote:


> > I am using the Scrolled canvas widget and when I use the scale method of
> > canvas, the scrollbars do not change to reflect the new scaling. Any
> > help will be greatly appreciated? Thanks.

> > Code -----
> > use Tk;
> > $top = MainWindow->new();
> > $canvas = $top->Scrolled('Canvas', -scrollbars => 'se', scrollregion =>
> > [0, 0, 50, 50])->pack();
> > $id2 = $canvas->createRectangle(20, 20, 40, 40, fill => "green", tag =>
> > 'rect');
> > $button = $top->Button(-text=> 'Zoom In',
> >                                       -command => sub {

> > $canvas->scale('all', 0, 0, 2, 2);
> >                                                                     }
> >                                       )->pack();
> > MainLoop;

> > -------
> > Behavior: When the canvas scales the rectangle becomes 2 times as big,
> > the scrollbars do not change to reflect the new scaling and consequently
> > some parts of the image go "outside" and cannot be viewed.

> You have to adjust the -scrollregion (please note the leading "-"!)
> manually. There are many other things, Tk's scale doesn't do like
> rescaling text size, images etc.

> Regards,
>         Slaven

> --

>     tkrevdiff - graphical display of diffs between revisions (RCS or CVS)
>     http://ptktools.sourceforge.net/#tkrevdiff

Yep, there are few assumptions made.  I used a subroutine that looks
like this:

sub scale_waveform {

# scale the waveform by scale or by 1/scale if invert is true
# then modify configuration and move to the needed point.


 if ($scale > 1) {
  $scale=1/$scale if ($invert);
  $c->scale("all",0,0,$scale,1);
  $main::waveform_unit*=$scale;
  $main::waveform_x_offset*=$scale;
  $main::waveform_change*=$scale;
  $main::waveform_stable*=$scale;
  $main::waveform_scale*=$scale;
 }
 $c->
   configure(-scrollregion=> [ 0,0,($c->bbox("all"))[2..3] ]);
 $c->xview('moveto',$moveto);

- Show quoted text -

Quote:
}



Mon, 12 Jan 2004 05:43:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Scaling fonts in Canvas again

2. Scaling fonts on Canvas

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

4. How to scale canvas coordinates?

5. scaling canvas items

6. Scaling text on a canvas

7. Tk::Canvas scale question

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

9. Perl/TK scrolled canvas scale zoom NOOP?

10. Zooming in a canvas with the scale method

11. Regarding Canvas and Scale widget

12. A little tutorial on Canvas scaling

 

 
Powered by phpBB® Forum Software