2009-08-03 19:12:47 +03:00
|
|
|
/*
|
|
|
|
* gui.c - Editor GUI core
|
|
|
|
*
|
|
|
|
* Written 2009 by Werner Almesberger
|
|
|
|
* Copyright 2009 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
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "inst.h"
|
|
|
|
#include "obj.h"
|
2009-08-06 09:54:41 +03:00
|
|
|
#include "dump.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
#include "gui_util.h"
|
|
|
|
#include "gui_style.h"
|
|
|
|
#include "gui_status.h"
|
|
|
|
#include "gui_canvas.h"
|
2009-08-04 10:24:13 +03:00
|
|
|
#include "gui_tools.h"
|
2009-08-08 22:35:16 +03:00
|
|
|
#include "gui_frame.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
#include "gui.h"
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *root;
|
|
|
|
|
|
|
|
static GtkWidget *frames_box;
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- menu bar ---------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2009-08-06 09:54:41 +03:00
|
|
|
static void menu_save(GtkWidget *widget, gpointer user)
|
|
|
|
{
|
|
|
|
dump(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
static void make_menu_bar(GtkWidget *vbox)
|
|
|
|
{
|
|
|
|
GtkWidget *bar;
|
2009-08-06 09:54:41 +03:00
|
|
|
GtkWidget *file_menu, *file, *quit, *save;
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
bar = gtk_menu_bar_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), bar, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
file_menu = gtk_menu_new();
|
|
|
|
|
|
|
|
file = gtk_menu_item_new_with_label("File");
|
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), file_menu);
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(bar), file);
|
|
|
|
|
2009-08-06 09:54:41 +03:00
|
|
|
save = gtk_menu_item_new_with_label("Save");
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), save);
|
|
|
|
g_signal_connect(G_OBJECT(save), "activate",
|
|
|
|
G_CALLBACK(menu_save), NULL);
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
quit = gtk_menu_item_new_with_label("Quit");
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), quit);
|
|
|
|
g_signal_connect(G_OBJECT(quit), "activate",
|
|
|
|
G_CALLBACK(gtk_main_quit), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-04 00:10:49 +03:00
|
|
|
/* ----- central screen area ----------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void make_center_area(GtkWidget *vbox)
|
|
|
|
{
|
|
|
|
GtkWidget *hbox, *frames_area, *paned;
|
2009-08-04 10:24:13 +03:00
|
|
|
GtkWidget *tools;
|
2009-08-04 00:10:49 +03:00
|
|
|
|
|
|
|
hbox = gtk_hbox_new(FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
paned = gtk_hpaned_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), paned, TRUE, TRUE, 0);
|
|
|
|
|
2009-08-04 00:10:49 +03:00
|
|
|
/* Frames */
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2009-08-04 00:10:49 +03:00
|
|
|
frames_area = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_paned_add1(GTK_PANED(paned), frames_area);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(frames_area),
|
2009-08-03 19:12:47 +03:00
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2009-08-04 00:10:49 +03:00
|
|
|
gtk_widget_set_size_request(frames_area, 250, 100);
|
|
|
|
|
|
|
|
frames_box = gtk_vbox_new(FALSE, 0);
|
|
|
|
build_frames(frames_box);
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2009-08-04 00:10:49 +03:00
|
|
|
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(frames_area),
|
|
|
|
frames_box);
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
/* Canvas */
|
|
|
|
|
|
|
|
gtk_paned_add2(GTK_PANED(paned), make_canvas());
|
|
|
|
|
|
|
|
/* Icon bar */
|
|
|
|
|
2009-08-04 10:24:13 +03:00
|
|
|
tools = gui_setup_tools(root->window);
|
|
|
|
gtk_box_pack_end(GTK_BOX(hbox), tools, FALSE, FALSE, 0);
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- GUI construction -------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
void change_world(void)
|
|
|
|
{
|
2009-08-04 02:23:00 +03:00
|
|
|
inst_deselect();
|
2009-08-03 19:12:47 +03:00
|
|
|
status_begin_reporting();
|
|
|
|
instantiate();
|
|
|
|
label_in_box_bg(active_frame->label, COLOR_FRAME_SELECTED);
|
|
|
|
build_frames(frames_box);
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void make_screen(GtkWidget *window)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new(FALSE, 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(window), vbox);
|
|
|
|
|
|
|
|
make_menu_bar(vbox);
|
|
|
|
make_center_area(vbox);
|
|
|
|
make_status_area(vbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int gui_init(int *argc, char ***argv)
|
|
|
|
{
|
|
|
|
gtk_init(argc, argv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-05 13:35:48 +03:00
|
|
|
int gui_main(void)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
|
|
|
root = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_window_set_position(GTK_WINDOW(root), GTK_WIN_POS_CENTER);
|
2009-08-08 00:47:51 +03:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(root), 620, 460);
|
2009-08-03 19:12:47 +03:00
|
|
|
gtk_window_set_title(GTK_WINDOW(root), "fped");
|
|
|
|
|
|
|
|
/* get root->window */
|
|
|
|
gtk_widget_show_all(root);
|
|
|
|
|
|
|
|
g_signal_connect_swapped(G_OBJECT(root), "destroy",
|
|
|
|
G_CALLBACK(gtk_main_quit), NULL);
|
|
|
|
|
|
|
|
make_screen(root);
|
|
|
|
|
|
|
|
gtk_widget_show_all(root);
|
|
|
|
|
|
|
|
gui_setup_style(root->window);
|
|
|
|
init_canvas();
|
|
|
|
edit_nothing();
|
|
|
|
select_frame(root_frame);
|
2009-08-06 23:19:00 +03:00
|
|
|
make_popups();
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|