Skip to content

Commit

Permalink
Update all gdk color calls
Browse files Browse the repository at this point in the history
Updates #770
  • Loading branch information
shawnlaffan committed Oct 28, 2020
1 parent 324e60d commit f46ca3b
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 68 deletions.
27 changes: 14 additions & 13 deletions lib/Biodiverse/GUI/Dendrogram.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ use constant LEAF_SPACING => 1; # arbitrary scale (length will be scaled to f
use constant HIGHLIGHT_WIDTH => 2; # width of highlighted horizontal lines (pixels)
use constant NORMAL_WIDTH => 1; # width of normal lines (pixels)

use constant COLOUR_BLACK => Gtk3::Gdk::Color->new(0,0,0);
use constant COLOUR_WHITE => Gtk3::Gdk::Color->new(255*257, 255*257, 255*257);
use constant COLOUR_GRAY => Gtk3::Gdk::Color->new(210*257, 210*257, 210*257);
use constant COLOUR_RED => Gtk3::Gdk::Color->new(255*257,0,0);
use constant COLOUR_BLACK => [Gtk3::Gdk::Color::parse ('#000000000000')]->[1]; #->new(0,0,0);
use constant COLOUR_WHITE => [Gtk3::Gdk::Color::parse ('#FFFFFFFFFFFF')]->[1]; # ->new(255*257, 255*257, 255*257);
use constant COLOUR_GRAY => [Gtk3::Gdk::Color::parse ('#D2D2D2D2D2D2')]->[1]; #->new(210*257, 210*257, 210*257);
use constant COLOUR_RED => [Gtk3::Gdk::Color::parse ('#FFFF00000000')]->[1]; #255*257,0,0);

use constant COLOUR_PALETTE_OVERFLOW => COLOUR_WHITE;
use constant COLOUR_OUTSIDE_SELECTION => COLOUR_WHITE;
Expand All @@ -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')]->[1]; # '#4D4D4D'

use constant HOVER_CURSOR => 'hand2';

