7cbf15dd14b27b920bcde42b7da4a8c327d9ac34
[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 40
43 #define COLOR_H 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,72,_(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         for( int i=0; i<3; ++i ) {
106                 vframes[i] = new VFrame(w, h, BC_RGB888);
107                 vframes[i]->clear_frame();
108         }
109 }
110
111 SketcherCurveColor::~SketcherCurveColor()
112 {
113         for( int i=0; i<3; ++i )
114                 delete vframes[i];
115 }
116
117 void SketcherCurveColor::handle_done_event(int result)
118 {
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];
124                 cv->color = color;
125                 gui->curve_list->update(ci);
126                 gui->send_configure_change();
127         }
128 }
129
130 int SketcherCurveColor::handle_new_color(int color, int alpha)
131 {
132         color |= ~alpha<<24;  this->color = color;
133         gui->lock_window("SketcherCurveColor::update_gui");
134         update_gui(color);
135         SketcherConfig &config = gui->plugin->config;
136         int ci = config.cv_selected;
137         if( ci >= 0 ) {
138                 SketcherCurve *cv = config.curves[ci];
139                 cv->color = color;
140                 gui->curve_list->update(ci);
141                 gui->send_configure_change();
142         }
143         gui->unlock_window();
144         return 1;
145 }
146
147
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)
151 {
152         this->gui = gui;
153         set_increment(1);
154 }
155 SketcherCoord::~SketcherCoord()
156 {
157 }
158
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)
162 {
163         this->gui = gui;
164         set_increment(1);
165 }
166 SketcherNum::~SketcherNum()
167 {
168 }
169
170 int SketcherPointX::handle_event()
171 {
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());
182                         points[pi]->x = v;
183                         point_list->set_point(pi, PT_X, v);
184                         point_list->update_list(pi);
185                         gui->send_configure_change();
186                 }
187         }
188         return 1;
189 }
190 int SketcherPointY::handle_event()
191 {
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());
202                         points[pi]->y = v;
203                         point_list->set_point(pi, PT_Y, v);
204                         point_list->update_list(pi);
205                         gui->send_configure_change();
206                 }
207         }
208         return 1;
209 }
210
211 int SketcherPointId::handle_event()
212 {
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());
223                         points[pi]->id = id;
224                         point_list->set_point(pi, PT_ID, id);
225                         point_list->update_list(pi);
226                         gui->send_configure_change();
227                 }
228         }
229         return 1;
230 }
231
232 SketcherCurveWidth::SketcherCurveWidth(SketcherWindow *gui, int x, int y, int width)
233  : SketcherNum(gui, x, y, width, 0, 255)
234 {
235         this->width = width;
236 }
237 SketcherCurveWidth::~SketcherCurveWidth()
238 {
239 }
240
241 int SketcherCurveWidth::handle_event()
242 {
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());
249                 cv->width = v;
250                 gui->curve_list->update(ci);
251                 gui->send_configure_change();
252         }
253         return 1;
254 }
255
256 void SketcherCurveWidth::update(int width)
257 {
258         SketcherNum::update(this->width=width);
259 }
260
261
262 SketcherWindow::SketcherWindow(Sketcher *plugin)
263  : PluginClientWindow(plugin, 380, 620, 380, 620, 0)
264 {
265         this->plugin = plugin;
266         this->title_pen = 0;  this->curve_pen = 0;
267         this->title_color = 0; this->curve_color = 0;
268         this->drag = 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;
278
279         position = -1;
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;
286         new_points = 0;
287         pending_motion = 0;
288         pending_config = 0;
289 }
290
291 SketcherWindow::~SketcherWindow()
292 {
293         delete curve_width;
294         delete point_x;
295         delete point_y;
296 }
297
298 void SketcherWindow::create_objects()
299 {
300         int x = 10, y = 10, dy = 0, x1, y1;
301         int margin = plugin->get_theme()->widget_border;
302         BC_Title *title;
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];
307
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;
318
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;
327
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;
342
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);
357
358         BC_Bar *bar;
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());
363         y += dy + 2*margin;
364
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;
374                 }
375         }
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;
384
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;
393
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;
410
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);
426
427         bar = new BC_Bar(x, y, get_w()-2*x);
428         add_subwindow(bar);             dy = bmax(dy,bar->get_h());
429         y += dy + 2*margin;
430
431         add_subwindow(notes0 = new BC_Title(x, y,
432                  _("\n"
433                    "Shift=\n"
434                    "None=\n"
435                    "Ctrl=\n"
436                    "Alt=\n"
437                    "Ctrl+Shift=")));    dy = bmax(dy, notes0->get_h());
438         add_subwindow(notes1 = new BC_Title(x+100, y,
439                  _("     LMB\n"
440                    "new line point\n"
441                    "select point\n"
442                    "drag point\n"
443                    "drag all curves\n"
444                    "new fill point"))); dy = bmax(dy, notes1->get_h());
445         add_subwindow(notes2 = new BC_Title(x+220, y,
446                  _("      RMB\n"
447                    "new arc point\n"
448                    "select curve\n"
449                    "drag curve\n"
450                    "new curve\n"
451                    "new off point"))); dy = bmax(dy, notes2->get_h());
452         y += dy + margin + 10;
453
454         add_subwindow(notes3 = new BC_Title(x, y,
455                    "Key DEL= delete point, +Shift= delete curve\n"));
456         show_window(1);
457 }
458
459 void SketcherWindow::done_event(int result)
460 {
461 }
462
463 void SketcherWindow::send_configure_change()
464 {
465         pending_config = 0;
466         plugin->send_configure_change();
467 }
468
469
470 int SketcherWindow::grab_event(XEvent *event)
471 {
472         int ret = do_grab_event(event);
473         if( !grab_event_count() ) {
474                 if( grab_cursor_motion() )
475                         pending_config = 1;
476                 if( pending_config ) {
477                         last_x = output_x;  last_y = output_y;
478                         send_configure_change();
479                 }
480         }
481         return ret;
482 }
483
484 int SketcherWindow::do_grab_event(XEvent *event)
485 {
486         switch( event->type ) {
487         case ButtonPress: break;
488         case ButtonRelease: break;
489         case MotionNotify: break;
490         case KeyPress:
491                 if( keysym_lookup(event) > 0 ) {
492                         switch( get_keysym() ) {
493                         case XK_Delete:
494                                 pending_config = 1;
495                                 return (event->xkey.state & ShiftMask) ?
496                                         del_curve->handle_event() :
497                                         del_point->handle_event() ;
498                         }
499                 } // fall thru
500         default:
501                 return 0;
502         }
503
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;
510
511         if( !dragging ) {
512                 if( cx < 0 || cx >= mwindow->theme->ccanvas_w ||
513                     cy < 0 || cy >= mwindow->theme->ccanvas_h )
514                         return 0;
515         }
516
517         switch( event->type ) {
518         case ButtonPress:
519                 if( dragging ) return 0;
520                 dragging = 1;
521                 break;
522         case ButtonRelease:
523                 dragging = 0;
524                 break;
525         case MotionNotify:
526                 if( dragging ) break;
527         default: // fall thru
528                 return 0;
529         }
530
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;
545
546         if( event->type == MotionNotify ) {
547                 memcpy(&motion_event, event, sizeof(motion_event));
548                 pending_motion = 1;
549                 return 1;
550         }
551         if( grab_cursor_motion() )
552                 pending_config = 1;
553
554         switch( event->type ) {
555         case ButtonPress:
556                 pending_config = grab_button_press(event);
557                 break;
558         case ButtonRelease:
559                 new_points = 0;
560                 break;
561         }
562
563         return 1;
564 }
565
566 int SketcherWindow::grab_button_press(XEvent *event)
567 {
568         SketcherConfig &config = plugin->config;
569         int ci = config.cv_selected;
570         if( ci < 0 || ci >= plugin->config.curves.size() )
571                 return 0;
572         SketcherCurves &curves = config.curves;
573         SketcherCurve *cv = curves[ci];
574         SketcherPoints &points = cv->points;
575         int pi = config.pt_selected;
576
577         int button_no = event->xbutton.button;
578         switch( button_no ) {
579         case LEFT_BUTTON: {
580                 if( (state & ShiftMask) ) { // create new point/string
581                         ++new_points;
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);
586                         break;
587                 }
588                 SketcherPoint *pt = 0; // select point
589                 double dist = cv->nearest_point(pi, output_x,output_y);
590                 if( dist >= 0 ) {
591                         pt = points[pi];
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; }
598                 }
599                 point_list->set_selected(pi);
600                 break; }
601         case RIGHT_BUTTON: {
602                 if( (state & ShiftMask) ) { // create new curve point
603                         ++new_points;
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);
608                         break;
609                 }
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);
614                         break;
615                 }
616                 SketcherPoint *pt = 0;
617                 double dist = config.nearest_point(ci, pi, output_x,output_y);
618                 if( dist >= 0 ) {
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; }
626                 }
627                 if( pt ) {
628                         curve_list->update(ci);
629                         point_list->update(pi);
630                 }
631                 break; }
632         }
633         return 1;
634 }
635
636 int SketcherWindow::grab_cursor_motion()
637 {
638         if( !pending_motion )
639                 return 0;
640         pending_motion = 0;
641         SketcherConfig &config = plugin->config;
642         int ci = config.cv_selected;
643         if( ci < 0 || ci >= plugin->config.curves.size() )
644                 return 0;
645         SketcherCurves &curves = config.curves;
646         SketcherCurve *cv = curves[ci];
647         SketcherPoints &points = cv->points;
648         int pi = config.pt_selected;
649
650         if( (state & ShiftMask) ) {  // string of points
651                 if( (state & (Button1Mask|Button3Mask)) ) {
652                         SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
653                         if( pt ) {
654                                 float dist = DISTANCE(pt->x, pt->y, output_x, output_y);
655                                 if( dist < get_w()*0.1 ) return 0; // tolerance w/10
656                         }
657                         ++new_points;
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);
661                 }
662                 return 1;
663         }
664         if( (state & Button1Mask) ) {
665                 if( (state & ControlMask) ) { // drag selected point
666                         SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
667                         if( pt ) {
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);
673                         }
674                         return 1;
675                 }
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;
685                                 }
686                         }
687                         SketcherPoint *pt = pi >= 0 && pi < points.size() ?
688                                 points[pi] : 0;
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);
693                         return 1;
694                 }
695                 double dist = cv->nearest_point(pi, output_x,output_y);
696                 if( dist >= 0 )
697                         point_list->set_selected(pi);
698                 return 1;
699         }
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;
707                         }
708                         SketcherPoint *pt = pi >= 0 && pi < points.size() ?
709                                 points[pi] : 0;
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);
714                         return 1;
715                 }
716                 double dist = config.nearest_point(ci, pi, output_x,output_y);
717                 if( dist >= 0 ) {
718                         curve_list->update(ci);
719                         point_list->update(pi);
720                 }
721                 return 1;
722         }
723         return 0;
724 }
725
726 int SketcherWindow::keypress_event()
727 {
728         int key = get_keypress();
729         switch( key ) {
730         case DELETE: return shift_down() ?
731                         del_curve->handle_event() :
732                         del_point->handle_event() ;
733         }
734         return 0;
735 }
736
737
738 SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
739  : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
740 {
741         this->gui = gui;
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;
748 }
749 SketcherCurveList::~SketcherCurveList()
750 {
751         clear();
752 }
753 void SketcherCurveList::clear()
754 {
755         for( int i=CV_SZ; --i>=0; )
756                 cols[i].remove_all_objects();
757 }
758
759 int SketcherCurveList::column_resize_event()
760 {
761         for( int i=CV_SZ; --i>=0; )
762                 col_widths[i] = get_column_width(i);
763         return 1;
764 }
765
766 int SketcherCurveList::handle_event()
767 {
768         int ci = get_selection_number(0, 0);
769         set_selected(ci);
770         gui->point_list->update(0);
771         gui->send_configure_change();
772         return 1;
773 }
774
775 int SketcherCurveList::selection_changed()
776 {
777         handle_event();
778         return 1;
779 }
780
781 void SketcherCurveList::set_selected(int k)
782 {
783         int ci = -1;
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);
789                 ci = k;
790         }
791         plugin->config.cv_selected = ci;
792         update_list(ci);
793 }
794
795 void SketcherCurveList::update_list(int k)
796 {
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);
800         center_selection();
801 }
802
803 void SketcherCurveList::update(int k)
804 {
805         clear();
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);
821         }
822         set_selected(k);
823 }
824
825 void SketcherCurveList::add_curve(const char *id, const char *pen,
826                 const char *width, const char *color, const char *alpha)
827 {
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));
833 }
834
835 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
836  : BC_GenericButton(x, y, 64, _("New"))
837 {
838         this->gui = gui;
839         this->plugin = plugin;
840 }
841 SketcherNewCurve::~SketcherNewCurve()
842 {
843 }
844 int SketcherNewCurve::handle_event()
845 {
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;
853         }
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();
858         return 1;
859 }
860
861 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
862  : BC_GenericButton(x, y, 64, C_("Del"))
863 {
864         this->gui = gui;
865         this->plugin = plugin;
866 }
867 SketcherDelCurve::~SketcherDelCurve()
868 {
869 }
870 int SketcherDelCurve::handle_event()
871 {
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--);
877                 if( ci < 0 ) ci = 0;
878                 if( !curves.size() )
879                         ci = plugin->new_curve();
880                 gui->curve_list->update(ci);
881                 gui->point_list->update(-1);
882                 gui->send_configure_change();
883         }
884         return 1;
885 }
886
887 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
888  : BC_GenericButton(x, y, _("Up"))
889 {
890         this->gui = gui;
891 }
892 SketcherCurveUp::~SketcherCurveUp()
893 {
894 }
895
896 int SketcherCurveUp::handle_event()
897 {
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);
906         }
907         gui->send_configure_change();
908         return 1;
909 }
910
911 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
912  : BC_GenericButton(x, y, _("Dn"))
913 {
914         this->gui = gui;
915 }
916 SketcherCurveDn::~SketcherCurveDn()
917 {
918 }
919
920 int SketcherCurveDn::handle_event()
921 {
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);
930         }
931         gui->send_configure_change();
932         return 1;
933 }
934
935
936 SketcherPointTypeItem::SketcherPointTypeItem(int arc)
937  : BC_MenuItem(_(pt_type[arc]))
938 {
939         this->arc = arc;
940 }
941 int SketcherPointTypeItem::handle_event()
942 {
943         SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
944         popup->update(arc);
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() )
950                 return 1;
951         SketcherCurve *cv = curves[ci];
952         SketcherPoints &points = cv->points;
953         int pi = config.pt_selected;
954
955         ArrayList<int> selected;
956         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
957                 selected.append(v);
958
959         for( int i=selected.size(); --i>=0; ) {
960                 int k = selected[i];
961                 if( k < 0 || k >= points.size() ) continue;
962                 SketcherPoint *pt = cv->points[k];
963                 pt->arc = arc;
964                 gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
965         }
966
967         gui->point_list->update_list(pi);
968         gui->send_configure_change();
969         return 1;
970 }
971
972 SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc)
973  : BC_PopupMenu(x,y,64,_(pt_type[arc]))
974 {
975         this->gui = gui;
976         this->type = arc;
977 }
978 void SketcherPointType::create_objects()
979 {
980         for( int arc=0; arc<PT_SZ; ++arc )
981                 add_item(new SketcherPointTypeItem(arc));
982 }
983 void SketcherPointType::update(int arc)
984 {
985         set_text(_(pt_type[this->type=arc]));
986 }
987
988
989 SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
990  : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
991 {
992         this->gui = gui;
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);
999 }
1000 SketcherPointList::~SketcherPointList()
1001 {
1002         clear();
1003 }
1004 void SketcherPointList::clear()
1005 {
1006         for( int i=PT_SZ; --i>=0; )
1007                 cols[i].remove_all_objects();
1008 }
1009
1010 int SketcherPointList::column_resize_event()
1011 {
1012         for( int i=PT_SZ; --i>=0; )
1013                 col_widths[i] = get_column_width(i);
1014         return 1;
1015 }
1016
1017 int SketcherPointList::handle_event()
1018 {
1019         int pi = get_selection_number(0, 0);
1020         if( get_selection_number(0, 1) >= 0 ) pi = -1;
1021         set_selected(pi);
1022         gui->send_configure_change();
1023         return 1;
1024 }
1025
1026 int SketcherPointList::selection_changed()
1027 {
1028         handle_event();
1029         return 1;
1030 }
1031
1032 void SketcherPointList::add_point(const char *id, const char *ty, const char *xp, const char *yp)
1033 {
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));
1038 }
1039
1040 void SketcherPointList::set_point(int i, int c, int v)
1041 {
1042         char stxt[BCSTRLEN];
1043         sprintf(stxt,"%d",v);
1044         set_point(i,c,stxt);
1045 }
1046 void SketcherPointList::set_point(int i, int c, coord v)
1047 {
1048         char stxt[BCSTRLEN];
1049         sprintf(stxt,"%0.1f",v);
1050         set_point(i,c,stxt);
1051 }
1052 void SketcherPointList::set_point(int i, int c, const char *cp)
1053 {
1054         cols[c].get(i)->set_text(cp);
1055 }
1056
1057 void SketcherPointList::set_selected(int k)
1058 {
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;
1064         }
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;
1070         update_list(pi);
1071 }
1072 void SketcherPointList::update_list(int k)
1073 {
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);
1077         center_selection();
1078 }
1079 void SketcherPointList::update(int k)
1080 {
1081         clear();
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;
1086                 sz = points.size();
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);
1094                 }
1095         }
1096         set_selected(k);
1097 }
1098
1099 void SketcherWindow::update_gui()
1100 {
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);
1115 }
1116
1117
1118 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
1119  : BC_GenericButton(x, y, _("Up"))
1120 {
1121         this->gui = gui;
1122 }
1123 SketcherPointUp::~SketcherPointUp()
1124 {
1125 }
1126
1127 int SketcherPointUp::handle_event()
1128 {
1129         SketcherConfig &config = gui->plugin->config;
1130         int ci = config.cv_selected;
1131         if( ci < 0 || ci >= config.curves.size() )
1132                 return 1;
1133         SketcherCurve *cv = config.curves[ci];
1134         SketcherPoints &points = cv->points;
1135         if( points.size() < 2 )
1136                 return 1;
1137         int pi = config.pt_selected;
1138
1139         ArrayList<int> selected;
1140         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1141                 selected.append(v);
1142
1143         for( int i=0; i<selected.size(); ++i ) {
1144                 int k = selected[i];
1145                 if( k <= 0 ) continue;
1146                 if( k == pi ) --pi;
1147                 SketcherPoint *&pt0 = points[k];
1148                 SketcherPoint *&pt1 = points[--k];
1149                 SketcherPoint *t = pt0;  pt0 = pt1;  pt1 = t;
1150         }
1151         gui->point_list->update(pi);
1152         gui->send_configure_change();
1153         return 1;
1154 }
1155
1156 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
1157  : BC_GenericButton(x, y, _("Dn"))
1158 {
1159         this->gui = gui;
1160 }
1161 SketcherPointDn::~SketcherPointDn()
1162 {
1163 }
1164
1165 int SketcherPointDn::handle_event()
1166 {
1167         SketcherConfig &config = gui->plugin->config;
1168         int ci = config.cv_selected;
1169         if( ci < 0 || ci >= config.curves.size() )
1170                 return 1;
1171         SketcherCurve *cv = config.curves[ci];
1172         SketcherPoints &points = cv->points;
1173         int sz1 = points.size()-1;
1174         if( sz1 < 1 )
1175                 return 1;
1176         int pi = config.pt_selected;
1177
1178         ArrayList<int> selected;
1179         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1180                 selected.append(v);
1181
1182         for( int i=selected.size(); --i>=0; ) {
1183                 int k = selected[i];
1184                 if( k >= sz1 ) continue;
1185                 if( k == pi ) ++pi;
1186                 SketcherPoint *&pt0 = points[k];
1187                 SketcherPoint *&pt1 = points[++k];
1188                 SketcherPoint *t = pt0;  pt0 = pt1;  pt1 = t;
1189         }
1190         gui->point_list->update(pi);
1191         gui->send_configure_change();
1192         return 1;
1193 }
1194
1195 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
1196  : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
1197 {
1198         this->gui = gui;
1199 }
1200 int SketcherDrag::handle_event()
1201 {
1202         CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
1203         int value = get_value();
1204         if( value ) {
1205                 if( !gui->grab(cwindow_gui) ) {
1206                         update(value = 0);
1207                         flicker(10,50);
1208                 }
1209         }
1210         else
1211                 gui->ungrab(cwindow_gui);
1212         gui->plugin->config.drag = value;
1213         gui->send_configure_change();
1214         return 1;
1215 }
1216
1217 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1218  : BC_GenericButton(x, y, 64, _("New"))
1219 {
1220         this->gui = gui;
1221         this->plugin = plugin;
1222 }
1223 SketcherNewPoint::~SketcherNewPoint()
1224 {
1225 }
1226 int SketcherNewPoint::handle_event()
1227 {
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();
1233         return 1;
1234 }
1235
1236 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1237  : BC_GenericButton(x, y, 64, C_("Del"))
1238 {
1239         this->gui = gui;
1240         this->plugin = plugin;
1241 }
1242 SketcherDelPoint::~SketcherDelPoint()
1243 {
1244 }
1245 int SketcherDelPoint::handle_event()
1246 {
1247         SketcherConfig &config = gui->plugin->config;
1248         SketcherCurves &curves = config.curves;
1249         int ci = config.cv_selected;
1250         if( ci < 0 || ci >= curves.size() )
1251                 return 1;
1252         SketcherCurve *cv = curves[ci];
1253         SketcherPoints &points = cv->points;
1254         int pi = config.pt_selected;
1255
1256         ArrayList<int> selected;
1257         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1258                 selected.append(v);
1259
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;
1265         }
1266         gui->point_list->update(pi);
1267         gui->send_configure_change();
1268         return 1;
1269 }
1270
1271 SketcherResetCurves::SketcherResetCurves(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1272  : BC_GenericButton(x, y, _("Reset"))
1273 {
1274         this->gui = gui;
1275         this->plugin = plugin;
1276 }
1277 SketcherResetCurves::~SketcherResetCurves()
1278 {
1279 }
1280 int SketcherResetCurves::handle_event()
1281 {
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();
1288         return 1;
1289 }
1290
1291 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1292  : BC_GenericButton(x, y, _("Reset"))
1293 {
1294         this->gui = gui;
1295         this->plugin = plugin;
1296 }
1297 SketcherResetPoints::~SketcherResetPoints()
1298 {
1299 }
1300 int SketcherResetPoints::handle_event()
1301 {
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();
1309         }
1310         return 1;
1311 }
1312