App-SourcePlot

 view release on metacpan or  search on metacpan

lib/App/SourcePlot/Plotter/Tk.pm  view on Meta::CPAN

package App::SourcePlot::Plotter::Tk;

=head1 NAME

App::SourcePlot::Plotter::Tk - Create a Tk canvas with easy-to-use method names

=head1 DESCRIPTION

This class provides methods to use a GUI canvas with ease.  The
commands will be generalized to ensure easy transfer between graphing
packages.

=cut

use 5.004;
use Carp;
use strict;

use Tk;

our $VERSION = '1.32';

=head1 METHODS

=head2 Constructor

=over 4

=item 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);

=cut

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;

    my $screen = shift;
    my $width = shift;
    my $height = shift;

    my $ET = bless {
        FONT => '-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
        FONT_COLOR => 'Black',
        DRAW_COLOR => 'Black',
        PEN_WIDTH => 1,
    }, $class;

    $ET->{CANVAS} = $screen->Canvas(
        -background => "LightCyan3",
        -relief => 'raised',
        -width => $width,
        -height => $height,
        -cursor => 'top_left_arrow',
    );
    $ET->{CANVAS}->grid(-row => 0, -column => 0, -sticky => 'nsew');

    $ET->setWorldSize(0, 0, 1, 1);
    $ET->usingWorld(0);

    return $ET;
}

=back

=head2 Canvas functions

=over 4

=item 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();

=cut

sub getCanvas {
    my $self = shift;
    return $self->{CANVAS};
}

=back

=head2 Setup tools

=over 4

=item width

Returns the width of a canvas.

    $w = $plotter->width();

=cut

sub width {
    my $self = shift;
    return $self->getCanvas->width;
}

=item height

Returns the width of a canvas.

    $w = $plotter->height();

=cut

sub height {
    my $self = shift;
    return $self->getCanvas->height;
}



( run in 1.845 second using v1.01-cache-2.11-cpan-97f6503c9c8 )