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->curve_list->update(ci);
126 gui->send_configure_change();
130 int SketcherCurveColor::handle_new_color(int color, int alpha)
132 color |= ~alpha<<24; this->color = color;
133 gui->lock_window("SketcherCurveColor::update_gui");
135 SketcherConfig &config = gui->plugin->config;
136 int ci = config.cv_selected;
138 SketcherCurve *cv = config.curves[ci];
140 gui->curve_list->update(ci);
141 gui->send_configure_change();
143 gui->unlock_window();
148 SketcherCoord::SketcherCoord(SketcherWindow *gui, int x, int y,
149 coord output, coord mn, coord mx)
150 : BC_TumbleTextBox(gui, output, mn, mx, x, y, 64, 1)
155 SketcherCoord::~SketcherCoord()
159 SketcherNum::SketcherNum(SketcherWindow *gui, int x, int y,
160 int output, int mn, int mx)
161 : BC_TumbleTextBox(gui, output, mn, mx, x, y, 54)
166 SketcherNum::~SketcherNum()
170 int SketcherPointX::handle_event()
172 if( !SketcherCoord::handle_event() ) return 0;
173 SketcherConfig &config = gui->plugin->config;
174 int ci = config.cv_selected;
175 if( ci >= 0 && ci < config.curves.size() ) {
176 SketcherCurve *cv = config.curves[ci];
177 SketcherPointList *point_list = gui->point_list;
178 int pi = config.pt_selected;
179 SketcherPoints &points = cv->points;
180 if( pi >= 0 && pi < points.size() ) {
181 coord v = atof(get_text());
183 point_list->set_point(pi, PT_X, v);
184 point_list->update_list(pi);
185 gui->send_configure_change();
190 int SketcherPointY::handle_event()
192 if( !SketcherCoord::handle_event() ) return 0;
193 SketcherConfig &config = gui->plugin->config;
194 int ci = config.cv_selected;
195 if( ci >= 0 && ci < config.curves.size() ) {
196 SketcherCurve *cv = config.curves[ci];
197 SketcherPointList *point_list = gui->point_list;
198 int pi = config.pt_selected;
199 SketcherPoints &points = cv->points;
200 if( pi >= 0 && pi < points.size() ) {
201 coord v = atof(get_text());
203 point_list->set_point(pi, PT_Y, v);
204 point_list->update_list(pi);
205 gui->send_configure_change();
211 int SketcherPointId::handle_event()
213 if( !SketcherNum::handle_event() ) return 0;
214 SketcherConfig &config = gui->plugin->config;
215 int ci = config.cv_selected;
216 if( ci >= 0 && ci < config.curves.size() ) {
217 SketcherCurve *cv = config.curves[ci];
218 SketcherPointList *point_list = gui->point_list;
219 int pi = config.pt_selected;
220 SketcherPoints &points = cv->points;
221 if( pi >= 0 && pi < points.size() ) {
222 int id = atoi(get_text());
224 point_list->set_point(pi, PT_ID, id);
225 point_list->update_list(pi);
226 gui->send_configure_change();
232 SketcherCurveWidth::SketcherCurveWidth(SketcherWindow *gui, int x, int y, int width)
233 : SketcherNum(gui, x, y, width, 0, 255)
237 SketcherCurveWidth::~SketcherCurveWidth()
241 int SketcherCurveWidth::handle_event()
243 if( !SketcherNum::handle_event() ) return 0;
244 SketcherConfig &config = gui->plugin->config;
245 int ci = config.cv_selected;
246 if( ci >= 0 && ci < config.curves.size() ) {
247 SketcherCurve *cv = config.curves[ci];
248 int v = atoi(get_text());
250 gui->curve_list->update(ci);
251 gui->send_configure_change();
256 void SketcherCurveWidth::update(int width)
258 SketcherNum::update(this->width=width);
262 SketcherWindow::SketcherWindow(Sketcher *plugin)
263 : PluginClientWindow(plugin, 380, 620, 380, 620, 0)
265 this->plugin = plugin;
266 this->title_pen = 0; this->curve_pen = 0;
267 this->title_color = 0; this->curve_color = 0;
269 this->new_curve = 0; this->del_curve = 0;
270 this->curve_up = 0; this->curve_dn = 0;
271 this->title_x = 0; this->point_x = 0;
272 this->title_y = 0; this->point_y = 0;
273 this->title_id = 0; this->point_id = 0;
274 this->new_point = 0; this->del_point = 0;
275 this->point_up = 0; this->point_dn = 0;
276 this->point_list = 0; this->notes0 = 0;
277 this->notes1 = 0; this->notes2 = 0;
280 track_w = track_h -1;
281 cursor_x = cursor_y = -1;
282 output_x = output_y = -1;
283 last_x = last_y = -1;
284 projector_x = projector_y = projector_z = -1;
285 state = 0; dragging = 0;
291 SketcherWindow::~SketcherWindow()
298 void SketcherWindow::create_objects()
300 int x = 10, y = 10, dy = 0, x1, y1;
301 int margin = plugin->get_theme()->widget_border;
303 int ci = plugin->config.cv_selected;
304 if( ci < 0 || ci >= plugin->config.curves.size() )
305 ci = plugin->new_curve();
306 SketcherCurve *cv = plugin->config.curves[ci];
308 reset_curves = new SketcherResetCurves(this, plugin, x1=x, y+3);
309 add_subwindow(reset_curves); dy = bmax(dy,reset_curves->get_h());
310 x1 += reset_curves->get_w() + 2*margin;
311 const char *curve_text = _("Curve");
312 title_width = new BC_Title(x1, y, _("Width:"));
313 add_subwindow(title_width); dy = bmax(dy,title_width->get_h());
314 x1 += title_width->get_w() + margin;
315 curve_width = new SketcherCurveWidth(this, x1, y, cv->width);
316 curve_width->create_objects();
317 y += dy + 2*margin; dy = 0;
319 x1 = get_w()-x - BC_Title::calculate_w(this, curve_text, LARGEFONT);
320 y1 = y-margin - BC_Title::calculate_h(this, curve_text, LARGEFONT);
321 title = new BC_Title(x1, y1, curve_text, LARGEFONT,
322 get_resources()->menu_highlighted_fontcolor);
323 add_subwindow(title); dy = bmax(dy,title->get_h());
324 curve_list = new SketcherCurveList(this, plugin, x, y);
325 add_subwindow(curve_list); dy = bmax(dy,curve_list->get_h());
326 y += dy + margin; dy = 0;
328 new_curve = new SketcherNewCurve(this, plugin, x1=x, y);
329 add_subwindow(new_curve); dy = bmax(dy,new_curve->get_h());
330 x1 += new_curve->get_w() + margin;
331 curve_up = new SketcherCurveUp(this, x1, y);
332 add_subwindow(curve_up); dy = bmax(dy,curve_up->get_h());
333 x1 += curve_up->get_w() + 4*margin;
334 y1 = BC_Title::calculate_h(this, _("Pen:"));
335 title_pen = new BC_Title(x1+30, y+dy-y1, _("Pen:"));
336 add_subwindow(title_pen); dy = bmax(dy,title_pen->get_h());
337 int x2 = (get_w()+x1)/2 + 20;
338 y1 = BC_Title::calculate_h(this, _("Color:"));
339 title_color = new BC_Title(x2, y+dy-y1, _("Color:"));
340 add_subwindow(title_color); dy = bmax(dy,title_color->get_h());
341 y += dy + margin; dy = 0;
343 del_curve = new SketcherDelCurve(this, plugin, x1=x, y);
344 add_subwindow(del_curve); dy = bmax(dy,del_curve->get_h());
345 x1 += del_curve->get_w() + margin;
346 curve_dn = new SketcherCurveDn(this, x1, y);
347 add_subwindow(curve_dn); dy = bmax(dy,curve_dn->get_h());
348 x1 += curve_dn->get_w() + 4*margin;
349 curve_pen = new SketcherCurvePen(this, x1, y, cv->pen);
350 add_subwindow(curve_pen); dy = bmax(dy,curve_pen->get_h());
351 curve_pen->create_objects();
352 curve_color = new SketcherCurveColor(this, x2, y, COLOR_W, COLOR_H,
353 cv->color&0xffffff, (~cv->color>>24)&0xff);
354 add_subwindow(curve_color); dy = bmax(dy,curve_color->get_h());
355 y += dy + margin; dy = 0;
356 curve_list->update(ci);
359 bar = new BC_Bar(x, y, get_w()-2*x);
360 add_subwindow(bar); dy = bmax(dy,bar->get_h());
361 bar = new BC_Bar(x, y+=dy, get_w()-2*x);
362 add_subwindow(bar); dy = bmax(dy,bar->get_h());
365 int pi = plugin->config.pt_selected;
366 SketcherPoint *pt = pi >= 0 && pi < cv->points.size() ? cv->points[pi] : 0;
367 reset_points = new SketcherResetPoints(this, plugin, x1=x, y+3);
368 add_subwindow(reset_points); dy = bmax(dy,reset_points->get_h());
369 x1 += reset_points->get_w() + 2*margin;
370 if( plugin->config.drag ) {
371 if( !grab(plugin->server->mwindow->cwindow->gui) ) {
372 eprintf("drag enabled, but compositor already grabbed\n");
373 plugin->config.drag = 0;
376 drag = new SketcherDrag(this, x1, y);
377 add_subwindow(drag); dy = bmax(dy,drag->get_h());
378 x1 += drag->get_w() + 2*margin;
379 int arc = pt ? pt->arc : ARC_LINE;
380 point_type = new SketcherPointType(this, x1, y, arc);
381 add_subwindow(point_type); dy = bmax(dy,point_type->get_h());
382 point_type->create_objects();
383 y += dy + margin; dy = 0;
385 const char *point_text = _("Point");
386 x1 = get_w()-x - BC_Title::calculate_w(this, point_text, LARGEFONT);
387 y1 = y-margin - BC_Title::calculate_h(this, point_text, LARGEFONT);
388 add_subwindow(title = new BC_Title(x1, y1, point_text, LARGEFONT,
389 get_resources()->menu_highlighted_fontcolor));
390 point_list = new SketcherPointList(this, plugin, x, y);
391 add_subwindow(point_list); dy = bmax(dy,point_list->get_h());
392 y += dy + margin; dy = 0;
394 new_point = new SketcherNewPoint(this, plugin, x1=x, y);
395 add_subwindow(new_point); dy = bmax(dy,new_point->get_h());
396 x1 += new_point->get_w() + margin;
397 point_up = new SketcherPointUp(this, x1, y);
398 add_subwindow(point_up); dy = bmax(dy,point_up->get_h());
399 x1 += point_up->get_w() + 2*margin;
400 title_x = new BC_Title(x1, y, _("X:"));
401 add_subwindow(title_x); dy = bmax(dy,title_x->get_h());
402 x1 += title_x->get_w() + margin;
403 point_x = new SketcherPointX(this, x1, y, !pt ? 0.f : pt->x);
404 point_x->create_objects(); dy = bmax(dy, point_x->get_h());
405 x2 = x1 + point_x->get_w() + 2*margin + 10;
406 y1 = BC_Title::calculate_h(this, _("ID:"));
407 title_id = new BC_Title(x2+16, y+dy-y1, _("ID:"));
408 add_subwindow(title_id); dy = bmax(dy, title_id->get_h());
409 y += dy + margin; dy = 0;
411 del_point = new SketcherDelPoint(this, plugin, x1=x, y);
412 add_subwindow(del_point); dy = bmax(dy,del_point->get_h());
413 x1 += del_point->get_w() + margin;
414 point_dn = new SketcherPointDn(this, x1, y);
415 add_subwindow(point_dn); dy = bmax(dy,point_dn->get_h());
416 x1 += point_dn->get_w() + 2*margin;
417 title_y = new BC_Title(x1, y, _("Y:"));
418 add_subwindow(title_y); dy = bmax(dy,title_y->get_h());
419 x1 += title_y->get_w() + margin;
420 point_y = new SketcherPointY(this, x1, y, !pt ? 0.f : pt->y);
421 point_y->create_objects(); dy = bmax(dy, point_y->get_h());
422 point_id = new SketcherPointId(this, x2, y, !pt ? 0 : pt->id);
423 point_id->create_objects(); dy = bmax(dy, point_id->get_h());
424 y += dy + margin + 5; dy = 0;
425 point_list->update(pi);
427 bar = new BC_Bar(x, y, get_w()-2*x);
428 add_subwindow(bar); dy = bmax(dy,bar->get_h());
431 add_subwindow(notes0 = new BC_Title(x, y,
437 "Ctrl+Shift="))); dy = bmax(dy, notes0->get_h());
438 add_subwindow(notes1 = new BC_Title(x+100, y,
444 "new fill point"))); dy = bmax(dy, notes1->get_h());
445 add_subwindow(notes2 = new BC_Title(x+220, y,
451 "new off point"))); dy = bmax(dy, notes2->get_h());
452 y += dy + margin + 10;
454 add_subwindow(notes3 = new BC_Title(x, y,
455 "Key DEL= delete point, +Shift= delete curve\n"));
459 void SketcherWindow::done_event(int result)
463 void SketcherWindow::send_configure_change()
466 plugin->send_configure_change();
470 int SketcherWindow::grab_event(XEvent *event)
472 int ret = do_grab_event(event);
473 if( !grab_event_count() ) {
474 if( grab_cursor_motion() )
476 if( pending_config ) {
477 last_x = output_x; last_y = output_y;
478 send_configure_change();
484 int SketcherWindow::do_grab_event(XEvent *event)
486 switch( event->type ) {
487 case ButtonPress: break;
488 case ButtonRelease: break;
489 case MotionNotify: break;
491 if( keysym_lookup(event) > 0 ) {
492 switch( get_keysym() ) {
495 return (event->xkey.state & ShiftMask) ?
496 del_curve->handle_event() :
497 del_point->handle_event() ;
504 MWindow *mwindow = plugin->server->mwindow;
505 CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
506 CWindowCanvas *canvas = cwindow_gui->canvas;
507 int cx, cy; cwindow_gui->get_relative_cursor(cx, cy);
508 cx -= mwindow->theme->ccanvas_x;
509 cy -= mwindow->theme->ccanvas_y;
512 if( cx < 0 || cx >= mwindow->theme->ccanvas_w ||
513 cy < 0 || cy >= mwindow->theme->ccanvas_h )
517 switch( event->type ) {
519 if( dragging ) return 0;
526 if( dragging ) break;
527 default: // fall thru
531 cursor_x = cx, cursor_y = cy;
532 canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
533 position = plugin->get_source_position();
534 Track *track = plugin->server->plugin->track;
535 track_w = track->track_w;
536 track_h = track->track_h;
537 track->automation->get_projector(
538 &projector_x, &projector_y, &projector_z,
539 position, PLAY_FORWARD);
540 projector_x += mwindow->edl->session->output_w / 2;
541 projector_y += mwindow->edl->session->output_h / 2;
542 output_x = (cursor_x - projector_x) / projector_z + track_w / 2;
543 output_y = (cursor_y - projector_y) / projector_z + track_h / 2;
544 state = event->xmotion.state;
546 if( event->type == MotionNotify ) {
547 memcpy(&motion_event, event, sizeof(motion_event));
551 if( grab_cursor_motion() )
554 switch( event->type ) {
556 pending_config = grab_button_press(event);
566 int SketcherWindow::grab_button_press(XEvent *event)
568 SketcherConfig &config = plugin->config;
569 int ci = config.cv_selected;
570 if( ci < 0 || ci >= plugin->config.curves.size() )
572 SketcherCurves &curves = config.curves;
573 SketcherCurve *cv = curves[ci];
574 SketcherPoints &points = cv->points;
575 int pi = config.pt_selected;
577 int button_no = event->xbutton.button;
578 switch( button_no ) {
580 if( (state & ShiftMask) ) { // create new point/string
582 pi = plugin->new_point(cv,
583 !(state & ControlMask) ? ARC_LINE : ARC_FILL,
584 output_x, output_y, pi+1);
585 point_list->update(pi);
588 SketcherPoint *pt = 0; // select point
589 double dist = cv->nearest_point(pi, output_x,output_y);
592 Track *track = plugin->server->plugin->track;
593 int track_w = track->track_w, track_h = track->track_h;
594 float px = (pt->x - track_w / 2) * projector_z + projector_x;
595 float py = (pt->y - track_h / 2) * projector_z + projector_y;
596 float pix = DISTANCE(px, py, cursor_x,cursor_y);
597 if( (state & ControlMask) && pix >= HANDLE_W ) { pi = -1; pt = 0; }
599 point_list->set_selected(pi);
602 if( (state & ShiftMask) ) { // create new curve point
604 pi = plugin->new_point(cv,
605 !(state & ControlMask) ? ARC_CURVE : ARC_OFF,
606 output_x, output_y, pi+1);
607 point_list->update(pi);
610 if( (state & AltMask) ) { // create new curve
611 ci = plugin->new_curve(cv->pen, cv->width, curve_color->color);
612 curve_list->update(ci);
613 point_list->update(-1);
616 SketcherPoint *pt = 0;
617 double dist = config.nearest_point(ci, pi, output_x,output_y);
619 pt = curves[ci]->points[pi];
620 Track *track = plugin->server->plugin->track;
621 int track_w = track->track_w, track_h = track->track_h;
622 float px = (pt->x - track_w / 2) * projector_z + projector_x;
623 float py = (pt->y - track_h / 2) * projector_z + projector_y;
624 float pix = DISTANCE(px, py, cursor_x,cursor_y);
625 if( (state & ControlMask) && pix >= HANDLE_W ) { ci = pi = -1; pt = 0; }
628 curve_list->update(ci);
629 point_list->update(pi);
636 int SketcherWindow::grab_cursor_motion()
638 if( !pending_motion )
641 SketcherConfig &config = plugin->config;
642 int ci = config.cv_selected;
643 if( ci < 0 || ci >= plugin->config.curves.size() )
645 SketcherCurves &curves = config.curves;
646 SketcherCurve *cv = curves[ci];
647 SketcherPoints &points = cv->points;
648 int pi = config.pt_selected;
650 if( (state & ShiftMask) ) { // string of points
651 if( (state & (Button1Mask|Button3Mask)) ) {
652 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
654 float dist = DISTANCE(pt->x, pt->y, output_x, output_y);
655 if( dist < get_w()*0.1 ) return 0; // tolerance w/10
658 int arc = (state & Button1Mask) ? ARC_LINE : ARC_CURVE;
659 pi = plugin->new_point(cv, arc, output_x, output_y, pi+1);
660 point_list->update(pi);
664 if( (state & Button1Mask) ) {
665 if( (state & ControlMask) ) { // drag selected point
666 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
668 point_list->set_point(pi, PT_X, pt->x = output_x);
669 point_list->set_point(pi, PT_Y, pt->y = output_y);
670 point_list->update_list(pi);
671 point_x->update(pt->x);
672 point_y->update(pt->y);
676 if( (state & AltMask) ) { // drag all curves
677 int dx = round(output_x - last_x);
678 int dy = round(output_y - last_y);
679 for( int i=0; i<curves.size(); ++i ) {
680 SketcherCurve *crv = plugin->config.curves[i];
681 int pts = crv->points.size();
682 for( int k=0; k<pts; ++k ) {
683 SketcherPoint *pt = crv->points[k];
684 pt->x += dx; pt->y += dy;
687 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
689 point_x->update(pt ? pt->x : 0.f);
690 point_y->update(pt ? pt->y : 0.f);
691 point_id->update(pt ? pt->id : 0);
692 point_list->update(pi);
695 double dist = cv->nearest_point(pi, output_x,output_y);
697 point_list->set_selected(pi);
700 if( (state & Button3Mask) ) {
701 if( (state & (ControlMask | AltMask)) ) { // drag selected curve(s)
702 int dx = round(output_x - last_x);
703 int dy = round(output_y - last_y);
704 for( int i=0; i<points.size(); ++i ) {
705 SketcherPoint *pt = points[i];
706 pt->x += dx; pt->y += dy;
708 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
710 point_x->update(pt ? pt->x : 0.f);
711 point_y->update(pt ? pt->y : 0.f);
712 point_id->update(pt ? pt->id : 0);
713 point_list->update(pi);
716 double dist = config.nearest_point(ci, pi, output_x,output_y);
718 curve_list->update(ci);
719 point_list->update(pi);
726 int SketcherWindow::keypress_event()
728 int key = get_keypress();
730 case DELETE: return shift_down() ?
731 del_curve->handle_event() :
732 del_point->handle_event() ;
738 SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
739 : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
742 this->plugin = plugin;
743 col_titles[CV_ID] = _("ID"); col_widths[CV_ID] = 64;
744 col_titles[CV_RAD] = _("width"); col_widths[CV_RAD] = 64;
745 col_titles[CV_PEN] = _("pen"); col_widths[CV_PEN] = 64;
746 col_titles[CV_CLR] = _("color"); col_widths[CV_CLR] = 80;
747 col_titles[CV_ALP] = _("alpha"); col_widths[CV_ALP] = 64;
749 SketcherCurveList::~SketcherCurveList()
753 void SketcherCurveList::clear()
755 for( int i=CV_SZ; --i>=0; )
756 cols[i].remove_all_objects();
759 int SketcherCurveList::column_resize_event()
761 for( int i=CV_SZ; --i>=0; )
762 col_widths[i] = get_column_width(i);
766 int SketcherCurveList::handle_event()
768 int ci = get_selection_number(0, 0);
770 gui->point_list->update(0);
771 gui->send_configure_change();
775 int SketcherCurveList::selection_changed()
781 void SketcherCurveList::set_selected(int k)
784 if( k >= 0 && k < plugin->config.curves.size() ) {
785 SketcherCurve *cv = plugin->config.curves[k];
786 gui->curve_width->update(cv->width);
787 gui->curve_pen->update(cv->pen);
788 gui->curve_color->update_gui(cv->color);
791 plugin->config.cv_selected = ci;
795 void SketcherCurveList::update_list(int k)
797 int xpos = get_xposition(), ypos = get_yposition();
798 if( k >= 0 ) update_selection(&cols[0], k);
799 BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],CV_SZ, xpos,ypos,k);
803 void SketcherCurveList::update(int k)
806 SketcherCurves &curves = plugin->config.curves;
807 int sz = curves.size();
808 for( int i=0; i<sz; ++i ) {
809 SketcherCurve *cv = curves[i];
810 char itxt[BCSTRLEN]; sprintf(itxt,"%d", cv->id);
811 char ptxt[BCSTRLEN]; sprintf(ptxt,"%s", cv_pen[cv->pen]);
812 char rtxt[BCSTRLEN]; sprintf(rtxt,"%d", cv->width);
813 int color = cv->color;
814 int r = (color>>16)&0xff;
815 int g = (color>> 8)&0xff;
816 int b = (color>> 0)&0xff;
817 int a = (~color>>24)&0xff;
818 char ctxt[BCSTRLEN]; sprintf(ctxt,"#%02x%02x%02x", r, g, b);
819 char atxt[BCSTRLEN]; sprintf(atxt,"%5.3f", a/255.);
820 add_curve(itxt, ptxt, rtxt, ctxt, atxt);
825 void SketcherCurveList::add_curve(const char *id, const char *pen,
826 const char *width, const char *color, const char *alpha)
828 cols[CV_ID].append(new BC_ListBoxItem(id));
829 cols[CV_RAD].append(new BC_ListBoxItem(width));
830 cols[CV_PEN].append(new BC_ListBoxItem(pen));
831 cols[CV_CLR].append(new BC_ListBoxItem(color));
832 cols[CV_ALP].append(new BC_ListBoxItem(alpha));
835 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
836 : BC_GenericButton(x, y, 64, _("New"))
839 this->plugin = plugin;
841 SketcherNewCurve::~SketcherNewCurve()
844 int SketcherNewCurve::handle_event()
846 int pen = gui->curve_pen->pen;
847 int color = gui->curve_color->color;
848 int width = gui->curve_width->width;
849 int ci = plugin->config.cv_selected;
850 if( ci >= 0 && ci < plugin->config.curves.size() ) {
851 SketcherCurve *cv = plugin->config.curves[ci];
852 pen = cv->pen; width = cv->width; color = cv->color;
854 ci = plugin->new_curve(pen, width, color);
855 gui->curve_list->update(ci);
856 gui->point_list->update(-1);
857 gui->send_configure_change();
861 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
862 : BC_GenericButton(x, y, 64, C_("Del"))
865 this->plugin = plugin;
867 SketcherDelCurve::~SketcherDelCurve()
870 int SketcherDelCurve::handle_event()
872 SketcherConfig &config = plugin->config;
873 int ci = config.cv_selected;
874 SketcherCurves &curves = config.curves;
875 if( ci >= 0 && ci < curves.size() ) {
876 curves.remove_object_number(ci--);
879 ci = plugin->new_curve();
880 gui->curve_list->update(ci);
881 gui->point_list->update(-1);
882 gui->send_configure_change();
887 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
888 : BC_GenericButton(x, y, _("Up"))
892 SketcherCurveUp::~SketcherCurveUp()
896 int SketcherCurveUp::handle_event()
898 SketcherConfig &config = gui->plugin->config;
899 int ci = config.cv_selected;
900 SketcherCurves &curves = config.curves;
901 if( ci > 0 && ci < curves.size() ) {
902 SketcherCurve *&cv0 = curves[ci];
903 SketcherCurve *&cv1 = curves[--ci];
904 SketcherCurve *t = cv0; cv0 = cv1; cv1 = t;
905 gui->curve_list->update(ci);
907 gui->send_configure_change();
911 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
912 : BC_GenericButton(x, y, _("Dn"))
916 SketcherCurveDn::~SketcherCurveDn()
920 int SketcherCurveDn::handle_event()
922 SketcherConfig &config = gui->plugin->config;
923 int ci = config.cv_selected;
924 SketcherCurves &curves = config.curves;
925 if( ci >= 0 && ci < curves.size()-1 ) {
926 SketcherCurve *&cv0 = curves[ci];
927 SketcherCurve *&cv1 = curves[++ci];
928 SketcherCurve *t = cv0; cv0 = cv1; cv1 = t;
929 gui->curve_list->update(ci);
931 gui->send_configure_change();
936 SketcherPointTypeItem::SketcherPointTypeItem(int arc)
937 : BC_MenuItem(_(pt_type[arc]))
941 int SketcherPointTypeItem::handle_event()
943 SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
945 SketcherWindow *gui = popup->gui;
946 SketcherConfig &config = gui->plugin->config;
947 SketcherCurves &curves = config.curves;
948 int ci = config.cv_selected;
949 if( ci < 0 || ci >= curves.size() )
951 SketcherCurve *cv = curves[ci];
952 SketcherPoints &points = cv->points;
953 int pi = config.pt_selected;
955 ArrayList<int> selected;
956 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
959 for( int i=selected.size(); --i>=0; ) {
961 if( k < 0 || k >= points.size() ) continue;
962 SketcherPoint *pt = cv->points[k];
964 gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
967 gui->point_list->update_list(pi);
968 gui->send_configure_change();
972 SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc)
973 : BC_PopupMenu(x,y,64,_(pt_type[arc]))
978 void SketcherPointType::create_objects()
980 for( int arc=0; arc<PT_SZ; ++arc )
981 add_item(new SketcherPointTypeItem(arc));
983 void SketcherPointType::update(int arc)
985 set_text(_(pt_type[this->type=arc]));
989 SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
990 : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
993 this->plugin = plugin;
994 col_titles[PT_ID] = _("ID"); col_widths[PT_ID] = 50;
995 col_titles[PT_TY] = _("Type"); col_widths[PT_TY] = 80;
996 col_titles[PT_X] = _("X"); col_widths[PT_X] = 90;
997 col_titles[PT_Y] = _("Y"); col_widths[PT_Y] = 90;
998 set_selection_mode(LISTBOX_MULTIPLE);
1000 SketcherPointList::~SketcherPointList()
1004 void SketcherPointList::clear()
1006 for( int i=PT_SZ; --i>=0; )
1007 cols[i].remove_all_objects();
1010 int SketcherPointList::column_resize_event()
1012 for( int i=PT_SZ; --i>=0; )
1013 col_widths[i] = get_column_width(i);
1017 int SketcherPointList::handle_event()
1019 int pi = get_selection_number(0, 0);
1020 if( get_selection_number(0, 1) >= 0 ) pi = -1;
1022 gui->send_configure_change();
1026 int SketcherPointList::selection_changed()
1032 void SketcherPointList::add_point(const char *id, const char *ty, const char *xp, const char *yp)
1034 cols[PT_ID].append(new BC_ListBoxItem(id));
1035 cols[PT_TY].append(new BC_ListBoxItem(ty));
1036 cols[PT_X].append(new BC_ListBoxItem(xp));
1037 cols[PT_Y].append(new BC_ListBoxItem(yp));
1040 void SketcherPointList::set_point(int i, int c, int v)
1042 char stxt[BCSTRLEN];
1043 sprintf(stxt,"%d",v);
1044 set_point(i,c,stxt);
1046 void SketcherPointList::set_point(int i, int c, coord v)
1048 char stxt[BCSTRLEN];
1049 sprintf(stxt,"%0.1f",v);
1050 set_point(i,c,stxt);
1052 void SketcherPointList::set_point(int i, int c, const char *cp)
1054 cols[c].get(i)->set_text(cp);
1057 void SketcherPointList::set_selected(int k)
1059 SketcherPoint *pt = 0;
1060 int ci = plugin->config.cv_selected, pi = -1;
1061 if( ci >= 0 && ci < plugin->config.curves.size() ) {
1062 SketcherCurve *cv = plugin->config.curves[ci];
1063 pt = k >= 0 && k < cv->points.size() ? cv->points[pi=k] : 0;
1065 gui->point_type->update(pt ? pt->arc : ARC_OFF);
1066 gui->point_x->update(pt ? pt->x : 0.f);
1067 gui->point_y->update(pt ? pt->y : 0.f);
1068 gui->point_id->update(pt ? pt->id : 0);
1069 plugin->config.pt_selected = pi;
1072 void SketcherPointList::update_list(int k)
1074 int xpos = get_xposition(), ypos = get_yposition();
1075 if( k >= 0 ) update_selection(&cols[0], k);
1076 BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],PT_SZ, xpos,ypos,k);
1079 void SketcherPointList::update(int k)
1082 int ci = plugin->config.cv_selected, sz = 0;
1083 if( ci >= 0 && ci < plugin->config.curves.size() ) {
1084 SketcherCurve *cv = plugin->config.curves[ci];
1085 SketcherPoints &points = cv->points;
1087 for( int i=0; i<sz; ++i ) {
1088 SketcherPoint *pt = points[i];
1089 char itxt[BCSTRLEN]; sprintf(itxt,"%d", pt->id);
1090 char ttxt[BCSTRLEN]; sprintf(ttxt,"%s", _(pt_type[pt->arc]));
1091 char xtxt[BCSTRLEN]; sprintf(xtxt,"%0.1f", pt->x);
1092 char ytxt[BCSTRLEN]; sprintf(ytxt,"%0.1f", pt->y);
1093 add_point(itxt, ttxt, xtxt, ytxt);
1099 void SketcherWindow::update_gui()
1101 SketcherConfig &config = plugin->config;
1102 int ci = config.cv_selected;
1103 int pi = config.pt_selected;
1104 curve_list->update(ci);
1105 point_list->update(pi);
1106 SketcherCurve *cv = ci >= 0 ? config.curves[ci] : 0;
1107 curve_width->update(cv ? cv->width : 1);
1108 curve_pen->update(cv ? cv->pen : PEN_SQUARE);
1109 curve_color->set_color(cv ? cv->color : CV_COLOR);
1110 SketcherPoint *pt = pi >= 0 ? cv->points[pi] : 0;
1111 point_x->update(pt ? pt->x : 0);
1112 point_y->update(pt ? pt->y : 0);
1113 point_id->update(pt ? pt->id : 0);
1114 drag->update(plugin->config.drag);
1118 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
1119 : BC_GenericButton(x, y, _("Up"))
1123 SketcherPointUp::~SketcherPointUp()
1127 int SketcherPointUp::handle_event()
1129 SketcherConfig &config = gui->plugin->config;
1130 int ci = config.cv_selected;
1131 if( ci < 0 || ci >= config.curves.size() )
1133 SketcherCurve *cv = config.curves[ci];
1134 SketcherPoints &points = cv->points;
1135 if( points.size() < 2 )
1137 int pi = config.pt_selected;
1139 ArrayList<int> selected;
1140 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1143 for( int i=0; i<selected.size(); ++i ) {
1144 int k = selected[i];
1145 if( k <= 0 ) continue;
1147 SketcherPoint *&pt0 = points[k];
1148 SketcherPoint *&pt1 = points[--k];
1149 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1151 gui->point_list->update(pi);
1152 gui->send_configure_change();
1156 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
1157 : BC_GenericButton(x, y, _("Dn"))
1161 SketcherPointDn::~SketcherPointDn()
1165 int SketcherPointDn::handle_event()
1167 SketcherConfig &config = gui->plugin->config;
1168 int ci = config.cv_selected;
1169 if( ci < 0 || ci >= config.curves.size() )
1171 SketcherCurve *cv = config.curves[ci];
1172 SketcherPoints &points = cv->points;
1173 int sz1 = points.size()-1;
1176 int pi = config.pt_selected;
1178 ArrayList<int> selected;
1179 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1182 for( int i=selected.size(); --i>=0; ) {
1183 int k = selected[i];
1184 if( k >= sz1 ) continue;
1186 SketcherPoint *&pt0 = points[k];
1187 SketcherPoint *&pt1 = points[++k];
1188 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1190 gui->point_list->update(pi);
1191 gui->send_configure_change();
1195 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
1196 : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
1200 int SketcherDrag::handle_event()
1202 CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
1203 int value = get_value();
1205 if( !gui->grab(cwindow_gui) ) {
1211 gui->ungrab(cwindow_gui);
1212 gui->plugin->config.drag = value;
1213 gui->send_configure_change();
1217 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1218 : BC_GenericButton(x, y, 64, _("New"))
1221 this->plugin = plugin;
1223 SketcherNewPoint::~SketcherNewPoint()
1226 int SketcherNewPoint::handle_event()
1228 int pi = plugin->config.pt_selected;
1229 int arc = gui->point_type->type;
1230 int k = plugin->new_point(pi+1, arc);
1231 gui->point_list->update(k);
1232 gui->send_configure_change();
1236 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1237 : BC_GenericButton(x, y, 64, C_("Del"))
1240 this->plugin = plugin;
1242 SketcherDelPoint::~SketcherDelPoint()
1245 int SketcherDelPoint::handle_event()
1247 SketcherConfig &config = gui->plugin->config;
1248 SketcherCurves &curves = config.curves;
1249 int ci = config.cv_selected;
1250 if( ci < 0 || ci >= curves.size() )
1252 SketcherCurve *cv = curves[ci];
1253 SketcherPoints &points = cv->points;
1254 int pi = config.pt_selected;
1256 ArrayList<int> selected;
1257 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1260 for( int i=selected.size(); --i>=0; ) {
1261 int k = selected[i];
1262 if( k < 0 || k >= points.size() ) continue;
1263 points.remove_object_number(k);
1264 if( k == pi && --pi < 0 && points.size() > 0 ) pi = 0;
1266 gui->point_list->update(pi);
1267 gui->send_configure_change();
1271 SketcherResetCurves::SketcherResetCurves(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1272 : BC_GenericButton(x, y, _("Reset"))
1275 this->plugin = plugin;
1277 SketcherResetCurves::~SketcherResetCurves()
1280 int SketcherResetCurves::handle_event()
1282 SketcherConfig &config = plugin->config;
1283 config.curves.remove_all_objects();
1284 int ci = plugin->new_curve();
1285 gui->curve_list->update(ci);
1286 gui->point_list->update(-1);
1287 gui->send_configure_change();
1291 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1292 : BC_GenericButton(x, y, _("Reset"))
1295 this->plugin = plugin;
1297 SketcherResetPoints::~SketcherResetPoints()
1300 int SketcherResetPoints::handle_event()
1302 SketcherConfig &config = gui->plugin->config;
1303 int ci = config.cv_selected;
1304 if( ci >= 0 && ci < config.curves.size() ) {
1305 SketcherCurve *cv = config.curves[ci];
1306 cv->points.remove_all_objects();
1307 gui->point_list->update(-1);
1308 gui->send_configure_change();