summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/gui/button.h63
-rw-r--r--include/gui/component.h46
-rw-r--r--include/gui/group.h78
-rw-r--r--include/gui/pictureframe.h2
-rw-r--r--include/gui/window.h93
-rw-r--r--src/gui/button.c57
-rw-r--r--src/gui/group.c88
-rw-r--r--src/gui/window.c60
-rw-r--r--test/gui/button.c30
-rw-r--r--test/gui/group.c39
-rw-r--r--test/gui/window.c15
11 files changed, 559 insertions, 12 deletions
diff --git a/include/gui/button.h b/include/gui/button.h
index 62f75a3..6f91e37 100644
--- a/include/gui/button.h
+++ b/include/gui/button.h
@@ -3,14 +3,73 @@
3 3
4/** 4/**
5 * File: button.h 5 * File: button.h
6 * Buttons handling
6 */ 7 */
7 8
9#include <stdbool.h>
10#include "component.h"
11
12/**
13 * Struct: Button
14 * Component that can be triggered by click to execute a specific action.
15 *
16 * Fields:
17 * component - component that will acted as a button thanks to a rightful initialization
18 * *label - title on the button
19 * sizeInterligne - parameter that change padding of the button
20 */
8typedef struct { 21typedef struct {
9 Component component; 22 Component component;
23 char *label;
24 int sizeInterligne;
10} Button; 25} Button;
11 26
12void button_init(Button *button, char *text); 27/**
28 * Function: button_init
29 * Initializes the button.
30 *
31 * Parameters:
32 * *button - pointer to the input button
33 * text - label for the button
34 * sizeInterligne - parameter to initialize padding inside the button
35 * x_pos - position of the button on x axis
36 * y_pos - position of the button on y axis
37 * clickHandler - pointer of function that will be loaded inside our button to perform its purpose
38 */
39void button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler);
13 40
14void button_free(Button *button); 41/**
42 * Function: button_print
43 * Prints the button.
44 *
45 * Parameters:
46 * *parameterSelf - pointer to the button
47 */
48void button_print(Component *parameterSelf);
49
50/**
51 * Function: button_click_test
52 * Debug function to test if the click is working on the current button.
53 *
54 * Parameters:
55 * x - position of the click on x axis
56 * y - position of the click on y axis
57 * *parameterSelf - pointer on the button that is clicked
58 */
59void button_click_test(int x, int y, Component *parameterSelf);
60
61/**
62 * Function: button_is_selected
63 * Checks if the button is selected or not.
64 *
65 * Parameters:
66 * x - position in x for the check
67 * y - position in y for the check
68 * *button - pointer to the current button
69 *
70 * Returns:
71 * A bool from stdbool
72 */
73bool button_is_selected(int x, int y, Button *button);
15 74
16#endif 75#endif
diff --git a/include/gui/component.h b/include/gui/component.h
new file mode 100644
index 0000000..dd101dc
--- /dev/null
+++ b/include/gui/component.h
@@ -0,0 +1,46 @@
1#ifndef UPEM_C_COMPONENT_H
2#define UPEM_C_COMPONENT_H
3
4#include <stdbool.h>
5/**
6 * File: component.h
7 * Windows and components handling.
8 *
9 * See also:
10 * The famous OS
11 */
12struct Component;
13
14/**
15 * Type: ClickHandler
16 * Type of functions that handle mouse's clicks.
17 */
18typedef void (*ClickHandler)(int x_pos, int y_pos, struct Component *parameter);
19
20/**
21 * Type: PrintMethod
22 * Type of functions that will be used to print our component. This must be initialized by the initialization function of the component.
23 */
24typedef void (*PrintMethod)(struct Component *);
25
26/**
27 * Struct: Component
28 * Represents an abstract module handling clicks and a way to be print on the screen.
29 *
30 * Fields:
31 * width - width of the component
32 * height - height of the component
33 * x_pos - position on the x axis from the origin meant to be placed in top left
34 * y_pos - position on the y axis from the origin meant to be placed in top left
35 * click_handler - pointer of function that is called on mouse click
36 * print_method - pointer of function that handle the component's print
37 */
38typedef struct Component {
39 int width, height;
40 int x_pos, y_pos;
41 bool activated;
42 ClickHandler click_handler;
43 PrintMethod print_method;
44} Component;
45
46#endif //UPEM_C_COMPONENT_H
diff --git a/include/gui/group.h b/include/gui/group.h
index 6914d55..2a02ee4 100644
--- a/include/gui/group.h
+++ b/include/gui/group.h
@@ -3,17 +3,91 @@
3 3
4/** 4/**
5 * File: group.h 5 * File: group.h
6 * Group of components
6 */ 7 */
8#include "component.h"
7 9
10/**
11 * Struct: _GroupElement
12 * Node of the linked list that is involved in the Group behavior
13 *
14 * Parameters:
15 * *component - component
16 * *sub_component - sub component
17 * *next - link to the next node
18 */
19typedef struct _GroupElement {
20 Component *sub_component;
21 struct _GroupElement *next;
22} GroupElement;
23
24/**
25 * Struct: Group
26 * Group representation
27 *
28 * Parameters:
29 * component - Component used for the Group to catch clicks and handle print to delegate to the components contented in it
30 * *group_head - pointer to the head of the list that regroup all the components contained inside of the group
31 * margin - margin for all components
32 */
8typedef struct { 33typedef struct {
9 Component component; 34 Component component;
10 Component *sub_components; 35 GroupElement *group_head;
36 int margin;
11} Group; 37} Group;
12 38
13void group_init(Group *group, int padding); 39/**
40 * Function: group_print
41 * Print method for a group that will print all components contained in.
42 *
43 * Parameters:
44 * *parameterSelf - pointer that will be casted into a Group to print
45 */
46void group_print(Component *parameterSelf);
47
48/**
49 * Function: group_click_handler
50 * Delegates the click handling to the component contained inside.
51 *
52 * Parameters:
53 * x_pos - position of the mouse on x axis
54 * y_pos - position of the mouse on y axis
55 * *parameterSelf - pointer that will be casted into a Group to print
56 */
57void group_click_handler(int x_pos, int y_pos, Component *parameterSelf);
58
59/**
60 * Function: group_init
61 * Initializes fields of a Group that must be allocated before.
62 *
63 * Parameters:
64 * *group - group that must be initialized
65 * width - width of the current group
66 * height - height of the current group
67 * x_pos - position on the x axis from the upper left corner
68 * y_pos - position on the y axis from the upper left corner
69 * margin - space between each components
70 */
71void group_init(Group *group, int width, int height, int x_pos, int y_pos, int margin);
14 72
73/**
74 * Function: group_free
75 * Frees the resources held by the group like the linked list.
76 *
77 * Parameters:
78 * *group - group that must be freed
79 */
15void group_free(Group *group); 80void group_free(Group *group);
16 81
82/**
83 * Function: group_add_component
84 * Adds the component at the end of the chained list held by group_head.
85 *
86 * Parameters:
87 * *group - group in which we add the component
88 * *component - component which is added to the group
89 */
17void group_add_component(Group *group, Component *component); 90void group_add_component(Group *group, Component *component);
18 91
92
19#endif 93#endif
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 @@
1#ifndef UPEM_MORPHING_PITUREFRAME 1#ifndef UPEM_MORPHING_PITUREFRAME
2#define UPEM_MORPHING_PITUREFRAME 2#define UPEM_MORPHING_PITUREFRAME
3 3
4#include <blender/canvas.h>
5
4/** 6/**
5 * File: pictureframe.h