improved documentation
[sdlgit/SDL_perl.git] / lib / SDL / Rect.pm
CommitLineData
bfd90409 1#!/usr/bin/env perl
2#
3# Rect.pm
4#
5# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6#
7# ------------------------------------------------------------------------------
8#
9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; either
12# version 2.1 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# Lesser General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public
20# License along with this library; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22#
23# ------------------------------------------------------------------------------
24#
25# Please feel free to send questions, suggestions or improvements to:
26#
27# David J. Goehrig
28# dgoehrig@cpan.org
29#
30
31package SDL::Rect;
32
33use strict;
084b921f 34use warnings;
35use Carp;
bfd90409 36use SDL;
37
38sub new {
39 my $proto = shift;
40 my $class = ref($proto) || $proto;
41 my %options = @_;
42
43 verify (%options, qw/ -x -y -width -height -w -h / ) if $SDL::DEBUG;
44
45 my $x = $options{-x} || 0;
46 my $y = $options{-y} || 0;
47 my $w = $options{-width} || $options{-w} || 0;
48 my $h = $options{-height} || $options{-h} || 0;
49
50 my $self = \SDL::NewRect($x,$y,$w,$h);
cc6d0c7c 51 croak SDL::GetError() unless $$self;
bfd90409 52 bless $self,$class;
53 return $self;
54}
55
56sub DESTROY {
57 SDL::FreeRect(${$_[0]});
58}
59
60sub x {
61 my $self = shift;
62 SDL::RectX($$self,@_);
63}
64
65sub y {
66 my $self = shift;
67 SDL::RectY($$self,@_);
68}
69
70sub width {
71 my $self = shift;
72 SDL::RectW($$self,@_);
73}
74
75sub height {
76 my $self = shift;
77 SDL::RectH($$self,@_);
78}
79
801;
81
82__END__;
83
bfd90409 84=head1 NAME
85
23dbccd4 86SDL::Rect - raw object for storing rectangular coordinates
bfd90409 87
88=head1 SYNOPSIS
89
23dbccd4 90 my $rect = SDL::Rect->new( -height => 4, -width => 40 );
91
92 $rect->x(12); # same as $rect->left(12)
93 $rect->y(9); # same as $rect->top(9)
bfd90409 94
95=head1 DESCRIPTION
96
97C<SDL::Rect::new> creates a SDL_Rect structure which is
23dbccd4 98used for specifying regions of pixels for filling, blitting, and updating.
bfd90409 99These objects make it easy to cut and backfill.
23dbccd4 100
101By default, x, y, height and width are all set to 0.
bfd90409 102
103=head2 METHODS
104
105The four fields of a rectangle can be set simply
106by passing a value to the applicable method. These are:
107
23dbccd4 108=head3 x
109
110=head3 left
111
112sets and fetches the x (lefmost) position of the rectangle.
bfd90409 113
23dbccd4 114=head3 y
bfd90409 115
23dbccd4 116=head3 top
bfd90409 117
23dbccd4 118sets and fetches the y (topmost) position.
bfd90409 119
23dbccd4 120=head3 w
bfd90409 121
23dbccd4 122=head3 width
bfd90409 123
23dbccd4 124sets and fetched the width of the rectangle (in pixels).
bfd90409 125
23dbccd4 126=head3 h
bfd90409 127
23dbccd4 128=head3 height
129
130sets and fetched the height of the rectangle (in pixels).
bfd90409 131
132=back
133
134=head1 AUTHOR
135
136David J. Goehrig
137
138=head1 SEE ALSO
139
140perl(1) SDL::Surface(3)