1 #include "bezierauto.h"
2 #include "bezierautos.h"
6 BezierAuto::BezierAuto(EDL *edl, BezierAutos *autos)
22 BezierAuto::~BezierAuto()
26 int BezierAuto::operator==(Auto &that)
28 return identical((BezierAuto*)&that);
31 int BezierAuto::operator==(BezierAuto &that)
33 return identical((BezierAuto*)&that);
36 int BezierAuto::identical(BezierAuto *src)
38 return EQUIV(center_x, src->center_x) &&
39 EQUIV(center_y, src->center_y) &&
40 EQUIV(center_z, src->center_z) &&
41 EQUIV(control_in_x, src->control_in_x) &&
42 EQUIV(control_in_y, src->control_in_y) &&
43 EQUIV(control_out_x, src->control_out_x) &&
44 EQUIV(control_out_y, src->control_out_y) &&
45 EQUIV(control_in_z, src->control_in_z) &&
46 EQUIV(control_out_z, src->control_out_z) ;
50 void BezierAuto::copy_from(Auto *that)
52 copy_from((BezierAuto*)that);
55 void BezierAuto::copy_from(BezierAuto *that)
57 Auto::copy_from(that);
59 center_x = that->center_x;
60 center_y = that->center_y;
61 center_z = that->center_z;
62 control_in_x = that->control_in_x;
63 control_in_y = that->control_in_y;
64 control_in_z = that->control_in_z;
65 control_out_x = that->control_out_x;
66 control_out_y = that->control_out_y;
67 control_out_z = that->control_out_z;
70 void BezierAuto::copy(int64_t start, int64_t end, FileXML *file, int default_auto)
72 file->tag.set_title("AUTO");
74 file->tag.set_property("POSITION", 0);
76 file->tag.set_property("POSITION", position - start);
77 file->tag.set_property("CENTER_X", center_x);
78 file->tag.set_property("CENTER_Y", center_y);
79 file->tag.set_property("CENTER_Z", center_z);
80 file->tag.set_property("CONTROL_IN_X", control_in_x);
81 file->tag.set_property("CONTROL_IN_Y", control_in_y);
82 file->tag.set_property("CONTROL_IN_Z", control_in_z);
83 file->tag.set_property("CONTROL_OUT_X", control_out_x);
84 file->tag.set_property("CONTROL_OUT_Y", control_out_y);
85 file->tag.set_property("CONTROL_OUT_Z", control_out_z);
87 file->append_newline();
90 void BezierAuto::load(FileXML *file)
92 center_x = file->tag.get_property("CENTER_X", (float)0);
93 center_y = file->tag.get_property("CENTER_Y", (float)0);
94 center_z = file->tag.get_property("CENTER_Z", (float)1);
95 control_in_x = file->tag.get_property("CONTROL_IN_X", (float)control_in_x);
96 control_in_y = file->tag.get_property("CONTROL_IN_Y", (float)control_in_y);
97 control_in_z = file->tag.get_property("CONTROL_IN_Z", (float)control_in_z);
98 control_out_x = file->tag.get_property("CONTROL_OUT_X", (float)control_out_x);
99 control_out_y = file->tag.get_property("CONTROL_OUT_Y", (float)control_out_y);
100 control_out_z = file->tag.get_property("CONTROL_OUT_Z", (float)control_out_z);
103 int BezierAuto::draw(BC_SubWindow *canvas,
110 show_value = 0; // skip drawing value for now
111 static int control_x[5], control_y[5];
114 get_control_points(x, center_pixel, scale, control_x, control_y, vertical);
116 // canvas->draw_disc(control_x[0] - WIDTH/2, control_y[0] - HEIGHT/2, WIDTH, HEIGHT);
117 for(i = 1; i < 5; i++)
119 // Draw zooms hollow and pan opaque.
121 canvas->draw_box(control_x[i] - WIDTH/2, control_y[i] - HEIGHT/2, WIDTH, HEIGHT);
123 canvas->draw_rectangle(control_x[i] - WIDTH/2, control_y[i] - HEIGHT/2, WIDTH, HEIGHT);
125 canvas->draw_line(control_x[i], control_y[i], control_x[0], control_y[0]);
128 if(show_value && ((BezierAutos*)autos)->selection_type > 1)
130 static char string[16];
131 static int text_x, text_y; // text position relative to canvas
133 value_to_str(string);
135 text_x = control_x[((BezierAutos*)autos)->selection_type - 2] + 20;
136 text_y = control_y[((BezierAutos*)autos)->selection_type - 2] + 20;
137 //canvas->set_font(SMALLFONT);
139 canvas->draw_text(text_x, text_y, string);
140 //canvas->set_font(MEDIUMFONT);
145 int BezierAuto::select(BC_SubWindow *canvas,
156 int control_x[5], control_y[5];
157 get_control_points(x, center_pixel, scale, control_x, control_y, vertical);
161 cursor_x ^= cursor_y;
162 cursor_y ^= cursor_x;
163 cursor_x ^= cursor_y;
168 // test control_in_xy
170 && test_control_point(control_x[0], control_y[0], control_x[1], control_y[1], cursor_x, cursor_y))
173 // test control_out_xy
175 && test_control_point(control_x[0], control_y[0], control_x[2], control_y[2], cursor_x, cursor_y))
178 // test control_in_zoom
180 && test_control_point(control_x[0], control_y[0], control_x[3], control_y[3], cursor_x, cursor_y))
183 // test control_out_zoom
185 && test_control_point(control_x[0], control_y[0], control_x[4], control_y[4], cursor_x, cursor_y))
189 if(cursor_x > control_x[0] - WIDTH/2 &&
190 cursor_x < control_x[0] + WIDTH/2 &&
191 cursor_y > control_y[0] - HEIGHT/2 &&
192 cursor_y < control_y[0] + HEIGHT/2)
194 if(mouse_button == 1)
199 return 1; // move frame
202 if(mouse_button == 3)
205 return 3; // move zoom
212 int BezierAuto::test_control_point(int center_x, int center_y, int x, int y, int cursor_x, int cursor_y)
214 if(cursor_x > x - WIDTH/2 &&
215 cursor_x < x + WIDTH/2 &&
216 cursor_y > y - HEIGHT/2 &&
217 cursor_y < y + HEIGHT/2) return 1;
219 // if(((x > center_x) ? cursor_x > center_x - WIDTH/2 : cursor_x > x - WIDTH/2) &&
220 // ((x > center_x) ? cursor_x < x + WIDTH/2 : x < center_x + WIDTH/2) &&
221 // ((y > center_y) ? cursor_y > center_y - HEIGHT/2 : cursor_y > y - HEIGHT/2) &&
222 // ((y > center_y) ? cursor_y < y - HEIGHT/2 : cursor_y < center_y + HEIGHT/2))
224 // float A = cursor_x - center_x;
225 // float B = cursor_y - center_y;
226 // float C = x - center_x;
227 // float D = y - center_y;
228 // float dist = (A * D - B * C) / sqrt(C * C + D * D);
230 // printf("%f\n", dist);
231 // if(dist < WIDTH / 2) return 1;
237 float BezierAuto::get_distance(int x1, int y1, int x2, int y2)
239 return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
242 int BezierAuto::get_control_points(int x, int center_pixel, float scale, int *control_x, int *control_y, int vertical)
244 // get control point locations relative to canvas
245 int y = center_pixel;
253 zoom_scale = ((BezierAutos*)autos)->frame_h * scale;
259 control_x[1] = (int)(control_in_x * scale + x);
260 control_y[1] = (int)(control_in_y * scale + y);
262 control_x[2] = (int)(control_out_x * scale + x);
263 control_y[2] = (int)(control_out_y * scale + y);
265 control_x[3] = (int)x;
266 control_y[3] = (int)(control_in_z * zoom_scale + y);
267 //printf("BezierAuto::get_control_points %d %f %f %d\n", control_y[3], control_in_z, scale, y);
269 control_x[4] = (int)x;
270 control_y[4] = (int)(control_out_z * zoom_scale + y);
273 int BezierAuto::value_to_str(char *string)
276 if(((BezierAutos*)autos)->frame_w)
277 switch(((BezierAutos*)autos)->selection_type)
280 sprintf(string, "%.0f, %.0f", center_x, center_y);
284 sprintf(string, "%.0f, %.0f", control_in_x, control_in_y);
288 sprintf(string, "%.0f, %.0f", control_out_x, control_out_y);
292 switch(((BezierAutos*)autos)->selection_type)
295 sprintf(string, "%.0f", center_y);
299 sprintf(string, "%.0f", control_in_y);
303 sprintf(string, "%.0f", control_out_y);