diff options
Diffstat (limited to 'include/gui')
-rw-r--r-- | include/gui/button.h | 80 | ||||
-rw-r--r-- | include/gui/component.h | 50 | ||||
-rw-r--r-- | include/gui/group.h | 78 | ||||
-rw-r--r-- | include/gui/pictureframe.h | 101 | ||||
-rw-r--r-- | include/gui/textview.h | 2 | ||||
-rw-r--r-- | include/gui/window.h | 93 |
6 files changed, 387 insertions, 17 deletions
diff --git a/include/gui/button.h b/include/gui/button.h index 62f75a3..41008c1 100644 --- a/include/gui/button.h +++ b/include/gui/button.h | |||
@@ -1,16 +1,90 @@ | |||
1 | #ifndef UPEM_MORPHING_BUTTON | 1 | #ifndef UPEM_MORPHING_BUTTON |
2 | #define UPEM_MORPHING_BUTTON | 2 | #define UPEM_MORPHING_BUTTON |
3 | |||
4 | /** | 3 | /** |
5 | * File: button.h | 4 | * File: button.h |
5 | * Buttons handling | ||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <stdbool.h> | ||
9 | #include "component.h" | ||
10 | |||
11 | /** | ||
12 | * Struct: Button | ||
13 | * Component that can be triggered by click to execute a specific action. | ||
14 | * | ||
15 | * Fields: | ||
16 | * component - component that will acted as a button thanks to a rightful initialization | ||
17 | * *label - title on the button | ||
18 | * sizeInterligne - parameter that change padding of the button | ||
19 | */ | ||
8 | typedef struct { | 20 | typedef struct { |
9 | Component component; | 21 | Component component; |
22 | char *label; | ||
23 | int sizeInterligne; | ||
10 | } Button; | 24 | } Button; |
11 | 25 | ||
12 | void button_init(Button *button, char *text); | 26 | /** |
27 | * Function: button_init | ||
28 | * Initializes the button. | ||
29 | * | ||
30 | * Parameters: | ||
31 | * *button - pointer to the input button | ||
32 | * text - label for the button | ||
33 | * sizeInterligne - parameter to initialize padding inside the button | ||
34 | * x_pos - position of the button on x axis | ||
35 | * y_pos - position of the button on y axis | ||
36 | * clickHandler - pointer of function that will be loaded inside our button to perform its purpose | ||
37 | */ | ||
38 | void button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler); | ||
39 | |||
40 | /** | ||
41 | * Function: button_print | ||
42 | * Prints the button. | ||
43 | * | ||
44 | * Parameters: | ||
45 | * *parameterSelf - pointer to the button | ||
46 | */ | ||
47 | void button_print(Component *parameterSelf); | ||
48 | |||
49 | /** | ||
50 | * Function: button_click_test | ||
51 | * Debug function to test if the click is working on the current button. | ||
52 | * | ||
53 | * Parameters: | ||
54 | * x - position of the click on x axis | ||
55 | * y - position of the click on y axis | ||
56 | * *parameterSelf - pointer on the button that is clicked | ||
57 | */ | ||
58 | void button_click_test(int x, int y, Component *parameterSelf); | ||
59 | |||
60 | void button_click_add_constraint(int x, int y, Component *parameterSelf); | ||
61 | |||
62 | void button_click_show_hide(int x, int y, Component *parameterSelf); | ||
63 | |||
64 | void button_click_exit(int x, int y, Component *parameterSelf); | ||
65 | |||
66 | void button_click_none(int x, int y, Component *parameterSelf); | ||
67 | |||
68 | void button_click_more_frame(int x, int y, Component *parameterSelf); | ||
69 | |||
70 | void button_click_less_frame(int x, int y, Component *parameterSelf); | ||
71 | |||
72 | void button_click_rendering(int x, int y, Component *parameterSelf); | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Function: button_is_selected | ||
77 | * Checks if the button is selected or not. | ||
78 | * | ||
79 | * Parameters: | ||
80 | * x - position in x for the check | ||
81 | * y - position in y for the check | ||
82 | * *button - pointer to the current button | ||
83 | * | ||
84 | * Returns: | ||
85 | * A bool from stdbool | ||
86 | */ | ||
13 | 87 | ||
14 | void button_free(Button *button); | 88 | bool button_is_selected(int x, int y, Button *button); |
15 | 89 | ||
16 | #endif | 90 | #endif |
diff --git a/include/gui/component.h b/include/gui/component.h new file mode 100644 index 0000000..0275d45 --- /dev/null +++ b/include/gui/component.h | |||
@@ -0,0 +1,50 @@ | |||
1 | #ifndef UPEM_C_COMPONENT_H | ||
2 | #define UPEM_C_COMPONENT_H | ||
3 | typedef enum { | ||
4 | WAITING_BUTTON_SHOW, WAITING_BUTTON_HIDE, INSERT_ORIGIN, INSERT_TARGET, PRINTING, EXITING, PRINTING_BUTTONS, RENDERING | ||
5 | } Mode; | ||
6 | |||
7 | extern Mode mode; | ||
8 | extern int frame; | ||
9 | extern char labelFrame[20]; | ||
10 | /** | ||
11 | * File: component.h | ||
12 | * Windows and components handling. | ||
13 | * | ||
14 | * See also: | ||
15 | * The famous OS | ||
16 | */ | ||
17 | struct Component; | ||
18 | |||
19 | /** | ||
20 | * Type: ClickHandler | ||
21 | * Type of functions that handle mouse's clicks. | ||
22 | */ | ||
23 | typedef void (*ClickHandler)(int x_pos, int y_pos, struct Component *parameter); | ||
24 | |||
25 | /** | ||
26 | * Type: PrintMethod | ||
27 | * Type of functions that will be used to print our component. This must be initialized by the initialization function of the component. | ||
28 | */ | ||
29 | typedef void (*PrintMethod)(struct Component *); | ||
30 | |||
31 | /** | ||
32 | * Struct: Component | ||
33 | * Represents an abstract module handling clicks and a way to be print on the screen. | ||
34 | * | ||
35 | * Fields: | ||
36 | * width - width of the component | ||
37 | * height - height of the component | ||
38 | * x_pos - position on the x axis from the origin meant to be placed in top left | ||
39 | * y_pos - position on the y axis from the origin meant to be placed in top left | ||
40 | * click_handler - pointer of function that is called on mouse click | ||
41 | * print_method - pointer of function that handle the component's print | ||
42 | */ | ||
43 | typedef struct Component { | ||
44 | int width, height; | ||
45 | int x_pos, y_pos; | ||
46 | ClickHandler click_handler; | ||
47 | PrintMethod print_method; | ||
48 | } Component; | ||
49 | |||
50 | #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 | */ | ||
19 | typedef 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 | */ | ||
8 | typedef struct { | 33 | typedef struct { |
9 | Component component; | 34 | Component component; |
10 | Component *sub_components; | 35 | GroupElement *group_head; |
36 | int margin; | ||
11 | } Group; | 37 | } Group; |
12 | 38 | ||
13 | void 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 | */ | ||
46 | void 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 | */ | ||
57 | void 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 | */ | ||
71 | void 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 | */ | ||
15 | void group_free(Group *group); | 80 | void 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 |