summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam NAILI2017-12-31 15:00:23 +0100
committerAdam NAILI2017-12-31 15:00:23 +0100
commit41da8b54ed619ea869ca286cd8ec02e105e21c19 (patch)
treef69a6ba2ece9ec4b0b8fa5d6880f61d5f13fc5ee
parent4b30bfee527edd88e035b93c1230ddf2101291f6 (diff)
downloadmorpher-41da8b54ed619ea869ca286cd8ec02e105e21c19.tar.gz
Implementing all kinds of buttons. Rendering to fix
-rw-r--r--include/gui/button.h14
-rw-r--r--include/gui/component.h4
-rw-r--r--include/gui/textview.h2
-rw-r--r--src/gui/button.c75
-rw-r--r--src/gui/component.c6
-rw-r--r--src/gui/pictureframe.c64
-rw-r--r--test/gui/pictureframe.c83
7 files changed, 197 insertions, 51 deletions
diff --git a/include/gui/button.h b/include/gui/button.h
index 26d7970..41008c1 100644
--- a/include/gui/button.h
+++ b/include/gui/button.h
@@ -58,6 +58,20 @@ void button_print(Component *parameterSelf);
58void button_click_test(int x, int y, Component *parameterSelf); 58void button_click_test(int x, int y, Component *parameterSelf);
59 59
60void button_click_add_constraint(int x, int y, Component *parameterSelf); 60void button_click_add_constraint(int x, int y, Component *parameterSelf);
61
62void button_click_show_hide(int x, int y, Component *parameterSelf);
63
64void button_click_exit(int x, int y, Component *parameterSelf);
65
66void button_click_none(int x, int y, Component *parameterSelf);
67
68void button_click_more_frame(int x, int y, Component *parameterSelf);
69
70void button_click_less_frame(int x, int y, Component *parameterSelf);
71
72void button_click_rendering(int x, int y, Component *parameterSelf);
73
74
61/** 75/**
62 * Function: button_is_selected 76 * Function: button_is_selected
63 * Checks if the button is selected or not. 77 * Checks if the button is selected or not.
diff --git a/include/gui/component.h b/include/gui/component.h
index 0e8f437..0275d45 100644
--- a/include/gui/component.h
+++ b/include/gui/component.h
@@ -1,10 +1,12 @@
1#ifndef UPEM_C_COMPONENT_H 1#ifndef UPEM_C_COMPONENT_H
2#define UPEM_C_COMPONENT_H 2#define UPEM_C_COMPONENT_H
3typedef enum { 3typedef enum {
4 WAITING_BUTTON, INSERT_ORIGIN, INSERT_TARGET,PRINTING 4 WAITING_BUTTON_SHOW, WAITING_BUTTON_HIDE, INSERT_ORIGIN, INSERT_TARGET, PRINTING, EXITING, PRINTING_BUTTONS, RENDERING
5} Mode; 5} Mode;
6 6
7extern Mode mode; 7extern Mode mode;
8extern int frame;
9extern char labelFrame[20];
8/** 10/**
9 * File: component.h 11 * File: component.h
10 * Windows and components handling. 12 * Windows and components handling.
diff --git a/include/gui/textview.h b/include/gui/textview.h
index 7a07eb3..7414336 100644
--- a/include/gui/textview.h
+++ b/include/gui/textview.h
@@ -1,6 +1,8 @@
1#ifndef UPEM_MORPHING_TEXTVIEW 1#ifndef UPEM_MORPHING_TEXTVIEW
2#define UPEM_MORPHING_TEXTVIEW 2#define UPEM_MORPHING_TEXTVIEW
3 3
4#include "component.h"
5
4/** 6/**
5 * File: textview.h 7 * File: textview.h
6 */ 8 */
diff --git a/src/gui/button.c b/src/gui/button.c
index a1fa1cf..03addf8 100644
--- a/src/gui/button.c
+++ b/src/gui/button.c
@@ -32,21 +32,88 @@ void button_click_test(int x, int y, Component *parameterSelf) {
32 assert(y >= 0); 32 assert(y >= 0);
33 assert(parameterSelf != NULL); 33 assert(parameterSelf != NULL);
34 Button *self = (Button *) parameterSelf; 34 Button *self = (Button *) parameterSelf;
35 if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { 35 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
36 printf("OK\n");
37 } 36 }
38} 37}
39 38
40void button_click_add_constraint(int x, int y, Component *parameterSelf){ 39void button_click_add_constraint(int x, int y, Component *parameterSelf) {
41 assert(x >= 0); 40 assert(x >= 0);
42 assert(y >= 0); 41 assert(y >= 0);
43 assert(parameterSelf != NULL); 42 assert(parameterSelf != NULL);
44 Button *self = (Button *) parameterSelf; 43 Button *self = (Button *) parameterSelf;
45 if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { 44 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
46 mode = INSERT_ORIGIN; 45 mode = INSERT_ORIGIN;
47 } 46 }
48} 47}
49 48
49void button_click_show_hide(int x, int y, Component *parameterSelf) {
50 assert(x >= 0);
51 assert(y >= 0);
52 assert(parameterSelf != NULL);
53 Button *self = (Button *) parameterSelf;
54 if (button_is_selected(x, y, self)) {
55 if (mode == WAITING_BUTTON_SHOW) {
56 mode = WAITING_BUTTON_HIDE;
57 } else if (mode == WAITING_BUTTON_HIDE) {
58 mode = WAITING_BUTTON_SHOW;
59 }
60 }
61}
62
63void button_click_exit(int x, int y, Component *parameterSelf) {
64 assert(x >= 0);
65 assert(y >= 0);
66 assert(parameterSelf != NULL);
67 Button *self = (Button *) parameterSelf;
68 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
69 mode = EXITING;
70 }
71}
72
73void button_click_less_frame(int x, int y, Component *parameterSelf) {
74 assert(x >= 0);
75 assert(y >= 0);
76 assert(parameterSelf != NULL);
77 Button *self = (Button *) parameterSelf;
78 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
79 if (frame > 2) {
80 frame = frame / 2;
81 sprintf(labelFrame,"%03d frames", frame);
82 mode = PRINTING_BUTTONS;
83 }
84 }
85}
86
87void button_click_more_frame(int x, int y, Component *parameterSelf) {
88 assert(x >= 0);
89 assert(y >= 0);
90 assert(parameterSelf != NULL);
91 Button *self = (Button *) parameterSelf;
92 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
93 if (frame < 256) {
94 frame = frame * 2;
95 sprintf(labelFrame,"%03d frames", frame);
96 mode = PRINTING_BUTTONS;
97 }
98 }
99}
100
101void button_click_rendering(int x,int y, Component *parameterSelf) {
102 assert(x >= 0);
103 assert(y >= 0);
104 assert(parameterSelf != NULL);
105 Button *self = (Button *) parameterSelf;
106 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
107 mode = RENDERING;
108 }
109}
110
111void button_click_none(int x, int y, Component *parameterSelf) {
112 assert(x >= 0);
113 assert(y >= 0);
114 assert(parameterSelf != NULL);
115}
116
50 117
51void 118void
52button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { 119button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) {
diff --git a/src/gui/component.c b/src/gui/component.c
index 07fb336..3eb31c5 100644
--- a/src/gui/component.c
+++ b/src/gui/component.c
@@ -1,3 +1,7 @@
1#include <gui/component.h> 1#include <gui/component.h>
2 2
3Mode mode = WAITING_BUTTON; 3Mode mode = WAITING_BUTTON_SHOW;
4
5int frame = 2;
6
7char labelFrame[20];
diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c
index e4081a7..4126f59 100644
--- a/src/gui/pictureframe.c
+++ b/src/gui/pictureframe.c
@@ -1,7 +1,6 @@
1#include <assert.h> 1#include <assert.h>
2#include <gui/pictureframe.h> 2#include <gui/pictureframe.h>
3#include <MLV/MLV_all.h> 3#include <MLV/MLV_all.h>
4#include <common/time.h>
5 4
6CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { 5CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) {
7 return cartesianMapping->origin; 6 return cartesianMapping->origin;
@@ -11,33 +10,39 @@ CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMappi
11 return cartesianMapping->target; 10 return cartesianMapping->target;
12} 11}
13 12
13void pictureframe_draw_canvas(PictureFrame *pictureFrame){
14 MLV_draw_image(pictureFrame->canvas->mlv, pictureFrame->component.x_pos, pictureFrame->component.y_pos);
15}
16
14void pictureframe_print(Component *parameterSelf) { 17void pictureframe_print(Component *parameterSelf) {
15 PictureFrame *self = (PictureFrame *) parameterSelf; 18 PictureFrame *self = (PictureFrame *) parameterSelf;
16 MLV_draw_image(self->canvas->mlv, self->component.x_pos, self->component.y_pos); 19 pictureframe_draw_canvas(self);
17 TriangleMap *p = self->morphing->first; 20 if (mode != WAITING_BUTTON_HIDE) {
18 CartesianVector p1; 21 TriangleMap *p = self->morphing->first;
19 CartesianVector p2; 22 CartesianVector p1;
20 CartesianVector p3; 23 CartesianVector p2;
21 CartesianVector pointToPrint1; 24 CartesianVector p3;
22 CartesianVector pointToPrint2; 25 CartesianVector pointToPrint1;
23 CartesianVector pointToPrint3; 26 CartesianVector pointToPrint2;
24 while(p != NULL){ 27 CartesianVector pointToPrint3;
25 p1 = self->cartesianMappingDivision(&(p->vertices[0])); 28 while (p != NULL) {
26 p2 = self->cartesianMappingDivision(&(p->vertices[1])); 29 p1 = self->cartesianMappingDivision(&(p->vertices[0]));
27 p3 = self->cartesianMappingDivision(&(p->vertices[2])); 30 p2 = self->cartesianMappingDivision(&(p->vertices[1]));
31 p3 = self->cartesianMappingDivision(&(p->vertices[2]));
28 32
29 pointToPrint1 = pictureframe_conversion_to_picture(p1.x,p1.y,self); 33 pointToPrint1 = pictureframe_conversion_to_picture(p1.x, p1.y, self);
30 pointToPrint2 = pictureframe_conversion_to_picture(p2.x,p2.y,self); 34 pointToPrint2 = pictureframe_conversion_to_picture(p2.x, p2.y, self);
31 pointToPrint3 = pictureframe_conversion_to_picture(p3.x,p3.y,self); 35 pointToPrint3 = pictureframe_conversion_to_picture(p3.x, p3.y, self);
32 36
33 MLV_draw_filled_circle(pointToPrint1.x,pointToPrint1.y,2,MLV_COLOR_RED); 37 MLV_draw_filled_circle(pointToPrint1.x, pointToPrint1.y, 2, MLV_COLOR_RED);
34 MLV_draw_filled_circle(pointToPrint2.x,pointToPrint2.y,2,MLV_COLOR_RED); 38 MLV_draw_filled_circle(pointToPrint2.x, pointToPrint2.y, 2, MLV_COLOR_RED);
35 MLV_draw_filled_circle(pointToPrint3.x,pointToPrint3.y,2,MLV_COLOR_RED); 39 MLV_draw_filled_circle(pointToPrint3.x, pointToPrint3.y, 2, MLV_COLOR_RED);
36 40
37 MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); 41 MLV_draw_line(pointToPrint1.x, pointToPrint1.y, pointToPrint2.x, pointToPrint2.y, MLV_COLOR_RED);
38 MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint3.x,pointToPrint3.y,MLV_COLOR_RED); 42 MLV_draw_line(pointToPrint1.x, pointToPrint1.y, pointToPrint3.x, pointToPrint3.y, MLV_COLOR_RED);
39 MLV_draw_line(pointToPrint3.x,pointToPrint3.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); 43 MLV_draw_line(pointToPrint3.x, pointToPrint3.y, pointToPrint2.x, pointToPrint2.y, MLV_COLOR_RED);
40 p = p->next; 44 p = p->next;
45 }
41 } 46 }