in reply to Total Newbies TkZinc questions
To your questions:
1. Is there a Tk::Zinc(::Graphics) way of building multiple items with similar characteristics? (and how good is my hacked solution)
Yes, look at the clone() method. Look in the zinc-demos, under User Contributed Demos, for TripleRotatingWheel. I make one wheel object, then clone it, then translate it into position. Like: my $arc2 = $zinc->clone($arc1);
2.Is there a reliable way to position text at center of group?
Here is a snippet to show you how. I also throw in a useful trick for reversing the y-axis direction, so coords are more like standard cartesian.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Zinc; my $mw = MainWindow->new; my $width = 700; my $height = 600; $mw->geometry($width.'x'.$height); my $zinc = $mw->Zinc(-width => $width, -height => $height, -backcolor => 'black', -borderwidth => 3, -relief => 'sunken', )->pack; $zinc->fontCreate( "fonta", -family => 'arial', -size => 30, -weight => 'normal' ); #create a group with it's origin at center my $centergroup= $zinc->add('group',1,-visible=> 1); $zinc->scale($centergroup,1,-1); #reverse direction of y axis $zinc->translate($centergroup,$width/2,$height/2); # Then we create a gray filled rectangle, in which we will display exp +lain text. $zinc->add('rectangle', $centergroup , [-100, -100, 100, 100], -linewidth => 2, -filled => 1, -fillcolor => 'SkyBlue', ); my $text = $zinc->add('text', $centergroup, -position => [0,0], -text => 'foobaz', -font => 'fonta', -anchor => 'center', -priority => 2 ); MainLoop;
3. Is there a way to correctly calulate delta x/y if scaling is active?
Your dragging works fine by itself, and your scaling works fine by itself. Maybe just make them mutually exclusive, and pop a warning saying scaling is disabled during dragging? How often is someone going to want to do that anyways? I saw a similar problem in the Gnome2::Canvas and Goo::Canvas where I needed to do some clever multiplications/divisions to account for the current scale when saving to pdf. All I can say is I spent a few hours experimenting before I got it right. :-)
4. Did I missing something when it comes to calculating positions of items relative to display settings?
If you are referring to the drag/scale problem, what I think you will need to do is have 2 separate code blocks for calculating dx/dy. One if scaling is active, and 1 for simple dragging. Since your scaling factor can constantly be changing while the darg is occurring, I think it will mean alot of recalculations for each pixel of drag. Think about it....how can Zinc know what your dx/dy is, if the scale is changing while you drag. At best, it will be jerky( visually not codewise :-) ). I have 2 suggestions. One is to pop a warning, saying scaling is disabled during a drag. Or two, get rid of the +/- button press for scaling, and use a SpinBox instead, to set the scale. That way, the mouse can only be in 1 place at a time...either setting the scale-SpinBox or dragging an item.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Total Newbies TkZinc questions
by rocklee (Beadle) on Oct 21, 2008 at 21:47 UTC | |
by zentara (Cardinal) on Oct 22, 2008 at 13:13 UTC | |
|
Re^2: Total Newbies TkZinc questions
by rocklee (Beadle) on Oct 21, 2008 at 23:39 UTC | |
by zentara (Cardinal) on Oct 22, 2008 at 13:19 UTC | |
by rocklee (Beadle) on Oct 22, 2008 at 18:32 UTC | |
by zentara (Cardinal) on Oct 22, 2008 at 19:05 UTC |