/* * Gem-graph OpenGL experiments * * Desc: User interface functions * * Copyright (C) 2023 Arthur Menges * Copyright (C) 2023 Adrien Bourmault * * 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 #include #include "../../include/base.h" #include "../../include/ui.h" /* -------------------------------------------------------------------------- */ static GemGraphClientWindow *window; /* -------------------------------------------------------------------------- */ struct _GemGraphClientWindow { GtkApplicationWindow parent_instance; /* Template widgets */ GtkHeaderBar *main_titlebar; GtkStack *main_stack; GtkStack *side_stack; GtkPaned *main_paned; GtkMenuButton *main_button_mode; GtkToggleButton *main_button_sidebar; GtkRevealer *toast_revealer; GtkToggleButton *toast_close_button; GtkLabel *toast_text; GtkBox *control_zone; GtkBox *run_glarea_box; GtkBox *edition_glarea_box; GtkBox *presentation_glarea_box; }; G_DEFINE_FINAL_TYPE (GemGraphClientWindow, gem_graph_client_window, GTK_TYPE_APPLICATION_WINDOW) static void gem_graph_client_window_class_init(GemGraphClientWindowClass *klass) { gchar *contents; gsize len; GError *err; GBytes *bytes; GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); if (g_file_get_contents("src/ui/gemgraph.ui", &contents, &len, &err) == FALSE) g_error("error reading gemgraph.ui: %s", err->message); bytes = g_bytes_new_take(contents, len); gtk_widget_class_set_template(GTK_WIDGET_CLASS(klass), bytes); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_titlebar); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_stack); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, side_stack); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_paned); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_button_mode); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_button_sidebar); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, toast_revealer); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, toast_close_button); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, toast_text); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, control_zone); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, run_glarea_box); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, edition_glarea_box); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, presentation_glarea_box); } static void gem_graph_client_window_init(GemGraphClientWindow *self) { gtk_widget_init_template(GTK_WIDGET(self)); window = self; // Launch with sidebar off ui_toggle_sidebar(); } /* -------------------------------------------------------------------------- */ void ui_set_stack(int mode) { //g_printerr("[debug] ui_set_stack()\n"); if (window->main_stack == NULL) { g_printerr("Can't find self->main_stack !\n"); return; } if (window->side_stack == NULL) { g_printerr("Can't find self->side_stack !\n"); return; } // Switch on the first letter of the mode, because switch is soooo simple :) switch(mode) { case EDIT_MODE: gtk_stack_set_visible_child_full(window->main_stack, "edition", GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_stack_set_visible_child_full(window->side_stack, "edition", GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_menu_button_set_icon_name(window->main_button_mode, "document-edit-symbolic"); ui_setup_glarea(EDIT_MODE, GTK_WIDGET(window->edition_glarea_box)); break; case RUN_MODE: gtk_stack_set_visible_child_full(window->main_stack, "run", GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_stack_set_visible_child_full(window->side_stack, "run", GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_menu_button_set_icon_name(window->main_button_mode, "system-run-symbolic"); ui_setup_glarea(RUN_MODE, GTK_WIDGET(window->run_glarea_box)); break; case PRESENTATION_MODE: gtk_stack_set_visible_child_full(window->main_stack, "presentation", GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_stack_set_visible_child_full(window->side_stack, "presentation", GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_menu_button_set_icon_name(window->main_button_mode, "x-office-presentation-symbolic"); ui_setup_glarea(PRESENTATION_MODE, GTK_WIDGET(window->presentation_glarea_box)); break; case HOME_MODE: gtk_stack_set_visible_child_full(window->main_stack, "home", GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_stack_set_visible_child_full(window->side_stack, "home", GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_paned_set_position(window->main_paned, 0); gtk_menu_button_set_icon_name(window->main_button_mode, "user-home-symbolic"); break; default: break; } } void ui_send_internal_notification(const char *message) { 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); } void ui_close_internal_notification(void) { 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_revealer_set_reveal_child(window->toast_revealer, false); } void ui_toggle_sidebar(void) { int position = gtk_paned_get_position(window->main_paned); if (position != 0) { gtk_paned_set_position(window->main_paned, 0); } else { gtk_paned_set_position(window->main_paned, 400); } }