[gtksourceview] view: premix current line background colors
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] view: premix current line background colors
- Date: Tue, 20 Jul 2021 23:06:42 +0000 (UTC)
commit 96567beb2eb73d1c4ad5b0df779542148e2a3e8c
Author: Christian Hergert <chergert redhat com>
Date: Tue Jul 20 15:44:54 2021 -0700
view: premix current line background colors
This will give us a chance at rendering the background without any sort
of alpha compositing.
gtksourceview/gtksourceview.c | 68 +++++++++++++++++++++++++++++++++----------
1 file changed, 52 insertions(+), 16 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index a525223f..617e1035 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -188,6 +188,7 @@ typedef struct
GdkRGBA background_pattern_color;
GdkRGBA current_line_color;
+ GdkRGBA current_line_number_color;
GdkRGBA right_margin_line_color;
GdkRGBA right_margin_overlay_color;
@@ -208,6 +209,7 @@ typedef struct
guint background_pattern_color_set : 1;
guint current_line_color_set : 1;
+ guint current_line_number_color_set : 1;
guint right_margin_line_color_set : 1;
guint right_margin_overlay_color_set : 1;
guint tabs_set : 1;
@@ -4621,22 +4623,6 @@ update_background_pattern_color (GtkSourceView *view)
&priv->background_pattern_color);
}
-static void
-update_current_line_color (GtkSourceView *view)
-{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
- if (priv->style_scheme == NULL)
- {
- priv->current_line_color_set = FALSE;
- return;
- }
-
- priv->current_line_color_set =
- _gtk_source_style_scheme_get_current_line_color (priv->style_scheme,
- &priv->current_line_color);
-}
-
static inline void
premix_colors (GdkRGBA *dest,
const GdkRGBA *fg,
@@ -4663,6 +4649,56 @@ premix_colors (GdkRGBA *dest,
}
}
+static void
+update_current_line_color (GtkSourceView *view)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+
+ if (priv->style_scheme != NULL)
+ {
+ priv->current_line_color_set =
+ _gtk_source_style_scheme_get_current_line_color (priv->style_scheme,
+ &priv->current_line_color);
+ priv->current_line_number_color_set =
+ _gtk_source_style_scheme_get_current_line_number_color (priv->style_scheme,
+
&priv->current_line_number_color);
+ }
+
+ /* If we failed to get a highlight-current-line color, then premix the foreground
+ * and the background to give something relatively useful (and avoid alpha-composite
+ * if we can w/ premix).
+ */
+ if (!priv->current_line_color_set)
+ {
+ GtkStyleContext *style_context = gtk_widget_get_style_context (GTK_WIDGET (view));
+ gboolean has_bg = FALSE;
+ GdkRGBA fg, bg;
+
+ if (priv->style_scheme != NULL)
+ has_bg = _gtk_source_style_scheme_get_background_color (priv->style_scheme, &bg);
+
+ gtk_style_context_get_color (style_context, &fg);
+
+ premix_colors (&priv->current_line_color, &fg, &bg, has_bg, 0.05);
+ priv->current_line_color_set = TRUE;
+ }
+
+ if (!priv->current_line_number_color_set)
+ {
+ GtkStyleContext *style_context = gtk_widget_get_style_context (GTK_WIDGET (view));
+ gboolean has_bg = FALSE;
+ GdkRGBA fg, bg;
+
+ if (priv->style_scheme != NULL)
+ has_bg = _gtk_source_style_scheme_get_background_color (priv->style_scheme, &bg);
+
+ gtk_style_context_get_color (style_context, &fg);
+
+ premix_colors (&priv->current_line_number_color, &fg, &bg, has_bg, 0.05);
+ priv->current_line_number_color_set = TRUE;
+ }
+}
+
static void
update_right_margin_colors (GtkSourceView *view)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]