1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-22 08:24:06 +02:00

- simplified tool_button and moved it from gui_tool.c to into gui_util.c

- moved make_image from gui_tool.c to into gui_util.c as well
- generalized set_frame_image and moved it to gui_util.c as set_image
- tool_button_press_event didn't check which button was pressed
- added buttons to switch visibility of frames, vectors, and measurements
- when creating a measurement through the GUI, don't invert if both points are
  minima (otherwise, one could never get the text point the other way)



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5411 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2009-08-08 21:59:33 +00:00
parent e677ee1691
commit 851c82af6f
11 changed files with 261 additions and 90 deletions

View File

@ -17,7 +17,8 @@ OBJS = fped.o expr.o coord.o obj.o delete.o inst.o util.o error.o \
gui_tool.o gui_over.o gui_meas.o gui_frame.o gui_tool.o gui_over.o gui_meas.o gui_frame.o
XPMS = point.xpm delete.xpm vec.xpm frame.xpm frame_locked.xpm frame_ready.xpm \ XPMS = point.xpm delete.xpm vec.xpm frame.xpm frame_locked.xpm frame_ready.xpm \
line.xpm rect.xpm pad.xpm circ.xpm meas.xpm meas_x.xpm meas_y.xpm line.xpm rect.xpm pad.xpm circ.xpm meas.xpm meas_x.xpm meas_y.xpm \
stuff.xpm stuff_off.xpm meas_off.xpm
CFLAGS_GTK = `pkg-config --cflags gtk+-2.0` CFLAGS_GTK = `pkg-config --cflags gtk+-2.0`
LIBS_GTK = `pkg-config --libs gtk+-2.0` LIBS_GTK = `pkg-config --libs gtk+-2.0`
@ -95,7 +96,7 @@ y.tab.c y.tab.h: fpd.y
y.tab.o: y.tab.c y.tab.o: y.tab.c
$(CC) -c $(CFLAGS) $(SLOPPY) y.tab.c $(CC) -c $(CFLAGS) $(SLOPPY) y.tab.c
gui_tool.o: $(XPMS:%=icons/%) gui_tool.o gui.o: $(XPMS:%=icons/%)
# ----- Dependencies ---------------------------------------------------------- # ----- Dependencies ----------------------------------------------------------

77
gui.c
View File

@ -24,10 +24,20 @@
#include "gui_frame.h" #include "gui_frame.h"
#include "gui.h" #include "gui.h"
#include "icons/stuff.xpm"
#include "icons/stuff_off.xpm"
#include "icons/meas.xpm"
#include "icons/meas_off.xpm"
GtkWidget *root; GtkWidget *root;
int show_stuff = 1;
int show_meas = 1;
static GtkWidget *frames_box; static GtkWidget *frames_box;
static GtkWidget *ev_stuff, *ev_meas;
static GtkWidget *stuff_image[2], *meas_image[2];
/* ----- menu bar ---------------------------------------------------------- */ /* ----- menu bar ---------------------------------------------------------- */
@ -39,13 +49,13 @@ static void menu_save(GtkWidget *widget, gpointer user)
} }
static void make_menu_bar(GtkWidget *vbox) static void make_menu_bar(GtkWidget *hbox)
{ {
GtkWidget *bar; GtkWidget *bar;
GtkWidget *file_menu, *file, *quit, *save; GtkWidget *file_menu, *file, *quit, *save;
bar = gtk_menu_bar_new(); bar = gtk_menu_bar_new();
gtk_box_pack_start(GTK_BOX(vbox), bar, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), bar, TRUE, TRUE, 0);
file_menu = gtk_menu_new(); file_menu = gtk_menu_new();
@ -65,6 +75,67 @@ static void make_menu_bar(GtkWidget *vbox)
} }
static gboolean toggle_stuff(GtkWidget *widget, GdkEventButton *event,
gpointer data)
{
switch (event->button) {
case 1:
show_stuff = !show_stuff;
set_image(ev_stuff, stuff_image[show_stuff]);
redraw();
break;
}
return TRUE;
}
static gboolean toggle_meas(GtkWidget *widget, GdkEventButton *event,
gpointer data)
{
switch (event->button) {
case 1:
show_meas = !show_meas;
set_image(ev_meas, meas_image[show_meas]);
redraw();
break;
}
return TRUE;
}
static void make_tool_bar(GtkWidget *hbox, GdkDrawable *drawable)
{
GtkWidget *bar;
bar = gtk_toolbar_new();
gtk_box_pack_end(GTK_BOX(hbox), bar, TRUE, TRUE, 0);
//gtk_box_pack_end(GTK_BOX(hbox), bar, FALSE, FALSE, 0);
gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_ICONS);
ev_stuff = tool_button(bar, drawable, NULL, toggle_stuff, NULL);
ev_meas = tool_button(bar, drawable, NULL, toggle_meas, NULL);
stuff_image[0] = gtk_widget_ref(make_image(drawable, xpm_stuff_off));
stuff_image[1] = gtk_widget_ref(make_image(drawable, xpm_stuff));
meas_image[0] = gtk_widget_ref(make_image(drawable, xpm_meas_off));
meas_image[1] = gtk_widget_ref(make_image(drawable, xpm_meas));
set_image(ev_stuff, stuff_image[show_stuff]);
set_image(ev_meas, meas_image[show_meas]);
}
static void make_top_bar(GtkWidget *vbox)
{
GtkWidget *hbox;
hbox = gtk_hbox_new(FALSE, 0);
make_menu_bar(hbox);
make_tool_bar(hbox, root->window);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
}
/* ----- central screen area ----------------------------------------------- */ /* ----- central screen area ----------------------------------------------- */
@ -125,7 +196,7 @@ static void make_screen(GtkWidget *window)
vbox = gtk_vbox_new(FALSE, 0); vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox); gtk_container_add(GTK_CONTAINER(window), vbox);
make_menu_bar(vbox); make_top_bar(vbox);
make_center_area(vbox); make_center_area(vbox);
make_status_area(vbox); make_status_area(vbox);
} }

