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
42 #define COLOR_W xS(40)
43 #define COLOR_H yS(24)
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,xS(100),_(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;
107 SketcherCurveColor::~SketcherCurveColor()
111 void SketcherCurveColor::handle_done_event(int result)
113 if( result ) color = orig_color | (~orig_alpha<<24);
114 SketcherConfig &config = gui->plugin->config;
115 int ci = config.cv_selected;
116 if( ci >= 0 && ci < config.curves.size() ) {
117 SketcherCurve *cv = config.curves[ci];
119 gui->lock_window("SketcherCurveColor::handle_done_event");
120 gui->curve_list->update(ci);
121 gui->unlock_window();
122 gui->send_configure_change();
126 int SketcherCurveColor::handle_new_color(int color, int alpha)
128 color |= ~alpha<<24; this->color = color;
129 gui->lock_window("SketcherCurveColor::update_gui");
131 SketcherConfig &config = gui->plugin->config;
132 int ci = config.cv_selected;
134 SketcherCurve *cv = config.curves[ci];
136 gui->curve_list->update(ci);
137 gui->send_configure_change();
139 gui->unlock_window();
144 SketcherCoord::SketcherCoord(SketcherWindow *gui, int x, int y,
145 coord output, coord mn, coord mx)
146 : BC_TumbleTextBox(gui, output, mn, mx, x, y, 64, 1)
151 SketcherCoord::~SketcherCoord()
155 SketcherNum::SketcherNum(SketcherWindow *gui, int x, int y,
156 int output, int mn, int mx)
157 : BC_TumbleTextBox(gui, output, mn, mx, x, y, 54)
162 SketcherNum::~SketcherNum()
166 int SketcherPointX::handle_event()
168 if( !SketcherCoord::handle_event() ) return 0;
169 SketcherConfig &config = gui->plugin->config;
170 int ci = config.cv_selected;
171 if( ci >= 0 && ci < config.curves.size() ) {
172 SketcherCurve *cv = config.curves[ci];
173 SketcherPointList *point_list = gui->point_list;
174 int pi = config.pt_selected;
175 SketcherPoints &points = cv->points;
176 if( pi >= 0 && pi < points.size() ) {
177 coord v = atof(get_text());
179 point_list->set_point(pi, PT_X, v);
180 point_list->update_list(pi);
181 gui->send_configure_change();
186 int SketcherPointY::handle_event()
188 if( !SketcherCoord::handle_event() ) return 0;
189 SketcherConfig &config = gui->plugin->config;
190 int ci = config.cv_selected;
191 if( ci >= 0 && ci < config.curves.size() ) {
192 SketcherCurve *cv = config.curves[ci];
193 SketcherPointList *point_list = gui->point_list;
194 int pi = config.pt_selected;
195 SketcherPoints &points = cv->points;
196 if( pi >= 0 && pi < points.size() ) {
197 coord v = atof(get_text());
199 point_list->set_point(pi, PT_Y, v);
200 point_list->update_list(pi);
201 gui->send_configure_change();
207 int SketcherPointId::handle_event()
209 if( !SketcherNum::handle_event() ) return 0;
210 SketcherConfig &config = gui->plugin->config;
211 int ci = config.cv_selected;
212 if( ci >= 0 && ci < config.curves.size() ) {
213 SketcherCurve *cv = config.curves[ci];
214 SketcherPointList *point_list = gui->point_list;
215 int pi = config.pt_selected;
216 SketcherPoints &points = cv->points;
217 if( pi >= 0 && pi < points.size() ) {
218 int id = atoi(get_text());
220 point_list->set_point(pi, PT_ID, id);
221 point_list->update_list(pi);
222 gui->send_configure_change();
228 SketcherCurveWidth::SketcherCurveWidth(SketcherWindow *gui, int x, int y, int width)
229 : SketcherNum(gui, x, y, width, 0, 255)
233 SketcherCurveWidth::~SketcherCurveWidth()
237 int SketcherCurveWidth::handle_event()
239 if( !SketcherNum::handle_event() ) return 0;
240 SketcherConfig &config = gui->plugin->config;
241 int ci = config.cv_selected;
242 if( ci >= 0 && ci < config.curves.size() ) {
243 SketcherCurve *cv = config.curves[ci];
244 int v = atoi(get_text());
246 gui->curve_list->update(ci);
247 gui->send_configure_change();
252 void SketcherCurveWidth::update(int width)
254 SketcherNum::update(this->width=width);
258 SketcherAliasItem::SketcherAliasItem(SketcherAliasing *popup, int v)
259 : BC_MenuItem(popup->alias_to_text(v))
265 int SketcherAliasItem::handle_event()
267 popup->set_text(get_text());
268 popup->plugin->config.aliasing = v;
269 popup->gui->send_configure_change();
274 SketcherAliasing::SketcherAliasing(SketcherWindow *gui, Sketcher *plugin,
276 : BC_PopupMenu(x, y, xS(64),
277 alias_to_text(plugin->config.aliasing), 1, 0, xS(3))
280 this->plugin = plugin;
282 SketcherAliasing::~SketcherAliasing()
286 void SketcherAliasing::create_objects()
288 add_item(new SketcherAliasItem(this, -1));
289 add_item(new SketcherAliasItem(this, 0));
290 add_item(new SketcherAliasItem(this, 1));
293 const char *SketcherAliasing::alias_to_text(int alias)
295 if( alias < 0 ) return _("Off");
296 if( alias > 0 ) return _("Dbl");
302 SketcherWindow::SketcherWindow(Sketcher *plugin)
303 : PluginClientWindow(plugin, xS(400), yS(620), xS(400), yS(620), 0)
305 this->plugin = plugin;
306 this->title_pen = 0; this->curve_pen = 0;
307 this->title_color = 0; this->curve_color = 0;
309 this->new_curve = 0; this->del_curve = 0;
310 this->curve_up = 0; this->curve_dn = 0;
311 this->title_x = 0; this->point_x = 0;
312 this->title_y = 0; this->point_y = 0;
313 this->title_id = 0; this->point_id = 0;
314 this->new_point = 0; this->del_point = 0;
315 this->point_up = 0; this->point_dn = 0;
316 this->point_list = 0; this->notes0 = 0;
317 this->notes1 = 0; this->notes2 = 0;
320 track_w = track_h -1;
321 output_x = output_y = -1;
322 track_x = track_y = -1;
323 last_x = last_y = -1;
324 projector_x = projector_y = projector_z = -1;
325 state = 0; dragging = 0;
331 SketcherWindow::~SketcherWindow()
338 void SketcherWindow::create_objects()
340 int x = xS(10), y = yS(10), dy = 0, x1, y1;
341 int margin = plugin->get_theme()->widget_border;
343 int ci = plugin->config.cv_selected;
344 if( ci < 0 || ci >= plugin->config.curves.size() )
345 ci = plugin->new_curve();
346 SketcherCurve *cv = plugin->config.curves[ci];
348 reset_curves = new SketcherResetCurves(this, plugin, x1=x, y+yS(3));
349 add_subwindow(reset_curves); dy = bmax(dy,reset_curves->get_h());
350 x1 += reset_curves->get_w() + 2*margin;
351 const char *curve_text = _("Curve");
352 title_width = new BC_Title(x1, y, _("Width:"));
353 add_subwindow(title_width); dy = bmax(dy,title_width->get_h());
354 x1 += title_width->get_w() + margin;
355 curve_width = new SketcherCurveWidth(this, x1, y, cv->width);
356 curve_width->create_objects();
357 x1 += curve_width->get_w() + margin;
358 aliasing = new SketcherAliasing(this, plugin, x1, y);
359 add_subwindow(aliasing); dy = bmax(dy,aliasing->get_h());
360 aliasing->create_objects();
361 y += dy + 2*margin; dy = 0;
363 x1 = get_w()-x - BC_Title::calculate_w(this, curve_text, LARGEFONT);
364 y1 = y-margin - BC_Title::calculate_h(this, curve_text, LARGEFONT);
365 title = new BC_Title(x1, y1, curve_text, LARGEFONT,
366 get_resources()->menu_highlighted_fontcolor);
367 add_subwindow(title); dy = bmax(dy,title->get_h());
368 curve_list = new SketcherCurveList(this, plugin, x, y);
369 add_subwindow(curve_list); dy = bmax(dy,curve_list->get_h());
370 y += dy + margin; dy = 0;
372 new_curve = new SketcherNewCurve(this, plugin, x1=x, y);
373 add_subwindow(new_curve); dy = bmax(dy,new_curve->get_h());
374 x1 += new_curve->get_w() + margin;
375 curve_up = new SketcherCurveUp(this, x1, y);
376 add_subwindow(curve_up); dy = bmax(dy,curve_up->get_h());
377 x1 += curve_up->get_w() + 4*margin;
378 y1 = BC_Title::calculate_h(this, _("Pen:"));
379 title_pen = new BC_Title(x1+xS(30), y+dy-y1, _("Pen:"));
380 add_subwindow(title_pen); dy = bmax(dy,title_pen->get_h());
381 int x2 = (get_w()+x1)/2 + xS(20);
382 y1 = BC_Title::calculate_h(this, _("Color:"));
383 title_color = new BC_Title(x2, y+dy-y1, _("Color:"));
384 add_subwindow(title_color); dy = bmax(dy,title_color->get_h());
385 y += dy + margin; dy = 0;
387 del_curve = new SketcherDelCurve(this, plugin, x1=x, y);
388 add_subwindow(del_curve); dy = bmax(dy,del_curve->get_h());
389 x1 += del_curve->get_w() + margin;
390 curve_dn = new SketcherCurveDn(this, x1, y);
391 add_subwindow(curve_dn); dy = bmax(dy,curve_dn->get_h());
392 x1 += curve_dn->get_w() + 4*margin;
393 curve_pen = new SketcherCurvePen(this, x1, y, cv->pen);
394 add_subwindow(curve_pen); dy = bmax(dy,curve_pen->get_h());
395 curve_pen->create_objects();
396 curve_color = new SketcherCurveColor(this, x2, y, COLOR_W, COLOR_H,
397 cv->color&0xffffff, (~cv->color>>24)&0xff);
398 add_subwindow(curve_color); dy = bmax(dy,curve_color->get_h());
399 y += dy + margin; dy = 0;
400 curve_list->update(ci);
403 bar = new BC_Bar(x, y, get_w()-xS(2)*x);
404 add_subwindow(bar); dy = bmax(dy,bar->get_h());
405 bar = new BC_Bar(x, y+=dy, get_w()-xS(2)*x);
406 add_subwindow(bar); dy = bmax(dy,bar->get_h());
407 y += dy + yS(2)*margin;
409 int pi = plugin->config.pt_selected;
410 SketcherPoint *pt = pi >= 0 && pi < cv->points.size() ? cv->points[pi] : 0;
411 reset_points = new SketcherResetPoints(this, plugin, x1=x, y+yS(3));
412 add_subwindow(reset_points); dy = bmax(dy,reset_points->get_h());
413 x1 += reset_points->get_w() + xS(2)*margin;
414 if( plugin->config.drag ) {
415 if( !grab(plugin->server->mwindow->cwindow->gui) ) {
416 eprintf("drag enabled, but compositor already grabbed\n");
417 plugin->config.drag = 0;
420 drag = new SketcherDrag(this, x1, y);
421 add_subwindow(drag); dy = bmax(dy,drag->get_h());
422 x1 += drag->get_w() + xS(2)*margin;
423 int arc = pt ? pt->arc : ARC_LINE;
424 point_type = new SketcherPointType(this, x1, y, arc);
425 add_subwindow(point_type); dy = bmax(dy,point_type->get_h());
426 point_type->create_objects();
427 y += dy + margin; dy = 0;
429 const char *point_text = _("Point");
430 x1 = get_w()-x - BC_Title::calculate_w(this, point_text, LARGEFONT);
431 y1 = y-margin - BC_Title::calculate_h(this, point_text, LARGEFONT);
432 add_subwindow(title = new BC_Title(x1, y1, point_text, LARGEFONT,
433 get_resources()->menu_highlighted_fontcolor));
434 point_list = new SketcherPointList(this, plugin, x, y);
435 add_subwindow(point_list); dy = bmax(dy,point_list->get_h());
436 y += dy + margin; dy = 0;
438 new_point = new SketcherNewPoint(this, plugin, x1=x, y);
439 add_subwindow(new_point); dy = bmax(dy,new_point->get_h());
440 x1 += new_point->get_w() + margin;
441 point_up = new SketcherPointUp(this, x1, y);
442 add_subwindow(point_up); dy = bmax(dy,point_up->get_h());
443 x1 += point_up->get_w() + xS(2)*margin;
444 title_x = new BC_Title(x1, y, _("X:"));
445 add_subwindow(title_x); dy = bmax(dy,title_x->get_h());
446 x1 += title_x->get_w() + margin;
447 point_x = new SketcherPointX(this, x1, y, !pt ? 0.f : pt->x);
448 point_x->create_objects(); dy = bmax(dy, point_x->get_h());
449 x2 = x1 + point_x->get_w() + xS(2)*margin + xS(10);
450 y1 = BC_Title::calculate_h(this, _("ID:"));
451 title_id = new BC_Title(x2+xS(16), y+dy-y1, _("ID:"));
452 add_subwindow(title_id); dy = bmax(dy, title_id->get_h());
453 y += dy + margin; dy = 0;
455 del_point = new SketcherDelPoint(this, plugin, x1=x, y);
456 add_subwindow(del_point); dy = bmax(dy,del_point->get_h());
457 x1 += del_point->get_w() + margin;
458 point_dn = new SketcherPointDn(this, x1, y);
459 add_subwindow(point_dn); dy = bmax(dy,point_dn->get_h());
460 x1 += point_dn->get_w() + xS(2)*margin;
461 title_y = new BC_Title(x1, y, _("Y:"));
462 add_subwindow(title_y); dy = bmax(dy,title_y->get_h());
463 x1 += title_y->get_w() + margin;
464 point_y = new SketcherPointY(this, x1, y, !pt ? 0.f : pt->y);
465 point_y->create_objects(); dy = bmax(dy, point_y->get_h());
466 point_id = new SketcherPointId(this, x2, y, !pt ? 0 : pt->id);
467 point_id->create_objects(); dy = bmax(dy, point_id->get_h());
468 y += dy + margin + yS(5); dy = 0;
469 point_list->update(pi);
471 bar = new BC_Bar(x, y, get_w()-xS(2)*x);
472 add_subwindow(bar); dy = bmax(dy,bar->get_h());
473 y += dy + yS(2)*margin;
475 add_subwindow(notes0 = new BC_Title(x, y,
481 "Ctrl+Shift="))); dy = bmax(dy, notes0->get_h());
482 add_subwindow(notes1 = new BC_Title(x+xS(100), y,
488 "new fill point"))); dy = bmax(dy, notes1->get_h());
489 add_subwindow(notes2 = new BC_Title(x+xS(220), y,
495 "new off point"))); dy = bmax(dy, notes2->get_h());
496 y += dy + margin + yS(10);
498 add_subwindow(notes3 = new BC_Title(x, y,
499 "Key DEL= delete point, +Shift= delete curve\n"));
503 void SketcherWindow::done_event(int result)
505 curve_color->close_picker();
506 ungrab(plugin->server->mwindow->cwindow->gui);
509 void SketcherWindow::send_configure_change()
512 plugin->send_configure_change();
516 int SketcherWindow::grab_event(XEvent *event)
518 int ret = do_grab_event(event);
519 if( !grab_event_count() ) {
520 if( grab_cursor_motion() )
522 if( pending_config ) {
523 last_x = track_x; last_y = track_y;
524 send_configure_change();
530 int SketcherWindow::do_grab_event(XEvent *event)
532 switch( event->type ) {
533 case ButtonPress: break;
534 case ButtonRelease: break;
535 case MotionNotify: break;
537 if( keysym_lookup(event) > 0 ) {
538 switch( get_keysym() ) {
541 return (event->xkey.state & ShiftMask) ?
542 del_curve->handle_event() :
543 del_point->handle_event() ;
550 MWindow *mwindow = plugin->server->mwindow;
551 CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
552 CWindowCanvas *canvas = cwindow_gui->canvas;
553 cwindow_gui->get_relative_cursor(cursor_x, cursor_y);
554 output_x = cursor_x - canvas->view_x;
555 output_y = cursor_y - canvas->view_y;
558 if( output_x < 0 || output_x >= canvas->view_w ||
559 output_y < 0 || output_y >= canvas->view_h )
564 switch( event->type ) {
566 if( dragging ) return 0;
573 if( dragging ) break;
574 default: // fall thru
578 canvas->canvas_to_output(mwindow->edl, 0, output_x, output_y);
579 plugin->output_to_track(output_x, output_y, track_x, track_y);
580 state = event->xmotion.state;
582 if( event->type == MotionNotify ) {
583 memcpy(&motion_event, event, sizeof(motion_event));
587 if( grab_cursor_motion() )
590 switch( event->type ) {
592 pending_config = grab_button_press(event);
602 int SketcherWindow::grab_button_press(XEvent *event)
604 SketcherConfig &config = plugin->config;
605 int ci = config.cv_selected;
606 if( ci < 0 || ci >= plugin->config.curves.size() )
608 MWindow *mwindow = plugin->server->mwindow;
609 CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
610 CWindowCanvas *canvas = cwindow_gui->canvas;
612 SketcherCurves &curves = config.curves;
613 SketcherCurve *cv = curves[ci];
614 SketcherPoints &points = cv->points;
615 int pi = config.pt_selected;
617 int button_no = event->xbutton.button;
618 switch( button_no ) {
620 if( (state & ShiftMask) ) { // create new point/string
622 pi = plugin->new_point(cv,
623 !(state & ControlMask) ? ARC_LINE : ARC_FILL,
624 track_x, track_y, pi+1);
625 point_list->update(pi);
628 SketcherPoint *pt = 0; // select point
629 double dist = cv->nearest_point(pi, track_x,track_y);
633 plugin->track_to_output(pt->x, pt->y, cx, cy);
634 canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
635 cx += canvas->view_x; cy += canvas->view_y;
636 dist = DISTANCE(cx,cy, cursor_x,cursor_y);
637 if( (state & ControlMask) && dist >= HANDLE_W ) {
641 point_list->set_selected(pi);
644 if( (state & ShiftMask) ) { // create new curve point
646 pi = plugin->new_point(cv,
647 !(state & ControlMask) ? ARC_CURVE : ARC_OFF,
648 track_x, track_y, pi+1);
649 point_list->update(pi);
652 if( (state & ControlMask) && (state & AltMask) ) { // create new curve
653 ci = plugin->new_curve(cv->pen, cv->width, curve_color->color);
654 curve_list->update(ci);
655 point_list->update(-1);
658 SketcherPoint *pt = 0;
659 double dist = config.nearest_point(ci, pi, track_x,track_y);
661 pt = curves[ci]->points[pi];
663 plugin->track_to_output(pt->x, pt->y, cx, cy);
664 canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
665 cx += canvas->view_x; cy += canvas->view_y;
666 dist = DISTANCE(cx,cy, cursor_x,cursor_y);
667 if( (state & ControlMask) && dist >= HANDLE_W ) {
668 ci = pi = -1; pt = 0;
672 curve_list->update(ci);
673 point_list->update(pi);
680 int SketcherWindow::grab_cursor_motion()
682 if( !pending_motion )
685 SketcherConfig &config = plugin->config;
686 int ci = config.cv_selected;
687 if( ci < 0 || ci >= plugin->config.curves.size() )
689 SketcherCurves &curves = config.curves;
690 SketcherCurve *cv = curves[ci];
691 SketcherPoints &points = cv->points;
692 int pi = config.pt_selected;
694 if( (state & ShiftMask) ) { // string of points
695 if( (state & (Button1Mask|Button3Mask)) ) {
696 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
698 float dist = DISTANCE(pt->x, pt->y, track_x, track_y);
699 if( dist < get_w()*0.1 ) return 0; // tolerance w/10
702 int arc = (state & Button1Mask) ? ARC_LINE : ARC_CURVE;
703 pi = plugin->new_point(cv, arc, track_x, track_y, pi+1);
704 point_list->update(pi);
708 if( (state & Button1Mask) ) {
709 if( (state & ControlMask) && !(state & AltMask) ) { // drag selected point
710 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
712 point_list->set_point(pi, PT_X, pt->x = track_x);
713 point_list->set_point(pi, PT_Y, pt->y = track_y);
714 point_list->update_list(pi);
715 point_x->update(pt->x);
716 point_y->update(pt->y);
720 if( (state & ControlMask) && (state & AltMask) ) { // drag all curves
721 int dx = round(track_x - last_x);
722 int dy = round(track_y - last_y);
723 for( int i=0; i<curves.size(); ++i ) {
724 SketcherCurve *crv = plugin->config.curves[i];
725 int pts = crv->points.size();
726 for( int k=0; k<pts; ++k ) {
727 SketcherPoint *pt = crv->points[k];
728 pt->x += dx; pt->y += dy;
731 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
733 point_x->update(pt ? pt->x : 0.f);
734 point_y->update(pt ? pt->y : 0.f);
735 point_id->update(pt ? pt->id : 0);
736 point_list->update(pi);
739 double dist = cv->nearest_point(pi, track_x,track_y);
741 point_list->set_selected(pi);
744 if( (state & Button3Mask) ) {
745 if( (state & (ControlMask | AltMask)) ) { // drag selected curve(s)
746 int dx = round(track_x - last_x);
747 int dy = round(track_y - last_y);
748 for( int i=0; i<points.size(); ++i ) {
749 SketcherPoint *pt = points[i];
750 pt->x += dx; pt->y += dy;
752 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
754 point_x->update(pt ? pt->x : 0.f);
755 point_y->update(pt ? pt->y : 0.f);
756 point_id->update(pt ? pt->id : 0);
757 point_list->update(pi);
760 double dist = config.nearest_point(ci, pi, track_x,track_y);
762 curve_list->update(ci);
763 point_list->update(pi);
770 int SketcherWindow::keypress_event()
772 int key = get_keypress();
774 case DELETE: return shift_down() ?
775 del_curve->handle_event() :
776 del_point->handle_event() ;
782 SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
783 : BC_ListBox(x, y, xS(360), yS(130), LISTBOX_TEXT)
786 this->plugin = plugin;
787 col_titles[CV_ID] = _("ID"); col_widths[CV_ID] = xS(64);
788 col_titles[CV_RAD] = _("width"); col_widths[CV_RAD] = xS(64);
789 col_titles[CV_PEN] = _("pen"); col_widths[CV_PEN] = xS(64);
790 col_titles[CV_CLR] = _("color"); col_widths[CV_CLR] = xS(80);
791 col_titles[CV_ALP] = _("alpha"); col_widths[CV_ALP] = xS(64);
793 SketcherCurveList::~SketcherCurveList()
797 void SketcherCurveList::clear()
799 for( int i=CV_SZ; --i>=0; )
800 cols[i].remove_all_objects();
803 int SketcherCurveList::column_resize_event()
805 for( int i=CV_SZ; --i>=0; )
806 col_widths[i] = get_column_width(i);
810 int SketcherCurveList::handle_event()
812 int ci = get_selection_number(0, 0);
814 gui->point_list->update(0);
815 gui->send_configure_change();
819 int SketcherCurveList::selection_changed()
821 gui->curve_color->close_picker();
826 void SketcherCurveList::set_selected(int k)
829 if( k >= 0 && k < plugin->config.curves.size() ) {
830 SketcherCurve *cv = plugin->config.curves[k];
831 gui->curve_width->update(cv->width);
832 gui->curve_pen->update(cv->pen);
833 gui->curve_color->update_gui(cv->color);
836 plugin->config.cv_selected = ci;
840 void SketcherCurveList::update_list(int k)
842 int xpos = get_xposition(), ypos = get_yposition();
843 if( k >= 0 ) update_selection(&cols[0], k);
844 BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],CV_SZ, xpos,ypos,k);
848 void SketcherCurveList::update(int k)
851 SketcherCurves &curves = plugin->config.curves;
852 int sz = curves.size();
853 for( int i=0; i<sz; ++i ) {
854 SketcherCurve *cv = curves[i];
855 char itxt[BCSTRLEN]; sprintf(itxt,"%d", cv->id);
856 char ptxt[BCSTRLEN]; sprintf(ptxt,"%s", cv_pen[cv->pen]);
857 char rtxt[BCSTRLEN]; sprintf(rtxt,"%d", cv->width);
858 int color = cv->color;
859 int r = (color>>16)&0xff;
860 int g = (color>> 8)&0xff;
861 int b = (color>> 0)&0xff;
862 int a = (~color>>24)&0xff;
863 char ctxt[BCSTRLEN]; sprintf(ctxt,"#%02x%02x%02x", r, g, b);
864 char atxt[BCSTRLEN]; sprintf(atxt,"%5.3f", a/255.);
865 add_curve(itxt, ptxt, rtxt, ctxt, atxt);
870 void SketcherCurveList::add_curve(const char *id, const char *pen,
871 const char *width, const char *color, const char *alpha)
873 cols[CV_ID].append(new BC_ListBoxItem(id));
874 cols[CV_RAD].append(new BC_ListBoxItem(width));
875 cols[CV_PEN].append(new BC_ListBoxItem(pen));
876 cols[CV_CLR].append(new BC_ListBoxItem(color));
877 cols[CV_ALP].append(new BC_ListBoxItem(alpha));
880 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
881 : BC_GenericButton(x, y, xS(64), _("New"))
884 this->plugin = plugin;
886 SketcherNewCurve::~SketcherNewCurve()
889 int SketcherNewCurve::handle_event()
891 int pen = gui->curve_pen->pen;
892 int color = gui->curve_color->color;
893 int width = gui->curve_width->width;
894 int ci = plugin->config.cv_selected;
895 if( ci >= 0 && ci < plugin->config.curves.size() ) {
896 SketcherCurve *cv = plugin->config.curves[ci];
897 pen = cv->pen; width = cv->width; color = cv->color;
899 ci = plugin->new_curve(pen, width, color);
900 gui->curve_list->update(ci);
901 gui->point_list->update(-1);
902 gui->send_configure_change();
906 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
907 : BC_GenericButton(x, y, xS(64), C_("Del"))
910 this->plugin = plugin;
912 SketcherDelCurve::~SketcherDelCurve()
915 int SketcherDelCurve::handle_event()
917 SketcherConfig &config = plugin->config;
918 int ci = config.cv_selected;
919 SketcherCurves &curves = config.curves;
920 if( ci >= 0 && ci < curves.size() ) {
921 curves.remove_object_number(ci--);
924 ci = plugin->new_curve();
925 gui->curve_list->update(ci);
926 gui->point_list->update(-1);
927 gui->send_configure_change();
932 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
933 : BC_GenericButton(x, y, _("Up"))
937 SketcherCurveUp::~SketcherCurveUp()
941 int SketcherCurveUp::handle_event()
943 SketcherConfig &config = gui->plugin->config;
944 int ci = config.cv_selected;
945 SketcherCurves &curves = config.curves;
946 if( ci > 0 && ci < curves.size() ) {
947 SketcherCurve *&cv0 = curves[ci];
948 SketcherCurve *&cv1 = curves[--ci];
949 SketcherCurve *t = cv0; cv0 = cv1; cv1 = t;
950 gui->curve_list->update(ci);
952 gui->send_configure_change();
956 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
957 : BC_GenericButton(x, y, _("Dn"))
961 SketcherCurveDn::~SketcherCurveDn()
965 int SketcherCurveDn::handle_event()
967 SketcherConfig &config = gui->plugin->config;
968 int ci = config.cv_selected;
969 SketcherCurves &curves = config.curves;
970 if( ci >= 0 && ci < curves.size()-1 ) {
971 SketcherCurve *&cv0 = curves[ci];
972 SketcherCurve *&cv1 = curves[++ci];
973 SketcherCurve *t = cv0; cv0 = cv1; cv1 = t;
974 gui->curve_list->update(ci);
976 gui->send_configure_change();
981 SketcherPointTypeItem::SketcherPointTypeItem(int arc)
982 : BC_MenuItem(_(pt_type[arc]))
986 int SketcherPointTypeItem::handle_event()
988 SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
990 SketcherWindow *gui = popup->gui;
991 SketcherConfig &config = gui->plugin->config;
992 SketcherCurves &curves = config.curves;
993 int ci = config.cv_selected;
994 if( ci < 0 || ci >= curves.size() )
996 SketcherCurve *cv = curves[ci];
997 SketcherPoints &points = cv->points;
998 int pi = config.pt_selected;
1000 ArrayList<int> selected;
1001 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1004 for( int i=selected.size(); --i>=0; ) {
1005 int k = selected[i];
1006 if( k < 0 || k >= points.size() ) continue;
1007 SketcherPoint *pt = cv->points[k];
1009 gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
1012 gui->point_list->update_list(pi);
1013 gui->send_configure_change();
1017 SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc)
1018 : BC_PopupMenu(x,y,xS(100),_(pt_type[arc]))
1023 void SketcherPointType::create_objects()
1025 for( int arc=0; arc<PT_SZ; ++arc )
1026 add_item(new SketcherPointTypeItem(arc));
1028 void SketcherPointType::update(int arc)
1030 set_text(_(pt_type[this->type=arc]));
1034 SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1035 : BC_ListBox(x, y, xS(360), yS(130), LISTBOX_TEXT)
1038 this->plugin = plugin;
1039 col_titles[PT_ID] = _("ID"); col_widths[PT_ID] = xS(50);
1040 col_titles[PT_TY] = _("Type"); col_widths[PT_TY] = xS(80);
1041 col_titles[PT_X] = _("X"); col_widths[PT_X] = xS(90);
1042 col_titles[PT_Y] = _("Y"); col_widths[PT_Y] = xS(90);
1043 set_selection_mode(LISTBOX_MULTIPLE);
1045 SketcherPointList::~SketcherPointList()
1049 void SketcherPointList::clear()
1051 for( int i=PT_SZ; --i>=0; )
1052 cols[i].remove_all_objects();
1055 int SketcherPointList::column_resize_event()
1057 for( int i=PT_SZ; --i>=0; )
1058 col_widths[i] = get_column_width(i);
1062 int SketcherPointList::handle_event()
1064 int pi = get_selection_number(0, 0);
1065 if( get_selection_number(0, 1) >= 0 ) pi = -1;
1067 gui->send_configure_change();
1071 int SketcherPointList::selection_changed()
1077 void SketcherPointList::add_point(const char *id, const char *ty, const char *xp, const char *yp)
1079 cols[PT_ID].append(new BC_ListBoxItem(id));
1080 cols[PT_TY].append(new BC_ListBoxItem(ty));
1081 cols[PT_X].append(new BC_ListBoxItem(xp));
1082 cols[PT_Y].append(new BC_ListBoxItem(yp));
1085 void SketcherPointList::set_point(int i, int c, int v)
1087 char stxt[BCSTRLEN];
1088 sprintf(stxt,"%d",v);
1089 set_point(i,c,stxt);
1091 void SketcherPointList::set_point(int i, int c, coord v)
1093 char stxt[BCSTRLEN];
1094 sprintf(stxt,"%0.1f",v);
1095 set_point(i,c,stxt);
1097 void SketcherPointList::set_point(int i, int c, const char *cp)
1099 cols[c].get(i)->set_text(cp);
1102 void SketcherPointList::set_selected(int k)
1104 SketcherPoint *pt = 0;
1105 int ci = plugin->config.cv_selected, pi = -1;
1106 if( ci >= 0 && ci < plugin->config.curves.size() ) {
1107 SketcherCurve *cv = plugin->config.curves[ci];
1108 pt = k >= 0 && k < cv->points.size() ? cv->points[pi=k] : 0;
1110 gui->point_type->update(pt ? pt->arc : ARC_OFF);
1111 gui->point_x->update(pt ? pt->x : 0.f);
1112 gui->point_y->update(pt ? pt->y : 0.f);
1113 gui->point_id->update(pt ? pt->id : 0);
1114 plugin->config.pt_selected = pi;
1117 void SketcherPointList::update_list(int k)
1119 int xpos = get_xposition(), ypos = get_yposition();
1120 if( k >= 0 ) update_selection(&cols[0], k);
1121 BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],PT_SZ, xpos,ypos,k);
1124 void SketcherPointList::update(int k)
1127 int ci = plugin->config.cv_selected, sz = 0;
1128 if( ci >= 0 && ci < plugin->config.curves.size() ) {
1129 SketcherCurve *cv = plugin->config.curves[ci];
1130 SketcherPoints &points = cv->points;
1132 for( int i=0; i<sz; ++i ) {
1133 SketcherPoint *pt = points[i];
1134 char itxt[BCSTRLEN]; sprintf(itxt,"%d", pt->id);
1135 char ttxt[BCSTRLEN]; sprintf(ttxt,"%s", _(pt_type[pt->arc]));
1136 char xtxt[BCSTRLEN]; sprintf(xtxt,"%0.1f", pt->x);
1137 char ytxt[BCSTRLEN]; sprintf(ytxt,"%0.1f", pt->y);
1138 add_point(itxt, ttxt, xtxt, ytxt);
1144 void SketcherWindow::update_gui()
1146 SketcherConfig &config = plugin->config;
1147 int ci = config.cv_selected;
1148 int pi = config.pt_selected;
1149 curve_list->update(ci);
1150 point_list->update(pi);
1151 SketcherCurve *cv = ci >= 0 ? config.curves[ci] : 0;
1152 curve_width->update(cv ? cv->width : 1);
1153 curve_pen->update(cv ? cv->pen : PEN_SQUARE);
1154 curve_color->set_color(cv ? cv->color : CV_COLOR);
1155 SketcherPoint *pt = pi >= 0 ? cv->points[pi] : 0;
1156 point_x->update(pt ? pt->x : 0);
1157 point_y->update(pt ? pt->y : 0);
1158 point_id->update(pt ? pt->id : 0);
1159 drag->update(plugin->config.drag);
1163 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
1164 : BC_GenericButton(x, y, _("Up"))
1168 SketcherPointUp::~SketcherPointUp()
1172 int SketcherPointUp::handle_event()
1174 SketcherConfig &config = gui->plugin->config;
1175 int ci = config.cv_selected;
1176 if( ci < 0 || ci >= config.curves.size() )
1178 SketcherCurve *cv = config.curves[ci];
1179 SketcherPoints &points = cv->points;
1180 if( points.size() < 2 )
1182 int pi = config.pt_selected;
1184 ArrayList<int> selected;
1185 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1188 for( int i=0; i<selected.size(); ++i ) {
1189 int k = selected[i];
1190 if( k <= 0 ) continue;
1192 SketcherPoint *&pt0 = points[k];
1193 SketcherPoint *&pt1 = points[--k];
1194 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1196 gui->point_list->update(pi);
1197 gui->send_configure_change();
1201 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
1202 : BC_GenericButton(x, y, _("Dn"))
1206 SketcherPointDn::~SketcherPointDn()
1210 int SketcherPointDn::handle_event()
1212 SketcherConfig &config = gui->plugin->config;
1213 int ci = config.cv_selected;
1214 if( ci < 0 || ci >= config.curves.size() )
1216 SketcherCurve *cv = config.curves[ci];
1217 SketcherPoints &points = cv->points;
1218 int sz1 = points.size()-1;
1221 int pi = config.pt_selected;
1223 ArrayList<int> selected;
1224 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1227 for( int i=selected.size(); --i>=0; ) {
1228 int k = selected[i];
1229 if( k >= sz1 ) continue;
1231 SketcherPoint *&pt0 = points[k];
1232 SketcherPoint *&pt1 = points[++k];
1233 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1235 gui->point_list->update(pi);
1236 gui->send_configure_change();
1240 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
1241 : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
1245 int SketcherDrag::handle_event()
1247 CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
1248 int value = get_value();
1250 if( !gui->grab(cwindow_gui) ) {
1256 gui->ungrab(cwindow_gui);
1257 gui->plugin->config.drag = value;
1258 gui->send_configure_change();
1262 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1263 : BC_GenericButton(x, y, xS(64), _("New"))
1266 this->plugin = plugin;
1268 SketcherNewPoint::~SketcherNewPoint()
1271 int SketcherNewPoint::handle_event()
1273 int pi = plugin->config.pt_selected;
1274 int arc = gui->point_type->type;
1275 int k = plugin->new_point(pi+1, arc);
1276 gui->point_list->update(k);
1277 gui->send_configure_change();
1281 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1282 : BC_GenericButton(x, y, xS(64), C_("Del"))
1285 this->plugin = plugin;
1287 SketcherDelPoint::~SketcherDelPoint()
1290 int SketcherDelPoint::handle_event()
1292 SketcherConfig &config = gui->plugin->config;
1293 SketcherCurves &curves = config.curves;
1294 int ci = config.cv_selected;
1295 if( ci < 0 || ci >= curves.size() )
1297 SketcherCurve *cv = curves[ci];
1298 SketcherPoints &points = cv->points;
1299 int pi = config.pt_selected;
1301 ArrayList<int> selected;
1302 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1305 for( int i=selected.size(); --i>=0; ) {
1306 int k = selected[i];
1307 if( k < 0 || k >= points.size() ) continue;
1308 points.remove_object_number(k);
1309 if( k == pi && --pi < 0 && points.size() > 0 ) pi = 0;
1311 gui->point_list->update(pi);
1312 gui->send_configure_change();
1316 SketcherResetCurves::SketcherResetCurves(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1317 : BC_GenericButton(x, y, _("Reset"))
1320 this->plugin = plugin;
1322 SketcherResetCurves::~SketcherResetCurves()
1325 int SketcherResetCurves::handle_event()
1327 SketcherConfig &config = plugin->config;
1328 config.curves.remove_all_objects();
1329 int ci = plugin->new_curve();
1330 gui->curve_list->update(ci);
1331 gui->point_list->update(-1);
1332 gui->send_configure_change();
1336 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1337 : BC_GenericButton(x, y, _("Reset"))
1340 this->plugin = plugin;
1342 SketcherResetPoints::~SketcherResetPoints()
1345 int SketcherResetPoints::handle_event()
1347 SketcherConfig &config = gui->plugin->config;
1348 int ci = config.cv_selected;
1349 if( ci >= 0 && ci < config.curves.size() ) {
1350 SketcherCurve *cv = config.curves[ci];
1351 cv->points.remove_all_objects();
1352 gui->point_list->update(-1);
1353 gui->send_configure_change();