From 4a271bc2d5c6662cbd0d5cc6189633279d5a1fc5 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Thu, 25 Jul 2024 23:25:04 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20demo=20en=20cliquant=20sur=20store=20et?= =?UTF-8?q?=20reset;=20reste=20=C3=A0=20mettre=20en=20m=C3=A9moire=20un=20?= =?UTF-8?q?=C3=A9tat=20choisi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/prefer.h | 2 +- include/widget.h | 5 ++--- src/fsm.c | 14 +++++++------ src/prefer.c | 46 ++++++++++++++++++++++++++++++++++-------- src/signal.c | 2 ++ src/widget/state/top.c | 19 ++++++----------- 6 files changed, 57 insertions(+), 31 deletions(-) diff --git a/include/prefer.h b/include/prefer.h index a1059c0..e4f0c37 100644 --- a/include/prefer.h +++ b/include/prefer.h @@ -33,4 +33,4 @@ #include void pref_set_store_restore_reset (int choice, int value, GtkScrollbar *scrollbar); - +int *pref_get_all_objects_transparencies(); diff --git a/include/widget.h b/include/widget.h index 047d1bd..b1b41b4 100644 --- a/include/widget.h +++ b/include/widget.h @@ -73,10 +73,9 @@ void *widget_get_sequence_control(); // bottom // called in : src/widget/state/top.c -//void widget_reset_all_objects_transparencies_to_value (int value); // top void widget_reset_all_situations_transparencies_to_value (int value); // top -GtkScrollbar *widget_get_object_32_transparency_scrollbar(); -void widget_reset_object_32_transparency_to_value (int value); +void widget_reset_objects_transparency_to_values (int *value); // top +void *widget_get_objects_transparencies(); // top /******************************************************************************/ diff --git a/src/fsm.c b/src/fsm.c index 66fafcb..b139e42 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -40,13 +40,14 @@ static int choice_EXEC_EDIT = EXEC; static int choice_STATE_RULES_DATA = STATE; -static int preferences = TRUE; +static int preferences_have_been_modified = FALSE; int fsm_get_exec_edit () {return choice_EXEC_EDIT;} int fsm_get_state_rules_data () {return choice_STATE_RULES_DATA;} -bool fsm_get_preferences_state () {return preferences;} -void fsm_set_preferences_state (bool value) {preferences = value;} +void fsm_set_preferences_state (bool value) {preferences_have_been_modified = value;} +bool fsm_get_preferences_state () {return preferences_have_been_modified;} +// preferences_have_been_modified and should be stored before closing the current session. TODO /******************************************************************************/ @@ -79,14 +80,15 @@ void fsm_set_state_rules_data (int choice) // ---------------------- S I T U A T I O N S ---------------------------// -static int choice_SITUATIONS_box_RESET_VALUE = -1; +static int reset_situations_to_value = -1; void fsm_reset_all_situations_transparencies_at_value (int value) { - debug_printing (choice_SITUATIONS_box_RESET_VALUE, value, 3); + debug_printing (reset_situations_to_value, value, 3); // SITUATIONS_box_RESTORE_VALUES is sub_automaton 3 - choice_SITUATIONS_box_RESET_VALUE = value; + reset_situations_to_value = value; widget_reset_all_situations_transparencies_to_value (value); + preferences_have_been_modified = TRUE; } diff --git a/src/prefer.c b/src/prefer.c index a66aea4..9544fe3 100644 --- a/src/prefer.c +++ b/src/prefer.c @@ -33,25 +33,55 @@ #include "../include/signal.h" #include "../include/widget.h" -// static struct preferences *pref = NULL; -// size_t pref_size = 0; struct preferences { - int id [n_objects]; + int transparency [n_objects]; // may become a long, long list... }; + static int choice_STORE_RESTORE_RESET = STORE; +static int p [n_objects]; + +void pref_set_all_objects_transparencies (int *q) +{ + for (int i = 0; i < n_objects; i++) p [i] = q [i]; +} + +int *pref_get_all_objects_transparencies () { return p; } + + +static void print_p (int *abc) { + for (int i = 0; i < n_objects; i++) printf("%3d ", abc [i]); printf("\n");} + + void pref_set_store_restore_reset (int choice, int value) { choice_STORE_RESTORE_RESET = choice; - GtkScrollbar *object_32 = widget_get_object_32_transparency_scrollbar(); + + int ppp [n_objects]; switch (choice) { - case (STORE) : printf("STORE current values in MEM [%d]\n", n_objects); break; - case (RESTORE) : printf("RESTORE values from MEM [%d]\n", n_objects); break; - case (RESET) : widget_reset_object_32_transparency_to_value (value); - printf("RESET current value from [%d]\n", value); + case (STORE) : printf("STORE current values in MEM [%d]\n", n_objects); + // GtkScrollbar *reset_scrollbar = + // GTK_SCROLLBAR (widget_get_objects_transparencies ()); + for (int i = 0; i < n_objects; i++) ppp [i] = i * 4; + // widget_get_object_transparency_scrollbar (i); + pref_set_all_objects_transparencies (ppp); // print_p (ppp); + widget_reset_objects_transparency_to_values (ppp); + fsm_set_preferences_state (TRUE); + break; + case (RESTORE) : printf("RESTORE values from MEM [%d]\n", n_objects); + for (int i = 0; i < n_objects; i++) ppp [i] = i * 4; + pref_set_all_objects_transparencies (ppp); // print_p (ppp); + widget_reset_objects_transparency_to_values (ppp); + fsm_set_preferences_state (TRUE); + break; + case (RESET) : printf("RESET \n"); + for (int i = 0; i < n_objects; i++) ppp [i] = rand() % 127; + pref_set_all_objects_transparencies (ppp); // print_p (ppp); + widget_reset_objects_transparency_to_values (ppp); + fsm_set_preferences_state (TRUE); break; default : printf("default in signal.switch_store_restore_reset()\n"); } diff --git a/src/signal.c b/src/signal.c index a581c39..382b856 100644 --- a/src/signal.c +++ b/src/signal.c @@ -331,6 +331,8 @@ void on_updating_objects_transparencies (GtkWidget *btt_source, GtkScrollbar *sc if ( ! strcmp (btt_name, "view-restore-symbolic")) pref_set_store_restore_reset (STORE, value, scrollbar); if ( ! strcmp (btt_name, "view-fullscreen-symbolic")) pref_set_store_restore_reset (RESTORE, value, scrollbar); if ( ! strcmp (btt_name, "view-refresh-symbolic")) pref_set_store_restore_reset (RESET, value, scrollbar); + + fsm_set_preferences_state (TRUE); // << à détailler TODO } diff --git a/src/widget/state/top.c b/src/widget/state/top.c index 3f164ff..4a53f63 100644 --- a/src/widget/state/top.c +++ b/src/widget/state/top.c @@ -40,17 +40,12 @@ static GtkScrollbar *object_bar [n_objects]; static GtkAdjustment *object_adjust [n_objects]; -GtkScrollbar *widget_get_object_32_transparency_scrollbar () {return object_bar [n_objects - 1];} +void *widget_get_objects_transparencies () {return object_bar;} -void widget_reset_object_32_transparency_to_value (int value) - { gtk_adjustment_set_value (object_adjust [n_objects - 1], value); } - -static void widget_reset_all_objects_transparencies_to_value (int value) +void widget_reset_objects_transparency_to_values (int *value) { for (int i = 0; i < n_objects; i++) - if (value > -1) - gtk_adjustment_set_value (object_adjust [i], value); - else gtk_adjustment_set_value (object_adjust [i], rand() % 127); + gtk_adjustment_set_value (object_adjust [i], value [i]); } static void *get_objects_box() @@ -67,7 +62,7 @@ static void *get_objects_box() GtkBox *reset_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0)); // GtkCheckButton *group_transparencies = GTK_CHECK_BUTTON (gtk_check_button_new ()); - GtkWidget *btt_store = gtk_toggle_button_new (); + GtkWidget *btt_store = gtk_toggle_button_new (); // _with_label ("store"); const char *btt_store_tip = " store current transparencies values.\n\n\ warning : this action will delete \n previous storage of these values"; char tooltip_text_for_btt_store [140]; @@ -79,7 +74,7 @@ static void *get_objects_box() g_signal_connect (btt_store, "toggled", G_CALLBACK (on_updating_objects_transparencies), reset_scrollbar); - GtkWidget *btt_restore = gtk_toggle_button_new (); + GtkWidget *btt_restore = gtk_toggle_button_new (); // _with_label ("restore"); const char *btt_restore_tip = " restore transparencies\n\ from previous storage"; // from the last storage ? char tooltip_text_for_btt_restore [140]; @@ -90,7 +85,7 @@ static void *get_objects_box() g_signal_connect (btt_restore, "toggled", G_CALLBACK (on_updating_objects_transparencies), reset_scrollbar); - GtkWidget *btt_reset = gtk_toggle_button_new (); + GtkWidget *btt_reset = gtk_toggle_button_new (); // _with_label ("reset"); const char *btt_reset_tip = "reset all transparencies to the value\n\ currently set by the left bar"; char tooltip_text_for_btt_reset [140]; @@ -124,8 +119,6 @@ static void *get_objects_box() gtk_box_append (objects_box, GTK_WIDGET (object_bar [i])); } - if (0) widget_reset_all_objects_transparencies_to_value (-1); -// else widget_reset_object_32_transparency_to_value (0); return objects_box; }