3 * Copyright (C) 2014 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "automation.h"
22 #include "bcdisplayinfo.h"
25 #include "sketcherwindow.h"
28 #include "cwindowgui.h"
30 #include "edlsession.h"
33 #include "mainerror.h"
36 #include "pluginserver.h"
40 #define AltMask Mod1Mask
45 const char *SketcherPoint::types[] = {
51 const char *SketcherCurve::pens[] = {
60 SketcherCurvePenItem::SketcherCurvePenItem(int pen)
61 : BC_MenuItem(_(SketcherCurve::pens[pen]))
65 int SketcherCurvePenItem::handle_event()
67 SketcherCurvePen *popup = (SketcherCurvePen*)get_popup_menu();
69 SketcherWindow *gui = popup->gui;
70 SketcherConfig &config = gui->plugin->config;
71 int ci = config.cv_selected;
72 if( ci >= 0 && ci < config.curves.size() ) {
73 SketcherCurve *cv = config.curves[ci];
75 gui->curve_list->update(ci);
76 gui->send_configure_change();
81 SketcherCurvePen::SketcherCurvePen(SketcherWindow *gui, int x, int y, int pen)
82 : BC_PopupMenu(x,y,72,_(cv_pen[pen]))
87 void SketcherCurvePen::create_objects()
89 int n = sizeof(cv_pen)/sizeof(cv_pen[0]);
90 for( int pen=0; pen<n; ++pen )
91 add_item(new SketcherCurvePenItem(pen));
93 void SketcherCurvePen::update(int pen)
95 set_text(_(cv_pen[this->pen=pen]));
99 SketcherCurveColor::SketcherCurveColor(SketcherWindow *gui,
100 int x, int y, int w, int h, int color, int alpha)
101 : ColorBoxButton(_("Curve Color"), x, y, w, h, color, alpha, 1)
104 this->color = CV_COLOR;
105 for( int i=0; i<3; ++i ) {
106 vframes[i] = new VFrame(w, h, BC_RGB888);
107 vframes[i]->clear_frame();
111 SketcherCurveColor::~SketcherCurveColor()
113 for( int i=0; i<3; ++i )
117 void SketcherCurveColor::handle_done_event(int result)
119 if( result ) color = orig_color | (~orig_alpha<<24);
120 SketcherConfig &config = gui->plugin->config;
121 int ci = config.cv_selected;
122 if( ci >= 0 && ci < config.curves.size() ) {
123 SketcherCurve *cv = config.curves[ci];
125 gui->lock_window("SketcherCurveColor::handle_done_event");
126 gui->curve_list->update(ci);
127 gui->unlock_window();
128 gui->send_configure_change();
132 int SketcherCurveColor::handle_new_color(int color, int alpha)
134 color |= ~alpha<<24; this->color = color;
135 gui->lock_window("SketcherCurveColor::update_gui");
137 SketcherConfig &config = gui->plugin->config;
138 int ci = config.cv_selected;
140 SketcherCurve *cv = config.curves[ci];
142 gui->curve_list->update(ci);
143 gui->send_configure_change();
145 gui->unlock_window();
150 SketcherCoord::SketcherCoord(SketcherWindow *gui, int x, int y,
151 coord output, coord mn, coord mx)
152 : BC_TumbleTextBox(gui, output, mn, mx, x, y, 64, 1)
157 SketcherCoord::~SketcherCoord()
161 SketcherNum::SketcherNum(SketcherWindow *gui, int x, int y,
162 int output, int mn, int mx)
163 : BC_TumbleTextBox(gui, output, mn, mx, x, y, 54)
168 SketcherNum::~SketcherNum()
172 int SketcherPointX::handle_event()
174 if( !SketcherCoord::handle_event() ) return 0;
175 SketcherConfig &config = gui->plugin->config;
176 int ci = config.cv_selected;
177 if( ci >= 0 && ci < config.curves.size() ) {
178 SketcherCurve *cv = config.curves[ci];
179 SketcherPointList *point_list = gui->point_list;
180 int pi = config.pt_selected;
181 SketcherPoints &points = cv->points;
182 if( pi >= 0 && pi < points.size() ) {
183 coord v = atof(get_text());
185 point_list->set_point(pi, PT_X, v);
186 point_list->update_list(pi);
187 gui->send_configure_change();
192 int SketcherPointY::handle_event()
194 if( !SketcherCoord::handle_event() ) return 0;
195 SketcherConfig &config = gui->plugin->config;
196 int ci = config.cv_selected;
197 if( ci >= 0 && ci < config.curves.size() ) {
198 SketcherCurve *cv = config.curves[ci];
199 SketcherPointList *point_list = gui->point_list;
200 int pi = config.pt_selected;
201 SketcherPoints &points = cv->points;
202 if( pi >= 0 && pi < points.size() ) {
203 coord v = atof(get_text());
205 point_list->set_point(pi, PT_Y, v);
206 point_list->update_list(pi);
207 gui->send_configure_change();
213 int SketcherPointId::handle_event()
215 if( !SketcherNum::handle_event() ) return 0;
216 SketcherConfig &config = gui->plugin->config;
217 int ci = config.cv_selected;
218 if( ci >= 0 && ci < config.curves.size() ) {
219 SketcherCurve *cv = config.curves[ci];
220 SketcherPointList *point_list = gui->point_list;
221 int pi = config.pt_selected;
222 SketcherPoints &points = cv->points;
223 if( pi >= 0 && pi < points.size() ) {
224 int id = atoi(get_text());
226 point_list->set_point(pi, PT_ID, id);
227 point_list->update_list(pi);
228 gui->send_configure_change();
234 SketcherCurveWidth::SketcherCurveWidth(SketcherWindow *gui, int x, int y, int width)
235 : SketcherNum(gui, x, y, width, 0, 255)
239 SketcherCurveWidth::~SketcherCurveWidth()
243 int SketcherCurveWidth::handle_event()
245 if( !SketcherNum::handle_event() ) return 0;
246 SketcherConfig &config = gui->plugin->config;
247 int ci = config.cv_selected;
248 if( ci >= 0 && ci < config.curves.size() ) {
249 SketcherCurve *cv = config.curves[ci];
250 int v = atoi(get_text());
252 gui->curve_list->update(ci);
253 gui->send_configure_change();
258 void SketcherCurveWidth::update(int width)
260 SketcherNum::update(this->width=width);
264 SketcherWindow::SketcherWindow(Sketcher *plugin)
265 : PluginClientWindow(plugin, 380, 620, 380, 620, 0)
267 this->plugin = plugin;
268 this->title_pen = 0; this->curve_pen = 0;
269 this->title_color = 0; this->curve_color = 0;
271 this->new_curve = 0; this->del_curve = 0;
272 this->curve_up = 0; this->curve_dn = 0;
273 this->title_x = 0; this->point_x = 0;
274 this->title_y = 0; this->point_y = 0;
275 this->title_id = 0; this->point_id = 0;
276 this->new_point = 0; this->del_point = 0;
277 this->point_up = 0; this->point_dn = 0;
278 this->point_list = 0; this->notes0 = 0;
279 this->notes1 = 0; this->notes2 = 0;
282 track_w = track_h -1;
283 cursor_x = cursor_y = -1;
284 output_x = output_y = -1;
285 last_x = last_y = -1;
286 projector_x = projector_y = projector_z = -1;
287 state = 0; dragging = 0;
293 SketcherWindow::~SketcherWindow()
300 void SketcherWindow::create_objects()
302 int x = 10, y = 10, dy = 0, x1, y1;
303 int margin = plugin->get_theme()->widget_border;
305 int ci = plugin->config.cv_selected;
306 if( ci < 0 || ci >= plugin->config.curves.size() )
307 ci = plugin->new_curve();
308 SketcherCurve *cv = plugin->config.curves[ci];
310 reset_curves = new SketcherResetCurves(this, plugin, x1=x, y+3);
311 add_subwindow(reset_curves); dy = bmax(dy,reset_curves->get_h());
312 x1 += reset_curves->get_w() + 2*margin;
313 const char *curve_text = _("Curve");
314 title_width = new BC_Title(x1, y, _("Width:"));
315 add_subwindow(title_width); dy = bmax(dy,title_width->get_h());
316 x1 += title_width->get_w() + margin;
317 curve_width = new SketcherCurveWidth(this, x1, y, cv->width);
318 curve_width->create_objects();
319 y += dy + 2*margin; dy = 0;
321 x1 = get_w()-x - BC_Title::calculate_w(this, curve_text, LARGEFONT);
322 y1 = y-margin - BC_Title::calculate_h(this, curve_text, LARGEFONT);
323 title = new BC_Title(x1, y1, curve_text, LARGEFONT,
324 get_resources()->menu_highlighted_fontcolor);
325 add_subwindow(title); dy = bmax(dy,title->get_h());
326 curve_list = new SketcherCurveList(this, plugin, x, y);
327 add_subwindow(curve_list); dy = bmax(dy,curve_list->get_h());
328 y += dy + margin; dy = 0;
330 new_curve = new SketcherNewCurve(this, plugin, x1=x, y);
331 add_subwindow(new_curve); dy = bmax(dy,new_curve->get_h());
332 x1 += new_curve->get_w() + margin;
333 curve_up = new SketcherCurveUp(this, x1, y);
334 add_subwindow(curve_up); dy = bmax(dy,curve_up->get_h());
335 x1 += curve_up->get_w() + 4*margin;
336 y1 = BC_Title::calculate_h(this, _("Pen:"));
337 title_pen = new BC_Title(x1+30, y+dy-y1, _("Pen:"));
338 add_subwindow(title_pen); dy = bmax(dy,title_pen->get_h());
339 int x2 = (get_w()+x1)/2 + 20;
340 y1 = BC_Title::calculate_h(this, _("Color:"));
341 title_color = new BC_Title(x2, y+dy-y1, _("Color:"));
342 add_subwindow(title_color); dy = bmax(dy,title_color->get_h());
343 y += dy + margin; dy = 0;
345 del_curve = new SketcherDelCurve(this, plugin, x1=x, y);
346 add_subwindow(del_curve); dy = bmax(dy,del_curve->get_h());
347 x1 += del_curve->get_w() + margin;
348 curve_dn = new SketcherCurveDn(this, x1, y);
349 add_subwindow(curve_dn); dy = bmax(dy,curve_dn->get_h());
350 x1 += curve_dn->get_w() + 4*margin;
351 curve_pen = new SketcherCurvePen(this, x1, y, cv->pen);
352 add_subwindow(curve_pen); dy = bmax(dy,curve_pen->get_h());
353 curve_pen->create_objects();
354 curve_color = new SketcherCurveColor(this, x2, y, COLOR_W, COLOR_H,
355 cv->color&0xffffff, (~cv->color>>24)&0xff);
356 add_subwindow(curve_color); dy = bmax(dy,curve_color->get_h());
357 y += dy + margin; dy = 0;
358 curve_list->update(ci);
361 bar = new BC_Bar(x, y, get_w()-2*x);
362 add_subwindow(bar); dy = bmax(dy,bar->get_h());
363 bar = new BC_Bar(x, y+=dy, get_w()-2*x);
364 add_subwindow(bar); dy = bmax(dy,bar->get_h());
367 int pi = plugin->config.pt_selected;
368 SketcherPoint *pt = pi >= 0 && pi < cv->points.size() ? cv->points[pi] : 0;
369 reset_points = new SketcherResetPoints(this, plugin, x1=x, y+3);
370 add_subwindow(reset_points); dy = bmax(dy,reset_points->get_h());
371 x1 += reset_points->get_w() + 2*margin;
372 if( plugin->config.drag ) {
373 if( !grab(plugin->server->mwindow->cwindow->gui) ) {
374 eprintf("drag enabled, but compositor already grabbed\n");
375 plugin->config.drag = 0;
378 drag = new SketcherDrag(this, x1, y);
379 add_subwindow(drag); dy = bmax(dy,drag->get_h());
380 x1 += drag->get_w() + 2*margin;
381 int arc = pt ? pt->arc : ARC_LINE;
382 point_type = new SketcherPointType(this, x1, y, arc);
383 add_subwindow(point_type); dy = bmax(dy,point_type->get_h());
384 point_type->create_objects();
385 y += dy + margin; dy = 0;
387 const char *point_text = _("Point");
388 x1 = get_w()-x - BC_Title::calculate_w(this, point_text, LARGEFONT);
389 y1 = y-margin - BC_Title::calculate_h(this, point_text, LARGEFONT);
390 add_subwindow(title = new BC_Title(x1, y1, point_text, LARGEFONT,
391 get_resources()->menu_highlighted_fontcolor));
392 point_list = new SketcherPointList(this, plugin, x, y);
393 add_subwindow(point_list); dy = bmax(dy,point_list->get_h());
394 y += dy + margin; dy = 0;
396 new_point = new SketcherNewPoint(this, plugin, x1=x, y);
397 add_subwindow(new_point); dy = bmax(dy,new_point->get_h());
398 x1 += new_point->get_w() + margin;
399 point_up = new SketcherPointUp(this, x1, y);
400 add_subwindow(point_up); dy = bmax(dy,point_up->get_h());
401 x1 += point_up->get_w() + 2*margin;
402 title_x = new BC_Title(x1, y, _("X:"));
403 add_subwindow(title_x); dy = bmax(dy,title_x->get_h());
404 x1 += title_x->get_w() + margin;
405 point_x = new SketcherPointX(this, x1, y, !pt ? 0.f : pt->x);
406 point_x->create_objects(); dy = bmax(dy, point_x->get_h());
407 x2 = x1 + point_x->get_w() + 2*margin + 10;
408 y1 = BC_Title::calculate_h(this, _("ID:"));
409 title_id = new BC_Title(x2+16, y+dy-y1, _("ID:"));
410 add_subwindow(title_id); dy = bmax(dy, title_id->get_h());
411 y += dy + margin; dy = 0;
413 del_point = new SketcherDelPoint(this, plugin, x1=x, y);
414 add_subwindow(del_point); dy = bmax(dy,del_point->get_h());
415 x1 += del_point->get_w() + margin;
416 point_dn = new SketcherPointDn(this, x1, y);
417 add_subwindow(point_dn); dy = bmax(dy,point_dn->get_h());
418 x1 += point_dn->get_w() + 2*margin;
419 title_y = new BC_Title(x1, y, _("Y:"));
420 add_subwindow(title_y); dy = bmax(dy,title_y->get_h());
421 x1 += title_y->get_w() + margin;
422 point_y = new SketcherPointY(this, x1, y, !pt ? 0.f : pt->y);
423 point_y->create_objects(); dy = bmax(dy, point_y->get_h());
424 point_id = new SketcherPointId(this, x2, y, !pt ? 0 : pt->id);
425 point_id->create_objects(); dy = bmax(dy, point_id->get_h());
426 y += dy + margin + 5; dy = 0;
427 point_list->update(pi);
429 bar = new BC_Bar(x, y, get_w()-2*x);
430 add_subwindow(bar); dy = bmax(dy,bar->get_h());
433 add_subwindow(notes0 = new BC_Title(x, y,
439 "Ctrl+Shift="))); dy = bmax(dy, notes0->get_h());
440 add_subwindow(notes1 = new BC_Title(x+100, y,
446 "new fill point"))); dy = bmax(dy, notes1->get_h());
447 add_subwindow(notes2 = new BC_Title(x+220, y,
453 "new off point"))); dy = bmax(dy, notes2->get_h());
454 y += dy + margin + 10;
456 add_subwindow(notes3 = new BC_Title(x, y,
457 "Key DEL= delete point, +Shift= delete curve\n"));
461 void SketcherWindow::done_event(int result)
465 void SketcherWindow::send_configure_change()
468 plugin->send_configure_change();
472 int SketcherWindow::grab_event(XEvent *event)
474 int ret = do_grab_event(event);
475 if( !grab_event_count() ) {
476 if( grab_cursor_motion() )
478 if( pending_config ) {
479 last_x = output_x; last_y = output_y;
480 send_configure_change();
486 int SketcherWindow::do_grab_event(XEvent *event)
488 switch( event->type ) {
489 case ButtonPress: break;
490 case ButtonRelease: break;
491 case MotionNotify: break;
493 if( keysym_lookup(event) > 0 ) {
494 switch( get_keysym() ) {
497 return (event->xkey.state & ShiftMask) ?
498 del_curve->handle_event() :
499 del_point->handle_event() ;
506 MWindow *mwindow = plugin->server->mwindow;
507 CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
508 CWindowCanvas *canvas = cwindow_gui->canvas;
509 int cx, cy; cwindow_gui->get_relative_cursor(cx, cy);
510 cx -= mwindow->theme->ccanvas_x;
511 cy -= mwindow->theme->ccanvas_y;
514 if( cx < 0 || cx >= mwindow->theme->ccanvas_w ||
515 cy < 0 || cy >= mwindow->theme->ccanvas_h )
519 switch( event->type ) {
521 if( dragging ) return 0;
528 if( dragging ) break;
529 default: // fall thru
533 cursor_x = cx, cursor_y = cy;
534 canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
535 position = plugin->get_source_position();
536 Track *track = plugin->server->plugin->track;
537 track_w = track->track_w;
538 track_h = track->track_h;
539 track->automation->get_projector(
540 &projector_x, &projector_y, &projector_z,
541 position, PLAY_FORWARD);
542 projector_x += mwindow->edl->session->output_w / 2;
543 projector_y += mwindow->edl->session->output_h / 2;
544 output_x = (cursor_x - projector_x) / projector_z + track_w / 2;
545 output_y = (cursor_y - projector_y) / projector_z + track_h / 2;
546 state = event->xmotion.state;
548 if( event->type == MotionNotify ) {
549 memcpy(&motion_event, event, sizeof(motion_event));
553 if( grab_cursor_motion() )
556 switch( event->type ) {
558 pending_config = grab_button_press(event);
568 int SketcherWindow::grab_button_press(XEvent *event)
570 SketcherConfig &config = plugin->config;
571 int ci = config.cv_selected;
572 if( ci < 0 || ci >= plugin->config.curves.size() )
574 SketcherCurves &curves = config.curves;
575 SketcherCurve *cv = curves[ci];
576 SketcherPoints &points = cv->points;
577 int pi = config.pt_selected;
579 int button_no = event->xbutton.button;
580 switch( button_no ) {
582 if( (state & ShiftMask) ) { // create new point/string
584 pi = plugin->new_point(cv,
585 !(state & ControlMask) ? ARC_LINE : ARC_FILL,
586 output_x, output_y, pi+1);
587 point_list->update(pi);
590 SketcherPoint *pt = 0; // select point
591 double dist = cv->nearest_point(pi, output_x,output_y);
594 Track *track = plugin->server->plugin->track;
595 int track_w = track->track_w, track_h = track->track_h;
596 float px = (pt->x - track_w / 2) * projector_z + projector_x;
597 float py = (pt->y - track_h / 2) * projector_z + projector_y;
598 float pix = DISTANCE(px, py, cursor_x,cursor_y);
599 if( (state & ControlMask) && pix >= HANDLE_W ) { pi = -1; pt = 0; }
601 point_list->set_selected(pi);
604 if( (state & ShiftMask) ) { // create new curve point
606 pi = plugin->new_point(cv,
607 !(state & ControlMask) ? ARC_CURVE : ARC_OFF,
608 output_x, output_y, pi+1);
609 point_list->update(pi);
612 if( (state & AltMask) ) { // create new curve
613 ci = plugin->new_curve(cv->pen, cv->width, curve_color->color);
614 curve_list->update(ci);
615 point_list->update(-1);
618 SketcherPoint *pt = 0;
619 double dist = config.nearest_point(ci, pi, output_x,output_y);
621 pt = curves[ci]->points[pi];
622 Track *track = plugin->server->plugin->track;
623 int track_w = track->track_w, track_h = track->track_h;
624 float px = (pt->x - track_w / 2) * projector_z + projector_x;
625 float py = (pt->y - track_h / 2) * projector_z + projector_y;
626 float pix = DISTANCE(px, py, cursor_x,cursor_y);
627 if( (state & ControlMask) && pix >= HANDLE_W ) { ci = pi = -1; pt = 0; }
630 curve_list->update(ci);
631 point_list->update(pi);
638 int SketcherWindow::grab_cursor_motion()
640 if( !pending_motion )
643 SketcherConfig &config = plugin->config;
644 int ci = config.cv_selected;
645 if( ci < 0 || ci >= plugin->config.curves.size() )
647 SketcherCurves &curves = config.curves;
648 SketcherCurve *cv = curves[ci];
649 SketcherPoints &points = cv->points;
650 int pi = config.pt_selected;
652 if( (state & ShiftMask) ) { // string of points
653 if( (state & (Button1Mask|Button3Mask)) ) {
654 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
656 float dist = DISTANCE(pt->x, pt->y, output_x, output_y);
657 if( dist < get_w()*0.1 ) return 0; // tolerance w/10
660 int arc = (state & Button1Mask) ? ARC_LINE : ARC_CURVE;
661 pi = plugin->new_point(cv, arc, output_x, output_y, pi+1);
662 point_list->update(pi);
666 if( (state & Button1Mask) ) {
667 if( (state & ControlMask) ) { // drag selected point
668 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
670 point_list->set_point(pi, PT_X, pt->x = output_x);
671 point_list->set_point(pi, PT_Y, pt->y = output_y);
672 point_list->update_list(pi);
673 point_x->update(pt->x);
674 point_y->update(pt->y);
678 if( (state & AltMask) ) { // drag all curves
679 int dx = round(output_x - last_x);
680 int dy = round(output_y - last_y);
681 for( int i=0; i<curves.size(); ++i ) {
682 SketcherCurve *crv = plugin->config.curves[i];
683 int pts = crv->points.size();
684 for( int k=0; k<pts; ++k ) {
685 SketcherPoint *pt = crv->points[k];
686 pt->x += dx; pt->y += dy;
689 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
691 point_x->update(pt ? pt->x : 0.f);
692 point_y->update(pt ? pt->y : 0.f);
693 point_id->update(pt ? pt->id : 0);
694 point_list->update(pi);
697 double dist = cv->nearest_point(pi, output_x,output_y);
699 point_list->set_selected(pi);
702 if( (state & Button3Mask) ) {
703 if( (state & (ControlMask | AltMask)) ) { // drag selected curve(s)
704 int dx = round(output_x - last_x);
705 int dy = round(output_y - last_y);
706 for( int i=0; i<points.size(); ++i ) {
707 SketcherPoint *pt = points[i];
708 pt->x += dx; pt->y += dy;
710 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
712 point_x->update(pt ? pt->x : 0.f);
713 point_y->update(pt ? pt->y : 0.f);
714 point_id->update(pt ? pt->id : 0);
715 point_list->update(pi);
718 double dist = config.nearest_point(ci, pi, output_x,output_y);
720 curve_list->update(ci);
721 point_list->update(pi);
728 int SketcherWindow::keypress_event()
730 int key = get_keypress();
732 case DELETE: return shift_down() ?
733 del_curve->handle_event() :
734 del_point->handle_event() ;
740 SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
741 : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
744 this->plugin = plugin;
745 col_titles[CV_ID] = _("ID"); col_widths[CV_ID] = 64;
746 col_titles[CV_RAD] = _("width"); col_widths[CV_RAD] = 64;
747 col_titles[CV_PEN] = _("pen"); col_widths[CV_PEN] = 64;
748 col_titles[CV_CLR] = _("color"); col_widths[CV_CLR] = 80;
749 col_titles[CV_ALP] = _("alpha"); col_widths[CV_ALP] = 64;
751 SketcherCurveList::~SketcherCurveList()
755 void SketcherCurveList::clear()
757 for( int i=CV_SZ; --i>=0; )
758 cols[i].remove_all_objects();
761 int SketcherCurveList::column_resize_event()
763 for( int i=CV_SZ; --i>=0; )
764 col_widths[i] = get_column_width(i);
768 int SketcherCurveList::handle_event()
770 int ci = get_selection_number(0, 0);
772 gui->point_list->update(0);
773 gui->send_configure_change();
777 int SketcherCurveList::selection_changed()
783 void SketcherCurveList::set_selected(int k)
786 if( k >= 0 && k < plugin->config.curves.size() ) {
787 SketcherCurve *cv = plugin->config.curves[k];
788 gui->curve_width->update(cv->width);
789 gui->curve_pen->update(cv->pen);
790 gui->curve_color->update_gui(cv->color);
793 plugin->config.cv_selected = ci;
797 void SketcherCurveList::update_list(int k)
799 int xpos = get_xposition(), ypos = get_yposition();
800 if( k >= 0 ) update_selection(&cols[0], k);
801 BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],CV_SZ, xpos,ypos,k);
805 void SketcherCurveList::update(int k)
808 SketcherCurves &curves = plugin->config.curves;
809 int sz = curves.size();
810 for( int i=0; i<sz; ++i ) {
811 SketcherCurve *cv = curves[i];
812 char itxt[BCSTRLEN]; sprintf(itxt,"%d", cv->id);
813 char ptxt[BCSTRLEN]; sprintf(ptxt,"%s", cv_pen[cv->pen]);
814 char rtxt[BCSTRLEN]; sprintf(rtxt,"%d", cv->width);
815 int color = cv->color;
816 int r = (color>>16)&0xff;
817 int g = (color>> 8)&0xff;
818 int b = (color>> 0)&0xff;
819 int a = (~color>>24)&0xff;
820 char ctxt[BCSTRLEN]; sprintf(ctxt,"#%02x%02x%02x", r, g, b);
821 char atxt[BCSTRLEN]; sprintf(atxt,"%5.3f", a/255.);
822 add_curve(itxt, ptxt, rtxt, ctxt, atxt);
827 void SketcherCurveList::add_curve(const char *id, const char *pen,
828 const char *width, const char *color, const char *alpha)
830 cols[CV_ID].append(new BC_ListBoxItem(id));
831 cols[CV_RAD].append(new BC_ListBoxItem(width));
832 cols[CV_PEN].append(new BC_ListBoxItem(pen));
833 cols[CV_CLR].append(new BC_ListBoxItem(color));
834 cols[CV_ALP].append(new BC_ListBoxItem(alpha));
837 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
838 : BC_GenericButton(x, y, 64, _("New"))
841 this->plugin = plugin;
843 SketcherNewCurve::~SketcherNewCurve()
846 int SketcherNewCurve::handle_event()
848 int pen = gui->curve_pen->pen;
849 int color = gui->curve_color->color;
850 int width = gui->curve_width->width;
851 int ci = plugin->config.cv_selected;
852 if( ci >= 0 && ci < plugin->config.curves.size() ) {
853 SketcherCurve *cv = plugin->config.curves[ci];
854 pen = cv->pen; width = cv->width; color = cv->color;
856 ci = plugin->new_curve(pen, width, color);
857 gui->curve_list->update(ci);
858 gui->point_list->update(-1);
859 gui->send_configure_change();
863 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
864 : BC_GenericButton(x, y, 64, C_("Del"))
867 this->plugin = plugin;
869 SketcherDelCurve::~SketcherDelCurve()
872 int SketcherDelCurve::handle_event()
874 SketcherConfig &config = plugin->config;
875 int ci = config.cv_selected;
876 SketcherCurves &curves = config.curves;
877 if( ci >= 0 && ci < curves.size() ) {
878 curves.remove_object_number(ci--);
881 ci = plugin->new_curve();
882 gui->curve_list->update(ci);
883 gui->point_list->update(-1);
884 gui->send_configure_change();
889 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
890 : BC_GenericButton(x, y, _("Up"))
894 SketcherCurveUp::~SketcherCurveUp()
898 int SketcherCurveUp::handle_event()
900 SketcherConfig &config = gui->plugin->config;
901 int ci = config.cv_selected;
902 SketcherCurves &curves = config.curves;
903 if( ci > 0 && ci < curves.size() ) {
904 SketcherCurve *&cv0 = curves[ci];
905 SketcherCurve *&cv1 = curves[--ci];
906 SketcherCurve *t = cv0; cv0 = cv1; cv1 = t;
907 gui->curve_list->update(ci);
909 gui->send_configure_change();
913 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
914 : BC_GenericButton(x, y, _("Dn"))
918 SketcherCurveDn::~SketcherCurveDn()
922 int SketcherCurveDn::handle_event()
924 SketcherConfig &config = gui->plugin->config;
925 int ci = config.cv_selected;
926 SketcherCurves &curves = config.curves;
927 if( ci >= 0 && ci < curves.size()-1 ) {
928 SketcherCurve *&cv0 = curves[ci];
929 SketcherCurve *&cv1 = curves[++ci];
930 SketcherCurve *t = cv0; cv0 = cv1; cv1 = t;
931 gui->curve_list->update(ci);
933 gui->send_configure_change();
938 SketcherPointTypeItem::SketcherPointTypeItem(int arc)
939 : BC_MenuItem(_(pt_type[arc]))
943 int SketcherPointTypeItem::handle_event()
945 SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
947 SketcherWindow *gui = popup->gui;
948 SketcherConfig &config = gui->plugin->config;
949 SketcherCurves &curves = config.curves;
950 int ci = config.cv_selected;
951 if( ci < 0 || ci >= curves.size() )
953 SketcherCurve *cv = curves[ci];
954 SketcherPoints &points = cv->points;
955 int pi = config.pt_selected;
957 ArrayList<int> selected;
958 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
961 for( int i=selected.size(); --i>=0; ) {
963 if( k < 0 || k >= points.size() ) continue;
964 SketcherPoint *pt = cv->points[k];
966 gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
969 gui->point_list->update_list(pi);
970 gui->send_configure_change();
974 SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc)
975 : BC_PopupMenu(x,y,64,_(pt_type[arc]))
980 void SketcherPointType::create_objects()
982 for( int arc=0; arc<PT_SZ; ++arc )
983 add_item(new SketcherPointTypeItem(arc));
985 void SketcherPointType::update(int arc)
987 set_text(_(pt_type[this->type=arc]));
991 SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
992 : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
995 this->plugin = plugin;
996 col_titles[PT_ID] = _("ID"); col_widths[PT_ID] = 50;
997 col_titles[PT_TY] = _("Type"); col_widths[PT_TY] = 80;
998 col_titles[PT_X] = _("X"); col_widths[PT_X] = 90;
999 col_titles[PT_Y] = _("Y"); col_widths[PT_Y] = 90;
1000 set_selection_mode(LISTBOX_MULTIPLE);
1002 SketcherPointList::~SketcherPointList()
1006 void SketcherPointList::clear()
1008 for( int i=PT_SZ; --i>=0; )
1009 cols[i].remove_all_objects();
1012 int SketcherPointList::column_resize_event()
1014 for( int i=PT_SZ; --i>=0; )
1015 col_widths[i] = get_column_width(i);
1019 int SketcherPointList::handle_event()
1021 int pi = get_selection_number(0, 0);
1022 if( get_selection_number(0, 1) >= 0 ) pi = -1;
1024 gui->send_configure_change();
1028 int SketcherPointList::selection_changed()
1034 void SketcherPointList::add_point(const char *id, const char *ty, const char *xp, const char *yp)
1036 cols[PT_ID].append(new BC_ListBoxItem(id));
1037 cols[PT_TY].append(new BC_ListBoxItem(ty));
1038 cols[PT_X].append(new BC_ListBoxItem(xp));
1039 cols[PT_Y].append(new BC_ListBoxItem(yp));
1042 void SketcherPointList::set_point(int i, int c, int v)
1044 char stxt[BCSTRLEN];
1045 sprintf(stxt,"%d",v);
1046 set_point(i,c,stxt);
1048 void SketcherPointList::set_point(int i, int c, coord v)
1050 char stxt[BCSTRLEN];
1051 sprintf(stxt,"%0.1f",v);
1052 set_point(i,c,stxt);
1054 void SketcherPointList::set_point(int i, int c, const char *cp)
1056 cols[c].get(i)->set_text(cp);
1059 void SketcherPointList::set_selected(int k)
1061 SketcherPoint *pt = 0;
1062 int ci = plugin->config.cv_selected, pi = -1;
1063 if( ci >= 0 && ci < plugin->config.curves.size() ) {
1064 SketcherCurve *cv = plugin->config.curves[ci];
1065 pt = k >= 0 && k < cv->points.size() ? cv->points[pi=k] : 0;
1067 gui->point_type->update(pt ? pt->arc : ARC_OFF);
1068 gui->point_x->update(pt ? pt->x : 0.f);
1069 gui->point_y->update(pt ? pt->y : 0.f);
1070 gui->point_id->update(pt ? pt->id : 0);
1071 plugin->config.pt_selected = pi;
1074 void SketcherPointList::update_list(int k)
1076 int xpos = get_xposition(), ypos = get_yposition();
1077 if( k >= 0 ) update_selection(&cols[0], k);
1078 BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],PT_SZ, xpos,ypos,k);
1081 void SketcherPointList::update(int k)
1084 int ci = plugin->config.cv_selected, sz = 0;
1085 if( ci >= 0 && ci < plugin->config.curves.size() ) {
1086 SketcherCurve *cv = plugin->config.curves[ci];
1087 SketcherPoints &points = cv->points;
1089 for( int i=0; i<sz; ++i ) {
1090 SketcherPoint *pt = points[i];
1091 char itxt[BCSTRLEN]; sprintf(itxt,"%d", pt->id);
1092 char ttxt[BCSTRLEN]; sprintf(ttxt,"%s", _(pt_type[pt->arc]));
1093 char xtxt[BCSTRLEN]; sprintf(xtxt,"%0.1f", pt->x);
1094 char ytxt[BCSTRLEN]; sprintf(ytxt,"%0.1f", pt->y);
1095 add_point(itxt, ttxt, xtxt, ytxt);
1101 void SketcherWindow::update_gui()
1103 SketcherConfig &config = plugin->config;
1104 int ci = config.cv_selected;
1105 int pi = config.pt_selected;
1106 curve_list->update(ci);
1107 point_list->update(pi);
1108 SketcherCurve *cv = ci >= 0 ? config.curves[ci] : 0;
1109 curve_width->update(cv ? cv->width : 1);
1110 curve_pen->update(cv ? cv->pen : PEN_SQUARE);
1111 curve_color->set_color(cv ? cv->color : CV_COLOR);
1112 SketcherPoint *pt = pi >= 0 ? cv->points[pi] : 0;
1113 point_x->update(pt ? pt->x : 0);
1114 point_y->update(pt ? pt->y : 0);
1115 point_id->update(pt ? pt->id : 0);
1116 drag->update(plugin->config.drag);
1120 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
1121 : BC_GenericButton(x, y, _("Up"))
1125 SketcherPointUp::~SketcherPointUp()
1129 int SketcherPointUp::handle_event()
1131 SketcherConfig &config = gui->plugin->config;
1132 int ci = config.cv_selected;
1133 if( ci < 0 || ci >= config.curves.size() )
1135 SketcherCurve *cv = config.curves[ci];
1136 SketcherPoints &points = cv->points;
1137 if( points.size() < 2 )
1139 int pi = config.pt_selected;
1141 ArrayList<int> selected;
1142 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1145 for( int i=0; i<selected.size(); ++i ) {
1146 int k = selected[i];
1147 if( k <= 0 ) continue;
1149 SketcherPoint *&pt0 = points[k];
1150 SketcherPoint *&pt1 = points[--k];
1151 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1153 gui->point_list->update(pi);
1154 gui->send_configure_change();
1158 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
1159 : BC_GenericButton(x, y, _("Dn"))
1163 SketcherPointDn::~SketcherPointDn()
1167 int SketcherPointDn::handle_event()
1169 SketcherConfig &config = gui->plugin->config;
1170 int ci = config.cv_selected;
1171 if( ci < 0 || ci >= config.curves.size() )
1173 SketcherCurve *cv = config.curves[ci];
1174 SketcherPoints &points = cv->points;
1175 int sz1 = points.size()-1;
1178 int pi = config.pt_selected;
1180 ArrayList<int> selected;
1181 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1184 for( int i=selected.size(); --i>=0; ) {
1185 int k = selected[i];
1186 if( k >= sz1 ) continue;
1188 SketcherPoint *&pt0 = points[k];
1189 SketcherPoint *&pt1 = points[++k];
1190 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1192 gui->point_list->update(pi);
1193 gui->send_configure_change();
1197 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
1198 : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
1202 int SketcherDrag::handle_event()
1204 CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
1205 int value = get_value();
1207 if( !gui->grab(cwindow_gui) ) {
1213 gui->ungrab(cwindow_gui);
1214 gui->plugin->config.drag = value;
1215 gui->send_configure_change();
1219 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1220 : BC_GenericButton(x, y, 64, _("New"))
1223 this->plugin = plugin;
1225 SketcherNewPoint::~SketcherNewPoint()
1228 int SketcherNewPoint::handle_event()
1230 int pi = plugin->config.pt_selected;
1231 int arc = gui->point_type->type;
1232 int k = plugin->new_point(pi+1, arc);
1233 gui->point_list->update(k);
1234 gui->send_configure_change();
1238 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1239 : BC_GenericButton(x, y, 64, C_("Del"))
1242 this->plugin = plugin;
1244 SketcherDelPoint::~SketcherDelPoint()
1247 int SketcherDelPoint::handle_event()
1249 SketcherConfig &config = gui->plugin->config;
1250 SketcherCurves &curves = config.curves;
1251 int ci = config.cv_selected;
1252 if( ci < 0 || ci >= curves.size() )
1254 SketcherCurve *cv = curves[ci];
1255 SketcherPoints &points = cv->points;
1256 int pi = config.pt_selected;
1258 ArrayList<int> selected;
1259 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1262 for( int i=selected.size(); --i>=0; ) {
1263 int k = selected[i];
1264 if( k < 0 || k >= points.size() ) continue;
1265 points.remove_object_number(k);
1266 if( k == pi && --pi < 0 && points.size() > 0 ) pi = 0;
1268 gui->point_list->update(pi);
1269 gui->send_configure_change();
1273 SketcherResetCurves::SketcherResetCurves(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1274 : BC_GenericButton(x, y, _("Reset"))
1277 this->plugin = plugin;
1279 SketcherResetCurves::~SketcherResetCurves()
1282 int SketcherResetCurves::handle_event()
1284 SketcherConfig &config = plugin->config;
1285 config.curves.remove_all_objects();
1286 int ci = plugin->new_curve();
1287 gui->curve_list->update(ci);
1288 gui->point_list->update(-1);
1289 gui->send_configure_change();
1293 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1294 : BC_GenericButton(x, y, _("Reset"))
1297 this->plugin = plugin;
1299 SketcherResetPoints::~SketcherResetPoints()
1302 int SketcherResetPoints::handle_event()
1304 SketcherConfig &config = gui->plugin->config;
1305 int ci = config.cv_selected;
1306 if( ci >= 0 && ci < config.curves.size() ) {
1307 SketcherCurve *cv = config.curves[ci];
1308 cv->points.remove_all_objects();
1309 gui->point_list->update(-1);
1310 gui->send_configure_change();