Re: Can't position Gnome2::Canvas within Gtk2::Frame

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.


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);

my $eBox = Gtk2::EventBox->new();
$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);



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);

  #Draw yellow line in middle.
  $cr->set_source_rgb(1, 1, 0);
  $cr->move_to(0, ($rectangle->height) / 2);
  $cr->line_to($rectangle->width, ($rectangle->height) / 2);

  #Draw frame.
  $cr->set_source_rgb(0, 0, 1);
  $cr->rectangle(0, 0, $rectangle->width, $rectangle->height);
  return FALSE;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]