Commit | Line | Data |
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 | |
31 | package SDL::Rect; |
32 | |
33 | use strict; |
084b921f |
34 | use warnings; |
35 | use Carp; |
bfd90409 |
36 | use SDL; |
37 | |
38 | sub 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 | |
56 | sub DESTROY { |
57 | SDL::FreeRect(${$_[0]}); |
58 | } |
59 | |
60 | sub x { |
61 | my $self = shift; |
62 | SDL::RectX($$self,@_); |
63 | } |
64 | |
65 | sub y { |
66 | my $self = shift; |
67 | SDL::RectY($$self,@_); |
68 | } |
69 | |
70 | sub width { |
71 | my $self = shift; |
72 | SDL::RectW($$self,@_); |
73 | } |
74 | |
75 | sub height { |
76 | my $self = shift; |
77 | SDL::RectH($$self,@_); |
78 | } |
79 | |
80 | 1; |
81 | |
82 | __END__; |
83 | |
84 | =pod |
85 | |
86 | |
87 | =head1 NAME |
88 | |
89 | SDL::Rect - a SDL perl extension |
90 | |
91 | =head1 SYNOPSIS |
92 | |
93 | $rect = new SDL::Rect ( -height => 4, -width => 40 ); |
94 | |
95 | =head1 DESCRIPTION |
96 | |
97 | C<SDL::Rect::new> creates a SDL_Rect structure which is |
98 | used for specifying regions for filling, blitting, and updating. |
99 | These objects make it easy to cut and backfill. |
100 | By default, x, y, h, w are 0. |
101 | |
102 | =head2 METHODS |
103 | |
104 | The four fields of a rectangle can be set simply |
105 | by passing a value to the applicable method. These are: |
106 | |
107 | =over 4 |
108 | |
109 | =item * |
110 | |
111 | C<SDL::Rect::x> sets and fetches the x position. |
112 | |
113 | =item * |
114 | |
115 | C<SDL::Rect::y> sets and fetches the y position. |
116 | |
117 | =item * |
118 | |
119 | C<SDL::Rect::width> sets and fetched the width. |
120 | |
121 | =item * |
122 | |
123 | C<SDL::Rect::height> sets and fetched the height. |
124 | |
125 | =back |
126 | |
127 | =head1 AUTHOR |
128 | |
129 | David J. Goehrig |
130 | |
131 | =head1 SEE ALSO |
132 | |
133 | perl(1) SDL::Surface(3) |
134 | |
135 | |
136 | =cut |
137 | |