« blib/lib/Gtk2/Ex/MindMapView/HotSpot/ToggleFactory.pm
↑ Summary
blib/lib/Gtk2/Ex/MindMapView/Content.pm »
| 1 | package Gtk2::Ex::MindMapView::HotSpot::GripFactory; | ||
| 2 | |||
| 3 | our $VERSION = '0.000001'; | ||
| 4 | |||
| 5 | use warnings; | ||
| 6 | use strict; | ||
| 7 | use Carp; | ||
| 8 | |||
| 9 | use Gtk2::Ex::MindMapView::HotSpot::Grip::Round; | ||
| 10 | use Gtk2::Ex::MindMapView::HotSpot::Grip::Lentil; | ||
| 11 | use Gtk2::Ex::MindMapView::HotSpot::Grip::RightAngle; | ||
| 12 | use Gtk2::Ex::MindMapView::HotSpot::Grip::EllipseRound; | ||
| 13 | |||
| 14 | use Gtk2::Ex::MindMapView::ArgUtils; | ||
| 15 | |||
| 16 | use List::Util; | ||
| 17 | |||
| 18 | use Glib ':constants'; | ||
| 19 | |||
| 20 | sub new | ||
| 21 | { | ||
| 22 | my $class = shift(@_); | ||
| 23 | |||
| 24 | my @attributes = @_; | ||
| 25 | |||
| 26 | my $self = {}; | ||
| 27 | |||
| 28 | bless $self, $class; | ||
| 29 | |||
| 30 | my %attributes = @attributes; | ||
| 31 | |||
| 32 | args_valid(\%attributes, qw(fill_color_gdk hotspot_color_gdk)); | ||
| 33 | |||
| 34 | args_store($self, \%attributes); | ||
| 35 | |||
| 36 | arg_default($self, "fill_color_gdk", Gtk2::Gdk::Color->parse('white')); | ||
| 37 | |||
| 38 | arg_default($self, "hotspot_color_gdk", Gtk2::Gdk::Color->parse('orange')); | ||
| 39 | |||
| 40 | return $self; | ||
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | sub create_grip | ||
| 45 | { | ||
| 46 | my ($self, @attributes) = @_; | ||
| 47 | |||
| 48 | my %attributes = @attributes; | ||
| 49 | |||
| 50 | args_valid(\%attributes, qw(item border side fill_color_gdk hotspot_color_gdk)); | ||
| 51 | |||
| 52 | args_required(\%attributes, qw(item border side)); | ||
| 53 | |||
| 54 | my $item = $attributes{item}; | ||
| 55 | |||
| 56 | if (!$item->isa('Gtk2::Ex::MindMapView::Item')) | ||
| 57 | { | ||
| 58 | croak "Invalid item. Item must be a 'Gtk2::Ex::MindMapView::Item'.\n"; | ||
| 59 | } | ||
| 60 | |||
| 61 | my $side = $attributes{side}; | ||
| 62 | |||
| 63 | if (!grep { $_ eq $side } qw(right left)) | ||
| 64 | { | ||
| 65 | croak "Invalid side. Must be 'right' or 'left'.\n"; | ||
| 66 | } | ||
| 67 | |||
| 68 | my $border = $attributes{border}; | ||
| 69 | |||
| 70 | my $fill_color_gdk = (defined $attributes{fill_color_gdk}) ? | ||
| 71 | $attributes{fill_color_gdk} : $self->{fill_color_gdk}; | ||
| 72 | |||
| 73 | my $hotspot_color_gdk = (defined $attributes{hotspot_color_gdk}) ? | ||
| 74 | $attributes{hotspot_color_gdk} : $self->{hotspot_color_gdk}; | ||
| 75 | |||
| 76 | my $color_gdk = ($side eq 'right') ? $hotspot_color_gdk : $fill_color_gdk; | ||
| 77 | |||
| 78 | if ($border->isa('Gtk2::Ex::MindMapView::Border::Ellipse')) | ||
| 79 | { | ||
| 80 | return Gtk2::Ex::MindMapView::HotSpot::Grip::EllipseRound->new( | ||
| 81 | item=>$item, side=>$side, | ||
| 82 | hotspot_color_gdk=>$hotspot_color_gdk, | ||
| 83 | outline_color_gdk=>$fill_color_gdk, | ||
| 84 | fill_color_gdk=>$color_gdk, | ||
| 85 | enabled=>TRUE); | ||
| 86 | } | ||
| 87 | |||
| 88 | if ($border->isa('Gtk2::Ex::MindMapView::Border::RoundedRect')) | ||
| 89 | { | ||
| 90 | return Gtk2::Ex::MindMapView::HotSpot::Grip::Lentil->new( | ||
| 91 | item=>$item, side=>$side, | ||
| 92 | hotspot_color_gdk=>$hotspot_color_gdk, | ||
| 93 | outline_color_gdk=>$fill_color_gdk, | ||
| 94 | fill_color_gdk=>$color_gdk, | ||
| 95 | enabled=>TRUE); | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 99 | if ($border->isa('Gtk2::Ex::MindMapView::Border::Rectangle')) | ||
| 100 | { | ||
| 101 | return Gtk2::Ex::MindMapView::HotSpot::Grip::RightAngle->new( | ||
| 102 | item=>$item, side=>$side, | ||
| 103 | hotspot_color_gdk=>$hotspot_color_gdk, | ||
| 104 | outline_color_gdk=>$fill_color_gdk, | ||
| 105 | fill_color_gdk=>$color_gdk, | ||
| 106 | enabled=>TRUE); | ||
| 107 | } | ||
| 108 | |||
| 109 | croak "Cannot make grip. Unexpected border: $border\n"; | ||
| 110 | } | ||
| 111 | |||
| 112 | |||
| 113 | 1; # Magic true value required at end of module | ||
| 114 | __END__ |