| 1 | package Ogre::BetaGUI::Button; | ||
| 2 | |||
| 3 | ### Note: this was ported to Perl from: | ||
| 4 | # /// Betajaen's GUI 016 Uncompressed | ||
| 5 | # /// Written by Robin "Betajaen" Southern 07-Nov-2006, http://www.ogre3d.org/wiki/index.php/BetaGUI | ||
| 6 | # /// This code is under the Whatevar! licence. Do what you want; but keep the original copyright header. | ||
| 7 | ### | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use warnings; | ||
| 11 | |||
| 12 | use Ogre 0.33; | ||
| 13 | use Ogre::MaterialManager; | ||
| 14 | |||
| 15 | |||
| 16 | # note: $Dimensions is an array ref with 4 values (Vector4) | ||
| 17 | sub new { | ||
| 18 | my ($pkg, $Dimensions, $Material, $Text, $callback, $parent) = @_; | ||
| 19 | |||
| 20 | my $self = bless { | ||
| 21 | 'x' => $Dimensions->[0], # x | ||
| 22 | 'y' => $Dimensions->[1], # y | ||
| 23 | 'w' => $Dimensions->[2], # z | ||
| 24 | 'h' => $Dimensions->[3], # w | ||
| 25 | mO => undef, # OverlayContainer * | ||
| 26 | mCP => undef, # OverlayContainer * (caption) | ||
| 27 | mmn => $Material, # material name normal | ||
| 28 | mma => $Material, # material name active | ||
| 29 | callback => $callback, # BetaGUI::Callback | ||
| 30 | }, $pkg; | ||
| 31 | |||
| 32 | my $ma = Ogre::MaterialManager->getSingletonPtr->getByName($self->{mmn} . ".active"); | ||
| 33 | $self->{mma} .= ".active" if defined $ma; | ||
| 34 | |||
| 35 | $self->{mO} = $parent->{mGUI}->createOverlay($parent->{mO}->getName . "b" . $parent->{mGUI}{bc}, | ||
| 36 | [$self->{'x'}, $self->{'y'}], | ||
| 37 | [$self->{'w'}, $self->{'h'}], | ||
| 38 | $Material, '', 0); | ||
| 39 | $parent->{mGUI}{bc}++; | ||
| 40 | $self->{mCP} = $parent->{mGUI}->createOverlay($self->{mO}->getName . "c", | ||
| 41 | [4, (($self->{'h'} - $parent->{mGUI}{mFontSize}) / 2)], | ||
| 42 | [$self->{'w'}, $self->{'h'}], | ||
| 43 | '', $Text, 0); | ||
| 44 | |||
| 45 | $parent->{mO}->addChild($self->{mO}); | ||
| 46 | $self->{mO}->show(); | ||
| 47 | $self->{mO}->addChild($self->{mCP}); | ||
| 48 | $self->{mCP}->show(); | ||
| 49 | |||
| 50 | return $self; | ||
| 51 | } | ||
| 52 | |||
| 53 | sub DESTROY { | ||
| 54 | my ($self) = @_; | ||
| 55 | |||
| 56 | # I have problems all the time with DESTROY in Perl.... | ||
| 57 | # $self->{mO}->getParent->removeChild($self->{mO}->getName) | ||
| 58 | # if defined $self->{mO}; | ||
| 59 | # $self->{mCP}->getParent->removeChild($self->{mCP}->getName) | ||
| 60 | # if defined $self->{mCP}; | ||
| 61 | } | ||
| 62 | |||
| 63 | sub activate { | ||
| 64 | my ($self, $a) = @_; | ||
| 65 | |||
| 66 | $self->{mO}->setMaterialName($self->{mmn}) if !$a && $self->{mmn} ne ''; | ||
| 67 | |||
| 68 | $self->{mO}->setMaterialName($self->{mma}) if $a && $self->{mma} ne ''; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub in { | ||
| 72 | my ($self, $mx, $my, $px, $py) = @_; | ||
| 73 | return !($mx >= $self->{'x'} + $px && $my >= $self->{'y'} + $py) | ||
| 74 | || !($mx <= $self->{'x'} + $px + $self->{'w'} && $my <= $self->{'y'} + $py + $self->{'h'}); | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | 1; |