Skip to content

Commit

Permalink
started on SDL::GFX::Primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Leich committed Nov 30, 2009
1 parent 90d6eb1 commit be0c2a2
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Build.PL
Expand Up @@ -63,6 +63,13 @@ my %subsystems =
},
libraries => [qw( SDL )],
},
Primitives => {
file => {
from => 'src/GFX/Primitives.xs',
to => 'lib/SDL/GFX/Primitives.xs',
},
libraries => [qw( SDL SDL_gfx )],
},
MultiThread => {
file => {
from => 'src/Core/MultiThread.xs',
Expand Down
9 changes: 9 additions & 0 deletions lib/SDL/GFX/Primitives.pm
@@ -0,0 +1,9 @@
package SDL::GFX::Primitives;
use strict;
use warnings;
require Exporter;
require DynaLoader;
our @ISA = qw(Exporter DynaLoader);
bootstrap SDL::GFX::Primitives;

1;
190 changes: 190 additions & 0 deletions src/GFX/Primitives.xs
@@ -0,0 +1,190 @@
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#ifndef aTHX_
#define aTHX_
#endif

#include <SDL.h>
#include <SDL_gfxPrimitives.h>

MODULE = SDL::GFX::Primitives PACKAGE = SDL::GFX::Primitives PREFIX = gfx_prim_

=for documentation

The Following are XS bindings to the SDL_gfx Library

Described here:

See: L<http://www.ferzkopp.net/joomla/content/view/19/14/>

=cut

int
gfx_prim_pixel_color(dst, x, y, color)
SDL_Surface *dst
Sint16 x
Sint16 y
Uint32 color
CODE:
RETVAL = pixelColor(dst, x, y, color);
OUTPUT:
RETVAL

=for documentation

pixelRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Horizontal line */

hlineColor(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color);
hlineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Vertical line */

vlineColor(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color);
vlineRGBA(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Rectangle */

rectangleColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
rectangleRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Filled rectangle (Box) */

boxColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
boxRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2,
Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Line */

lineColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
lineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* AA Line */
aalineColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
aalineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Circle */

circleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
circleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Circle */

arcColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Sint16 start, Sint16 end, Uint32 color);
arcRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* AA Circle */

aacircleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
aacircleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Filled Circle */

filledCircleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
filledCircleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Ellipse */

ellipseColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
ellipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* AA Ellipse */

aaellipseColor(SDL_Surface * dst, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color);
aaellipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Filled Ellipse */

filledEllipseColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
filledEllipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

#define CLOCKWISE

/* Pie */

pieColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint32 color);
pieRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Filled Pie */

filledPieColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint32 color);
filledPieRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Trigon */

trigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
trigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* AA-Trigon */

aatrigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
aatrigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Filled Trigon */

filledTrigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
filledTrigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Polygon */

polygonColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
polygonRGBA(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy,
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* AA-Polygon */

aapolygonColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
aapolygonRGBA(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy,
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/* Filled Polygon */

filledPolygonColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
filledPolygonRGBA(SDL_Surface * dst, const Sint16 * vx,
const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
texturedPolygon(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, SDL_Surface * texture,int texture_dx,int texture_dy);

/* (Note: These MT versions are required for multi-threaded operation.) */

filledPolygonColorMT(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color, int **polyInts, int *polyAllocated);
filledPolygonRGBAMT(SDL_Surface * dst, const Sint16 * vx,
const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
int **polyInts, int *polyAllocated);
texturedPolygonMT(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, SDL_Surface * texture,int texture_dx,int texture_dy, int **polyInts, int *polyAllocated);

/* Bezier */
/* (s = number of steps) */

bezierColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, int s, Uint32 color);
bezierRGBA(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy,
int n, int s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);


/* Characters/Strings */

characterColor(SDL_Surface * dst, Sint16 x, Sint16 y, char c, Uint32 color);
characterRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, char c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
stringColor(SDL_Surface * dst, Sint16 x, Sint16 y, const char *c, Uint32 color);
stringRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, const char *c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

gfxPrimitivesSetFont(const void *fontdata, int cw, int ch);

=cut
1 change: 1 addition & 0 deletions t/00-load.t
Expand Up @@ -32,6 +32,7 @@ SDL::Mixer::MixChunk
SDL::Mixer::MixMusic
SDL::Version
SDL::GFX::Primitives
SDL::Image
/;
plan tests => scalar @modules;
Expand Down
48 changes: 48 additions & 0 deletions t/core_gfx_primitives.t
@@ -0,0 +1,48 @@
#!perl
use strict;
use warnings;
use SDL;
use SDL::Config;
use SDL::Video;
use SDL::Surface;
use SDL::GFX::Primitives;
use Test::More;

use lib 't/lib';
use SDL::TestTool;

if( !SDL::TestTool->init(SDL_INIT_VIDEO) )
{
plan( skip_all => 'Failed to init video' );
}
elsif( !SDL::Config->has('SDL_gfx') )
{
plan( skip_all => 'SDL_gfx support not compiled' );
}
else
{
plan( tests => 5 );
}

use_ok('SDL');
use_ok('SDL::Surface');
use_ok('SDL::GFX::Primitives');

my $display = SDL::Video::set_video_mode(640,480,32, SDL_HWSURFACE );

if(!$display)
{
plan skip_all => 'Couldn\'t set video mode: ' . SDL::get_error();
}

SDL::Video::lock_surface($display) if(SDL::Video::MUSTLOCK($display));

is( SDL::GFX::Primitives::pixel_color($display, 5, 5, 0xFFFFFF00), 0, 'pixel_color' );

SDL::Video::unlock_surface($display) if(SDL::Video::MUSTLOCK($display));

SDL::Video::update_rect($display, 0, 0, 640, 480);

SDL::delay(2000);

pass 'Are we still alive? Checking for segfaults';

0 comments on commit be0c2a2

Please sign in to comment.