| 1 | package Ogre::BetaGUI::TextInput; | ||
| 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, $Value, $length, $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 | value => $Value, | ||
| 30 | length => $length, | ||
| 31 | }, $pkg; | ||
| 32 | |||
| 33 | my $ma = Ogre::MaterialManager->getSingletonPtr->getByName($self->{mmn} . ".active"); | ||
| 34 | $self->{mma} .= ".active" if defined $ma; | ||
| 35 | |||
| 36 | $self->{mO} = $parent->{mGUI}->createOverlay($parent->{mO}->getName . "t" . $parent->{mGUI}{tc}, | ||
| 37 | [$self->{'x'}, $self->{'y'}], | ||
| 38 | [$self->{'w'}, $self->{'h'}], | ||
| 39 | $Material, '', 0); | ||
| 40 | $parent->{mGUI}{tc}++; | ||
| 41 | $self->{mCP} = $parent->{mGUI}->createOverlay($self->{mO}->getName . "c", | ||
| 42 | [4, (($self->{'h'} - $parent->{mGUI}{mFontSize}) / 2)], | ||
| 43 | [$self->{'w'}, $self->{'h'}], | ||
| 44 | '', $Value, 0); | ||
| 45 | |||
| 46 | $parent->{mO}->addChild($self->{mO}); | ||
| 47 | $self->{mO}->show(); | ||
| 48 | $self->{mO}->addChild($self->{mCP}); | ||
| 49 | $self->{mCP}->show(); | ||
| 50 | |||
| 51 | return $self; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub getValue { $_[0]->{value} } | ||
| 55 | |||
| 56 | sub setValue { | ||
| 57 | my ($self, $v) = @_; | ||
| 58 | |||
| 59 | $self->{value} = $v; | ||
| 60 | $self->{mCP}->setCaption($v); | ||
| 61 | } | ||
| 62 | |||
| 63 | sub in { | ||
| 64 | my ($self, $mx, $my, $px, $py) = @_; | ||
| 65 | return !($mx >= $self->{'x'} + $px && $my >= $self->{'y'} + $py) | ||
| 66 | || !($mx <= $self->{'x'} + $px + $self->{'w'} && $my <= $self->{'y'} + $py + $self->{'h'}); | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | 1; |