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)
{
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;
unit_type diag;
set_with_units(status_set_sys_x, "X ", pos.x);
set_with_units(status_set_sys_y, "Y ", pos.y);
set_with_units(status_set_sys_x, "X ", pos.x, "Absolute X position");
set_with_units(status_set_sys_y, "Y ", pos.y, "Absolute Y position");
user.x = pos.x-user_origin.x;
user.y = pos.y-user_origin.y;
set_with_units(status_set_user_x, "x ", user.x);
set_with_units(status_set_user_y, "y ", user.y);
set_with_units(status_set_user_x, "x ", user.x,
"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) {
diag = hypot(user.x, user.y);
set_with_units(status_set_r, "r = ", diag);
status_set_angle_xy(user);
set_with_units(status_set_r, "r = ", diag,
"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);
label_in_box_bg(var->widget, COLOR_VAR_EDITING);
status_set_type_entry("name =");
status_set_name("%s", var->name);
status_set_type_entry("Variable name", "name =");
status_set_name("Variable name", "%s", var->name);
edit_nothing();
edit_unique_with_values(&var->name, validate_var_name, var,
set_values, user, max_values);
@ -1336,8 +1336,8 @@ static gboolean pkg_name_edit_event(GtkWidget *widget, GdkEventButton *event,
case 1:
inst_select_outside(widget, unselect_pkg_name);
label_in_box_bg(widget, COLOR_PART_NAME_EDITING);
status_set_type_entry("package =");
status_set_name("%s", pkg_name);
status_set_type_entry("Package name", "package =");
status_set_name("Package name (actual)", "%s", pkg_name);
edit_nothing();
edit_name(&pkg_name, validate_pkg_name, NULL);
break;
@ -1465,10 +1465,13 @@ static void unselect_frame(void *data)
static void edit_frame(struct frame *frame)
{
const char *tip;
inst_select_outside(frame, unselect_frame);
label_in_box_bg(frame->label, COLOR_FRAME_EDITING);
status_set_type_entry("name =");
status_set_name("%s", frame->name);
tip = "Frame name";
status_set_type_entry(tip, "name =");
status_set_name(tip, "%s", frame->name);
edit_nothing();
edit_unique(&frame->name, validate_frame_name, frame);
}

View File

@ -71,24 +71,26 @@ static GtkWidget *status_msg;
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;
s = stralloc_vprintf(fmt, ap);
gtk_label_set_text(GTK_LABEL(label), s);
gtk_widget_set_tooltip_markup(label, tooltip);
free(s);
}
#define SETTER(name) \
void status_set_##name(const char *fmt, ...) \
{ \
va_list ap; \
\
va_start(ap, fmt); \
set_label(status_##name, fmt, ap); \
va_end(ap); \
#define SETTER(name) \
void status_set_##name(const char *tooltip, const char *fmt, ...)\
{ \
va_list ap; \
\
va_start(ap, fmt); \
set_label(status_##name, tooltip, fmt, ap); \
va_end(ap); \
}
SETTER(type_x)
@ -111,8 +113,8 @@ SETTER(unit)
/* ----- set things with units --------------------------------------------- */
void set_with_units(void (*set)(const char *fmt, ...), const char *prefix,
unit_type u)
void set_with_units(void (*set)(const char *tooltip, const char *fmt, ...),
const char *prefix, unit_type u, const char *tooltip)
{
double n;
int mm;
@ -134,10 +136,10 @@ void set_with_units(void (*set)(const char *fmt, ...), const char *prefix,
}
if (mm) {
/* -NNN.NNN mm */
set("%s" MM_FORMAT_FIXED " mm", prefix, n);
set(tooltip, "%s" MM_FORMAT_FIXED " mm", prefix, n);
} else {
/* -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)
{
/* do dX/dY etc. stuff later */
status_set_type_x("X =");
status_set_type_y("Y =");
status_set_type_x("Width", "X =");
status_set_type_y("Height", "Y =");
set_with_units(status_set_x, "", coord.x);
set_with_units(status_set_y, "", coord.y);
set_with_units(status_set_x, "", coord.x, "Width");
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)
status_set_angle("a = 0 deg");
status_set_angle(tooltip, "a = 0 deg");
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 const char *tip = "Display unit. Click to cycle.";
switch (curr_unit) {
case curr_unit_mm:
status_set_unit("mm");
status_set_unit(tip, "mm");
break;
case curr_unit_mil:
status_set_unit("mil");
status_set_unit(tip, "mil");
break;
case curr_unit_auto:
status_set_unit("auto");
status_set_unit(tip, "auto");
break;
default:
abort();

View File

@ -1,8 +1,8 @@
/*
* gui_status.h - GUI, status area
*
* Written 2009 by Werner Almesberger
* Copyright 2009 by Werner Almesberger
* Written 2009, 2010 by Werner Almesberger
* Copyright 2009, 2010 by Werner Almesberger
*
* 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
@ -50,43 +50,34 @@ void edit_x(struct expr **expr);
void edit_y(struct expr **expr);
void edit_nothing(void);
void set_with_units(void (*set)(const char *fmt, ...), const char *prefix,
unit_type u);
void set_with_units(void (*set)(const char *tooltip, const char *fmt, ...),
const char *prefix, unit_type u, const char *tooltip);
void status_set_type_x(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_type_y(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_type_entry(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_name(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_x(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_y(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_r(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_angle(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_sys_x(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_sys_y(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void status_set_user_x(const char *fmt, ...)
__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)));
#define SETTER(name) \
void status_set_##name(const char *tooltip, const char *fmt, ...) \
__attribute__((format(printf, 2, 3))) \
SETTER(type_x);
SETTER(type_y);
SETTER(type_entry);
SETTER(name);
SETTER(x);
SETTER(y);
SETTER(r);
SETTER(angle);
SETTER(sys_x);
SETTER(sys_y);
SETTER(user_x);
SETTER(user_y);
SETTER(zoom);
SETTER(grid);
SETTER(unit);
#undef SETTER
void status_set_icon(GtkWidget *image);
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);

View File

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

73
inst.c
View File

@ -1,8 +1,8 @@
/*
* inst.c - Instance structures
*
* Written 2009 by Werner Almesberger
* Copyright 2009 by Werner Almesberger
* Written 2009, 2010 by Werner Almesberger
* Copyright 2009, 2010 by Werner Almesberger
*
* 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
@ -386,14 +386,14 @@ void inst_deselect(void)
gui_frame_deselect_inst(selected_inst);
}
deselect_outside();
status_set_type_x("");
status_set_type_y("");
status_set_type_entry("");
status_set_name("");
status_set_x("");
status_set_y("");
status_set_r("");
status_set_angle("");
status_set_type_x(NULL, "");
status_set_type_y(NULL, "");
status_set_type_entry(NULL, "");
status_set_name(NULL, "");
status_set_x(NULL, "");
status_set_y(NULL, "");
status_set_r(NULL, "");
status_set_angle(NULL, "");
selected_inst = NULL;
edit_nothing();
refresh_pos();
@ -452,15 +452,17 @@ found:
static void rect_status(struct coord a, struct coord b, unit_type width,
int rounded)
{
const char *tip;
struct coord d = sub_vec(b, a);
double r;
unit_type diag;
status_set_xy(d);
tip = "Angle of diagonal";
if (!d.x && !d.y)
status_set_angle("a = 0 deg");
status_set_angle(tip, "a = 0 deg");
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)
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;
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) {
status_set_type_entry("width =");
set_with_units(status_set_name, "", width);
tip = "Line 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)
{
status_set_type_entry("ref =");
status_set_name("%s", self->vec->name ? self->vec->name : "");
const char *tip;
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);
vec_edit(self->vec);
}
@ -814,8 +820,8 @@ static void obj_pad_edit(struct obj *obj)
static void pad_op_select(struct inst *self)
{
status_set_type_entry("label =");
status_set_name("%s", self->u.pad.name);
status_set_type_entry("Pad name", "label =");
status_set_name("Pad name (actual)", "%s", self->u.pad.name);
rect_status(self->base, self->u.pad.other, -1, 0);
obj_pad_edit(self->obj);
}
@ -842,8 +848,8 @@ static struct inst_ops pad_ops = {
static void rpad_op_select(struct inst *self)
{
status_set_type_entry("label =");
status_set_name("%s", self->u.pad.name);
status_set_type_entry("Pad name", "label =");
status_set_name("Pad name (actual)", "%s", self->u.pad.name);
rect_status(self->base, self->u.pad.other, -1, 1);
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)
{
const char *tip;
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.a2-self->u.arc.a1);
set_with_units(status_set_r, "r = ", self->u.arc.r);
status_set_type_entry("width =");
set_with_units(status_set_name, "", self->u.arc.width);
set_with_units(status_set_r, "r = ", self->u.arc.r, "Radius");
tip = "Line width";
status_set_type_entry(tip, "width =");
set_with_units(status_set_name, "", self->u.arc.width, tip);
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)
{
const char *tip;
rect_status(self->bbox.min, self->bbox.max, -1, 0);
status_set_type_entry("offset =");
set_with_units(status_set_name, "", self->u.meas.offset);
tip = "Measurement line offset";
status_set_type_entry(tip, "offset =");
set_with_units(status_set_name, "", self->u.meas.offset, tip);
obj_meas_edit(self->obj);
}
@ -1084,9 +1096,12 @@ void inst_end_active(void)
static void frame_op_select(struct inst *self)
{
const char *tip;
tip = "Frame name";
rect_status(self->bbox.min, self->bbox.max, -1, 0);
status_set_type_entry("name =");
status_set_name("%s", self->u.frame.ref->name);
status_set_type_entry(tip, "name =");
status_set_name(tip, "%s", self->u.frame.ref->name);
}