1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-25 18:15:55 +02:00

Yet more tooltips. This time, for all non-editable fields in the status area.

- gui_status.h: use macro to generate status_set_* delarations, just as we use
  a macro for their definitions
- added tooltips for all non-editable fields in the status area



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5773 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2010-01-02 23:27:36 +00:00
parent f9eefa4e69
commit 661398c20a
6 changed files with 123 additions and 107 deletions

View File

@ -52,7 +52,7 @@ static struct inst *selected_before_drag;
static void update_zoom(void) static void update_zoom(void)
{ {
status_set_zoom("x%d", draw_ctx.scale); status_set_zoom("Zoom factor", "x%d", draw_ctx.scale);
} }
@ -61,18 +61,21 @@ static void update_pos(struct coord pos)
struct coord user; struct coord user;
unit_type diag; unit_type diag;
set_with_units(status_set_sys_x, "X ", pos.x); set_with_units(status_set_sys_x, "X ", pos.x, "Absolute X position");
set_with_units(status_set_sys_y, "Y ", pos.y); set_with_units(status_set_sys_y, "Y ", pos.y, "Absolute Y position");
user.x = pos.x-user_origin.x; user.x = pos.x-user_origin.x;
user.y = pos.y-user_origin.y; user.y = pos.y-user_origin.y;
set_with_units(status_set_user_x, "x ", user.x); set_with_units(status_set_user_x, "x ", user.x,
set_with_units(status_set_user_y, "y ", user.y); "User X position. Press SPACE to zero.");
set_with_units(status_set_user_y, "y ", user.y,
"User Y position. Press SPACE to zero.");
if (!selected_inst) { if (!selected_inst) {
diag = hypot(user.x, user.y); diag = hypot(user.x, user.y);
set_with_units(status_set_r, "r = ", diag); set_with_units(status_set_r, "r = ", diag,
status_set_angle_xy(user); "Distance from user origin");
status_set_angle_xy("Angle from user origin", user);
} }
} }

View File

