1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package SDL::X::SimpleButton;
sub new {
my ($class,@params) = @_;
my $self = {};
bless($self,$class);
for(qw(ID APP X IMG IMGHV)){
$self->{$_} = shift(@params);
}
$self->{HV} = 0;
$self->draw($self->{IMG});
return($self);
}
sub draw{
my ($self,$img) = @_;
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,$mx,$my,$event) = @_;
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 == 1 ) {
return $self->{ID};
}
}
else{
if($self->{HV}) {
$self->{HV}=0;
$self->draw($self->{IMG});
}
return 0;
}
}
1;
\n\n
<!--EDIT|renee|1144052691-->