Skip to content

Commit

Permalink
Merge branch 'experimental' of github.com:PerlGameDev/SDL into experi…
Browse files Browse the repository at this point in the history
…mental
  • Loading branch information
garu committed Oct 4, 2011
2 parents 4276fdb + 2505625 commit 21d8eeb
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 80 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,6 +1,8 @@
Revision history for Perl extension SDL_perl.

* 2.534
- SDL::Palette fixed colors() to return an array [Blaizer]
- SDL::Video fixed set_colors, set_palette [FROGGS, Blaizer]
- SDLx::Text improved error message [garu]
- SDLx::Text new getter: font_filename() [garu]
- SDLx::Text fixed size() accessor [garu]
Expand Down
2 changes: 1 addition & 1 deletion lib/SDL.pm
Expand Up @@ -54,7 +54,7 @@ our %EXPORT_TAGS = (
defaults => $SDL::Constants::EXPORT_TAGS{'SDL/defaults'}
);

our $VERSION = '2.534_02';
our $VERSION = '2.534_03';
$VERSION = eval $VERSION;

print "$VERSION" if ( defined( $ARGV[0] ) && ( $ARGV[0] eq '--SDLperl' ) );
Expand Down
10 changes: 10 additions & 0 deletions lib/SDLx/Controller.pm
Expand Up @@ -52,6 +52,16 @@ sub new {
return $self;
}


sub delay {
my $self = shift;
my $delay = shift;
my $ref = refaddr $self;

$_sleep_cycle{ $ref } = $delay if $delay;
return $self;
}

