Permalink
Browse files

SDLx::App icon done and documented but transparency doesn't work.

SDLx::App is just about done now, except for some polish. Needs tests, too...
  • Loading branch information...
1 parent f31d22f commit 740e7f86b9c81426e199ea2866d4d74ef899b1d3 @Blaizer Blaizer committed Feb 2, 2012
Showing with 38 additions and 16 deletions.
  1. +18 −5 lib/SDLx/App.pm
  2. +20 −11 lib/pods/SDLx/App.pod
View
@@ -9,7 +9,8 @@ use SDL::Video ();
use SDL::Mouse ();
use SDL::Event ();
use SDL::Surface ();
-use SDL::VideoInfo();
+use SDL::VideoInfo ();
+use SDLx::Validate ();
use base qw/SDLx::Surface SDLx::Controller/;
# SDL modules used for other reasons
@@ -39,13 +40,14 @@ sub new {
my $d = defined $o{depth} ? $o{depth} : defined $o{d} ? $o{d} : undef;
my $f = defined $o{flags} ? $o{flags} : defined $o{f} ? $o{f} : 0;
my $pos = defined $o{position} ? $o{position} : defined $o{pos} ? $o{pos} : undef;
+ my $ico = $o{icon};
# undef is a valid input
my $t = $o{title};
my $it = $o{icon_title};
- my $icon = $o{icon};
my $init = exists $o{initialize} ? $o{initialize} : $o{init};
my $s = exists $o{stash} ? $o{stash} : {};
+ my $icc = $o{icon_color_key};
# boolean
my $sw = $o{software_surface} || $o{sw_surface} || $o{sw};
@@ -58,7 +60,7 @@ sub new {
my $gl = $o{open_gl} || $o{opengl} || $o{gl};
my $rs = $o{resizable} || $o{resizeable}; # it's a hard word to spell :-)
my $nf = $o{no_frame};
- my $ncur = $o{no_cursor};
+ my $ncur = $o{hide_cursor} || $o{no_cursor};
my $cen = $o{centered} || $o{center};
my $gi = $o{grab_input};
my $nc = $o{no_controller};
@@ -148,14 +150,16 @@ sub new {
SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_SWAP_CONTROL, $sc ) if defined $sc;
SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_ACCELERATED_VISUAL, $av ) if defined $av;
}
+
+ # icon must be set before set_video_mode
+ SDLx::App->icon( $ico, $icc ) if defined $ico;
my $self = $class->set_video_mode( $w, $h, $d, $f );
$self->SDLx::Controller::new( %o ) unless $nc;
$t = defined $it ? $it : $0 unless defined $t;
$it = $t unless defined $it;
$self->title( $t, $it );
- $self->icon( $icon );
$self->show_cursor( 0 ) if $ncur;
$self->grab_input( $gi ) if $gi;
@@ -257,7 +261,16 @@ sub title {
}
sub icon {
- my ( undef, $icon, $mask ) = @_;
+ my ( undef, $icon, $color ) = @_;
+ SDLx::App->init( SDL::SDL_INIT_VIDEO );
+ unless( UNIVERSAL::isa( $icon, "SDL::Surface" ) ) {
+ $icon = SDL::Video::load_BMP( $icon );
+ $icon or Carp::confess( "Could not load_BMP icon '$icon': ", SDL::get_error() );
+ }
+ if( defined $color ) {
+ $color = SDLx::Validate::map_rgb( $color, $icon->format );
+ SDL::Video::set_color_key( $icon, SDL::Video::SDL_SRCCOLORKEY, $color );
+ }
SDL::Video::wm_set_icon( $icon );
}
View
@@ -76,9 +76,10 @@ providing all the methods they both provide.
height => 480,
depth => 32,
- title => "Application Title",
- icon_title => "App Title",
- icon => TODO,
+ title => "Application Title",
+ icon_title => "App Title",
+ icon => "icon.bmp",
+ icon_color_key => [255, 255, 0],
# two ways to do init. init video is assumed regardless
init => SDL_INIT_AUDIO | SDL_INIT_JOYSTICK,
@@ -102,7 +103,7 @@ providing all the methods they both provide.
centered => 1,
position => [ 150, 100 ],
- no_cursor => 1,
+ hide_cursor => 1,
grab_input => 1,
# don't initialize an SDLx::Controller for the app
@@ -161,7 +162,11 @@ The application's icon title, as a string. Defaults to the L</title> if defined,
=item icon
-The application's icon. Set with L</icon>.
+The application's icon. Set with the L</icon> method.
+
+=item icon_color_key
+
+You can optionally use this when specifying the C<icon> parameter to set its color key (transparent pixel).
=item init
@@ -257,10 +262,11 @@ The position of the window on the screen, as an array ref. The array ref should
specifying C<x> and C<y> values, in pixels, used to position the window on the screen.
Implemented using C<$ENV{SDL_VIDEO_WINDOW_POS}>. Alias: C<pos>.
-=item no_cursor
+=item hide_cursor
A boolean value. If true, hides the cursor on the video surface using L</show_cursor>.
A surface can then instead be blitted to the display at the location of the cursor.
+Alias: C<no_cursor>.
=item grab_input
@@ -357,12 +363,15 @@ icon title the same, or a string to modify them.
=head2 icon
- SDLx::App->icon( $filename );
- SDLx::App->icon( SDL::Video::load_BMP( $filename ) );
- SDLx::App->icon( $icon, $color_key );
- SDLx::App->icon( $icon, $mask );
+ SDLx::App->icon( $filename, $color );
+ SDLx::App->icon( $surface, $color );
-This is yet to be implemented. Currently only the second form works.
+Sets the window's icon.
+This must be called before creating the display surface, so SDL::Image can not be used.
+If a filename is specified, it is loaded withL<SDL::Video::load_BMP|SDL::Video/load_BMP>.
+Otherwise, the first argument should be a surface. Win32 icons must be 32x32.
+The C<$color> argument is optional and, if specified, is used to set the icon's color key (transparent pixel).
+It should be an RGB color as either a number or array ref.
=head2 error

0 comments on commit 740e7f8

Please sign in to comment.