diff --git a/include/ui.h b/include/ui.h index 51bb530..d50807e 100644 --- a/include/ui.h +++ b/include/ui.h @@ -25,16 +25,10 @@ #pragma once #include #include - #include "../include/base.h" // Gem-graph successive realizations -enum -{ - GG_2023, - GG_2024_05, - GG_2024_06 -}; +enum { GG_2023, GG_2024_05, GG_2024_06 }; #define W 1920 #define H 960 @@ -45,44 +39,28 @@ enum #define H_IMAGE_LOCAL H / 16 G_BEGIN_DECLS - #define GEM_GRAPH_CLIENT_TYPE_WINDOW (gem_graph_client_window_get_type()) - -G_DECLARE_FINAL_TYPE (GemGraphClientWindow, - gem_graph_client_window, - GEM_GRAPH_CLIENT, - WINDOW, - GtkApplicationWindow) - +G_DECLARE_FINAL_TYPE (GemGraphClientWindow, gem_graph_client_window, GEM_GRAPH_CLIENT, WINDOW, GtkApplicationWindow) G_END_DECLS G_BEGIN_DECLS - #define GEM_GRAPH_CLIENT_TYPE_APPLICATION (gem_graph_client_application_get_type()) - -G_DECLARE_FINAL_TYPE (GemGraphClientApplication, - gem_graph_client_application, - GEM_GRAPH_CLIENT, - APPLICATION, - GtkApplication) - -GemGraphClientApplication *gem_graph_client_application_new(const char *application_id, - GApplicationFlags flags); - +G_DECLARE_FINAL_TYPE (GemGraphClientApplication, gem_graph_client_application, GEM_GRAPH_CLIENT, APPLICATION, GtkApplication) +GemGraphClientApplication *gem_graph_client_application_new (const char *application_id, GApplicationFlags flags); G_END_DECLS - -void ui_enable_action(const char *name); - -void ui_disable_action(const char *name); +void ui_enable_action (const char *name); +void ui_disable_action (const char *name); void set_run_edit_mode(int prescribed_mode); int get_run_edit_mode(); -// -// Actions -// +// https://docs.gtk.org/gio/method.ActionMap.add_action_entries.html +// A function for creating multiple GSimpleAction instances and adding them to a GActionMap. +// @see application . gem_graph_client_application_init (GemGraphClientApplication *self) { +// g_action_map_add_action_entries (G_ACTION_MAP(self), app_actions, G_N_ELEMENTS(app_actions), self); ... + void on_quit_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); void on_about_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); void on_preferences_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); @@ -97,91 +75,64 @@ void on_closefile_action (GSimpleAction *action, GVariant *parameter, gpoint void on_savefile_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); void on_toast_close_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); - static const GActionEntry app_actions[] = { - { "quit", on_quit_action, NULL, NULL, NULL }, - { "about", on_about_action, NULL, NULL, NULL }, - { "preferences", on_preferences_action, NULL, NULL, NULL }, - { "togglerunedit", on_togglerunedit_action, NULL, NULL, NULL }, - { "togglerunstop", on_togglerunstop_action, NULL, NULL, NULL }, - { "togglesidebar", on_togglesidebar_action, NULL, NULL, NULL }, - { "editmode", on_editmode_action, NULL, NULL, NULL }, - { "runmode", on_runmode_action, NULL, NULL, NULL }, - { "presentmode", on_presentmode_action, NULL, NULL, NULL }, - { "openfile", on_openfile_action, NULL, NULL, NULL }, - { "closefile", on_closefile_action, NULL, NULL, NULL }, - { "savefile", on_savefile_action, NULL, NULL, NULL }, - { "toastclose", on_toast_close_action, NULL, NULL, NULL }, + { "quit", on_quit_action, NULL, NULL, NULL }, + { "about", on_about_action, NULL, NULL, NULL }, + { "preferences", on_preferences_action, NULL, NULL, NULL }, + { "togglerunedit", on_togglerunedit_action, NULL, NULL, NULL }, + { "togglerunstop", on_togglerunstop_action, NULL, NULL, NULL }, + { "togglesidebar", on_togglesidebar_action, NULL, NULL, NULL }, + { "editmode", on_editmode_action, NULL, NULL, NULL }, + { "runmode", on_runmode_action, NULL, NULL, NULL }, + { "presentmode", on_presentmode_action, NULL, NULL, NULL }, + { "openfile", on_openfile_action, NULL, NULL, NULL }, + { "closefile", on_closefile_action, NULL, NULL, NULL }, + { "savefile", on_savefile_action, NULL, NULL, NULL }, + { "toastclose", on_toast_close_action, NULL, NULL, NULL }, }; +/******************************************************************************/ +/* R E A D I N G M O D E L F I L E */ +/******************************************************************************/ +void on_openfile_response (GtkNativeDialog *native, int response, GemGraphClientWindow *self); +void ui_model_loading (GObject *source_object, GAsyncResult *result, GemGraphClientWindow *self); +void ui_debug_model_loading (GtkWindow *self, const char *file); -// -// Actions responses -// -void on_openfile_response(GtkNativeDialog *native, - int response, - GemGraphClientWindow *self); - -void ui_model_loading(GObject *source_object, - GAsyncResult *result, - GemGraphClientWindow *self); - -void ui_debug_model_loading (GtkWindow *self, const char *file); -// -// General events -// -void on_axis_value_change(GtkAdjustment *adjustment, gpointer data); - -gboolean on_glarea_render(GtkGLArea * area, GdkGLContext * context); - -void on_glarea_realize(GtkWidget *widget); - -void on_glarea_unrealize(GtkWidget *widget); - -void on_close_window(GtkWidget *widget); -/* - * A GtkBuilder holds a reference to all objects that it has constructed - * and drops these references when it is finalized. - * This finalization can cause the destruction of non-widget objects or widgets - * which are not contained in a toplevel window. - * For toplevel windows constructed by a builder, it is the responsibility of the user - * to call gtk_window_destroy() to get rid of them and all the widgets they contain. - * https://docs.gtk.org/gtk4/class.Builder.html - */ -void gtk_window_destroy (GtkWindow* window); // (in application.c) TODO ? - -// -// Tree-related events -// -void on_tree_expander_toggled(GtkExpander *expander, gpointer user_data); - -void on_tree_setup_factory(GtkSignalListItemFactory *factory, - GObject* object, gpointer user_data); - -void on_tree_bind_factory(GtkSignalListItemFactory *factory, GObject* object, - gpointer user_data); - -void on_tree_selection_changed(GtkSelectionModel* self, guint position, - guint n_items, gpointer user_data); - - -/* -------------------------------------------------------------------------- */ - -// -// Window primitives -// - +/******************************************************************************/ +/* W I N D O W P R I M I T I V E S */ +/******************************************************************************/ void ui_set_stack(int mode); - void ui_send_internal_notification(const char *message); void ui_close_internal_notification(void); void ui_toggle_runedit_button(); void ui_toggle_runstop_button(); void ui_toggle_sidebar(); -// -// Graphical stuff -// +/******************************************************************************/ +/* T R E E - R E L A T E D E V E N T S */ +/******************************************************************************/ +void on_tree_expander_toggled (GtkExpander *expander, gpointer user_data); +void on_tree_setup_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data); +void on_tree_bind_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data); +void on_tree_selection_changed (GtkSelectionModel* self, guint position, guint n_items, gpointer user_data); +void ui_create_tree (GtkWidget *target_widget); // TODO +/******************************************************************************/ +/* G R A P H I C I N I T - C L O S E */ +/******************************************************************************/ +gboolean on_glarea_render (GtkGLArea *area, GdkGLContext * context); +// TRUE to stop other handlers from being invoked for the event. +// FALSE to propagate the event further. +void on_glarea_realize (GtkWidget *widget); +void on_glarea_unrealize (GtkWidget *widget); +void on_axis_value_change (GtkAdjustment *adjustment, gpointer data); +void on_close_window (GtkWidget *widget); +void gtk_window_destroy (GtkWindow* window); // (in application.c) TODO ? + +/******************************************************************************/ +/* G R A P H I C S E S S I O N E V E N T S */ +/******************************************************************************/ + +// W A R N I N G <> le nom "stack" prête à confusion <> à renommer TODO /* * Creates GLArea and indexes it * @@ -190,8 +141,7 @@ void ui_toggle_sidebar(); * * @returns bool, true if success */ -bool ui_setup_glarea(int target_mode, GtkWidget *target_widget); - +bool ui_setup_glarea (int target_mode, GtkWidget *target_widget); /* * Look for stack entry and returns stack_id @@ -200,7 +150,7 @@ bool ui_setup_glarea(int target_mode, GtkWidget *target_widget); * * @returns stack_id */ -long ui_get_graphic_stack(void *container_widget); +long ui_get_graphic_stack (void *container_widget); /* * Look for stack entry and initializes OpenGL for it @@ -209,7 +159,7 @@ long ui_get_graphic_stack(void *container_widget); * * @returns bool, true if success */ -bool ui_init_graphic_stack(void *container_widget, GError *error_buffer); +bool ui_init_graphic_stack (void *container_widget, GError *error_buffer); /* * Look for stack entry and shutdowns OpenGL for it @@ -218,10 +168,9 @@ bool ui_init_graphic_stack(void *container_widget, GError *error_buffer); * * @returns bool, true if success */ -bool ui_shutdown_graphic_stack(void *container_widget, GError *error_buffer); +bool ui_shutdown_graphic_stack (void *container_widget, GError *error_buffer); - -void ui_clean_stack_index(void); +void ui_clean_stack_index (void); // Tout est dit (no comments required) /* * Look for stack entry and triggers OpenGL for drawing @@ -230,7 +179,7 @@ void ui_clean_stack_index(void); * * @returns bool, true if success */ -bool ui_render_stack(GtkWidget *container_widget); +bool ui_render_stack (GtkWidget *container_widget); /* * Look for every stack entry and shutdowns OpenGL for it @@ -239,7 +188,7 @@ bool ui_render_stack(GtkWidget *container_widget); * * @returns bool, true if success */ -void ui_shutdown_all_graphic_stacks(void); +void ui_shutdown_all_graphic_stacks (void); /* * Look for stack entry and triggers OpenGL for drawing @@ -248,9 +197,4 @@ void ui_shutdown_all_graphic_stacks(void); * * @returns bool, true if success */ -bool ui_update_axis_stack(GtkWidget *container_widget, int axis, int value); - - - -// XXX -void ui_create_tree (GtkWidget *target_widget); +bool ui_update_axis_stack (GtkWidget *container_widget, int axis, int value); diff --git a/src/ui/application.c b/src/ui/application.c index 26fee11..59d2a52 100644 --- a/src/ui/application.c +++ b/src/ui/application.c @@ -47,7 +47,7 @@ static void gem_graph_client_application_activate (GApplication *app) switch(COMMUTE) { // enum {...} in ui.h case GG_2023: // Launch with sidebar of gtk_notebook_append_pagef ui_toggle_sidebar(); - ui_set_stack (HOME_MODE); + // ui_set_stack (HOME_MODE); ui_debug_model_loading (window, "data/models/dimers random walk.xml"); // XXX the window closes when a leaf expander is clicked (Erreur de segmentation) break;