gem-graph-client/include/util.h

155 lines
6.3 KiB
C

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Gem-graph client *
* Utilities header *
* *
* Copyright © 2021 Libre en Communs <contact@a-lec.org> *
* Copyright © 2024 Jean Sirmai <jean@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 publishedby 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 <stdbool.h>
#include <stddef.h>
#include <gtk-4.0/gtk/gtk.h>
#include "../include/fsm.h"
char *util_read_file (char *filename);
typedef struct pile {int value; struct pile *prev;} pile; // structure d'un élément
void util_pile_clear (pile **); // vide toute la pile
void util_pile_view (pile *); // affiche la pile en commençant par le sommet
int util_pile_push (pile **, int); // ajoute une valeur sur la pile
int util_pile_pop (pile **); // retire la dernière valeur empilée
int util_pile_length (pile *p); // renvoie le nombre d'éléments de la pile
//------------------------------------------------------------------------------
typedef struct elem {int value; struct elem *prev; struct elem *next;} elem;
typedef struct {elem *first; elem *last;} dblist; // structure d'accès à la liste
void util_list_2x2_init (dblist *l); // initialisation
void util_list_2x2_clear (dblist *l); // vide toute la liste
void util_list_2x2_view (dblist l); // affiche les valeurs de toute la liste
int util_list_2x2_push_back (dblist *l, int val); // ajoute une valeur en fin de liste
int util_list_2x2_push_front (dblist *l, int val); // ajoute une valeur en début de liste
int util_list_2x2_pop_back (dblist *l); // retire une valeur en fin de liste
int util_list_2x2_pop_front (dblist *l); // retire une valeur en début de liste
int util_list_2x2_length (dblist l); // renvoie le nombre d'éléments de la liste
//------------------------------------------------------------------------------
typedef struct slist {int value; struct slist *suiv;} slist ;
void util_sorted_list_clear (slist **sl); // vide toute la liste
void util_sorted_list_view (slist *sl); // affiche toute la liste
int util_sorted_list_insert (slist **sl, int val); // insertion d'un élément selon son rang
int util_sorted_list_pop (slist **sl); // retire la dernière valeur de la liste
int util_sorted_list_length (slist *sl); // renvoie le nombre d'éléments de la liste
//------------------------------------------------------------------------------
void util_trigger_test(); // def: util/tests.c calls: ...
void util_pile_test(); // called in fsm/measure.c
void util_double_list_test(); // " "
void util_sorted_list_test(); // " "
//------------------------------------------------------------------------------
/*
* Look for stack entry and returns stack_id
*
* @params container_widget, generally the GtkBox that contains the GLArea
*
* @returns stack_id
*/
long util_gl_get_stack(void *container_widget);
/*
* Look for stack entry and returns stack_id
*
* @params container_widget, generally the GtkBox that contains the GLArea
*
* @returns stack_id
*/
long util_gl_is_util_ready(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 util_gl_init_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 util_gl_shutdown_stack(void *container_widget, GError *error_buffer);
void util_gl_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 util_gl_render_stack(GtkWidget *container_widget);
/*
* 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 util_gl_update_axis(GtkWidget *container_widget, int axis, int value);
/*
* Look for every stack entry and shutdowns OpenGL for it
*
* @params void
*
* @returns bool, true if success
*/
void util_gl_shutdown_all_stacks(void);
/*
* Creates a slider widget
*
* @params axis, meaning which axis we're building (for label)
*
* @returns GtkWidget*, pointer to the new widget
*/
GtkWidget *create_axis_slider(int axis);
/*
* Creates GLArea and indexes it
*
* @params target_mode, meaning which util_gl_stack we're on
* target_widget, meaning the box that will host the GLArea
*
* @returns bool, true if success
*/
bool util_gl_setup_glarea(int target_mode, GtkWidget *target_widget);