gem-graph-client/include/ui.h

250 lines
7.1 KiB
C
Raw Normal View History

2023-01-24 21:06:32 +01:00
/*
* 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
2023-01-25 12:24:52 +01:00
#include <unistd.h>
#include <gtk-4.0/gtk/gtk.h>
2023-01-24 21:06:32 +01:00
2023-01-25 12:24:52 +01:00
#include "../include/base.h"
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
2023-01-24 21:06:32 +01:00
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
2023-01-25 15:25:04 +01:00
2023-01-26 01:38:51 +01:00
void ui_enable_action(const char *name);
void ui_disable_action(const char *name);
2023-01-25 15:25:04 +01:00
//
// Actions
//
void on_about_action(GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void on_quit_action(GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void on_preferences_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);
2023-01-25 23:14:55 +01:00
void on_toast_close_action(GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
2023-01-25 15:25:04 +01:00
static const GActionEntry app_actions[] = {
2023-01-25 18:48:01 +01:00
{ "quit", on_quit_action, NULL, NULL, NULL },
{ "about", on_about_action, NULL, NULL, NULL },
{ "preferences", on_preferences_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 },
2023-01-25 23:14:55 +01:00
{ "toastclose", on_toast_close_action, NULL, NULL, NULL },
2023-01-25 15:25:04 +01:00
};
2023-01-25 18:48:01 +01:00
//
// Actions responses
//
void on_openfile_response(GtkNativeDialog *native,
int response,
GemGraphClientWindow *self);
void ui_model_loading(GObject *source_object,
2023-01-25 18:48:01 +01:00
GAsyncResult *result,
GemGraphClientWindow *self);
2023-01-26 01:38:51 +01:00
//
// General events
//
void on_axis_value_change(GtkAdjustment *adjustment, gpointer data);
2023-12-20 13:34:44 +01:00
gboolean on_glarea_render(GtkGLArea * area, GdkGLContext * context);
2023-01-26 01:38:51 +01:00
2023-12-20 13:34:44 +01:00
void on_glarea_realize(GtkWidget *widget);
2023-01-26 01:38:51 +01:00
2023-12-20 13:34:44 +01:00
void on_glarea_unrealize(GtkWidget *widget);
2023-01-26 01:38:51 +01:00
void on_close_window(GtkWidget *widget);
//
// 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);
2023-01-25 18:48:01 +01:00
/* -------------------------------------------------------------------------- */
//
// Window primitives
//
void ui_set_stack(int mode);
2023-01-25 18:48:01 +01:00
2023-01-25 20:20:25 +01:00
void ui_send_internal_notification(const char *message);
2023-01-25 23:14:55 +01:00
void ui_close_internal_notification(void);
2023-01-26 01:38:51 +01:00
void ui_toggle_sidebar();
2023-01-26 01:56:54 +01:00
2023-12-20 13:34:44 +01:00
//
// Graphical stuff
//
/*
* 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
2023-12-20 13:34:44 +01:00
*/
bool ui_setup_glarea(int target_mode, GtkWidget *target_widget);
2023-12-20 13:34:44 +01:00
/*
* 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);
2023-12-20 13:34:44 +01:00
/*
* 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);
2023-12-20 13:34:44 +01:00
void ui_clean_stack_index(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_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);
// XXX
void ui_create_tree (GtkWidget *target_widget);