summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam NAILI2017-12-10 18:39:27 +0100
committerAdam NAILI2017-12-10 18:41:38 +0100
commitbd3864dda0ca20a2d234bda525e6cd7c21d4f729 (patch)
treee34ee8dc7312918d19d7103c77080c277083f33d
parent8ad5554529a9f1a6d128582af5aec13c792f0932 (diff)
downloadmorpher-bd3864dda0ca20a2d234bda525e6cd7c21d4f729.tar.gz
Modification of the implementation of init, free and successful test for the init function (creation of a window with the right parameters)
-rw-r--r--src/gui/window.c23
-rw-r--r--test/gui/window.c13
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 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <gui/window.h> 2#include <gui/window.h>
3#include <common/mem.h> 3#include "gui/window.h"
4#include "common/mem.h"
4#include "string.h" 5#include "string.h"
5#include "assert.h" 6#include "assert.h"
7#include "MLV/MLV_window.h"
6 8
7void window_init(Window *window, int width, int height, char *title) { 9void window_init(Window *window, int width, int height, char *title) {
8 window = malloc_or_die(sizeof(window));
9 assert(width > 0); 10 assert(width > 0);
10 assert(height > 0); 11 assert(height > 0);
11 window->width = width; 12 window->width = width;
12 window->height = height; 13 window->height = height;
13 assert(title != NULL); 14 assert(title != NULL);
14 strcpy(window->title,title); 15 window->title = malloc_or_die(sizeof(char) * (strlen(title) + 1));
16 strcpy(window->title, title);
15 window->group_buttons = malloc_or_die(sizeof(Group)); 17 window->group_buttons = malloc_or_die(sizeof(Group));
18 group_init(window->group_buttons, 5);
16 window->group_pictureframe = malloc_or_die(sizeof(Group)); 19 window->group_pictureframe = malloc_or_die(sizeof(Group));
20 group_init(window->group_pictureframe, 5);
17} 21}
18 22
19void window_free(Window *window) { 23void window_free(Window *window) {
24 free(window->title);
20 group_free(window->group_buttons); 25 group_free(window->group_buttons);
21 group_free(window->group_pictureframe); 26 group_free(window->group_pictureframe);
22} 27}
23 28
24void window_add_button(Window *window, Component *component){ 29void window_add_button(Window *window, Component *component) {
25 group_add_component(window->group_buttons,component); 30 group_add_component(window->group_buttons, component);
26} 31}
27 32
28void window_add_pictureframe(Window *window, Component *component){ 33void window_add_pictureframe(Window *window, Component *component) {
29 group_add_component(window->group_pictureframe,component); 34 group_add_component(window->group_pictureframe, component);
35}
36
37void window_create(Window *window) {
38 MLV_create_window(window->title, window->title, (unsigned int) window->width, (unsigned int) window->height);
30} \ No newline at end of file 39} \ 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 @@
1static void test_window(){ 1#include "gui/window.h"
2#include "MLV/MLV_all.h"
2 3
4static void test_window() {
5 Window window;
6 window_init(&window, 1000, 512, "Coucou");
7 window_create(&window);
8 MLV_wait_seconds(150);
9 window_free(&window);
3} 10}
4int main(){ 11
12int main() {
13 test_window();
5 return 0; 14 return 0;
6} \ No newline at end of file 15} \ No newline at end of file