diff --git a/gui_inst.c b/gui_inst.c index fb25329..53d20bc 100644 --- a/gui_inst.c +++ b/gui_inst.c @@ -122,7 +122,7 @@ unit_type gui_dist_vec(struct inst *self, struct coord pos, unit_type scale) { unit_type d; - d = dist_point(pos, self->u.rect.end)/scale; + d = dist_point(pos, self->u.vec.end)/scale; return d > VEC_EYE_R ? -1 : d; } @@ -138,14 +138,14 @@ unit_type gui_dist_vec_fallback(struct inst *self, struct coord pos, { unit_type d; - d = dist_line(pos, self->base, self->u.rect.end)/scale; + d = dist_line(pos, self->base, self->u.vec.end)/scale; return d > SELECT_R ? -1 : d; } void gui_highlight_vec(struct inst *self) { - struct coord center = translate(self->u.rect.end); + struct coord center = translate(self->u.vec.end); draw_circle(DA, gc_highlight, FALSE, center.x, center.y, VEC_EYE_R); } @@ -154,7 +154,7 @@ void gui_highlight_vec(struct inst *self) void gui_draw_vec(struct inst *self) { struct coord from = translate(self->base); - struct coord to = translate(self->u.rect.end); + struct coord to = translate(self->u.vec.end); GdkGC *gc; gc = gc_vec[get_mode(self)]; diff --git a/gui_meas.c b/gui_meas.c index 5c4254a..86b5161 100644 --- a/gui_meas.c +++ b/gui_meas.c @@ -64,7 +64,7 @@ static int is_min(lt_op_type lt, const struct inst *inst) struct coord min; min = meas_find_min(lt, active_pkg->samples[inst->vec->n]); - return coord_eq(inst->u.rect.end, min); + return coord_eq(inst->u.vec.end, min); } @@ -74,8 +74,8 @@ static int is_next(lt_op_type lt, struct coord next; next = meas_find_next(lt, active_pkg->samples[inst->vec->n], - ref->u.rect.end); - return coord_eq(inst->u.rect.end, next); + ref->u.vec.end); + return coord_eq(inst->u.vec.end, next); } @@ -84,7 +84,7 @@ static int is_max(lt_op_type lt, const struct inst *inst) struct coord max; max = meas_find_max(lt, active_pkg->samples[inst->vec->n]); - return coord_eq(inst->u.rect.end, max); + return coord_eq(inst->u.vec.end, max); } @@ -97,7 +97,7 @@ static int is_a_next(lt_op_type lt, struct inst *inst) min = meas_find_min(lt, active_pkg->samples[a->vec->n]); next = meas_find_next(lt, active_pkg->samples[inst->vec->n], min); - if (coord_eq(next, inst->u.rect.end)) + if (coord_eq(next, inst->u.vec.end)) return 1; } return 0; @@ -112,7 +112,7 @@ static int is_min_of_next(lt_op_type lt, min = meas_find_min(lt, inst->vec->samples); next = meas_find_next(lt, ref->vec->samples, min); - return coord_eq(next, ref->u.rect.end); + return coord_eq(next, ref->u.vec.end); } #endif @@ -234,12 +234,15 @@ static void tool_deselected_meas(void) /* ----- find start point (new measurement) -------------------------------- */ +static int is_highlighted(struct inst *inst, void *user) +{ + return inst->u.vec.highlighted; +} + + static struct inst *find_point_meas_new(struct coord pos) { - if (meas_inst) - return inst_find_vec(pos, meas_pick_vec_b, meas_inst); - else - return inst_find_vec(pos, meas_pick_vec_a, NULL); + return inst_find_vec(pos, is_highlighted, NULL); } @@ -302,14 +305,8 @@ static int end_new_meas(struct inst *from, struct inst *to) } meas->inverted = mode == min_to_next_or_max && is_min(meas_dsc->lt, to) ? 0 : - meas_dsc->lt(from->u.rect.end, to->u.rect.end) != + meas_dsc->lt(from->u.vec.end, to->u.vec.end) != (mode == min_to_next_or_max); -{ -char *sm[] = { "min_to", "max_to", "next_to" }; -char *st[] = { "nxy", "nx", "ny", "mxy", "mx", "my" }; -fprintf(stderr, "mode %s type %s, inverted %d\n", -sm[mode], st[meas->type], meas->inverted); -} meas->offset = NULL; meas_dsc = NULL; return 1; @@ -388,7 +385,7 @@ void begin_drag_move_meas(struct inst *inst, int i) struct inst *find_point_meas_move(struct inst *inst, struct coord pos) { - return inst_find_vec(pos, meas_pick_vec_b, meas_inst); + return inst_find_vec(pos, is_highlighted, NULL); } diff --git a/gui_tool.c b/gui_tool.c index fa25f45..754230d 100644 --- a/gui_tool.c +++ b/gui_tool.c @@ -274,14 +274,14 @@ static struct pix_buf *drag_new_vec(struct inst *from, struct coord to) struct pix_buf *draw_move_vec(struct inst *inst, struct coord pos, int i) { return draw_move_line_common(inst, - add_vec(sub_vec(inst->u.rect.end, inst->base), pos), pos, i); + add_vec(sub_vec(inst->u.vec.end, inst->base), pos), pos, i); } struct pix_buf *gui_hover_vec(struct inst *self) { return hover_common(gc_vec[mode_hover], - self->u.rect.end, VEC_EYE_R); + self->u.vec.end, VEC_EYE_R); } diff --git a/inst.c b/inst.c index 5f4542b..13a6f35 100644 --- a/inst.c +++ b/inst.c @@ -353,7 +353,7 @@ int inst_find_point_selected(struct coord pos, struct inst **res) struct coord inst_get_point(const struct inst *inst) { if (inst->ops == &vec_ops) - return inst->u.rect.end; + return inst->u.vec.end; if (inst->ops == &frame_ops) return inst->base; abort(); @@ -575,7 +575,7 @@ static void vec_op_select(struct inst *self) { status_set_type_entry("ref ="); status_set_name("%s", self->vec->name ? self->vec->name : ""); - rect_status(self->base, self->u.rect.end, -1, 0); + rect_status(self->base, self->u.vec.end, -1, 0); vec_edit(self->vec); } @@ -628,7 +628,7 @@ int inst_vec(struct vec *vec, struct coord base) inst = add_inst(&vec_ops, ip_vec, base); inst->vec = vec; - inst->u.rect.end = vec->pos; + inst->u.vec.end = vec->pos; update_bbox(&inst->bbox, vec->pos); propagate_bbox(inst); return 1; @@ -1199,9 +1199,11 @@ void inst_highlight_vecs(int (*pick)(struct inst *inst, void *user), void *user) struct inst *inst; int i; - FOR_ALL_INSTS(i, ip_vec, inst) - if (pick(inst, user)) + FOR_ALL_INSTS(i, ip_vec, inst) { + inst->u.vec.highlighted = pick(inst, user); + if (inst->u.vec.highlighted) gui_highlight_vec(inst); + } } diff --git a/inst.h b/inst.h index 749a35a..61c20e3 100644 --- a/inst.h +++ b/inst.h @@ -78,14 +78,18 @@ struct inst { struct inst *outer; /* frame containing this item */ int active; union { + struct { + int highlighted; /* for measurements */ + struct coord end; + } vec; struct { struct frame *ref; int active; } frame; const char *name; struct { - struct coord end; unit_type width; + struct coord end; } rect; struct { char *name;