package MTools::Widget::MSplitPane; # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU LGPL Libray General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU Library General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, # or refer to http://www.gnu.org/copyleft/lgpl.html # ################################################################## use strict; use MTools; use MTools::SVG::SVGLoader; use vars qw /@ISA/; use MTools::MGroup; use MTools::Widget::MBouton; use MTools::Comp::MMover; use MTools::Anim::MTranslator; use MTools::GUI::MClip; BEGIN { @ISA = qw /MTools::MGroup/; } sub new { my ($class, $parent, %options) = @_; my $self = new MTools::MGroup ($parent); bless $self, $class; $self -> recordProperty ('percentage', 0.00001); my $size = $options {size}; $self -> recordProperty ('size', $size); $self -> {__firstgp} = my $gp_first = $options {first_group}; $self -> {__secondgp} = my $gp_second = $options {second_group}; my $orientation = $options {orientation}? $options {orientation}:'vertical'; $self -> {__vertical} = my $vertical = $orientation eq 'vertical'; $self -> {__cursor_size} = $options {cursor_size}? $options {cursor_size}:'10'; if ($vertical) { new MTools::GUI::MClip ($gp_first, ['rectangle', -2, -1000, $size, 1000]); new MTools::GUI::MClip ($gp_second, ['rectangle', -2, -1000, $size, 1000]); } else { new MTools::GUI::MClip ($gp_first, ['rectangle', -1000, -2, 1000, $size]); new MTools::GUI::MClip ($gp_second, ['rectangle',-1000, -2, 1000, $size]); } $self -> {__curseur} = new MTools::MSwitch ( $self, on => [$options {cursor_on}], off => [$options {cursor_off}], ); $self -> {__mover} = my $mover = new MTools::Comp::MMover($self -> {__curseur}, $self, 1, x_min => 0, y_min => 0, x_max => $vertical ? $options {size} : 0, y_max => !$vertical ? $options {size} : 0, ); $self -> propagate ($mover, 'MOVED'); if ($options {with_buttons}) { my $bouton_open = new MTools::Widget::MBouton ( parent => $self, g_on => $options {button_open_on}, g_off => $options {button_open_off}, e_press => 'PRESS', e_release => 'OPEN', ); my $bouton_close = new MTools::Widget::MBouton ( parent => $self, g_on => $options {button_close_on}, g_off => $options {button_close_off}, e_press => 'PRESS', e_release => 'CLOSE', ); $self -> {__boutons} = new MTools::MSwitch ( $self, open => $bouton_open, close => $bouton_close, ); $self -> {__boutons} -> mconfigure ('state' => 'open'); $self -> {__anim_open} = new MTools::Anim::MTranslator ( from_x => 0, from_y => 0, to_x => $vertical * $options {size}, to_y => (!$vertical) * $options {size}, targets => $mover, duration => 0.5, ); $bouton_open -> binding ('OPEN', [$self, \&opening]); $bouton_close -> binding ('CLOSE', [$self, \&closing]); } $gp_first -> scale ( $vertical? 0.00001:1, !$vertical? 0.00001:1); $self -> {__old_val} = 0; $gp_second -> translate ($vertical * $self -> {__cursor_size}, (!$vertical) * $self -> {__cursor_size}); $mover -> binding ('MOVED', [$self, \&moved]); new MTools::MState ( current_state => 'on', events => { press => [$mover, 'PRESSED'], release => [$mover, 'RELEASED'], }, transitions => { on => { press => { to => 'off', }, }, off => { release => { to => 'on', }, }, }, switchs => [$self -> {__curseur}], ); return $self; } sub moved { my ($self, $x, $y) = @_; my $gp_first = $self -> {__firstgp}; my $gp_second = $self -> {__secondgp}; my $vertical = $self -> {__vertical}; my $val = $vertical ? $x : $y; my $size = $self -> mget ('size'); my $oldperc = $self -> mget ('percentage'); my $perc = $val / $size; my $operc = 1 - $perc; my $oldoperc = 1 - $oldperc; if ($perc < 0.00001) { $perc = 0.00001; } if ($operc < 0.00001) { $operc = 0.00001; } if ($oldoperc < 0.00001) { $oldoperc = 0.00001; } $gp_first -> scale ($vertical ? $perc / $oldperc : 1, !$vertical ? $perc / $oldperc : 1); my $trans = $val - $self -> {__old_val}; $gp_second -> translate ($vertical * $trans, (!$vertical) * $trans); my $pos = $val + $self -> {__cursor_size}; $gp_second -> scale ($vertical ? $operc / $oldoperc : 1, !$vertical ? $operc / $oldoperc : 1, $vertical * $pos, (!$vertical) * $pos); $self -> mconfigure ('percentage', $perc); $self -> {__old_val} = $val; if ($val > $size / 2) { $self -> {__boutons} -> mconfigure ('state' => 'close'); } else { $self -> {__boutons} -> mconfigure ('state' => 'open'); } } sub opening { my ($self) = @_; if ($self -> {__vertical}) { $self -> {__anim_open} -> mconfigure ( from_x => $self -> {__old_val}, to_x => $self -> mget ('size'), ); } else { $self -> {__anim_open} -> mconfigure ( from_y => $self -> {__old_val}, to_y => $self -> mget ('size'), ); } $self -> {__anim_open} -> start (); } sub closing { my ($self) = @_; if ($self -> {__vertical}) { $self -> {__anim_open} -> mconfigure ( from_x => $self -> {__old_val}, to_x => 0, ); } else { $self -> {__anim_open} -> mconfigure ( from_y => $self -> {__old_val}, to_y => 0, ); } $self -> {__anim_open} -> start (); } 1;