| 1 | package Gtk2::Ex::MindMapView::Border::Ellipse; | ||
| 2 | |||
| 3 | our $VERSION = '0.000001'; | ||
| 4 | |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 1 | ▶ | use List::Util; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 0 | ▶ | use Gnome2::Canvas; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | |||
| 13 | use Gtk2::Ex::MindMapView::ArgUtils; | ||
| 14 | |||
| 15 | use base 'Gtk2::Ex::MindMapView::Border'; | ||
| 16 | |||
| 17 | sub new | ||
| 18 | { | ||
| 19 | my $class = shift(@_); | ||
| 20 | |||
| 21 | my $self = $class->SUPER::new(@_); | ||
| 22 | |||
| 23 | my %attributes = @_; | ||
| 24 | |||
| 25 | args_valid(\%attributes, qw(group x y width height content width_pixels | ||
| 26 | padding_pixels fill_color_gdk outline_color_gdk)); | ||
| 27 | |||
| 28 | arg_default($self, "fill_color_gdk", Gtk2::Gdk::Color->parse('white')); | ||
| 29 | |||
| 30 | arg_default($self, "outline_color_gdk", Gtk2::Gdk::Color->parse('gray')); | ||
| 31 | |||
| 32 | $self->{border} = $self->border_get_image(); | ||
| 33 | |||
| 34 | $self->{content}->set(anchor=>'north-west'); | ||
| 35 | |||
| 36 | my ($top, $left, $bottom, $right) = $self->border_insets(); | ||
| 37 | |||
| 38 | my $content_width = $self->{content}->get('width'); | ||
| 39 | |||
| 40 | my $content_height = $self->{content}->get('height'); | ||
| 41 | |||
| 42 | my $width_adjust = List::Util::max($content_width * 1.5, ($left + $right)); | ||
| 43 | |||
| 44 | my $height_adjust = List::Util::max($content_height * 1.5, ($top + $bottom)); | ||
| 45 | |||
| 46 | $self->{width} = $content_width + $width_adjust; | ||
| 47 | |||
| 48 | $self->{height} = $content_height + $height_adjust; | ||
| 49 | |||
| 50 | return $self; | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | sub border_get_image | ||
| 55 | { | ||
| 56 | my $self = shift(@_); | ||
| 57 | |||
| 58 | return Gnome2::Canvas::Item->new($self->{group}, 'Gnome2::Canvas::Ellipse', | ||
| 59 | 'fill-color-gdk'=>$self->{fill_color_gdk}, | ||
| 60 | 'outline-color-gdk'=>$self->{outline_color_gdk}); | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | sub border_insets | ||
| 65 | { | ||
| 66 | my $self = shift(@_); | ||
| 67 | |||
| 68 | my $min_inset = $self->{width_pixels} + $self->{padding_pixels}; | ||
| 69 | |||
| 70 | my $top = List::Util::max($min_inset, $self->{height} / 4); | ||
| 71 | |||
| 72 | my $left = List::Util::max($min_inset, $self->{width} / 4); | ||
| 73 | |||
| 74 | return ($top, $left, $top, $left); | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | sub border_set_x | ||
| 79 | { | ||
| 80 | my ($self, $value) = @_; | ||
| 81 | |||
| 82 | $self->{border}->set(x1=>$value); | ||
| 83 | |||
| 84 | $self->{border}->set(x2=>$value + $self->{width}); | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | sub border_set_y | ||
| 89 | { | ||
| 90 | my ($self, $value) = @_; | ||
| 91 | |||
| 92 | $self->{border}->set(y1=>$value); | ||
| 93 | |||
| 94 | $self->{border}->set(y2=>$value + $self->{height}); | ||
| 95 | } | ||
| 96 | |||
| 97 | |||
| 98 | sub border_set_width | ||
| 99 | { | ||
| 100 | my ($self, $value) = @_; | ||
| 101 | |||
| 102 | $self->{border}->set(x2=>$self->{x} + $value); | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | sub border_set_height | ||
| 107 | { | ||
| 108 | my ($self, $value) = @_; | ||
| 109 | |||
| 110 | $self->{border}->set(y2=>$self->{y} + $value); | ||
| 111 | } | ||
| 112 | |||
| 113 | |||
| 114 | sub border_set_param | ||
| 115 | { | ||
| 116 | my ($self, $name, $value) = @_; | ||
| 117 | |||
| 118 | $self->{border}->set($name=>$value); | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
| 122 | 1; # Magic true value required at end of module | ||
| 123 | __END__ | ||