Curses::Toolkit::Object::Coordinates - simple coordinates class
version 0.211
Trivial class to hold 2 points.
+ and - are properly overloaded.
Top left x coordinate of the object. Can be either an integer or a coderef.
Top left y coordinate of the object. Can be either an integer or a coderef.
Bottom right x coordinate of the object. Can be either an integer or a coderef.
Bottom right y coordinate of the object. Can be either an integer or a coderef.
A boolean to swap coordinates to make sure x1 < x2 and y1 < y2 if set to true (default). If set to false, the coordinates will be untouched.
my $coord = CTO::Coordinates->new( @attributes ); my $coord = CTO::Coordinates->new( $coord_to_clone ); my $coord = CTO::Coordinates->new( x1=>$x1, y1=>$y1, width=>$w, height=>$h );
Constructor for the class. Acceps various kind of attributes.
input : x1 : top left x y1 : top left y x2 : right bottom x y2 : right bottom y [ normalize ] : optional OR input : x1 : top left x y1 : top left y width : width height : height [ normalize ] : optional OR input : x1 : sub { ... } # returns top left x y1 : sub { ... } # returns top left y x2 : sub { ... } # returns right bottom x y2 : sub { ... } # returns right bottom y [ normalize ] : optional OR input : a Curses::Toolkit::Object::Coordinates object output : a Curses::Toolkit::Object::Coordinates object
my $coord = CTO::Coordinates->new_zero;
Creates a new coordinates with all individual coords set to zero.
input : none output : a Curses::Toolkit::Object::Coordinates object
my $c2 = $c1->clone;
Clone a coordinates object.
$coord->set( x1=>$x1, y1=>$y1, x2=>$x2, y2=>$y2, normalize => 1 );
Set attributes of the coordinate object.
input : one or more of x1, x2, y1, y2 output : the coordinate object
my $width = $coord->width;
Returns the width represented by the coordinate object.
my $height = $coord->height;
Returns the height represented by the coordinate object.
$coord->add( $const ); $coord->add( $coord_to_add ); $coord->add( { x1=>$x1, y1=>$y1, x2=>$x2, y2=>$y2 } );
Add to the coordinate attributes of the object.
If the argument is a constant, it's added to all the components of the coordinate. If it's a Curses::Toolkit::Object::Coordinates, it's added side by side If it's a hashref, it's added side by side
input : a CONSTANT OR input : a Curses::Toolkit::Object::Coordinates OR input : a HASHREF of 'x1', 'x2', 'y1', 'y2' output : the Curses::Toolkit::Object::Coordinates object
$coord->subtract( $const ); $coord->subtract( $coord_to_add ); $coord->subtract( { x1=>$x1, y1=>$y1, x2=>$x2, y2=>$y2 } );
Substract from the coordinate (also overloads '-').
If the argument is a constant, it's subtracted from all the components of the coordinate. If it's a Curses::Toolkit::Object::Coordinates, it's subtracted side by side If it's a hashref, it's subtracted side by side
$coord->restrict_to( $coord_to_fit_into );
Force the coordinate to be inside the passed coordinate.
input : a Curses::Toolkit::Object::Coordinates object output : the object
$coord->grow_to( $coord_to_match );
Force the coordinate to be at least as big as the passed coordinate.
$coord->translate( x=>$x, y=>$y );
Given a X value and a Y value, translates the coordinate accordingly
input : x : value to translate the coord horizontally y : value to translate the coord vertically output : the Curses::Toolkit::Object::Coordinates object
$coord->translate_up( $offset );
Given a value, translates the coordinate up (value sign is ignored)
input : value to translate the coord up output : the Curses::Toolkit::Object::Coordinates object
$coord->translate_down( $offset );
Given a value, translates the coordinate down (value sign is ignored)
input : value to translate the coord down output : the Curses::Toolkit::Object::Coordinates object
$coord->translate_left( $offset );
Given a value, translates the coordinate left (value sign is ignored)
input : value to translate the coord left output : the Curses::Toolkit::Object::Coordinates object
$coord->translate_right( $offset );
Given a value, translates the coordinate right (value sign is ignored)
input : value to translate the coord right output : the Curses::Toolkit::Object::Coordinates object
my $bool = $coord->contains( $coord_to_check );
Return true if the coordinates contains the given coordinates
input : a Curses::Toolkit::Object::Coordinates object : the coordinates output : true or false
my $bool = $coord->is_inside( $coord_to_check );
Return true if the coordinates is inside the given coordinates
my $bool = $coord->is_in_widget( $widget );
Return true if the coordinates is inside the given widget
input : Curses::Toolkit::Widget : the widget output : true or false
my $bool = $coord->is_in_widget_visible_shape( $widget );
Return true if the coordinates is inside the visible part of a given widget
Damien "dams" Krotkine
This software is copyright (c) 2011 by Damien "dams" Krotkine.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Curses::Toolkit, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Curses::Toolkit
CPAN shell
perl -MCPAN -e shell install Curses::Toolkit
For more information on module installation, please visit the detailed CPAN module installation guide.