mirror of
git://projects.qi-hardware.com/ben-scans.git
synced 2024-11-21 21:45:55 +02:00
The GUI can now switch among operations.
- solidify/level.c (key_press_event, make_screen), solidify/solidify.c (key_press_event): moved "q" handler to solidify.c - solidify/level.h (level), solidify/level.c (make_screen, level): removed root window initialization and merged remainder into "level" - solidify/overlap.h (overlap), solidify/overlap.c (make_screen, overlap): removed root window initialization and merged remainder into "overlap" - solidify/solidify.c (gui): initialize the root window - solidify/solidify.c (gui, gui_buttons, clicked): added buttons to select operation
This commit is contained in:
parent
fbbbd29a28
commit
b8bba1d3ab
@ -131,45 +131,20 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event,
|
||||
}
|
||||
|
||||
|
||||
static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
|
||||
gpointer data)
|
||||
{
|
||||
if (event->keyval == 'q')
|
||||
gtk_main_quit();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void make_screen(GtkWidget *root, struct face *f)
|
||||
void level(GtkWidget *canvas, struct face *f)
|
||||
{
|
||||
GtkWidget *evbox, *da;
|
||||
|
||||
evbox = gtk_event_box_new();
|
||||
da = gtk_drawing_area_new();
|
||||
gtk_widget_set_size_request(da, f->sx, f->sy);
|
||||
evbox = gtk_event_box_new();
|
||||
gtk_container_add(GTK_CONTAINER(canvas), evbox);
|
||||
gtk_container_add(GTK_CONTAINER(evbox), da);
|
||||
gtk_container_add(GTK_CONTAINER(root), evbox);
|
||||
gtk_widget_show_all(root);
|
||||
|
||||
draw_image(da, f);
|
||||
|
||||
g_signal_connect(G_OBJECT(evbox), "scroll-event",
|
||||
G_CALLBACK(scroll_event), f);
|
||||
g_signal_connect(G_OBJECT(da), "expose-event",
|
||||
G_CALLBACK(expose_event), f);
|
||||
g_signal_connect(G_OBJECT(root), "key-press-event",
|
||||
G_CALLBACK(key_press_event), NULL);
|
||||
}
|
||||
|
||||
|
||||
void level(struct face *f)
|
||||
{
|
||||
GtkWidget *root;
|
||||
|
||||
root = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_position(GTK_WINDOW(root), GTK_WIN_POS_CENTER);
|
||||
|
||||
g_signal_connect(G_OBJECT(root), "destroy",
|
||||
G_CALLBACK(gtk_main_quit), NULL);
|
||||
make_screen(root, f);
|
||||
gtk_main();
|
||||
}
|
||||
|
@ -13,9 +13,11 @@
|
||||
#ifndef LEVEL_H
|
||||
#define LEVEL_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "face.h"
|
||||
|
||||
|
||||
void level(struct face *f);
|
||||
void level(GtkWidget *canvas, struct face *f);
|
||||
|
||||
#endif /* LEVEL_H */
|
||||
|
@ -156,33 +156,22 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event,
|
||||
|
||||
|
||||
|
||||
static void make_screen(GtkWidget *root, struct face *f)
|
||||
void overlap(GtkWidget *canvas, struct face *f)
|
||||
{
|
||||
GtkWidget *evbox, *da;
|
||||
|
||||
evbox = gtk_event_box_new();
|
||||
da = gtk_drawing_area_new();
|
||||
gtk_widget_set_size_request(da, f->sx, f->sy);
|
||||
evbox = gtk_event_box_new();
|
||||
gtk_container_add(GTK_CONTAINER(canvas), evbox);
|
||||
gtk_container_add(GTK_CONTAINER(evbox), da);
|
||||
gtk_container_add(GTK_CONTAINER(root), evbox);
|
||||
gtk_widget_show_all(root);
|
||||
|
||||
draw_image(da, f);
|
||||
|
||||
g_signal_connect(G_OBJECT(evbox), "scroll-event",
|
||||
G_CALLBACK(scroll_event), f);
|
||||
g_signal_connect(G_OBJECT(da), "expose-event",
|
||||
G_CALLBACK(expose_event), f);
|
||||
}
|
||||
|
||||
void overlap(struct face *face)
|
||||
{
|
||||
GtkWidget *root;
|
||||
|
||||
root = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_position(GTK_WINDOW(root), GTK_WIN_POS_CENTER);
|
||||
|
||||
g_signal_connect(G_OBJECT(root), "destroy",
|
||||
G_CALLBACK(gtk_main_quit), NULL);
|
||||
make_screen(root, face);
|
||||
gtk_main();
|
||||
|
||||
return evbox;
|
||||
}
|
||||
|
@ -10,12 +10,12 @@
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OVERLAP_H
|
||||
#define OVERLAP_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
void overlap(struct face *face);
|
||||
|
||||
void overlap(GtkWidget *canvas, struct face *face);
|
||||
|
||||
#endif /* !OVERLAP_H */
|
||||
|
@ -18,6 +18,98 @@
|
||||
|
||||
#include "face.h"
|
||||
#include "level.h"
|
||||
#include "overlap.h"
|
||||
|
||||
|
||||
static struct face *face_a, *face_b;
|
||||
static const struct face *active;
|
||||
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
|
||||
overlap(canvas, face_a);
|
||||
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",
|
||||
G_CALLBACK(clicked), face_a);
|
||||
|
||||
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",
|
||||
G_CALLBACK(clicked), face_b);
|
||||
|
||||
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);
|
||||
|
||||
level(canvas, face_a);
|
||||
active = face_a;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
@ -29,8 +121,6 @@ static void usage(const char *name)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct face *top;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
switch (argc) {
|
||||
case 2:
|
||||
@ -39,8 +129,9 @@ int main(int argc, char **argv)
|
||||
usage(*argv);
|
||||
}
|
||||
setlocale(LC_ALL, "C"); /* damage control */
|
||||
top = read_face(argv[1]);
|
||||
level(top);
|
||||
face_a = read_face(argv[1]);
|
||||
face_b = face_a;
|
||||
gui();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user