Leser: 1
|< 1 2 3 4 >| | 38 Einträge, 4 Seiten |
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
#!/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;
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
use FindBin qw($Bin); chdir($Bin);
use lib $FindBin::Bin . '/LIBS';
use SimpleButton; #in zusätzlichen sub dir "X", daher X::
my $SimpleButton = SimpleButton->new();
use SDL;
use SDL::App;
use SDL::Event;
use SDL::Surface;
use SDL::Color;
use SDL::Rect;
my $app = SDL::App->new(
-width => 900,
-height => 600,
-depth => 16,
);
my $img = SDL::Surface->new( -name => 'x.png' );
my $img2 = SDL::Surface->new( -name => 'x_on.png' );
for my $i (0..10)
{
for my $x (0..7)
{
$SimpleButton = SimpleButton->new();
$id++;
$SimpleButton->add_Butt($id,$app,(105*$x),(45*$i),$img,$img2);
push(@butts,$SimpleButton);
}
}
$event = new SDL::Event();
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));
for(@butts)
{
my $click = $_->check($event->button_x,$event->button_y,$event);
if($click ne 0 ) {print "\r ",$click," ";}
}
}
$container->handle_events
Quotesub new {
my $self = shift;
my $Referenz = {};
$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});
bless($Referenz,$self);
return($Referenz);
}
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;
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
Aufruf:
$SimpleButton = SimpleButton->new($id,$app,(65*$x),(25*$i),$img,$img2);
MODUL:
sub new {
my $self = shift;
$self->{ID} = shift;
$self->{APP} = shift;
$self->{X} = shift;
$self->{Y} = shift;
$self->{IMG} = shift;
$self->{IMGHV} = shift;
$self->{HV} = 0;
my $Referenz = {};
bless($Referenz,$self);
print " -- ",$self->{IMG}," ---";
$self->draw($self->{IMG});
return($Referenz);
}
sub draw
{
my ($self, $img) = @_;
print "IMG: $img";
}
|< 1 2 3 4 >| | 38 Einträge, 4 Seiten |