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;
166 int cur_x = cursor_x - drag_dx;
167 int cur_y = cursor_y - drag_dy;
170 float dx = cur_x - x0;
171 float dy = cur_y - y0;
172 if( !dx && !dy ) return 1;
173 if( (drag_w-=dx) < 1 ) drag_w = 1;
174 if( (drag_h-=dy) < 1 ) drag_h = 1;
175 drag_x = cur_x; drag_y = cur_y;
178 float dy = cur_y - y0;
181 if( (drag_h-=dy) < 1 ) drag_h = 1;
184 float dx = cur_x - x2;
185 float dy = cur_y - y0;
186 if( (drag_w+=dx) < 1 ) drag_w = 1;
187 if( (drag_h-=dy) < 1 ) drag_h = 1;
191 float dx = cur_x - x2;
193 if( (drag_w+=dx) < 1 ) drag_w = 1;
196 float dx = cur_x - x2;
197 float dy = cur_y - y2;
198 if( (drag_w+=dx) < 1 ) drag_w = 1;
199 if( (drag_h+=dy) < 1 ) drag_h = 1;
202 float dy = cur_y - y2;
204 if( (drag_h+=dy) < 1 ) drag_h = 1;
207 float dx = cur_x - x0;
208 float dy = cur_y - y2;
209 if( (drag_w-=dx) < 1 ) drag_w = 1;
210 if( (drag_h+=dy) < 1 ) drag_h = 1;
214 float dx = cur_x - x0;
216 if( (drag_w-=dx) < 1 ) drag_w = 1;
220 float dx = cur_x - x1;
221 float dy = cur_y - y1;
222 if( !dx && !dy ) return 1;
227 if( grab_event_count() )
229 else if( dragging ) {
237 void DragCheckBox::bound()
239 Track *track = get_drag_track();
240 int trk_w = track->track_w, trk_h = track->track_h;
241 float x1 = drag_x, x2 = x1 + drag_w;
242 float y1 = drag_y, y2 = y1 + drag_h;
243 bclamp(x1, 0, trk_w); bclamp(x2, 0, trk_w);
244 bclamp(y1, 0, trk_h); bclamp(y2, 0, trk_h);
245 if( x1 >= x2 ) { if( x2 > 0 ) x1 = x2-1; else x2 = (x1=0)+1; }
246 if( y1 >= y2 ) { if( x2 > 0 ) y1 = y2-1; else y2 = (y1=0)+1; }
247 drag_x = x1; drag_y = y1; drag_w = x2-x1; drag_h = y2-y1;
250 void DragCheckBox::draw_boundary(VFrame *out,
251 int x, int y, int w, int h)
253 int iw = out->get_w(), ih = out->get_h();
254 int mr = MIN(iw, ih)/200 + 2, rr = 2*mr;
256 int x0 = x-r2, x1 = x+(w+1)/2, x2 = x+w+r2;
257 int y0 = y-r2, y1 = y+(h+1)/2, y2 = y+h+r2;
259 for( int r=2; r<mr; r<<=1 ) st = r;
262 for( int r=mr/2; --r>=0; ) { // bbox
263 int lft = x+r, rgt = x+w-1-r;
264 int top = y+r, bot = y+h-1-r;
265 out->draw_line(lft,top, rgt,top);
266 out->draw_line(rgt,top, rgt,bot);
267 out->draw_line(rgt,bot, lft,bot);
268 out->draw_line(lft,bot, lft,top);
271 for( int r=mr; r<rr; ++r ) { // center
272 out->draw_smooth(x1-r,y1, x1-r,y1+r, x1,y1+r);
273 out->draw_smooth(x1,y1+r, x1+r,y1+r, x1+r,y1);
274 out->draw_smooth(x1+r,y1, x1+r,y1-r, x1,y1-r);
275 out->draw_smooth(x1,y1-r, x1-r,y1-r, x1-r,y1);
278 for( int r=rr; --r>=0; ) { // edge arrows
279 out->draw_line(x1-r,y0+r, x1+r,y0+r);
280 out->draw_line(x2-r,y1-r, x2-r,y1+r);
281 out->draw_line(x1-r,y2-r, x1+r,y2-r);
282 out->draw_line(x0+r,y1+r, x0+r,y1-r);
284 x0 += r2; y0 += r2; x2 -= r2; y2 -= r2;
285 for( int r=2*mr; --r>=0; ) { // corner arrows
286 out->draw_line(x0,y0+r, x0+r,y0);
287 out->draw_line(x2,y0+r, x2-r,y0);
288 out->draw_line(x2,y2-r, x2-r,y2);
289 out->draw_line(x0,y2-r, x0+r,y2);