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;
}

=item setBackground

Sets the background color

    $plotter->setBackground('black');

=cut

sub setBackground {
    my $self = shift;
    my $color = shift;
    $self->getCanvas()->configure(-background => $color);
}

=item setForeground

Sets the foreground color.

    $plotter->setForeground('black');

=cut

sub setForeground {
    my $self = shift;
    my $color = shift;
    $self->getCanvas()->configure(-foreground => $color);
}

=item font

Sets and returns the font currently being used.

    $f = $plotter->font();
    $plotter->font($f);

=cut

sub font {
    my $self = shift;
    if (@_) {
        $self->{FONT} = shift;
    }
    return $self->{FONT};
}

=item fontColor

Sets and returns the font color.

    $plotter->fontColor('black');

=cut

sub fontColor {
    my $self = shift;
    if (@_) {
        $self->{FONT_COLOR} = shift;
    }
    return $self->{FONT_COLOR};
}

=item fontSize

Sets and returns the font size.

    $plotter->fontSize(5);
    $size = $plotter->fontSize();

=cut

sub fontSize {
    my $self = shift;



( run in 0.634 second using v1.01-cache-2.11-cpan-f4a522933cf )