diff options
author | Thomas White <taw@bitwiz.me.uk> | 2019-05-07 18:23:59 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.me.uk> | 2019-05-07 18:23:59 +0200 |
commit | e9c36334f53bb6aea931d0ec00e8967ef822c92c (patch) | |
tree | 4c8f2a982f6da60697ede9021e8bfb999d7143d8 /libstorycode/gtk | |
parent | e1f1f218ba9559161f5fc1c01bcdda1dd7eb308e (diff) |
Beautify cursor and selection highlight for slides
Diffstat (limited to 'libstorycode/gtk')
-rw-r--r-- | libstorycode/gtk/gtknarrativeview.c | 74 |
1 files changed, 45 insertions, 29 deletions
diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index 600e01f..a174c9d 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -554,50 +554,66 @@ static void get_cursor_pos(Narrative *n, struct edit_pos cpos, } -static void draw_caret(cairo_t *cr, Narrative *n, struct edit_pos cpos, - int hgh, double ww) +static void draw_caret(cairo_t *cr, Narrative *n, struct edit_pos cpos, double ww) { - double cx, clow, chigh, h; - const double t = 1.8; + assert(n != NULL); - if ( hgh ) { - draw_para_highlight(cr, n, cpos.para, ww); - return; - } + if ( narrative_item_is_text(n, cpos.para) ) { - assert(n != NULL); + /* Normal text-style cursor */ - if ( n->items[cpos.para].type == NARRATIVE_ITEM_SLIDE ) { - draw_para_highlight(cr, n, cpos.para, ww); - return; - } + double cx, clow, chigh, h; + const double t = 1.8; - get_cursor_pos(n, cpos, &cx, &clow, &h); + get_cursor_pos(n, cpos, &cx, &clow, &h); - chigh = clow+h; + chigh = clow+h; - cairo_move_to(cr, cx, clow); - cairo_line_to(cr, cx, chigh); + cairo_move_to(cr, cx, clow); + cairo_line_to(cr, cx, chigh); - cairo_move_to(cr, cx-t, clow-t); - cairo_line_to(cr, cx, clow); - cairo_move_to(cr, cx+t, clow-t); - cairo_line_to(cr, cx, clow); + cairo_move_to(cr, cx-t, clow-t); + cairo_line_to(cr, cx, clow); + cairo_move_to(cr, cx+t, clow-t); + cairo_line_to(cr, cx, clow); - cairo_move_to(cr, cx-t, chigh+t); - cairo_line_to(cr, cx, chigh); - cairo_move_to(cr, cx+t, chigh+t); - cairo_line_to(cr, cx, chigh); + cairo_move_to(cr, cx-t, chigh+t); + cairo_line_to(cr, cx, chigh); + cairo_move_to(cr, cx+t, chigh+t); + cairo_line_to(cr, cx, chigh); - cairo_set_source_rgb(cr, 0.86, 0.0, 0.0); - cairo_set_line_width(cr, 1.0); - cairo_stroke(cr); + cairo_set_source_rgb(cr, 0.86, 0.0, 0.0); + cairo_set_line_width(cr, 1.0); + cairo_stroke(cr); + + } else { + + /* Block highlight cursor */ + + double cx, cy, cw, ch; + + cx = n->space_l - 5.5; + cy = n->space_t + para_top(n, cpos.para) - 5.5; + cw = n->items[cpos.para].slide_w + 11.0; + ch = n->items[cpos.para].slide_h + 11.0; + + cairo_new_path(cr); + cairo_rectangle(cr, cx, cy, cw, ch); + cairo_set_source_rgb(cr, 0.86, 0.0, 0.0); + cairo_set_line_width(cr, 1.0); + cairo_stroke(cr); + + } } static void draw_overlay(cairo_t *cr, GtkNarrativeView *e) { - draw_caret(cr, e->n, e->cpos, e->para_highlight, e->w); + if ( e->para_highlight ) { + draw_para_highlight(cr, e->n, e->cpos.para, e->w); + } else { + draw_caret(cr, e->n, e->cpos, e->w); + } } |