App-Fotagger
view release on metacpan or search on metacpan
lib/App/Fotagger/Display/SDL.pm view on Meta::CPAN
use strict;
use warnings;
use 5.010;
use Moose;
use SDL;
use SDL::App;
use SDL::Surface;
use SDL::Tool::Graphic;
use SDL::TTFont;
use SDL::Rect;
use SDL::Event;
use SDL::Color;
has 'width' => (isa=>'Int',is=>'ro',default=>'1000');
has 'height' => (isa=>'Int',is=>'ro',default=>'750');
has 'black' => (isa=>'SDL::Color',is=>'ro',default=>sub {SDL::Color->new(-r=>0, -g=>0, -b=>0)});
has 'red' => (isa=>'SDL::Color',is=>'ro',default=>sub {SDL::Color->new(-r=>255, -g=>0, -b=>0)});
has 'yellow' => (isa=>'SDL::Color',is=>'ro',default=>sub {SDL::Color->new(-r=>255, -g=>255, -b=>0)});
has 'grey' => (isa=>'SDL::Color',is=>'ro',default=>sub {SDL::Color->new(-r=>50, -g=>50, -b=>50)});
has 'white' => (isa=>'SDL::Color',is=>'ro',default=>sub {SDL::Color->new(-r=>255, -g=>255, -b=>255)});
has 'blank_tags' => (isa=>'SDL::Rect',is=>'rw');
has 'blank_stars' => (isa=>'SDL::Rect',is=>'rw');
has 'font' => (isa=>'SDL::TTFont',is=>'rw');
has 'starfont' => (isa=>'SDL::TTFont',is=>'rw');
has 'event' => (isa=>'SDL::Event',is=>'rw');
has 'window'=> (isa=>'SDL::App',is=>'rw');
has 'app' => (isa=>'App::Fotagger',is=>'ro');
no Moose;
__PACKAGE__->meta->make_immutable;
sub run {
my ($class, $app) = @_;
my $self = $class->new(
app=>$app
);
my $window = SDL::App->new(
-width => $self->width,
-height => $self->height,
-depth => 16,
);
$self->window($window);
$self->font(SDL::TTFont->new(-name=>'/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf', -size=>12,-bg=>$self->black, -fg=>$self->white));
$self->starfont(SDL::TTFont->new(-name=>'/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf', -size=>60,-bg=>$self->black, -fg=>$self->yellow));
$self->event(SDL::Event->new);
$self->event->set_unicode(1);
$self->blank_tags(SDL::Rect->new(-width=>$self->width, -height=>16, -y=>680, -x=>0));
$self->blank_stars(SDL::Rect->new(-width=>$self->width, -height=>30, -y=>696, -x=>0));
my $event = $self->event;
$self->draw_image;
while (1) {
MAIN: while ($event->poll) {
my $type = $event->type();
exit if ($type == SDL_QUIT);
exit if ($type == SDL_KEYDOWN && $event->key_name() eq 'escape');
my $key = $event->key_name();
if ($type == SDL_KEYDOWN && !$app->tagging) {
given($key) {
when (['n','return']) {
$app->_lasttags($app->current_image->tags);
$app->_laststar($app->current_image->stars);
$app->next_image;
$self->draw_image;
}
when (['p','backspace']) {
$app->_lasttags($app->current_image->tags);
$app->_laststar($app->current_image->stars);
$app->prev_image;
$self->draw_image;
}
when ('page down') {
$app->next_image(10);
$self->draw_image;
}
when ('page up') {
$app->prev_image(10);
$self->draw_image;
}
when ('d') {
my $ltag=$app->_lasttags;
my $lstar = $app->_laststar;
$app->current_image->delete;
$app->next_image;
$self->draw_image;
$app->_lasttags($ltag) if $ltag;
$app->_laststar($lstar) if $lstar;
}
when ('u') {
$app->current_image->restore;
$self->draw_image;
}
when ('s') {
$app->current_image->add_tags($app->_lasttags);
$app->current_image->stars($app->_laststar);
$app->current_image->write();
$self->draw_image;
}
when ('t') {
$app->tagging(1);
if (my $old_tags=$app->current_image->tags) {
$app->current_image->tags($old_tags.', ');
$self->draw_tags();
}
}
when([0 .. 5]) {
$app->current_image->stars($key);
$app->current_image->write;
$self->draw_stars;
$self->draw_tags;
}
}
} elsif ($type == SDL_KEYDOWN && $app->tagging) {
( run in 3.134 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )