add stacked edl editing, add sketcher/vframe line anti-aliasing
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / sketcher / sketcherwindow.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2014 Adam Williams <broadcast at earthling dot net>
4  *
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.
9  *
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.
14  *
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
18  *
19  */
20
21 #include "automation.h"
22 #include "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "sketcher.h"
25 #include "sketcherwindow.h"
26 #include "cstrdup.h"
27 #include "cwindow.h"
28 #include "cwindowgui.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "keys.h"
32 #include "language.h"
33 #include "mainerror.h"
34 #include "mwindow.h"
35 #include "plugin.h"
36 #include "pluginserver.h"
37 #include "theme.h"
38 #include "track.h"
39
40 #define AltMask Mod1Mask
41
42 #define COLOR_W xS(40)
43 #define COLOR_H yS(24)
44
45 const char *SketcherPoint::types[] = {
46         N_("off"),
47         N_("line"),
48         N_("curve"),
49         N_("fill"),
50 };
51 const char *SketcherCurve::pens[] = {
52         N_("off"),
53         N_("box"),
54         N_("+"),
55         N_("/"),
56         N_("X"),
57 };
58
59
60 SketcherCurvePenItem::SketcherCurvePenItem(int pen)
61  : BC_MenuItem(_(SketcherCurve::pens[pen]))
62 {
63         this->pen = pen;
64 }
65 int SketcherCurvePenItem::handle_event()
66 {
67         SketcherCurvePen *popup = (SketcherCurvePen*)get_popup_menu();
68         popup->update(pen);
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];
74                 cv->pen = pen;
75                 gui->curve_list->update(ci);
76                 gui->send_configure_change();
77         }
78         return 1;
79 }
80
81 SketcherCurvePen::SketcherCurvePen(SketcherWindow *gui, int x, int y, int pen)
82  : BC_PopupMenu(x,y,xS(100),_(cv_pen[pen]))
83 {
84         this->gui = gui;
85         this->pen = pen;
86 }
87 void SketcherCurvePen::create_objects()
88 {
89         int n = sizeof(cv_pen)/sizeof(cv_pen[0]);
90         for( int pen=0; pen<n; ++pen )
91                 add_item(new SketcherCurvePenItem(pen));
92 }
93 void SketcherCurvePen::update(int pen)
94 {
95         set_text(_(cv_pen[this->pen=pen]));
96 }
97
98
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)
102 {
103         this->gui = gui;
104         this->color = CV_COLOR;
105 }
106
107 SketcherCurveColor::~SketcherCurveColor()
108 {
109 }
110
111 void SketcherCurveColor::handle_done_event(int result)
112 {
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];
118                 cv->color = color;
119                 gui->lock_window("SketcherCurveColor::handle_done_event");
120                 gui->curve_list->update(ci);
121                 gui->unlock_window();
122                 gui->send_configure_change();
123         }
124 }
125
126 int SketcherCurveColor::handle_new_color(int color, int alpha)
127 {
128         color |= ~alpha<<24;  this->color = color;
129         gui->lock_window("SketcherCurveColor::update_gui");
130         update_gui(color);
131         SketcherConfig &config = gui->plugin->config;
132         int ci = config.cv_selected;
133         if( ci >= 0 ) {
134                 SketcherCurve *cv = config.curves[ci];
135                 cv->color = color;
136                 gui->curve_list->update(ci);
137                 gui->send_configure_change();
138         }
139         gui->unlock_window();
140         return 1;
141 }
142
143
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)
147 {
148         this->gui = gui;
149         set_increment(1);
150 }
151 SketcherCoord::~SketcherCoord()
152 {
153 }
154
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)
158 {
159         this->gui = gui;
160         set_increment(1);
161 }
162 SketcherNum::~SketcherNum()
163 {
164 }
165
166 int SketcherPointX::handle_event()
167 {
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());
178                         points[pi]->x = v;
179                         point_list->set_point(pi, PT_X, v);
180                         point_list->update_list(pi);
181                         gui->send_configure_change();
182                 }
183         }
184         return 1;
185 }
186 int SketcherPointY::handle_event()
187 {
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());
198                         points[pi]->y = v;
199                         point_list->set_point(pi, PT_Y, v);
200                         point_list->update_list(pi);
201                         gui->send_configure_change();
202                 }
203         }
204         return 1;
205 }
206
207 int SketcherPointId::handle_event()
208 {
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());
219                         points[pi]->id = id;
220                         point_list->set_point(pi, PT_ID, id);
221                         point_list->update_list(pi);
222                         gui->send_configure_change();
223                 }
224         }
225         return 1;
226 }
227
228 SketcherCurveWidth::SketcherCurveWidth(SketcherWindow *gui, int x, int y, int width)
229  : SketcherNum(gui, x, y, width, 0, 255)
230 {
231         this->width = width;
232 }
233 SketcherCurveWidth::~SketcherCurveWidth()
234 {
235 }
236
237 int SketcherCurveWidth::handle_event()
238 {
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());
245                 cv->width = v;
246                 gui->curve_list->update(ci);
247                 gui->send_configure_change();
248         }
249         return 1;
250 }
251
252 void SketcherCurveWidth::update(int width)
253 {
254         SketcherNum::update(this->width=width);
255 }
256
257
258 SketcherAliasItem::SketcherAliasItem(SketcherAliasing *popup, int v)
259  : BC_MenuItem(popup->alias_to_text(v))
260 {
261         this->popup = popup;
262         this->v = v;
263 }
264
265 int SketcherAliasItem::handle_event()
266 {
267         popup->set_text(get_text());
268         popup->plugin->config.aliasing = v;
269         popup->gui->send_configure_change();
270         return 1;
271 }
272
273
274 SketcherAliasing::SketcherAliasing(SketcherWindow *gui, Sketcher *plugin,
275                 int x, int y)
276  : BC_PopupMenu(x, y, xS(64),
277                 alias_to_text(plugin->config.aliasing), 1, 0, xS(3))
278 {
279         this->gui = gui;
280         this->plugin = plugin;
281 }
282 SketcherAliasing::~SketcherAliasing()
283 {
284 }
285
286 void SketcherAliasing::create_objects()
287 {
288         add_item(new SketcherAliasItem(this, -1));
289         add_item(new SketcherAliasItem(this, 0));
290         add_item(new SketcherAliasItem(this, 1));
291 }
292
293 const char *SketcherAliasing::alias_to_text(int alias)
294 {
295         if( alias < 0 ) return _("Off");
296         if( alias > 0 ) return _("Dbl");
297         return _("On");
298 }
299
300
301
302 SketcherWindow::SketcherWindow(Sketcher *plugin)
303  : PluginClientWindow(plugin, xS(400), yS(620), xS(400), yS(620), 0)
304 {
305         this->plugin = plugin;
306         this->title_pen = 0;  this->curve_pen = 0;
307         this->title_color = 0; this->curve_color = 0;
308         this->drag = 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;
318
319         position = -1;
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;
326         new_points = 0;
327         pending_motion = 0;
328         pending_config = 0;
329 }
330
331 SketcherWindow::~SketcherWindow()
332 {
333         delete curve_width;
334         delete point_x;
335         delete point_y;
336 }
337
338 void SketcherWindow::create_objects()
339 {
340         int x = xS(10), y = yS(10), dy = 0, x1, y1;
341         int margin = plugin->get_theme()->widget_border;
342         BC_Title *title;
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];
347
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;
362
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;
371
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;
386
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);
401
402         BC_Bar *bar;
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;
408
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;
418                 }
419         }
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;
428
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;
437
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;
454
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);
470
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;
474
475         add_subwindow(notes0 = new BC_Title(x, y,
476                  _("\n"
477                    "Shift=\n"
478                    "None=\n"
479                    "Ctrl=\n"
480                    "Ctrl+Alt=\n"
481                    "Ctrl+Shift=")));    dy = bmax(dy, notes0->get_h());
482         add_subwindow(notes1 = new BC_Title(x+xS(100), y,
483                  _("     LMB\n"
484                    "new line point\n"
485                    "select point\n"
486                    "drag point\n"
487                    "drag all curves\n"
488                    "new fill point"))); dy = bmax(dy, notes1->get_h());
489         add_subwindow(notes2 = new BC_Title(x+xS(220), y,
490                  _("      RMB\n"
491                    "new arc point\n"
492                    "select curve\n"
493                    "drag curve\n"
494                    "new curve\n"
495                    "new off point"))); dy = bmax(dy, notes2->get_h());
496         y += dy + margin + yS(10);
497
498         add_subwindow(notes3 = new BC_Title(x, y,
499                    "Key DEL= delete point, +Shift= delete curve\n"));
500         show_window(1);
501 }
502
503 void SketcherWindow::done_event(int result)
504 {
505         curve_color->close_picker();
506         ungrab(plugin->server->mwindow->cwindow->gui);
507 }
508
509 void SketcherWindow::send_configure_change()
510 {
511         pending_config = 0;
512         plugin->send_configure_change();
513 }
514
515
516 int SketcherWindow::grab_event(XEvent *event)
517 {
518         int ret = do_grab_event(event);
519         if( !grab_event_count() ) {
520                 if( grab_cursor_motion() )
521                         pending_config = 1;
522                 if( pending_config ) {
523                         last_x = track_x;  last_y = track_y;
524                         send_configure_change();
525                 }
526         }
527         return ret;
528 }
529
530 int SketcherWindow::do_grab_event(XEvent *event)
531 {
532         switch( event->type ) {
533         case ButtonPress: break;
534         case ButtonRelease: break;
535         case MotionNotify: break;
536         case KeyPress:
537                 if( keysym_lookup(event) > 0 ) {
538                         switch( get_keysym() ) {
539                         case XK_Delete:
540                                 pending_config = 1;
541                                 return (event->xkey.state & ShiftMask) ?
542                                         del_curve->handle_event() :
543                                         del_point->handle_event() ;
544                         }
545                 } // fall thru
546         default:
547                 return 0;
548         }
549
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;
556
557         if( !dragging ) {
558                 if( output_x < 0 || output_x >= canvas->view_w ||
559                     output_y < 0 || output_y >= canvas->view_h )
560                         return 0;
561         }
562
563
564         switch( event->type ) {
565         case ButtonPress:
566                 if( dragging ) return 0;
567                 dragging = 1;
568                 break;
569         case ButtonRelease:
570                 dragging = 0;
571                 break;
572         case MotionNotify:
573                 if( dragging ) break;
574         default: // fall thru
575                 return 0;
576         }
577
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;
581
582         if( event->type == MotionNotify ) {
583                 memcpy(&motion_event, event, sizeof(motion_event));
584                 pending_motion = 1;
585                 return 1;
586         }
587         if( grab_cursor_motion() )
588                 pending_config = 1;
589
590         switch( event->type ) {
591         case ButtonPress:
592                 pending_config = grab_button_press(event);
593                 break;
594         case ButtonRelease:
595                 new_points = 0;
596                 break;
597         }
598
599         return 1;
600 }
601
602 int SketcherWindow::grab_button_press(XEvent *event)
603 {
604         SketcherConfig &config = plugin->config;
605         int ci = config.cv_selected;
606         if( ci < 0 || ci >= plugin->config.curves.size() )
607                 return 0;
608         MWindow *mwindow = plugin->server->mwindow;
609         CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
610         CWindowCanvas *canvas = cwindow_gui->canvas;
611
612         SketcherCurves &curves = config.curves;
613         SketcherCurve *cv = curves[ci];
614         SketcherPoints &points = cv->points;
615         int pi = config.pt_selected;
616
617         int button_no = event->xbutton.button;
618         switch( button_no ) {
619         case LEFT_BUTTON: {
620                 if( (state & ShiftMask) ) { // create new point/string
621                         ++new_points;
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);
626                         break;
627                 }
628                 SketcherPoint *pt = 0; // select point
629                 double dist = cv->nearest_point(pi, track_x,track_y);
630                 if( dist >= 0 ) {
631                         pt = points[pi];
632                         float cx, cy;
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 ) {
638                                 pi = -1;  pt = 0;
639                         }
640                 }
641                 point_list->set_selected(pi);
642                 break; }
643         case RIGHT_BUTTON: {
644                 if( (state & ShiftMask) ) { // create new curve point
645                         ++new_points;
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);
650                         break;
651                 }
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);
656                         break;
657                 }
658                 SketcherPoint *pt = 0;
659                 double dist = config.nearest_point(ci, pi, track_x,track_y);
660                 if( dist >= 0 ) {
661                         pt = curves[ci]->points[pi];
662                         float cx, cy;
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;
669                         }
670                 }
671                 if( pt ) {
672                         curve_list->update(ci);
673                         point_list->update(pi);
674                 }
675                 break; }
676         }
677         return 1;
678 }
679
680 int SketcherWindow::grab_cursor_motion()
681 {
682         if( !pending_motion )
683                 return 0;
684         pending_motion = 0;
685         SketcherConfig &config = plugin->config;
686         int ci = config.cv_selected;
687         if( ci < 0 || ci >= plugin->config.curves.size() )
688                 return 0;
689         SketcherCurves &curves = config.curves;
690         SketcherCurve *cv = curves[ci];
691         SketcherPoints &points = cv->points;
692         int pi = config.pt_selected;
693
694         if( (state & ShiftMask) ) {  // string of points
695                 if( (state & (Button1Mask|Button3Mask)) ) {
696                         SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
697                         if( pt ) {
698                                 float dist = DISTANCE(pt->x, pt->y, track_x, track_y);
699                                 if( dist < get_w()*0.1 ) return 0; // tolerance w/10
700                         }
701                         ++new_points;
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);
705                 }
706                 return 1;
707         }
708         if( (state & Button1Mask) ) {
709                 if( (state & ControlMask) && !(state & AltMask) ) { // drag selected point
710                         SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
711                         if( pt ) {
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);
717                         }
718                         return 1;
719                 }
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;
729                                 }
730                         }
731                         SketcherPoint *pt = pi >= 0 && pi < points.size() ?
732                                 points[pi] : 0;
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);
737                         return 1;
738                 }
739                 double dist = cv->nearest_point(pi, track_x,track_y);
740                 if( dist >= 0 )
741                         point_list->set_selected(pi);
742                 return 1;
743         }
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;
751                         }
752                         SketcherPoint *pt = pi >= 0 && pi < points.size() ?
753                                 points[pi] : 0;
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);
758                         return 1;
759                 }
760                 double dist = config.nearest_point(ci, pi, track_x,track_y);
761                 if( dist >= 0 ) {
762                         curve_list->update(ci);
763                         point_list->update(pi);
764                 }
765                 return 1;
766         }
767         return 0;
768 }
769
770 int SketcherWindow::keypress_event()
771 {
772         int key = get_keypress();
773         switch( key ) {
774         case DELETE: return shift_down() ?
775                         del_curve->handle_event() :
776                         del_point->handle_event() ;
777         }
778         return 0;
779 }
780
781
782 SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
783  : BC_ListBox(x, y, xS(360), yS(130), LISTBOX_TEXT)
784 {
785         this->gui = gui;
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);
792 }
793 SketcherCurveList::~SketcherCurveList()
794 {
795         clear();
796 }
797 void SketcherCurveList::clear()
798 {
799         for( int i=CV_SZ; --i>=0; )
800                 cols[i].remove_all_objects();
801 }
802
803 int SketcherCurveList::column_resize_event()
804 {
805         for( int i=CV_SZ; --i>=0; )
806                 col_widths[i] = get_column_width(i);
807         return 1;
808 }
809
810 int SketcherCurveList::handle_event()
811 {
812         int ci = get_selection_number(0, 0);
813         set_selected(ci);
814         gui->point_list->update(0);
815         gui->send_configure_change();
816         return 1;
817 }
818
819 int SketcherCurveList::selection_changed()
820 {
821         gui->curve_color->close_picker();
822         handle_event();
823         return 1;
824 }
825
826 void SketcherCurveList::set_selected(int k)
827 {
828         int ci = -1;
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);
834                 ci = k;
835         }
836         plugin->config.cv_selected = ci;
837         update_list(ci);
838 }
839
840 void SketcherCurveList::update_list(int k)
841 {
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);
845         center_selection();
846 }
847
848 void SketcherCurveList::update(int k)
849 {
850         clear();
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);
866         }
867         set_selected(k);
868 }
869
870 void SketcherCurveList::add_curve(const char *id, const char *pen,
871                 const char *width, const char *color, const char *alpha)
872 {
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));
878 }
879
880 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
881  : BC_GenericButton(x, y, xS(64), _("New"))
882 {
883         this->gui = gui;
884         this->plugin = plugin;
885 }
886 SketcherNewCurve::~SketcherNewCurve()
887 {
888 }
889 int SketcherNewCurve::handle_event()
890 {
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;
898         }
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();
903         return 1;
904 }
905
906 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
907  : BC_GenericButton(x, y, xS(64), C_("Del"))
908 {
909         this->gui = gui;
910         this->plugin = plugin;
911 }
912 SketcherDelCurve::~SketcherDelCurve()
913 {
914 }
915 int SketcherDelCurve::handle_event()
916 {
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--);
922                 if( ci < 0 ) ci = 0;
923                 if( !curves.size() )
924                         ci = plugin->new_curve();
925                 gui->curve_list->update(ci);
926                 gui->point_list->update(-1);
927                 gui->send_configure_change();
928         }
929         return 1;
930 }
931
932 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
933  : BC_GenericButton(x, y, _("Up"))
934 {
935         this->gui = gui;
936 }
937 SketcherCurveUp::~SketcherCurveUp()
938 {
939 }
940
941 int SketcherCurveUp::handle_event()
942 {
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);
951         }
952         gui->send_configure_change();
953         return 1;
954 }
955
956 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
957  : BC_GenericButton(x, y, _("Dn"))
958 {
959         this->gui = gui;
960 }
961 SketcherCurveDn::~SketcherCurveDn()
962 {
963 }
964
965 int SketcherCurveDn::handle_event()
966 {
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);
975         }
976         gui->send_configure_change();
977         return 1;
978 }
979
980
981 SketcherPointTypeItem::SketcherPointTypeItem(int arc)
982  : BC_MenuItem(_(pt_type[arc]))
983 {
984         this->arc = arc;
985 }
986 int SketcherPointTypeItem::handle_event()
987 {
988         SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
989         popup->update(arc);
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() )
995                 return 1;
996         SketcherCurve *cv = curves[ci];
997         SketcherPoints &points = cv->points;
998         int pi = config.pt_selected;
999
1000         ArrayList<int> selected;
1001         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1002                 selected.append(v);
1003
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];
1008                 pt->arc = arc;
1009                 gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
1010         }
1011
1012         gui->point_list->update_list(pi);
1013         gui->send_configure_change();
1014         return 1;
1015 }
1016
1017 SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc)
1018  : BC_PopupMenu(x,y,xS(100),_(pt_type[arc]))
1019 {
1020         this->gui = gui;
1021         this->type = arc;
1022 }
1023 void SketcherPointType::create_objects()
1024 {
1025         for( int arc=0; arc<PT_SZ; ++arc )
1026                 add_item(new SketcherPointTypeItem(arc));
1027 }
1028 void SketcherPointType::update(int arc)
1029 {
1030         set_text(_(pt_type[this->type=arc]));
1031 }
1032
1033
1034 SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1035  : BC_ListBox(x, y, xS(360), yS(130), LISTBOX_TEXT)
1036 {
1037         this->gui = gui;
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);
1044 }
1045 SketcherPointList::~SketcherPointList()
1046 {
1047         clear();
1048 }
1049 void SketcherPointList::clear()
1050 {
1051         for( int i=PT_SZ; --i>=0; )
1052                 cols[i].remove_all_objects();
1053 }
1054
1055 int SketcherPointList::column_resize_event()
1056 {
1057         for( int i=PT_SZ; --i>=0; )
1058                 col_widths[i] = get_column_width(i);
1059         return 1;
1060 }
1061
1062 int SketcherPointList::handle_event()
1063 {
1064         int pi = get_selection_number(0, 0);
1065         if( get_selection_number(0, 1) >= 0 ) pi = -1;
1066         set_selected(pi);
1067         gui->send_configure_change();
1068         return 1;
1069 }
1070
1071 int SketcherPointList::selection_changed()
1072 {
1073         handle_event();
1074         return 1;
1075 }
1076
1077 void SketcherPointList::add_point(const char *id, const char *ty, const char *xp, const char *yp)
1078 {
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));
1083 }
1084
1085 void SketcherPointList::set_point(int i, int c, int v)
1086 {
1087         char stxt[BCSTRLEN];
1088         sprintf(stxt,"%d",v);
1089         set_point(i,c,stxt);
1090 }
1091 void SketcherPointList::set_point(int i, int c, coord v)
1092 {
1093         char stxt[BCSTRLEN];
1094         sprintf(stxt,"%0.1f",v);
1095         set_point(i,c,stxt);
1096 }
1097 void SketcherPointList::set_point(int i, int c, const char *cp)
1098 {
1099         cols[c].get(i)->set_text(cp);
1100 }
1101
1102 void SketcherPointList::set_selected(int k)
1103 {
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;
1109         }
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;
1115         update_list(pi);
1116 }
1117 void SketcherPointList::update_list(int k)
1118 {
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);
1122         center_selection();
1123 }
1124 void SketcherPointList::update(int k)
1125 {
1126         clear();
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;
1131                 sz = points.size();
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);
1139                 }
1140         }
1141         set_selected(k);
1142 }
1143
1144 void SketcherWindow::update_gui()
1145 {
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);
1160 }
1161
1162
1163 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
1164  : BC_GenericButton(x, y, _("Up"))
1165 {
1166         this->gui = gui;
1167 }
1168 SketcherPointUp::~SketcherPointUp()
1169 {
1170 }
1171
1172 int SketcherPointUp::handle_event()
1173 {
1174         SketcherConfig &config = gui->plugin->config;
1175         int ci = config.cv_selected;
1176         if( ci < 0 || ci >= config.curves.size() )
1177                 return 1;
1178         SketcherCurve *cv = config.curves[ci];
1179         SketcherPoints &points = cv->points;
1180         if( points.size() < 2 )
1181                 return 1;
1182         int pi = config.pt_selected;
1183
1184         ArrayList<int> selected;
1185         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1186                 selected.append(v);
1187
1188         for( int i=0; i<selected.size(); ++i ) {
1189                 int k = selected[i];
1190                 if( k <= 0 ) continue;
1191                 if( k == pi ) --pi;
1192                 SketcherPoint *&pt0 = points[k];
1193                 SketcherPoint *&pt1 = points[--k];
1194                 SketcherPoint *t = pt0;  pt0 = pt1;  pt1 = t;
1195         }
1196         gui->point_list->update(pi);
1197         gui->send_configure_change();
1198         return 1;
1199 }
1200
1201 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
1202  : BC_GenericButton(x, y, _("Dn"))
1203 {
1204         this->gui = gui;
1205 }
1206 SketcherPointDn::~SketcherPointDn()
1207 {
1208 }
1209
1210 int SketcherPointDn::handle_event()
1211 {
1212         SketcherConfig &config = gui->plugin->config;
1213         int ci = config.cv_selected;
1214         if( ci < 0 || ci >= config.curves.size() )
1215                 return 1;
1216         SketcherCurve *cv = config.curves[ci];
1217         SketcherPoints &points = cv->points;
1218         int sz1 = points.size()-1;
1219         if( sz1 < 1 )
1220                 return 1;
1221         int pi = config.pt_selected;
1222
1223         ArrayList<int> selected;
1224         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1225                 selected.append(v);
1226
1227         for( int i=selected.size(); --i>=0; ) {
1228                 int k = selected[i];
1229                 if( k >= sz1 ) continue;
1230                 if( k == pi ) ++pi;
1231                 SketcherPoint *&pt0 = points[k];
1232                 SketcherPoint *&pt1 = points[++k];
1233                 SketcherPoint *t = pt0;  pt0 = pt1;  pt1 = t;
1234         }
1235         gui->point_list->update(pi);
1236         gui->send_configure_change();
1237         return 1;
1238 }
1239
1240 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
1241  : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
1242 {
1243         this->gui = gui;
1244 }
1245 int SketcherDrag::handle_event()
1246 {
1247         CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
1248         int value = get_value();
1249         if( value ) {
1250                 if( !gui->grab(cwindow_gui) ) {
1251                         update(value = 0);
1252                         flicker(10,50);
1253                 }
1254         }
1255         else
1256                 gui->ungrab(cwindow_gui);
1257         gui->plugin->config.drag = value;
1258         gui->send_configure_change();
1259         return 1;
1260 }
1261
1262 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1263  : BC_GenericButton(x, y, xS(64), _("New"))
1264 {
1265         this->gui = gui;
1266         this->plugin = plugin;
1267 }
1268 SketcherNewPoint::~SketcherNewPoint()
1269 {
1270 }
1271 int SketcherNewPoint::handle_event()
1272 {
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();
1278         return 1;
1279 }
1280
1281 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1282  : BC_GenericButton(x, y, xS(64), C_("Del"))
1283 {
1284         this->gui = gui;
1285         this->plugin = plugin;
1286 }
1287 SketcherDelPoint::~SketcherDelPoint()
1288 {
1289 }
1290 int SketcherDelPoint::handle_event()
1291 {
1292         SketcherConfig &config = gui->plugin->config;
1293         SketcherCurves &curves = config.curves;
1294         int ci = config.cv_selected;
1295         if( ci < 0 || ci >= curves.size() )
1296                 return 1;
1297         SketcherCurve *cv = curves[ci];
1298         SketcherPoints &points = cv->points;
1299         int pi = config.pt_selected;
1300
1301         ArrayList<int> selected;
1302         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1303                 selected.append(v);
1304
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;
1310         }
1311         gui->point_list->update(pi);
1312         gui->send_configure_change();
1313         return 1;
1314 }
1315
1316 SketcherResetCurves::SketcherResetCurves(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1317  : BC_GenericButton(x, y, _("Reset"))
1318 {
1319         this->gui = gui;
1320         this->plugin = plugin;
1321 }
1322 SketcherResetCurves::~SketcherResetCurves()
1323 {
1324 }
1325 int SketcherResetCurves::handle_event()
1326 {
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();
1333         return 1;
1334 }
1335
1336 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1337  : BC_GenericButton(x, y, _("Reset"))
1338 {
1339         this->gui = gui;
1340         this->plugin = plugin;
1341 }
1342 SketcherResetPoints::~SketcherResetPoints()
1343 {
1344 }
1345 int SketcherResetPoints::handle_event()
1346 {
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();
1354         }
1355         return 1;
1356 }
1357