[gtksourceview] scheme: cleanup naming and caching of current-line state
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] scheme: cleanup naming and caching of current-line state
- Date: Wed, 22 Dec 2021 07:32:12 +0000 (UTC)
commit bd95f69dc7cd37aa8b25dbb5ddc04787b24991cf
Author: Christian Hergert <chergert redhat com>
Date: Tue Dec 21 23:10:07 2021 -0800
scheme: cleanup naming and caching of current-line state
We try to cache some of this information to make it faster for us to use
from various parts of GtkSourceView at runtime. This cleans up the naming
so it is significantly less confusing to read foreground vs background.
gtksourceview/gtksourcestylescheme-private.h | 9 +++-
gtksourceview/gtksourcestylescheme.c | 38 +++++++++++++-
gtksourceview/gtksourceview-private.h | 3 ++
gtksourceview/gtksourceview.c | 75 +++++++++++++++++-----------
testsuite/test-stylescheme.c | 2 +-
5 files changed, 95 insertions(+), 32 deletions(-)
---
diff --git a/gtksourceview/gtksourcestylescheme-private.h b/gtksourceview/gtksourcestylescheme-private.h
index 176ba76d..0371b367 100644
--- a/gtksourceview/gtksourcestylescheme-private.h
+++ b/gtksourceview/gtksourcestylescheme-private.h
@@ -47,12 +47,19 @@ GtkSourceStyle *_gtk_source_style_scheme_get_right_margin_style (Gtk
G_GNUC_INTERNAL
GtkSourceStyle *_gtk_source_style_scheme_get_draw_spaces_style (GtkSourceStyleScheme *scheme);
G_GNUC_INTERNAL
-gboolean _gtk_source_style_scheme_get_current_line_color (GtkSourceStyleScheme *scheme,
+gboolean _gtk_source_style_scheme_get_current_line_number_bold (GtkSourceStyleScheme *scheme);
+G_GNUC_INTERNAL
+gboolean _gtk_source_style_scheme_get_current_line_background_color
+ (GtkSourceStyleScheme *scheme,
GdkRGBA *color);
G_GNUC_INTERNAL
gboolean _gtk_source_style_scheme_get_current_line_number_color(GtkSourceStyleScheme *scheme,
GdkRGBA *color);
G_GNUC_INTERNAL
+gboolean _gtk_source_style_scheme_get_current_line_number_background_color
+ (GtkSourceStyleScheme *scheme,
+ GdkRGBA *color);
+G_GNUC_INTERNAL
gboolean _gtk_source_style_scheme_get_background_pattern_color (GtkSourceStyleScheme *scheme,
GdkRGBA *color);
G_GNUC_INTERNAL
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index aa2c7766..64417c0a 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -641,8 +641,8 @@ get_color (GtkSourceStyle *style,
* Returns TRUE if the style for current-line is set in the scheme
*/
gboolean
-_gtk_source_style_scheme_get_current_line_color (GtkSourceStyleScheme *scheme,
- GdkRGBA *color)
+_gtk_source_style_scheme_get_current_line_background_color (GtkSourceStyleScheme *scheme,
+ GdkRGBA *color)
{
GtkSourceStyle *style;
@@ -665,6 +665,40 @@ _gtk_source_style_scheme_get_current_line_number_color (GtkSourceStyleScheme *sc
style = gtk_source_style_scheme_get_style (scheme, STYLE_CURRENT_LINE_NUMBER);
+ return get_color (style, TRUE, color);
+}
+
+gboolean
+_gtk_source_style_scheme_get_current_line_number_bold (GtkSourceStyleScheme *scheme)
+{
+ GtkSourceStyle *style;
+ gboolean bold_set = FALSE;
+ gboolean bold = FALSE;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), FALSE);
+
+ if ((style = gtk_source_style_scheme_get_style (scheme, STYLE_CURRENT_LINE_NUMBER)))
+ {
+ g_object_get (style,
+ "bold-set", &bold_set,
+ "bold", &bold,
+ NULL);
+ }
+
+ return !bold_set || bold;
+}
+
+gboolean
+_gtk_source_style_scheme_get_current_line_number_background_color (GtkSourceStyleScheme *scheme,
+ GdkRGBA *color)
+{
+ GtkSourceStyle *style;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), FALSE);
+ g_return_val_if_fail (color != NULL, FALSE);
+
+ style = gtk_source_style_scheme_get_style (scheme, STYLE_CURRENT_LINE_NUMBER);
+
return get_color (style, FALSE, color);
}
diff --git a/gtksourceview/gtksourceview-private.h b/gtksourceview/gtksourceview-private.h
index 6cd4cfbd..b19c344b 100644
--- a/gtksourceview/gtksourceview-private.h
+++ b/gtksourceview/gtksourceview-private.h
@@ -89,5 +89,8 @@ gboolean _gtk_source_view_get_current_line_background (GtkSourceView *vie
GdkRGBA *rgba);
gboolean _gtk_source_view_get_current_line_number_background (GtkSourceView *view,
GdkRGBA *rgba);
+gboolean _gtk_source_view_get_current_line_number_color (GtkSourceView *view,
+ GdkRGBA *rgba);
+gboolean _gtk_source_view_get_current_line_number_bold (GtkSourceView *view);
G_END_DECLS
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 5b73ef5e..879a26aa 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -187,8 +187,9 @@ typedef struct
GtkSourceGutterRenderer *marks_renderer;
GdkRGBA background_pattern_color;
- GdkRGBA current_line_color;
+ GdkRGBA current_line_background_color;
GdkRGBA current_line_number_color;
+ GdkRGBA current_line_number_background_color;
GdkRGBA right_margin_line_color;
GdkRGBA right_margin_overlay_color;
@@ -208,8 +209,10 @@ typedef struct
GtkSourceViewSnippets snippets;
guint background_pattern_color_set : 1;
- guint current_line_color_set : 1;
+ guint current_line_background_color_set : 1;
+ guint current_line_number_bold : 1;
guint current_line_number_color_set : 1;
+ guint current_line_number_background_color_set : 1;
guint right_margin_line_color_set : 1;
guint right_margin_overlay_color_set : 1;
guint tabs_set : 1;
@@ -2666,7 +2669,7 @@ gtk_source_view_paint_current_line_highlight (GtkSourceView *view,
gtk_source_view_paint_line_background (view,
snapshot,
y, height,
- &priv->current_line_color);
+ &priv->current_line_background_color);
}
static void
@@ -2706,7 +2709,7 @@ gtk_source_view_snapshot_layer (GtkTextView *text_view,
if (gtk_widget_is_sensitive (GTK_WIDGET (view)) &&
priv->highlight_current_line &&
- priv->current_line_color_set)
+ priv->current_line_background_color_set)
{
gtk_source_view_paint_current_line_highlight (view, snapshot);
}
@@ -4638,19 +4641,24 @@ update_current_line_color (GtkSourceView *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_background_color_set =
+ _gtk_source_style_scheme_get_current_line_background_color (priv->style_scheme,
+
&priv->current_line_background_color);
+ priv->current_line_number_background_color_set =
+ _gtk_source_style_scheme_get_current_line_number_background_color (priv->style_scheme,
+
&priv->current_line_number_background_color);
priv->current_line_number_color_set =
_gtk_source_style_scheme_get_current_line_number_color (priv->style_scheme,
-
&priv->current_line_number_color);
+
&priv->current_line_number_color);
+ priv->current_line_number_bold =
+ _gtk_source_style_scheme_get_current_line_number_bold (priv->style_scheme);
}
/* 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)
+ if (!priv->current_line_background_color_set)
{
GtkStyleContext *style_context = gtk_widget_get_style_context (GTK_WIDGET (view));
gboolean has_bg = FALSE;
@@ -4661,23 +4669,8 @@ update_current_line_color (GtkSourceView *view)
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;
+ premix_colors (&priv->current_line_background_color, &fg, &bg, has_bg, 0.05);
+ priv->current_line_background_color_set = TRUE;
}
}
@@ -5396,10 +5389,10 @@ _gtk_source_view_get_current_line_background (GtkSourceView *view,
if (rgba != NULL)
{
- *rgba = priv->current_line_color;
+ *rgba = priv->current_line_background_color;
}
- return priv->current_line_color_set;
+ return priv->current_line_background_color_set;
}
gboolean
@@ -5410,6 +5403,22 @@ _gtk_source_view_get_current_line_number_background (GtkSourceView *view,
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
+ if (rgba != NULL)
+ {
+ *rgba = priv->current_line_number_background_color;
+ }
+
+ return priv->current_line_number_background_color_set;
+}
+
+gboolean
+_gtk_source_view_get_current_line_number_color (GtkSourceView *view,
+ GdkRGBA *rgba)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+
+ g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
+
if (rgba != NULL)
{
*rgba = priv->current_line_number_color;
@@ -5417,3 +5426,13 @@ _gtk_source_view_get_current_line_number_background (GtkSourceView *view,
return priv->current_line_number_color_set;
}
+
+gboolean
+_gtk_source_view_get_current_line_number_bold (GtkSourceView *view)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+
+ g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
+
+ return priv->current_line_number_bold;
+}
diff --git a/testsuite/test-stylescheme.c b/testsuite/test-stylescheme.c
index be7fe443..af433a69 100644
--- a/testsuite/test-stylescheme.c
+++ b/testsuite/test-stylescheme.c
@@ -156,7 +156,7 @@ test_named_color_alpha (TestFixture *fixture,
scheme = gtk_source_style_scheme_manager_get_scheme (fixture->manager, "test");
/* Use these two semi private methods to compare a named color and a normal one */
- res = _gtk_source_style_scheme_get_current_line_color (scheme, &color1);
+ res = _gtk_source_style_scheme_get_current_line_background_color (scheme, &color1);
g_assert_true (res);
res = _gtk_source_style_scheme_get_background_pattern_color (scheme, &color2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]