[ghex] gtkhex: Cursor rendering improvements
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex] gtkhex: Cursor rendering improvements
- Date: Thu, 9 Dec 2021 21:20:25 +0000 (UTC)
commit a4998b472d704672c66ff2d45e2311f210868a8a
Author: Logan Rathbone <poprocks gmail com>
Date: Thu Dec 9 16:03:32 2021 -0500
gtkhex: Cursor rendering improvements
No longer simply render based on :selected bg color - use :checked
pseudoclass (if we'd used separate widgets for all this stuff we
wouldn't have to be hunting for pseudoclasses that _kinda_ fit...)
Draw a dashed cursor for either pane if out of focus.
ISSUES: some redraws getting missed when widgets go in and out of focus.
Likely this isn't a _new_ issue, but just having these different colours
is revealing issues that were there all along.
src/ghex.css | 5 +++++
src/gtkhex.c | 48 ++++++++++++++++++++++++++++++++----------------
2 files changed, 37 insertions(+), 16 deletions(-)
---
diff --git a/src/ghex.css b/src/ghex.css
index 78364f4..526d9ab 100644
--- a/src/ghex.css
+++ b/src/ghex.css
@@ -9,6 +9,11 @@ hex {
background-color: alpha(red, 0.5);
}
+.view:checked {
+ color: @theme_bg_color;
+ background-color: alpha(@theme_fg_color, 0.9);
+}
+
#offsets {
background-color: shade(@theme_bg_color, 0.95);
}
diff --git a/src/gtkhex.c b/src/gtkhex.c
index c145cb5..8d6a1f1 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -562,6 +562,7 @@ render_cursor (GtkHex *gh,
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_color (context, &fg_color);
/* Find out if we're at the end of the row and/or the end of the file,
* since this will make a difference when in insert mode
@@ -597,13 +598,10 @@ render_cursor (GtkHex *gh,
if (gh->insert && at_file_end)
{
- if (at_new_row)
- {
+ if (at_new_row) {
range[0] = 0;
range[1] = 1;
- }
- else
- {
+ } else {
--range[0];
--range[1];
}
@@ -628,14 +626,30 @@ render_cursor (GtkHex *gh,
cairo_clip (cr);
cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
- /* Render background - fill bg with default selection colour if we have
- * focus on the pane in question; otherwise, draw a solid box.
+ /* - If don't have focus: draw dashed square.
+ * - If have focus, draw filled in square (colour defined w/ css using
+ * `:checked` pseudoclass) if the pane we're drawing is selected;
+ * otherwise, draw a solid square.
*/
- if (gh->active_view == cursor_type)
+ if (! gtk_widget_has_focus (GTK_WIDGET(gh)))
+ {
+ cairo_save (cr);
+ cairo_set_source_rgba (cr,
+ fg_color.red, fg_color.green, fg_color.blue, 0.75);
+
+ cairo_set_line_width (cr, 1.5);
+ cairo_set_dash (cr, (double[]){1.0}, 1, 0.0);
+
+ cairo_rectangle (cr, x1, y1, ABS(x2-x1), ABS(y2-y1));
+
+ cairo_stroke (cr);
+ cairo_restore (cr);
+ }
+ else if (gh->active_view == cursor_type)
{
gtk_style_context_save (context);
- state |= GTK_STATE_FLAG_SELECTED;
+ state |= GTK_STATE_FLAG_CHECKED;
gtk_style_context_set_state (context, state);
gtk_render_background (context, cr,
@@ -656,11 +670,9 @@ render_cursor (GtkHex *gh,
}
else
{
- gtk_style_context_get_color (context, &fg_color);
cairo_save (cr);
cairo_set_source_rgba (cr,
- fg_color.red, fg_color.green, fg_color.blue,
- fg_color.alpha);
+ fg_color.red, fg_color.green, fg_color.blue, fg_color.alpha);
cairo_set_line_width (cr, 1.5);
cairo_rectangle (cr, x1, y1, ABS(x2-x1), ABS(y2-y1));
@@ -668,10 +680,7 @@ render_cursor (GtkHex *gh,
cairo_stroke (cr);
cairo_restore (cr);
}
-
- /* Restore state from cairo_clip */
-
- cairo_restore (cr);
+ cairo_restore (cr); /* from cairo_clip above */
}
static void
@@ -739,8 +748,15 @@ render_highlights (GtkHex *gh,
if (is_autohighlight)
state |= GTK_STATE_FLAG_LINK;
else
+ {
state |= GTK_STATE_FLAG_SELECTED;
+ if (gtk_widget_has_focus (GTK_WIDGET(gh)))
+ {
+ state |= GTK_STATE_FLAG_FOCUS_WITHIN;
+ }
+ }
+
gtk_style_context_set_state (context, state);
gtk_hex_validate_highlight (gh, highlight);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]