Skip to content

Commit

Permalink
Start shift to GooCanvas2 (currently non-functional)
Browse files Browse the repository at this point in the history
Also update color parse calls for Gtk3

Updates #770 and #771
  • Loading branch information
shawnlaffan committed Jul 2, 2020
1 parent 40a6c36 commit adefba5
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 110 deletions.
93 changes: 47 additions & 46 deletions lib/Biodiverse/GUI/Dendrogram.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use List::Util 1.29 qw /min pairs/;
use List::MoreUtils qw /firstidx/;

use Gtk3;
use Gnome2::Canvas;
use GooCanvas2;
use POSIX qw /ceil/; # for ceil()

our $VERSION = '3.1';
Expand Down Expand Up @@ -46,7 +46,7 @@ use constant COLOUR_LIST_UNDEF => COLOUR_WHITE;

use constant DEFAULT_LINE_COLOUR => COLOUR_BLACK;
use constant DEFAULT_LINE_COLOUR_RGB => "#000000";
use constant DEFAULT_LINE_COLOUR_VERT => Gtk3::Gdk::Color->parse('#7F7F7F'); # '#4D4D4D'
use constant DEFAULT_LINE_COLOUR_VERT => Gtk3::Gdk::Color::parse('#7F7F7F'); # '#4D4D4D'

use constant HOVER_CURSOR => 'hand2';

