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