From 4a8c4d7c8b8214c30fd8bb4bdec52f8b214e668b Mon Sep 17 00:00:00 2001 From: Shawn Laffan Date: Mon, 5 Sep 2016 16:45:51 +1000 Subject: [PATCH] add method to increment the multi-select colour Also add methods to get the colour palettes as Gtk2::Gdk::Color objects. The increment process needs some thought yet, as it currently resets to red if a colour from outside the palette is used. This will be simplified once we keep track of which nodes are which colour. Updates #600 --- bin/ui/hboxClusteringPage.ui | 20 +++++++++++- lib/Biodiverse/GUI/Dendrogram.pm | 55 ++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/bin/ui/hboxClusteringPage.ui b/bin/ui/hboxClusteringPage.ui index 32200c342..a304a0e7b 100644 --- a/bin/ui/hboxClusteringPage.ui +++ b/bin/ui/hboxClusteringPage.ui @@ -612,6 +612,24 @@ Does not affect the vertical connectors. 3 2 4 + + + + + + + + + + + + + + + + + + True @@ -1481,7 +1499,7 @@ This setting has no effect on the slider bar. True False - Colour + Next colour diff --git a/lib/Biodiverse/GUI/Dendrogram.pm b/lib/Biodiverse/GUI/Dendrogram.pm index 064e6967e..b1973ab74 100644 --- a/lib/Biodiverse/GUI/Dendrogram.pm +++ b/lib/Biodiverse/GUI/Dendrogram.pm @@ -11,6 +11,7 @@ use Time::HiRes qw /gettimeofday time/; use Scalar::Util qw /weaken blessed/; use List::Util qw /min/; +use List::MoreUtils qw /firstidx/; use Tie::RefHash; use Gtk2; @@ -112,6 +113,9 @@ sub new { $self->{sp_list} = undef; $self->{sp_index} = undef; bless $self, $class; + + # also initialises it + $self->increment_sequential_selection_colour; # clean up if we are a refresh if (my $child = $main_frame->get_child) { @@ -526,6 +530,22 @@ sub get_palette_colorbrewer13 { #4B4B4B'; } +sub get_gdk_colors_colorbrewer9 { + my $self = shift; + my @colours + = map {Gtk2::Gdk::Color->parse ($_)} + $self->get_palette_colorbrewer9; + return @colours; +} + +sub get_gdk_colors_colorbrewer13 { + my $self = shift; + my @colours + = map {Gtk2::Gdk::Color->parse ($_)} + $self->get_palette_colorbrewer13; + return @colours; +} + # Returns a list of colours to use for colouring however-many clusters # returns STRING COLOURS sub get_palette { @@ -921,6 +941,36 @@ sub get_current_sequential_colour { return $colour; } +sub increment_sequential_selection_colour { + my $self = shift; + + return if !$self->{cluster_colour_mode} eq 'sequential'; + + my $colour = $self->get_current_sequential_colour; + + my @colours = $self->get_gdk_colors_colorbrewer9; + + if (my $last_colour = $self->{last_sequential_colour}) { + my $i = firstidx {$last_colour->equal($_)} @colours; + $i++; + $i %= scalar @colours; + $colour = $colours[$i]; + } + else { + $colour = $colours[0]; + } + + my $widget_name = 'selector_colorbutton'; + eval { + my $widget = $self->{parent_tab}->{xmlPage}->get_object($widget_name); + $widget->set_color ($colour); + }; + croak $@ if $@; + + $self->{last_sequential_colour} = $colour; + + return; +} sub get_colour_not_in_tree { my $self = shift; @@ -2073,16 +2123,17 @@ sub on_event { $f = $self->{ctrl_click_func}; $f->($node); } - # Just click - colour nodes } + # Left click - colour nodes elsif ($event->button == 1) { $self->do_colour_nodes_below($node); if (defined $self->{click_func}) { $f = $self->{click_func}; $f->($node); } - # Right click - set marks semi-permanently + $self->increment_sequential_selection_colour; } + # Right click - set marks semi-permanently elsif ($event->button == 3) { # Restore previously clicked/hovered line