summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-08-13 13:22:42 +0200
committerTor Andersson <tor.andersson@artifex.com>2015-10-06 11:21:23 +0200
commit9e21f954145e690ae44ff91b1deb0c2071b324b4 (patch)
tree025a0283001ac1321917557e5dcb42e8390bcaab
parentba0aed96eeb8ce2b897b711bd07068e19fd02632 (diff)
downloadmupdf-9e21f954145e690ae44ff91b1deb0c2071b324b4.tar.xz
glut: Mouse select text in text fields.
-rw-r--r--platform/glut/glut-main.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/platform/glut/glut-main.c b/platform/glut/glut-main.c
index 119597f0..e7c8885c 100644
--- a/platform/glut/glut-main.c
+++ b/platform/glut/glut-main.c
@@ -363,6 +363,19 @@ static float measure_string_part(const int *s, const int *e)
return w;
}
+static int *find_string_location(int *s, int *e, float w, float x)
+{
+ while (s < e)
+ {
+ int cw = glutBitmapWidth(GLUT_BITMAP_HELVETICA_12, *s);
+ if (w + (cw / 2) >= x)
+ return s;
+ w += cw;
+ ++s;
+ }
+ return e;
+}
+
static inline int isalnum(int c)
{
int cat = ucdn_get_general_category(c);
@@ -392,6 +405,19 @@ static void ui_input_draw(int x0, int y0, int x1, int y1, struct input *input)
float px, qx, ex;
int *p, *q;
+ if (ui.x >= x0 && ui.x < x1 && ui.y >= y0 && ui.y < y1)
+ {
+ ui.hot = input;
+ if (!ui.active && ui.down)
+ {
+ ui.active = input;
+ input->p = find_string_location(input->text, input->end, x0 + 2, ui.x);
+ }
+ }
+
+ if (ui.active == input)
+ input->q = find_string_location(input->text, input->end, x0 + 2, ui.x);
+
glColor4f(1, 1, 1, 1);
glRectf(x0, y0, x1, y1);