| 1 | package Finance::GeniusTrader::Graphics::Object::Text; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 4 | # This file is distributed under the terms of the General Public License | ||
| 5 | # version 2 or (at your option) any later version. | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use vars qw(@ISA); | ||
| 9 | @ISA = qw(Finance::GeniusTrader::Graphics::Object); | ||
| 10 | |||
| 11 | use Finance::GeniusTrader::Prices; | ||
| 12 | use Finance::GeniusTrader::Graphics::Object; | ||
| 13 | use Finance::GeniusTrader::Graphics::Driver; | ||
| 14 | use Finance::GeniusTrader::Graphics::Tools qw(:color); | ||
| 15 | use Finance::GeniusTrader::Conf; | ||
| 16 | |||
| 17 | Finance::GeniusTrader::Conf::default("Graphic::Text::Color", "black"); | ||
| 18 | |||
| 19 | =head1 Finance::GeniusTrader::Graphics::Object::Text | ||
| 20 | |||
| 21 | This graphical object displays a block of text. | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | sub init { | ||
| 26 | my ($self, $x, $y, $halign, $valign) = @_; | ||
| 27 | |||
| 28 | $halign = "left" if (! defined($halign)); | ||
| 29 | $valign = "top" if (! defined($valign)); | ||
| 30 | |||
| 31 | # Default values ... | ||
| 32 | $self->{'fg_color'} = get_color(Finance::GeniusTrader::Conf::get("Graphic::Text::Color")); | ||
| 33 | $self->{'x_pc'} = $x / 100; | ||
| 34 | $self->{'y_pc'} = $y / 100; | ||
| 35 | $self->set_horizontal_align($halign); | ||
| 36 | $self->set_vertical_align($valign); | ||
| 37 | $self->{'font_size'} = $FONT_SIZE_SMALL; | ||
| 38 | $self->{'font_face'} = $FONT_FIXED; | ||
| 39 | } | ||
| 40 | |||
| 41 | =head2 $o->set_horizontal_align($value) | ||
| 42 | |||
| 43 | =head2 $o->set_vertical_align($value) | ||
| 44 | |||
| 45 | =head2 $o->set_x_position($value_in_pc) | ||
| 46 | |||
| 47 | =head2 $o->set_y_position($value_in_pc) | ||
| 48 | |||
| 49 | =head2 $o->set_font_size($fontsize) | ||
| 50 | |||
| 51 | =head2 $o->set_font_face($font_face) | ||
| 52 | |||
| 53 | =cut | ||
| 54 | sub set_horizontal_align { | ||
| 55 | my ($self, $align) = @_; | ||
| 56 | if ($align =~ /middle|center/i) { | ||
| 57 | $self->{'halign'} = $ALIGN_CENTER; | ||
| 58 | } elsif ($align =~ /left/i) { | ||
| 59 | $self->{'halign'} = $ALIGN_LEFT; | ||
| 60 | } elsif ($align =~ /right/i) { | ||
| 61 | $self->{'halign'} = $ALIGN_RIGHT; | ||
| 62 | } else { | ||
| 63 | die "Bad alignment: $align !\n"; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | sub set_vertical_align { | ||
| 67 | my ($self, $align) = @_; | ||
| 68 | if ($align =~ /middle|center/i) { | ||
| 69 | $self->{'valign'} = $ALIGN_CENTER; | ||
| 70 | } elsif ($align =~ /top/i) { | ||
| 71 | $self->{'valign'} = $ALIGN_TOP; | ||
| 72 | } elsif ($align =~ /bottom/i) { | ||
| 73 | $self->{'valign'} = $ALIGN_BOTTOM; | ||
| 74 | } else { | ||
| 75 | die "Bad alignment: $align !\n"; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | sub set_x_position { $_[0]->{'x_pc'} = $_[1] / 100 } | ||
| 79 | sub set_y_position { $_[0]->{'y_pc'} = $_[1] / 100 } | ||
| 80 | sub set_font_size { $_[0]->{'font_size'} = $_[1] } | ||
| 81 | sub set_font_face { $_[0]->{'font_face'} = $_[1] } | ||
| 82 | |||
| 83 | sub display { | ||
| 84 | my ($self, $driver, $picture) = @_; | ||
| 85 | my $zone = $self->{'zone'}; | ||
| 86 | |||
| 87 | $driver->string($picture, $self->{'font_face'}, $self->{'font_size'}, | ||
| 88 | $self->{'fg_color'}, | ||
| 89 | $zone->absolute_coordinate($self->{'x_pc'} * $zone->width, | ||
| 90 | $self->{'y_pc'} * $zone->height), | ||
| 91 | $self->{'source'}, $self->{'halign'}, $self->{'valign'}, | ||
| 92 | $ORIENTATION_RIGHT); | ||
| 93 | } | ||
| 94 | |||
| 95 | 1; |