diff --git a/gui.c b/gui.c index d921dfd..5049bd2 100644 --- a/gui.c +++ b/gui.c @@ -39,18 +39,37 @@ static GtkWidget *ev_stuff, *ev_meas; static GtkWidget *stuff_image[2], *meas_image[2]; +/* ----- view callbacks ---------------------------------------------------- */ + + +static void swap_var_code(void) +{ + extern int show_vars; + + show_vars = !show_vars; + change_world(); +} + + /* ----- menu bar ---------------------------------------------------------- */ static GtkItemFactoryEntry menu_entries[] = { { "/File", NULL, NULL, 0, "" }, { "/File/Save", NULL, save_fpd, 0, "" }, - { "/File/sep0", NULL, NULL, 0, "" }, + { "/File/sep1", NULL, NULL, 0, "" }, { "/File/Write KiCad", NULL, write_kicad, 0, "" }, { "/File/Write Postscript", NULL, write_ps, 0, "" }, { "/File/sep2", NULL, NULL, 0, "" }, { "/File/Quit", NULL, gtk_main_quit, 0, "" }, + { "/View", NULL, NULL, 0, "" }, + { "/View/Zoom in", NULL, zoom_in_center, 0, "" }, + { "/View/Zoom out", NULL, zoom_out_center,0, "" }, + { "/View/Zoom all", NULL, zoom_to_extents,0, "" }, + { "/View/Zoom frame", NULL, zoom_to_frame, 0, "" }, + { "/View/sep1", NULL, NULL, 0, "" }, + { "/View/Swap var&code",NULL, swap_var_code, 0, "" }, }; diff --git a/gui_canvas.c b/gui_canvas.c index 286eeb5..56e3536 100644 --- a/gui_canvas.c +++ b/gui_canvas.c @@ -279,6 +279,38 @@ static void zoom_out(struct coord pos) } +void zoom_in_center(void) +{ + zoom_in(draw_ctx.center); +} + + +void zoom_out_center(void) +{ + zoom_out(draw_ctx.center); +} + + +void zoom_to_frame(void) +{ + tool_dehover(); + center(&active_frame_bbox); + auto_scale(&active_frame_bbox); + redraw(); + tool_hover(canvas_to_coord(curr_pos.x, curr_pos.y)); +} + + +void zoom_to_extents(void) +{ + tool_dehover(); + center(NULL); + auto_scale(NULL); + redraw(); + tool_hover(canvas_to_coord(curr_pos.x, curr_pos.y)); +} + + static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) { @@ -321,18 +353,10 @@ static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event, zoom_out(pos); break; case '*': - tool_dehover(); - center(NULL); - auto_scale(NULL); - redraw(); - tool_hover(canvas_to_coord(curr_pos.x, curr_pos.y)); + zoom_to_extents(); break; case '#': - tool_dehover(); - center(&active_frame_bbox); - auto_scale(&active_frame_bbox); - redraw(); - tool_hover(canvas_to_coord(curr_pos.x, curr_pos.y)); + zoom_to_frame(); break; case '.': tool_dehover(); diff --git a/gui_canvas.h b/gui_canvas.h index ed21864..5842797 100644 --- a/gui_canvas.h +++ b/gui_canvas.h @@ -29,6 +29,11 @@ void refresh_pos(void); void redraw(void); +void zoom_in_center(void); +void zoom_out_center(void); +void zoom_to_frame(void); +void zoom_to_extents(void); + GtkWidget *make_canvas(void); void init_canvas(void); diff --git a/gui_frame.c b/gui_frame.c index 7722774..a3c5175 100644 --- a/gui_frame.c +++ b/gui_frame.c @@ -743,6 +743,34 @@ static gboolean table_value_select_event(GtkWidget *widget, } +static gboolean table_scroll_event(GtkWidget *widget, GdkEventScroll *event, + gpointer data) +{ + struct table *table = data; + struct row *row, *last; + + switch (event->direction) { + case GDK_SCROLL_UP: + last = NULL; + for (row = table->rows; + row && (!last || row != table->active_row); row = row->next) + last = row; + table->active_row = last; + change_world(); + break; + case GDK_SCROLL_DOWN: + table->active_row = table->active_row->next; + if (!table->active_row) + table->active_row = table->rows; + change_world(); + break; + default: + /* ignore */; + } + return TRUE; +} + + static void build_table(GtkWidget *vbox, struct frame *frame, struct table *table) { @@ -786,6 +814,9 @@ static void build_table(GtkWidget *vbox, struct frame *frame, g_signal_connect(G_OBJECT(box_of_label(field)), "button_press_event", G_CALLBACK(table_var_select_event), var); + g_signal_connect(G_OBJECT(box_of_label(field)), + "scroll_event", + G_CALLBACK(table_scroll_event), table); var->widget = field; n_vars++; } @@ -805,6 +836,9 @@ static void build_table(GtkWidget *vbox, struct frame *frame, g_signal_connect(G_OBJECT(box_of_label(field)), "button_press_event", G_CALLBACK(table_value_select_event), value); + g_signal_connect(G_OBJECT(box_of_label(field)), + "scroll_event", + G_CALLBACK(table_scroll_event), table); value->widget = field; n_vars++; } diff --git a/gui_meas.c b/gui_meas.c index 29dd317..6a90640 100644 --- a/gui_meas.c +++ b/gui_meas.c @@ -102,6 +102,7 @@ static int is_a_next(lt_op_type lt, struct inst *inst) } +#if 0 static int is_min_of_next(lt_op_type lt, const struct inst *inst, const struct inst *ref) { @@ -111,6 +112,7 @@ static int is_min_of_next(lt_op_type lt, next = meas_find_next(lt, ref->vec->samples, min); return coord_eq(next, ref->u.rect.end); } +#endif /* ----- picker functions -------------------------------------------------- */ diff --git a/inst.c b/inst.c index d08fb8b..2ee8d51 100644 --- a/inst.c +++ b/inst.c @@ -879,14 +879,18 @@ int inst_meas(struct obj *obj, struct coord from, struct coord to, unit_type offset) { struct inst *inst; + struct coord a1, b1; inst = add_inst(&meas_ops, ip_meas, from); inst->obj = obj; inst->u.meas.end = to; inst->u.meas.offset = offset; inst->active = 1; /* measurements are always active */ - /* @@@ our bbox is actually a bit more complex than this */ + /* @@@ we still need to consider the text size as well */ update_bbox(&inst->bbox, to); + project_meas(inst, &a1, &b1); + update_bbox(&inst->bbox, a1); + update_bbox(&inst->bbox, b1); propagate_bbox(inst); return 1; }