From 0a52cd20ba690303958c29e94ef526442789effa Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Wed, 6 Dec 2017 21:02:36 +0100 Subject: Update doc on window.h --- include/gui/window.h | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/include/gui/window.h b/include/gui/window.h index 9394c84..defc6f7 100644 --- a/include/gui/window.h +++ b/include/gui/window.h @@ -3,24 +3,58 @@ /** * File: window.h + * Windows and components handling. + * + * See also: + * The famous OS */ typedef void (*ClickHandler)(int x_pos, int y_pos); - +/** + * Type: Component + * Abstract component that handles clicks. + */ typedef struct { int width, height; ClickHandler click_handler; } Component; - +/** + * Type: Window + * Supports and handles components. + */ typedef struct { int width, height; Component *components; } Window; - +/** + * Function: window_init + * Initializes a window. + * + * Parameters: + * *window - pointer to the input window + * width - width of the window to initialize + * height - height of the window to initialize + * *title - title of the actual window + */ void window_init(Window *window, int width, int height, char *title); - +/** + * Function: window_free + * Frees the resources supported by the window and the window itself. + * + * Parameters: + * *window - pointer to the input window + */ void window_free(Window *window); - +/** + * Function: window_add_component + * Adds components to the current window at the position specified in x and y. + * + * Parameters: + * *window - pointer to the input window + * *component - pointer to the input component + * x_pos - coordinate on x axis to place the component + * y_pos - coordinate on y axis to place the component + */ void window_add_component(Window *window, Component *component, int x_pos, int y_pos); #endif -- cgit v1.2.3 From 68672a10cc01c5f0c50aaa5779eab8af33046f43 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Wed, 6 Dec 2017 21:02:50 +0100 Subject: Update doc on button.h --- include/gui/button.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/gui/button.h b/include/gui/button.h index 62f75a3..4d3bfe5 100644 --- a/include/gui/button.h +++ b/include/gui/button.h @@ -3,14 +3,34 @@ /** * File: button.h + * Buttons handling */ +/** + * Type: Button + * Component that can be triggered by click to execute a specific action. + */ typedef struct { Component component; } Button; +/** + * Function: button_init + * Initializes the button. + * + * Parameters: + * *button - pointer to the input button + * text - label for the button + */ void button_init(Button *button, char *text); +/** + * Function: button_free + * Frees the resources for the button. + * + * Parameters: + * *button - pointer to the input button + */ void button_free(Button *button); #endif -- cgit v1.2.3 From 81eb171910e03ecb06b3b984375622efbe48b739 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 8 Dec 2017 21:31:50 +0100 Subject: Updating window.h doc and rework of the Component struct (adding a pointer of function to print) --- include/gui/window.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/include/gui/window.h b/include/gui/window.h index defc6f7..c7e12cf 100644 --- a/include/gui/window.h +++ b/include/gui/window.h @@ -9,14 +9,27 @@ * The famous OS */ +/** + * Type: ClickHandler + * Type of functions that handle mouse's clicks. + */ typedef void (*ClickHandler)(int x_pos, int y_pos); + +/** + * Type: PrintMethod + * Type of functions that will be used to print our component. This must be initialized by the initialization function of the component. + */ +typedef void (*PrintMethod)(void); + /** * Type: Component * Abstract component that handles clicks. */ typedef struct { int width, height; + int x_pos, y_pos; ClickHandler click_handler; + PrintMethod print_method; } Component; /** * Type: Window @@ -26,6 +39,7 @@ typedef struct { int width, height; Component *components; } Window; + /** * Function: window_init * Initializes a window. @@ -37,6 +51,7 @@ typedef struct { * *title - title of the actual window */ void window_init(Window *window, int width, int height, char *title); + /** * Function: window_free * Frees the resources supported by the window and the window itself. @@ -45,6 +60,7 @@ void window_init(Window *window, int width, int height, char *title); * *window - pointer to the input window */ void window_free(Window *window); + /** * Function: window_add_component * Adds components to the current window at the position specified in x and y. @@ -52,9 +68,8 @@ void window_free(Window *window); * Parameters: * *window - pointer to the input window * *component - pointer to the input component - * x_pos - coordinate on x axis to place the component - * y_pos - coordinate on y axis to place the component */ -void window_add_component(Window *window, Component *component, int x_pos, int y_pos); +void window_add_component(Window *window, Component *component); + #endif -- cgit v1.2.3 From 4bb6d10d3ffe0376389f9e6f08c90e155687aa91 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 8 Dec 2017 21:34:40 +0100 Subject: Including window.h --- include/gui/button.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/gui/button.h b/include/gui/button.h index 4d3bfe5..8537151 100644 --- a/include/gui/button.h +++ b/include/gui/button.h @@ -1,6 +1,7 @@ #ifndef UPEM_MORPHING_BUTTON #define UPEM_MORPHING_BUTTON +#include "window.h" /** * File: button.h * Buttons handling -- cgit v1.2.3 From 95064360e29a17f511490d153134421da0c4ba40 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sat, 9 Dec 2017 01:50:06 +0100 Subject: Creating test file window --- test/gui/window.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test/gui/window.c diff --git a/test/gui/window.c b/test/gui/window.c new file mode 100644 index 0000000..2e7e0cb --- /dev/null +++ b/test/gui/window.c @@ -0,0 +1,6 @@ +static void test_window(){ + +} +int main(){ + return 0; +} \ No newline at end of file -- cgit v1.2.3 From a7e6f8a296b536966cee49f8de105960970d04c5 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sat, 9 Dec 2017 01:58:10 +0100 Subject: Creating source file window.c --- src/gui/window.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/gui/window.c diff --git a/src/gui/window.c b/src/gui/window.c new file mode 100644 index 0000000..2b4c7e0 --- /dev/null +++ b/src/gui/window.c @@ -0,0 +1,13 @@ +#include "gui/window.h" + +void window_init(Window *window, int width, int height, char *title) { +//TODO +} + +void window_free(Window *window) { +//TODO +} + +void window_add_component(Window *window, Component *component) { +//TODO +} -- cgit v1.2.3 From c9f0cce6b9e6c50fdda1cb94a6ac1831264ab020 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sat, 9 Dec 2017 02:37:14 +0100 Subject: Rework of the structure Group --- include/gui/group.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/gui/group.h b/include/gui/group.h index 6914d55..45ec3b2 100644 --- a/include/gui/group.h +++ b/include/gui/group.h @@ -1,13 +1,20 @@ #ifndef UPEM_MORPHING_GROUP #define UPEM_MORPHING_GROUP +#include "window.h" + /** * File: group.h */ +typedef struct _GroupElement { + Component *c; + struct _GroupElement *next; +} GroupElement; + typedef struct { Component component; - Component *sub_components; + GroupElement *group_head; } Group; void group_init(Group *group, int padding); -- cgit v1.2.3 From 16b67f89eccc78ed6d04f889cae8c2e5c2a3b49d Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sat, 9 Dec 2017 02:38:36 +0100 Subject: Rework of the structure Window --- include/gui/window.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/gui/window.h b/include/gui/window.h index c7e12cf..6ccf00a 100644 --- a/include/gui/window.h +++ b/include/gui/window.h @@ -9,6 +9,8 @@ * The famous OS */ +#include "group.h" + /** * Type: ClickHandler * Type of functions that handle mouse's clicks. @@ -37,7 +39,8 @@ typedef struct { */ typedef struct { int width, height; - Component *components; + Group *group_buttons; + Group *group_images; } Window; /** -- cgit v1.2.3 From e94826bd09fd785c8ae80c132c3e0a8f4125892b Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 12:59:10 +0100 Subject: Updating button documentation --- include/gui/button.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/gui/button.h b/include/gui/button.h index 8537151..4e8ad95 100644 --- a/include/gui/button.h +++ b/include/gui/button.h @@ -1,15 +1,18 @@ #ifndef UPEM_MORPHING_BUTTON #define UPEM_MORPHING_BUTTON -#include "window.h" /** * File: button.h * Buttons handling */ +#include "window.h" /** - * Type: Button + * Struct: Button * Component that can be triggered by click to execute a specific action. + * + * Fields: + * component - component that will acted as a button thanks to a rightful initialization. */ typedef struct { Component component; -- cgit v1.2.3 From 6e91c1be2b0abddb6cfe16152b35cd0559b83c4a Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 13:00:32 +0100 Subject: Updating documentation and reworking the structure of the Window --- include/gui/window.h | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/include/gui/window.h b/include/gui/window.h index 6ccf00a..a20456d 100644 --- a/include/gui/window.h +++ b/include/gui/window.h @@ -24,8 +24,16 @@ typedef void (*ClickHandler)(int x_pos, int y_pos); typedef void (*PrintMethod)(void); /** - * Type: Component - * Abstract component that handles clicks. + * Struct: Component + * Represents an abstract module handling clicks and a way to be print on the screen. + * + * Fields: + * width - width of the component + * height - height of the component + * x_pos - position on the x axis from the origin meant to be placed in top left + * y_pos - position on the y axis from the origin meant to be placed in top left + * click_handler - pointer of function that is called on mouse click + * print_method - pointer of function that handle the component's print */ typedef struct { int width, height; @@ -34,13 +42,21 @@ typedef struct { PrintMethod print_method; } Component; /** - * Type: Window + * Struct: Window * Supports and handles components. + * + * Fields: + * width - width of the window + * height - height of the window + * *title - string printed as name for the window + * *group_buttons - group that handles the buttons added to the window + * *group_pictureframe - group that handles the picture frames added to the window */ typedef struct { int width, height; + char *title; Group *group_buttons; - Group *group_images; + Group *group_pictureframe; } Window; /** @@ -65,14 +81,24 @@ void window_init(Window *window, int width, int height, char *title); void window_free(Window *window); /** - * Function: window_add_component - * Adds components to the current window at the position specified in x and y. + * Function: window_add_button + * Adds Button component to the group of buttons of the current window. + * + * Parameters: + * *window - pointer to the input window + * *component - pointer to the input component + */ +void window_add_button(Window *window, Component *component); + +/** + * Function: window_add_pictureframe + * Adds PictureFrame component to the group of picture frames of the current window. * * Parameters: * *window - pointer to the input window * *component - pointer to the input component */ -void window_add_component(Window *window, Component *component); +void window_add_pictureframe(Window *window, Component *component); #endif -- cgit v1.2.3 From 2aed52d89856847ea394b06d7b70782fa6b21d24 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 13:01:42 +0100 Subject: Implementing init, free, add_button, add_pictureframe functions for window --- src/gui/window.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/gui/window.c b/src/gui/window.c index 2b4c7e0..bd96050 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -1,13 +1,30 @@ -#include "gui/window.h" +#include +#include +#include +#include "string.h" +#include "assert.h" void window_init(Window *window, int width, int height, char *title) { -//TODO + window = malloc_or_die(sizeof(window)); + assert(width > 0); + assert(height > 0); + window->width = width; + window->height = height; + assert(title != NULL); + strcpy(window->title,title); + window->group_buttons = malloc_or_die(sizeof(Group)); + window->group_pictureframe = malloc_or_die(sizeof(Group)); } void window_free(Window *window) { -//TODO + group_free(window->group_buttons); + group_free(window->group_pictureframe); } -void window_add_component(Window *window, Component *component) { -//TODO +void window_add_button(Window *window, Component *component){ + group_add_component(window->group_buttons,component); } + +void window_add_pictureframe(Window *window, Component *component){ + group_add_component(window->group_pictureframe,component); +} \ No newline at end of file -- cgit v1.2.3 From 3449e695fa8885bb8150e105c267d92ab8a3d4ee Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 13:28:40 +0100 Subject: Updating documentation of group.h --- include/gui/group.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/include/gui/group.h b/include/gui/group.h index 45ec3b2..bd46852 100644 --- a/include/gui/group.h +++ b/include/gui/group.h @@ -1,17 +1,35 @@ #ifndef UPEM_MORPHING_GROUP #define UPEM_MORPHING_GROUP -#include "window.h" - /** * File: group.h + * Group of components */ +#include "window.h" +/** + * Struct: _GroupElement + * Nod of the linked list that is involved in the Group behavior + * + * Parameters: + * *component - component + * *sub_component - sub component + * *next - link to the next nod + */ typedef struct _GroupElement { - Component *c; + Component *component; + Component *sub_component; struct _GroupElement *next; } GroupElement; +/** + * Struct: Group + * Group representation + * + * Parameters: + * component - Component used for the Group to catch clicks and handle print to delegate to the components contented in it + * *group_head - pointer to the head of the list that regroup all the components contained inside of the group + */ typedef struct { Component component; GroupElement *group_head; -- cgit v1.2.3 From 27b78c91216f397e9aed3c0dd87db2c54dca50fa Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 17:03:55 +0100 Subject: Creation of component.h and move the content about Component to this header file --- include/gui/component.h | 45 ++++++++++++++++++++++++++++++++++++++ include/gui/group.h | 2 +- include/gui/window.h | 57 +++++++++++++++++++++++-------------------------- 3 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 include/gui/component.h diff --git a/include/gui/component.h b/include/gui/component.h new file mode 100644 index 0000000..d61b713 --- /dev/null +++ b/include/gui/component.h @@ -0,0 +1,45 @@ +#ifndef UPEM_C_COMPONENT_H +#define UPEM_C_COMPONENT_H + +/** + * File: component.h + * Windows and components handling. + * + * See also: + * The famous OS + */ + +#include "group.h" + +/** + * Type: ClickHandler + * Type of functions that handle mouse's clicks. + */ +typedef void (*ClickHandler)(int x_pos, int y_pos); + +/** + * Type: PrintMethod + * Type of functions that will be used to print our component. This must be initialized by the initialization function of the component. + */ +typedef void (*PrintMethod)(void); + +/** + * Struct: Component + * Represents an abstract module handling clicks and a way to be print on the screen. + * + * Fields: + * width - width of the component + * height - height of the component + * x_pos - position on the x axis from the origin meant to be placed in top left + * y_pos - position on the y axis from the origin meant to be placed in top left + * click_handler - pointer of function that is called on mouse click + * print_method - pointer of function that handle the component's print + */ +typedef struct { + int width, height; + int x_pos, y_pos; + ClickHandler click_handler; + PrintMethod print_method; +} Component; + +#endif //UPEM_C_COMPONENT_H diff --git a/include/gui/group.h b/include/gui/group.h index bd46852..b766ded 100644 --- a/include/gui/group.h +++ b/include/gui/group.h @@ -5,7 +5,7 @@ * File: group.h * Group of components */ -#include "window.h" +#include "component.h" /** * Struct: _GroupElement diff --git a/include/gui/window.h b/include/gui/window.h index a20456d..3212a49 100644 --- a/include/gui/window.h +++ b/include/gui/window.h @@ -10,37 +10,8 @@ */ #include "group.h" +#include "component.h" -/** - * Type: ClickHandler - * Type of functions that handle mouse's clicks. - */ -typedef void (*ClickHandler)(int x_pos, int y_pos); - -/** - * Type: PrintMethod - * Type of functions that will be used to print our component. This must be initialized by the initialization function of the component. - */ -typedef void (*PrintMethod)(void); - -/** - * Struct: Component - * Represents an abstract module handling clicks and a way to be print on the screen. - * - * Fields: - * width - width of the component - * height - height of the component - * x_pos - position on the x axis from the origin meant to be placed in top left - * y_pos - position on the y axis from the origin meant to be placed in top left - * click_handler - pointer of function that is called on mouse click - * print_method - pointer of function that handle the component's print - */ -typedef struct { - int width, height; - int x_pos, y_pos; - ClickHandler click_handler; - PrintMethod print_method; -} Component; /** * Struct: Window * Supports and handles components. @@ -100,5 +71,31 @@ void window_add_button(Window *window, Component *component); */ void window_add_pictureframe(Window *window, Component *component); +/** + * Function: window_create + * Initializes the resources to create a window. + * + * Parameters: + * *window - pointer to the input window + */ +void window_create(Window *window); + +/** + * Function: window_print_buttons + * Prints all the buttons to the screen + * + * Parameters: + * *window - pointer to the input window + */ +void window_print_buttons(Window *window); + +/** + * Function: window_print_pictureframes + * Prints all the picture frames to the screen + * + * Parameters: + * *window - pointer to the input window + */ +void window_print_pictureframes(Window *window); #endif -- cgit v1.2.3 From ed99a651c4e0c1a162f416ec384cef7df4268a88 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 18:31:02 +0100 Subject: Deleting the documentation button_free and the prototype --- include/gui/button.h | 8 -------- src/gui/group.c | 1 + 2 files changed, 1 insertion(+), 8 deletions(-) create mode 100644 src/gui/group.c diff --git a/include/gui/button.h b/include/gui/button.h index 4e8ad95..fda83e9 100644 --- a/include/gui/button.h +++ b/include/gui/button.h @@ -28,13 +28,5 @@ typedef struct { */ void button_init(Button *button, char *text); -/** - * Function: button_free - * Frees the resources for the button. - * - * Parameters: - * *button - pointer to the input button - */ -void button_free(Button *button); #endif diff --git a/src/gui/group.c b/src/gui/group.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/gui/group.c @@ -0,0 +1 @@ + -- cgit v1.2.3 From 8ad5554529a9f1a6d128582af5aec13c792f0932 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 18:33:11 +0100 Subject: Update doc and reworking structure and signature of init function for group --- include/gui/group.h | 4 +++- src/gui/group.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/gui/group.h b/include/gui/group.h index b766ded..1887bf6 100644 --- a/include/gui/group.h +++ b/include/gui/group.h @@ -29,13 +29,15 @@ typedef struct _GroupElement { * Parameters: * component - Component used for the Group to catch clicks and handle print to delegate to the components contented in it * *group_head - pointer to the head of the list that regroup all the components contained inside of the group + * padding - padding for all components */ typedef struct { Component component; GroupElement *group_head; + int padding; } Group; -void group_init(Group *group, int padding); +void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding); void group_free(Group *group); diff --git a/src/gui/group.c b/src/gui/group.c index 8b13789..dc48c50 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -1 +1,26 @@ +#include +#include +void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { + group->component.width = width; + group->component.height = height; + group->component.x_pos = x_pos; + group->component.y_pos = y_pos; + group->padding = padding; +} + +void group_free(Group *group) { + if (group->group_head != NULL) { + GroupElement *p = group->group_head; + while (p->next != NULL) { + GroupElement *tmp = group->group_head; + p = p->next; + free(tmp); + } + group->group_head = NULL; + } +} + +void group_add_component(Group *group, Component *component) { + +} \ No newline at end of file -- cgit v1.2.3 From bd3864dda0ca20a2d234bda525e6cd7c21d4f729 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 18:39:27 +0100 Subject: Modification of the implementation of init, free and successful test for the init function (creation of a window with the right parameters) --- src/gui/window.c | 23 ++++++++++++++++------- test/gui/window.c | 13 +++++++++++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/gui/window.c b/src/gui/window.c index bd96050..81af66a 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -1,30 +1,39 @@ #include #include -#include +#include "gui/window.h" +#include "common/mem.h" #include "string.h" #include "assert.h" +#include "MLV/MLV_window.h" void window_init(Window *window, int width, int height, char *title) { - window = malloc_or_die(sizeof(window)); assert(width > 0); assert(height > 0); window->width = width; window->height = height; assert(title != NULL); - strcpy(window->title,title); + window->title = malloc_or_die(sizeof(char) * (strlen(title) + 1)); + strcpy(window->title, title); window->group_buttons = malloc_or_die(sizeof(Group)); + group_init(window->group_buttons, 5); window->group_pictureframe = malloc_or_die(sizeof(Group)); + group_init(window->group_pictureframe, 5); } void window_free(Window *window) { + free(window->title); group_free(window->group_buttons); group_free(window->group_pictureframe); } -void window_add_button(Window *window, Component *component){ - group_add_component(window->group_buttons,component); +void window_add_button(Window *window, Component *component) { + group_add_component(window->group_buttons, component); } -void window_add_pictureframe(Window *window, Component *component){ - group_add_component(window->group_pictureframe,component); +void window_add_pictureframe(Window *window, Component *component) { + group_add_component(window->group_pictureframe, component); +} + +void window_create(Window *window) { + MLV_create_window(window->title, window->title, (unsigned int) window->width, (unsigned int) window->height); } \ No newline at end of file diff --git a/test/gui/window.c b/test/gui/window.c index 2e7e0cb..e3b062a 100644 --- a/test/gui/window.c +++ b/test/gui/window.c @@ -1,6 +1,15 @@ -static void test_window(){ +#include "gui/window.h" +#include "MLV/MLV_all.h" +static void test_window() { + Window window; + window_init(&window, 1000, 512, "Coucou"); + window_create(&window); + MLV_wait_seconds(150); + window_free(&window); } -int main(){ + +int main() { + test_window(); return 0; } \ No newline at end of file -- cgit v1.2.3 From 00a6e1d29ad8dae2d769810b9af65c3934788487 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 12 Dec 2017 13:08:47 +0100 Subject: Reworking on the signature of PrintMethod --- include/gui/component.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gui/component.h b/include/gui/component.h index d61b713..50aee63 100644 --- a/include/gui/component.h +++ b/include/gui/component.h @@ -21,7 +21,7 @@ typedef void (*ClickHandler)(int x_pos, int y_pos); * Type: PrintMethod * Type of functions that will be used to print our component. This must be initialized by the initialization function of the component. */ -typedef void (*PrintMethod)(void); +typedef void (*PrintMethod)(void*); /** * Struct: Component -- cgit v1.2.3 From 45800d79fb2fd74542daeda29e2cb2467f46399a Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 12 Dec 2017 13:09:53 +0100 Subject: Reworking on the _GroupElement structure and updating doc --- include/gui/group.h | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/include/gui/group.h b/include/gui/group.h index 1887bf6..88fffbc 100644 --- a/include/gui/group.h +++ b/include/gui/group.h @@ -9,15 +9,14 @@ /** * Struct: _GroupElement - * Nod of the linked list that is involved in the Group behavior + * Node of the linked list that is involved in the Group behavior * * Parameters: * *component - component * *sub_component - sub component - * *next - link to the next nod + * *next - link to the next node */ typedef struct _GroupElement { - Component *component; Component *sub_component; struct _GroupElement *next; } GroupElement; @@ -37,10 +36,46 @@ typedef struct { int padding; } Group; +/** + * Function: group_print + * Print method for a group (BETA VERSION). + * + * Parameters: + * *parameter - pointer that will be casted into a Group to print + */ +void group_print(void *parameter); + +/** + * Function: group_init + * Initializes fields of a Group that must be allocated before. + * + * Parameters: + * *group - group that must be initialized + * width - width of the current group + * height - height of the current group + * x_pos - position on the x axis from the upper left corner + * y_pos - position on the y axis from the upper left corner + * padding - space between each components + */ void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding); +/** + * Function: group_free + * Frees the resources held by the group like the linked list. + * + * Parameters: + * *group - group that must be freed + */ void group_free(Group *group); +/** + * Function: group_add_component + * Adds the component at the end of the chained list held by group_head. + * + * Parameters: + * *group - group in which we add the component + * *component - component which is added to the group + */ void group_add_component(Group *group, Component *component); #endif -- cgit v1.2.3 From 26bb3df365ed43dd415be8ac870da8ac8991b425 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 12 Dec 2017 13:13:24 +0100 Subject: Adding beta version of print function, working on implementation of the linked list (add + free) --- src/gui/group.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/gui/group.c b/src/gui/group.c index dc48c50..ac2c440 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -1,11 +1,31 @@ #include #include +#include +#include +#include "MLV/MLV_shape.h" +#include "MLV/MLV_window.h" + +void group_print(void *parameter) { + Group *group = (Group *) parameter; + /*DEBUG*/ + MLV_draw_filled_rectangle(group->component.x_pos, group->component.y_pos, group->component.width, + group->component.height, MLV_COLOR_AQUAMARINE); + /**/ + MLV_actualise_window(); +} void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { + assert(group != NULL); + assert(width>0); + assert(height>0); + assert(x_pos>=0); + assert(y_pos>=0); + assert(padding>=0); group->component.width = width; group->component.height = height; group->component.x_pos = x_pos; group->component.y_pos = y_pos; + group->component.print_method = group_print; group->padding = padding; } @@ -22,5 +42,20 @@ void group_free(Group *group) { } void group_add_component(Group *group, Component *component) { - + if (group->group_head != NULL) { + /*Initialize the new node*/ + GroupElement *tmp = malloc_or_die(sizeof(GroupElement)); + tmp->sub_component = component; + tmp->next = NULL; + GroupElement *p = group->group_head; + /*Browsing*/ + while (p->next != NULL) { + p = p->next; + } + p->next = tmp; + } else { + group->group_head = malloc_or_die(sizeof(GroupElement)); + group->group_head->sub_component = component; + group->group_head->next = NULL; + } } \ No newline at end of file -- cgit v1.2.3 From e96c998be9e867e328d393966a60599dc3c37e3a Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 12 Dec 2017 13:18:22 +0100 Subject: Adding asserts, fixing the call of group_init that changed --- src/gui/window.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/window.c b/src/gui/window.c index 81af66a..7b5a75f 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include "gui/window.h" #include "common/mem.h" #include "string.h" @@ -7,6 +9,7 @@ #include "MLV/MLV_window.h" void window_init(Window *window, int width, int height, char *title) { + assert(window != NULL); assert(width > 0); assert(height > 0); window->width = width; @@ -15,9 +18,9 @@ void window_init(Window *window, int width, int height, char *title) { window->title = malloc_or_die(sizeof(char) * (strlen(title) + 1)); strcpy(window->title, title); window->group_buttons = malloc_or_die(sizeof(Group)); - group_init(window->group_buttons, 5); + group_init(window->group_buttons,window->width,100,0,window->height-100,5); window->group_pictureframe = malloc_or_die(sizeof(Group)); - group_init(window->group_pictureframe, 5); + group_init(window->group_pictureframe,window->width,window->height-100,0,0,5); } void window_free(Window *window) { -- cgit v1.2.3 From 2bf31463b7fb1649d89a9d948dc9adf56ebc8d81 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 12 Dec 2017 13:25:12 +0100 Subject: Successful test of initializing and beta printing of the group_buttons that held window --- test/gui/group.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/gui/group.c diff --git a/test/gui/group.c b/test/gui/group.c new file mode 100644 index 0000000..e3d25f3 --- /dev/null +++ b/test/gui/group.c @@ -0,0 +1,18 @@ +#include +#include +#include "MLV/MLV_all.h" + + +static void test_group() { + Window window; + window_init(&window, 1000, 512, "Coucou"); + window_create(&window); + window.group_buttons->component.print_method(window.group_pictureframe); + MLV_wait_seconds(5); + window_free(&window); +} + +int main() { + test_group(); + return 0; +} \ No newline at end of file -- cgit v1.2.3 From a42fdf7d5c9712297f1bbe3dd0951baa8ee32447 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 12 Dec 2017 13:25:56 +0100 Subject: Formatting files --- src/gui/group.c | 10 +++++----- src/gui/window.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gui/group.c b/src/gui/group.c index ac2c440..cb50b1c 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -16,11 +16,11 @@ void group_print(void *parameter) { void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { assert(group != NULL); - assert(width>0); - assert(height>0); - assert(x_pos>=0); - assert(y_pos>=0); - assert(padding>=0); + assert(width > 0); + assert(height > 0); + assert(x_pos >= 0); + assert(y_pos >= 0); + assert(padding >= 0); group->component.width = width; group->component.height = height; group->component.x_pos = x_pos; diff --git a/src/gui/window.c b/src/gui/window.c index 7b5a75f..2c84aeb 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -18,9 +18,9 @@ void window_init(Window *window, int width, int height, char *title) { window->title = malloc_or_die(sizeof(char) * (strlen(title) + 1)); strcpy(window->title, title); window->group_buttons = malloc_or_die(sizeof(Group)); - group_init(window->group_buttons,window->width,100,0,window->height-100,5); + group_init(window->group_buttons, window->width, 100, 0, window->height - 100, 5); window->group_pictureframe = malloc_or_die(sizeof(Group)); - group_init(window->group_pictureframe,window->width,window->height-100,0,0,5); + group_init(window->group_pictureframe, window->width, window->height - 100, 0, 0, 5); } void window_free(Window *window) { -- cgit v1.2.3 From a05d3ad97d513c03d671059a5bae18487af23e24 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 22 Dec 2017 18:31:33 +0100 Subject: Updating doc of button, implementing button_is_selected, button_print, button_click_test (debug click handling), button_init --- include/gui/button.h | 49 ++++++++++++++++++++++++++++++++++++++++++--- src/gui/button.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/gui/button.c | 4 ++++ 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 src/gui/button.c create mode 100644 test/gui/button.c diff --git a/include/gui/button.h b/include/gui/button.h index fda83e9..6f91e37 100644 --- a/include/gui/button.h +++ b/include/gui/button.h @@ -5,17 +5,23 @@ * File: button.h * Buttons handling */ -#include "window.h" + +#include +#include "component.h" /** * Struct: Button * Component that can be triggered by click to execute a specific action. * * Fields: - * component - component that will acted as a button thanks to a rightful initialization. + * component - component that will acted as a button thanks to a rightful initialization + * *label - title on the button + * sizeInterligne - parameter that change padding of the button */ typedef struct { Component component; + char *label; + int sizeInterligne; } Button; /** @@ -25,8 +31,45 @@ typedef struct { * Parameters: * *button - pointer to the input button * text - label for the button + * sizeInterligne - parameter to initialize padding inside the button + * x_pos - position of the button on x axis + * y_pos - position of the button on y axis + * clickHandler - pointer of function that will be loaded inside our button to perform its purpose + */ +void button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler); + +/** + * Function: button_print + * Prints the button. + * + * Parameters: + * *parameterSelf - pointer to the button + */ +void button_print(Component *parameterSelf); + +/** + * Function: button_click_test + * Debug function to test if the click is working on the current button. + * + * Parameters: + * x - position of the click on x axis + * y - position of the click on y axis + * *parameterSelf - pointer on the button that is clicked */ -void button_init(Button *button, char *text); +void button_click_test(int x, int y, Component *parameterSelf); +/** + * Function: button_is_selected + * Checks if the button is selected or not. + * + * Parameters: + * x - position in x for the check + * y - position in y for the check + * *button - pointer to the current button + * + * Returns: + * A bool from stdbool + */ +bool button_is_selected(int x, int y, Button *button); #endif diff --git a/src/gui/button.c b/src/gui/button.c new file mode 100644 index 0000000..fbdc172 --- /dev/null +++ b/src/gui/button.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include +#include + + +bool button_is_selected(int x, int y, Button *button) { + assert(x >= 0); + assert(y >= 0); + assert(button != NULL); + int x1 = button->component.x_pos; + int y1 = button->component.y_pos; + int x2 = button->component.x_pos + button->component.width; + int y2 = button->component.y_pos + button->component.height; + if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { + return true; + } + return false; +} + +void button_print(Component *parameterSelf) { + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + MLV_draw_adapted_text_box(self->component.x_pos, self->component.y_pos, self->label, self->sizeInterligne, + MLV_COLOR_BLACK, MLV_COLOR_WHITE, MLV_COLOR_DARK_GREY, MLV_TEXT_CENTER); +} + +void button_click_test(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self)) { + printf("OK\n"); + } +} + +void +button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { + assert(button != NULL); + assert(text != NULL); + assert(sizeInterligne >= 0); + assert(x_pos >= 0); + assert(y_pos >= 0); + button->label = malloc_or_die(sizeof(char) * (strlen(text) + 1)); + strcpy(button->label, text); + button->sizeInterligne = sizeInterligne; + MLV_get_size_of_adapted_text_box(text, sizeInterligne, &button->component.width, &button->component.height); + button->component.x_pos = x_pos; + button->component.y_pos = y_pos; + button->component.print_method = button_print; + button->component.click_handler = clickHandler; +} diff --git a/test/gui/button.c b/test/gui/button.c new file mode 100644 index 0000000..58270ef --- /dev/null +++ b/test/gui/button.c @@ -0,0 +1,4 @@ +// +// Created by adam on 16/12/17. +// + -- cgit v1.2.3 From 1a4d7b44eaefd7831860b2ffdf178b00af3e1c7e Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 22 Dec 2017 18:56:31 +0100 Subject: Modifying signature of ClickHandler pointer of function, PrintMethod pointer of function, adding a boolean to lock a component --- include/gui/component.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/gui/component.h b/include/gui/component.h index 50aee63..dd101dc 100644 --- a/include/gui/component.h +++ b/include/gui/component.h @@ -1,6 +1,7 @@ #ifndef UPEM_C_COMPONENT_H #define UPEM_C_COMPONENT_H +#include /** * File: component.h * Windows and components handling. @@ -8,20 +9,19 @@ * See also: * The famous OS */ - -#include "group.h" +struct Component; /** * Type: ClickHandler * Type of functions that handle mouse's clicks. */ -typedef void (*ClickHandler)(int x_pos, int y_pos); +typedef void (*ClickHandler)(int x_pos, int y_pos, struct Component *parameter); /** * Type: PrintMethod * Type of functions that will be used to print our component. This must be initialized by the initialization function of the component. */ -typedef void (*PrintMethod)(void*); +typedef void (*PrintMethod)(struct Component *); /** * Struct: Component @@ -35,9 +35,10 @@ typedef void (*PrintMethod)(void*); * click_handler - pointer of function that is called on mouse click * print_method - pointer of function that handle the component's print */ -typedef struct { +typedef struct Component { int width, height; int x_pos, y_pos; + bool activated; ClickHandler click_handler; PrintMethod print_method; } Component; -- cgit v1.2.3 From f3e1ec505dab2d68f7d5ce542f1693d00d7f0537 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 22 Dec 2017 19:11:06 +0100 Subject: Updating doc of group, correcting chained list behaviour, completing implementation of group_init, implementing group_print and group_click_handler to delegate on components --- include/gui/group.h | 26 +++++++++++++++------ src/gui/group.c | 65 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 64 insertions(+), 27 deletions(-) diff --git a/include/gui/group.h b/include/gui/group.h index 88fffbc..2a02ee4 100644 --- a/include/gui/group.h +++ b/include/gui/group.h @@ -28,22 +28,33 @@ typedef struct _GroupElement { * Parameters: * component - Component used for the Group to catch clicks and handle print to delegate to the components contented in it * *group_head - pointer to the head of the list that regroup all the components contained inside of the group - * padding - padding for all components + * margin - margin for all components */ typedef struct { Component component; GroupElement *group_head; - int padding; + int margin; } Group; /** * Function: group_print - * Print method for a group (BETA VERSION). + * Print method for a group that will print all components contained in. * * Parameters: - * *parameter - pointer that will be casted into a Group to print + * *parameterSelf - pointer that will be casted into a Group to print */ -void group_print(void *parameter); +void group_print(Component *parameterSelf); + +/** + * Function: group_click_handler + * Delegates the click handling to the component contained inside. + * + * Parameters: + * x_pos - position of the mouse on x axis + * y_pos - position of the mouse on y axis + * *parameterSelf - pointer that will be casted into a Group to print + */ +void group_click_handler(int x_pos, int y_pos, Component *parameterSelf); /** * Function: group_init @@ -55,9 +66,9 @@ void group_print(void *parameter); * height - height of the current group * x_pos - position on the x axis from the upper left corner * y_pos - position on the y axis from the upper left corner - * padding - space between each components + * margin - space between each components */ -void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding); +void group_init(Group *group, int width, int height, int x_pos, int y_pos, int margin); /** * Function: group_free @@ -78,4 +89,5 @@ void group_free(Group *group); */ void group_add_component(Group *group, Component *component); + #endif diff --git a/src/gui/group.c b/src/gui/group.c index cb50b1c..d287205 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -2,38 +2,56 @@ #include #include #include +#include #include "MLV/MLV_shape.h" #include "MLV/MLV_window.h" -void group_print(void *parameter) { - Group *group = (Group *) parameter; - /*DEBUG*/ - MLV_draw_filled_rectangle(group->component.x_pos, group->component.y_pos, group->component.width, - group->component.height, MLV_COLOR_AQUAMARINE); - /**/ - MLV_actualise_window(); +void group_print(Component *parameterSelf) { + assert(parameterSelf != NULL); + Group *self = (Group *) parameterSelf; + if (self->group_head != NULL) { + GroupElement *p = self->group_head; + while (p != NULL) { + p->sub_component->print_method(p->sub_component); + p = p->next; + } + } +} + +void group_click_handler(int x_pos, int y_pos, Component *parameterSelf) { + assert(parameterSelf != NULL); + Group *self = (Group *) parameterSelf; + if (self->group_head != NULL) { + GroupElement *p = self->group_head; + while (p != NULL) { + p->sub_component->click_handler(x_pos, y_pos, p->sub_component); + p = p->next; + } + } } -void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { +void group_init(Group *group, int width, int height, int x_pos, int y_pos, int margin) { assert(group != NULL); assert(width > 0); assert(height > 0); assert(x_pos >= 0); assert(y_pos >= 0); - assert(padding >= 0); + assert(margin >= 0); group->component.width = width; group->component.height = height; group->component.x_pos = x_pos; group->component.y_pos = y_pos; group->component.print_method = group_print; - group->padding = padding; + group->component.click_handler = group_click_handler; + group->margin = margin; } void group_free(Group *group) { + assert(group != NULL); if (group->group_head != NULL) { GroupElement *p = group->group_head; - while (p->next != NULL) { - GroupElement *tmp = group->group_head; + while (p != NULL) { + GroupElement *tmp = p; p = p->next; free(tmp); } @@ -42,20 +60,27 @@ void group_free(Group *group) { } void group_add_component(Group *group, Component *component) { + assert(group != NULL); + assert(component != NULL); + /*Initialize the new node*/ + GroupElement *tmp = malloc_or_die(sizeof(GroupElement)); + tmp->sub_component = component; + tmp->next = NULL; if (group->group_head != NULL) { - /*Initialize the new node*/ - GroupElement *tmp = malloc_or_die(sizeof(GroupElement)); - tmp->sub_component = component; - tmp->next = NULL; GroupElement *p = group->group_head; /*Browsing*/ while (p->next != NULL) { p = p->next; } p->next = tmp; + /*Modifying for margin*/ + tmp->sub_component->y_pos = p->sub_component->y_pos; + tmp->sub_component->x_pos = p->sub_component->x_pos + p->sub_component->width + group->margin; } else { - group->group_head = malloc_or_die(sizeof(GroupElement)); - group->group_head->sub_component = component; - group->group_head->next = NULL; + tmp->sub_component->y_pos = group->component.y_pos; + tmp->sub_component->x_pos = group->component.x_pos; + group->group_head = tmp; + } -} \ No newline at end of file +} + -- cgit v1.2.3 From 629928d374812c69392879a6c4aca5d6479c33cb Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 22 Dec 2017 19:12:49 +0100 Subject: Including blender/canvas.h for type resolution in pictureframe.h --- include/gui/pictureframe.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/gui/pictureframe.h b/include/gui/pictureframe.h index 59aaf3b..f194feb 100644 --- a/include/gui/pictureframe.h +++ b/include/gui/pictureframe.h @@ -1,6 +1,8 @@ #ifndef UPEM_MORPHING_PITUREFRAME #define UPEM_MORPHING_PITUREFRAME +#include + /** * File: pictureframe.h */ -- cgit v1.2.3 From e84ae1203b8cd7a51d93ec77a5a2663e7496eef5 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 22 Dec 2017 19:14:55 +0100 Subject: Adding asserts, modifying signatures of function for more precise type, implementing window_add functions, window_print functions --- include/gui/window.h | 10 ++++++---- src/gui/window.c | 32 +++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/include/gui/window.h b/include/gui/window.h index 3212a49..329997b 100644 --- a/include/gui/window.h +++ b/include/gui/window.h @@ -11,6 +11,8 @@ #include "group.h" #include "component.h" +#include "button.h" +#include "pictureframe.h" /** * Struct: Window @@ -57,9 +59,9 @@ void window_free(Window *window); * * Parameters: * *window - pointer to the input window - * *component - pointer to the input component + * *button - pointer to the input button */ -void window_add_button(Window *window, Component *component); +void window_add_button(Window *window, Button *button); /** * Function: window_add_pictureframe @@ -67,9 +69,9 @@ void window_add_button(Window *window, Component *component); * * Parameters: * *window - pointer to the input window - * *component - pointer to the input component + * *pictureFrame - pointer to the input picture frame */ -void window_add_pictureframe(Window *window, Component *component); +void window_add_pictureframe(Window *window, PictureFrame *pictureFrame); /** * Function: window_create diff --git a/src/gui/window.c b/src/gui/window.c index 2c84aeb..6e287e5 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -1,8 +1,8 @@ #include #include +#include +#include #include -#include -#include "gui/window.h" #include "common/mem.h" #include "string.h" #include "assert.h" @@ -12,9 +12,9 @@ void window_init(Window *window, int width, int height, char *title) { assert(window != NULL); assert(width > 0); assert(height > 0); + assert(title != NULL); window->width = width; window->height = height; - assert(title != NULL); window->title = malloc_or_die(sizeof(char) * (strlen(title) + 1)); strcpy(window->title, title); window->group_buttons = malloc_or_die(sizeof(Group)); @@ -24,19 +24,37 @@ void window_init(Window *window, int width, int height, char *title) { } void window_free(Window *window) { + assert(window != NULL); free(window->title); group_free(window->group_buttons); group_free(window->group_pictureframe); } -void window_add_button(Window *window, Component *component) { - group_add_component(window->group_buttons, component); +void window_add_button(Window *window, Button *button) { + assert(window != NULL); + assert(button != NULL); + group_add_component(window->group_buttons, &(button->component)); } -void window_add_pictureframe(Window *window, Component *component) { - group_add_component(window->group_pictureframe, component); +void window_add_pictureframe(Window *window, PictureFrame *pictureFrame) { + assert(window != NULL); + assert(pictureFrame != NULL); + group_add_component(window->group_pictureframe, &(pictureFrame->component)); } void window_create(Window *window) { + assert(window != NULL); MLV_create_window(window->title, window->title, (unsigned int) window->width, (unsigned int) window->height); +} + +void window_print_buttons(Window *window) { + assert(window != NULL); + window->group_buttons->component.print_method(&(window->group_buttons->component)); + MLV_actualise_window(); +} + +void window_print_pictureframes(Window *window) { + assert(window != NULL); + window->group_pictureframe->component.print_method(&(window->group_pictureframe->component)); + MLV_actualise_window(); } \ No newline at end of file -- cgit v1.2.3 From 92c999f56a86f221e6d3dc2182b5b7f7e0e08231 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 22 Dec 2017 19:15:56 +0100 Subject: Successful test for the group management and button handling. Buttons are placed in the right spots thanks to group position handling --- test/gui/button.c | 32 +++++++++++++++++++++++++++++--- test/gui/group.c | 27 ++++++++++++++++++++++++--- test/gui/window.c | 4 ++-- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/test/gui/button.c b/test/gui/button.c index 58270ef..df3e04d 100644 --- a/test/gui/button.c +++ b/test/gui/button.c @@ -1,4 +1,30 @@ -// -// Created by adam on 16/12/17. -// +#include +#include +#include +#include +#include "MLV/MLV_all.h" + +static void test_button() { + /* Window window; + window_init(&window, 1000, 512, "Coucou"); + window_create(&window); + Button button1; + button_init(&button1, "OK", 10, 500, 256, button_click_test); + button1.component.print_method(&button1); + int mouse_x; + int mouse_y; + while (1) { + if (MLV_get_mouse_button_state(MLV_BUTTON_LEFT) == MLV_PRESSED) { + MLV_get_mouse_position(&mouse_x, &mouse_y); + button1.component.click_handler(mouse_x, mouse_y, &(button1.component)); + } + }*/ + /*MLV_wait_seconds(10); + window_free(&window);*/ +} + +int main() { + test_button(); + return 0; +} \ No newline at end of file diff --git a/test/gui/group.c b/test/gui/group.c index e3d25f3..555c246 100644 --- a/test/gui/group.c +++ b/test/gui/group.c @@ -7,9 +7,30 @@ static void test_group() { Window window; window_init(&window, 1000, 512, "Coucou"); window_create(&window); - window.group_buttons->component.print_method(window.group_pictureframe); - MLV_wait_seconds(5); - window_free(&window); + + Button button1; + Button button2; + Button button3; + + button_init(&button1, "OK", 10, 500, 256, button_click_test); + button_init(&button2,"Bouton magique",10, 500,290, NULL); + button_init(&button3,"Très lonnggggg boooouttttooooon",10,0,0,button_click_test); + + window_add_button(&window,&button1); + window_add_button(&window,&button2); + window_add_button(&window,&button3); + + window_print_buttons(&window); + int mouse_x; + int mouse_y; + while(1){ + if (MLV_get_mouse_button_state(MLV_BUTTON_LEFT) == MLV_PRESSED) { + MLV_get_mouse_position(&mouse_x, &mouse_y); + group_click_handler(mouse_x,mouse_y,&(window.group_buttons->component)); + } + } + /*MLV_wait_seconds(15); + window_free(&window);*/ } int main() { diff --git a/test/gui/window.c b/test/gui/window.c index e3b062a..b19300e 100644 --- a/test/gui/window.c +++ b/test/gui/window.c @@ -2,11 +2,11 @@ #include "MLV/MLV_all.h" static void test_window() { - Window window; + /*Window window; window_init(&window, 1000, 512, "Coucou"); window_create(&window); MLV_wait_seconds(150); - window_free(&window); + window_free(&window);*/ } int main() { -- cgit v1.2.3 From ee98053ef83869033713c8c7d6d487457d6443d8 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Wed, 27 Dec 2017 17:16:20 +0100 Subject: Implementing the locking system to disable components --- src/gui/button.c | 3 ++- src/gui/group.c | 4 +++- test/gui/group.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gui/button.c b/src/gui/button.c index fbdc172..96cbd9a 100644 --- a/src/gui/button.c +++ b/src/gui/button.c @@ -33,7 +33,7 @@ void button_click_test(int x, int y, Component *parameterSelf) { assert(y >= 0); assert(parameterSelf != NULL); Button *self = (Button *) parameterSelf; - if (button_is_selected(x, y, self)) { + if (button_is_selected(x, y, self) && self->component.activated) { printf("OK\n"); } } @@ -51,6 +51,7 @@ button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int MLV_get_size_of_adapted_text_box(text, sizeInterligne, &button->component.width, &button->component.height); button->component.x_pos = x_pos; button->component.y_pos = y_pos; + button->component.activated = true; button->component.print_method = button_print; button->component.click_handler = clickHandler; } diff --git a/src/gui/group.c b/src/gui/group.c index d287205..11a0583 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -21,7 +21,8 @@ void group_print(Component *parameterSelf) { void group_click_handler(int x_pos, int y_pos, Component *parameterSelf) { assert(parameterSelf != NULL); Group *self = (Group *) parameterSelf; - if (self->group_head != NULL) { + + if (self->group_head != NULL && self->component.activated) { GroupElement *p = self->group_head; while (p != NULL) { p->sub_component->click_handler(x_pos, y_pos, p->sub_component); @@ -41,6 +42,7 @@ void group_init(Group *group, int width, int height, int x_pos, int y_pos, int m group->component.height = height; group->component.x_pos = x_pos; group->component.y_pos = y_pos; + group->component.activated = true; group->component.print_method = group_print; group->component.click_handler = group_click_handler; group->margin = margin; diff --git a/test/gui/group.c b/test/gui/group.c index 555c246..99a567e 100644 --- a/test/gui/group.c +++ b/test/gui/group.c @@ -13,7 +13,7 @@ static void test_group() { Button button3; button_init(&button1, "OK", 10, 500, 256, button_click_test); - button_init(&button2,"Bouton magique",10, 500,290, NULL); + button_init(&button2,"Bouton magique",10, 500,290, button_click_test); button_init(&button3,"Très lonnggggg boooouttttooooon",10,0,0,button_click_test); window_add_button(&window,&button1); -- cgit v1.2.3 From 46fecbfedfc61658caeb721565fd36f49c0d3db9 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Wed, 27 Dec 2017 18:31:16 +0100 Subject: Updating documentation of PictureFrame. Defining structures, types, methods signatures --- include/gui/pictureframe.h | 70 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/include/gui/pictureframe.h b/include/gui/pictureframe.h index f194feb..de9ae1c 100644 --- a/include/gui/pictureframe.h +++ b/include/gui/pictureframe.h @@ -2,23 +2,83 @@ #define UPEM_MORPHING_PITUREFRAME #include +#include /** * File: pictureframe.h */ - +/** + * Type: CartesianMappingDivision + * Type of functions needed to split CartesianMapping and keep only the CartesianVector needed, related to the type of PictureFrame involved + */ +typedef CartesianVector (*CartesianMappingDivision)(const CartesianMapping *cartesianMapping); +/** + * Struct: PictureFrame + * Represents a component to print pictures. + * + * Fields: + * component - inherent component management of the PictureFrame + * morphing - abstract coordinate transform + * canvas - image that will be printed + * cartesianMappingDivision - pointer of function that gives the role of the current PictureFrame to retrieve the right CartesianVector related to its usage + */ typedef struct { Component component; + Morphing *morphing; + Canvas *canvas; + CartesianMappingDivision cartesianMappingDivision; } PictureFrame; -void pictureframe_init(PictureFrame *pictureFrame, int length); +/** + * Function: pictureframe_origin_split + * Splits the CartesianMapping to get the CartesianVector related to the origin PictureFrame. + * + * Parameters: + * *cartesianMapping - CartesianMapping that contains the origin and target CartesianVector needed to be split + */ +CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping); + +/** + * Function: pictureframe_target_split + * Splits the CartesianMapping to get the CartesianVector related to the target PictureFrame. + * + * Parameters: + * *cartesianMapping - CartesianMapping that contains the origin and target CartesianVector needed to be split + */ +CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping); + +void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, CartesianMappingDivision cartesianMappingDivision); void pictureframe_free(PictureFrame *pictureFrame); -void pictureframe_draw_canvas(PictureFrame *pictureFrame, Canvas *canvas); +/** + * Function: pictureframe_draw_canvas + * Draws the contained Canvas of the PictureFrame. + * + * Parameters: + * *pictureFrame - current PictureFrame containing the Canvas to print. + */ +void pictureframe_draw_canvas(PictureFrame *pictureFrame); -void pictureframe_draw_triangulation(PictureFrame *pictureFrame, void *triangulation); +/** + * Function: pictureframe_print + * Prints the PictureFrame (The Canvas involved, plus the triangles and points of the Morphing) + * + * Parameters: + * *parameterSelf - pointer that will be casted into a PictureFrame to be printed + */ +void pictureframe_print(Component *parameterSelf); + +/** + * Function: pictureframe_click_handler + * Adds a point on the coordinate of the picture that the mouse is pointing. + * + * Parameters: + * x_pos - coordinate on x axis of the mouse + * y_pos - coordinate on y axis of the mouse + * *parameterSelf - pointer that will be casted into a PictureFrame + */ +void pictureframe_click_handler(int x_pos, int y_pos, Component *parameterSelf); -void pictureframe_draw_point(PictureFrame *pictureFrame, int x_pos, int y_pos); #endif -- cgit v1.2.3 From aaf57e5ee1e0cf74afdbdf56293f1afd7e79e6b0 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Thu, 28 Dec 2017 16:22:43 +0100 Subject: Reworking signatures of pictureframe function, beginning of implementation, debug tests --- include/gui/pictureframe.h | 5 ++++- src/gui/pictureframe.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ test/gui/group.c | 2 +- test/gui/pictureframe.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/gui/pictureframe.c create mode 100644 test/gui/pictureframe.c diff --git a/include/gui/pictureframe.h b/include/gui/pictureframe.h index de9ae1c..1f5407c 100644 --- a/include/gui/pictureframe.h +++ b/include/gui/pictureframe.h @@ -3,6 +3,7 @@ #include #include +#include "component.h" /** * File: pictureframe.h @@ -12,6 +13,7 @@ * Type of functions needed to split CartesianMapping and keep only the CartesianVector needed, related to the type of PictureFrame involved */ typedef CartesianVector (*CartesianMappingDivision)(const CartesianMapping *cartesianMapping); + /** * Struct: PictureFrame * Represents a component to print pictures. @@ -47,7 +49,8 @@ CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMappi */ CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping); -void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, CartesianMappingDivision cartesianMappingDivision); +void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, + CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas); void pictureframe_free(PictureFrame *pictureFrame); diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c new file mode 100644 index 0000000..543ba4c --- /dev/null +++ b/src/gui/pictureframe.c @@ -0,0 +1,45 @@ +#include +#include +#include + +CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { + +} + +CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping) { + +} + +void pictureframe_print(Component *parameterSelf) { + PictureFrame *self = (PictureFrame *) parameterSelf; + /*DEBUG*/ + MLV_draw_filled_rectangle(self->component.x_pos, self->component.y_pos, self->component.width, self->component.height, + MLV_COLOR_RED); + /**/ +} + +void pictureframe_click_handler(int x_pos, int y_pos, Component *parameterSelf) { + printf("ClickHandler pictureframe activated \n"); +} + +void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, + CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas) { + assert(pictureFrame != NULL); + assert(width > 0); + assert(height > 0); + assert(x_pos >= 0); + assert(y_pos >= 0); + assert(cartesianMappingDivision != NULL); + assert(morphing != NULL); + assert(canvas != NULL); + pictureFrame->component.width = width; + pictureFrame->component.height = height; + pictureFrame->component.x_pos = x_pos; + pictureFrame->component.y_pos = y_pos; + pictureFrame->component.activated = true; + pictureFrame->component.print_method = pictureframe_print; + pictureFrame->component.click_handler = pictureframe_click_handler; + pictureFrame->morphing = morphing; + pictureFrame->canvas = canvas; + pictureFrame->cartesianMappingDivision = cartesianMappingDivision; +} \ No newline at end of file diff --git a/test/gui/group.c b/test/gui/group.c index 99a567e..5ec9194 100644 --- a/test/gui/group.c +++ b/test/gui/group.c @@ -4,7 +4,7 @@ static void test_group() { - Window window; + /*Window window; window_init(&window, 1000, 512, "Coucou"); window_create(&window); diff --git a/test/gui/pictureframe.c b/test/gui/pictureframe.c new file mode 100644 index 0000000..a47eaa0 --- /dev/null +++ b/test/gui/pictureframe.c @@ -0,0 +1,40 @@ +#include +#include +#include "MLV/MLV_all.h" + + +static void test_pictureframe() { + Window window; + window_init(&window, 1000, 512, "Coucou"); + window_create(&window); + + PictureFrame pictureFrame1; + PictureFrame pictureFrame2; + + Morphing *morphing = morphing_create(500,250); + Canvas canvas; + canvas_init(&canvas,500,250); + + pictureframe_init(&pictureFrame1,500,250,0,0,pictureframe_origin_split,morphing,&canvas); + pictureframe_init(&pictureFrame2,500,250,0,0,pictureframe_target_split,morphing,&canvas); + + window_add_pictureframe(&window,&pi