diff --git a/TODO b/TODO index 182a4fd..b6ca810 100644 --- a/TODO +++ b/TODO @@ -24,7 +24,6 @@ Style: Bugs: - default silk width has no business being hard-coded in obj.c - undelete only works if not much has changed since the deletion -- re-center while dragging confuses the save-under mechanism Code cleanup: - merge edit_unique with edit_name diff --git a/gui_canvas.c b/gui_canvas.c index 4da67c2..a0aae44 100644 --- a/gui_canvas.c +++ b/gui_canvas.c @@ -104,6 +104,7 @@ void redraw(void) gdk_draw_rectangle(ctx.widget->window, gc_bg, TRUE, 0, 0, aw, ah); inst_draw(&ctx); + tool_redraw(&ctx); } @@ -198,7 +199,10 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event, { struct coord pos = canvas_to_coord(&ctx, event->x, event->y); - if (dragging) { + switch (event->button) { + case 1: + if (!dragging) + break; dragging = 0; if (hypot(pos.x-drag_start.x, pos.y-drag_start.y)/ctx.scale < DRAG_MIN_R) @@ -207,6 +211,7 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event, if (tool_end_drag(&ctx, pos)) change_world(); } + break; } return TRUE; } @@ -234,9 +239,10 @@ static void zoom_out(struct coord pos) bbox = inst_get_bbox(); bbox.min = translate(&ctx, bbox.min); bbox.max = translate(&ctx, bbox.max); - if (bbox.min.x >= 0 && bbox.max.y >= 0 && - bbox.max.x < ctx.widget->allocation.width && - bbox.min.y < ctx.widget->allocation.height) + if (bbox.min.x >= ZOOM_STOP_BORDER && + bbox.max.y >= ZOOM_STOP_BORDER && + bbox.max.x < ctx.widget->allocation.width-ZOOM_STOP_BORDER && + bbox.min.y < ctx.widget->allocation.height-ZOOM_STOP_BORDER) return; ctx.scale *= 2; ctx.center.x = 2*ctx.center.x-pos.x; diff --git a/gui_style.h b/gui_style.h index f5ee427..5b373a9 100644 --- a/gui_style.h +++ b/gui_style.h @@ -24,6 +24,9 @@ #define CANVAS_CLEARANCE 10 +#define ZOOM_STOP_BORDER 50 /* stop zoom if we have at least a 50 + pixel border */ + #define VEC_ARROW_LEN 10 #define VEC_ARROW_ANGLE 20 #define VEC_EYE_R 5 diff --git a/gui_tools.c b/gui_tools.c index 2f1a5ea..73197f0 100644 --- a/gui_tools.c +++ b/gui_tools.c @@ -59,7 +59,6 @@ static struct tool_ops *active_ops = NULL; static struct inst *hover_inst = NULL; static GtkWidget *frame_image, *frame_image_locked, *frame_image_ready; - static struct drag_state { struct inst *inst; /* non-NULL if dragging an existing object */ struct inst *new; /* non-NULL if dragging a new object */ @@ -72,6 +71,7 @@ static struct drag_state { }; static struct pix_buf *pix_buf; +static struct coord last_canvas_pos; static struct vec *new_vec(struct inst *base) @@ -706,6 +706,7 @@ int tool_consider_drag(struct draw_ctx *ctx, struct coord pos) assert(!drag.new); assert(!drag.anchors_n); + last_canvas_pos = translate(ctx, pos); curr = inst_find_point(ctx, pos); if (!curr) return 0; @@ -736,6 +737,7 @@ void tool_drag(struct draw_ctx *ctx, struct coord to) { if (pix_buf) restore_pix_buf(pix_buf); + last_canvas_pos = translate(ctx, to); tool_hover(ctx, to); pix_buf = drag.new ? active_ops->drag_new(ctx, drag.new, to) : inst_draw_move(drag.inst, ctx, to, drag.anchor_i); @@ -746,8 +748,10 @@ void tool_cancel_drag(struct draw_ctx *ctx) { tool_dehover(ctx); tool_reset(); - if (pix_buf) + if (pix_buf) { restore_pix_buf(pix_buf); + pix_buf = NULL; + } drag.new = NULL; active_ops = NULL; drag.anchors_n = 0; @@ -776,6 +780,18 @@ int tool_end_drag(struct draw_ctx *ctx, struct coord to) } +void tool_redraw(struct draw_ctx *ctx) +{ + if (!drag.new && !drag.anchors_n) + return; + if (pix_buf) + free_pix_buf(pix_buf); + pix_buf = NULL; + tool_drag(ctx, canvas_to_coord(ctx, + last_canvas_pos.x, last_canvas_pos.y)); +} + + /* ----- tool bar creation ------------------------------------------------- */ diff --git a/gui_tools.h b/gui_tools.h index 836113c..8cf3920 100644 --- a/gui_tools.h +++ b/gui_tools.h @@ -42,6 +42,7 @@ int tool_consider_drag(struct draw_ctx *ctx, struct coord pos); void tool_drag(struct draw_ctx *ctx, struct coord to); void tool_cancel_drag(struct draw_ctx *ctx); int tool_end_drag(struct draw_ctx *ctx, struct coord to); +void tool_redraw(struct draw_ctx *ctx); /* * Cache the frame and track it. diff --git a/gui_util.c b/gui_util.c index aa9f249..05df08f 100644 --- a/gui_util.c +++ b/gui_util.c @@ -51,6 +51,13 @@ void set_width(GdkGC *gc, int width) /* ----- backing store ----------------------------------------------------- */ +void free_pix_buf(struct pix_buf *buf) +{ + g_object_unref(G_OBJECT(buf->buf)); + free(buf); +} + + struct pix_buf *save_pix_buf(GdkDrawable *da, int xa, int ya, int xb, int yb, int border) { @@ -92,8 +99,7 @@ void restore_pix_buf(struct pix_buf *buf) { gdk_draw_pixbuf(buf->da, NULL, buf->buf, 0, 0, buf->x, buf->y, -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0); - g_object_unref(G_OBJECT(buf->buf)); - free(buf); + free_pix_buf(buf); } diff --git a/gui_util.h b/gui_util.h index 6683e59..f5c6a8b 100644 --- a/gui_util.h +++ b/gui_util.h @@ -28,6 +28,7 @@ GdkColor get_color(const char *spec); void set_width(GdkGC *gc, int width); +void free_pix_buf(struct pix_buf *buf); struct pix_buf *save_pix_buf(GdkDrawable *da, int xa, int ya, int xb, int yb, int border); void restore_pix_buf(struct pix_buf *buf); diff --git a/inst.c b/inst.c index dd4346e..b2ea571 100644 --- a/inst.c +++ b/inst.c @@ -763,7 +763,7 @@ void inst_end_frame(const struct frame *frame) curr_frame = curr_frame->outer; if (curr_frame) propagate_bbox(inst); - if (inst->active && frame == active_frame) + if (inst->u.frame.active && frame == active_frame) active_frame_bbox = inst->bbox; }