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