Re: Can't position Gnome2::Canvas within Gtk2::Frame
- From: cecashon aol com
- To: lestrol123 gmx com, gtk-perl-list gnome org
- Subject: Re: Can't position Gnome2::Canvas within Gtk2::Frame
- Date: Sat, 7 Oct 2017 15:39:59 -0400
Hi Les,
I am not familiar with the Gnome canvas but you could try this using an event box and drawing on that. That might be easier.
Eric
#!/usr/bin/perl
use strict;
use diagnostics;
use warnings;
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
# Draw a Gtk2 window
my $window = Gtk2::Window->new();
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_default_size(500, 500);
$window->set_border_width(5);
my $eBox = Gtk2::EventBox->new();
$eBox->set_app_paintable(TRUE);
$eBox->signal_connect('expose_event' => \&draw_event_box);
my $Label1 = Gtk2::Label->new("Label1");
$Label1->set_markup("<span foreground='green' font='25'>Label1</span>");
my $Label2 = Gtk2::Label->new("Label2");
$Label2->set_markup("<span foreground='red' font='25'>Label2</span>");
my $vBox = Gtk2::VBox->new(FALSE, 0);
$vBox->pack_start_defaults($Label1);
$vBox->pack_start_defaults($Label2);
$eBox->add($vBox);
$window->add($eBox);
$window->show_all();
Gtk2->main;
sub draw_event_box
{
my ($widget, $event, $user_data) = @_;
my $cr = Gtk2::Gdk::Cairo::Context->create( $widget->window );
my $rectangle = $widget->allocation;
#Paint background.
$cr->set_source_rgb(0, 1, 1);
$cr->paint;
#Draw yellow line in middle.
$cr->set_source_rgb(1, 1, 0);
$cr->set_line_width(10);
$cr->move_to(0, ($rectangle->height) / 2);
$cr->line_to($rectangle->width, ($rectangle->height) / 2);
$cr->stroke();
#Draw frame.
$cr->set_source_rgb(0, 0, 1);
$cr->set_line_width(15);
$cr->rectangle(0, 0, $rectangle->width, $rectangle->height);
$cr->stroke();
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]