[dia] text: improve cursor positioning via mouse
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] text: improve cursor positioning via mouse
- Date: Thu, 25 Sep 2014 19:26:18 +0000 (UTC)
commit 09985069ec609412af3f21e2c2c5995ec3df772a
Author: Hans Breuer <hans breuer org>
Date: Mon Sep 22 23:48:07 2014 +0200
text: improve cursor positioning via mouse
the click had to be completely after the glyph, now the right half
of the glyph is enough
lib/text.c | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/lib/text.c b/lib/text.c
index 4660308..050189f 100644
--- a/lib/text.c
+++ b/lib/text.c
@@ -708,14 +708,19 @@ text_set_cursor(Text *text, Point *clicked_point,
/* Do an ugly linear search for the cursor index:
TODO: Change to binary search */
-
- for (i=0;i<=text_get_line_strlen(text, row);i++) {
- str_width_first =
- DIA_RENDERER_GET_CLASS(renderer)->get_text_width(renderer, text_get_line(text, row), i);
- if (clicked_point->x - start_x >= str_width_first) {
- text->cursor_pos = i;
- } else {
- return;
+ {
+ real min_dist = G_MAXDOUBLE;
+ for (i=0;i<=text_get_line_strlen(text, row);i++) {
+ real dist;
+ str_width_first =
+ DIA_RENDERER_GET_CLASS(renderer)->get_text_width(renderer, text_get_line(text, row), i);
+ dist = fabs(clicked_point->x - (start_x + str_width_first));
+ if (dist < min_dist) {
+ min_dist = dist;
+ text->cursor_pos = i;
+ } else {
+ return;
+ }
}
}
text->cursor_pos = text_get_line_strlen(text, row);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]