Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

How to rotate text in Tk::Abstract Canvas ?

by KuntalBhusan (Acolyte)
on May 09, 2013 at 09:18 UTC ( #1032748=perlquestion: print w/replies, xml ) Need Help??
KuntalBhusan has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, The Tk::Abstract canvas manual page in CPAN says of a method :
$acnv->rotate(TagOrID, angle ?,x, y?) This method rotates the object identified by TagOrID by angle. The ang +le is specified in degrees. If an x, y coordinate is specified, then +the object is rotated about that point. Otherwise, the object is rota +ted about its center point, if that can be determined.

and also mentions later that :

As it stands, the module can only rotate the following object types ab +out their centers: Lines Polygons Rectangles (if rectToPoly(1) is called) Ovals (if ovalToPoly(1) is called) All other object types (bitmap, image, arc, text, && window) can only +be rotated about another point. A warning is issued if the user tries + to rotate one of these object types about their center. Hopefully, m +ore types will be able to center-rotate in the future.

This means that it is able to rotate texts...

when I tried to do the same using the code below, my text is not rotated...

use Tk; use Tk::AbstractCanvas; my $mw=MainWindow->new(-title=>'RotateText-Test'); my $w = $mw->screenwidth; my $h = $mw->screenheight; $mw->geometry( $w."x".$h); $mw->resizable(1,1); my $canvas = $mw->Scrolled('AbstractCanvas', -background => "white", -scrollbars => "osoe", -height => 0, -relief => "solid", -width => 0, -scrollregion=>[0,0,1,1], )->pack(-anchor=>'nw', -side=>'top', -fill=>'both', -expand=>1); my $text = $canvas->createText(0,0,-anchor=>'center',-fill => 'red',-t +ext => 'Hello Monks !!!',); #my $text = $canvas->createText(2,10,-anchor=>'center',-fill => 'red', +width => 1,-text => 'Hello Monks !!!',); ## this rotates but not the +characters :( $canvas->rotate($text,90,$x,$y); $canvas->viewAll(); MainLoop; ();

seeking the Monks help..

Replies are listed 'Best First'.
Re: How to rotate text in Tk::Abstract Canvas ?
by kcott (Chancellor) on May 09, 2013 at 21:02 UTC

    G'day KuntalBhusan,

    You haven't defined either $x or $y in $canvas->rotate($text,90,$x,$y);.

    Looking at Tk::AbstractCanvas' Source, you'll see these values must be defined (the return() unless ... line):

    sub rotate { # takes as input id of obj to rot, angle to rot by, && op +tional x,y point to rot about instead of obj center, if possible my($self, $obid, $angl, $xfoc, $yfoc)= @_; croak "rotate: Must suppl +y an angle -" unless(defined($angl)); my $type = $self->type($obid); # some objs need a pivot point to rot +ate their center around return() unless(exists($_can_rotate_about_center{$type}) || (defined +($xfoc) && defined($yfoc))); $_rotate_methods{$type}->($self, $obid, $angl, $xfoc, $yfoc); }

    -- Ken

      Sorry for that...actually this snippet is part of a code where the $x and $y comes from a file ( i just pasted it and forgot to change it...perhaps it would be 0,0 or something but it is optional as the subroutine says..).

      But even after altering and applying the changes it wont work...can you edit this code suitably so that it is rotated by a supplied angle...waiting eagerly for some help...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1032748]
Approved by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2018-05-26 20:52 GMT
Find Nodes?
    Voting Booth?