| 1 | package Gtk2::Ex::MindMapView::ItemFactory; | ||
| 2 | |||
| 3 | our $VERSION = '0.000001'; | ||
| 4 | |||
| 5 | 9 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 9 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 9 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 0 | ▶ | use Gtk2::Ex::MindMapView::ContentFactory; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use Gtk2::Ex::MindMapView::BorderFactory; | ||
| 11 | use Gtk2::Ex::MindMapView::HotSpot::ToggleFactory; | ||
| 12 | use Gtk2::Ex::MindMapView::HotSpot::GripFactory; | ||
| 13 | |||
| 14 | use Gtk2::Ex::MindMapView::Item; | ||
| 15 | |||
| 16 | use Gtk2::Ex::MindMapView::ArgUtils; | ||
| 17 | |||
| 18 | use List::Util; | ||
| 19 | |||
| 20 | use Glib ':constants'; | ||
| 21 | |||
| 22 | sub new | ||
| 23 | { | ||
| 24 | my $class = shift(@_); | ||
| 25 | |||
| 26 | my @attributes = @_; | ||
| 27 | |||
| 28 | my $self = {}; | ||
| 29 | |||
| 30 | bless $self, $class; | ||
| 31 | |||
| 32 | my %attributes = @attributes; | ||
| 33 | |||
| 34 | args_valid(\%attributes, qw(view font_desc fill_color_gdk text_color_gdk | ||
| 35 | outline_color_gdk hotspot_color_gdk)); | ||
| 36 | |||
| 37 | args_required(\%attributes, qw(view)); | ||
| 38 | |||
| 39 | args_store($self, \%attributes); | ||
| 40 | |||
| 41 | if (!($self->{view}->isa('Gtk2::Ex::MindMapView'))) | ||
| 42 | { | ||
| 43 | carp "Invalid Gtk2::Ex::MindMapView argument.\n"; | ||
| 44 | } | ||
| 45 | |||
| 46 | arg_default($self, "font_desc", | ||
| 47 | Gtk2::Pango::FontDescription->from_string("Ariel Normal 10")); | ||
| 48 | |||
| 49 | arg_default($self, "fill_color_gdk", Gtk2::Gdk::Color->parse('white')); | ||
| 50 | |||
| 51 | arg_default($self, "text_color_gdk", Gtk2::Gdk::Color->parse('black')); | ||
| 52 | |||
| 53 | arg_default($self, "outline_color_gdk", Gtk2::Gdk::Color->parse('gray')); | ||
| 54 | |||
| 55 | arg_default($self, "hotspot_color_gdk", Gtk2::Gdk::Color->parse('orange')); | ||
| 56 | |||
| 57 | $self->{content_factory} = | ||
| 58 | Gtk2::Ex::MindMapView::ContentFactory->new(view=>$self->{view}); | ||
| 59 | |||
| 60 | $self->{border_factory} = | ||
| 61 | Gtk2::Ex::MindMapView::BorderFactory->new(view=>$self->{view}); | ||
| 62 | |||
| 63 | $self->{grip_factory} = Gtk2::Ex::MindMapView::HotSpot::GripFactory->new(); | ||
| 64 | |||
| 65 | $self->{toggle_factory} = Gtk2::Ex::MindMapView::HotSpot::ToggleFactory->new(); | ||
| 66 | |||
| 67 | return $self; | ||
| 68 | } | ||
| 69 | |||
| 70 | |||
| 71 | sub create_item | ||
| 72 | { | ||
| 73 | my ($self, @attributes) = @_; | ||
| 74 | |||
| 75 | my %attributes = @attributes; | ||
| 76 | |||
| 77 | args_valid(\%attributes, qw(border content text browser uri pixbuf | ||
| 78 | font_desc fill_color_gdk text_color_gdk | ||
| 79 | outline_color_gdk hotspot_color_gdk)); | ||
| 80 | |||
| 81 | args_required(\%attributes, qw(border content)); | ||
| 82 | |||
| 83 | my $border_type = $attributes{border}; | ||
| 84 | |||
| 85 | my $content_type = $attributes{content}; | ||
| 86 | |||
| 87 | my $text = $attributes{text}; | ||
| 88 | |||
| 89 | my $browser = $attributes{browser}; | ||
| 90 | |||
| 91 | my $uri = $attributes{uri}; | ||
| 92 | |||
| 93 | my $pixbuf = $attributes{pixbuf}; | ||
| 94 | |||
| 95 | my $font_desc = (defined $attributes{font_desc}) ? | ||
| 96 | $attributes{font_desc} : $self->{font_desc}; | ||
| 97 | |||
| 98 | my $fill_color_gdk = (defined $attributes{fill_color_gdk}) ? | ||
| 99 | $attributes{fill_color_gdk} : $self->{fill_color_gdk}; | ||
| 100 | |||
| 101 | my $text_color_gdk = (defined $attributes{text_color_gdk}) ? | ||
| 102 | $attributes{text_color_gdk} : $self->{text_color_gdk}; | ||
| 103 | |||
| 104 | my $outline_color_gdk = (defined $attributes{outline_color_gdk}) ? | ||
| 105 | $attributes{outline_color_gdk} : $self->{outline_color_gdk}; | ||
| 106 | |||
| 107 | my $hotspot_color_gdk = (defined $attributes{hotspot_color_gdk}) ? | ||
| 108 | $attributes{hotspot_color_gdk} : $self->{hotspot_color_gdk}; | ||
| 109 | |||
| 110 | my $content = $self->{content_factory}->create_content( | ||
| 111 | type=>$content_type, browser=>$browser, | ||
| 112 | text=>$text, uri=>$uri, pixbuf=>$pixbuf, | ||
| 113 | font_desc=>$font_desc, | ||
| 114 | text_color_gdk=>$text_color_gdk); | ||
| 115 | |||
| 116 | my $border = $self->{border_factory}->create_border( | ||
| 117 | type=>$border_type, | ||
| 118 | content=>$content, | ||
| 119 | fill_color_gdk=>$fill_color_gdk, | ||
| 120 | outline_color_gdk=>$outline_color_gdk); | ||
| 121 | |||
| 122 | my $item = Gnome2::Canvas::Item->new( | ||
| 123 | $self->{view}->root, | ||
| 124 | 'Gtk2::Ex::MindMapView::Item', | ||
| 125 | border=>$border, | ||
| 126 | x=>0, y=>0); | ||
| 127 | |||
| 128 | my $hotspot1 = $self->{grip_factory}->create_grip( | ||
| 129 | item=>$item, | ||
| 130 | border=>$border, | ||
| 131 | side=>'left', | ||
| 132 | fill_color_gdk=>$fill_color_gdk, | ||
| 133 | hotspot_color_gdk=>$hotspot_color_gdk); | ||
| 134 | |||
| 135 | my $hotspot2 = $self->{grip_factory}->create_grip( | ||
| 136 | item=>$item, | ||
| 137 | border=>$border, | ||
| 138 | side=>'right', | ||
| 139 | fill_color_gdk=>$fill_color_gdk, | ||
| 140 | hotspot_color_gdk=>$hotspot_color_gdk); | ||
| 141 | |||
| 142 | my $hotspot3 = $self->{toggle_factory}->create_toggle( | ||
| 143 | item=>$item, | ||
| 144 | border=>$border, | ||
| 145 | side=>'left', | ||
| 146 | fill_color_gdk=>$fill_color_gdk, | ||
| 147 | outline_color_gdk=>$outline_color_gdk, | ||
| 148 | hotspot_color_gdk=>$hotspot_color_gdk); | ||
| 149 | |||
| 150 | my $hotspot4 = $self->{toggle_factory}->create_toggle( | ||
| 151 | item=>$item, | ||
| 152 | border=>$border, | ||
| 153 | side=>'right', | ||
| 154 | fill_color_gdk=>$fill_color_gdk, | ||
| 155 | outline_color_gdk=>$outline_color_gdk, | ||
| 156 | hotspot_color_gdk=>$hotspot_color_gdk); | ||
| 157 | |||
| 158 | $item->add_hotspot('lower_left', $hotspot1); | ||
| 159 | |||
| 160 | $item->add_hotspot('lower_right', $hotspot2); | ||
| 161 | |||
| 162 | $item->add_hotspot('toggle_left', $hotspot3); | ||
| 163 | |||
| 164 | $item->add_hotspot('toggle_right', $hotspot4); | ||
| 165 | |||
| 166 | return $item; | ||
| 167 | } | ||
| 168 | |||
| 169 | |||
| 170 | 1; # Magic true value required at end of module | ||
| 171 | __END__ | ||