| 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
|
|
7125
|
use strict; |
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
216
|
|
|
9
|
5
|
|
|
5
|
|
31
|
use warnings; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
168
|
|
|
10
|
5
|
|
|
5
|
|
28
|
use Carp; |
|
|
5
|
|
|
|
|
84
|
|
|
|
5
|
|
|
|
|
335
|
|
|
11
|
5
|
|
|
5
|
|
27
|
use SDL; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
423
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
1440
|
use SDL::Rect; |
|
|
5
|
|
|
|
|
15
|
|
|
|
5
|
|
|
|
|
1370
|
|
|
14
|
5
|
|
|
5
|
|
1606
|
use SDL::Video; |
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
2699
|
|
|
15
|
5
|
|
|
5
|
|
2466
|
use SDL::Event; |
|
|
5
|
|
|
|
|
16
|
|
|
|
5
|
|
|
|
|
4717
|
|
|
16
|
5
|
|
|
5
|
|
2584
|
use SDL::Events; |
|
|
5
|
|
|
|
|
22
|
|
|
|
5
|
|
|
|
|
18299
|
|
|
17
|
5
|
|
|
5
|
|
1346
|
use SDL::Surface; |
|
|
5
|
|
|
|
|
15
|
|
|
|
5
|
|
|
|
|
1910
|
|
|
18
|
5
|
|
|
5
|
|
36
|
use SDL::PixelFormat; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
2089
|
|
|
19
|
5
|
|
|
5
|
|
2833
|
use SDL::VideoInfo; |
|
|
5
|
|
|
|
|
15
|
|
|
|
5
|
|
|
|
|
2098
|
|
|
20
|
5
|
|
|
5
|
|
3470
|
use SDLx::Surface; |
|
|
5
|
|
|
|
|
22
|
|
|
|
5
|
|
|
|
|
283
|
|
|
21
|
5
|
|
|
5
|
|
8046
|
use Data::Dumper; |
|
|
5
|
|
|
|
|
52775
|
|
|
|
5
|
|
|
|
|
426
|
|
|
22
|
5
|
|
|
5
|
|
49
|
use Scalar::Util 'refaddr'; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
319
|
|
|
23
|
5
|
|
|
5
|
|
32
|
use base qw/SDLx::Surface SDLx::Controller/; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
3286
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $screen_w; |
|
26
|
|
|
|
|
|
|
my $screen_h; |
|
27
|
|
|
|
|
|
|
my $screen_d; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
|
30
|
3
|
|
|
3
|
0
|
76488
|
my $proto = shift; |
|
31
|
3
|
|
33
|
|
|
32
|
my $class = ref($proto) || $proto; |
|
32
|
3
|
|
|
|
|
20
|
my %options = @_; |
|
33
|
|
|
|
|
|
|
|
|
34
|
3
|
0
|
33
|
|
|
22
|
unless($screen_w && $screen_h && $screen_d) { |
|
|
|
|
33
|
|
|
|
|
|
35
|
3
|
|
|
|
|
45
|
my $video_info = SDL::Video::get_video_info(); |
|
36
|
3
|
100
|
|
|
|
38
|
if($video_info) { |
|
37
|
2
|
|
|
|
|
14
|
$screen_w = $video_info->current_w; |
|
38
|
2
|
|
|
|
|
9
|
$screen_h = $video_info->current_h; |
|
39
|
2
|
|
|
|
|
44
|
$screen_d = $video_info->vfmt->BitsPerPixel; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# SDL_INIT_VIDEO() is 0, so check defined instead of truth. |
|
44
|
3
|
50
|
|
|
|
26
|
unless ( exists( $options{noinit} ) ) # we shouldn't do init always |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
3
|
50
|
|
|
|
13
|
my $init = |
|
47
|
|
|
|
|
|
|
defined $options{init} |
|
48
|
|
|
|
|
|
|
? $options{init} |
|
49
|
|
|
|
|
|
|
: SDL::SDL_INIT_EVERYTHING; |
|
50
|
|
|
|
|
|
|
|
|
51
|
3
|
|
|
|
|
151
|
SDL::init($init); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
3
|
|
66
|
|
|
34
|
my $t = $options{title} || $options{t} || $0; |
|
55
|
3
|
|
33
|
|
|
40
|
my $it = $options{icon_title} || $options{it} || $t; |
|
56
|
3
|
|
50
|
|
|
34
|
my $ic = $options{icon} || $options{i} || ""; |
|
57
|
3
|
|
100
|
|
|
22
|
my $w = $options{width} || $options{w} || 800; |
|
58
|
3
|
|
100
|
|
|
21
|
my $h = $options{height} || $options{h} || 600; |
|
59
|
3
|
|
50
|
|
|
81
|
my $d = $options{depth} || $options{d} || 16; |
|
60
|
3
|
|
50
|
|
|
37
|
my $f = $options{flags} || $options{f} || SDL::Video::SDL_ANYFORMAT; |
|
61
|
3
|
|
50
|
|
|
31
|
my $r = $options{red_size} || $options{r} || 5; |
|
62
|
3
|
|
50
|
|
|
29
|
my $g = $options{green_size} || $options{g} || 5; |
|
63
|
3
|
|
50
|
|
|
35
|
my $b = $options{blue_size} || $options{b} || 5; |
|
64
|
3
|
|
50
|
|
|
99
|
my $a = $options{alpha_size} || $options{a} || 0; |
|
65
|
3
|
|
50
|
|
|
39
|
my $ras = $options{red_accum_size} || $options{ras} || 0; |
|
66
|
3
|
|
50
|
|
|
28
|
my $gas = $options{green_accum_size} || $options{gas} || 0; |
|
67
|
3
|
|
50
|
|
|
34
|
my $bas = $options{blue_accum_size} || $options{bas} || 0; |
|
68
|
3
|
|
50
|
|
|
34
|
my $aas = $options{alpha_accum_size} || $options{aas} || 0; |
|
69
|
3
|
|
50
|
|
|
29
|
my $db = $options{double_buffer} || $options{db} || 0; |
|
70
|
|
|
|
|
|
|
|
|
71
|
3
|
|
50
|
|
|
28
|
my $bs = $options{buffer_size} || $options{bs} || 0; |
|
72
|
3
|
|
50
|
|
|
38
|
my $st = $options{stencil_size} || $options{st} || 0; |
|
73
|
3
|
|
50
|
|
|
19
|
my $async = $options{asyncblit} || 0; |
|
74
|
|
|
|
|
|
|
|
|
75
|
3
|
50
|
33
|
|
|
23
|
$f |= SDL::Video::SDL_OPENGL if ( $options{gl} || $options{opengl} ); |
|
76
|
3
|
50
|
33
|
|
|
21
|
$f |= SDL::Video::SDL_FULLSCREEN |
|
77
|
|
|
|
|
|
|
if ( $options{fullscreen} || $options{full} ); |
|
78
|
3
|
50
|
|
|
|
12
|
$f |= SDL::Video::SDL_RESIZABLE if ( $options{resizeable} ); |
|
79
|
3
|
50
|
|
|
|
14
|
$f |= SDL::Video::SDL_DOUBLEBUF if ($db); |
|
80
|
3
|
50
|
|
|
|
13
|
$f |= SDL::Video::SDL_ASYNCBLIT if ($async); |
|
81
|
|
|
|
|
|
|
|
|
82
|
3
|
50
|
|
|
|
13
|
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
|
|
|
|
|
7
|
$SDLx::App::USING_OPENGL = 0; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
3
|
50
|
|
|
|
6658
|
my $surface = SDL::Video::set_video_mode( $w, $h, $d, $f ) |
|
124
|
|
|
|
|
|
|
or Carp::confess SDL::get_error(); |
|
125
|
3
|
|
|
|
|
15
|
$options{surface} = $surface; |
|
126
|
|
|
|
|
|
|
|
|
127
|
3
|
|
|
|
|
210
|
my $self = SDLx::Surface->new(%options); |
|
128
|
|
|
|
|
|
|
|
|
129
|
3
|
50
|
33
|
|
|
20
|
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
|
|
|
|
|
57
|
SDL::Video::wm_set_caption( $t, $it ); |
|
135
|
3
|
|
|
|
|
33
|
$self = $self->SDLx::Controller::new(%options); |
|
136
|
3
|
|
|
|
|
13
|
bless $self, $class; |
|
137
|
|
|
|
|
|
|
|
|
138
|
3
|
|
|
|
|
21
|
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
|
|
2223522
|
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; |