sub DESTROY {
my $self = shift;
my $ref = refaddr $self;
Expand Down
27 changes: 17 additions & 10 deletions lib/pods/SDL/Palette.pod
Expand Up @@ -11,27 +11,34 @@ Core, Video, Structure

=head1 DESCRIPTION

Each pixel in an 8-bit surface is an index into the colors field of the C<SDL::Palette> structure store in C<SDL::PixelFormat>. A C<SDL::Palette>
should never need to be created manually. It is automatically created when SDL allocates a C<SDL::PixelFormat> for a surface. The colors
values of a C<SDL::Surface>'s palette can be set with the C<SDL::Video::set_colors>.
Each pixel in an 8-bit surface is an index into the colors field of the C<SDL::Palette> object stored in its C<SDL::PixelFormat>.
A C<SDL::Palette> is created automatically when SDL allocates a C<SDL::PixelFormat> for a surface.
This class has methods for returning the colors in a palette object.
The colors can be set with L<SDL::Video::set_colors|SDL::Video/set_colors> and L<SDL::Video::set_palette|SDL::Video/set_palette>.

=head1 METHODS

=head2 ncolors ( )
=head2 ncolors

Fetches the number of colors in palette
$ncolors = $palette->ncolors();

=head2 colors ( index )
Returns the number of colors in palette.

Fetches an array of colors in palette
=head2 colors

=head2 color_index ( index )
@colors = @{ $palette->colors() };

Fetches the SDL_Color at the provide index in palette
Returns an array, C<ncolors> in length, of the L<SDL::Color>s in the palette.

=head2 color_index

$color = $palette->color_index( $index );

Returns the L<SDL::Color> at the provided index of the palette.

=head1 SEE ALSO

L<SDL::Color> L<SDL::Surface>
L<SDL::Video> L<SDL::PixelFormat> L<SDL::Color> L<SDL::Surface>

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion lib/pods/SDL/Surface.pod
Expand Up @@ -104,7 +104,7 @@ B<Disclaimer:> The following methods can be very slow, making them suitable for

my $pixel = $surface->get_pixel( $offset )

Returns the pixel value for the given C<$offset>.
Returns the numeric pixel value for the given C<$offset>.
The pixel value depends on current pixel format.

B<Note:> For surfaces with a palette (1 byte per pixel) the palette index is returned instead of color values.
Expand Down
2 changes: 2 additions & 0 deletions lib/pods/SDL/Video.pod
Expand Up @@ -421,6 +421,8 @@ it returns 0 on success or -1 on error.
$set_color_key = SDL::Video::set_color_key( $surface, $flag, $key );

Sets the color key (transparent pixel) in a blittable surface and enables or disables RLE blit acceleration.
C<$key> can be an integer or an L<SDL::Color|SDL::Color> object. If you pass an L<SDL::Color|SDL::Color> object
L<SDL::Video::map_RGB|/map_RGB> will be called on it before setting the color key.

RLE acceleration can substantially speed up blitting of images with large horizontal runs of transparent pixels (i.e., pixels that match
the key value).
Expand Down
128 changes: 68 additions & 60 deletions src/Core/Video.xs
Expand Up @@ -14,7 +14,7 @@ void _uinta_free(Uint16* av, int len_from_av_len)
{
if( av != NULL)
return;

safefree(av);
}

Expand All @@ -26,7 +26,7 @@ Uint16* av_to_uint16 (AV* av)
int i;
Uint16* table = (Uint16 *)safemalloc(sizeof(Uint16)*(len+1));
for ( i = 0; i < len+1 ; i++ )
{
{
SV ** temp = av_fetch(av,i,0);
if( temp != NULL )
{
Expand Down Expand Up @@ -78,15 +78,15 @@ video_get_video_info()

SV *
video_video_driver_name( )

CODE:
char buffer[1024];
if ( SDL_VideoDriverName(buffer, 1024) != NULL )
{
if ( SDL_VideoDriverName(buffer, 1024) != NULL )
{
RETVAL = newSVpv(buffer, 0);
}
else
XSRETURN_UNDEF;
}
else
XSRETURN_UNDEF;
OUTPUT:
RETVAL

Expand Down Expand Up @@ -159,7 +159,7 @@ video_update_rects ( surface, ... )
num_rects = items - 1;
rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
for(i=0;i<num_rects;i++) {
void** pointers = (void**)(SvIV((SV*)SvRV( ST(i+1) )));
void** pointers = (void**)(SvIV((SV*)SvRV( ST(i+1) )));
rects[i] = *(SDL_Rect *)(pointers[0]);
}
SDL_UpdateRects(surface,num_rects,rects);
Expand All @@ -179,57 +179,48 @@ video_set_colors ( surface, start, ... )
SDL_Surface *surface
int start
CODE:
SDL_Color *colors,*temp;
int i, length;
if ( items < 3 ) { RETVAL = 0;}
if ( items < 3 )
RETVAL = 0;
else
{
length = items - 2;
colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
for ( i = 0; i < length ; i++ ) {
void** pointers = (void**)(SvIV(ST(i+2)));
temp = (SDL_Color *)pointers[0];
colors[i].r = temp->r;
colors[i].g = temp->g;
colors[i].b = temp->b;
int i;
int length = items - 2;
SDL_Color *colors = (SDL_Color *)safemalloc(sizeof(SDL_Color) * (length + 1));
for ( i = 0; i < length ; i++ ) {
SDL_Color *temp = (SDL_Color *)bag2obj( ST(i + 2) );
colors[i].r = temp->r;
colors[i].g = temp->g;
colors[i].b = temp->b;
}
RETVAL = SDL_SetColors(surface, colors, start, length);
safefree(colors);
}
RETVAL = SDL_SetColors(surface, colors, start, length );
safefree(colors);
}

OUTPUT:
OUTPUT:
RETVAL

int
video_set_palette ( surface, flags, start, ... )
SDL_Surface *surface
int flags
int start

CODE:
SDL_Color *colors;
SDL_Color *temp;
int i,length;

if ( items < 4 ) {
RETVAL = 0;

} else {
length = items - 3;
colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
for ( i = 0; i < length; i++ ){

void** pointers = (void**)(SvIV(ST(i+3)));
temp = (SDL_Color *)pointers[0];
colors[i].r = temp->r;
colors[i].g = temp->g;
colors[i].b = temp->b;
}

RETVAL = SDL_SetPalette(surface, flags, colors, start, length);
safefree(colors);
if ( items < 4 )
RETVAL = 0;
else
{
int i;
int length = items - 3;
SDL_Color *colors = (SDL_Color *)safemalloc(sizeof(SDL_Color) * (length + 1));
for ( i = 0; i < length ; i++ ) {
SDL_Color *temp = (SDL_Color *)bag2obj( ST(i + 3) );
colors[i].r = temp->r;
colors[i].g = temp->g;
colors[i].b = temp->b;
}
RETVAL = SDL_SetPalette(surface, flags, colors, start, length);
safefree(colors);
}
OUTPUT:
OUTPUT:
RETVAL

int
Expand All @@ -239,7 +230,7 @@ video_set_gamma(r, g, b)
float b;
CODE:
RETVAL = SDL_SetGamma(r,g,b);
OUTPUT:
OUTPUT:
RETVAL

int
Expand All @@ -260,7 +251,7 @@ video_get_gamma_ramp( redtable, greentable, bluetable )
}
OUTPUT:
RETVAL

int
video_set_gamma_ramp( rt, gt, bt )
AV* rt;
Expand All @@ -272,11 +263,11 @@ video_set_gamma_ramp( rt, gt, bt )
greentable = av_to_uint16(gt);
bluetable = av_to_uint16(bt);
RETVAL = SDL_SetGammaRamp(redtable, greentable, bluetable);
_uinta_free(redtable, av_len(rt) );
_uinta_free(greentable, av_len(gt) );
_uinta_free(redtable, av_len(rt) );
_uinta_free(greentable, av_len(gt) );
_uinta_free(bluetable, av_len(bt) );
OUTPUT:
RETVAL
RETVAL



Expand All @@ -296,7 +287,7 @@ video_map_RGBA ( pixel_format, r, g, b, a )
SDL_PixelFormat *pixel_format
Uint8 r
Uint8 g
Uint8 b
Uint8 b
Uint8 a
CODE:
RETVAL = SDL_MapRGBA(pixel_format, r,g,b,a );
Expand Down Expand Up @@ -356,9 +347,16 @@ int
video_set_color_key ( surface, flag, key )
SDL_Surface *surface
Uint32 flag
SDL_Color *key
SV *key
CODE:
Uint32 pixel = SDL_MapRGB(surface->format,key->r,key->g,key->b);
Uint32 pixel;
if(SvOK(key) && SvIOK(key))
pixel = (Uint32)SvUV(key);
else
{
SDL_Color *color = (SDL_Color *)bag2obj(key);
pixel = SDL_MapRGB(surface->format, color->r, color->g, color->b);
}
RETVAL = SDL_SetColorKey(surface,flag,pixel);
OUTPUT:
RETVAL
Expand Down Expand Up @@ -434,12 +432,22 @@ fill_rect ( dest, dest_rect, pixel )
RETVAL

int
blit_surface ( src, src_rect, dest, dest_rect )
blit_surface ( src, src_rect_sv, dest, dest_rect_sv )
SDL_Surface *src
SDL_Surface *dest
SDL_Rect *src_rect
SDL_Rect *dest_rect
SV *src_rect_sv
SV *dest_rect_sv
CODE:
SDL_Rect* src_rect = NULL;
SDL_Rect* dest_rect = NULL;
if( SvOK(src_rect_sv ) )
{
src_rect = (SDL_Rect*)bag2obj(src_rect_sv);
}
if( SvOK( dest_rect_sv) )
{
dest_rect = (SDL_Rect*)bag2obj(dest_rect_sv);
}
RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect);
OUTPUT:
RETVAL
Expand Down Expand Up @@ -580,4 +588,4 @@ video_MUSTLOCK ( surface )
CODE:
RETVAL = SDL_MUSTLOCK(surface);
OUTPUT:
RETVAL
RETVAL
4 changes: 1 addition & 3 deletions src/Core/objects/Palette.xs
Expand Up @@ -38,9 +38,7 @@ palette_colors ( palette )
RETVAL = (AV*)sv_2mortal((SV*)newAV());
int i;
for(i = 0; i < palette->ncolors; i++)
{
av_push(RETVAL,newSViv( PTR2IV( palette->colors + i ) ) );
}
av_push( RETVAL, cpy2bag( (SDL_Color *)(palette->colors + i), sizeof(SDL_Color *), sizeof(SDL_Color), "SDL::Color" ) );
OUTPUT:
RETVAL

Expand Down
10 changes: 5 additions & 5 deletions t/core_palette.t
Expand Up @@ -17,7 +17,7 @@ $ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
plan( skip_all => 'Failed to init video' );
} else {
plan( tests => 9 );
plan( tests => 10 );
}

use_ok('SDL::Palette');
Expand Down Expand Up @@ -47,10 +47,10 @@ SKIP:

is( $disp->format->palette->ncolors, 256, '256 colors in palette' );

isa_ok(
$disp->format->palette->colors(),
'ARRAY', 'Palette->colors[x] is a color'
);
my $colors = $disp->format->palette->colors();
isa_ok( $colors, 'ARRAY', 'Palette->colors is an array' );

isa_ok( $colors->[0], 'SDL::Color', 'Palette->colors[x] is an SDL::Color' );

isa_ok(
$disp->format->palette->color_index(23),
Expand Down

0 comments on commit 21d8eeb

Please sign in to comment.