Commit | Line | Data |
8fde61e3 |
1 | # |
2 | # Rect.pm |
3 | # |
4 | # A package for manipulating SDL_Rect * |
5 | # |
6 | # Copyright (C) 2003 David J. Goehrig |
7 | |
8 | package SDL::Rect; |
9 | use strict; |
10 | use SDL; |
11 | |
12 | sub new { |
13 | my $proto = shift; |
14 | my $class = ref($proto) || $proto; |
15 | my %options = @_; |
16 | |
17 | verify (%options, qw/ -x -y -width -height -w -h / ) if $SDL::DEBUG; |
18 | |
19 | my $x = $options{-x} || 0; |
20 | my $y = $options{-y} || 0; |
21 | my $w = $options{-width} || $options{-w} || 0; |
22 | my $h = $options{-height} || $options{-h} || 0; |
23 | |
24 | my $self = \SDL::NewRect($x,$y,$w,$h); |
25 | bless $self,$class; |
26 | return $self; |
27 | } |
28 | |
29 | sub DESTROY { |
30 | SDL::FreeRect(${$_[0]}); |
31 | } |
32 | |
33 | sub x { |
34 | my $self = shift; |
35 | SDL::RectX($$self,@_); |
36 | } |
37 | |
38 | sub y { |
39 | my $self = shift; |
40 | SDL::RectY($$self,@_); |
41 | } |
42 | |
43 | sub width { |
44 | my $self = shift; |
45 | SDL::RectW($$self,@_); |
46 | } |
47 | |
48 | sub height { |
49 | my $self = shift; |
50 | SDL::RectH($$self,@_); |
51 | } |
52 | |
53 | 1; |
54 | |
55 | __END__; |
56 | |
57 | =pod |
58 | |
59 | |
60 | =head1 NAME |
61 | |
62 | SDL::Rect - a SDL perl extension |
63 | |
64 | =head1 SYNOPSIS |
65 | |
66 | $rect = new SDL::Rect ( -height => 4, -width => 40 ); |
67 | |
68 | =head1 DESCRIPTION |
69 | |
70 | C<SDL::Rect::new> creates a SDL_Rect structure which is |
71 | used for specifying regions for filling, blitting, and updating. |
72 | These objects make it easy to cut and backfill. |
73 | By default, x, y, h, w are 0. |
74 | |
75 | =head2 METHODS |
76 | |
77 | The four fields of a rectangle can be set simply |
78 | by passing a value to the applicable method. These are: |
79 | |
80 | =over 4 |
81 | |
82 | =item * |
83 | |
84 | C<SDL::Rect::x> sets and fetches the x position. |
85 | |
86 | =item * |
87 | |
88 | C<SDL::Rect::y> sets and fetches the y position. |
89 | |
90 | =item * |
91 | |
92 | C<SDL::Rect::width> sets and fetched the width. |
93 | |
94 | =item * |
95 | |
96 | C<SDL::Rect::height> sets and fetched the height. |
97 | |
98 | =back |
99 | |
100 | =head1 AUTHOR |
101 | |
102 | David J. Goehrig |
103 | |
104 | =head1 SEE ALSO |
105 | |
106 | perl(1) SDL::Surface(3) |
107 | |
108 | |
109 | =cut |
110 | |