summaryrefslogtreecommitdiff
path: root/test/gui/pictureframe.c
blob: f1d90dfb129668002468c219d6a56696927ed4ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "gui/component.h"
#include "gui/window.h"
#include "common/mem.h"

extern Mode mode;

static void test_pictureframe() {
  Window *window = window_create(1005, 512, "Coucou");

  sprintf(labelFrame, "%03d frames", frame);
  Button *button1 = button_create("Add constraint point", 10, 0, 0, button_click_add_constraint);
  Button *button2 = button_create("Show/Hide", 10, 0, 0, button_click_show_hide);
  Button *button3 = button_create("Start rendering", 10, 0, 0, button_click_rendering);
  Button *button4 = button_create("<<<", 10, 0, 0, button_click_less_frame);
  Button *button5 = button_create(labelFrame, 10, 0, 0, button_click_none);
  Button *button6 = button_create(">>>", 10, 0, 0, button_click_more_frame);
  Button *button7 = button_create("Exit", 10, 0, 0, button_click_exit);


  Morphing *morphing = morphing_create(500, 250);
  Canvas *canvasSrc = canvas_create_from_image("/home/adam/Images/goku.png");
  Canvas *canvasTarget = canvas_create_from_image("/home/adam/Images/marty.jpg");

  PictureFrame *pictureFrame1 = pictureframe_create(500, 250, 0, 0, pictureframe_origin_split, morphing, canvasSrc,
                                                    pictureframe_click_handler_origin);
  PictureFrame *pictureFrame2 = pictureframe_create(500, 250, 0, 0, pictureframe_target_split, morphing, canvasTarget,
                                                    pictureframe_click_handler_target);

  window_add_pictureframe(window, pictureFrame1);
  window_add_pictureframe(window, pictureFrame2);

  window_add_button(window, button1);
  window_add_button(window, button2);
  window_add_button(window, button3);
  window_add_button(window, button4);
  window_add_button(window, button5);
  window_add_button(window, button6);
  window_add_button(window, button7);


  window_print_buttons(window);
  window_print_pictureframes(window);

  MLV_Keyboard_button keyboardButton;
  MLV_Keyboard_modifier keyboardModifier;
  int unicode;
  int mouse_x;
  int mouse_y;

  while (mode != EXITING) {
    window_click_keyboard_handler(window, &keyboardButton, &keyboardModifier, &unicode, &mouse_x, &mouse_y);
    switch (mode) {
      case PRINTING:
        window_print_pictureframes(window);
        mode = WAITING_BUTTON_SHOW;
        break;
      case WAITING_BUTTON_SHOW:
        window_print_pictureframes(window);
        break;
      case WAITING_BUTTON_HIDE:
        window_print_pictureframes(window);
        break;
      case PRINTING_BUTTONS:
        free(button5->label);
        button5->label = malloc_or_die(sizeof(char) * (strlen(labelFrame) + 1));
        strcpy(button5->label, labelFrame);
        window_print_buttons(window);
        mode = WAITING_BUTTON_SHOW;
        break;
      case RENDERING:
        window_rendering(window, pictureFrame1, canvasSrc, canvasTarget, morphing);
        break;
      case INSERT_TARGET:
        if (keyboardButton == MLV_KEYBOARD_ESCAPE) {
          window_print_pictureframes(window);
          mode = WAITING_BUTTON_SHOW;
        }
        break;
      default:
        break;
    }
  }

  button_destroy(button1);
  button_destroy(button2);
  button_destroy(button3);
  button_destroy(button4);
  button_destroy(button5);
  button_destroy(button6);
  button_destroy(button7);

  pictureframe_destroy(pictureFrame1);
  pictureframe_destroy(pictureFrame2);

  canvas_destroy(canvasSrc);
  canvas_destroy(canvasTarget);
  morphing_destroy(morphing);

  window_destroy(window);
}

int main() {
  test_pictureframe();
  return 0;
}