2
gui.h
View File

@ -18,6 +18,8 @@
extern GtkWidget *root; extern GtkWidget *root;
extern int show_stuff;
extern int show_meas;
/* update everything after a model change */ /* update everything after a model change */

View File

@ -286,8 +286,10 @@ static int end_new_meas(struct inst *from, struct inst *to)
default: default:
abort(); abort();
} }
meas->inverted = meas_dsc->lt(from->u.rect.end, to->u.rect.end) != meas->inverted =
(mode == min_to_next_or_max); mode == min_to_next_or_max && is_min(meas_dsc->lt, to) ? 0 :
meas_dsc->lt(from->u.rect.end, to->u.rect.end) !=
(mode == min_to_next_or_max);
{ {
char *sm[] = { "min_to", "max_to", "next_to" }; char *sm[] = { "min_to", "max_to", "next_to" };
char *st[] = { "nxy", "nx", "ny", "mxy", "mx", "my" }; char *st[] = { "nxy", "nx", "ny", "mxy", "mx", "my" };

View File

@ -510,17 +510,9 @@ static int is_parent_of(const struct frame *p, const struct frame *c)
static struct frame *locked_frame = NULL; static struct frame *locked_frame = NULL;
static void remove_child(GtkWidget *widget, gpointer data)
{
gtk_container_remove(GTK_CONTAINER(data), widget);
}
static void set_frame_image(GtkWidget *image) static void set_frame_image(GtkWidget *image)
{ {
gtk_container_foreach(GTK_CONTAINER(ev_frame), remove_child, ev_frame); set_image(ev_frame, image);
gtk_container_add(GTK_CONTAINER(ev_frame), image);
gtk_widget_show_all(ev_frame);
} }
@ -851,63 +843,12 @@ void tool_reset(void)
static gboolean tool_button_press_event(GtkWidget *widget, static gboolean tool_button_press_event(GtkWidget *widget,
GdkEventButton *event, gpointer data) GdkEventButton *event, gpointer data)
{ {
tool_select(widget, data); switch (event->button) {
return TRUE; case 1:
} tool_select(widget, data);
break;
static GtkWidget *make_image(GdkDrawable *drawable, char **xpm)
{
GdkPixmap *pixmap;
GtkWidget *image;
pixmap = gdk_pixmap_create_from_xpm_d(drawable, NULL, NULL, xpm);
image = gtk_image_new_from_pixmap(pixmap, NULL);
gtk_misc_set_padding(GTK_MISC(image), 1, 1);
return image;
}
static GtkWidget *tool_button(GtkWidget *bar, GdkDrawable *drawable,
char **xpm, GtkWidget *last_evbox, struct tool_ops *ops)
{
GtkWidget *image, *evbox;
GtkToolItem *item;
GtkToolItem *last = NULL;
if (last_evbox)
last = GTK_TOOL_ITEM(gtk_widget_get_ancestor(last_evbox,
GTK_TYPE_TOOL_ITEM));
/*
* gtk_radio_tool_button_new_from_widget is *huge*. we try to do things in a
* more compact way.
*/
#if 0
if (last)
item = gtk_radio_tool_button_new_from_widget(
GTK_RADIO_TOOL_BUTTON(last));
else
item = gtk_radio_tool_button_new(NULL);
gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(item), image);
#else
evbox = gtk_event_box_new();
if (xpm) {
image = make_image(drawable, xpm);
gtk_container_add(GTK_CONTAINER(evbox), image);
} }
g_signal_connect(G_OBJECT(evbox), "button_press_event", return TRUE;
G_CALLBACK(tool_button_press_event), ops);
item = gtk_tool_item_new();
gtk_container_add(GTK_CONTAINER(item), evbox);
gtk_container_set_border_width(GTK_CONTAINER(item), 0);
#endif
gtk_toolbar_insert(GTK_TOOLBAR(bar), item, -1);
return evbox;
} }
@ -924,27 +865,36 @@ static void tool_separator(GtkWidget *bar)
GtkWidget *gui_setup_tools(GdkDrawable *drawable) GtkWidget *gui_setup_tools(GdkDrawable *drawable)
{ {
GtkWidget *bar; GtkWidget *bar;
GtkWidget *last;
bar = gtk_toolbar_new(); bar = gtk_toolbar_new();
gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_ICONS); gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_ICONS);
gtk_toolbar_set_orientation(GTK_TOOLBAR(bar), gtk_toolbar_set_orientation(GTK_TOOLBAR(bar),
GTK_ORIENTATION_VERTICAL); GTK_ORIENTATION_VERTICAL);
ev_point = tool_button(bar, drawable, xpm_point, NULL, NULL); ev_point = tool_button(bar, drawable, xpm_point,
last = tool_button(bar, drawable, xpm_delete, ev_point, &delete_ops); tool_button_press_event, NULL);
tool_button(bar, drawable, xpm_delete,
tool_button_press_event, &delete_ops);
tool_separator(bar); tool_separator(bar);
last = tool_button(bar, drawable, xpm_vec, last, &vec_ops); tool_button(bar, drawable, xpm_vec,
ev_frame = tool_button(bar, drawable, NULL, last, &frame_ops); tool_button_press_event, &vec_ops);
last = ev_frame; ev_frame = tool_button(bar, drawable, NULL,
last = tool_button(bar, drawable, xpm_pad, last, &pad_ops); tool_button_press_event, &frame_ops);
last = tool_button(bar, drawable, xpm_line, last, &line_ops); tool_button(bar, drawable, xpm_pad,
last = tool_button(bar, drawable, xpm_rect, last, &rect_ops); tool_button_press_event, &pad_ops);
last = tool_button(bar, drawable, xpm_circ, last, &circ_ops); tool_button(bar, drawable, xpm_line,
tool_button_press_event, &line_ops);
tool_button(bar, drawable, xpm_rect,
tool_button_press_event, &rect_ops);
tool_button(bar, drawable, xpm_circ,
tool_button_press_event, &circ_ops);
tool_separator(bar); tool_separator(bar);
last = tool_button(bar, drawable, xpm_meas, last, &meas_ops); tool_button(bar, drawable, xpm_meas,
last = tool_button(bar, drawable, xpm_meas_x, last, &meas_ops_x); tool_button_press_event, &meas_ops);
last = tool_button(bar, drawable, xpm_meas_y, last, &meas_ops_y); tool_button(bar, drawable, xpm_meas_x,
tool_button_press_event, &meas_ops_x);
tool_button(bar, drawable, xpm_meas_y,
tool_button_press_event, &meas_ops_y);
frame_image = gtk_widget_ref(make_image(drawable, xpm_frame)); frame_image = gtk_widget_ref(make_image(drawable, xpm_frame));
frame_image_locked = frame_image_locked =

View File

@ -161,6 +161,67 @@ void label_in_box_bg(GtkWidget *label, const char *color)
} }
/* ----- generate a tool button with an XPM image -------------------------- */
GtkWidget *make_image(GdkDrawable *drawable, char **xpm)
{
GdkPixmap *pixmap;
GtkWidget *image;
pixmap = gdk_pixmap_create_from_xpm_d(drawable, NULL, NULL, xpm);
image = gtk_image_new_from_pixmap(pixmap, NULL);
gtk_misc_set_padding(GTK_MISC(image), 1, 1);
return image;
}
static void remove_child(GtkWidget *widget, gpointer data)
{
gtk_container_remove(GTK_CONTAINER(data), widget);
}
void set_image(GtkWidget *widget, GtkWidget *image)
{
gtk_container_foreach(GTK_CONTAINER(widget), remove_child, widget);
gtk_container_add(GTK_CONTAINER(widget), image);
gtk_widget_show_all(widget);
}
GtkWidget *tool_button(GtkWidget *bar, GdkDrawable *drawable, char **xpm,
gboolean (*cb)(GtkWidget *widget, GdkEventButton *event, gpointer data),
gpointer data)
{
GtkWidget *image, *evbox;
GtkToolItem *item;
/*
* gtk_radio_tool_button_new_from_widget is *huge*. We try to do things
* in a
* more compact way.
*/
evbox = gtk_event_box_new();
if (xpm) {
image = make_image(drawable, xpm);
gtk_container_add(GTK_CONTAINER(evbox), image);
}
g_signal_connect(G_OBJECT(evbox), "button_press_event",
G_CALLBACK(cb), data);
item = gtk_tool_item_new();
gtk_container_add(GTK_CONTAINER(item), evbox);
gtk_container_set_border_width(GTK_CONTAINER(item), 0);
gtk_toolbar_insert(GTK_TOOLBAR(bar), item, -1);
return evbox;
}
/* ----- render a text string ---------------------------------------------- */ /* ----- render a text string ---------------------------------------------- */

