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 int DragCheckBox::get_track_w()
35 Track *track = get_drag_track();
36 return track ? track->track_w : mwindow->edl->session->output_w;
38 int DragCheckBox::get_track_h()
40 Track *track = get_drag_track();
41 return track ? track->track_h : mwindow->edl->session->output_h;
44 void DragCheckBox::create_objects()
46 if( !drag_w ) drag_w = get_track_w();
47 if( !drag_h ) drag_h = get_track_h();
52 int DragCheckBox::handle_event()
54 int ret = BC_CheckBox::handle_event();
56 if( drag_activate() ) {
66 int DragCheckBox::drag_activate()
69 if( !grabbed && !(grabbed = grab(mwindow->cwindow->gui)) ) {
77 void DragCheckBox::drag_deactivate()
80 ungrab(mwindow->cwindow->gui);
87 int DragCheckBox::handle_ungrab()
95 int DragCheckBox::check_pending()
97 if( pending && !grab_event_count() ) {
104 int DragCheckBox::grab_event(XEvent *event)
106 switch( event->type ) {
107 case ButtonPress: break;
108 case ButtonRelease: break;
109 case MotionNotify: break;
111 return check_pending();
114 CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
115 CWindowCanvas *canvas = cwindow_gui->canvas;
116 int cx, cy; cwindow_gui->get_relative_cursor(cx, cy);
117 cx -= mwindow->theme->ccanvas_x;
118 cy -= mwindow->theme->ccanvas_y;
121 if( cx < 0 || cx >= mwindow->theme->ccanvas_w ||
122 cy < 0 || cy >= mwindow->theme->ccanvas_h )
123 return check_pending();
126 switch( event->type ) {
128 if( !dragging ) break;
131 if( !dragging ) return check_pending();
135 if( !dragging ) return check_pending();
138 return check_pending();
141 int track_w = get_track_w(), track_h = get_track_h();
142 if( !drag_w ) drag_w = track_w;
143 if( !drag_h ) drag_h = track_h;
145 int64_t position = get_drag_position();
146 float cursor_x = cx, cursor_y = cy;
147 canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
148 float projector_x, projector_y, projector_z;
149 Track *track = get_drag_track();
151 track->automation->get_projector(
152 &projector_x, &projector_y, &projector_z,
153 position, PLAY_FORWARD);
154 projector_x += mwindow->edl->session->output_w / 2;
155 projector_y += mwindow->edl->session->output_h / 2;
156 cursor_x = (cursor_x - projector_x) / projector_z + track_w / 2;
157 cursor_y = (cursor_y - projector_y) / projector_z + track_h / 2;
159 float r = MIN(track_w, track_h)/100.f + 2;
160 float x0 = drag_x, x1 = drag_x+(drag_w+1)/2, x2 = drag_x+drag_w;
161 float y0 = drag_y, y1 = drag_y+(drag_h+1)/2, y2 = drag_y+drag_h;
162 if( !dragging ) { // clockwise
163 if( fabs(drag_dx = cursor_x-x0) < r && // x0,y0
164 fabs(drag_dy = cursor_y-y0) < r ) dragging = 1;
165 else if( fabs(drag_dx = cursor_x-x1) < r && // x1,y0
166 fabs(drag_dy = cursor_y-y0) < r ) dragging = 2;
167 else if( fabs(drag_dx = cursor_x-x2) < r && // x2,y0
168 fabs(drag_dy = cursor_y-y0) < r ) dragging = 3;
169 else if( fabs(drag_dx = cursor_x-x2) < r && // x2,y1
170 fabs(drag_dy = cursor_y-y1) < r ) dragging = 4;
171 else if( fabs(drag_dx = cursor_x-x2) < r && // x2,y2
172 fabs(drag_dy = cursor_y-y2) < r ) dragging = 5;
173 else if( fabs(drag_dx = cursor_x-x1) < r && // x1,y2
174 fabs(drag_dy = cursor_y-y2) < r ) dragging = 6;
175 else if( fabs(drag_dx = cursor_x-x0) < r && // x0,y2
176 fabs(drag_dy = cursor_y-y2) < r ) dragging = 7;
177 else if( fabs(drag_dx = cursor_x-x0) < r && // x0,y1
178 fabs(drag_dy = cursor_y-y1) < r ) dragging = 8;
179 else if( fabs(drag_dx = cursor_x-x1) < r && // x1,y1
180 fabs(drag_dy = cursor_y-y1) < r ) dragging = 9;
185 int cur_x = cursor_x - drag_dx;
186 int cur_y = cursor_y - drag_dy;
189 float dx = cur_x - x0;
190 float dy = cur_y - y0;
191 if( !dx && !dy ) return 1;
192 if( (drag_w-=dx) < 1 ) drag_w = 1;
193 if( (drag_h-=dy) < 1 ) drag_h = 1;
194 drag_x = cur_x; drag_y = cur_y;
197 float dy = cur_y - y0;
200 if( (drag_h-=dy) < 1 ) drag_h = 1;
203 float dx = cur_x - x2;
204 float dy = cur_y - y0;
205 if( (drag_w+=dx) < 1 ) drag_w = 1;
206 if( (drag_h-=dy) < 1 ) drag_h = 1;
210 float dx = cur_x - x2;
212 if( (drag_w+=dx) < 1 ) drag_w = 1;
215 float dx = cur_x - x2;
216 float dy = cur_y - y2;
217 if( (drag_w+=dx) < 1 ) drag_w = 1;
218 if( (drag_h+=dy) < 1 ) drag_h = 1;
221 float dy = cur_y - y2;
223 if( (drag_h+=dy) < 1 ) drag_h = 1;
226 float dx = cur_x - x0;
227 float dy = cur_y - y2;
228 if( (drag_w-=dx) < 1 ) drag_w = 1;
229 if( (drag_h+=dy) < 1 ) drag_h = 1;
233 float dx = cur_x - x0;
235 if( (drag_w-=dx) < 1 ) drag_w = 1;
239 float dx = cur_x - x1;
240 float dy = cur_y - y1;
241 if( !dx && !dy ) return 1;
246 if( grab_event_count() )
248 else if( dragging ) {
256 void DragCheckBox::bound()
258 int trk_w = get_track_w(), trk_h = get_track_h();
259 float x1 = drag_x, x2 = x1 + drag_w;
260 float y1 = drag_y, y2 = y1 + drag_h;
261 bclamp(x1, 0, trk_w); bclamp(x2, 0, trk_w);
262 bclamp(y1, 0, trk_h); bclamp(y2, 0, trk_h);
263 if( x1 >= x2 ) { if( x2 > 0 ) x1 = x2-1; else x2 = (x1=0)+1; }
264 if( y1 >= y2 ) { if( x2 > 0 ) y1 = y2-1; else y2 = (y1=0)+1; }
265 drag_x = x1; drag_y = y1; drag_w = x2-x1; drag_h = y2-y1;
268 void DragCheckBox::draw_boundary(VFrame *out,
269 int x, int y, int w, int h)
271 int iw = out->get_w(), ih = out->get_h();
272 int mr = MIN(iw, ih)/200 + 2, rr = 2*mr;
274 int x0 = x-r2, x1 = x+(w+1)/2, x2 = x+w+r2;
275 int y0 = y-r2, y1 = y+(h+1)/2, y2 = y+h+r2;
277 for( int r=2; r<mr; r<<=1 ) st = r;
280 for( int r=mr/2; --r>=0; ) { // bbox
281 int lft = x+r, rgt = x+w-1-r;
282 int top = y+r, bot = y+h-1-r;
283 out->draw_line(lft,top, rgt,top);
284 out->draw_line(rgt,top, rgt,bot);
285 out->draw_line(rgt,bot, lft,bot);
286 out->draw_line(lft,bot, lft,top);
289 for( int r=mr; r<rr; ++r ) { // center
290 out->draw_smooth(x1-r,y1, x1-r,y1+r, x1,y1+r);
291 out->draw_smooth(x1,y1+r, x1+r,y1+r, x1+r,y1);
292 out->draw_smooth(x1+r,y1, x1+r,y1-r, x1,y1-r);
293 out->draw_smooth(x1,y1-r, x1-r,y1-r, x1-r,y1);
296 for( int r=rr; --r>=0; ) { // edge arrows
297 out->draw_line(x1-r,y0+r, x1+r,y0+r);
298 out->draw_line(x2-r,y1-r, x2-r,y1+r);
299 out->draw_line(x1-r,y2-r, x1+r,y2-r);
300 out->draw_line(x0+r,y1+r, x0+r,y1-r);
302 x0 += r2; y0 += r2; x2 -= r2; y2 -= r2;
303 for( int r=2*mr; --r>=0; ) { // corner arrows
304 out->draw_line(x0,y0+r, x0+r,y0);
305 out->draw_line(x2,y0+r, x2-r,y0);
306 out->draw_line(x2,y2-r, x2-r,y2);
307 out->draw_line(x0,y2-r, x0+r,y2);