NAME
App::SourcePlot::Plotter::Tk - Create a Tk canvas with easy-to-use method names
DESCRIPTION
This class provides methods to use a GUI canvas with ease. The commands will be generalized to ensure easy transfer between graphing packages.
METHODS
Constructor
- new
-
Create a new instance of Plotter::Tk object. A new canvas will be created with the specified coordinates. This method will create a new window for use by the canvas if one is not passed in.
$plotter = App::SourcePlot::Plotter::Tk->new($MainWindow, $width, $height);
Canvas functions
- getCanvas
-
Used specifically within this module, it allows the programmer to add new features to this module with ease by accessing the Tk canvas.
$can = $plotter->getCanvas();
Setup tools
- width
-
Returns the width of a canvas.
$w = $plotter->width();
- height
-
Returns the width of a canvas.
$w = $plotter->height();
- setBackground
-
Sets the background color
$plotter->setBackground('black');
- setForeground
-
Sets the foreground color.
$plotter->setForeground('black');
- font
-
Sets and returns the font currently being used.
$f = $plotter->font(); $plotter->font($f);
- fontColor
-
Sets and returns the font color.
$plotter->fontColor('black');
- fontSize
-
Sets and returns the font size.
$plotter->fontSize(5); $size = $plotter->fontSize();
- drawColor
-
Sets and returns the drawing color, used for filling as well.
$plotter->drawColor('Black'); $c = $plotter->drawColor();
- penWidth
-
Sets and returns the width lines, circles, etc will be drawn in.
$plotter->penWidth(3); $w = $plotter->penWidth();
- pack
-
Packs the canvas into a certain position within a main window or frame.
$plotter->pack(-side => 'left');
Conversion from world to pixels
- worldCenter
-
Sets the center of the world coordinates on the screen Best to set the centre in pixels, and then the appropriate world coordinates can be set at this point using worldAtZero.
$plotter->worldCenter ($centerx, $centery);
- worldAtZero
-
Offsets the centre of the world coordinates to allow specific world coordinates to be the new centre coordinates.
$plotter->worldAtZero ($centerx, $centery);
- worldToPixRatio
-
Sets the ratio between the world coordinates and pixels
$plotter->worldToPixRatio($dx, $dy);
- usingWorld
-
Tells the module whether you wish to use the world coordinates when specifying coordinates, or if you want to use pixels. Returns and sets the value (1 for on, 0 for off).
$u = $plotter->usingWorld(); $plotter->usingWorld(1);
- setWorldSize
-
Sets the center of the world coordinates and the ratio between those coordinates and pixels
$plotter->setWorldSize($centerx, $centery, $dx, $dy);
- toP
-
Converts coordinates into pixels. The input coordinates are assumed to be associated with the value in usingWorld.
($x, $y) = $plotter->toP($x1, $y1); ($x) = $plotter->toPx($x1); ($y) = $plotter->toPy($y1);
- toPx
-
Converts passed in paramter into pixels.
- toPy
-
Converts passed in paramter into pixels.
- toW
-
Converts pixel coordinates into current system. The output coordinates are assumed to be associated with the value in usingWorld.
($x, $y) = $plotter->toW($x1, $y1); ($x) = $plotter->toWx($x1); ($y) = $plotter->toWy($y1);
- toWx
-
Must specify (x).
- toWy
-
Must specify (y).
Drawing tools
- clean
-
Removes all drawn objects from the canvas.
$plotter->clean();
- delete
-
Deletes all objects with one specific tag.
$plotter->delete('oval');
- printCanvas
-
Prints the canvas to a printer
$plotter->printCanvas('file', 'filename'); $plotter->printCanvas('printer', '-PHello');
- flushGraphics
-
This function is not used in this module but should be included as the last command before you want your graphics to appear. Allows for easy mobility between different plotters.
$plotter->flushGraphics();
- configureTag
-
Configures the items with the given tag.
$plotter->configureTag('oval', -fill => 'black');
- bindTag
-
Binds the items with the given tag.
$plotter->bindTag('oval', '<Any-Enter>' => sub {print "hello"});
- existTag
-
Returns the number of items associated with that tag
$exists = $plotter->existTag('oval');
- raiseAbove
-
Raise the objects with the first tag above the objects with the second tag.
$plotter->raiseAbove('oval', 'square');
- lowerBelow
-
Lowers the objects with the first tag below the objects with the second tag.
$plotter->lowerBelow('oval', 'square');
- drawTextVert
-
Draws text on the canvas in the given (x, y) coordinates using the current font, font size, and font Color. Returns the text item number. Adds a tag name if one is given. Draws it vertically
$plotter->drawTextVert(5, 5, "hello"); $id = $plotter->drawTextVert(5, 5, "hello", 'text');
- drawText
-
Draws text on the canvas in the given (x, y) coordinates using the current font, font size, and font Color. Returns the text item number. Adds a tag name if one is given.
$plotter->drawText(5, 5, "hello"); $id = $plotter->drawText(5, 5, "hello", 'text');
- drawTextFromLeft
-
Draws text on the canvas in the given (x, y) coordinates using the current font, font size, and font Color. Returns the text item number. Adds a tag name if one is given.
$plotter->drawTextFromLeft(5, 5, "hello"); $id = $plotter->drawTextFromLeft(5, 5, "hello", 'text');
- drawTextFromRight
-
Draws text on the canvas in the given (x, y) coordinates using the current font, font size, and font Color. Returns the text item number. Adds a tag name if one is given.
$plotter->drawTextFromRight(5, 5, "hello"); $id = $plotter->drawTextFromRight(5, 5, "hello", 'text');
- drawOval
-
Draws an oval on the canvas in the given set of (x, y) coordinates Returns the ovals item number. Adds a tag name if one is given.
$plotter->drawOval(5, 5, 10, 10); $id = $plotter->drawOval(5, 5, 10, 10, 'oval');
- drawFillOval
-
Draws an oval on the canvas in the given set of (x, y) coordinates and fills it. Returns the ovals item number. Adds a tag name if one is given.
$plotter->drawFillOval(5, 5, 10, 10); $id = $plotter->drawFillOval(5, 5, 10, 10, 'oval');
- drawLine
-
Draws a line on the canvas in the given set of (x, y) coordinates Returns the lines item number. Adds a tag name if one is given.
$plotter->drawLine(5, 5, 10, 10); $id = $plotter->drawLine(5, 5, 10, 10, 'line');
- drawSmoothLine
-
Draws a smooth line on the canvas through the given (x, y) coordinates. Gives the object the tag $tag if one is given
$plotter->drawSmoothLine(5 => 5, 10 => 10, 15 => 5, 20 => 0); $id = $plotter->drawSmoothLine(5 => 5, 10 => 10, 15 => 5, 20 => 0, $tag);
- drawBox
-
Draws a box on the canvas in the given set of (x, y) coordinates Returns the box item number. Adds a tag name if one is given.
$plotter->drawBox(5, 5, 10, 10); $id = $plotter->drawBox(5, 5, 10, 10, 'box');
AUTHOR
Casey Best (University of Victoria) with help from Tim Jenness.
COPYRIGHT
Copyright (C) 2012 Science and Technology Facilities Council. Copyright 1998-2000 Particle Physics and Astronomy Research Council. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.