NAME

Curses::Toolkit::Object::Coordinates - simple coordinates class

VERSION

version 0.092920

DESCRIPTION

Trivial class to hold 2 points

+ and - are properly overloaded

CONSTRUCTOR

new

input  : x1 : top left x
         y1 : top left y
         x2 : right bottom x
         y2 : right bottom y
         [ normalize ] : optional, if false, won't normalize the coords (see below)
  OR
input  : x1 : top left x
         y1 : top left y
         width : width
         height : heigth
         [ normalize ] : optional, if false, won't normalize the coords (see below)
  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, if false, won't normalize the coords (see below)
  OR
input  : a Curses::Toolkit::Object::Coordinates object

output : a Curses::Toolkit::Object::Coordinates object

Normalize option : if set to false, the coordinate will be untouched. If set to true (default), the coordinate will make sure x1 < x2 and y1 < y2, and that they are all integers, swapping or rounding them if necessary.

new_zero

Creates a new coordinates with all zero

input  : none
output : a Curses::Toolkit::Object::Coordinates object

METHODS

clone

clone an coordinates object

input  : none
output : a Curses::Toolkit::Object::Coordinates object

set

set attributes of the coordinate

input  : one or more of x1, x2, y1, y2, width, height
output : the coordinate object

width

returns the width represented by the coordinates

height

returns the height represented by the coordinates

x1, x2, y1, y2

These are helpers to retrieve the coordinates values

add

Add to the coordinate.

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

substract

Substract from the coordinate (also overloads '-').

If the argument is a constant, it's substracted from all the components of the coordinate. If it's a Curses::Toolkit::Object::Coordinates, it's substracted side by side If it's a hashref, it's substracted 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

restrict_to

Force the coordinate to be inside the passed coordinate.

input  : a Curses::Toolkit::Object::Coordinates object
output : the object

translate

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

translate_up

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

translate_down

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

translate_left

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

translate_right

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

contains

Return true if the coordinates contains the given coordinates

my $boolean = $self->contains( $coord )

input  : a Curses::Toolkit::Object::Coordinates object : the coordinates
output : true or false

is_inside

Return true if the coordinates is inside the given coordinates

my $boolean = $self->is_inside( $coord )

input  : a Curses::Toolkit::Object::Coordinates object : the coordinates
output : true or false

is_in_widget

Return true if the coordinates is in side the give widget

input  : Curses::Toolkit::Widget : the widget
output : true or false

AUTHOR

Damien "dams" Krotkine

COPYRIGHT AND LICENSE

This software is copyright (c) 2008 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.