line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# App.pm |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package SDLx::App; |
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
2486
|
use strict; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
132
|
|
9
|
5
|
|
|
5
|
|
18
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
94
|
|
10
|
5
|
|
|
5
|
|
16
|
use Carp; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
193
|
|
11
|
5
|
|
|
5
|
|
16
|
use SDL; |
|
5
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
224
|
|
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
651
|
use SDL::Rect; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
578
|
|
14
|
5
|
|
|
5
|
|
731
|
use SDL::Video; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
1308
|
|
15
|
5
|
|
|
5
|
|
923
|
use SDL::Event; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
2403
|
|
16
|
5
|
|
|
5
|
|
949
|
use SDL::Events; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
7464
|
|
17
|
5
|
|
|
5
|
|
701
|
use SDL::Surface; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
748
|
|
18
|
5
|
|
|
5
|
|
24
|
use SDL::PixelFormat; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
996
|
|
19
|
5
|
|
|
5
|
|
1026
|
use SDL::VideoInfo; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
5147
|
|
20
|
5
|
|
|
5
|
|
1705
|
use SDLx::Surface; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
187
|
|
21
|
5
|
|
|
5
|
|
2052
|
use Data::Dumper; |
|
5
|
|
|
|
|
18826
|
|
|
5
|
|
|
|
|
243
|
|
22
|
5
|
|
|
5
|
|
26
|
use Scalar::Util 'refaddr'; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
168
|
|
23
|
5
|
|
|
5
|
|
20
|
use base qw/SDLx::Surface SDLx::Controller/; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
1677
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $screen_w; |
26
|
|
|
|
|
|
|
my $screen_h; |
27
|
|
|
|
|
|
|
my $screen_d; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
3
|
|
|
3
|
0
|
15519
|
my $proto = shift; |
31
|
3
|
|
33
|
|
|
22
|
my $class = ref($proto) || $proto; |
32
|
3
|
|
|
|
|
12
|
my %options = @_; |
33
|
|
|
|
|
|
|
|
34
|
3
|
0
|
33
|
|
|
15
|
unless($screen_w && $screen_h && $screen_d) { |
|
|
|
33
|
|
|
|
|
35
|
3
|
|
|
|
|
37
|
my $video_info = SDL::Video::get_video_info(); |
36
|
3
|
100
|
|
|
|
21
|
if($video_info) { |
37
|
2
|
|
|
|
|
8
|
$screen_w = $video_info->current_w; |
38
|
2
|
|
|
|
|
5
|
$screen_h = $video_info->current_h; |
39
|
2
|
|
|
|
|
25
|
$screen_d = $video_info->vfmt->BitsPerPixel; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# SDL_INIT_VIDEO() is 0, so check defined instead of truth. |
44
|
3
|
50
|
|
|
|
14
|
unless ( exists( $options{noinit} ) ) # we shouldn't do init always |
45
|
|
|
|
|
|
|
{ |
46
|
3
|
50
|
|
|
|
11
|
my $init = |
47
|
|
|
|
|
|
|
defined $options{init} |
48
|
|
|
|
|
|
|
? $options{init} |
49
|
|
|
|
|
|
|
: SDL::SDL_INIT_EVERYTHING; |
50
|
|
|
|
|
|
|
|
51
|
3
|
|
|
|
|
117
|
SDL::init($init); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
66
|
|
|
18
|
my $t = $options{title} || $options{t} || $0; |
55
|
3
|
|
33
|
|
|
31
|
my $it = $options{icon_title} || $options{it} || $t; |
56
|
3
|
|
50
|
|
|
20
|
my $ic = $options{icon} || $options{i} || ""; |
57
|
3
|
|
100
|
|
|
17
|
my $w = $options{width} || $options{w} || 800; |
58
|
3
|
|
100
|
|
|
13
|
my $h = $options{height} || $options{h} || 600; |
59
|
3
|
|
50
|
|
|
18
|
my $d = $options{depth} || $options{d} || 16; |
60
|
3
|
|
50
|
|
|
20
|
my $f = $options{flags} || $options{f} || SDL::Video::SDL_ANYFORMAT; |
61
|
3
|
|
50
|
|
|
19
|
my $r = $options{red_size} || $options{r} || 5; |
62
|
3
|
|
50
|
|
|
21
|
my $g = $options{green_size} || $options{g} || 5; |
63
|
3
|
|
50
|
|
|
30
|
my $b = $options{blue_size} || $options{b} || 5; |
64
|
3
|
|
50
|
|
|
19
|
my $a = $options{alpha_size} || $options{a} || 0; |
65
|
3
|
|
50
|
|
|
17
|
my $ras = $options{red_accum_size} || $options{ras} || 0; |
66
|
3
|
|
50
|
|
|
16
|
my $gas = $options{green_accum_size} || $options{gas} || 0; |
67
|
3
|
|
50
|
|
|
18
|
my $bas = $options{blue_accum_size} || $options{bas} || 0; |
68
|
3
|
|
50
|
|
|
25
|
my $aas = $options{alpha_accum_size} || $options{aas} || 0; |
69
|
3
|
|
50
|
|
|
22
|
my $db = $options{double_buffer} || $options{db} || 0; |
70
|
|
|
|
|
|
|
|
71
|
3
|
|
50
|
|
|
22
|
my $bs = $options{buffer_size} || $options{bs} || 0; |
72
|
3
|
|
50
|
|
|
20
|
my $st = $options{stencil_size} || $options{st} || 0; |
73
|
3
|
|
50
|
|
|
14
|
my $async = $options{asyncblit} || 0; |
74
|
|
|
|
|
|
|
|
75
|
3
|
50
|
33
|
|
|
13
|
$f |= SDL::Video::SDL_OPENGL if ( $options{gl} || $options{opengl} ); |
76
|
3
|
50
|
33
|
|
|
12
|
$f |= SDL::Video::SDL_FULLSCREEN |
77
|
|
|
|
|
|
|
if ( $options{fullscreen} || $options{full} ); |
78
|
3
|
50
|
|
|
|
7
|
$f |= SDL::Video::SDL_RESIZABLE if ( $options{resizeable} ); |
79
|
3
|
50
|
|
|
|
7
|
$f |= SDL::Video::SDL_DOUBLEBUF if ($db); |
80
|
3
|
50
|
|
|
|
7
|
$f |= SDL::Video::SDL_ASYNCBLIT if ($async); |
81
|
|
|
|
|
|
|
|
82
|
3
|
50
|
|
|
|
16
|
if ( $f & SDL::Video::SDL_OPENGL ) { |
83
|
0
|
|
|
|
|
0
|
$SDLx::App::USING_OPENGL = 1; |
84
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_RED_SIZE(), $r ) |
85
|
|
|
|
|
|
|
if ($r); |
86
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_GREEN_SIZE(), $g ) |
87
|
|
|
|
|
|
|
if ($g); |
88
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_BLUE_SIZE(), $b ) |
89
|
|
|
|
|
|
|
if ($b); |
90
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_ALPHA_SIZE(), $a ) |
91
|
|
|
|
|
|
|
if ($a); |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( |
94
|
|
|
|
|
|
|
SDL::Constants::SDL_GL_RED_ACCUM_SIZE(), |
95
|
|
|
|
|
|
|
$ras |
96
|
|
|
|
|
|
|
) if ($ras); |
97
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( |
98
|
|
|
|
|
|
|
SDL::Constants::SDL_GL_GREEN_ACCUM_SIZE(), |
99
|
|
|
|
|
|
|
$gas |
100
|
|
|
|
|
|
|
) if ($gas); |
101
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( |
102
|
|
|
|
|
|
|
SDL::Constants::SDL_GL_BLUE_ACCUM_SIZE(), |
103
|
|
|
|
|
|
|
$bas |
104
|
|
|
|
|
|
|
) if ($bas); |
105
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( |
106
|
|
|
|
|
|
|
SDL::Constants::SDL_GL_ALPHA_ACCUM_SIZE(), |
107
|
|
|
|
|
|
|
$aas |
108
|
|
|
|
|
|
|
) if ($aas); |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( |
111
|
|
|
|
|
|
|
SDL::Constants::SDL_GL_DOUBLEBUFFER(), |
112
|
|
|
|
|
|
|
$db |
113
|
|
|
|
|
|
|
) if ($db); |
114
|
0
|
0
|
|
|
|
0
|
SDL::Video::GL_set_attribute( |
115
|
|
|
|
|
|
|
SDL::Constants::SDL_GL_BUFFER_SIZE(), |
116
|
|
|
|
|
|
|
$bs |
117
|
|
|
|
|
|
|
) if ($bs); |
118
|
0
|
|
|
|
|
0
|
SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_DEPTH_SIZE(), $d ); |
119
|
|
|
|
|
|
|
} else { |
120
|
3
|
|
|
|
|
3
|
$SDLx::App::USING_OPENGL = 0; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
3
|
50
|
|
|
|
2187
|
my $surface = SDL::Video::set_video_mode( $w, $h, $d, $f ) |
124
|
|
|
|
|
|
|
or Carp::confess SDL::get_error(); |
125
|
3
|
|
|
|
|
11
|
$options{surface} = $surface; |
126
|
|
|
|
|
|
|
|
127
|
3
|
|
|
|
|
31
|
my $self = SDLx::Surface->new(%options); |
128
|
|
|
|
|
|
|
|
129
|
3
|
50
|
33
|
|
|
15
|
if ( $ic and -e $ic ) { |
130
|
0
|
|
|
|
|
0
|
my $icon = SDL::Video::load_BMP($ic); |
131
|
0
|
|
|
|
|
0
|
SDL::Video::wm_set_icon($icon); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
3
|
|
|
|
|
32
|
SDL::Video::wm_set_caption( $t, $it ); |
135
|
3
|
|
|
|
|
21
|
$self = $self->SDLx::Controller::new(%options); |
136
|
3
|
|
|
|
|
8
|
bless $self, $class; |
137
|
|
|
|
|
|
|
|
138
|
3
|
|
|
|
|
13
|
return $self; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub resize { |
142
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $w, $h ) = @_; |
143
|
0
|
|
|
|
|
0
|
my $flags = $self->flags; |
144
|
0
|
0
|
|
|
|
0
|
if ( $flags & SDL::Video::SDL_RESIZABLE ) { |
145
|
0
|
|
|
|
|
0
|
my $bpp = $self->format->BitsPerPixel; |
146
|
0
|
0
|
|
|
|
0
|
$self = SDL::Video::set_video_mode( $w, $h, $bpp, $flags ) |
147
|
|
|
|
|
|
|
or die "SDL cannot set video:" . SDL::get_error; |
148
|
|
|
|
|
|
|
} else { |
149
|
0
|
|
|
|
|
0
|
die "Application surface not resizable"; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub title { |
154
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
155
|
0
|
|
|
|
|
0
|
my ( $title, $icon ); |
156
|
0
|
0
|
|
|
|
0
|
if (@_) { |
157
|
0
|
|
|
|
|
0
|
$title = shift; |
158
|
0
|
|
0
|
|
|
0
|
$icon = shift || $title; |
159
|
0
|
|
|
|
|
0
|
SDL::Video::wm_set_caption( $title, $icon ); |
160
|
|
|
|
|
|
|
} |
161
|
0
|
|
|
|
|
0
|
return SDL::Video::wm_get_caption(); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub delay { |
165
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
166
|
0
|
|
|
|
|
0
|
my $delay = shift; |
167
|
0
|
|
|
|
|
0
|
SDL::delay($delay); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub ticks { |
171
|
0
|
|
|
0
|
0
|
0
|
return SDL::get_ticks(); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub error { |
175
|
0
|
|
|
0
|
0
|
0
|
return SDL::get_error(); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub warp { |
179
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
180
|
0
|
|
|
|
|
0
|
SDL::Mouse::warp_mouse(@_); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub fullscreen { |
184
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
185
|
0
|
|
|
|
|
0
|
SDL::Video::wm_toggle_fullscreen($self); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub iconify { |
189
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
190
|
0
|
|
|
|
|
0
|
SDL::Video::wm_iconify_window(); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub grab_input { |
194
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $mode ) = @_; |
195
|
0
|
|
|
|
|
0
|
SDL::Video::wm_grab_input($mode); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub sync { |
199
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
200
|
0
|
0
|
|
|
|
0
|
if ($SDLx::App::USING_OPENGL) { |
201
|
0
|
|
|
|
|
0
|
SDL::Video::GL_swap_buffers(); |
202
|
|
|
|
|
|
|
} else { |
203
|
0
|
|
|
|
|
0
|
$self->flip(); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub attribute { |
208
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $mode, $value ) = @_; |
209
|
0
|
0
|
|
|
|
0
|
return undef unless ($SDLx::App::USING_OPENGL); |
210
|
0
|
0
|
|
|
|
0
|
if ( defined $value ) { |
211
|
0
|
|
|
|
|
0
|
SDL::Video::GL_set_attribute( $mode, $value ); |
212
|
|
|
|
|
|
|
} |
213
|
0
|
|
|
|
|
0
|
my $returns = SDL::Video::GL_get_attribute($mode); |
214
|
0
|
0
|
|
|
|
0
|
Carp::confess "SDLx::App::attribute failed to get GL attribute" |
215
|
|
|
|
|
|
|
if ( $$returns[0] < 0 ); |
216
|
0
|
|
|
|
|
0
|
$$returns[1]; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
my %_stash; |
222
|
|
|
|
|
|
|
sub stash :lvalue{ |
223
|
0
|
|
|
0
|
0
|
0
|
my $ref = refaddr($_[0]); |
224
|
0
|
0
|
|
|
|
0
|
$_stash{ $ref } = {} unless $_stash{ $ref }; |
225
|
0
|
|
|
|
|
0
|
return $_stash{ $ref } |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub DESTROY { |
229
|
3
|
0
|
33
|
3
|
|
2215716
|
if($screen_w && $screen_h && $screen_d) { |
|
|
|
33
|
|
|
|
|
230
|
0
|
|
|
|
|
|
SDL::Video::set_video_mode( $screen_w, $screen_h, $screen_d, SDL_ANYFORMAT ); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
1; |