#!/usr/bin/perl package SimpleButton; sub new { my $self = shift; my $Referenz = {}; bless($Referenz,$self); return($Referenz); } sub add_Butt { my $self = shift; $self->{ID} = shift; $self->{APP} = shift; $self->{X} = shift; $self->{Y} = shift; $self->{IMG} = shift; $self->{IMGHV} = shift; $self->{HV} = 0; $self->draw($self->{IMG}); return 1; } sub draw { my $self = shift; my $img = shift; my $frame_rect = SDL::Rect->new(-height => $img->height(),-width => $img->width(),-x => 0, -y => 0); my $dest_rect = SDL::Rect->new(-height => $img->height(),-width => $img->width(), -x => $self->{X},-y => $self->{Y},); $img->blit( $frame_rect, $self->{APP}, $dest_rect ); $self->{APP}->update( $dest_rect ); $self->{APP}->flip; return 1; } sub check { my $self = shift; my $mx = shift; my $my = shift; my $event = shift; my $img = $self->{IMG}; #Hover - Effekt if($mx > $self->{X} && $mx < ($self->{X}+ $img->width) && $my > $self->{Y} && $my < ($self->{Y}+ $img->height) ) { if(not $self->{HV}) {$self->{HV}=1; $self->draw($self->{IMGHV});} if($event->button eq 1 ) {return $self->{ID};} } else { if($self->{HV}) {$self->{HV}=0; $self->draw($self->{IMG});} return 0; } } 1;