diff options
author | caramel | 2007-08-24 12:46:09 +0000 |
---|---|---|
committer | caramel | 2007-08-24 12:46:09 +0000 |
commit | 9611f8deb6b7d665ee8caa87473cb7b0872a82af (patch) | |
tree | 323848e376526e50e2a05a3e901b80bd181ca177 /src/MTools | |
parent | e77e58d465ef29b1d774fce706dfa0b960323323 (diff) | |
download | mtc-9611f8deb6b7d665ee8caa87473cb7b0872a82af.zip mtc-9611f8deb6b7d665ee8caa87473cb7b0872a82af.tar.gz mtc-9611f8deb6b7d665ee8caa87473cb7b0872a82af.tar.bz2 mtc-9611f8deb6b7d665ee8caa87473cb7b0872a82af.tar.xz |
Modification du ToggleButton pour le rendre fonctionnel
Diffstat (limited to 'src/MTools')
-rw-r--r-- | src/MTools/Widget/MToggleBouton.pm | 162 |
1 files changed, 146 insertions, 16 deletions
diff --git a/src/MTools/Widget/MToggleBouton.pm b/src/MTools/Widget/MToggleBouton.pm index 57f90d3..cc13fec 100644 --- a/src/MTools/Widget/MToggleBouton.pm +++ b/src/MTools/Widget/MToggleBouton.pm @@ -34,34 +34,137 @@ sub new { my $self = new MTools::GUI::MGroup ($options {parent}); bless $self, $class; - - my $on = $options {g_on}; - my $off = $options {g_off}; - my $eventOn = $options {e_press}; - my $eventOff = $options {e_release}; - + + my $on1 = minstance ($options {g_on1}, $self); + my $off1 = minstance ($options {g_off1}, $self); + my $over1 = defined $options {g_over1} ? minstance ($options {g_over1}, $self) : $on1; + my $on2 = minstance ($options {g_on2}, $self); + my $off2 = minstance ($options {g_off2}, $self); + my $over2 = defined $options {g_over2} ? minstance ($options {g_over2}, $self) : $on2; + + my $eventOn = defined $options {e_press} ? $options {e_press} : 'PRESS'; + my $eventOff = defined $options {e_release} ? $options {e_release} : 'RELEASED'; + my $cb = $options {call} if (defined $options {call}); + + my @gon1; + push (@gon1, $on1); + my @goff1; + push (@goff1, $off1); + my @gover1; + push (@gover1, $over1); + my @gon2; + push (@gon2, $on2); + my @goff2; + push (@goff2, $off2); + my @gover2; + push (@gover2, $over2); + + if (defined $options {g_text1}) + { + $self -> recordProperty ('text1', $options {text1}); + my $txt1 = minstance ($options {g_text1}, $self); + push (@gon1, $txt1); + push (@goff1, $txt1); + push (@gover1, $txt1); + plink ([$self, 'text1'], [$txt1, '-text1']); + } + if (defined $options {g_text2}) + { + $self -> recordProperty ('text2', $options {text2}); + my $txt2 = minstance ($options {g_text2}, $self); + push (@gon2, $txt2); + push (@goff2, $txt2); + push (@gover2, $txt2); + plink ([$self, 'text2'], [$txt2, '-text2']); + } + + + $self -> {gp_over} = new MTools::GUI::MGroup ($self); + push (@gon1, $self -> {gp_over}); + push (@goff1, $self -> {gp_over}); + push (@gover1, $self -> {gp_over}); + push (@gon2, $self -> {gp_over}); + push (@goff2, $self -> {gp_over}); + push (@gover2, $self -> {gp_over}); + + +# my $timer = new MTools::MTimer (5, 1); +# my @gon_tmp = @gon; +# push (@gon_tmp, $timer); + + + my $sw = new MTools::MSwitch ( $self, - on => [$on], - off => [$off], + 'idle1' => \@gon1, + 'hover1' => \@gover1, + 'pressed1' => \@goff1, + 'idle2' => \@gon2, + 'hover2' => \@gover2, + 'pressed2' => \@goff2, ); my $st = new MTools::MState ( - current_state => 'on', + current_state => 'idle1', events => { - press => [$sw, '<Button-1>'], + press => [$self, '<Button-1>'], + release => [$self, '<ButtonRelease-1>'], + enter => [$self, '<Enter>'], + leave => [$self, '<Leave>'], }, transitions => { - on => { - press => { - to => 'off', + 'idle1' => { + 'enter' => { + to => 'hover1', + }, + 'press' => { + to => 'pressed1', + notify => $eventOn, + }, + }, + 'hover1' => { + 'press' => { + to => 'pressed1', notify => $eventOn, }, + 'leave' => { + to => 'idle1', + } }, - off => { - press => { - to => 'on', + 'pressed1' => { + 'release' => { + to => 'hover2', notify => $eventOff, }, + 'leave' => { + to => 'idle1', + } + }, + 'idle2' => { + 'enter' => { + to => 'hover2', + }, + 'press' => { + to => 'pressed2', + notify => $eventOn, + }, + }, + 'hover2' => { + 'press' => { + to => 'pressed2', + notify => $eventOn, + }, + 'leave' => { + to => 'idle2', + } + }, + 'pressed2' => { + 'release' => { + to => 'hover1', + notify => $eventOff, + }, + 'leave' => { + to => 'idle2', + } }, }, switchs => [$sw], @@ -70,6 +173,33 @@ sub new { $self -> propagate ($st, $eventOn); $self -> propagate ($st, $eventOff); + if (defined $cb) + { + $st -> binding ($eventOn, sub { + executer ($cb); + }); + } + + $self -> propagate ($st, $eventOn); + $self -> propagate ($st, $eventOff); + + delete $options {g_on1} if defined $options {g_on1}; + delete $options {g_off1} if defined $options {g_off1}; + delete $options {g_over1} if defined $options {g_over1}; + delete $options {g_on2} if defined $options {g_on2}; + delete $options {g_off2} if defined $options {g_off2}; + delete $options {g_over2} if defined $options {g_over2}; + delete $options {e_press} if defined $options {e_press}; + delete $options {e_release} if defined $options {e_release}; + delete $options {call} if defined $options {call}; + delete $options {text1} if defined $options {text1}; + delete $options {g_text1} if defined $options {g_text1}; + delete $options {text2} if defined $options {text2}; + delete $options {g_text2} if defined $options {g_text2}; + delete $options {parent} if defined $options {parent}; + $self -> mconfigure (%options); + + return $self; } |