Habe nun das Ganze in einen Container implementiert... :-)
Es gibt aber noch Probleme..
1. wie spreche ich eleganter die allgemeinen subs in X::GFXButton an?
2. kann ich die rückreferenz auf den container(X) besser machen?
Codeteile:
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} = [];}
z.b. soll im X::GFXButton
die sub destroy_buttons
aufgerufen werden..
Das Problem ist, das ich kein Objekt habe..
im Hauptcode steht der Aufruf:
$GFXButton->destroy_buttons($container);
somit ist in der sub destroy_buttons das $self sinnlos
und ich muss:
1. container wieder mitgeben
2. mir mit der Variable $GFXButton aushelfen
was problematisch ist, denn wenn ich
im X.pm
statt "sub GFX_Button_add" nur "sub GFX_Button" mache, gibts probleme...\n\n
<!--EDIT|master|1144329507-->
$i='re5tsFam ^l\rep';$i=~s/[^a-z| ]//g;$\= reverse "\U!$i";print;