/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Gem-graph client * * * * Signals * * * * Copyright © 2021 Libre en Communs * * Copyright © 2021 Adrien Bourmault * * Copyright © 2021 Jean Sirmai * * * * This file is part of Gem-graph. * * * * This program is free software: you can redistribute it and/or modify it * * under the terms of the GNU Affero General Public License * * as published by the Free Software Foundation, * * either version 3 of the License, * * or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; * * without even the implied warranty of MERCHANTABILITY * * or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public License * * along with this program. If not, see . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "../include/fsm.h" #include "../include/signal.h" #include "../include/widget.h" #include "../include/graphics.h" static void on_auto_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 app->toast_overlay !\n"); return; } if (window->toast_text == NULL) { g_printerr("Can't find app->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 */ /******************************************************************************/ static 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) {...} do something ? TODO Check ! 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); } void on_setup_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){ GtkWidget* expander = gtk_expander_new (NULL); gtk_list_item_set_child (GTK_LIST_ITEM (object), expander); if (0) printf("[on_setup_user_tree_factory] here is an expander\n"); } /******************************************************************************/ /* 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) { on_auto_notification("An OpenGL error occured !"); return false; } if (graphics_render_stack(gtk_widget_get_parent(GTK_WIDGET(area))) == false) { on_auto_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) { on_auto_notification("An OpenGL error occured !"); return; } // Link graphical stack to widget if (graphics_init_graphics_stack(gtk_widget_get_parent(widget), internal_error) == false) { on_auto_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) { on_auto_notification("An OpenGL error occured !"); return; } // Destroy graphic stack if (graphics_shutdown_graphics_stack(gtk_widget_get_parent(widget), internal_error) == false) { on_auto_notification( "Failed to shutdown the graphic stack !"); return; } } void on_axis_value_change(GtkAdjustment *adjustment, gpointer data) { GtkWidget *slider = gtk_widget_get_parent(GTK_WIDGET(data)); GtkWidget *container_widget = gtk_widget_get_parent(GTK_WIDGET(slider)); const gchar *label_text = gtk_label_get_label(GTK_LABEL(data)); // THANKS ASCIIIII/Unicode/Whateverrr ! int axis = label_text[0] - 'X'; g_assert(axis >= 0 && axis < N_AXIS); /* Update the rotation angle */ graphics_update_axis_stack(container_widget, axis, gtk_adjustment_get_value(adjustment)); /* Update the contents of the GL drawing area */ } /******************************************************************************/ /* D I A L O G W I D G E T S */ /******************************************************************************/ void on_save_current_model_before_editing (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data) { gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); printf ("signal.c - SAVE_CURRENT_MODEL_BEFORE_EDITING\n"); } void on_discard_current_model_before_editing (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data) { gtk_window_close (GTK_WINDOW (data)); printf ("signal.c - DISCARD_CURRENT_MODEL_AND_START_EDITING\n"); } void on_write_current_model (GtkWidget *btt_WRITE_CURRENT_MODEL, gpointer data) { gtk_window_close (GTK_WINDOW (data)); printf ("signal.c - WRITE_CURRENT_MODEL\n"); } /******************************************************************************/ /* S T A T E W I D G E T */ /******************************************************************************/ static void switch_state_rules_data() { switch (fsm_get_state_rules_data()) { case (STATE) : gtk_window_set_child (GTK_WINDOW (widget_get_main_window ()), GTK_WIDGET (widget_get_state_page())); break; case (RULES) : gtk_window_set_child (GTK_WINDOW (widget_get_main_window ()), GTK_WIDGET (widget_get_rules_page())); break; case (DATA) : gtk_window_set_child (GTK_WINDOW (widget_get_main_window ()), GTK_WIDGET (widget_get_stock_page())); break; default : printf("default in signal.on_toggle_state_rule_data()\n"); } } void on_toggle_exec_edit (GtkWidget *toggled_button, gpointer user_data) { if (fsm_get_exec_edit ()) { gtk_button_set_icon_name (GTK_BUTTON (toggled_button), "power-profile-balanced-rtl-symbolic"); fsm_set_exec_edit (EXEC); } else { gtk_button_set_icon_name (GTK_BUTTON (toggled_button), "text-editor-symbolic"); // https://docs.gtk.org/gtk4/class.Window.html TODO 2024-06-30 // gtk_window_present (GTK_WINDOW (widget_get_dialog_window())); // works once only ! fsm_set_exec_edit (EDIT); } switch_state_rules_data(); } // TODO Il doit y avoir plus élégant,... void on_toggle_state_rules_data (GtkWidget *toggled_button, gpointer user_data) { const char *toggled_button_name = gtk_check_button_get_label (GTK_CHECK_BUTTON (toggled_button)); int is_active = gtk_check_button_get_active (GTK_CHECK_BUTTON (toggled_button)); if (! strcmp (toggled_button_name, "state")) { fsm_set_state_rules_data (STATE); } if (! strcmp (toggled_button_name, "rules")) { fsm_set_state_rules_data (RULES); } if (! strcmp (toggled_button_name, "data analysis")) { fsm_set_state_rules_data (DATA); } if (is_active) { switch_state_rules_data(); } } void on_objects_box_do_reset (GtkWidget *btt_reset, GtkScrollbar *reset_scrollbar) { GtkAdjustment *adj_obj = gtk_scrollbar_get_adjustment (reset_scrollbar); fsm_reset_all_objects_transparencies_at_value (gtk_adjustment_get_value (adj_obj)); } void on_situations_box_do_reset (GtkWidget *btt_reset, GtkScrollbar *reset_scrollbar) { GtkAdjustment *adj_situ = gtk_scrollbar_get_adjustment (reset_scrollbar); fsm_reset_all_situations_transparencies_at_value (gtk_adjustment_get_value (adj_situ)); } /******************************************************************************/ /* M A I N W I N D O W H E A D E R W I D G E T S */ /******************************************************************************/ void on_clicked_search (GtkWidget *btt_menu, gpointer list_box) { // next line presents the text_window and works only once.\nIt should present a menu.\n"); // TODO gtk_window_present (GTK_WINDOW (widget_get_text_window())); } void on_clicked_home (GtkWidget *btt_reset, gpointer data) { printf ("signal.on_clicked_HOME() button presents the dialog_window\ ( :- ) but it works only once.\n"); // TODO gtk_window_present (GTK_WINDOW (widget_get_dialog_window())); } /******************************************************************************/ /* M E N U */ /******************************************************************************/