2010-09-24 02:13:48 +03:00
|
|
|
/*
|
|
|
|
* solidify.c - Merge two opposing faces of a part into a solid
|
|
|
|
*
|
|
|
|
* Written 2010 by Werner Almesberger
|
|
|
|
* Copyright 2010 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
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-09-22 23:04:43 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2010-09-24 12:22:48 +03:00
|
|
|
#include <unistd.h>
|
2010-09-22 23:04:43 +03:00
|
|
|
#include <locale.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "face.h"
|
Introduce a solid data type and use it, mainly in overlap()
- solidify/solid.h: definition of a solid made from two opposing faces
- solidify/overlap.h (overlap), solidify/overlap.c (draw_image,
scroll_event, overlap): operate on solid instead of face
- solidify/overlap.c (sx, sy, draw_image, overlap): helper functions sx()
and sy() to determine canvas size
- solidify/overlap.c (BORDER, sx, sy): added a border around the piece,
to help with positioning
- solidify/solidify.c (clicked, gui_buttons, gui, main): use solid instead
of faces
2010-09-24 05:41:35 +03:00
|
|
|
#include "solid.h"
|
2010-09-25 03:01:59 +03:00
|
|
|
#include "project.h"
|
When leveling, the center circle is now shown when the pointer approaches it.
- solidify/Makefile: added util.o
- solidify/util.h, solidify/util.c (draw_circle): wrapper for gdk_draw_arc
- solidify/Makefile: added style.o
- solidify/style.h, solidify/style.c, solidify/solidify.c (main): GUI style
parameters and items
- solidify/level.c (scroll_z. scroll_xy, scroll_event, level),
solidify/overlap.c (scroll_event, overlap): renamed "da" to "darea", to
avoid confusion with "da" for GdkDrawable in style.c
- solidify/level.c (r_center, scroll_event): moved center radius
calculation to separate function
- solidify/level.c (draw_image): renamed to draw_map
- solidify/level.c (draw_image): draw an on-screen display (OSD)
- solidify/level.c (scroll_z, scroll_xy, expose_event, level): propagate
OSD on/off switch
- solidify/level.c (scroll_event, motion_notify_event, level): enable OSD
when approaching the center circle
2010-09-24 08:04:04 +03:00
|
|
|
#include "style.h"
|
2010-09-22 23:04:43 +03:00
|
|
|
#include "level.h"
|
2010-09-24 05:18:46 +03:00
|
|
|
#include "overlap.h"
|
|
|
|
|
|
|
|
|
2010-09-25 03:01:59 +03:00
|
|
|
static struct project *prj;
|
|
|
|
static const struct face *active; /* NULL if overlapping */
|
2010-09-24 05:18:46 +03:00
|
|
|
static GtkWidget *canvas;
|
|
|
|
|
|
|
|
|
|
|
|
static void clicked(GtkButton *button, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct face *face = user_data;
|
|
|
|
|
|
|
|
if (active == face)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_widget_destroy(gtk_bin_get_child(GTK_BIN(canvas)));
|
|
|
|
|
|
|
|
if (face)
|
|
|
|
level(canvas, face);
|
|
|
|
else
|
2010-09-25 03:01:59 +03:00
|
|
|
overlap(canvas, &prj->s);
|
2010-09-24 05:18:46 +03:00
|
|
|
active = face;
|
|
|
|
|
|
|
|
gtk_widget_show_all(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *gui_buttons(void)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox, *but;
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new(FALSE, 0);
|
|
|
|
|
|
|
|
but = gtk_button_new_with_label("A");
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect(G_OBJECT(but), "clicked",
|
2010-09-25 03:01:59 +03:00
|
|
|
G_CALLBACK(clicked), prj->s.a);
|
2010-09-24 05:18:46 +03:00
|
|
|
|
|
|
|
but = gtk_button_new_with_label("B");
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect(G_OBJECT(but), "clicked",
|
2010-09-25 03:01:59 +03:00
|
|
|
G_CALLBACK(clicked), prj->s.b);
|
2010-09-24 05:18:46 +03:00
|
|
|
|
|
|
|
but = gtk_button_new_with_label("A+B");
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect(G_OBJECT(but), "clicked",
|
|
|
|
G_CALLBACK(clicked), NULL);
|
|
|
|
|
|
|
|
return vbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
if (event->keyval == 'q')
|
|
|
|
gtk_main_quit();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void gui(void)
|
|
|
|
{
|
|
|
|
GtkWidget *root, *hbox, *buttons;
|
|
|
|
|
|
|
|
root = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_window_set_position(GTK_WINDOW(root), GTK_WIN_POS_CENTER);
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new(FALSE, 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(root), hbox);
|
|
|
|
|
|
|
|
canvas = gtk_event_box_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), canvas, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* initialize root->window */
|
|
|
|
gtk_widget_show_all(root);
|
|
|
|
|
|
|
|
buttons = gui_buttons();
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), buttons, FALSE, FALSE, 0);
|
|
|
|
|
2010-09-25 03:01:59 +03:00
|
|
|
level(canvas, prj->s.a);
|
|
|
|
active = prj->s.a;
|
2010-09-24 05:18:46 +03:00
|
|
|
|
When leveling, the center circle is now shown when the pointer approaches it.
- solidify/Makefile: added util.o
- solidify/util.h, solidify/util.c (draw_circle): wrapper for gdk_draw_arc
- solidify/Makefile: added style.o
- solidify/style.h, solidify/style.c, solidify/solidify.c (main): GUI style
parameters and items
- solidify/level.c (scroll_z. scroll_xy, scroll_event, level),
solidify/overlap.c (scroll_event, overlap): renamed "da" to "darea", to
avoid confusion with "da" for GdkDrawable in style.c
- solidify/level.c (r_center, scroll_event): moved center radius
calculation to separate function
- solidify/level.c (draw_image): renamed to draw_map
- solidify/level.c (draw_image): draw an on-screen display (OSD)
- solidify/level.c (scroll_z, scroll_xy, expose_event, level): propagate
OSD on/off switch
- solidify/level.c (scroll_event, motion_notify_event, level): enable OSD
when approaching the center circle
2010-09-24 08:04:04 +03:00
|
|
|
init_style(root->window);
|
|
|
|
|
2010-09-24 05:18:46 +03:00
|
|
|
gtk_widget_show_all(root);
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(root), "key-press-event",
|
|
|
|
G_CALLBACK(key_press_event), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(root), "destroy",
|
|
|
|
G_CALLBACK(gtk_main_quit), NULL);
|
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
}
|
2010-09-22 23:04:43 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
2010-09-25 03:01:59 +03:00
|
|
|
fprintf(stderr, "usage: %s project [top bottom dist]\n", name);
|
2010-09-22 23:04:43 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2010-09-25 03:01:59 +03:00
|
|
|
double dist;
|
|
|
|
|
2010-09-22 23:04:43 +03:00
|
|
|
gtk_init(&argc, &argv);
|
2010-09-25 01:53:06 +03:00
|
|
|
setlocale(LC_ALL, "C"); /* damage control */
|
|
|
|
|
2010-09-22 23:04:43 +03:00
|
|
|
switch (argc) {
|
2010-09-25 03:01:59 +03:00
|
|
|
case 2:
|
|
|
|
prj = load_project(argv[1]);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
dist = atof(argv[4]);
|
|
|
|
prj = new_project(argv[1], argv[2], argv[3], dist);
|
2010-09-22 23:04:43 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
2010-09-25 01:53:06 +03:00
|
|
|
|
2010-09-24 05:18:46 +03:00
|
|
|
gui();
|
2010-09-25 01:53:06 +03:00
|
|
|
|
2010-09-25 03:01:59 +03:00
|
|
|
save_project(prj);
|
|
|
|
|
2010-09-24 12:22:48 +03:00
|
|
|
if (!isatty(1))
|
2010-09-25 03:01:59 +03:00
|
|
|
povray(&prj->s);
|
2010-09-22 23:04:43 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|