From 41da8b54ed619ea869ca286cd8ec02e105e21c19 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 31 Dec 2017 15:00:23 +0100 Subject: Implementing all kinds of buttons. Rendering to fix --- src/gui/button.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++--- src/gui/component.c | 6 +++- src/gui/pictureframe.c | 64 ++++++++++++++++++++++-------------------- 3 files changed, 110 insertions(+), 35 deletions(-) (limited to 'src') 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) { assert(y >= 0); assert(parameterSelf != NULL); Button *self = (Button *) parameterSelf; - if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { - printf("OK\n"); + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { } } -void button_click_add_constraint(int x, int y, Component *parameterSelf){ +void button_click_add_constraint(int x, int y, Component *parameterSelf) { assert(x >= 0); assert(y >= 0); assert(parameterSelf != NULL); Button *self = (Button *) parameterSelf; - if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { mode = INSERT_ORIGIN; } } +void button_click_show_hide(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self)) { + if (mode == WAITING_BUTTON_SHOW) { + mode = WAITING_BUTTON_HIDE; + } else if (mode == WAITING_BUTTON_HIDE) { + mode = WAITING_BUTTON_SHOW; + } + } +} + +void button_click_exit(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { + mode = EXITING; + } +} + +void button_click_less_frame(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { + if (frame > 2) { + frame = frame / 2; + sprintf(labelFrame,"%03d frames", frame); + mode = PRINTING_BUTTONS; + } + } +} + +void button_click_more_frame(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { + if (frame < 256) { + frame = frame * 2; + sprintf(labelFrame,"%03d frames", frame); + mode = PRINTING_BUTTONS; + } + } +} + +void button_click_rendering(int x,int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { + mode = RENDERING; + } +} + +void button_click_none(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); +} + void button_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 @@ #include -Mode mode = WAITING_BUTTON; +Mode mode = WAITING_BUTTON_SHOW; + +int frame = 2; + +char 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 @@ #include #include #include -#include CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { return cartesianMapping->origin; @@ -11,33 +10,39 @@ CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMappi return cartesianMapping->target; } +void pictureframe_draw_canvas(PictureFrame *pictureFrame){ + MLV_draw_image(pictureFrame->canvas->mlv, pictureFrame->component.x_pos, pictureFrame->component.y_pos); +} + void pictureframe_print(Component *parameterSelf) { PictureFrame *self = (PictureFrame *) parameterSelf; - MLV_draw_image(self->canvas->mlv, self->component.x_pos, self->component.y_pos); - TriangleMap *p = self->morphing->first; - CartesianVector p1; - CartesianVector p2; - CartesianVector p3; - CartesianVector pointToPrint1; - CartesianVector pointToPrint2; - CartesianVector pointToPrint3; - while(p != NULL){ - p1 = self->cartesianMappingDivision(&(p->vertices[0])); - p2 = self->cartesianMappingDivision(&(p->vertices[1])); - p3 = self->cartesianMappingDivision(&(p->vertices[2])); + pictureframe_draw_canvas(self); + if (mode != WAITING_BUTTON_HIDE) { + TriangleMap *p = self->morphing->first; + CartesianVector p1; + CartesianVector p2; + CartesianVector p3; + CartesianVector pointToPrint1; + CartesianVector pointToPrint2; + CartesianVector pointToPrint3; + while (p != NULL) { + p1 = self->cartesianMappingDivision(&(p->vertices[0])); + p2 = self->cartesianMappingDivision(&(p->vertices[1])); + p3 = self->cartesianMappingDivision(&(p->vertices[2])); - pointToPrint1 = pictureframe_conversion_to_picture(p1.x,p1.y,self); - pointToPrint2 = pictureframe_conversion_to_picture(p2.x,p2.y,self); - pointToPrint3 = pictureframe_conversion_to_picture(p3.x,p3.y,self); + pointToPrint1 = pictureframe_conversion_to_picture(p1.x, p1.y, self); + pointToPrint2 = pictureframe_conversion_to_picture(p2.x, p2.y, self); + pointToPrint3 = pictureframe_conversion_to_picture(p3.x, p3.y, self); - MLV_draw_filled_circle(pointToPrint1.x,pointToPrint1.y,2,MLV_COLOR_RED); - MLV_draw_filled_circle(pointToPrint2.x,pointToPrint2.y,2,MLV_COLOR_RED); - MLV_draw_filled_circle(pointToPrint3.x,pointToPrint3.y,2,MLV_COLOR_RED); + MLV_draw_filled_circle(pointToPrint1.x, pointToPrint1.y, 2, MLV_COLOR_RED); + MLV_draw_filled_circle(pointToPrint2.x, pointToPrint2.y, 2, MLV_COLOR_RED); + MLV_draw_filled_circle(pointToPrint3.x, pointToPrint3.y, 2, MLV_COLOR_RED); - MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); - MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint3.x,pointToPrint3.y,MLV_COLOR_RED); - MLV_draw_line(pointToPrint3.x,pointToPrint3.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); - p = p->next; + MLV_draw_line(pointToPrint1.x, pointToPrint1.y, pointToPrint2.x, pointToPrint2.y, MLV_COLOR_RED); + MLV_draw_line(pointToPrint1.x, pointToPrint1.y, pointToPrint3.x, pointToPrint3.y, MLV_COLOR_RED); + MLV_draw_line(pointToPrint3.x, pointToPrint3.y, pointToPrint2.x, pointToPrint2.y, MLV_COLOR_RED); + p = p->next; + } } } @@ -72,8 +77,8 @@ CartesianVector pictureframe_conversion_to_picture(int x, int y, PictureFrame *p void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) { PictureFrame *self = (PictureFrame *) parameterSelf; if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_ORIGIN) { - CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); - MLV_draw_filled_circle(x_pos,y_pos,2,MLV_COLOR_BLUE); + CartesianVector vector = pictureframe_conversion_to_origin(x_pos, y_pos, self); + MLV_draw_filled_circle(x_pos, y_pos, 2, MLV_COLOR_BLUE); savedPoint = vector; MLV_actualise_window(); mode = INSERT_TARGET; @@ -83,16 +88,15 @@ void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *paramete void pictureframe_click_handler_target(int x_pos, int y_pos, Component *parameterSelf) { PictureFrame *self = (PictureFrame *) parameterSelf; if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_TARGET) { - CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); - printf("(%d,%d) | (%d,%d)\n",savedPoint.x,savedPoint.y,vector.x,vector.y); - morphing_add_constraint(self->morphing,savedPoint,vector); - printf("OK\n"); + CartesianVector vector = pictureframe_conversion_to_origin(x_pos, y_pos, self); + morphing_add_constraint(self->morphing, savedPoint, vector); mode = PRINTING; } } void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, - CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas,ClickHandler clickHandler) { + CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas, + ClickHandler clickHandler) { assert(pictureFrame != NULL); assert(width > 0); assert(height > 0); -- cgit v1.2.3