Skip to content

Commit

Permalink
GUI: More GooCanvas2 work
Browse files Browse the repository at this point in the history
Still very incomplete

Many cases where calls are disabled for now.

Updates #771
  • Loading branch information
shawnlaffan committed Nov 5, 2020
1 parent 0e48935 commit a9e0168
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
36 changes: 24 additions & 12 deletions lib/Biodiverse/GUI/Grid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ sub set_base_struct {
#$self->update_legend();

# show legend by default - gets hidden by caller if needed
$self->get_legend->show;
## CHECK CHECK
## Can't locate object method "show" via package "GooCanvas2::CanvasGroup"
#$self->get_legend->show;
# Store info needed by load_shapefile
$self->{dataset_info} = [$min_x, $min_y, $max_x, $max_y, $cell_x, $cell_y];

Expand Down Expand Up @@ -1719,17 +1721,23 @@ sub end_selection {

sub setup_scrollbars {
my $self = shift;
my ($total_width, $total_height) = $self->{canvas}->w2c($self->{width_units}, $self->{height_units});

# not sure this is the right method to use here
# was w2c under Gnome2::Canvas
my ($total_width, $total_height) = $self->{canvas}->convert_from_pixels(
$self->{width_units},
$self->{height_units},
);

$self->{hadjust}->upper( $total_width );
$self->{vadjust}->upper( $total_height );
$self->{hadjust}->set_upper( $total_width );
$self->{vadjust}->set_upper( $total_height );

if ($self->{width_px}) {
$self->{hadjust}->page_size( $self->{width_px} );
$self->{vadjust}->page_size( $self->{height_px} );
$self->{hadjust}->set_page_size( $self->{width_px} );
$self->{vadjust}->set_page_size( $self->{height_px} );

$self->{hadjust}->page_increment( $self->{width_px} / 2 );
$self->{vadjust}->page_increment( $self->{height_px} / 2 );
$self->{hadjust}->set_page_increment( $self->{width_px} / 2 );
$self->{vadjust}->set_page_increment( $self->{height_px} / 2 );
}

$self->{hadjust}->changed;
Expand Down Expand Up @@ -1784,13 +1792,17 @@ sub resize_background_rect {

if ($self->{width_px}) {
# Make it the full visible area
my ($width, $height) = $self->{canvas}->c2w($self->{width_px}, $self->{height_px});
# was c2w under Gnome2::Canvas
my ($width, $height) = $self->{canvas}->convert_to_pixels(
$self->{width_px},
$self->{height_px},
);
if (not $self->{dragging}) {
$self->{back_rect}->set(
x2 => max($width, $self->{width_units}),
y2 => max($height, $self->{height_units}),
width => max($width, $self->{width_units}),
height => max($height, $self->{height_units}),
);
$self->{back_rect}->lower_to_bottom();
$self->{back_rect}->lower();
}
}
return;
Expand Down
34 changes: 25 additions & 9 deletions lib/Biodiverse/GUI/Legend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ sub make_rect {
# We do this because we are about to create it again
# with a different colour scheme as defined by legend_mode.
if ($self->{legend_colours_group}) {
$self->{legend_colours_group}->destroy();
## CHECK CHECK
#$self->{legend_colours_group}->destroy();
$self->{legend_colours_group} = undef;
}

# Make a group so we can pack the coloured
Expand Down Expand Up @@ -275,16 +277,29 @@ sub reposition {

# Convert coordinates into world units
# (this has been tricky to get working right...)
my ($width, $height) = $self->{canvas}->c2w($width_px || 0, $height_px || 0);
# CHECK CHECK - goo canvas changes
# was c2w
my ($width, $height) = $self->{canvas}->convert_to_pixels(
$width_px || 0,
$height_px || 0,
);

my ($scroll_x, $scroll_y) = $self->{canvas}->get_scroll_offsets();
($scroll_x, $scroll_y) = $self->{canvas}->c2w($scroll_x, $scroll_y);
# CHECK CHECK - what is get_scroll_offsets in GooCanvas2?
#my ($scroll_x, $scroll_y) = $self->{canvas}->get_scroll_offsets();
# ($scroll_x, $scroll_y) = $self->{canvas}->convert_to_pixels($scroll_x, $scroll_y);
my ($scroll_x, $scroll_y) = (0,0); # maybe get bounds?

my ($border_width, $legend_width) = $self->{canvas}->c2w(BORDER_SIZE, $self->get_width);
my ($border_width, $legend_width) = $self->{canvas}->convert_to_pixels(
BORDER_SIZE,
$self->get_width,
);

# CHECK CHECK
# Get the pixels per unit value from the canvas
# to scale the legend with.
my $ppu = $self->{canvas}->get_pixels_per_unit();
# was get_pixels_per_unit under gnome2 canvas
#my $ppu = $self->{canvas}->scale;
my $ppu = 1;

# Reposition the legend group box
$self->{legend_group}->set(
Expand All @@ -293,15 +308,16 @@ sub reposition {
);

# Scale the legend's height and width to match the current size of the canvas.
my $matrix = [
my $matrix = Cairo::Matrix->init (
$legend_width * $ppu, # scale x
0,
0,
$height / $self->{legend_height}, # scale y
0,
0
];
$self->{legend_colours_group}->affine_absolute($matrix);
);
# CHECK CHECK
#$self->{legend_colours_group}->transform($matrix);

# Reposition the "mark" textboxes
foreach my $i (0..3) {
Expand Down

0 comments on commit a9e0168

Please sign in to comment.