Fixed test for hardware or underlying fails
[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;
bfd90409 35use SDL;
36
37sub new {
38 my $proto = shift;
39 my $class = ref($proto) || $proto;
40 my %options = @_;
41
96493475 42 verify (%options, qw/ -x -y -top -left -width -height -w -h / ) if $SDL::DEBUG;
bfd90409 43
96493475 44 my $x = $options{-x} || $options{-left} || 0;
45 my $y = $options{-y} || $options{-top} || 0;
bfd90409 46 my $w = $options{-width} || $options{-w} || 0;
47 my $h = $options{-height} || $options{-h} || 0;
48
49 my $self = \SDL::NewRect($x,$y,$w,$h);
69e6e191 50 unless ($$self) {
51 require Carp;
52 Carp::croak SDL::GetError();
53 }
bfd90409 54 bless $self,$class;
55 return $self;
56}
57
58sub DESTROY {
59 SDL::FreeRect(${$_[0]});
60}
61
96493475 62# TODO: mangle with the symbol table to create an alias
63# to sub x. We could call x from inside the sub but that
64# would be another call and rects are a time-critical object.
65sub left {
66 my $self = shift;
67 SDL::RectX($$self,@_);
68}
69
bfd90409 70sub x {
71 my $self = shift;
72 SDL::RectX($$self,@_);
73}
74
69e6e191 75### TODO: see 'left' above (this is an 'alias' to sub y)
96493475 76sub top {
77 my $self = shift;
78 SDL::RectY($$self,@_);
79}
80
bfd90409 81sub y {
82 my $self = shift;
83 SDL::RectY($$self,@_);
84}
85
69e6e191 86### TODO: see 'left' above (this is an 'alias' to sub width)
96493475 87sub w {
88 my $self = shift;
89 SDL::RectW($$self,@_);
90}
91
bfd90409 92sub width {
93 my $self = shift;
94 SDL::RectW($$self,@_);
95}
96
69e6e191 97### TODO: see 'left' above (this is an 'alias' to sub height)
96493475 98sub h {
99 my $self = shift;
100 SDL::RectH($$self,@_);
101}
102
bfd90409 103sub height {
104 my $self = shift;
105 SDL::RectH($$self,@_);
106}
107
1081;
109
110__END__;
111
bfd90409 112=head1 NAME
113
23dbccd4 114SDL::Rect - raw object for storing rectangular coordinates
bfd90409 115
116=head1 SYNOPSIS
117
23dbccd4 118 my $rect = SDL::Rect->new( -height => 4, -width => 40 );
119
120 $rect->x(12); # same as $rect->left(12)
121 $rect->y(9); # same as $rect->top(9)
bfd90409 122
123=head1 DESCRIPTION
124
125C<SDL::Rect::new> creates a SDL_Rect structure which is
23dbccd4 126used for specifying regions of pixels for filling, blitting, and updating.
bfd90409 127These objects make it easy to cut and backfill.
23dbccd4 128
129By default, x, y, height and width are all set to 0.
bfd90409 130
131=head2 METHODS
132
133The four fields of a rectangle can be set simply
134by passing a value to the applicable method. These are:
135
23dbccd4 136=head3 x
137
138=head3 left
139
140sets and fetches the x (lefmost) position of the rectangle.
bfd90409 141
23dbccd4 142=head3 y
bfd90409 143
23dbccd4 144=head3 top
bfd90409 145
23dbccd4 146sets and fetches the y (topmost) position.
bfd90409 147
23dbccd4 148=head3 w
bfd90409 149
23dbccd4 150=head3 width
bfd90409 151
08b9a27f 152sets and fetches the width of the rectangle (in pixels).
bfd90409 153
23dbccd4 154=head3 h
bfd90409 155
23dbccd4 156=head3 height
157
08b9a27f 158sets and fetches the height of the rectangle (in pixels).
bfd90409 159
160=head1 AUTHOR
161
162David J. Goehrig
163
164=head1 SEE ALSO
165
166perl(1) SDL::Surface(3)