gem-graph-client/widgets.c

244 lines
11 KiB
C

#include <stdio.h>
#include <gtk-4.0/gtk/gtk.h>
#include "cold.h"
#include "widgets.h"
#include "pages.h"
GtkWidget *get_test_image(){
GtkWidget *image;
// forget > GTK_WIDGET(get_scrolled_gl_area());
// Use GtkImage if you want to display a fixed-size icon
// and GtkPicture if you want to display a (maybe) scaled picture.
image = gtk_image_new_from_file("/home/jean/01/Gtk4/Getting_Started_with_GTK/image aXoris.png");
image = gtk_picture_new_for_filename ("/home/jean/01/Gtk4/Getting_Started_with_GTK/image gg sketch.png");
image = gtk_picture_new_for_filename ("/home/jean/01/Gtk4/Getting_Started_with_GTK/image E coli (Goodsell).png");
return image;
}
GtkWidget *get_scroll_speed(){
GtkAdjustment *speed_adjust = gtk_adjustment_new (0, 0, 100, 1, 0, 0);
GtkWidget *scroll_speed = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, speed_adjust);
return scroll_speed;
}
// TODO cliquer sur "RUN" --> affiche "STOP" (et inversement)
GtkBox *get_RUN_STOP_box(){
GtkBox *RUN_STOP_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2)); // spacing = 2
GtkWidget *RUN_Label = GTK_WIDGET (gtk_label_new (NULL)); // "RUN"));
const char *str = " RUN-STOP";
const char *format = "<span style=\"oblique\">\%s</span>"; // ^c^v no more...
char *markup;
markup = g_markup_printf_escaped (format, str);
gtk_label_set_markup (GTK_LABEL (RUN_Label), markup); // Sets the labels text and attributes from markup.
g_free (markup);
gtk_label_set_max_width_chars (GTK_LABEL(RUN_Label), 12);
gtk_label_set_wrap (GTK_LABEL(RUN_Label), TRUE);
gtk_label_set_xalign (GTK_LABEL(RUN_Label), 0.5); // xalign value, between 0 and 1
gtk_label_set_yalign (GTK_LABEL(RUN_Label), 0.5);
gtk_label_set_selectable (GTK_LABEL(RUN_Label), FALSE); // default = FALSE
gtk_label_set_single_line_mode (GTK_LABEL(RUN_Label), TRUE); // default = TRUE
//
gtk_box_append (RUN_STOP_box, RUN_Label);
return RUN_STOP_box;
}
GtkBox *get_STEP_by_STEP_box(){
GtkBox *STEP_by_STEP_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
GtkWidget *STEP_by_STEP_Label = GTK_WIDGET (gtk_label_new ("ONE\nSTEP"));
gtk_box_append (STEP_by_STEP_box, STEP_by_STEP_Label);
return STEP_by_STEP_box;
}
GtkBox *get_ZOOM_box(){
GtkBox *ZOOM_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
GtkWidget *ZOOM_Label = GTK_WIDGET (gtk_label_new ("ZOOM\n ---\n(space\nstruct.)"));
gtk_box_append (ZOOM_box, ZOOM_Label);
return ZOOM_box;
}
GtkBox *get_edit_TOOL_box(){
GtkBox *TOOL_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
GtkWidget *ZOOM_Label = GTK_WIDGET (gtk_label_new ("TOOLS\n ---\n(space\nstruct.)"));
gtk_box_append (TOOL_box, ZOOM_Label);
return TOOL_box;
}
GtkBox *get_XYZ_box(){
GtkBox *XYZ_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2)); // spacing = 2
// GtkWidget *scale_X = gtk_scale_button_new (0, 360, 10, NULL); < à étudier
// (double min, double max, double step, const char** icons)
GtkAdjustment *X_adjust = gtk_adjustment_new (0, 0, 380, 1, 0, 0);
GtkAdjustment *Y_adjust = gtk_adjustment_new (0, 0, 380, 1, 0, 0);
GtkAdjustment *Z_adjust = gtk_adjustment_new (0, 0, 380, 1, 0, 0);
GtkWidget *scroll_X = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, X_adjust);
GtkWidget *scroll_Y = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, Y_adjust);
GtkWidget *scroll_Z = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, Z_adjust);
gtk_box_append (XYZ_box, scroll_X);
gtk_box_append (XYZ_box, scroll_Y);
gtk_box_append (XYZ_box, scroll_Z);
// gtk_box_set_baseline_position (XYZ_box, GTK_BASELINE_POSITION_BOTTOM);
return XYZ_box;
}
GtkBox *get_ELAPSED_TIME_box(){
GtkBox *ELAPSED_TIME_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2));
// GtkProgressBar *get_simulation_time_extent_buffer(){
GtkProgressBar *buffer = GTK_PROGRESS_BAR (gtk_progress_bar_new ());
gtk_progress_bar_set_text (buffer, "<--- [buffer] (simulation extensive time) --->");
gtk_progress_bar_set_show_text (buffer, TRUE);
gtk_widget_set_size_request (GTK_WIDGET (buffer), W_IMAGE, 40);
gtk_box_append (ELAPSED_TIME_box, GTK_WIDGET(buffer));
return ELAPSED_TIME_box;
}
GtkProgressBar *get_simulation_time_extent_buffer(){
GtkProgressBar *buffer = GTK_PROGRESS_BAR (gtk_progress_bar_new ());
gtk_progress_bar_set_text (buffer, "<--- [buffer] (simulation extensive time) --->");
gtk_progress_bar_set_show_text (buffer, TRUE);
gtk_widget_set_size_request (GTK_WIDGET (buffer), W_IMAGE, 40);
return buffer;
}
GtkBox *get_objects_box(){
GtkBox *objects_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
gtk_box_append (objects_box, GTK_WIDGET (gtk_label_new (" membrane ")));
gtk_box_append (objects_box, GTK_WIDGET (gtk_label_new (" co-enzyme A ")));
gtk_box_append (objects_box, GTK_WIDGET (gtk_label_new (" ribosome ")));
gtk_box_append (objects_box, GTK_WIDGET (gtk_label_new (" cytochrome C ")));
gtk_box_append (objects_box, GTK_WIDGET (gtk_label_new (" ATP synthase ")));
gtk_box_append (objects_box, GTK_WIDGET (gtk_label_new (" chromosome ")));
return objects_box;
}
GtkBox *get_situations_box(){
GtkBox *situations_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
gtk_box_append (situations_box, GTK_WIDGET (gtk_label_new (" transcription ")));
gtk_box_append (situations_box, GTK_WIDGET (gtk_label_new (" promotion opéron lactose ")));
gtk_box_append (situations_box, GTK_WIDGET (gtk_label_new (" translation ")));
gtk_box_append (situations_box, GTK_WIDGET (gtk_label_new (" transport Na/K ")));
gtk_box_append (situations_box, GTK_WIDGET (gtk_label_new (" ubiquitination ")));
gtk_box_append (situations_box, GTK_WIDGET (gtk_label_new (" rotation du moteur flagellaire ")));
return situations_box;
}
static GtkWidget *get_frame_objects(){
GtkWidget *frame_objects = gtk_frame_new (" Objects"); // defines each class of object transparence
gtk_widget_set_size_request (frame_objects, 0, H_STYLES_PANE); // < utile seulement pour la largeur min/max
gtk_frame_set_child (GTK_FRAME (frame_objects), GTK_WIDGET (get_objects_box()));
return frame_objects;
}
static GtkWidget *get_frame_situations(){
GtkWidget *frame_situations = gtk_frame_new (" Situations"); // facilitates each situation identification
gtk_widget_set_size_request (GTK_WIDGET (frame_situations), 0, H_STYLES_PANE); // < utile seulement pour la largeur min/max
gtk_frame_set_child (GTK_FRAME (frame_situations), GTK_WIDGET (get_situations_box()));
return frame_situations;
}
GtkWidget *get_objects_and_situations_horizontal_pane(){
GtkWidget *objects_and_situations_horizontal_pane = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
gtk_paned_set_start_child (GTK_PANED(objects_and_situations_horizontal_pane), GTK_WIDGET (get_frame_objects()));
gtk_paned_set_end_child (GTK_PANED(objects_and_situations_horizontal_pane), GTK_WIDGET (get_frame_situations()));
return objects_and_situations_horizontal_pane;
}
GtkScrolledWindow *get_scrolled_gl_area(){
GtkScrolledWindow *scrolled = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new());
gtk_scrolled_window_set_min_content_width (scrolled, W_IMAGE);
gtk_scrolled_window_set_min_content_height (scrolled, H_IMAGE);
// GtkAdjustment *width = gtk_adjustment_new (600, 300, 1000, 1, 1, 1000);
// GtkAdjustment *height = gtk_adjustment_new (600, 300, 1000, 1, 1, 1000);
// (value, lower, upper, step_increment, page_increment, page_size)
// GtkWidget *GLarea = gtk_gl_area_new();
// gtk_scrolled_window_set_child (scrolled, GLarea);
// https://docs.gtk.org/gtk4/class.GLArea.html
return scrolled;
}
GtkFrame *get_frame_with_label(){ // EN ATTENDANT DE SAVOIR UTILISER : GtkTextTagTable et GtkTextBuffer
char *text = "\n\
>>> Dans : [space_page - mode RUN] doivent être : ------------------------------------------------------\n\
\n\
(1) les commandes de mouvement:\n\
- run/stop, slow down/speed up, step by step, do/undo/redo\n\
+ le buffer [elapsed time] qui montre le temps de simulation écoulé\n\
\n\
(2) les commandes qui modifient la perception de l'espace (la caméra)\n\
- son orientation (X,Y,Z),\n\
+ le zoom,\n\
+ les paramètres qui définissent la perspective (distances oeil/écran, écran/objet virtuel) \n\
\n\
(3) les commandes qui modifient les apparences des objets et des situations d'intérêt\n\
(+/- transparents, colorés, etc.)\n\
\n\
(4) les commandes qui modifient l'apparence de l'espace (grilles, +/- surfaces, aspect des flèches, etc.)\n\
\n\
(0) NB >>> AUCUNE COMMANDE NE DOIT PERMETTRE D'ÉDITER L'ESPACE ! <<<\n\
\n\
\n\
>>> Dans : [space_page - mode EDIT] doivent être : ------------------------------------------------------\n\
\n\
(1) les commandes qui modifient la perception de l'espace (la caméra)\n\
- son orientation (X,Y,Z),\n\
+ le zoom,\n\
+ les paramètres qui définissent la perspective (distances oeil/écran, écran/objet virtuel) \n\
\n\
(2) les commandes qui modifient les apparences des objets et des situations d'intérêt\n\
(+/- transparents, colorés, etc.)\n\
\n\
(3) les commandes qui modifient l'apparence de l'espace (grilles, +/- surfaces, aspect des flèches, etc.)\n\
\n\
(4) les commandes d'édition locales (drag and drop une flèche)\n\
('faire de la place' pour insérer)\n\
(sélectionner pour déplacer ou enlever...)\n\
NB ces commandes doivent être graphiques et/ou accessibles par raccourcis ou en ligne\n\
\n\
(5) les commandes d'édition globales\n\
(ex: introduire, retirer, transformer +/-aléatoirement (n) objets dans l'espace)\n\
\n\
\n\
NB une action effectuée sur une zone d'intérêt devrait pouvoir être automatiquement appliquée\n\
à d'autres zones d'intérêt identifiées comme similaires\n\
\n\
(0) NB >>> AUCUNE COMMANDE NE DOIT PERMETTRE D'EXÉCUTER UN RUN ! <<<\n\
\n\
\n\
>>> L'objectif est que l'utilisateur ait accès à une organsisation aussi ergonomique que possible -----\n\
\n\
i.e : chaque utilisateur devrait disposer de 'préférences'\n\
c'est-à-dire avoir la possiblité de faire des choix ergonomiques personnalisés.\n\
";
GtkFrame *space_specif = GTK_FRAME(gtk_frame_new ("Space (run / edit) specifications"));
GtkWidget *any_Label = GTK_WIDGET (gtk_label_new (text));
gtk_frame_set_child (GTK_FRAME (space_specif), GTK_WIDGET (any_Label));
return space_specif;
}
//GtkFrame *space_specif = gtk_frame_new (char* const "Space (run / edit) specifications");
GtkWidget *get_text_view(){ // WTF ?!& @Grr #~! https://docs.gtk.org/gtk4/section-text-widget.html
GtkWidget *my_view = gtk_text_view_new ();
GtkTextTagTable *my_table = gtk_text_tag_table_new ();
GtkTextBuffer *my_buffer = gtk_text_buffer_new (my_table);
gtk_text_buffer_set_text (my_buffer, "Hello, this is some text", -1);
gtk_text_view_set_buffer (GTK_TEXT_VIEW (my_view), my_buffer);
/* Now you might put the view in a container and display it on the
* screen; when the user edits the text, signals on the buffer
* will be emitted, such as "changed", "insert_text", and so on.
*/
return my_view;
}