mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-22 23:26:27 +02:00
Added auxiliary projections to help mis-levelling with more confidence.
- solidify/level.c (xz, draw_xz, motion_notify_event, level): show a projection on a xz plane at the cursor position - solidify/level.c (zy, draw_zy, motion_notify_event, level): show a projection on a zy plane at the cursor position
This commit is contained in:
parent
2997c6b441
commit
a3f17c504b
111
solidify/level.c
111
solidify/level.c
@ -27,6 +27,7 @@
|
||||
|
||||
|
||||
static int has_osd;
|
||||
static GtkWidget *xz, *zy;
|
||||
|
||||
|
||||
static double r_center(const struct face *f)
|
||||
@ -91,6 +92,78 @@ static void draw_image(GtkWidget *widget, struct face *f, int osd)
|
||||
}
|
||||
|
||||
|
||||
static void draw_xz(GtkWidget *widget, struct face *f, int y)
|
||||
{
|
||||
int x, z, z0;
|
||||
guchar *rgbbuf, *p;
|
||||
|
||||
rgbbuf = p = calloc(f->sx*f->sz, 3);
|
||||
if (!rgbbuf) {
|
||||
perror("calloc");
|
||||
exit(1);
|
||||
}
|
||||
if (y != -1)
|
||||
for (x = 0; x != f->sx ; x++) {
|
||||
z = get(f->a, x+f->a->min_x, y+f->a->min_y);
|
||||
if (z != UNDEF) {
|
||||
p = rgbbuf+3*(x+f->sx*(f->sz-z+f->a->min_z-1));
|
||||
p[0] = 0xff;
|
||||
p[1] = 0xff;
|
||||
p[2] = 0xff;
|
||||
}
|
||||
z0 = round(face_z0(f, x, y));
|
||||
/* @@@ anti-alias */
|
||||
if (z0 >= f->a->min_z && z0 <= f->a->max_z) {
|
||||
p = rgbbuf+3*(x+f->sx*(f->sz-z0+f->a->min_z-1));
|
||||
p[0] = 0x80;
|
||||
p[1] = 0xc0;
|
||||
p[2] = 0xff;
|
||||
}
|
||||
}
|
||||
gdk_draw_rgb_image(widget->window,
|
||||
widget->style->fg_gc[GTK_STATE_NORMAL],
|
||||
0, 0, f->sx, f->sz, GDK_RGB_DITHER_MAX, rgbbuf, f->sx*3);
|
||||
free(rgbbuf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void draw_zy(GtkWidget *widget, struct face *f, int x)
|
||||
{
|
||||
int y, z, z0;
|
||||
guchar *rgbbuf, *p;
|
||||
|
||||
rgbbuf = p = calloc(f->sy*f->sz, 3);
|
||||
if (!rgbbuf) {
|
||||
perror("calloc");
|
||||
exit(1);
|
||||
}
|
||||
if (x != -1)
|
||||
for (y = 0; y != f->sy ; y++) {
|
||||
z = get(f->a, x+f->a->min_x, y+f->a->min_y);
|
||||
if (z != UNDEF) {
|
||||
p = rgbbuf+3*(f->a->max_z-z+f->sz*(f->sy-y-1));
|
||||
p[0] = 0xff;
|
||||
p[1] = 0xff;
|
||||
p[2] = 0xff;
|
||||
}
|
||||
z0 = round(face_z0(f, x, y));
|
||||
/* @@@ anti-alias */
|
||||
if (z0 >= f->a->min_z && z0 <= f->a->max_z) {
|
||||
p = rgbbuf+3*(f->a->max_z-z0+f->sz*(f->sy-y-1));
|
||||
p[0] = 0x80;
|
||||
p[1] = 0xc0;
|
||||
p[2] = 0xff;
|
||||
}
|
||||
}
|
||||
gdk_draw_rgb_image(widget->window,
|
||||
widget->style->fg_gc[GTK_STATE_NORMAL],
|
||||
0, 0, f->sz, f->sy, GDK_RGB_DITHER_MAX, rgbbuf, f->sz*3);
|
||||
free(rgbbuf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void scroll_z(GtkWidget *darea, struct face *f, int up, int osd)
|
||||
{
|
||||
if (up) {
|
||||
@ -144,6 +217,8 @@ static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event,
|
||||
default:
|
||||
/* ignore */;
|
||||
}
|
||||
draw_xz(xz, f, f->sy-1-event->y);
|
||||
draw_zy(zy, f, event->x);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -168,33 +243,51 @@ static gboolean motion_notify_event(GtkWidget *widget, GdkEventMotion *event,
|
||||
|
||||
if (osd != has_osd)
|
||||
draw_image(widget, f, osd);
|
||||
draw_xz(xz, f, f->sy-1-event->y);
|
||||
draw_zy(zy, f, event->x);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
void level(GtkWidget *canvas, struct face *f)
|
||||
{
|
||||
GtkWidget *evbox, *darea;
|
||||
GtkWidget *evbox, *tab, *xy;
|
||||
|
||||
evbox = gtk_event_box_new();
|
||||
darea = gtk_drawing_area_new();
|
||||
tab = gtk_table_new(2, 2, FALSE);
|
||||
xy = gtk_drawing_area_new();
|
||||
xz = gtk_drawing_area_new();
|
||||
zy = gtk_drawing_area_new();
|
||||
|
||||
gtk_widget_set_events(darea,
|
||||
gtk_widget_set_events(xy,
|
||||
GDK_EXPOSE | GDK_KEY_PRESS_MASK |
|
||||
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
|
||||
GDK_SCROLL |
|
||||
GDK_POINTER_MOTION_MASK);
|
||||
|
||||
gtk_widget_set_size_request(darea, f->sx, f->sy);
|
||||
gtk_container_add(GTK_CONTAINER(canvas), evbox);
|
||||
gtk_container_add(GTK_CONTAINER(evbox), darea);
|
||||
gtk_widget_set_size_request(xy, f->sx, f->sy);
|
||||
gtk_widget_set_size_request(xz, f->sx, f->sz);
|
||||
gtk_widget_set_size_request(zy, f->sz, f->sy);
|
||||
|
||||
draw_image(darea, f, 0);
|
||||
gtk_table_set_row_spacings(GTK_TABLE(tab), 2);
|
||||
gtk_table_set_col_spacings(GTK_TABLE(tab), 2);
|
||||
|
||||
gtk_table_attach_defaults(GTK_TABLE(tab), evbox, 0, 1, 0, 1);
|
||||
gtk_table_attach_defaults(GTK_TABLE(tab), xz, 0, 1, 1, 2);
|
||||
gtk_table_attach_defaults(GTK_TABLE(tab), zy, 1, 2, 0, 1);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(canvas), tab);
|
||||
gtk_container_add(GTK_CONTAINER(evbox), xy);
|
||||
|
||||
gtk_widget_show_all(canvas);
|
||||
draw_image(xy, f, 0);
|
||||
draw_xz(xz, f, -1);
|
||||
draw_zy(zy, f, -1);
|
||||
|
||||
g_signal_connect(G_OBJECT(evbox), "scroll-event",
|
||||
G_CALLBACK(scroll_event), f);
|
||||
g_signal_connect(G_OBJECT(darea), "expose-event",
|
||||
g_signal_connect(G_OBJECT(xy), "expose-event",
|
||||
G_CALLBACK(expose_event), f);
|
||||
g_signal_connect(G_OBJECT(darea), "motion-notify-event",
|
||||
g_signal_connect(G_OBJECT(xy), "motion-notify-event",
|
||||
G_CALLBACK(motion_notify_event), f);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user