From 4b6383bf0c63e89d01902f4256366fc6f13bb012 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 24 Jan 2023 21:06:05 +0100 Subject: [PATCH] WIP: obtained a window --- include/ui.h | 32 --------- src/graphics.c | 2 +- src/main.c | 17 +++-- src/ui.c | 191 ------------------------------------------------- ui/gemgraph.ui | 2 +- 5 files changed, 15 insertions(+), 229 deletions(-) delete mode 100644 include/ui.h delete mode 100644 src/ui.c diff --git a/include/ui.h b/include/ui.h deleted file mode 100644 index d6725f7..0000000 --- a/include/ui.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Gem-graph OpenGL experiments - * - * Desc: User interface header - * - * 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 . - */ - -#pragma once -#include -#include - -extern float rotation_angles[N_AXIS]; - -void on_activate(GtkApplication *app, gpointer user_data); - diff --git a/src/graphics.c b/src/graphics.c index a42594a..c636838 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -33,7 +33,7 @@ #include #include "../include/base.h" -#include "../include/ui.h" +#include "../include/window.h" #define VERTEX_SHADER_FILE "data/shader.vert" #define FRAG_SHADER_FILE "data/shader.frag" diff --git a/src/main.c b/src/main.c index 4884235..fa25e32 100644 --- a/src/main.c +++ b/src/main.c @@ -26,17 +26,26 @@ #include #include "../include/base.h" -#include "../include/ui.h" +#include "../include/window.h" +#include "../include/application.h" /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { - GtkApplication *app; + g_autoptr(GemGraphClientApplication) app = NULL; int res; - app = gtk_application_new(NULL, G_APPLICATION_DEFAULT_FLAGS); - g_signal_connect(app, "activate", G_CALLBACK(on_activate), NULL); + // bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + // bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + // textdomain (GETTEXT_PACKAGE); + + //app = gtk_application_new(NULL, G_APPLICATION_DEFAULT_FLAGS); + app = gem_graph_client_application_new("org.alec.gemgraph", + G_APPLICATION_DEFAULT_FLAGS); + + //g_signal_connect(app, "activate", G_CALLBACK(on_activate), NULL); + res = g_application_run(G_APPLICATION(app), argc, argv); g_object_unref(app); diff --git a/src/ui.c b/src/ui.c deleted file mode 100644 index 71565b6..0000000 --- a/src/ui.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * 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/graphics.h" - -/* -------------------------------------------------------------------------- */ - -float rotation_angles[N_AXIS] = { 0.0 }; // Rotation angles on each axis - -static GtkWidget *gl_area = NULL; - -/* -------------------------------------------------------------------------- */ - -static void on_axis_value_change(GtkAdjustment *adjustment, gpointer data); - -static inline GtkWidget *create_axis_slider(int axis) -{ - GtkWidget *box, *label, *slider; - GtkAdjustment *adj; - const char *text; - - box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - - switch (axis) { - case X_AXIS: - text = "X"; - break; - - case Y_AXIS: - text = "Y"; - break; - - case Z_AXIS: - text = "Z"; - break; - - default: - g_assert_not_reached(); - } - - label = gtk_label_new(text); - gtk_box_append(GTK_BOX(box), label); - gtk_widget_show(label); - - adj = gtk_adjustment_new(0.0, 0.0, 360.0, 1.0, 12.0, 0.0); - g_signal_connect(adj, "value-changed", - G_CALLBACK(on_axis_value_change), - GINT_TO_POINTER(axis)); - slider = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, adj); - gtk_box_append(GTK_BOX(box), slider); - gtk_widget_set_hexpand(slider, TRUE); - gtk_widget_show(slider); - - gtk_widget_show(box); - - return box; -} - -/* -------------------------------------------------------------------------- */ - -static void on_axis_value_change(GtkAdjustment *adjustment, gpointer data) -{ - int axis = GPOINTER_TO_INT(data); - - g_assert(axis >= 0 && axis < N_AXIS); - - /* Update the rotation angle */ - rotation_angles[axis] = gtk_adjustment_get_value(adjustment); - - /* Update the contents of the GL drawing area */ - gtk_widget_queue_draw(gl_area); -} - -static gboolean on_render(GtkGLArea * area, GdkGLContext * context) -{ - if(gtk_gl_area_get_error(area) != NULL) - return FALSE; - - graphicsDraw(); - - return TRUE; -} - - -/* We need to set up our state when we realize the GtkGLArea widget */ -static void on_realize(GtkWidget *widget) -{ - gtk_gl_area_make_current(GTK_GL_AREA(widget)); - - if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL) - return; - - graphicsInitGL(); -} - -/* We should tear down the state when unrealizing */ -static void on_unrealize(GtkWidget *widget) -{ - gtk_gl_area_make_current(GTK_GL_AREA(widget)); - - if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL) - return; - - graphicsShutdownGL(); -} - -static void on_close_window(GtkWidget *widget) -{ - /* Reset the state */ - gl_area = NULL; - - rotation_angles[X_AXIS] = 0.0; - rotation_angles[Y_AXIS] = 0.0; - rotation_angles[Z_AXIS] = 0.0; -} - -void on_activate(GtkApplication *app, gpointer user_data) -{ - GtkWidget *window, *box, *button, *controls; - int i, minor=4, major=0; - - window = gtk_application_window_new(app); - gtk_window_set_default_size(GTK_WINDOW(window), 400, 600); - gtk_window_set_title(GTK_WINDOW(window), "GemGL (essais pour Gem-graph en OpenGL)"); - g_signal_connect(window, "destroy", G_CALLBACK(on_close_window), NULL); - - box = gtk_box_new(GTK_ORIENTATION_VERTICAL, FALSE); - gtk_widget_set_margin_start(box, 12); - gtk_widget_set_margin_end(box, 12); - gtk_widget_set_margin_top(box, 12); - gtk_widget_set_margin_bottom(box, 12); - gtk_box_set_spacing(GTK_BOX(box), 6); - gtk_window_set_child(GTK_WINDOW(window), box); - - gl_area = gtk_gl_area_new(); - gtk_gl_area_set_required_version( GTK_GL_AREA(gl_area), minor, major); - gtk_gl_area_get_required_version( GTK_GL_AREA(gl_area), &minor, &major); - gtk_widget_set_hexpand(gl_area, TRUE); - gtk_widget_set_vexpand(gl_area, TRUE); - gtk_widget_set_size_request(gl_area, 100, 200); - gtk_box_append(GTK_BOX(box), gl_area); - - // We need to initialize and free GL resources, so we use - // the realize and unrealize signals on the widget - // - g_signal_connect(gl_area, "realize", G_CALLBACK(on_realize), NULL); - g_signal_connect(gl_area, "unrealize", G_CALLBACK(on_unrealize), NULL); - - // The main "draw" call for GtkGLArea - g_signal_connect(gl_area, "render", G_CALLBACK(on_render), NULL); - - controls = gtk_box_new(GTK_ORIENTATION_VERTICAL, FALSE); - gtk_box_append(GTK_BOX(box), controls); - gtk_widget_set_hexpand(controls, TRUE); - - for(i = 0; i < N_AXIS; i++) - gtk_box_append(GTK_BOX(controls), create_axis_slider(i)); - - button = gtk_button_new_with_label("Fermer"); - gtk_widget_set_hexpand(button, TRUE); - gtk_box_append(GTK_BOX(box), button); - g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_window_destroy), window); - - gtk_widget_show(window); -} diff --git a/ui/gemgraph.ui b/ui/gemgraph.ui index f3189e3..555fa73 100644 --- a/ui/gemgraph.ui +++ b/ui/gemgraph.ui @@ -4,7 +4,7 @@ -