250 lines
12 KiB
C
250 lines
12 KiB
C
/*
|
||
* Gem-graph OpenGL experiments
|
||
*
|
||
* Desc: User interface header
|
||
*
|
||
* Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org>
|
||
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
|
||
*
|
||
* 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 <http://www.gnu.org/licenses/>.
|
||
*/
|
||
|
||
#pragma once
|
||
#include <unistd.h>
|
||
#include <gtk-4.0/gtk/gtk.h>
|
||
#include "../include/base.h"
|
||
|
||
// Gem-graph successive realizations
|
||
enum { GG_2023, GG_2024_05, GG_2024_06 };
|
||
|
||
#define W 1920
|
||
#define H 960
|
||
#define W_IMAGE W - 320
|
||
#define H_IMAGE H - 126
|
||
#define H_STYLES_PANE 30
|
||
#define W_IMAGE_LOCAL W / 16
|
||
#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_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_END_DECLS
|
||
|
||
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();
|
||
|
||
|
||
// 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);
|
||
void on_togglerunedit_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
|
||
void on_togglerunstop_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
|
||
void on_togglesidebar_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
|
||
void on_editmode_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
|
||
void on_runmode_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
|
||
void on_presentmode_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
|
||
void on_openfile_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
|
||
void on_closefile_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
|
||
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 },
|
||
};
|
||
/******************************************************************************/
|
||
/* 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);
|
||
|
||
/******************************************************************************/
|
||
/* 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();
|
||
|
||
/******************************************************************************/
|
||
/* 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); // in views.c 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
|
||
*
|
||
* @params target_mode, meaning which ui_stack we're on
|
||
* target_widget, meaning the box that will host the GLArea
|
||
*
|
||
* @returns bool, true if success
|
||
*/
|
||
bool ui_setup_glarea (int target_mode, GtkWidget *target_widget);
|
||
|
||
/*
|
||
* Look for stack entry and returns stack_id
|
||
*
|
||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||
*
|
||
* @returns stack_id
|
||
*/
|
||
long ui_get_graphic_stack (void *container_widget);
|
||
|
||
/*
|
||
* Look for stack entry and initializes OpenGL for it
|
||
*
|
||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||
*
|
||
* @returns bool, true if success
|
||
*/
|
||
bool ui_init_graphic_stack (void *container_widget, GError *error_buffer);
|
||
|
||
/*
|
||
* Look for stack entry and shutdowns OpenGL for it
|
||
*
|
||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||
*
|
||
* @returns bool, true if success
|
||
*/
|
||
bool ui_shutdown_graphic_stack (void *container_widget, GError *error_buffer);
|
||
|
||
void ui_clean_stack_index (void); // Tout est dit (no comments required)
|
||
|
||
/*
|
||
* Look for stack entry and triggers OpenGL for drawing
|
||
*
|
||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||
*
|
||
* @returns bool, true if success
|
||
*/
|
||
bool ui_render_stack (GtkWidget *container_widget);
|
||
|
||
/*
|
||
* Look for every stack entry and shutdowns OpenGL for it
|
||
*
|
||
* @params void
|
||
*
|
||
* @returns bool, true if success
|
||
*/
|
||
void ui_shutdown_all_graphic_stacks (void);
|
||
|
||
/*
|
||
* Look for stack entry and triggers OpenGL for drawing
|
||
*
|
||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||
*
|
||
* @returns bool, true if success
|
||
*/
|
||
bool ui_update_axis_stack (GtkWidget *container_widget, int axis, int value);
|
||
|
||
|
||
|
||
/*
|
||
struct TreeNode_t *create_tree_node (const gchar* text)
|
||
{
|
||
struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t));
|
||
node->text = g_strdup(text);
|
||
node->child = NULL;
|
||
return node;
|
||
}
|
||
|
||
// pourquoi je n'arrive pas à le déplacer ici ?
|
||
// l'initialisation de « struct TreeNode_t * » depuis « int »
|
||
// transforme un entier en pointeur sans transtypage
|
||
|
||
static void let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root) {
|
||
struct TreeNode_t *a = create_tree_node("We, the people");add_child_node(tree_root, a);
|
||
struct TreeNode_t *b = create_tree_node("in Order to"); add_child_node(tree_root, b);
|
||
struct TreeNode_t *c = create_tree_node("do establish"); add_child_node(tree_root, c);
|
||
struct TreeNode_t *aa = create_tree_node("aware of"); add_child_node(a, aa);
|
||
struct TreeNode_t *aaa = create_tree_node("our rights"); add_child_node(aa, aaa);
|
||
struct TreeNode_t *aab = create_tree_node("our duties"); add_child_node(aa, aab);
|
||
struct TreeNode_t *aaaa = create_tree_node("read"); add_child_node(aaa, aaaa);
|
||
struct TreeNode_t *aaab = create_tree_node("write"); add_child_node(aaa, aaab);
|
||
struct TreeNode_t *aaac = create_tree_node("copy"); add_child_node(aaa, aaac);
|
||
struct TreeNode_t *aaad = create_tree_node("edit"); add_child_node(aaa, aaad);
|
||
struct TreeNode_t *aaaba= create_tree_node("code"); add_child_node(aaab, aaaba);
|
||
struct TreeNode_t *aaabb= create_tree_node("language"); add_child_node(aaab, aaabb);
|
||
struct TreeNode_t *aaabc= create_tree_node("any art..."); add_child_node(aaab, aaabc);
|
||
struct TreeNode_t *aaadb= create_tree_node("publish"); add_child_node(aaac, aaadb);
|
||
struct TreeNode_t *aaada= create_tree_node("create"); add_child_node(aaad, aaada);
|
||
struct TreeNode_t *aaba = create_tree_node("learn"); add_child_node(aab, aaba);
|
||
struct TreeNode_t *aabb = create_tree_node("help"); add_child_node(aab, aabb);
|
||
struct TreeNode_t *ba = create_tree_node("promote"); add_child_node(b, ba);
|
||
struct TreeNode_t *bb = create_tree_node("individual"); add_child_node(b, bb);
|
||
struct TreeNode_t *bc = create_tree_node("and common"); add_child_node(b, bc);
|
||
struct TreeNode_t *bca = create_tree_node("education"); add_child_node(bc, bca);
|
||
struct TreeNode_t *bcb = create_tree_node("mutual"); add_child_node(bc, bcb);
|
||
struct TreeNode_t *bcc = create_tree_node("support"); add_child_node(bc, bcc);
|
||
struct TreeNode_t *bcd = create_tree_node("health"); add_child_node(bc, bcd);
|
||
struct TreeNode_t *bcda = create_tree_node("mental"); add_child_node(bcd, bcda);
|
||
struct TreeNode_t *bcdb = create_tree_node("physical"); add_child_node(bcd, bcdb);
|
||
struct TreeNode_t *ca = create_tree_node("free"); add_child_node(c, ca);
|
||
struct TreeNode_t *cb = create_tree_node("code"); add_child_node(c, cb);
|
||
struct TreeNode_t *cc = create_tree_node("access"); add_child_node(c, cc);
|
||
}
|
||
*/
|
||
|