@ -541,8 +541,8 @@ static void edit_var(struct var *var,
{ {
inst_select_outside(var, unselect_var); inst_select_outside(var, unselect_var);
label_in_box_bg(var->widget, COLOR_VAR_EDITING); label_in_box_bg(var->widget, COLOR_VAR_EDITING);
status_set_type_entry("name ="); status_set_type_entry("Variable name", "name =");
status_set_name("%s", var->name); status_set_name("Variable name", "%s", var->name);
edit_nothing(); edit_nothing();
edit_unique_with_values(&var->name, validate_var_name, var, edit_unique_with_values(&var->name, validate_var_name, var,
set_values, user, max_values); set_values, user, max_values);
@ -1336,8 +1336,8 @@ static gboolean pkg_name_edit_event(GtkWidget *widget, GdkEventButton *event,
case 1: case 1:
inst_select_outside(widget, unselect_pkg_name); inst_select_outside(widget, unselect_pkg_name);
label_in_box_bg(widget, COLOR_PART_NAME_EDITING); label_in_box_bg(widget, COLOR_PART_NAME_EDITING);
status_set_type_entry("package ="); status_set_type_entry("Package name", "package =");
status_set_name("%s", pkg_name); status_set_name("Package name (actual)", "%s", pkg_name);
edit_nothing(); edit_nothing();
edit_name(&pkg_name, validate_pkg_name, NULL); edit_name(&pkg_name, validate_pkg_name, NULL);
break; break;
@ -1465,10 +1465,13 @@ static void unselect_frame(void *data)
static void edit_frame(struct frame *frame) static void edit_frame(struct frame *frame)
{ {
const char *tip;
inst_select_outside(frame, unselect_frame); inst_select_outside(frame, unselect_frame);
label_in_box_bg(frame->label, COLOR_FRAME_EDITING); label_in_box_bg(frame->label, COLOR_FRAME_EDITING);
status_set_type_entry("name ="); tip = "Frame name";
status_set_name("%s", frame->name); status_set_type_entry(tip, "name =");
status_set_name(tip, "%s", frame->name);
edit_nothing(); edit_nothing();
edit_unique(&frame->name, validate_frame_name, frame); edit_unique(&frame->name, validate_frame_name, frame);
} }

View File

@ -71,24 +71,26 @@ static GtkWidget *status_msg;
static GtkWidget *status_entry_x; static GtkWidget *status_entry_x;
static void set_label(GtkWidget *label, const char *fmt, va_list ap) static void set_label(GtkWidget *label, const char *tooltip,
const char *fmt, va_list ap)
{ {
char *s; char *s;
s = stralloc_vprintf(fmt, ap); s = stralloc_vprintf(fmt, ap);
gtk_label_set_text(GTK_LABEL(label), s); gtk_label_set_text(GTK_LABEL(label), s);
gtk_widget_set_tooltip_markup(label, tooltip);
free(s); free(s);
} }
#define SETTER(name) \ #define SETTER(name) \
void status_set_##name(const char *fmt, ...) \ void status_set_##name(const char *tooltip, const char *fmt, ...)\
{ \ { \
va_list ap; \ va_list ap; \
\ \
va_start(ap, fmt); \ va_start(ap, fmt); \
set_label(status_##name, fmt, ap); \ set_label(status_##name, tooltip, fmt, ap); \
va_end(ap); \ va_end(ap); \
} }
SETTER(type_x) SETTER(type_x)
@ -111,8 +113,8 @@ SETTER(unit)
/* ----- set things with units --------------------------------------------- */ /* ----- set things with units --------------------------------------------- */
void set_with_units(void (*set)(const char *fmt, ...), const char *prefix, void set_with_units(void (*set)(const char *tooltip, const char *fmt, ...),
unit_type u) const char *prefix, unit_type u, const char *tooltip)
{ {
double n; double n;
int mm; int mm;
@ -134,10 +136,10 @@ void set_with_units(void (*set)(const char *fmt, ...), const char *prefix,
} }
if (mm) { if (mm) {
/* -NNN.NNN mm */ /* -NNN.NNN mm */
set("%s" MM_FORMAT_FIXED " mm", prefix, n); set(tooltip, "%s" MM_FORMAT_FIXED " mm", prefix, n);
} else { } else {
/* -NNNN.N mil */ /* -NNNN.N mil */
set("%s" MIL_FORMAT_FIXED " mil", prefix, n); set(tooltip, "%s" MIL_FORMAT_FIXED " mil", prefix, n);
} }
} }
@ -157,20 +159,20 @@ void status_set_icon(GtkWidget *image)
void status_set_xy(struct coord coord) void status_set_xy(struct coord coord)
{ {
/* do dX/dY etc. stuff later */ /* do dX/dY etc. stuff later */
status_set_type_x("X ="); status_set_type_x("Width", "X =");
status_set_type_y("Y ="); status_set_type_y("Height", "Y =");
set_with_units(status_set_x, "", coord.x); set_with_units(status_set_x, "", coord.x, "Width");
set_with_units(status_set_y, "", coord.y); set_with_units(status_set_y, "", coord.y, "Height");
} }
void status_set_angle_xy(struct coord v) void status_set_angle_xy(const char *tooltip, struct coord v)
{ {
if (!v.x && !v.y) if (!v.x && !v.y)
status_set_angle("a = 0 deg"); status_set_angle(tooltip, "a = 0 deg");
else else
status_set_angle("a = %3.1f deg", theta_vec(v)); status_set_angle(tooltip, "a = %3.1f deg", theta_vec(v));
} }
@ -831,15 +833,17 @@ void status_begin_reporting(void)
static void show_curr_unit(void) static void show_curr_unit(void)
{ {
static const char *tip = "Display unit. Click to cycle.";
switch (curr_unit) { switch (curr_unit) {
case curr_unit_mm: case curr_unit_mm:
status_set_unit("mm"); status_set_unit(tip, "mm");
break; break;
case curr_unit_mil: case curr_unit_mil:
status_set_unit("mil"); status_set_unit(tip, "mil");
break; break;
case curr_unit_auto: case curr_unit_auto:
status_set_unit("auto"); status_set_unit(tip, "auto");
break; break;
default: default:
abort(); abort();

View File

@ -1,8 +1,8 @@
/* /*
* gui_status.h - GUI, status area * gui_status.h - GUI, status area
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -50,43 +50,34 @@ void edit_x(struct expr **expr);
void edit_y(struct expr **expr); void edit_y(struct expr **expr);
void edit_nothing(void); void edit_nothing(void);
void set_with_units(void (*set)(const char *fmt, ...), const char *prefix, void set_with_units(void (*set)(const char *tooltip, const char *fmt, ...),
unit_type u); const char *prefix, unit_type u, const char *tooltip);
void status_set_type_x(const char *fmt, ...) #define SETTER(name) \
__attribute__((format(printf, 1, 2))); void status_set_##name(const char *tooltip, const char *fmt, ...) \
void status_set_type_y(const char *fmt, ...) __attribute__((format(printf, 2, 3))) \
__attribute__((format(printf, 1, 2)));
void status_set_type_entry(const char *fmt, ...) SETTER(type_x);
__attribute__((format(printf, 1, 2))); SETTER(type_y);
void status_set_name(const char *fmt, ...) SETTER(type_entry);
__attribute__((format(printf, 1, 2))); SETTER(name);
void status_set_x(const char *fmt, ...) SETTER(x);
__attribute__((format(printf, 1, 2))); SETTER(y);
void status_set_y(const char *fmt, ...) SETTER(r);
__attribute__((format(printf, 1, 2))); SETTER(angle);
void status_set_r(const char *fmt, ...) SETTER(sys_x);
__attribute__((format(printf, 1, 2))); SETTER(sys_y);
void status_set_angle(const char *fmt, ...) SETTER(user_x);
__attribute__((format(printf, 1, 2))); SETTER(user_y);
void status_set_sys_x(const char *fmt, ...) SETTER(zoom);
__attribute__((format(printf, 1, 2))); SETTER(grid);
void status_set_sys_y(const char *fmt, ...) SETTER(unit);
__attribute__((format(printf, 1, 2)));
void status_set_user_x(const char *fmt, ...) #undef SETTER
__attribute__((format(printf, 1, 2)));
void status_set_user_y(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_zoom(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_grid(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_unit(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_icon(GtkWidget *image); void status_set_icon(GtkWidget *image);
void status_set_xy(struct coord coord); void status_set_xy(struct coord coord);
void status_set_angle_xy(struct coord v); void status_set_angle_xy(const char *tooltip, struct coord v);
void status_begin_reporting(void); void status_begin_reporting(void);

View File

@ -249,18 +249,18 @@ static struct pix_buf *drag_new_vec(struct inst *from, struct coord to)
pos = inst_get_point(from); pos = inst_get_point(from);
to = gridify(pos, to); to = gridify(pos, to);
status_set_type_x("dX ="); status_set_type_x(NULL, "dX =");
status_set_type_y("dX ="); status_set_type_y(NULL, "dX =");
/* @@@ use status_set_xy */ /* @@@ use status_set_xy */
switch (curr_unit) { switch (curr_unit) {
case curr_unit_mm: case curr_unit_mm:
case curr_unit_auto: case curr_unit_auto:
status_set_x("%lg mm", units_to_mm(to.x-pos.x)); status_set_x(NULL, "%lg mm", units_to_mm(to.x-pos.x));
status_set_y("%lg mm", units_to_mm(to.y-pos.y)); status_set_y(NULL, "%lg mm", units_to_mm(to.y-pos.y));
break; break;
case curr_unit_mil: case curr_unit_mil:
status_set_x("%lg mil", units_to_mil(to.x-pos.x)); status_set_x(NULL, "%lg mil", units_to_mil(to.x-pos.x));
status_set_y("%lg mil", units_to_mil(to.y-pos.y)); status_set_y(NULL, "%lg mil", units_to_mil(to.y-pos.y));
break; break;
default: default:
abort(); abort();

75
inst.c
View File

@ -1,8 +1,8 @@
/* /*
* inst.c - Instance structures * inst.c - Instance structures
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -386,14 +386,14 @@ void inst_deselect(void)
gui_frame_deselect_inst(selected_inst); gui_frame_deselect_inst(selected_inst);
} }
deselect_outside(); deselect_outside();
status_set_type_x(""); status_set_type_x(NULL, "");
status_set_type_y(""); status_set_type_y(NULL, "");
status_set_type_entry(""); status_set_type_entry(NULL, "");
status_set_name(""); status_set_name(NULL, "");
status_set_x(""); status_set_x(NULL, "");
status_set_y(""); status_set_y(NULL, "");
status_set_r(""); status_set_r(NULL, "");
status_set_angle(""); status_set_angle(NULL, "");
selected_inst = NULL; selected_inst = NULL;
edit_nothing(); edit_nothing();
refresh_pos(); refresh_pos();
@ -452,15 +452,17 @@ found:
static void rect_status(struct coord a, struct coord b, unit_type width, static void rect_status(struct coord a, struct coord b, unit_type width,
int rounded) int rounded)
{ {
const char *tip;
struct coord d = sub_vec(b, a); struct coord d = sub_vec(b, a);
double r; double r;
unit_type diag; unit_type diag;
status_set_xy(d); status_set_xy(d);
tip = "Angle of diagonal";
if (!d.x && !d.y) if (!d.x && !d.y)
status_set_angle("a = 0 deg"); status_set_angle(tip, "a = 0 deg");
else { else {
status_set_angle("a = %3.1f deg", theta(a, b)); status_set_angle(tip, "a = %3.1f deg", theta(a, b));
} }
if (d.x < 0) if (d.x < 0)
d.x = -d.x; d.x = -d.x;
@ -488,10 +490,11 @@ static void rect_status(struct coord a, struct coord b, unit_type width,
r = (d.x > d.y ? d.y : d.x)/2; r = (d.x > d.y ? d.y : d.x)/2;
diag -= 2*r*(d.x+d.y-sqrt(2*d.x*d.y))/diag; diag -= 2*r*(d.x+d.y-sqrt(2*d.x*d.y))/diag;
} }
set_with_units(status_set_r, "d = ", diag); set_with_units(status_set_r, "d = ", diag, "Length of diagonal");
if (width != -1) { if (width != -1) {
status_set_type_entry("width ="); tip = "Line width";
set_with_units(status_set_name, "", width); status_set_type_entry(tip, "width =");
set_with_units(status_set_name, "", width, tip);
} }
} }
@ -578,8 +581,11 @@ static void vec_edit(struct vec *vec)
static void vec_op_select(struct inst *self) static void vec_op_select(struct inst *self)
{ {
status_set_type_entry("ref ="); const char *tip;
status_set_name("%s", self->vec->name ? self->vec->name : "");
tip = "Vector reference (name)";
status_set_type_entry(tip, "ref =");
status_set_name(tip, "%s", self->vec->name ? self->vec->name : "");
rect_status(self->base, self->u.vec.end, -1, 0); rect_status(self->base, self->u.vec.end, -1, 0);
vec_edit(self->vec); vec_edit(self->vec);
} }
@ -814,8 +820,8 @@ static void obj_pad_edit(struct obj *obj)
static void pad_op_select(struct inst *self) static void pad_op_select(struct inst *self)
{ {
status_set_type_entry("label ="); status_set_type_entry("Pad name", "label =");
status_set_name("%s", self->u.pad.name); status_set_name("Pad name (actual)", "%s", self->u.pad.name);
rect_status(self->base, self->u.pad.other, -1, 0); rect_status(self->base, self->u.pad.other, -1, 0);
obj_pad_edit(self->obj); obj_pad_edit(self->obj);
} }
@ -842,8 +848,8 @@ static struct inst_ops pad_ops = {
static void rpad_op_select(struct inst *self) static void rpad_op_select(struct inst *self)
{ {
status_set_type_entry("label ="); status_set_type_entry("Pad name", "label =");
status_set_name("%s", self->u.pad.name); status_set_name("Pad name (actual)", "%s", self->u.pad.name);
rect_status(self->base, self->u.pad.other, -1, 1); rect_status(self->base, self->u.pad.other, -1, 1);
obj_pad_edit(self->obj); obj_pad_edit(self->obj);
} }
@ -886,13 +892,16 @@ static void obj_arc_edit(struct obj *obj)
static void arc_op_select(struct inst *self) static void arc_op_select(struct inst *self)
{ {
const char *tip;
status_set_xy(self->base); status_set_xy(self->base);
status_set_angle("a = %3.1f deg", status_set_angle("Angle", "a = %3.1f deg",
self->u.arc.a1 == self->u.arc.a2 ? 360 : self->u.arc.a1 == self->u.arc.a2 ? 360 :
self->u.arc.a2-self->u.arc.a1); self->u.arc.a2-self->u.arc.a1);
set_with_units(status_set_r, "r = ", self->u.arc.r); set_with_units(status_set_r, "r = ", self->u.arc.r, "Radius");
status_set_type_entry("width ="); tip = "Line width";
set_with_units(status_set_name, "", self->u.arc.width); status_set_type_entry(tip, "width =");
set_with_units(status_set_name, "", self->u.arc.width, tip);
obj_arc_edit(self->obj); obj_arc_edit(self->obj);
} }
@ -959,9 +968,12 @@ static void obj_meas_edit(struct obj *obj)
static void meas_op_select(struct inst *self) static void meas_op_select(struct inst *self)
{ {
const char *tip;
rect_status(self->bbox.min, self->bbox.max, -1, 0); rect_status(self->bbox.min, self->bbox.max, -1, 0);
status_set_type_entry("offset ="); tip = "Measurement line offset";
set_with_units(status_set_name, "", self->u.meas.offset); status_set_type_entry(tip, "offset =");
set_with_units(status_set_name, "", self->u.meas.offset, tip);
obj_meas_edit(self->obj); obj_meas_edit(self->obj);
} }
@ -1084,9 +1096,12 @@ void inst_end_active(void)
static void frame_op_select(struct inst *self) static void frame_op_select(struct inst *self)
{ {
const char *tip;
tip = "Frame name";
rect_status(self->bbox.min, self->bbox.max, -1, 0); rect_status(self->bbox.min, self->bbox.max, -1, 0);
status_set_type_entry("name ="); status_set_type_entry(tip, "name =");
status_set_name("%s", self->u.frame.ref->name); status_set_name(tip, "%s", self->u.frame.ref->name);
} }