View File

@ -56,6 +56,12 @@ GtkWidget *label_in_box_new(const char *s);
GtkWidget *box_of_label(GtkWidget *label); GtkWidget *box_of_label(GtkWidget *label);
void label_in_box_bg(GtkWidget *box, const char *color); void label_in_box_bg(GtkWidget *box, const char *color);
GtkWidget *make_image(GdkDrawable *drawable, char **xpm);
void set_image(GtkWidget *widget, GtkWidget *image);
GtkWidget *tool_button(GtkWidget *bar, GdkDrawable *drawable, char **xpm,
gboolean (*cb)(GtkWidget *widget, GdkEventButton *event, gpointer data),
gpointer data);
void render_text(GdkDrawable *da, GdkGC *gc, int x, int y, double angle, void render_text(GdkDrawable *da, GdkGC *gc, int x, int y, double angle,
const char *s, const char *font, double xalign, double yalign, const char *s, const char *font, double xalign, double yalign,
int xmax, int ymax); int xmax, int ymax);

19
icons/meas_off.fig Normal file
View File

@ -0,0 +1,19 @@
#FIG 3.2 Produced by xfig version 3.2.5a
Landscape
Center
Inches
A4
100.00
Single
-2
1200 2
2 2 0 1 0 7 50 -1 10 0.000 0 0 -1 0 0 5
3600 2400 6000 2400 6000 4800 3600 4800 3600 2400
2 1 0 10 0 7 40 -1 -1 0.000 0 0 -1 0 0 2
3900 3600 4200 4200
2 1 0 10 0 7 40 -1 -1 0.000 0 0 -1 1 1 2
0 0 10.00 450.00 450.00
0 0 10.00 450.00 450.00
4050 3900 5550 3150
2 1 0 10 0 7 40 -1 -1 0.000 0 0 -1 0 0 2
5400 2850 5700 3450

