App-Asciio
view release on metacpan or search on metacpan
lib/App/Asciio/GTK/Asciio.pm view on Meta::CPAN
sub set_font
{
my ($self, $font_family, $font_size) = @_;
$self->SUPER::set_font($font_family, $font_size) ;
$self->{widget}->modify_font
(
Gtk2::Pango::FontDescription->from_string
(
$self->{FONT_FAMILY} . ' ' . $self->{FONT_SIZE}
)
);
}
#-----------------------------------------------------------------------------
sub update_display
{
my ($self) = @_;
$self->SUPER::update_display() ;
my $widget = $self->{widget} ;
$widget->queue_draw_area(0, 0, $widget->allocation->width,$widget->allocation->height);
}
#-----------------------------------------------------------------------------
sub configure_event
{
my ($widget, $event, $self) = @_;
$self->{PIXMAP} = Gtk2::Gdk::Pixmap->new
(
$widget->window,
$widget->allocation->width, $widget->allocation->height,
-1
);
$self->{WINDOW_SIZE} = [$widget->allocation->width, $widget->allocation->height] ;
$self->{PIXMAP}->draw_rectangle
(
$widget->get_style->base_gc ($widget->state),
TRUE, 0, 0, $widget->allocation->width,
$widget->allocation->height
);
return TRUE;
}
#-----------------------------------------------------------------------------
sub expose_event
{
my ($widget, $event, $self) = @_;
my $gc = Gtk2::Gdk::GC->new($self->{PIXMAP});
# draw background
$gc->set_foreground($self->get_color('background'));
$self->{PIXMAP}->draw_rectangle
(
$gc, TRUE,
0, 0,
$widget->allocation->width, $widget->allocation->height
);
my ($character_width, $character_height) = $self->get_character_size() ;
my ($widget_width, $widget_height) = $self->{PIXMAP}->get_size();
if($self->{DISPLAY_GRID})
{
$gc->set_foreground($self->get_color('grid'));
for my $horizontal (0 .. ($widget_height/$character_height) + 1)
{
$self->{PIXMAP}->draw_line
(
$gc,
0, $horizontal * $character_height,
$widget_width, $horizontal * $character_height
);
}
for my $vertical(0 .. ($widget_width/$character_width) + 1)
{
$self->{PIXMAP}->draw_line
(
$gc,
$vertical * $character_width, 0,
$vertical * $character_width, $widget_height
);
}
}
# draw elements
for my $element (@{$self->{ELEMENTS}})
{
my ($background_color, $foreground_color) = $element->get_colors() ;
if($self->is_element_selected($element))
{
if(exists $element->{GROUP} and defined $element->{GROUP}[-1])
{
$background_color =
$self->get_color
(
$self->{COLORS}{group_colors}[$element->{GROUP}[-1]{GROUP_COLOR}][0]
) ;
}
else
{
$background_color = $self->get_color('selected_element_background');
}
}
else
{
if(defined $background_color)
{
$background_color = $self->get_color($background_color) ;
}
else
{
if(exists $element->{GROUP} and defined $element->{GROUP}[-1])
{
$background_color =
$self->get_color
(
$self->{COLORS}{group_colors}[$element->{GROUP}[-1]{GROUP_COLOR}][1]
) ;
}
else
{
$background_color = $self->get_color('element_background') ;
}
}
}
$foreground_color =
defined $foreground_color
? $self->get_color($foreground_color)
: $self->get_color('element_foreground') ;
$gc->set_foreground($foreground_color);
for my $mask_and_element_strip ($element->get_mask_and_element_stripes())
{
$gc->set_foreground($background_color);
$self->{PIXMAP}->draw_rectangle
(
$gc,
$self->{OPAQUE_ELEMENTS},
($element->{X} + $mask_and_element_strip->{X_OFFSET}) * $character_width,
($element->{Y} + $mask_and_element_strip->{Y_OFFSET}) * $character_height,
$mask_and_element_strip->{WIDTH} * $character_width,
$mask_and_element_strip->{HEIGHT} * $character_height,
);
$gc->set_foreground($foreground_color);
my $layout = $widget->create_pango_layout($mask_and_element_strip->{TEXT}) ;
my ($text_width, $text_height) = $layout->get_pixel_size;
$self->{PIXMAP}->draw_layout
(
$gc,
($element->{X} + $mask_and_element_strip->{X_OFFSET}) * $character_width,
($element->{Y} + $mask_and_element_strip->{Y_OFFSET}) * $character_height,
$layout
);
}
}
# draw ruler lines
for my $line (@{$self->{RULER_LINES}})
{
my $color = Gtk2::Gdk::Color->new( map {$_ * 257} @{$line->{COLOR} }) ;
$self->{widget}->get_colormap->alloc_color($color,TRUE,TRUE) ;
$gc->set_foreground($color);
if($line->{TYPE} eq 'VERTICAL')
{
$self->{PIXMAP}->draw_line
(
$gc,
$line->{POSITION} * $character_width, 0,
$line->{POSITION} * $character_width, $widget_height
);
}
else
{
$self->{PIXMAP}->draw_line
(
$gc,
0, $line->{POSITION} * $character_height,
$widget_width, $line->{POSITION} * $character_height
);
}
}
# draw connections
my (%connected_connections, %connected_connectors) ;
for my $connection (@{$self->{CONNECTIONS}})
{
( run in 0.611 second using v1.01-cache-2.11-cpan-13bb782fe5a )