Move function is_color_light to gnc-gtk-utils and rename

Move is_color_light and rename to gnc_is_dark_theme and update required
files where used.
This commit is contained in:
Robert Fewell
2017-08-30 11:13:26 +01:00
parent b81a4a559d
commit 08d7830f7b
4 changed files with 25 additions and 30 deletions

View File

@@ -25,6 +25,7 @@
#include "gnc-dense-cal.h"
#include "gnc-dense-cal-model.h"
#include "gnc-engine.h"
#include "gnc-gtk-utils.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
@@ -923,21 +924,6 @@ gnc_style_context_get_border_color (GtkStyleContext *context,
gdk_rgba_free (c);
}
static gboolean
is_color_light (GdkRGBA *color)
{
gboolean is_light = FALSE;
// Counting the perceptive luminance - human eye favors green color...
double a = (0.299 * color->red + 0.587 * color->green + 0.114 * color->blue);
if (a > 0.5)
is_light = TRUE;
return is_light;
}
static void
gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
{
GtkWidget *widget;
@@ -980,7 +966,7 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color);
if (is_color_light (&color))
if (gnc_is_dark_theme (&color))
class_extension = "-dark";
primary_color_class = g_strconcat ("primary", class_extension, NULL);

View File

@@ -223,3 +223,22 @@ gnc_cbwe_require_list_item (GtkComboBox *cbwe)
g_object_set_data(G_OBJECT(cbwe), CHANGED_ID, GINT_TO_POINTER(id));
}
/** Test to see if fg_color is a light one which should be a foreground
* one and hence would be on a dark background
*
* @param fg_color The foreground color to test.
*/
gboolean
gnc_is_dark_theme (GdkRGBA *fg_color)
{
gboolean is_dark = FALSE;
// Counting the perceptive luminance - human eye favors green color...
double lightness = (0.299 * fg_color->red + 0.587 * fg_color->green + 0.114 * fg_color->blue);
if (lightness > 0.5)
is_dark = TRUE;
return is_dark;
}

View File

@@ -45,6 +45,7 @@ void gnc_cbwe_set_by_string(GtkComboBox *cbwe, const gchar *text);
void gnc_cbwe_add_completion (GtkComboBox *cbwe);
void gnc_cbwe_require_list_item (GtkComboBox *cbwe);
gboolean gnc_is_dark_theme (GdkRGBA *fg_color);
/** @} */
#endif /* GNC_GTK_UTILS_H */

View File

@@ -43,6 +43,7 @@
#include "gnc-ui.h"
#include "gnc-ui-util.h"
#include "gnc-engine.h"
#include "gnc-gtk-utils.h"
#include "import-settings.h"
#include "import-match-picker.h"
#include "import-backend.h"
@@ -511,19 +512,7 @@ gnc_gen_trans_init_view (GNCImportMainMatcher *info,
G_CALLBACK(gnc_gen_trans_row_changed_cb), info);
}
static gboolean
is_color_light (GdkRGBA *color)
{
gboolean is_light = FALSE;
// Counting the perceptive luminance - human eye favors green color...
double a = (0.299 * color->red + 0.587 * color->green + 0.114 * color->blue);
if (a > 0.5)
is_light = TRUE;
return is_light;
}
GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent,
const gchar* heading,
@@ -547,7 +536,7 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent,
stylectxt = gtk_widget_get_style_context (GTK_WIDGET(parent));
gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color);
info->dark_theme = is_color_light (&color);
info->dark_theme = gnc_is_dark_theme (&color);
/* Initialize the GtkDialog. */
builder = gtk_builder_new();
@@ -616,7 +605,7 @@ GNCImportMainMatcher * gnc_gen_trans_assist_new (GtkWidget *parent,
stylectxt = gtk_widget_get_style_context (GTK_WIDGET(parent));
gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color);
info->dark_theme = is_color_light (&color);
info->dark_theme = gnc_is_dark_theme (&color);
/* load the interface */
builder = gtk_builder_new();