aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/frame.c35
-rw-r--r--src/frame.h3
-rw-r--r--src/sc_editor.c9
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) )
{