diff options
author | Thomas White <taw@bitwiz.org.uk> | 2016-03-29 17:57:42 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2016-03-29 17:57:42 +0200 |
commit | b14d1503e73100f6973c813845632dfa05c583b9 (patch) | |
tree | cef1c7900d956ca57b8e6d9de4a2d780483a4b79 /src | |
parent | 0973dc26a6c384a09d898bc0bcfa41ee6f962129 (diff) |
Highlight the current paragraph
Has the nice effect of showing which slide is selected.
Diffstat (limited to 'src')
-rw-r--r-- | src/frame.c | 35 | ||||
-rw-r--r-- | src/frame.h | 3 | ||||
-rw-r--r-- | src/sc_editor.c | 9 |
3 files changed, 43 insertions, 4 deletions
diff --git a/src/frame.c b/src/frame.c index f71e764..b021b42 100644 --- a/src/frame.c +++ b/src/frame.c @@ -576,6 +576,31 @@ int find_cursor(struct frame *fr, double x, double y, } +int get_para_highlight(struct frame *fr, int cursor_para, + double *cx, double *cy, double *cw, double *ch) +{ + Paragraph *para; + int i; + double py = 0.0; + + if ( cursor_para > fr->n_paras ) { + fprintf(stderr, "Cursor paragraph number is too high!\n"); + return 1; + } + + para = fr->paras[cursor_para]; + for ( i=0; i<cursor_para; i++ ) { + py += fr->paras[i]->height; + } + + *cx = fr->pad_l; + *cy = fr->pad_t + py; + *cw = fr->w - fr->pad_l - fr->pad_r; + *ch = para->height; + return 0; +} + + int get_cursor_pos(struct frame *fr, int cursor_para, int cursor_pos, double *cx, double *cy, double *ch) { @@ -590,14 +615,16 @@ int get_cursor_pos(struct frame *fr, int cursor_para, int cursor_pos, } para = fr->paras[cursor_para]; + for ( i=0; i<cursor_para; i++ ) { + py += fr->paras[i]->height; + } - if ( para->type != PARA_TYPE_TEXT ) return 1; + if ( para->type != PARA_TYPE_TEXT ) { + return 1; + } pango_layout_get_cursor_pos(para->layout, cursor_pos, &rect, NULL); - for ( i=0; i<cursor_para; i++ ) { - py += fr->paras[i]->height; - } *cx = pango_units_to_double(rect.x) + fr->pad_l; *cy = pango_units_to_double(rect.y) + fr->pad_t + py; *ch = pango_units_to_double(rect.height); diff --git a/src/frame.h b/src/frame.h index 976fc2b..f61f414 100644 --- a/src/frame.h +++ b/src/frame.h @@ -130,6 +130,9 @@ extern size_t end_offset_of_para(struct frame *fr, int pn); extern int find_cursor(struct frame *fr, double x, double y, int *ppara, int *ppos, int *ptrail); +extern int get_para_highlight(struct frame *fr, int cursor_para, + double *cx, double *cy, double *cw, double *ch); + extern int get_cursor_pos(struct frame *fr, int cursor_para, int cursor_pos, double *cx, double *cy, double *ch); diff --git a/src/sc_editor.c b/src/sc_editor.c index 379af90..5352028 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -403,8 +403,17 @@ static void draw_caret(cairo_t *cr, struct frame *fr, int cursor_para, size_t cursor_pos, int cursor_trail) { double cx, clow, chigh, h; + double cy, w; const double t = 1.8; + if ( get_para_highlight(fr, cursor_para, &cx, &cy, &w, &h) == 0 ) { + cairo_new_path(cr); + cairo_rectangle(cr, cx, cy, w, h); + cairo_set_source_rgba(cr, 0.7, 0.7, 1.0, 0.5); + cairo_set_line_width(cr, 5.0); + cairo_stroke(cr); + } + if ( get_cursor_pos(fr, cursor_para, cursor_pos+cursor_trail, &cx, &clow, &h) ) { |