Expand All @@ -68,7 +68,8 @@ sub new {
my $use_slider_to_select_nodes = !$args{no_use_slider_to_select_nodes};
my $want_legend = $args{want_legend};

my $grey = 0.9 * 255 * 257;
#my $grey = 0.9 * 255 * 257;
my $grey = '#E665E665E665';

my $self = {
map => $map,
Expand All @@ -86,7 +87,7 @@ sub new {
render_height => 0,
graph_height_px => 0,
use_slider_to_select_nodes => $use_slider_to_select_nodes,
colour_not_in_tree => Gtk3::Gdk::Color->new($grey, $grey, $grey),
colour_not_in_tree => [Gtk3::Gdk::Color::parse ($grey)]->[1], #->new($grey, $grey, $grey),
use_highlight_func => 1, # should we highlight?
};

Expand Down Expand Up @@ -135,8 +136,8 @@ sub new {
}

# Make and hook up the canvases
$self->{canvas} = Gnome2::Canvas->new();
$self->{graph} = Gnome2::Canvas->new();
$self->{canvas} = GooCanvas2::Canvas->new();
$self->{graph} = GooCanvas2::Canvas->new();
$main_frame->add( $self->{canvas} );
$graph_frame->add( $self->{graph} );
$self->{canvas}->signal_connect_swapped (
Expand Down Expand Up @@ -2277,7 +2278,7 @@ sub render_tree {
my $root_circ_diameter = 0.5 * $self->{border_len} * $self->{length_scale};
$self->{root_circle} = GooCanvas2::CanvasItem->new (
$self->{lines_group},
'Gnome2::Canvas::Ellipse',
'GooCanvas2::CanvasEllipse',
x1 => $root_offset,
y1 => $root_y + $root_circ_diameter / 2,
x2 => $root_offset + $root_circ_diameter,
Expand Down Expand Up @@ -2404,7 +2405,7 @@ sub render_graph {

my $hline = GooCanvas2::CanvasItem->new (
$graph_group,
'Gnome2::Canvas::Line',
'GooCanvas2::CanvasPolyline',
points => [$current_x - $segment_length, $segment_y, $current_x, $segment_y],
fill_color_gdk => COLOUR_BLACK,
width_pixels => NORMAL_WIDTH
Expand All @@ -2414,7 +2415,7 @@ sub render_graph {
if ($previous_y) {
my $vline = GooCanvas2::CanvasItem->new (
$graph_group,
'Gnome2::Canvas::Line',
'GooCanvas2::CanvasPolyline',
points => [$current_x, $previous_y, $current_x, $segment_y],
fill_color_gdk => COLOUR_BLACK,
width_pixels => NORMAL_WIDTH
Expand Down Expand Up @@ -2534,7 +2535,7 @@ sub draw_line {

return GooCanvas2::CanvasItem->new (
$self->{lines_group},
'Gnome2::Canvas::Line',
'GooCanvas2::CanvasPolyline',
points => $vertices,
fill_color_gdk => $colour_ref,
line_style => $line_style,
Expand Down
40 changes: 20 additions & 20 deletions lib/Biodiverse/GUI/Grid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ use constant INDEX_MINUS => 5;

use constant HOVER_CURSOR => 'hand2';

use constant HIGHLIGHT_COLOUR => Gtk3::Gdk::Color->new(255*257,0,0); # red
use constant COLOUR_BLACK => Gtk3::Gdk::Color->new(0, 0, 0);
use constant COLOUR_WHITE => Gtk3::Gdk::Color->new(255*257, 255*257, 255*257);
use constant CELL_OUTLINE_COLOUR => Gtk3::Gdk::Color->new(0, 0, 0);
use constant OVERLAY_COLOUR => Gtk3::Gdk::Color::parse('#001169');
use constant HIGHLIGHT_COLOUR => [Gtk3::Gdk::Color::parse('red')]->[1]; #->new(255*257,0,0); # red
use constant COLOUR_BLACK => [Gtk3::Gdk::Color::parse('black')]->[1]; #->new(0, 0, 0);
use constant COLOUR_WHITE => [Gtk3::Gdk::Color::parse('white')]->[1]; # ->new(255*257, 255*257, 255*257);
use constant CELL_OUTLINE_COLOUR => [Gtk3::Gdk::Color::parse('black')]->[1]; #->new(0, 0, 0);
use constant OVERLAY_COLOUR => [Gtk3::Gdk::Color::parse('#001169')]->[1];
use constant DARKEST_GREY_FRAC => 0.2;
use constant LIGHTEST_GREY_FRAC => 0.8;

Expand Down Expand Up @@ -138,7 +138,7 @@ sub new {
$self->set_colour_for_undef;

# Make the canvas and hook it up
$self->{canvas} = Gnome2::Canvas->new();
$self->{canvas} = GooCanvas2::Canvas->new();
$frame->add($self->{canvas});
$self->{canvas}->signal_connect_swapped (size_allocate => \&on_size_allocate, $self);

Expand Down Expand Up @@ -720,7 +720,7 @@ sub load_shapefile {
if (@plot_points > 2) { # must have more than one point (two coords)
my $poly = GooCanvas2::CanvasItem->new (
$shapefile_group,
'Gnome2::Canvas::Line',
'GooCanvas2::CanvasPolyline',
points => \@plot_points,
fill_color_gdk => $colour,
);
Expand Down Expand Up @@ -1020,7 +1020,7 @@ sub draw_circle {

my $item = GooCanvas2::CanvasItem->new (
$group,
'Gnome2::Canvas::Ellipse',
'GooCanvas2::CanvasEllipse',
x1 => $offset_x,
y1 => $offset_y,
x2 => $offset_x + CIRCLE_DIAMETER,
Expand Down Expand Up @@ -1051,14 +1051,14 @@ sub on_marker_event {
#
# GooCanvas2::CanvasItem->new (
# $cross_group,
# "Gnome2::Canvas::Line",
# "GooCanvas2::CanvasPolyline",
# points => [MARK_OFFSET_X, MARK_OFFSET_X, MARK_END_OFFSET_X, MARK_END_OFFSET_X],
# fill_color_gdk => COLOUR_BLACK,
# width_units => 1,
# );
# GooCanvas2::CanvasItem->new (
# $cross_group,
# "Gnome2::Canvas::Line",
# "GooCanvas2::CanvasPolyline",
# points => [MARK_END_OFFSET_X, MARK_OFFSET_X, MARK_OFFSET_X, MARK_END_OFFSET_X],
# fill_color_gdk => COLOUR_BLACK,
# width_units => 1,
Expand All @@ -1073,7 +1073,7 @@ sub draw_minus {

return GooCanvas2::CanvasItem->new (
$group,
'Gnome2::Canvas::Line',
'GooCanvas2::CanvasPolyline',
points => [
MARK_X_OFFSET,
$offset_y,
Expand Down Expand Up @@ -1165,11 +1165,11 @@ sub get_colour_hue {
#
my $hue;
if (! defined $max || ! defined $min) {
return Gtk3::Gdk::Color->new(0, 0, 0);
return [Gtk3::Gdk::Color::parse('black')]->[1];
#return COLOUR_BLACK;
}
elsif ($max != $min) {
return Gtk3::Gdk::Color->new(0, 0, 0) if ! defined $val;
return [Gtk3::Gdk::Color::parse('black')]->[1] if ! defined $val;
$hue = ($val - $min) / ($max - $min) * 180;
}
else {
Expand All @@ -1180,7 +1180,7 @@ sub get_colour_hue {

my ($r, $g, $b) = hsv_to_rgb($hue, 1, 1);

return Gtk3::Gdk::Color->new($r*257, $g*257, $b*257);
return [Gtk3::Gdk::Color::parse(sprintf '#%x%x%x', $r*257, $g*257, $b*257)]->[1];
}

sub get_colour_saturation {
Expand All @@ -1190,11 +1190,11 @@ sub get_colour_saturation {
# Hue is variable, Brightness 1
my $sat;
if (! defined $max || ! defined $min) {
return Gtk3::Gdk::Color->new(0, 0, 0);
return [Gtk3::Gdk::Color::parse('black')]->[1];
#return COLOUR_BLACK;
}
elsif ($max != $min) {
return Gtk3::Gdk::Color->new(0, 0, 0) if ! defined $val;
return [Gtk3::Gdk::Color::parse('black')]->[1] if ! defined $val;
$sat = ($val - $min) / ($max - $min);
}
else {
Expand All @@ -1204,19 +1204,19 @@ sub get_colour_saturation {
my $hue = $self->get_legend->get_hue // 0;
my ($r, $g, $b) = hsv_to_rgb($hue, $sat, 1);

return Gtk3::Gdk::Color->new($r*257, $g*257, $b*257);
return [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $r*257, $g*257, $b*257)]->[1];
}

sub get_colour_grey {
my ($self, $val, $min, $max) = @_;

my $sat;
if (! defined $max || ! defined $min) {
return Gtk3::Gdk::Color->new(0, 0, 0);
return [Gtk3::Gdk::Color::parse ('black')]->[1];
#return COLOUR_BLACK;
}
elsif ($max != $min) {
return Gtk3::Gdk::Color->new(0, 0, 0)
return [Gtk3::Gdk::Color::parse ('black')]->[1]
if ! defined $val;

$sat = ($val - $min) / ($max - $min);
Expand All @@ -1228,7 +1228,7 @@ sub get_colour_grey {
$sat = $self->rescale_grey($sat); # don't use all the shades
$sat *= 257;

return Gtk3::Gdk::Color->new($sat, $sat, $sat);
return [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $sat, $sat, $sat)]->[1];
}

# FROM http://blog.webkist.com/archives/000052.html
Expand Down
24 changes: 12 additions & 12 deletions lib/Biodiverse/GUI/Legend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ use constant MARK_Y_LEGEND_OFFSET => 8;
use constant LEGEND_HEIGHT => 380;
use constant INDEX_RECT => 2; # Canvas (square) rectangle for the cell

use constant COLOUR_BLACK => Gtk3::Gdk::Color->new(0, 0, 0);
use constant COLOUR_WHITE => Gtk3::Gdk::Color->new(255*257, 255*257, 255*257);
use constant COLOUR_BLACK => [Gtk3::Gdk::Color::parse('#000000')]->[1]; #0, 0, 0);
use constant COLOUR_WHITE => [Gtk3::Gdk::Color::parse('#FFFFFF')]->[1]; #255*257, 255*257, 255*257);
use constant DARKEST_GREY_FRAC => 0.2;
use constant LIGHTEST_GREY_FRAC => 0.8;

Expand Down Expand Up @@ -215,7 +215,7 @@ sub add_row {
x2 => $width,
y1 => $row,
y2 => $row+1,
fill_color_gdk => Gtk3::Gdk::Color->new($r,$g,$b),
fill_color_gdk => [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $r,$g,$b)]->[1],
);
}

Expand Down Expand Up @@ -476,11 +476,11 @@ sub get_colour_hue {
#
my $hue;
if (! defined $max || ! defined $min) {
return Gtk3::Gdk::Color->new(0, 0, 0);
return [Gtk3::Gdk::Color::parse ('black')]->[1];
#return COLOUR_BLACK;
}
elsif ($max != $min) {
return Gtk3::Gdk::Color->new(0, 0, 0) if ! defined $val;
return [Gtk3::Gdk::Color::parse ('black')]->[1] if ! defined $val;
$hue = ($val - $min) / ($max - $min) * 180;
}
else {
Expand All @@ -491,7 +491,7 @@ sub get_colour_hue {

my ($r, $g, $b) = hsv_to_rgb($hue, 1, 1);

return Gtk3::Gdk::Color->new($r*257, $g*257, $b*257);
return [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $r, $g, $b)]->[1];
}

sub get_colour_saturation {
Expand All @@ -501,11 +501,11 @@ sub get_colour_saturation {
# Hue is variable, Brightness 1
my $sat;
if (! defined $max || ! defined $min) {
return Gtk3::Gdk::Color->new(0, 0, 0);
return [Gtk3::Gdk::Color::parse ('black')]->[1];
#return COLOUR_BLACK;
}
elsif ($max != $min) {
return Gtk3::Gdk::Color->new(0, 0, 0) if ! defined $val;
return [Gtk3::Gdk::Color::parse ('black')]->[1] if ! defined $val;
$sat = ($val - $min) / ($max - $min);
}
else {
Expand All @@ -514,19 +514,19 @@ sub get_colour_saturation {

my ($r, $g, $b) = hsv_to_rgb($self->{hue}, $sat, 1);

return Gtk3::Gdk::Color->new($r*257, $g*257, $b*257);
return [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $r, $g, $b)]->[1];
}

sub get_colour_grey {
my ($self, $val, $min, $max) = @_;

my $sat;
if (! defined $max || ! defined $min) {
return Gtk3::Gdk::Color->new(0, 0, 0);
return [Gtk3::Gdk::Color::parse ('black')]->[1];
#return COLOUR_BLACK;
}
elsif ($max != $min) {
return Gtk3::Gdk::Color->new(0, 0, 0)
return [Gtk3::Gdk::Color::parse ('black')]->[1]
if ! defined $val;

$sat = ($val - $min) / ($max - $min);
Expand All @@ -538,7 +538,7 @@ sub get_colour_grey {
$sat = $self->rescale_grey($sat); # don't use all the shades
$sat *= 257;

return Gtk3::Gdk::Color->new($sat, $sat, $sat);
return [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $sat, $sat, $sat)]->[1];
}


Expand Down
19 changes: 9 additions & 10 deletions lib/Biodiverse/GUI/MatrixGrid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ use constant INDEX_MINUS => 5;

use constant HOVER_CURSOR => 'hand2';

use constant HIGHLIGHT_COLOUR => Gtk3::Gdk::Color->new(255*257, 0, 0); # red
use constant CELL_BLACK => Gtk3::Gdk::Color->new(0, 0, 0);
use constant CELL_WHITE => Gtk3::Gdk::Color->new(255*257, 255*257, 255*257);
#use constant CELL_COLOUR => Gtk3::Gdk::Color::parse('#B3FFFF');
use constant CELL_COLOUR => Gtk3::Gdk::Color::parse('#FFFFFF');
use constant OVERLAY_COLOUR => Gtk3::Gdk::Color::parse('#001169');
use constant HIGHLIGHT_COLOUR => [Gtk3::Gdk::Color::parse ('red')]->[1]; # red
use constant CELL_BLACK => [Gtk3::Gdk::Color::parse ('black')]->[1];
use constant CELL_WHITE => [Gtk3::Gdk::Color::parse ('white')]->[1];
use constant CELL_COLOUR => [Gtk3::Gdk::Color::parse('white')]->[1];
use constant OVERLAY_COLOUR => [Gtk3::Gdk::Color::parse('#001169')]->[1];

# Stiple for the selection-masking shape
my $gray50_width = 2;
Expand Down Expand Up @@ -571,7 +570,7 @@ sub get_colour_hue {
#
my $hue;
if (! defined $max || ! defined $min) {
return Gtk3::Gdk::Color->new(0, 0, 0);
return [Gtk3::Gdk::Color::parse ('black')]->[1];
}
elsif ($max != $min) {
$hue = ($val - $min) / ($max - $min) * 180;
Expand All @@ -584,7 +583,7 @@ sub get_colour_hue {

my ($r, $g, $b) = hsv_to_rgb($hue, 1, 1);

return Gtk3::Gdk::Color->new($r*257, $g*257, $b*257);
return [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $r, $g, $b)]->[1];
}

sub get_colour_saturation {
Expand All @@ -594,7 +593,7 @@ sub get_colour_saturation {
# Hue is variable, Brightness 1
my $sat;
if (! defined $max || ! defined $min) {
return Gtk3::Gdk::Color->new(0, 0, 0);
return [Gtk3::Gdk::Color::parse ('black')]->[1];
}
elsif ($max != $min) {
$sat = ($val - $min) / ($max - $min);
Expand All @@ -605,7 +604,7 @@ sub get_colour_saturation {

my ($r, $g, $b) = hsv_to_rgb($self->{hue}, $sat, 1);

return Gtk3::Gdk::Color->new($r*257, $g*257, $b*257);
return [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', $r, $g, $b)]->[1];
}

# FROM http://blog.webkist.com/archives/000052.html
Expand Down
2 changes: 1 addition & 1 deletion lib/Biodiverse/GUI/Tabs/Clustering.pm
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ sub new {
$self->init_map_list_combo();

$self->{colour_mode} = 'Hue';
$self->{hue} = Gtk3::Gdk::Color->new(65535, 0, 0); # For Sat mode
$self->{hue} = [Gtk3::Gdk::Color::parse ('red')]->[1]; # was 65535, 0, 0); # For Sat mode

$self->{calculations_model}
= Biodiverse::GUI::Tabs::CalculationsTree::make_calculations_model(
Expand Down
7 changes: 4 additions & 3 deletions lib/Biodiverse/GUI/Tabs/Labels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ use constant LABELS_MODEL_REDUNDANCY => 3;
my $labels_model_list1_sel_col; # these are set in sub make_labels_model
my $labels_model_list2_sel_col;

use constant CELL_WHITE => Gtk3::Gdk::Color->new(255*257, 255*257, 255*257);
use constant COLOUR_BLACK => Gtk3::Gdk::Color->new(0,0,0);
use constant COLOUR_GREY => Gtk3::Gdk::Color->new(255*257*2/3, 255*257*2/3, 255*257*2/3);
use constant CELL_WHITE => [Gtk3::Gdk::Color::parse ('white')]->[1];
use constant COLOUR_BLACK => [Gtk3::Gdk::Color::parse ('black')]->[1];
use constant COLOUR_GREY
=> [Gtk3::Gdk::Color::parse (sprintf '#%x%x%x', 255*257*2/3, 255*257*2/3, 255*257*2/3)]->[1];

my $selected_list1_name = 'Selected';
my $selected_list2_name = 'Col selected';
Expand Down
Loading

0 comments on commit f46ca3b

Please sign in to comment.