1 #include "automation.h"
5 #include "cwindowgui.h"
6 #include "dragcheckbox.h"
8 #include "edlsession.h"
14 DragCheckBox::DragCheckBox(MWindow *mwindow,
15 int x, int y, const char *text, int *value,
16 float drag_x, float drag_y, float drag_w, float drag_h)
17 : BC_CheckBox(x, y, value, text)
19 this->mwindow = mwindow;
20 this->drag_x = drag_x; this->drag_y = drag_y;
21 this->drag_w = drag_w; this->drag_h = drag_h;
22 drag_dx = drag_dy = 0;
28 DragCheckBox::~DragCheckBox()
33 void DragCheckBox::create_objects()
35 if( !drag_w ) drag_w = get_drag_track()->track_w;
36 if( !drag_h ) drag_h = get_drag_track()->track_h;
41 int DragCheckBox::handle_event()
43 int ret = BC_CheckBox::handle_event();
45 if( drag_activate() ) {
55 int DragCheckBox::drag_activate()
58 if( !grabbed && !(grabbed = grab(mwindow->cwindow->gui)) ) {
66 void DragCheckBox::drag_deactivate()
69 ungrab(mwindow->cwindow->gui);
76 int DragCheckBox::check_pending()
78 if( pending && !grab_event_count() ) {
85 int DragCheckBox::grab_event(XEvent *event)
87 switch( event->type ) {
88 case ButtonPress: break;
89 case ButtonRelease: break;
90 case MotionNotify: break;
92 return check_pending();
95 CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
96 CWindowCanvas *canvas = cwindow_gui->canvas;
97 int cx, cy; cwindow_gui->get_relative_cursor(cx, cy);
98 cx -= mwindow->theme->ccanvas_x;
99 cy -= mwindow->theme->ccanvas_y;
102 if( cx < 0 || cx >= mwindow->theme->ccanvas_w ||
103 cy < 0 || cy >= mwindow->theme->ccanvas_h )
104 return check_pending();
107 switch( event->type ) {
109 if( !dragging ) break;
112 if( !dragging ) return check_pending();
116 if( !dragging ) return check_pending();
119 return check_pending();
122 Track *track = get_drag_track();
123 if( !track ) return 0;
124 if( !drag_w ) drag_w = track->track_w;
125 if( !drag_h ) drag_h = track->track_h;
127 int64_t position = get_drag_position();
129 float cursor_x = cx, cursor_y = cy;
130 canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
131 float projector_x, projector_y, projector_z;
132 int track_w = track->track_w, track_h = track->track_h;
133 track->automation->get_projector(
134 &projector_x, &projector_y, &projector_z,
135 position, PLAY_FORWARD);
136 projector_x += mwindow->edl->session->output_w / 2;
137 projector_y += mwindow->edl->session->output_h / 2;
138 cursor_x = (cursor_x - projector_x) / projector_z + track_w / 2;
139 cursor_y = (cursor_y - projector_y) / projector_z + track_h / 2;
140 float r = MIN(track_w, track_h)/100.f + 2;
141 float x0 = drag_x, x1 = drag_x+(drag_w+1)/2, x2 = drag_x+drag_w;
142 float y0 = drag_y, y1 = drag_y+(drag_h+1)/2, y2 = drag_y+drag_h;
143 if( !dragging ) { // clockwise
144 if( fabs(drag_dx = cursor_x-x0) < r && // x0,y0
145 fabs(drag_dy = cursor_y-y0) < r ) dragging = 1;
146 else if( fabs(drag_dx = cursor_x-x1) < r && // x1,y0
147 fabs(drag_dy = cursor_y-y0) < r ) dragging = 2;
148 else if( fabs(drag_dx = cursor_x-x2) < r && // x2,y0
149 fabs(drag_dy = cursor_y-y0) < r ) dragging = 3;
150 else if( fabs(drag_dx = cursor_x-x2) < r && // x2,y1
151 fabs(drag_dy = cursor_y-y1) < r ) dragging = 4;
152 else if( fabs(drag_dx = cursor_x-x2) < r && // x2,y2
153 fabs(drag_dy = cursor_y-y2) < r ) dragging = 5;
154 else if( fabs(drag_dx = cursor_x-x1) < r && // x1,y2
155 fabs(drag_dy = cursor_y-y2) < r ) dragging = 6;
156 else if( fabs(drag_dx = cursor_x-x0) < r && // x0,y2
157 fabs(drag_dy = cursor_y-y2) < r ) dragging = 7;
158 else if( fabs(drag_dx = cursor_x-x0) < r && // x0,y1
159 fabs(drag_dy = cursor_y-y1) < r ) dragging = 8;
160 else if( fabs(drag_dx = cursor_x-x1) < r && // x1,y1
161 fabs(drag_dy = cursor_y-y1) < r ) dragging = 9;
164 int cur_x = cursor_x - drag_dx;
165 int cur_y = cursor_y - drag_dy;
168 float dx = cur_x - x0;
169 float dy = cur_y - y0;
170 if( !dx && !dy ) return 1;
171 if( (drag_w-=dx) < 1 ) drag_w = 1;
172 if( (drag_h-=dy) < 1 ) drag_h = 1;
173 drag_x = cur_x; drag_y = cur_y;
176 float dy = cur_y - y0;
179 if( (drag_h-=dy) < 1 ) drag_h = 1;
182 float dx = cur_x - x2;
183 float dy = cur_y - y0;
184 if( (drag_w+=dx) < 1 ) drag_w = 1;
185 if( (drag_h-=dy) < 1 ) drag_h = 1;
189 float dx = cur_x - x2;
191 if( (drag_w+=dx) < 1 ) drag_w = 1;
194 float dx = cur_x - x2;
195 float dy = cur_y - y2;
196 if( (drag_w+=dx) < 1 ) drag_w = 1;
197 if( (drag_h+=dy) < 1 ) drag_h = 1;
200 float dy = cur_y - y2;
202 if( (drag_h+=dy) < 1 ) drag_h = 1;
205 float dx = cur_x - x0;
206 float dy = cur_y - y2;
207 if( (drag_w-=dx) < 1 ) drag_w = 1;
208 if( (drag_h+=dy) < 1 ) drag_h = 1;
212 float dx = cur_x - x0;
214 if( (drag_w-=dx) < 1 ) drag_w = 1;
218 float dx = cur_x - x1;
219 float dy = cur_y - y1;
220 if( !dx && !dy ) return 1;
225 if( grab_event_count() )
227 else if( dragging ) {
234 void DragCheckBox::draw_boundary(VFrame *out,
235 int x, int y, int w, int h)
237 int iw = out->get_w(), ih = out->get_h();
238 int mr = MIN(iw, ih)/200 + 2, rr = 2*mr;
240 int x0 = x-r2, x1 = x+(w+1)/2, x2 = x+w+r2;
241 int y0 = y-r2, y1 = y+(h+1)/2, y2 = y+h+r2;
243 for( int r=2; r<mr; r<<=1 ) st = r;
246 for( int r=mr/2; --r>=0; ) { // bbox
247 int lft = x+r, rgt = x+w-1-r;
248 int top = y+r, bot = y+h-1-r;
249 out->draw_line(lft,top, rgt,top);
250 out->draw_line(rgt,top, rgt,bot);
251 out->draw_line(rgt,bot, lft,bot);
252 out->draw_line(lft,bot, lft,top);
255 for( int r=mr; r<rr; ++r ) { // center
256 out->draw_smooth(x1-r,y1, x1-r,y1+r, x1,y1+r);
257 out->draw_smooth(x1,y1+r, x1+r,y1+r, x1+r,y1);
258 out->draw_smooth(x1+r,y1, x1+r,y1-r, x1,y1-r);
259 out->draw_smooth(x1,y1-r, x1-r,y1-r, x1-r,y1);
262 for( int r=rr; --r>=0; ) { // edge arrows
263 out->draw_line(x1-r,y0+r, x1+r,y0+r);
264 out->draw_line(x2-r,y1-r, x2-r,y1+r);
265 out->draw_line(x1-r,y2-r, x1+r,y2-r);
266 out->draw_line(x0+r,y1+r, x0+r,y1-r);
268 x0 += r2; y0 += r2; x2 -= r2; y2 -= r2;
269 for( int r=2*mr; --r>=0; ) { // corner arrows
270 out->draw_line(x0,y0+r, x0+r,y0);
271 out->draw_line(x2,y0+r, x2-r,y0);
272 out->draw_line(x2,y2-r, x2-r,y2);
273 out->draw_line(x0,y2-r, x0+r,y2);