Expand Down Expand Up @@ -168,9 +168,9 @@ sub new {
$self->{height_scale} = 1;

# Create background rectangle to receive mouse events for panning
my $rect = Gnome2::Canvas::Item->new (
my $rect = GooCanvas2::CanvasItem->new (
$self->{canvas}->root,
'Gnome2::Canvas::Rect',
'GooCanvas2::CanvasRect',
x1 => 0,
y1 => 0,
x2 => 1,
Expand Down Expand Up @@ -277,9 +277,9 @@ sub make_slider {
return;
}

$self->{slider} = Gnome2::Canvas::Item->new (
$self->{slider} = GooCanvas2::CanvasItem->new (
$self->{canvas}->root,
'Gnome2::Canvas::Rect',
'GooCanvas2::CanvasRect',
x1 => 0,
y1 => 0,
x2 => 1,
Expand All @@ -289,9 +289,9 @@ sub make_slider {
$self->{slider}->signal_connect_swapped (event => \&on_slider_event, $self);

# Slider for the graph at the bottom
$self->{graph_slider} = Gnome2::Canvas::Item->new (
$self->{graph_slider} = GooCanvas2::CanvasItem->new (
$self->{graph}->root,
'Gnome2::Canvas::Rect',
'GooCanvas2::CanvasRect',
x1 => 0,
y1 => 0,
x2 => 1,
Expand All @@ -301,27 +301,27 @@ sub make_slider {
$self->{graph_slider}->signal_connect_swapped (event => \&on_slider_event, $self);

# Make the #Clusters textbox
$self->{clusters_group} = Gnome2::Canvas::Item->new (
$self->{clusters_group} = GooCanvas2::CanvasItem->new (
$self->{canvas}->root,
'Gnome2::Canvas::Group',
'GooCanvas2::CanvasGroup',
x => 0,
y => 0,
);
$self->{clusters_group}->lower_to_bottom();

$self->{clusters_rect} = Gnome2::Canvas::Item->new (
$self->{clusters_rect} = GooCanvas2::CanvasItem->new (
$self->{clusters_group},
'Gnome2::Canvas::Rect',
'GooCanvas2::CanvasRect',
x1 => 0,
y1 => 0,
x2 => 0,
y2 =>0,
'fill-color' => 'blue',
);

$self->{clusters_text} = Gnome2::Canvas::Item->new (
$self->{clusters_text} = GooCanvas2::CanvasItem->new (
$self->{clusters_group},
'Gnome2::Canvas::Text',
'GooCanvas2::CanvasText',
x => 0,
y => 0,
anchor => 'nw',
Expand Down Expand Up @@ -552,15 +552,15 @@ sub get_palette_colorbrewer13 {
sub get_gdk_colors_colorbrewer9 {
my $self = shift;
my @colours
= map {Gtk3::Gdk::Color->parse ($_)}
= map {Gtk3::Gdk::Color::parse ($_)}
$self->get_palette_colorbrewer9;
return @colours;
}

sub get_gdk_colors_colorbrewer13 {
my $self = shift;
my @colours
= map {Gtk3::Gdk::Color->parse ($_)}
= map {Gtk3::Gdk::Color::parse ($_)}
$self->get_palette_colorbrewer13;
return @colours;
}
Expand Down Expand Up @@ -796,7 +796,7 @@ sub assign_cluster_palette_colours {
# assign colours
my $colour_ref;
foreach my $k (0..$#sorted_clusters) {
$colour_ref = Gtk3::Gdk::Color->parse($palette[$k]);
$colour_ref = Gtk3::Gdk::Color::parse($palette[$k]);
#$sorted_clusters[$k]->set_cached_value(__gui_palette_colour => $colour_ref);
$self->{node_palette_colours}{$sorted_clusters[$k]->get_name} = $colour_ref;
}
Expand Down Expand Up @@ -1071,7 +1071,7 @@ sub set_current_multiselect_colour {

eval {
if ((blessed $colour // '') !~ /Gtk3::Gdk::Color/) {
$colour = Gtk3::Gdk::Color->parse ($colour);
$colour = Gtk3::Gdk::Color::parse ($colour);
}
$colour = $self->{selector_colorbutton}->set_color ($colour);
};
Expand Down Expand Up @@ -2234,9 +2234,9 @@ sub render_tree {
$self->{root_circle}->destroy() if $self->{root_circle};

# Make group so we can transform everything together
my $lines_group = Gnome2::Canvas::Item->new (
my $lines_group = GooCanvas2::CanvasItem->new (
$self->{canvas}->root,
'Gnome2::Canvas::Group',
'GooCanvas2::CanvasGroup',
x => 0,
y => 0
);
Expand Down Expand Up @@ -2275,7 +2275,7 @@ sub render_tree {
# Draw a circle to mark out the root node
my $root_y = $tree->get_value('_y') * $self->{height_scale};
my $root_circ_diameter = 0.5 * $self->{border_len} * $self->{length_scale};
$self->{root_circle} = Gnome2::Canvas::Item->new (
$self->{root_circle} = GooCanvas2::CanvasItem->new (
$self->{lines_group},
'Gnome2::Canvas::Ellipse',
x1 => $root_offset,
Expand All @@ -2292,24 +2292,25 @@ sub render_tree {
$self->{root_circle}->lower_to_bottom();
$self->{back_rect}->lower_to_bottom();

if (0) {
# Spent ages on this - not working - NO IDEA WHY!!

# Draw an equilateral triangle to mark out the root node
# Vertex pointing at the root, the up-down side half border_len behind
my $perp_height = 0.5 * $self->{length_scale} * $self->{border_len} / 1.732; # 1.723 ~ sqrt(3)
my $triangle_path = Gnome2::Canvas::PathDef->new;
$triangle_path->moveto($root_offset, $root_y);
$triangle_path->lineto($root_offset - 0.5 * $self->{border_len}, $root_y + $perp_height);
$triangle_path->lineto($root_offset - 0.5 * $self->{border_len}, $root_y - $perp_height);
$triangle_path->closepath();

my $triangle = Gnome2::Canvas::Item->new ( $lines_group,
"Gnome2::Canvas::Shape",
fill_color => "green",
);
$triangle->set_path_def($triangle_path);
}
#if (0) {
# # Spent ages on this - not working - NO IDEA WHY!!
#
# # Draw an equilateral triangle to mark out the root node
# # Vertex pointing at the root, the up-down side half border_len behind
# my $perp_height = 0.5 * $self->{length_scale} * $self->{border_len} / 1.732; # 1.723 ~ sqrt(3)
# my $triangle_path = Gnome2::Canvas::PathDef->new;
# $triangle_path->moveto($root_offset, $root_y);
# $triangle_path->lineto($root_offset - 0.5 * $self->{border_len}, $root_y + $perp_height);
# $triangle_path->lineto($root_offset - 0.5 * $self->{border_len}, $root_y - $perp_height);
# $triangle_path->closepath();
#
# my $triangle = GooCanvas2::CanvasItem->new (
# $lines_group,
# "GooCanvas2::CanvasPolyline", # maybe not a polyline? was shape
# fill_color => "green",
# );
# $triangle->set_path_def($triangle_path);
#}

#$self->restore_line_colours();

Expand Down Expand Up @@ -2351,9 +2352,9 @@ sub render_graph {
}

# Make group so we can transform everything together
my $graph_group = Gnome2::Canvas::Item->new (
my $graph_group = GooCanvas2::CanvasItem->new (
$self->{graph}->root,
'Gnome2::Canvas::Group',
'GooCanvas2::CanvasGroup',
x => 0,
y => 0
);
Expand Down Expand Up @@ -2401,7 +2402,7 @@ sub render_graph {
my $segment_y = ($i * $graph_height_units) / $y_offset;
#print "[render_graph] segment_y=$segment_y current_x=$current_x\n";

my $hline = Gnome2::Canvas::Item->new (
my $hline = GooCanvas2::CanvasItem->new (
$graph_group,
'Gnome2::Canvas::Line',
points => [$current_x - $segment_length, $segment_y, $current_x, $segment_y],
Expand All @@ -2411,7 +2412,7 @@ sub render_graph {

# Now the vertical line
if ($previous_y) {
my $vline = Gnome2::Canvas::Item->new (
my $vline = GooCanvas2::CanvasItem->new (
$graph_group,
'Gnome2::Canvas::Line',
points => [$current_x, $previous_y, $current_x, $segment_y],
Expand Down Expand Up @@ -2531,7 +2532,7 @@ sub draw_line {
? 'solid'
: 'on-off-dash';

return Gnome2::Canvas::Item->new (
return GooCanvas2::CanvasItem->new (
$self->{lines_group},
'Gnome2::Canvas::Line',
points => $vertices,
Expand Down Expand Up @@ -2700,9 +2701,9 @@ sub on_background_event {
);
$self->{selecting} = 1;

$self->{sel_rect} = Gnome2::Canvas::Item->new (
$self->{sel_rect} = GooCanvas2::CanvasItem->new (
$self->{canvas}->root,
'Gnome2::Canvas::Rect',
'GooCanvas2::CanvasRect',
x1 => $x,
y1 => $y,
x2 => $x,
Expand Down
Loading

0 comments on commit adefba5

Please sign in to comment.