17
icons/stuff.fig Normal file
View File

@ -0,0 +1,17 @@
#FIG 3.2 Produced by xfig version 3.2.5a
Landscape
Center
Inches
A4
100.00
Single
-2
1200 2
0 32 #c0c000
2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
3600 2400 6000 2400 6000 4800 3600 4800 3600 2400
2 1 0 10 32 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 10.00 300.00 300.00
3900 4515 5700 3315
2 1 0 10 12 7 50 -1 -1 0.000 0 1 -1 0 0 3
3900 3600 3900 2760 5700 2760

17
icons/stuff_off.fig Normal file
View File

@ -0,0 +1,17 @@
#FIG 3.2 Produced by xfig version 3.2.5a
Landscape
Center
Inches
A4
100.00
Single
-2
1200 2
0 32 #c0c000
2 1 0 10 0 7 40 -1 -1 0.000 0 0 -1 1 0 2
1 1 10.00 300.00 300.00
3900 4515 5700 3315
2 1 0 10 0 7 40 -1 -1 0.000 0 1 -1 0 0 3
3900 3600 3900 2760 5700 2760
2 2 0 1 0 7 50 -1 10 0.000 0 0 -1 0 0 5
3600 2400 6000 2400 6000 4800 3600 4800 3600 2400

35
inst.c
View File

