Damien Krotkine > Curses-Toolkit-0.207 > Curses::Toolkit::Object::Coordinates

Download:
Curses-Toolkit-0.207.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

New  1
Open  2
View/Report Bugs
Module Version: 0.207   Source   Latest Release: Curses-Toolkit-0.211

NAME ^

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

VERSION ^

version 0.207

DESCRIPTION ^

Trivial class to hold 2 points.

+ and - are properly overloaded.

ATTRIBUTES ^

x1

Top left x coordinate of the object. Can be either an integer or a coderef.

y1

Top left y coordinate of the object. Can be either an integer or a coderef.

x2

Bottom right x coordinate of the object. Can be either an integer or a coderef.

y2

Bottom right y coordinate of the object. Can be either an integer or a coderef.

normalize

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.

METHODS ^

new

    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

new_zero

    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

clone

    my $c2 = $c1->clone;

Clone a coordinates object.

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

set

    $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

width

    my $width = $coord->width;

Returns the width represented by the coordinate object.

height

    my $height = $coord->height;

Returns the height represented by the coordinate object.

add

    $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

subtract

    $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

      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

    $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

grow_to

    $coord->grow_to( $coord_to_match );

Force the coordinate to be at least as big as the passed coordinate.

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

translate

    $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

translate_up

    $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

translate_down

    $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

translate_left

    $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

translate_right

    $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

contains

    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

is_inside

    my $bool = $coord->is_inside( $coord_to_check );

Return true if the coordinates is inside the given coordinates

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

is_in_widget

    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

is_in_widget_visible_shape

    my $bool = $coord->is_in_widget_visible_shape( $widget );

Return true if the coordinates is inside the visible part of a given widget

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

AUTHOR ^

Damien "dams" Krotkine

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: