[gnote] Use RGBA for contrast
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Use RGBA for contrast
- Date: Fri, 1 Jan 2021 16:30:58 +0000 (UTC)
commit be68da9998f5f9978ec83ee1e2356f80c92a8b72
Author: Aurimas Černius <aurisc4 gmail com>
Date: Fri Jan 1 18:17:07 2021 +0200
Use RGBA for contrast
src/contrast.cpp | 17 +++++++++--------
src/contrast.hpp | 7 ++++---
src/notetag.cpp | 13 +++++--------
src/notetag.hpp | 8 ++++----
4 files changed, 22 insertions(+), 23 deletions(-)
---
diff --git a/src/contrast.cpp b/src/contrast.cpp
index 81167f64..53525ff3 100644
--- a/src/contrast.cpp
+++ b/src/contrast.cpp
@@ -1,6 +1,7 @@
/*
* contrast.c
*
+ * Copyright (c) 2021 Aurimas Cernius
* Copyright (c) 2006-2007 David Trowbridge
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -192,8 +193,8 @@ lab_distance(float La,
* Creates a specific color value for a foreground color, optimizing for
* maximum readability against the background.
*/
-Gdk::Color
-contrast_render_foreground_color(const Gdk::Color & background,
+Gdk::RGBA
+contrast_render_foreground_color(const Gdk::RGBA & background,
ContrastPaletteColor color)
{
float L, a, b;
@@ -202,10 +203,9 @@ contrast_render_foreground_color(const Gdk::Color & background,
float points[8][3];
float ld, cd;
int i;
- Gdk::Color rcolor;
+ Gdk::RGBA rcolor;
- rgb_to_lab(background.get_red(), background.get_green(),
- background.get_blue(), &L, &a, &b);
+ rgb_to_lab(background.get_red_u(), background.get_green_u(), background.get_blue_u(), &L, &a, &b);
points[0][0] = color_regions[color][0]; points[0][1] = color_regions[color][2]; points[0][2] =
color_regions[color][4];
points[1][0] = color_regions[color][0]; points[1][1] = color_regions[color][2]; points[1][2] =
color_regions[color][5];
@@ -254,9 +254,10 @@ contrast_render_foreground_color(const Gdk::Color & background,
// &rcolor.red,
// &rcolor.green,
// &rcolor.blue);
- rcolor.set_red(re);
- rcolor.set_green(gr);
- rcolor.set_blue(bl);
+ rcolor.set_red_u(re);
+ rcolor.set_green_u(gr);
+ rcolor.set_blue_u(bl);
+ rcolor.set_alpha_u(65535);
return rcolor;
}
diff --git a/src/contrast.hpp b/src/contrast.hpp
index 26c49d8a..3ad2f6be 100644
--- a/src/contrast.hpp
+++ b/src/contrast.hpp
@@ -1,6 +1,7 @@
/*
* contrast.h
*
+ * Copyright (c) 2021 Aurimas Cernius
* Copyright (c) 2006-2007 David Trowbridge
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -27,7 +28,7 @@
#ifndef __CONTRAST_H_
#define __CONTRAST_H_
-#include <gdkmm/color.h>
+#include <gdkmm/rgba.h>
/*
* Defined colors. Keep this list alphabetized if you add new ones, but set the
@@ -61,8 +62,8 @@ typedef enum {
CONTRAST_COLOR_LAST = 23
} ContrastPaletteColor;
-Gdk::Color
-contrast_render_foreground_color(const Gdk::Color & background,
+Gdk::RGBA
+contrast_render_foreground_color(const Gdk::RGBA & background,
ContrastPaletteColor color);
#endif
diff --git a/src/notetag.cpp b/src/notetag.cpp
index 7f63804e..9a9b0784 100644
--- a/src/notetag.cpp
+++ b/src/notetag.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011,2013-2014,2017,2019-2020 Aurimas Cernius
+ * Copyright (C) 2011,2013-2014,2017,2019-2021 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -292,20 +292,17 @@ namespace gnote {
}
}
- Gdk::Color NoteTag::get_background() const
+ Gdk::RGBA NoteTag::get_background() const
{
/* We can't know the exact background because we're not
in TextView's rendering, but we can make a guess */
if (property_background_set().get_value())
- return property_background_gdk().get_value();
+ return property_background_rgba().get_value();
- Gdk::RGBA rgba = Gtk::TextView().get_style_context()->get_background_color();
- Gdk::Color color;
- color.set_rgb(rgba.get_red_u(), rgba.get_green_u(), rgba.get_blue_u());
- return color;
+ return Gtk::TextView().get_style_context()->get_background_color();
}
- Gdk::Color NoteTag::render_foreground(ContrastPaletteColor symbol)
+ Gdk::RGBA NoteTag::render_foreground(ContrastPaletteColor symbol)
{
return contrast_render_foreground_color(get_background(), symbol);
}
diff --git a/src/notetag.hpp b/src/notetag.hpp
index 99b81bf0..57b758f5 100644
--- a/src/notetag.hpp
+++ b/src/notetag.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011,2013-2014,2017,2019 Aurimas Cernius
+ * Copyright (C) 2011,2013-2014,2017,2019,2021 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -154,7 +154,7 @@ public:
{
m_palette_foreground = value;
// XXX We should also watch theme changes.
- property_foreground_gdk().set_value(render_foreground(value));
+ property_foreground_rgba().set_value(render_foreground(value));
}
protected:
NoteTag(const Glib::ustring & tag_name, int flags = 0);
@@ -166,8 +166,8 @@ protected:
virtual bool on_event(const Glib::RefPtr<Glib::Object> &, GdkEvent *, const Gtk::TextIter & ) override;
virtual bool on_activate(const NoteEditor & , const Gtk::TextIter &, const Gtk::TextIter &);
private:
- Gdk::Color get_background() const;
- Gdk::Color render_foreground(ContrastPaletteColor symbol);
+ Gdk::RGBA get_background() const;
+ Gdk::RGBA render_foreground(ContrastPaletteColor symbol);
Glib::ustring m_element_name;
Glib::RefPtr<Gtk::TextMark> m_widget_location;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]