summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAdam NAILI2018-01-01 23:36:39 +0100
committerAdam NAILI2018-01-01 23:36:39 +0100
commitff2d78256b6b2288e9a5954a49fe4babaf6400cb (patch)
treeed10145f7f49c949a57a19597251c576ef0ac5c1 /src/gui
parent8565b20b86a489b09f611ed1cd3b0ba7ac23a94a (diff)
downloadmorpher-ff2d78256b6b2288e9a5954a49fe4babaf6400cb.tar.gz
Implementing rendering
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/button.c18
-rw-r--r--src/gui/gui.c4
-rw-r--r--src/gui/pictureframe.c18
-rw-r--r--src/gui/window.c33
4 files changed, 45 insertions, 28 deletions
diff --git a/src/gui/button.c b/src/gui/button.c
index 03addf8..a55796d 100644
--- a/src/gui/button.c
+++ b/src/gui/button.c
@@ -7,8 +7,6 @@
7#include <gui/component.h> 7#include <gui/component.h>
8 8
9bool button_is_selected(int x, int y, Button *button) { 9bool button_is_selected(int x, int y, Button *button) {
10 assert(x >= 0);
11 assert(y >= 0);
12 assert(button != NULL); 10 assert(button != NULL);
13 int x1 = button->component.x_pos; 11 int x1 = button->component.x_pos;
14 int y1 = button->component.y_pos; 12 int y1 = button->component.y_pos;
@@ -28,8 +26,6 @@ void button_print(Component *parameterSelf) {
28} 26}
29 27
30void button_click_test(int x, int y, Component *parameterSelf) { 28void button_click_test(int x, int y, Component *parameterSelf) {
31 assert(x >= 0);
32 assert(y >= 0);
33 assert(parameterSelf != NULL); 29 assert(parameterSelf != NULL);
34 Button *self = (Button *) parameterSelf; 30 Button *self = (Button *) parameterSelf;
35 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { 31 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
@@ -37,8 +33,6 @@ void button_click_test(int x, int y, Component *parameterSelf) {
37} 33}
38 34
39void button_click_add_constraint(int x, int y, Component *parameterSelf) { 35void button_click_add_constraint(int x, int y, Component *parameterSelf) {
40 assert(x >= 0);
41 assert(y >= 0);
42 assert(parameterSelf != NULL); 36 assert(parameterSelf != NULL);
43 Button *self = (Button *) parameterSelf; 37 Button *self = (Button *) parameterSelf;
44 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { 38 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
@@ -47,8 +41,6 @@ void button_click_add_constraint(int x, int y, Component *parameterSelf) {
47} 41}
48 42
49void button_click_show_hide(int x, int y, Component *parameterSelf) { 43void button_click_show_hide(int x, int y, Component *parameterSelf) {
50 assert(x >= 0);
51 assert(y >= 0);
52 assert(parameterSelf != NULL); 44 assert(parameterSelf != NULL);
53 Button *self = (Button *) parameterSelf; 45 Button *self = (Button *) parameterSelf;
54 if (button_is_selected(x, y, self)) { 46 if (button_is_selected(x, y, self)) {
@@ -61,8 +53,6 @@ void button_click_show_hide(int x, int y, Component *parameterSelf) {
61} 53}
62 54
63void button_click_exit(int x, int y, Component *parameterSelf) { 55void button_click_exit(int x, int y, Component *parameterSelf) {
64 assert(x >= 0);
65 assert(y >= 0);
66 assert(parameterSelf != NULL); 56 assert(parameterSelf != NULL);
67 Button *self = (Button *) parameterSelf; 57 Button *self = (Button *) parameterSelf;
68 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { 58 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
@@ -71,8 +61,6 @@ void button_click_exit(int x, int y, Component *parameterSelf) {
71} 61}
72 62
73void button_click_less_frame(int x, int y, Component *parameterSelf) { 63void button_click_less_frame(int x, int y, Component *parameterSelf) {
74 assert(x >= 0);
75 assert(y >= 0);
76 assert(parameterSelf != NULL); 64 assert(parameterSelf != NULL);
77 Button *self = (Button *) parameterSelf; 65 Button *self = (Button *) parameterSelf;
78 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { 66 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
@@ -85,8 +73,6 @@ void button_click_less_frame(int x, int y, Component *parameterSelf) {
85} 73}
86 74
87void button_click_more_frame(int x, int y, Component *parameterSelf) { 75void button_click_more_frame(int x, int y, Component *parameterSelf) {
88 assert(x >= 0);
89 assert(y >= 0);
90 assert(parameterSelf != NULL); 76 assert(parameterSelf != NULL);
91 Button *self = (Button *) parameterSelf; 77 Button *self = (Button *) parameterSelf;
92 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { 78 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
@@ -99,8 +85,6 @@ void button_click_more_frame(int x, int y, Component *parameterSelf) {
99} 85}
100 86
101void button_click_rendering(int x,int y, Component *parameterSelf) { 87void button_click_rendering(int x,int y, Component *parameterSelf) {
102 assert(x >= 0);
103 assert(y >= 0);
104 assert(parameterSelf != NULL); 88 assert(parameterSelf != NULL);
105 Button *self = (Button *) parameterSelf; 89 Button *self = (Button *) parameterSelf;
106 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { 90 if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) {
@@ -109,8 +93,6 @@ void button_click_rendering(int x,int y, Component *parameterSelf) {
109} 93}
110 94
111void button_click_none(int x, int y, Component *parameterSelf) { 95void button_click_none(int x, int y, Component *parameterSelf) {
112 assert(x >= 0);
113 assert(y >= 0);
114 assert(parameterSelf != NULL); 96 assert(parameterSelf != NULL);
115} 97}
116 98
diff --git a/src/gui/gui.c b/src/gui/gui.c
new file mode 100644
index 0000000..2a3d018
--- /dev/null
+++ b/src/gui/gui.c
@@ -0,0 +1,4 @@
1//
2// Created by adam on 01/01/18.
3//
4
diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c
index 4126f59..a6a94bf 100644
--- a/src/gui/pictureframe.c
+++ b/src/gui/pictureframe.c
@@ -17,7 +17,7 @@ void pictureframe_draw_canvas(PictureFrame *pictureFrame){
17void pictureframe_print(Component *parameterSelf) { 17void pictureframe_print(Component *parameterSelf) {
18 PictureFrame *self = (PictureFrame *) parameterSelf; 18 PictureFrame *self = (PictureFrame *) parameterSelf;
19 pictureframe_draw_canvas(self); 19 pictureframe_draw_canvas(self);
20 if (mode != WAITING_BUTTON_HIDE) { 20 if (mode != WAITING_BUTTON_HIDE && mode != RENDERING) {
21 TriangleMap *p = self->morphing->first; 21 TriangleMap *p = self->morphing->first;
22 CartesianVector p1; 22 CartesianVector p1;
23 CartesianVector p2; 23 CartesianVector p2;
@@ -30,9 +30,9 @@ void pictureframe_print(Component *parameterSelf) {
30 p2 = self->cartesianMappingDivision(&(p->vertices[1])); 30 p2 = self->cartesianMappingDivision(&(p->vertices[1]));
31 p3 = self->cartesianMappingDivision(&(p->vertices[2])); 31 p3 = self->cartesianMappingDivision(&(p->vertices[2]));
32 32
33 pointToPrint1 = pictureframe_conversion_to_picture(p1.x, p1.y, self); 33 pointToPrint1 = pictureframe_conversion_to_origin(p1.x, p1.y, self);
34 pointToPrint2 = pictureframe_conversion_to_picture(p2.x, p2.y, self); 34 pointToPrint2 = pictureframe_conversion_to_origin(p2.x, p2.y, self);
35 pointToPrint3 = pictureframe_conversion_to_picture(p3.x, p3.y, self); 35 pointToPrint3 = pictureframe_conversion_to_origin(p3.x, p3.y, self);
36 36
37 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);
38 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);
@@ -47,8 +47,6 @@ void pictureframe_print(Component *parameterSelf) {
47} 47}
48 48
49bool pictureframe_is_selected(int x, int y, PictureFrame *pictureFrame) { 49bool pictureframe_is_selected(int x, int y, PictureFrame *pictureFrame) {
50 assert(x >= 0);
51 assert(y >= 0);
52 assert(pictureFrame != NULL); 50 assert(pictureFrame != NULL);
53 int x1 = pictureFrame->component.x_pos; 51 int x1 = pictureFrame->component.x_pos;
54 int y1 = pictureFrame->component.y_pos; 52 int y1 = pictureFrame->component.y_pos;
@@ -60,14 +58,14 @@ bool pictureframe_is_selected(int x, int y, PictureFrame *pictureFrame) {
60 return false; 58 return false;
61} 59}
62 60
63CartesianVector pictureframe_conversion_to_origin(int x, int y, PictureFrame *pictureFrame) { 61CartesianVector pictureframe_conversion_to_pic(int x, int y, PictureFrame *pictureFrame) {
64 CartesianVector vector; 62 CartesianVector vector;
65 vector.x = x - pictureFrame->component.x_pos; 63 vector.x = x - pictureFrame->component.x_pos;
66 vector.y = y - pictureFrame->component.y_pos; 64 vector.y = y - pictureFrame->component.y_pos;
67 return vector; 65 return vector;
68} 66}
69 67
70CartesianVector pictureframe_conversion_to_picture(int x, int y, PictureFrame *pictureFrame) { 68CartesianVector pictureframe_conversion_to_origin(int x, int y, PictureFrame *pictureFrame) {
71 CartesianVector vector; 69 CartesianVector vector;
72 vector.x = x + pictureFrame->component.x_pos; 70 vector.x = x + pictureFrame->component.x_pos;
73 vector.y = y + pictureFrame->component.y_pos; 71 vector.y = y + pictureFrame->component.y_pos;
@@ -77,7 +75,7 @@ CartesianVector pictureframe_conversion_to_picture(int x, int y, PictureFrame *p
77void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) { 75void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) {
78 PictureFrame *self = (PictureFrame *) parameterSelf; 76 PictureFrame *self = (PictureFrame *) parameterSelf;
79 if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_ORIGIN) { 77 if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_ORIGIN) {
80 CartesianVector vector = pictureframe_conversion_to_origin(x_pos, y_pos, self); 78 CartesianVector vector = pictureframe_conversion_to_pic(x_pos, y_pos, self);
81 MLV_draw_filled_circle(x_pos, y_pos, 2, MLV_COLOR_BLUE); 79 MLV_draw_filled_circle(x_pos, y_pos, 2, MLV_COLOR_BLUE);
82 savedPoint = vector; 80 savedPoint = vector;
83 MLV_actualise_window(); 81 MLV_actualise_window();
@@ -88,7 +86,7 @@ void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *paramete
88void pictureframe_click_handler_target(int x_pos, int y_pos, Component *parameterSelf) { 86void pictureframe_click_handler_target(int x_pos, int y_pos, Component *parameterSelf) {
89 PictureFrame *self = (PictureFrame *) parameterSelf; 87 PictureFrame *self = (PictureFrame *) parameterSelf;
90 if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_TARGET) { 88 if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_TARGET) {
91 CartesianVector vector = pictureframe_conversion_to_origin(x_pos, y_pos, self); 89 CartesianVector vector = pictureframe_conversion_to_pic(x_pos, y_pos, self);
92 morphing_add_constraint(self->morphing, savedPoint, vector); 90 morphing_add_constraint(self->morphing, savedPoint, vector);
93 mode = PRINTING; 91 mode = PRINTING;
94 } 92 }
diff --git a/src/gui/window.c b/src/gui/window.c
index 6e287e5..32aeb26 100644
--- a/src/gui/window.c
+++ b/src/gui/window.c
@@ -3,6 +3,10 @@
3#include <gui/button.h> 3#include <gui/button.h>
4#include <gui/pictureframe.h> 4#include <gui/pictureframe.h>
5#include <gui/group.h> 5#include <gui/group.h>
6#include <MLV/MLV_keyboard.h>
7#include <MLV/MLV_all.h>
8#include <caca_conio.h>
9#include <painter/rasterizer.h>
6#include "common/mem.h" 10#include "common/mem.h"
7#include "string.h" 11#include "string.h"
8#include "assert.h" 12#include "assert.h"
@@ -57,4 +61,33 @@ void window_print_pictureframes(Window *window) {
57 assert(window != NULL); 61 assert(window != NULL);
58 window->group_pictureframe->component.print_method(&(window->group_pictureframe->component)); 62 window->group_pictureframe->component.print_method(&(window->group_pictureframe->component));
59 MLV_actualise_window(); 63 MLV_actualise_window();
64}
65
66void window_wait_keyboard_or_mouse(MLV_Keyboard_button *keyboardButton, MLV_Keyboard_modifier *keyboardModifier,
67 int *unicode, int *mouse_x, int *mouse_y) {
68 *mouse_x = -1;
69 *mouse_y = -1;
70 *keyboardButton = MLV_KEYBOARD_NONE;
71 MLV_wait_keyboard_or_mouse(keyboardButton, keyboardModifier, unicode, mouse_x, mouse_y);
72}
73
74void window_click_keyboard_handler(Window *window, MLV_Keyboard_button *keyboardButton,
75 MLV_Keyboard_modifier *keyboardModifier,
76 int *unicode, int *mouse_x, int *mouse_y) {
77 window_wait_keyboard_or_mouse(keyboardButton,keyboardModifier,unicode,mouse_x,mouse_y);
78 group_click_handler(*mouse_x, *mouse_y, &(window->group_buttons->component));
79 group_click_handler(*mouse_x, *mouse_y, &(window->group_pictureframe->component));
80}
81
82void window_rendering(Window *window,PictureFrame *pictureFrame1,Canvas *canvasSrc, Canvas *canvasTarget, Morphing *morphing){