WIP: images stack Dois-je gérer les images ? Ou seulement les pointeurs vers les images ?
This commit is contained in:
parent
16d0ea162d
commit
3d47418a1a
|
@ -36,7 +36,7 @@
|
|||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h> /* Defines NULL. */
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
|
@ -86,21 +86,6 @@ int widget_get_object_transparency (int i); // top
|
|||
/******************************************************************************/
|
||||
// called in : src/widget/rules/distrib.c
|
||||
|
||||
// Define a structure for the stack
|
||||
#define MAX_SIZE 255
|
||||
typedef struct { GtkWidget *arr[MAX_SIZE]; int top; } Stack;
|
||||
|
||||
Stack get_stack();
|
||||
void set_stack (Stack *stack_new);
|
||||
|
||||
void initialize(Stack *stack);
|
||||
bool isEmpty(Stack *stack);
|
||||
bool isFull(Stack *stack);
|
||||
void push(Stack *stack, GtkWidget *value);
|
||||
GtkWidget *pop(Stack *stack);
|
||||
GtkWidget *peek(Stack *stack);
|
||||
void *push_images_onto_stack();
|
||||
|
||||
void *widget_get_selected_rule();
|
||||
void *widget_get_rules_left_pane();
|
||||
void *widget_get_rules_page();
|
||||
|
|
|
@ -33,57 +33,60 @@
|
|||
|
||||
#define W_IMAGE_ABSURD 1920 / 32 // 1920 x 960 ad hoc (pour mon écran)
|
||||
#define H_IMAGE_ABSURD 960
|
||||
#define MAX_SIZE 255
|
||||
|
||||
Stack stack;
|
||||
|
||||
Stack get_stack() {return stack;}
|
||||
void set_stack (Stack *stack_new) {stack = *stack_new;}
|
||||
|
||||
// https://www.geeksforgeeks.org/implement-stack-in-c/
|
||||
|
||||
void *get_an_impression_of_what_a_rules_comparator_could_be(){
|
||||
|
||||
GtkBox *compare_left = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
||||
gtk_widget_set_size_request (GTK_WIDGET (compare_left), W_IMAGE_ABSURD, H_IMAGE_ABSURD);
|
||||
|
||||
GtkBox *compare_right = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
||||
gtk_widget_set_size_request (GTK_WIDGET (compare_right), W_IMAGE_ABSURD, H_IMAGE_ABSURD);
|
||||
|
||||
initialize(&stack);
|
||||
|
||||
push_images_onto_stack (stack);
|
||||
|
||||
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ATP.png")));
|
||||
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ADP.png")));
|
||||
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/AMP.png")));
|
||||
|
||||
gtk_box_append (compare_left, pop(&stack));
|
||||
gtk_box_append (compare_left, pop(&stack));
|
||||
gtk_box_append (compare_left, pop(&stack));
|
||||
// gtk_box_append (compare_left, pop(&stack));
|
||||
|
||||
GtkBox *comparator = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2));
|
||||
gtk_box_append (comparator, GTK_WIDGET (compare_left));
|
||||
gtk_box_append (comparator, GTK_WIDGET (compare_right));
|
||||
|
||||
return comparator;
|
||||
// -----------------------------------------------------------------------
|
||||
// Below is ^c^v from RMS C manual
|
||||
//
|
||||
struct intlistlink {int datum; struct intlistlink *next;} babar;
|
||||
struct intlistlink *my_list = NULL;
|
||||
struct intlistlink *alloc_intlistlink ()
|
||||
{
|
||||
struct intlistlink *p;
|
||||
p = malloc (sizeof (struct intlistlink));
|
||||
if (p == NULL) printf ("fatal: ran out of storage");
|
||||
p->datum = 0;
|
||||
p->next = NULL;
|
||||
return p;
|
||||
}
|
||||
void add_to_mylist (int my_int)
|
||||
{
|
||||
struct intlistlink *p = alloc_intlistlink ();
|
||||
p->datum = my_int;
|
||||
p->next = my_list;
|
||||
my_list = p;
|
||||
}
|
||||
void free_intlist (struct intlistlink *p)
|
||||
{
|
||||
while (p)
|
||||
{
|
||||
struct intlistlink *q = p;
|
||||
p = p->next;
|
||||
free (q);
|
||||
}
|
||||
}
|
||||
// TODO free_intlist (mylist);
|
||||
// TODO mylist = NULL;
|
||||
// TODO offsetof (type, field)
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// Below is ^c^v from https://www.geeksforgeeks.org/implement-stack-in-c/
|
||||
|
||||
void initialize (Stack *stack) { stack->top = -1; }
|
||||
bool isEmpty (Stack *stack) { return stack->top == -1; }
|
||||
bool isFull (Stack *stack) { return stack->top == MAX_SIZE - 1; }
|
||||
typedef struct { GtkWidget *arr[MAX_SIZE]; int top; } Stack;
|
||||
static Stack stack_b;
|
||||
static void initialize (Stack *stack) { stack->top = -1; }
|
||||
static bool isEmpty (Stack *stack) { return stack->top == -1; }
|
||||
static bool isFull (Stack *stack) { return stack->top == MAX_SIZE - 1; }
|
||||
|
||||
void push (Stack *stack, GtkWidget *value)
|
||||
static void push (Stack *stack, GtkWidget *value)
|
||||
{
|
||||
if (isFull(stack)) { printf("Stack Overflow\n"); return; }
|
||||
stack->arr[++stack->top] = value;
|
||||
printf("%d ", stack->top);
|
||||
}
|
||||
|
||||
GtkWidget *pop (Stack *stack)
|
||||
static GtkWidget *pop (Stack *stack)
|
||||
{
|
||||
if (isEmpty(stack)) { printf("Stack Underflow\n"); return NULL; }
|
||||
GtkWidget *popped = stack->arr[stack->top];
|
||||
|
@ -93,12 +96,52 @@ GtkWidget *pop (Stack *stack)
|
|||
return popped;
|
||||
}
|
||||
|
||||
GtkWidget *peek(Stack *stack)
|
||||
static GtkWidget *peek(Stack *stack)
|
||||
{
|
||||
if (isEmpty(stack)) { printf("Stack is empty\n"); return NULL; }
|
||||
return stack->arr[stack->top];
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// confrontation of both examples and methods
|
||||
|
||||
static void *push_images_onto_stack (Stack stack_b);
|
||||
|
||||
void *get_an_impression_of_what_a_rules_comparator_could_be(){
|
||||
|
||||
GtkBox *compare_left = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
||||
gtk_widget_set_size_request (GTK_WIDGET (compare_left), W_IMAGE_ABSURD, H_IMAGE_ABSURD);
|
||||
|
||||
GtkBox *compare_right = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
||||
gtk_widget_set_size_request (GTK_WIDGET (compare_right), W_IMAGE_ABSURD, H_IMAGE_ABSURD);
|
||||
|
||||
initialize(&stack_b);
|
||||
|
||||
push_images_onto_stack (stack_b);
|
||||
|
||||
push(&stack_b, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ATP.png")));
|
||||
push(&stack_b, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ADP.png")));
|
||||
push(&stack_b, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/AMP.png")));
|
||||
|
||||
printf(" --------- \n");//%d\n", *stack_b->arr[0]);
|
||||
|
||||
peek(&stack_b);
|
||||
// gtk_box_append (compare_left, peek(&stack_b));
|
||||
gtk_box_append (compare_left, pop(&stack_b));
|
||||
gtk_box_append (compare_left, pop(&stack_b));
|
||||
gtk_box_append (compare_left, pop(&stack_b));
|
||||
// gtk_box_append (compare_left, pop(&stack));
|
||||
|
||||
GtkBox *comparator = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2));
|
||||
gtk_box_append (comparator, GTK_WIDGET (compare_left));
|
||||
gtk_box_append (comparator, GTK_WIDGET (compare_right));
|
||||
|
||||
return comparator;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -114,7 +157,7 @@ GtkWidget *peek(Stack *stack)
|
|||
|
||||
|
||||
|
||||
void *push_images_onto_stack (Stack stack)
|
||||
static void *push_images_onto_stack (Stack stack)
|
||||
{
|
||||
clock_t start, end;
|
||||
printf("compare.c push_images_onto_stack() start >> ");
|
||||
|
|
Loading…
Reference in New Issue