summaryrefslogtreecommitdiff
path: root/platform/gl/gl-input.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-02-21 22:00:10 +0100
committerRobin Watts <robin.watts@artifex.com>2018-06-22 16:48:46 +0100
commit41050d282409f86f425ac4a157fc07d889e4b54d (patch)
treeff0611853ff17214a3c6e3e472b7ee2dfb425107 /platform/gl/gl-input.c
parentbde703f83b83232f830426b45957b10e4e44043d (diff)
downloadmupdf-41050d282409f86f425ac4a157fc07d889e4b54d.tar.xz
gl: Add annotation editor.
* Select with right mouse, edit with left mouse. * Clamp movement to page area. * Integrate page scroll offset into matrices. * Edit Ink annotations. * Initialise important annotation properties when creating them. * Deselect annotation when pressing ESC. * Add polygon/polyline annotation editing. * Tweak polygon editing. * Edit square/circle annotations. * Cancel canvas edits on right click. * Expand selectable areas and grab zones for rects. * Edit line annotations. * Edit caret annotations. * Return true when value has changed (checkbox and slider). * Add popup menu widget: Menu items are drawn at ui_end to overlay other widgets properly. * Use popup menu to set icons. * Fix text selection translation offset. * Edit quad point annotations. * Set user and modification date when creating new annotations. * Add select widget. * Edit line endings. * Edit highlight opacity. * Create properly sized stamp annotations. * Edit FreeText annotations. * Trigger list selection on mouse-up instead of mouse-down. * Use index in ui_select. * Edit Freetext quadding. * Fix windows build issues. * Use 'const void *' for ids. * Add file dialog to choose file when none given on command line. * Add save file dialog. * Add pdfwrite options to save dialog. * Add error dialog instead of dying silently on exceptions. * Add password dialog. * Add warning dialog that does not exit the program. * Show in title bar when document is modified. * Separate motion and passive motion callbacks. * Add /Volumes 'disk' for MacOS X mount points. * Tweak input focus/blur handling. * Use popup menu to create annotations instead of big list of buttons. * Update appearance after canvas edits too. * Release old grab before checking for new grab and taking focus. * Set cursor shape depending on hot item. * Draw prettier widgets. * Use integers for slider to allow snapping to values. * Add 'ui.gridsize' to ease layout of buttons and text fields. * Tweak file dialog layout. * Bevels around lists and scroll bars. * Only add new points to the ink list when drawing. * Use named color constants instead of hardcoding color values. * Adjust layout and which properties to edit for each annotation. * Use a panel for search field. * Add splitter, dialogs, and panel padding. * Popup menus above the button if they don't fit below it. * Use triangle strip to draw check mark.
Diffstat (limited to 'platform/gl/gl-input.c')
-rw-r--r--platform/gl/gl-input.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/platform/gl/gl-input.c b/platform/gl/gl-input.c
index ad68a692..73243865 100644
--- a/platform/gl/gl-input.c
+++ b/platform/gl/gl-input.c
@@ -89,6 +89,7 @@ static void ui_input_delete_selection(struct input *input)
char *q = input->p > input->q ? input->p : input->q;
memmove(p, q, input->end - q);
input->end -= q - p;
+ *input->end = 0;
input->p = input->q = p;
}
@@ -111,6 +112,8 @@ static int ui_input_key(struct input *input)
{
switch (ui.key)
{
+ case 0:
+ return UI_INPUT_NONE;
case KEY_LEFT:
if (ui.mod == GLUT_ACTIVE_CTRL + GLUT_ACTIVE_SHIFT)
{
@@ -213,7 +216,7 @@ static int ui_input_key(struct input *input)
break;
case KEY_ESCAPE:
ui.focus = NULL;
- return UI_INPUT_CANCEL;
+ return UI_INPUT_NONE;
case KEY_ENTER:
ui.focus = NULL;
return UI_INPUT_ACCEPT;
@@ -281,66 +284,74 @@ static int ui_input_key(struct input *input)
}
break;
}
- return UI_INPUT_CONTINUE;
+ return UI_INPUT_EDIT;
}
void ui_input_init(struct input *input, const char *text)
{
fz_strlcpy(input->text, text, sizeof input->text);
input->end = input->text + strlen(input->text);
- input->p = input->q = input->text;
+ input->p = input->text;
+ input->q = input->end;
}
int ui_input(struct input *input, int width)
{
fz_irect area;
- float px, qx;
+ float ax, px, qx;
char *p, *q;
int state;
- area = ui_pack(width, ui.lineheight + 4);
+ area = ui_pack(width, ui.lineheight + 6);
if (ui_mouse_inside(&area))
{
ui.hot = input;
+ if (!ui.active || ui.active == input)
+ ui.cursor = GLUT_CURSOR_TEXT;
if (!ui.active && ui.down)
{
- input->p = find_string_location(input->text, input->end, area.x0 + 2, ui.x);
+ input->p = find_string_location(input->text, input->end, area.x0 + 3, ui.x);
ui.active = input;
}
}
if (ui.active == input)
{
- input->q = find_string_location(input->text, input->end, area.x0 + 2, ui.x);
+ input->q = find_string_location(input->text, input->end, area.x0 + 3, ui.x);
ui.focus = input;
}
if (ui.focus == input)
state = ui_input_key(input);
else
- state = 0;
+ state = UI_INPUT_NONE;
- glColor4f(0, 0, 0, 1);
- glRectf(area.x0, area.y0, area.x1, area.y1);
-
- glColor4f(1, 1, 1, 1);
- glRectf(area.x0+1, area.y0+1, area.x1-1, area.y1-1);
+ ui_draw_bevel_rect(area, UI_COLOR_TEXT_BG, 1);
p = input->p < input->q ? input->p : input->q;
q = input->p > input->q ? input->p : input->q;
- px = area.x0 + 2 + measure_string_part(input->text, p);
+ ax = area.x0 + 4;
+ px = ax + measure_string_part(input->text, p);
qx = px + measure_string_part(p, q);
if (ui.focus == input)
{
- glColor4f(0.6f, 0.6f, 1.0f, 1.0f);
- glRectf(px, area.y0 + 2, qx+1, area.y1 - 2);
+ glColorHex(UI_COLOR_TEXT_SEL_BG);
+ glRectf(px, area.y0 + 3, qx+1, area.y1 - 3);
+ glColorHex(UI_COLOR_TEXT_FG);
+ draw_string_part(ax, area.y0 + 3, input->text, p);
+ glColorHex(UI_COLOR_TEXT_SEL_FG);
+ draw_string_part(px, area.y0 + 3, p, q);
+ glColorHex(UI_COLOR_TEXT_FG);
+ draw_string_part(qx, area.y0 + 3, q, input->end);
+ }
+ else
+ {
+ glColorHex(UI_COLOR_TEXT_FG);
+ draw_string_part(ax, area.y0 + 3, input->text, input->end);
}
-
- glColor4f(0, 0, 0, 1);
- draw_string_part(area.x0 + 2, area.y0 + 2, input->text, input->end);
return state;
}