summaryrefslogtreecommitdiff
path: root/src/gui/button.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/button.c')
-rw-r--r--src/gui/button.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/src/gui/button.c b/src/gui/button.c
index a55796d..35ac2ed 100644
--- a/src/gui/button.c
+++ b/src/gui/button.c
@@ -1,37 +1,28 @@
1#include <gui/button.h>
2#include <stdlib.h> 1#include <stdlib.h>
2#include <stdbool.h>
3#include <assert.h> 3#include <assert.h>
4#include <common/mem.h>
5#include <string.h> 4#include <string.h>
6#include <MLV/MLV_all.h> 5#include "gui/button.h"
7#include <gui/component.h> 6#include "MLV/MLV_all.h"
7#include "common/mem.h"
8 8
9bool button_is_selected(int x, int y, Button *button) { 9
10static bool button_is_selected(int x, int y, Button *button) {
10 assert(button != NULL); 11 assert(button != NULL);
11 int x1 = button->component.x_pos; 12 int x1 = button->component.x_pos;
12 int y1 = button->component.y_pos; 13 int y1 = button->component.y_pos;
13 int x2 = button->component.x_pos + button->component.width; 14 int x2 = button->component.x_pos + button->component.width;
14 int y2 = button->component.y_pos + button->component.height; 15 int y2 = button->component.y_pos + button->component.height;
15 if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { 16 return x >= x1 && x <= x2 && y >= y1 && y <= y2;
16 return true;
17 }
18 return false;
19} 17}
20 18
21void button_print(Component *parameterSelf) { 19static void button_print(Component *parameterSelf) {
22 assert(parameterSelf != NULL); 20 assert(parameterSelf != NULL);
23 Button *self = (Button *) parameterSelf; 21 Button *self = (Button *) parameterSelf;
24 MLV_draw_adapted_text_box(self->component.x_pos, self->component.y_pos, self->label, self->sizeInterligne, 22 MLV_draw_adapted_text_box(self->component.x_pos, self->component.y_pos, self->label, self->sizeInterligne,
25 MLV_COLOR_BLACK, MLV_COLOR_WHITE, MLV_COLOR_DARK_GREY, MLV_TEXT_CENTER); 23 MLV_COLOR_BLACK, MLV_COLOR_WHITE, MLV_COLOR_DARK_GREY, MLV_TEXT_CENTER);
26} 24}
27 25
28void button_click_test(int x, int y, Component *parameterSelf) {
29 assert(parameterSelf != NULL);
30 Button *self = (Button *) parameterSelf;
31 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
32 }
33}
34
35void button_click_add_constraint(int x, int y, Component *parameterSelf) { 26void button_click_add_constraint(int x, int y, Component *parameterSelf) {
36 assert(parameterSelf != NULL); 27 assert(parameterSelf != NULL);
37 Button *self = (Button *) parameterSelf; 28 Button *self = (Button *) parameterSelf;
@@ -66,7 +57,7 @@ void button_click_less_frame(int x, int y, Component *parameterSelf) {
66 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { 57 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
67 if (frame > 2) { 58 if (frame > 2) {
68 frame = frame / 2; 59 frame = frame / 2;
69 sprintf(labelFrame,"%03d frames", frame); 60 sprintf(labelFrame, "%03d frames", frame);
70 mode = PRINTING_BUTTONS; 61 mode = PRINTING_BUTTONS;
71 } 62 }
72 } 63 }
@@ -78,13 +69,13 @@ void button_click_more_frame(int x, int y, Component *parameterSelf) {
78 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { 69 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
79 if (frame < 256) { 70 if (frame < 256) {
80 frame = frame * 2; 71 frame = frame * 2;
81 sprintf(labelFrame,"%03d frames", frame); 72 sprintf(labelFrame, "%03d frames", frame);
82 mode = PRINTING_BUTTONS; 73 mode = PRINTING_BUTTONS;
83 } 74 }
84 } 75 }
85} 76}
86 77
87void button_click_rendering(int x,int y, Component *parameterSelf) { 78void button_click_rendering(int x, int y, Component *parameterSelf) {
88 assert(parameterSelf != NULL); 79 assert(parameterSelf != NULL);
89 Button *self = (Button *) parameterSelf; 80 Button *self = (Button *) parameterSelf;
90 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { 81 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
@@ -96,14 +87,12 @@ void button_click_none(int x, int y, Component *parameterSelf) {
96 assert(parameterSelf != NULL); 87 assert(parameterSelf != NULL);
97} 88}
98 89
99 90Button *button_create(const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) {
100void
101button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) {
102 assert(button != NULL);
103 assert(text != NULL); 91 assert(text != NULL);
104 assert(sizeInterligne >= 0); 92 assert(sizeInterligne >= 0);
105 assert(x_pos >= 0); 93 assert(x_pos >= 0);
106 assert(y_pos >= 0); 94 assert(y_pos >= 0);
95 Button *button = malloc_or_die(sizeof(Button));
107 button->label = malloc_or_die(sizeof(char) * (strlen(text) + 1)); 96 button->label = malloc_or_die(sizeof(char) * (strlen(text) + 1));
108 strcpy(button->label, text); 97 strcpy(button->label, text);
109 button->sizeInterligne = sizeInterligne; 98 button->sizeInterligne = sizeInterligne;
@@ -112,4 +101,11 @@ button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int
112 button->component.y_pos = y_pos; 101 button->component.y_pos = y_pos;
113 button->component.print_method = button_print; 102 button->component.print_method = button_print;
114 button->component.click_handler = clickHandler; 103 button->component.click_handler = clickHandler;
104 return button;
115} 105}
106
107void button_destroy(Button *button){
108 assert(button != NULL);
109 free(button->label);
110 free(button);
111} \ No newline at end of file