Leser: 1
![]() |
|< 1 2 3 4 >| | ![]() |
38 Einträge, 4 Seiten |
1
2
3
4
5
6
7
8
9
$active_element = $X->checkall($event->button_x,$event->button_y);
if($event->button eq 1)
{
if($active_element ne false and $active_element->dosub() ne false ) { &{$active_element->dosub()}($active_element); }
}
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package X::GFXButton;
use strict;
my @butts;
#----------------------------------------------------- INI --------------------------------------------------------
#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); &n
bsp; #IMG hover
$self->{IMG_click} = shift(@params); #IMG click
$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);
}
#------------ Alle Elemente Prüfen --------------------
sub checkall
{
my ($self, $mx, $my) = @_;
my $active_element = 0;
my $B_event_sub = 0;
for(@butts) {
if($_->check_button($mx,$my)){$active_element = $_;}
}
#Events bearbeiten....
if($active_element) {$B_event_sub = $active_element->{DOSUB};}
return ($active_element, $B_event_sub); &n
bsp; &n
bsp; #Object and the sub
}
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 $self;
} else
{
if($self->{HV}) {$self->{HV}=0; $self->draw($self->{IMG});}
}
return 0;
}
sub button_click
{
my $self = shift; $self->draw($self->{IMG_click});
}
sub button_check{}
sub button_hover{}
#---------------------------------------------------------- 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 );
}
#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;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#Button hinzufügen...(test)
for my $i (0..15) { for my $x (0..10) { $id++; $X->new($id,$app,(65*$x),(25*$i),$img,$img2,$img3, 'loslos'); }}
$X = X::GFXButton;
($active_element, $B_event_sub) = $X->checkall($event->button_x,$event->button_y);
if($event->button eq 1 && $active_element)
{
$active_element->button_click();
&{$B_event_sub}($active_element) if($B_event_sub);
}
#Button Event
sub loslos
{
my $self = shift;
my ($ID, $IMG ) = $self->get("ID", "IMG");
print "\r $ID - $IMG ";
}
1
2
my $container = ...::Container->new($app);
$container->add("SimpleButton", ...); # alternativ: $button = ...::SimpleButton->new(...); $container->add($button);
$container->check_all;
$container->SimpleButton(...)
QuoteIch würde vielleicht nich die Möglichkeit geben nicht nur Bilder für den Button zu benutzen sondern, dass z.B. 2 Rechtecke aufeinander gezeichnet werden.
1 Rechteck: Der Rand.(Ein bisschen größer als Nummer 2)
2 Rechteck: Eigentlicher Button.
Dann müsstest du dir nur überlegen wie du die Größe der Schrift berechnest, die man auch noch drauf schreiben lassen können müsste.
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
------------- Hauptprogramm -------------
my $container = X->new();
$GFXButton = X::GFXButton;
$container->GFXButton_add($id,$app,(65*$x),(25*$i),$img,$img2,$img3, 'loslos'); }}
$GFXButton->destroy_buttons($container);
------------- x.pm -------------
package X;
use X::GFXButton;
my $GFXButton = X::GFXButton;
#Erzeugen
sub new {
my ($class,@params) = @_;
my $self = {};
bless($self,$class);
$self->{BUTTS} = [];
return($self);
}
sub GFXButton_add
{return $GFXButton->new(@_);}
------------- GFXButton.pm -------------
#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);
}
#Bei MausUP Buttons normal zeichnen
sub buttons_up {
my ($self, $container) = @_;
for(@{$container->{BUTTS}})
{$_->{PRESSED} = 0; $_->draw($_->{IMG});}
}
#Buttons nicht mehr prüfen
sub destroy_buttons {
my ($self, $container) = @_;
$container->{BUTTS} = [];}
1;
![]() |
|< 1 2 3 4 >| | ![]() |
38 Einträge, 4 Seiten |