@ -24,6 +24,7 @@
#include "gui_status.h" #include "gui_status.h"
#include "gui_tool.h" #include "gui_tool.h"
#include "gui_inst.h" #include "gui_inst.h"
#include "gui.h"
#include "inst.h" #include "inst.h"
@ -83,6 +84,23 @@ static unsigned long active_set = 0;
#define IS_ACTIVE ((active_set & 1)) #define IS_ACTIVE ((active_set & 1))
/* ----- selective visibility ---------------------------------------------- */
static int show(enum inst_prio prio)
{
switch (prio) {
case ip_vec:
case ip_frame:
return show_stuff;
case ip_meas:
return show_meas;
default:
return 1;
}
}
/* ----- selection of items not on the canvas ------------------------------ */ /* ----- selection of items not on the canvas ------------------------------ */
@ -142,6 +160,8 @@ int inst_select(struct coord pos)
edit_nothing(); edit_nothing();
selected_inst = NULL; selected_inst = NULL;
FOR_INST_PRIOS_DOWN(prio) { FOR_INST_PRIOS_DOWN(prio) {
if (!show(prio))
continue;
for (inst = insts[prio]; inst; inst = inst->next) { for (inst = insts[prio]; inst; inst = inst->next) {
if (!inst->active || !inst->ops->distance) if (!inst->active || !inst->ops->distance)
continue; continue;
@ -155,6 +175,9 @@ int inst_select(struct coord pos)
goto selected; goto selected;
} }
if (!show_stuff)
return 0;
/* give vectors a second chance */ /* give vectors a second chance */
for (inst = insts[ip_vec]; inst; inst = inst->next) { for (inst = insts[ip_vec]; inst; inst = inst->next) {
@ -828,15 +851,17 @@ void inst_draw(void)
struct inst *inst; struct inst *inst;
FOR_INSTS_UP(prio, inst) FOR_INSTS_UP(prio, inst)
if (!inst->active && inst->ops->draw) if (show(prio) && !inst->active && inst->ops->draw)
inst->ops->draw(inst); inst->ops->draw(inst);
FOR_INSTS_UP(prio, inst) FOR_INSTS_UP(prio, inst)
if (prio != ip_frame && inst->active && if (show(prio) && prio != ip_frame && inst->active &&
inst != selected_inst && inst->ops->draw) inst != selected_inst && inst->ops->draw)
inst->ops->draw(inst); inst->ops->draw(inst);
for (inst = insts[ip_frame]; inst; inst = inst->next) if (show_stuff)
if (inst->active && inst != selected_inst && inst->ops->draw) for (inst = insts[ip_frame]; inst; inst = inst->next)
inst->ops->draw(inst); if (inst->active && inst != selected_inst &&
inst->ops->draw)
inst->ops->draw(inst);
if (selected_inst && selected_inst->ops->draw) if (selected_inst && selected_inst->ops->draw)
selected_inst->ops->draw(selected_inst); selected_inst->ops->draw(selected_inst);
} }