package X::GFXButton; use strict; #----------------------------------------------------- INI -------------------------------------------------------- #Erzeugen sub new {    my ($class,@params) = @_;    my $self = {};    bless($self,$class);    #for(qw(ID APP X Y IMG IMGHV)){$self->{$_} = shift(@params);}    $self->{CONTAINER} = shift(@params);        #Container    $self->{ID} = shift(@params);         #ID oder Name    $self->{APP} = shift(@params); #SDL APP    $self->{X} = shift(@params);    $self->{Y} = shift(@params);    $self->{IMG} = shift(@params);  #IMG normal    $self->{IMGHV} = shift(@params);   #IMG hover    $self->{IMG_click} = shift(@params);            #IMG click    $self->{DOSUB} = shift(@params);#Button's sub    $self->{TXT} = shift(@params); #Button's Text    $self->{HV} = 0; #Hover state    $self->draw($self->{IMG}); #Display     push( @{$self->{CONTAINER}->{BUTTS}}   ,  $self);    return($self); } sub check_button {    my ($self, $mx, $my) = @_;    my $img = $self->{IMG};    #Hover - Effekt    if($mx > $self->{X} &&  $mx < ($self->{X}+ $img->width)  && $my > $self->{Y}    &&   $my < ($self->{Y}+ $img->height) )    {        if($self->{PRESSED} eq 1){$self->draw($self->{IMG_click});} else        {            if(not  $self->{HV}) {$self->{HV}=1; $self->draw($self->{IMGHV});}        }         return $self;    } else    {            if($self->{PRESSED} eq 1){$self->draw($self->{IMG_click});} else            {                if($self->{HV}) {$self->{HV}=0; $self->draw($self->{IMG});}            }    }    return 0; } #---------------------------------------------------------- CODE OK ---------------------------------------------------------- #Grafik darstellen sub draw {    my ($self, $img) = @_;    my $dest_rect = SDL::Rect->new(-height => $img->height(),-width  => $img->width(),-x=> $self->{X},-y => $self->{Y});    $img->blit( SDL::Rect->new(-height => $img->height(),-width  => $img->width(),-x => 0, -y  => 0), $self->{APP}, $dest_rect );    $self->{APP}->update( $dest_rect ); } #Button geklickt darstellen sub button_down { $_->{PRESSED} = 1;} #Bei MausUP Buttons normal zeichnen sub buttons_up  { my ($self, $container) = @_; for(@{$container->{BUTTS}}) {$_->{PRESSED} = 0; $_->draw($_->{IMG});} } #Button_on #Button_off #Buttons_on #Buttons_off #Buttons nicht mehr prüfen sub destroy_buttons { my ($self, $container) = @_; $container->{BUTTS} = [];} #Parameter zurückgeben (mehrere) sub get {my ($self, @values) = @_; my @out = ();for(@values) {push(@out,$self->{"$_"}); } return @out;} #Einelnen Parameter setzen sub set {my ($self, $param, $value) = @_;  $self->{$param} = $value;} 1;