#include #include #include "tree.h" #include "contain.h" #include "texts.h" #include "in_depth.h" #include "parsing.h" #include "graph_area.h" /******************************************************************************/ /* M A I N W I N D O W A C T I V A T I O N */ /******************************************************************************/ void ui_main_window (GtkApplication *self, gpointer user_data) { GtkWindow *main_window = GTK_WINDOW (gtk_application_window_new (self)); window_header_bar (main_window, "E coli (with permission from David S. Goodsell, 2009)"); two_notebooks_in_two_panes (main_window); gtk_window_present (GTK_WINDOW (main_window)); } void ui_send_internal_notification(const char *message) { /* Ignored (2024-06-06) because I don't know how to get "main_window" easily if (window->toast_revealer == NULL) { g_printerr("Can't find self->toast_overlay !\n"); return; } if (window->toast_text == NULL) { g_printerr("Can't find self->toast_overlay !\n"); return; } gtk_label_set_label(window->toast_text, message); gtk_revealer_set_reveal_child(window->toast_revealer, true); */ g_printerr("%s\n", message); } /******************************************************************************/ /* T R E E */ /******************************************************************************/ void on_user_tree_expander_toggled (GtkExpander *expander, gpointer user_data) { GtkTreeListRow *row = GTK_TREE_LIST_ROW (user_data); gboolean is_expanded = gtk_tree_list_row_get_expanded(row); gtk_tree_list_row_set_expanded (row, !is_expanded); } void on_bind_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data) { GtkListItem *list_item = GTK_LIST_ITEM (object); assert (list_item); GtkTreeListRow *row = gtk_list_item_get_item (list_item); assert (row); // if (row != NULL) {...} ? const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row))); GtkWidget *expander = gtk_list_item_get_child (list_item); gtk_expander_set_label (GTK_EXPANDER (expander), text); g_signal_handlers_disconnect_by_func(expander, G_CALLBACK (on_user_tree_expander_toggled), row); g_signal_connect(expander, "activate", G_CALLBACK (on_user_tree_expander_toggled), row); gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row) * 20); } /******************************************************************************/ /* G L A R E A */ /******************************************************************************/ gboolean on_glarea_render(GtkGLArea *area, GdkGLContext *context) { // Check if the widget is a glarea if(gtk_gl_area_get_error(area) != NULL) { ////////////////////////// ui_send_internal_notification("An OpenGL error occured !"); return false; } ////////////////////////// if (ui_render_stack(gtk_widget_get_parent(GTK_WIDGET(area))) == false) { ////////////////////////// ui_send_internal_notification("Failed to render corresponding graphic stack !"); ////////////////////////// return false; ////////////////////////// } return true; } /* We need to set up our state when we realize the GtkGLArea widget */ void on_glarea_realize(GtkWidget *widget) { GError *internal_error = NULL; // Make the GL context current to be able to call the GL API gtk_gl_area_make_current(GTK_GL_AREA(widget)); // Check if the widget is a glarea if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL) { ui_send_internal_notification("An OpenGL error occured !"); return; } // Link graphical stack to widget if (ui_init_graphic_stack(gtk_widget_get_parent(widget), internal_error) == false) { ui_send_internal_notification( "Failed to link the graphic stack to widgets !"); return; } gtk_gl_area_set_auto_render(GTK_GL_AREA(widget), true); } /* We should tear down the state when unrealizing */ void on_glarea_unrealize(GtkWidget *widget) { GError *internal_error = NULL; // Make the GL context current to be able to call the GL API gtk_gl_area_make_current(GTK_GL_AREA(widget)); // Check if the widget is a glarea if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL) { ui_send_internal_notification("An OpenGL error occured !"); return; } // Destroy graphic stack if (ui_shutdown_graphic_stack(gtk_widget_get_parent(widget), internal_error) == false) { ui_send_internal_notification( "Failed to shutdown the graphic stack !"); return; } } /******************************************************************************/ /* B U T T O N S */ /******************************************************************************/ void ui_toggle_exec_edit (GtkWidget *btt_exec_xor_edit, GtkWidget *btt_run_stop_model_exec) { if (get_exec_edit_mode()) { gtk_button_set_icon_name (GTK_BUTTON (btt_exec_xor_edit), "system-run-symbolic"); gtk_button_set_icon_name (GTK_BUTTON (btt_run_stop_model_exec), "media-playback-start-symbolic"); gtk_widget_set_sensitive (GTK_WIDGET (btt_run_stop_model_exec), TRUE); set_exec_edit_mode (0); } else { gtk_button_set_icon_name (GTK_BUTTON (btt_exec_xor_edit), "document-edit-symbolic"); gtk_button_set_icon_name (GTK_BUTTON (btt_exec_xor_edit), "text-editor-symbolic"); // I hesitate set_exec_edit_mode (1); // Ici, il faudra prévenir l'utilisateur par une pop-up window : TODO (sauvegarde automatique sinon) // S'il ne prend pas la main, les données de la simulation en cours risquent d'être perdues gtk_button_set_icon_name (GTK_BUTTON (btt_run_stop_model_exec), "media-playback-pause-symbolic"); gtk_widget_set_sensitive (GTK_WIDGET (btt_run_stop_model_exec), FALSE); set_run_xor_stop_exec (0); } } void ui_toggle_model_exec (GtkWidget *btt_run_stop_model_exec, gpointer data) { if (get_run_xor_stop_exec() && ! get_exec_edit_mode()) { gtk_button_set_icon_name (GTK_BUTTON (btt_run_stop_model_exec), "media-playback-start-symbolic"); set_run_xor_stop_exec (0); } else { gtk_button_set_icon_name (GTK_BUTTON (btt_run_stop_model_exec), "media-playback-pause-symbolic"); set_run_xor_stop_exec (1); } }