aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-11-09 21:23:10 +0100
committerThomas White <taw@bitwiz.org.uk>2011-11-09 21:23:10 +0100
commit6ee425b365d2486304f05ff87da3f1846eb26408 (patch)
tree55dfeeb314747b0172881348acf16928f4bab751 /src
parente96766c0531adca197c8b02f58070cf68286b0b0 (diff)
Drag to move objects with rubber band box (faster)
Diffstat (limited to 'src')
-rw-r--r--src/tool_select.c72
1 files changed, 60 insertions, 12 deletions
diff --git a/src/tool_select.c b/src/tool_select.c
index bf2393e..ca537e1 100644
--- a/src/tool_select.c
+++ b/src/tool_select.c
@@ -35,11 +35,24 @@
#include "slide_render.h"
+enum select_drag_reason
+{
+ SELECT_DRAG_REASON_NONE,
+ SELECT_DRAG_REASON_POTENTIAL_MOVE,
+ SELECT_DRAG_REASON_MOVE,
+};
+
+
struct select_toolinfo
{
struct toolinfo base;
double drag_offs_x;
double drag_offs_y;
+ double box_x;
+ double box_y;
+ double box_width;
+ double box_height;
+ enum select_drag_reason drag_reason;
};
@@ -56,35 +69,61 @@ static void click_select(struct presentation *p, struct toolinfo *tip,
*drag_status = DRAG_STATUS_COULD_DRAG;
*drag_reason = DRAG_REASON_TOOL;
+ ti->drag_reason = SELECT_DRAG_REASON_MOVE;
}
-static void drag(struct toolinfo *tip, struct presentation *p,
- struct object *o, double x, double y)
+static void update_box(struct select_toolinfo *ti, double x, double y,
+ struct object *o)
{
- struct select_toolinfo *ti = (struct select_toolinfo *)tip;
+ double nx, ny;
double eright, ebottom;
- o->x = x + ti->drag_offs_x;
- o->y = y + ti->drag_offs_y;
+ nx = x + ti->drag_offs_x;
+ ny = y + ti->drag_offs_y;
/* Enforce margins */
eright = o->parent->parent->slide_width - o->style->margin_right;
ebottom = o->parent->parent->slide_height - o->style->margin_bottom;
- if ( o->x < o->style->margin_left ) o->x = o->style->margin_left;
- if ( o->y < o->style->margin_top ) o->y = o->style->margin_top;
- if ( o->x+o->bb_width > eright ) o->x = eright - o->bb_width;
- if ( o->y+o->bb_height > ebottom ) o->y = ebottom - o->bb_height;
+ if ( nx < o->style->margin_left ) nx = o->style->margin_left;
+ if ( ny < o->style->margin_top ) ny = o->style->margin_top;
+ if ( nx+o->bb_width > eright ) nx = eright - o->bb_width;
+ if ( ny+o->bb_height > ebottom ) ny = ebottom - o->bb_height;
+
+ ti->box_x = nx;
+ ti->box_y = ny;
+ ti->box_width = o->bb_width;
+ ti->box_height = o->bb_height;
+}
- o->update_object(o);
- redraw_slide(o->parent);
+
+static void drag(struct toolinfo *tip, struct presentation *p,
+ struct object *o, double x, double y)
+{
+ struct select_toolinfo *ti = (struct select_toolinfo *)tip;
+
+ if ( ti->drag_reason != SELECT_DRAG_REASON_POTENTIAL_MOVE ) {
+ ti->drag_reason = SELECT_DRAG_REASON_MOVE;
+ }
+
+ if ( ti->drag_reason != SELECT_DRAG_REASON_MOVE ) return;
+
+ update_box(ti, x, y, o);
+
+ redraw_overlay(p);
}
static void end_drag(struct toolinfo *tip, struct presentation *p,
struct object *o, double x, double y)
{
- /* FIXME: Update projection or something? */
+ struct select_toolinfo *ti = (struct select_toolinfo *)tip;
+
+ update_box(ti, x, y, o);
+ o->x = ti->box_x;
+ o->y = ti->box_y;
+ ti->drag_reason = SELECT_DRAG_REASON_NONE;
+ redraw_slide(o->parent);
}
@@ -110,9 +149,16 @@ static int deselect_object(struct object *o,struct toolinfo *tip)
static void draw_overlay(struct toolinfo *tip, cairo_t *cr, struct object *o)
{
+ struct select_toolinfo *ti = (struct select_toolinfo *)tip;
+
if ( o != NULL ) {
draw_editing_box(cr, o->x, o->y, o->bb_width, o->bb_height);
}
+
+ if ( ti->drag_reason == SELECT_DRAG_REASON_MOVE ) {
+ draw_rubberband_box(cr, ti->box_x, ti->box_y,
+ ti->box_width, ti->box_height);
+ }
}
@@ -140,6 +186,8 @@ struct toolinfo *initialise_select_tool()
ti = malloc(sizeof(*ti));
+ ti->drag_reason = SELECT_DRAG_REASON_NONE;
+
ti->base.click_select = click_select;
ti->base.create_default = NULL;
ti->base.select = select_object;