Skip to content

Commit

Permalink
GUI: Start shift to GooCanvas2
Browse files Browse the repository at this point in the history
Still very incomplete

Updates #771
  • Loading branch information
shawnlaffan committed Nov 5, 2020
1 parent 0c0ab73 commit 0e48935
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 58 deletions.
6 changes: 6 additions & 0 deletions bin/BiodiverseGUI_gtk3.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
use warnings;
use Carp;

BEGIN {
use Path::Tiny qw /path/;
use Env qw /@PATH/;
push @PATH, path($^X)->parent->parent->parent->child ('c/bin')->stringify;
}

use 5.022;

#use File::Basename;
Expand Down
80 changes: 41 additions & 39 deletions lib/Biodiverse/GUI/Grid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ sub new {
'fill-color' => 'white',
);
#$rect->lower_to_bottom();
##FIXME
$self->{canvas}->get_root_item->signal_connect_swapped (
event => \&on_background_event,
$self,
);
##FIXME CHECK CHECK
#$self->{canvas}->get_root_item->signal_connect_swapped (
# event => \&on_background_event,
# $self,
#);

$self->{back_rect} = $rect;
# Create the Label legend
Expand Down Expand Up @@ -262,7 +262,8 @@ sub destroy {
$self->{shapefile_group}->destroy();
}
if ($self->{cells_group}) {
$self->{cells_group}->destroy();
delete $self->{cells_group}; # mem leak? GooCanvas2 has no destroy method, but perhaps it GCs itself
#$self->{cells_group}->destroy();
}

# Destroy the legend group.
Expand Down Expand Up @@ -464,9 +465,8 @@ sub set_base_struct {
}

# Make group so we can transform everything together
my $cells_group = GooCanvas2::CanvasItem->new (
$self->{canvas}->root,
'GooCanvas2::CanvasGroup',
my $cells_group = GooCanvas2::CanvasGroup->new (
parent => $self->{canvas}->get_root_item,
x => 0,
y => 0,
);
Expand Down Expand Up @@ -494,7 +494,7 @@ sub set_base_struct {
#);

$self->{cells_group} = $cells_group;
$cells_group->lower_to_bottom();
#$cells_group->lower(); ## CHECK CHECK

my $i = 0;
foreach my $element (keys %$elts) {
Expand All @@ -519,27 +519,26 @@ sub set_base_struct {
my $ycoord = $y * $cell_size_y - $cell_size_y / 2;

# Make container group ("cell") for the rectangle and any marks
my $container = GooCanvas2::CanvasItem->new (
$cells_group,
'GooCanvas2::CanvasGroup',
my $container = GooCanvas2::CanvasGroup->new (
parent => $cells_group,
x => $xcoord,
y => $ycoord
);

# (all coords now relative to the group)
my $rect = GooCanvas2::CanvasItem->new (
$container,
'GooCanvas2::CanvasRect',
x1 => 0,
y1 => 0,
x2 => CELL_SIZE_X,
y2 => $cell_size_y,
fill_color_gdk => COLOUR_WHITE,
outline_color_gdk => COLOUR_BLACK,
width_pixels => $width_pixels
my $rect = GooCanvas2::CanvasRect->new (
parent => $container,
x => 0,
y => 0,
width => CELL_SIZE_X,
height => $cell_size_y,
'fill-color' => 'white',
'stroke-color' => 'black',
'line-width' => $width_pixels
);

$container->signal_connect_swapped (event => \&on_event, $self);
## CHECK CHECK
#$container->signal_connect_swapped (event => \&on_event, $self);

$self->{cells}{$container}[INDEX_COLOUR] = COLOUR_WHITE;
$self->{cells}{$container}[INDEX_ELEMENT] = $element;
Expand Down Expand Up @@ -576,22 +575,25 @@ sub set_base_struct {
$self->{width_units} = $width + 2*BORDER_SIZE;
$self->{height_units} = $height + 4*BORDER_SIZE;

$cells_group->affine_absolute([
1,
0,
0,
-1,
#my $tfm = $cells_group->set_transform;

my $cairo_mx = Cairo::Matrix->init (
1, 0,
0, -1,
BORDER_SIZE,
$height + 2*BORDER_SIZE,
]);

# Set visible region
$self->{canvas}->set_scroll_region(
0,
0,
$self->{width_units},
$self->{height_units},
);
# this seg faults
#$cells_group->set_transform($cairo_mx);

# Set visible region
# Needed for GooCanvas?
#$self->{canvas}->set_scroll_region(
# 0,
# 0,
# $self->{width_units},
# $self->{height_units},
#);

# Update
$self->setup_scrollbars();
Expand Down Expand Up @@ -1527,8 +1529,8 @@ sub on_event {
# Implements resizing
sub on_size_allocate {
my ($self, $size, $canvas) = @_;
$self->{width_px} = $size->width;
$self->{height_px} = $size->height;
$self->{width_px} = $size->{width};
$self->{height_px} = $size->{height};

if (exists $self->{width_units}) {
if ($self->get_zoom_fit_flag) {
Expand Down
34 changes: 15 additions & 19 deletions lib/Biodiverse/GUI/Legend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,15 @@ sub new {
$self->{width_px} || 0,
$self->{height_px} || 0,
);
say "xxxxx $width, $height";

# Make group so we can pack the coloured
# rectangles into it.
$self->{legend_group} = GooCanvas2::CanvasItem->new (
$self->{legend_group} = GooCanvas2::CanvasGroup->new (
parent => $self->{canvas}->get_root_item,
x => $width - $self->get_width,
y => 0,
);
$self->{legend_group}->raise_to_top();
#$self->{legend_group}->raise(); # might yet need this

# Create the legend rectangle.
$self->{legend} = $self->make_rect();
Expand Down Expand Up @@ -146,9 +145,8 @@ sub make_rect {

# Make a group so we can pack the coloured
# rectangles into it to create the legend.
$self->{legend_colours_group} = GooCanvas2::CanvasItem->new (
$self->{legend_group},
'GooCanvas2::CanvasGroup',
$self->{legend_colours_group} = GooCanvas2::CanvasGroup->new (
parent => $self->{legend_group},
x => 0,
y => 0,
);
Expand Down Expand Up @@ -213,14 +211,13 @@ sub add_row {

my $width = $self->get_width;

my $legend_colour_row = GooCanvas2::CanvasItem->new (
$group,
'GooCanvas2::CanvasRect',
x1 => 0,
x2 => $width,
y1 => $row,
y2 => $row+1,
fill_color_gdk => [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $r,$g,$b)]->[1],
my $legend_colour_row = GooCanvas2::CanvasRect->new (
parent => $group,
x => 0,
y => $row,
width => $width,
height => $row+1,
'fill-color' => [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $r,$g,$b)]->[1],
);
}

Expand All @@ -231,15 +228,14 @@ sub add_row {
sub make_mark {
my $self = shift;
my $anchor = shift;
my $mark = GooCanvas2::CanvasItem->new (
$self->{legend_group},
'GooCanvas2::CanvasText',
my $mark = GooCanvas2::CanvasText->new (
parent => $self->{legend_group},
text => q{0},
anchor => $anchor,
fill_color_gdk => COLOUR_BLACK,
'fill-color' => 'black',
);

$mark->raise_to_top();
#$mark->raise(); ## CHECK CHECK

return $mark;
}
Expand Down

0 comments on commit 0e48935

Please sign in to comment.