Funktioniert nun relativ gut...
Modul-Komplett:
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package SimpleButton;
#Erzeugen
sub new {
my ($class,@params) = @_;
my $self = {};
bless($self,$class);
#for(qw(ID APP X Y IMG IMGHV)){$self->{$_} = shift(@params);}
$self->{ID} = shift(@params); &n
bsp; #ID oder Name
$self->{APP} = shift(@params); &n
bsp; #SDL APP
$self->{X} = shift(@params);
$self->{Y} = shift(@params);
$self->{IMG} = shift(@params); &n
bsp; #IMG normal
$self->{IMGHV} = shift(@params); #IMG hover
$self->{DOSUB} = shift(@params); &n
bsp; #Button's sub
$self->{HV} = 0; &nbs
p; #Hover state
$self->draw($self->{IMG}); &n
bsp; #Display
push(@butts, $self);
return($self);
}
#Button 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 );
}
#Alle Elemente Prüfen
sub checkall
{
my ($self, $mx, $my) = @_;
for(@butts) { if($_->check_button($mx,$my)){$active_element = $_;} }
return $active_element;
}
#Sub zurückgeben
sub dosub
{ my $self = shift; return $self->{DOSUB}; }
sub get
{
my $self = shift;
my $values = shift;
return $self->{"$values"};
}
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(not $self->{HV}) {$self->{HV}=1; $self->draw($self->{IMGHV});}
return true;
} else
{
if($self->{HV}) {$self->{HV}=0; $self->draw($self->{IMG});}
}
return false;
}
sub button_check{}
sub button_hover{}
sub button_click{}
1;
AufrufCode Teil:
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
while(1)
{
#process event queue
$event->pump;
$event->poll;
my $etype=$event->type;
# handle user events
last if ($etype eq SDL_QUIT );
last if (SDL::GetKeyState(SDLK_ESCAPE));
$checked = SimpleButton->checkall($event->button_x,$event->button_y);
print "\r ",$checked->get('ID')," ";
if($event->button eq 1)
{
&{$checked->dosub()}($checked);
}
}
#Button Event
sub loslos
{
my $self = shift;
print "\r ",$self->get('ID')," ";
}
\n\n
<!--EDIT|master|1144065429-->
$i='re5tsFam ^l\rep';$i=~s/[^a-z| ]//g;$\= reverse "\U!$i";print;