f835d0072f3415026defdd0d8b870e4387b5c175
[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,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         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->lock_window("SketcherCurveColor::handle_done_event");
126                 gui->curve_list->update(ci);
127                 gui->unlock_window();
128                 gui->send_configure_change();
129         }
130 }
131
132 int SketcherCurveColor::handle_new_color(int color, int alpha)
133 {
134         color |= ~alpha<<24;  this->color = color;
135         gui->lock_window("SketcherCurveColor::update_gui");
136         update_gui(color);
137         SketcherConfig &config = gui->plugin->config;
138         int ci = config.cv_selected;
139         if( ci >= 0 ) {
140                 SketcherCurve *cv = config.curves[ci];
141                 cv->color = color;
142                 gui->curve_list->update(ci);
143                 gui->send_configure_change();
144         }
145         gui->unlock_window();
146         return 1;
147 }
148
149
150 SketcherCoord::SketcherCoord(SketcherWindow *gui, int x, int y,
151                 coord output, coord mn, coord mx)
152  : BC_TumbleTextBox(gui, output, mn, mx, x, y, 64, 1)
153 {
154         this->gui = gui;
155         set_increment(1);
156 }
157 SketcherCoord::~SketcherCoord()
158 {
159 }
160
161 SketcherNum::SketcherNum(SketcherWindow *gui, int x, int y,
162                 int output, int mn, int mx)
163  : BC_TumbleTextBox(gui, output, mn, mx, x, y, 54)
164 {
165         this->gui = gui;
166         set_increment(1);
167 }
168 SketcherNum::~SketcherNum()
169 {
170 }
171
172 int SketcherPointX::handle_event()
173 {
174         if( !SketcherCoord::handle_event() ) return 0;
175         SketcherConfig &config = gui->plugin->config;
176         int ci = config.cv_selected;
177         if( ci >= 0 && ci < config.curves.size() ) {
178                 SketcherCurve *cv = config.curves[ci];
179                 SketcherPointList *point_list = gui->point_list;
180                 int pi = config.pt_selected;
181                 SketcherPoints &points = cv->points;
182                 if( pi >= 0 && pi < points.size() ) {
183                         coord v = atof(get_text());
184                         points[pi]->x = v;
185                         point_list->set_point(pi, PT_X, v);
186                         point_list->update_list(pi);
187                         gui->send_configure_change();
188                 }
189         }
190         return 1;
191 }
192 int SketcherPointY::handle_event()
193 {
194         if( !SketcherCoord::handle_event() ) return 0;
195         SketcherConfig &config = gui->plugin->config;
196         int ci = config.cv_selected;
197         if( ci >= 0 && ci < config.curves.size() ) {
198                 SketcherCurve *cv = config.curves[ci];
199                 SketcherPointList *point_list = gui->point_list;
200                 int pi = config.pt_selected;
201                 SketcherPoints &points = cv->points;
202                 if( pi >= 0 && pi < points.size() ) {
203                         coord v = atof(get_text());
204                         points[pi]->y = v;
205                         point_list->set_point(pi, PT_Y, v);
206                         point_list->update_list(pi);
207                         gui->send_configure_change();
208                 }
209         }
210         return 1;
211 }
212
213 int SketcherPointId::handle_event()
214 {
215         if( !SketcherNum::handle_event() ) return 0;
216         SketcherConfig &config = gui->plugin->config;
217         int ci = config.cv_selected;
218         if( ci >= 0 && ci < config.curves.size() ) {
219                 SketcherCurve *cv = config.curves[ci];
220                 SketcherPointList *point_list = gui->point_list;
221                 int pi = config.pt_selected;
222                 SketcherPoints &points = cv->points;
223                 if( pi >= 0 && pi < points.size() ) {
224                         int id = atoi(get_text());
225                         points[pi]->id = id;
226                         point_list->set_point(pi, PT_ID, id);
227                         point_list->update_list(pi);
228                         gui->send_configure_change();
229                 }
230         }
231         return 1;
232 }
233
234 SketcherCurveWidth::SketcherCurveWidth(SketcherWindow *gui, int x, int y, int width)
235  : SketcherNum(gui, x, y, width, 0, 255)
236 {
237         this->width = width;
238 }
239 SketcherCurveWidth::~SketcherCurveWidth()
240 {
241 }
242
243 int SketcherCurveWidth::handle_event()
244 {
245         if( !SketcherNum::handle_event() ) return 0;
246         SketcherConfig &config = gui->plugin->config;
247         int ci = config.cv_selected;
248         if( ci >= 0 && ci < config.curves.size() ) {
249                 SketcherCurve *cv = config.curves[ci];
250                 int v = atoi(get_text());
251                 cv->width = v;
252                 gui->curve_list->update(ci);
253                 gui->send_configure_change();
254         }
255         return 1;
256 }
257
258 void SketcherCurveWidth::update(int width)
259 {
260         SketcherNum::update(this->width=width);
261 }
262
263
264 SketcherWindow::SketcherWindow(Sketcher *plugin)
265  : PluginClientWindow(plugin, 380, 620, 380, 620, 0)
266 {
267         this->plugin = plugin;
268         this->title_pen = 0;  this->curve_pen = 0;
269         this->title_color = 0; this->curve_color = 0;
270         this->drag = 0;
271         this->new_curve = 0;  this->del_curve = 0;
272         this->curve_up = 0;   this->curve_dn = 0;
273         this->title_x = 0;    this->point_x = 0;
274         this->title_y = 0;    this->point_y = 0;
275         this->title_id = 0;   this->point_id = 0;
276         this->new_point = 0;  this->del_point = 0;
277         this->point_up = 0;   this->point_dn = 0;
278         this->point_list = 0; this->notes0 = 0;
279         this->notes1 = 0;     this->notes2 = 0;
280
281         position = -1;
282         track_w = track_h -1;
283         cursor_x = cursor_y = -1;
284         output_x = output_y = -1;
285         last_x = last_y = -1;
286         projector_x = projector_y = projector_z = -1;
287         state = 0;  dragging = 0;
288         new_points = 0;
289         pending_motion = 0;
290         pending_config = 0;
291 }
292
293 SketcherWindow::~SketcherWindow()
294 {
295         delete curve_width;
296         delete point_x;
297         delete point_y;
298 }
299
300 void SketcherWindow::create_objects()
301 {
302         int x = 10, y = 10, dy = 0, x1, y1;
303         int margin = plugin->get_theme()->widget_border;
304         BC_Title *title;
305         int ci = plugin->config.cv_selected;
306         if( ci < 0 || ci >= plugin->config.curves.size() )
307                 ci = plugin->new_curve();
308         SketcherCurve *cv = plugin->config.curves[ci];
309
310         reset_curves = new SketcherResetCurves(this, plugin, x1=x, y+3);
311         add_subwindow(reset_curves);    dy = bmax(dy,reset_curves->get_h());
312         x1 += reset_curves->get_w() + 2*margin;
313         const char *curve_text = _("Curve");
314         title_width = new BC_Title(x1, y, _("Width:"));
315         add_subwindow(title_width);     dy = bmax(dy,title_width->get_h());
316         x1 += title_width->get_w() + margin;
317         curve_width = new SketcherCurveWidth(this, x1, y, cv->width);
318         curve_width->create_objects();
319         y += dy + 2*margin;             dy = 0;
320
321         x1 = get_w()-x - BC_Title::calculate_w(this, curve_text, LARGEFONT);
322         y1 = y-margin - BC_Title::calculate_h(this, curve_text, LARGEFONT);
323         title = new BC_Title(x1, y1, curve_text, LARGEFONT,
324                 get_resources()->menu_highlighted_fontcolor);
325         add_subwindow(title);           dy = bmax(dy,title->get_h());
326         curve_list = new SketcherCurveList(this, plugin, x, y);
327         add_subwindow(curve_list);      dy = bmax(dy,curve_list->get_h());
328         y += dy + margin;               dy = 0;
329
330         new_curve = new SketcherNewCurve(this, plugin, x1=x, y);
331         add_subwindow(new_curve);       dy = bmax(dy,new_curve->get_h());
332         x1 += new_curve->get_w() + margin;
333         curve_up = new SketcherCurveUp(this, x1, y);
334         add_subwindow(curve_up);        dy = bmax(dy,curve_up->get_h());
335         x1 += curve_up->get_w() + 4*margin;
336         y1 = BC_Title::calculate_h(this, _("Pen:"));
337         title_pen = new BC_Title(x1+30, y+dy-y1, _("Pen:"));
338         add_subwindow(title_pen);       dy = bmax(dy,title_pen->get_h());
339         int x2 = (get_w()+x1)/2 + 20;
340         y1 = BC_Title::calculate_h(this, _("Color:"));
341         title_color = new BC_Title(x2, y+dy-y1, _("Color:"));
342         add_subwindow(title_color);     dy = bmax(dy,title_color->get_h());
343         y += dy + margin;               dy = 0;
344
345         del_curve = new SketcherDelCurve(this, plugin, x1=x, y);
346         add_subwindow(del_curve);       dy = bmax(dy,del_curve->get_h());
347         x1 += del_curve->get_w() + margin;
348         curve_dn = new SketcherCurveDn(this, x1, y);
349         add_subwindow(curve_dn);        dy = bmax(dy,curve_dn->get_h());
350         x1 += curve_dn->get_w() + 4*margin;
351         curve_pen = new SketcherCurvePen(this, x1, y, cv->pen);
352         add_subwindow(curve_pen);       dy = bmax(dy,curve_pen->get_h());
353         curve_pen->create_objects();
354         curve_color = new SketcherCurveColor(this, x2, y, COLOR_W, COLOR_H,
355                 cv->color&0xffffff, (~cv->color>>24)&0xff);
356         add_subwindow(curve_color);     dy = bmax(dy,curve_color->get_h());
357         y += dy + margin;  dy = 0;
358         curve_list->update(ci);
359
360         BC_Bar *bar;
361         bar = new BC_Bar(x, y, get_w()-2*x);
362         add_subwindow(bar);             dy = bmax(dy,bar->get_h());
363         bar = new BC_Bar(x, y+=dy, get_w()-2*x);
364         add_subwindow(bar);             dy = bmax(dy,bar->get_h());
365         y += dy + 2*margin;
366
367         int pi = plugin->config.pt_selected;
368         SketcherPoint *pt = pi >= 0 && pi < cv->points.size() ? cv->points[pi] : 0;
369         reset_points = new SketcherResetPoints(this, plugin, x1=x, y+3);
370         add_subwindow(reset_points);    dy = bmax(dy,reset_points->get_h());
371         x1 += reset_points->get_w() + 2*margin; 
372         if( plugin->config.drag ) {
373                 if( !grab(plugin->server->mwindow->cwindow->gui) ) {
374                         eprintf("drag enabled, but compositor already grabbed\n");
375                         plugin->config.drag = 0;
376                 }
377         }
378         drag = new SketcherDrag(this, x1, y);
379         add_subwindow(drag);            dy = bmax(dy,drag->get_h());
380         x1 += drag->get_w() + 2*margin;
381         int arc = pt ? pt->arc : ARC_LINE;
382         point_type = new SketcherPointType(this, x1, y, arc);
383         add_subwindow(point_type);      dy = bmax(dy,point_type->get_h());
384         point_type->create_objects();
385         y += dy + margin;  dy = 0;
386
387         const char *point_text = _("Point");
388         x1 = get_w()-x - BC_Title::calculate_w(this, point_text, LARGEFONT);
389         y1 = y-margin - BC_Title::calculate_h(this, point_text, LARGEFONT);
390         add_subwindow(title = new BC_Title(x1, y1, point_text, LARGEFONT,
391                 get_resources()->menu_highlighted_fontcolor));
392         point_list = new SketcherPointList(this, plugin, x, y);
393         add_subwindow(point_list);      dy = bmax(dy,point_list->get_h());
394         y += dy + margin;               dy = 0;
395
396         new_point = new SketcherNewPoint(this, plugin, x1=x, y);
397         add_subwindow(new_point);       dy = bmax(dy,new_point->get_h());
398         x1 += new_point->get_w() + margin;
399         point_up = new SketcherPointUp(this, x1, y);
400         add_subwindow(point_up);        dy = bmax(dy,point_up->get_h());
401         x1 += point_up->get_w() + 2*margin;
402         title_x = new BC_Title(x1, y, _("X:"));
403         add_subwindow(title_x);         dy = bmax(dy,title_x->get_h());
404         x1 += title_x->get_w() + margin;
405         point_x = new SketcherPointX(this, x1, y, !pt ? 0.f : pt->x);
406         point_x->create_objects();      dy = bmax(dy, point_x->get_h());
407         x2 = x1 + point_x->get_w() + 2*margin + 10;
408         y1 = BC_Title::calculate_h(this, _("ID:"));
409         title_id = new BC_Title(x2+16, y+dy-y1, _("ID:"));
410         add_subwindow(title_id);        dy = bmax(dy, title_id->get_h());
411         y += dy + margin;  dy = 0;
412
413         del_point = new SketcherDelPoint(this, plugin, x1=x, y);
414         add_subwindow(del_point);       dy = bmax(dy,del_point->get_h());
415         x1 += del_point->get_w() + margin;
416         point_dn = new SketcherPointDn(this, x1, y);
417         add_subwindow(point_dn);        dy = bmax(dy,point_dn->get_h());
418         x1 += point_dn->get_w() + 2*margin;
419         title_y = new BC_Title(x1, y, _("Y:"));
420         add_subwindow(title_y);         dy = bmax(dy,title_y->get_h());
421         x1 += title_y->get_w() + margin;
422         point_y = new SketcherPointY(this, x1, y, !pt ? 0.f : pt->y);
423         point_y->create_objects();      dy = bmax(dy, point_y->get_h());
424         point_id = new SketcherPointId(this, x2, y, !pt ? 0 : pt->id);
425         point_id->create_objects();     dy = bmax(dy, point_id->get_h());
426         y += dy + margin + 5;           dy = 0;
427         point_list->update(pi);
428
429         bar = new BC_Bar(x, y, get_w()-2*x);
430         add_subwindow(bar);             dy = bmax(dy,bar->get_h());
431         y += dy + 2*margin;
432
433         add_subwindow(notes0 = new BC_Title(x, y,
434                  _("\n"
435                    "Shift=\n"
436                    "None=\n"
437                    "Ctrl=\n"
438                    "Ctrl+Alt=\n"
439                    "Ctrl+Shift=")));    dy = bmax(dy, notes0->get_h());
440         add_subwindow(notes1 = new BC_Title(x+100, y,
441                  _("     LMB\n"
442                    "new line point\n"
443                    "select point\n"
444                    "drag point\n"
445                    "drag all curves\n"
446                    "new fill point"))); dy = bmax(dy, notes1->get_h());
447         add_subwindow(notes2 = new BC_Title(x+220, y,
448                  _("      RMB\n"
449                    "new arc point\n"
450                    "select curve\n"
451                    "drag curve\n"
452                    "new curve\n"
453                    "new off point"))); dy = bmax(dy, notes2->get_h());
454         y += dy + margin + 10;
455
456         add_subwindow(notes3 = new BC_Title(x, y,
457                    "Key DEL= delete point, +Shift= delete curve\n"));
458         show_window(1);
459 }
460
461 void SketcherWindow::done_event(int result)
462 {
463         curve_color->close_picker();
464         ungrab(plugin->server->mwindow->cwindow->gui);
465 }
466
467 void SketcherWindow::send_configure_change()
468 {
469         pending_config = 0;
470         plugin->send_configure_change();
471 }
472
473
474 int SketcherWindow::grab_event(XEvent *event)
475 {
476         int ret = do_grab_event(event);
477         if( !grab_event_count() ) {
478                 if( grab_cursor_motion() )
479                         pending_config = 1;
480                 if( pending_config ) {
481                         last_x = output_x;  last_y = output_y;
482                         send_configure_change();
483                 }
484         }
485         return ret;
486 }
487
488 int SketcherWindow::do_grab_event(XEvent *event)
489 {
490         switch( event->type ) {
491         case ButtonPress: break;
492         case ButtonRelease: break;
493         case MotionNotify: break;
494         case KeyPress:
495                 if( keysym_lookup(event) > 0 ) {
496                         switch( get_keysym() ) {
497                         case XK_Delete:
498                                 pending_config = 1;
499                                 return (event->xkey.state & ShiftMask) ?
500                                         del_curve->handle_event() :
501                                         del_point->handle_event() ;
502                         }
503                 } // fall thru
504         default:
505                 return 0;
506         }
507
508         MWindow *mwindow = plugin->server->mwindow;
509         CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
510         CWindowCanvas *canvas = cwindow_gui->canvas;
511         int cx, cy;  cwindow_gui->get_relative_cursor(cx, cy);
512         cx -= canvas->view_x;
513         cy -= canvas->view_y;
514
515         if( !dragging ) {
516                 if( cx < 0 || cx >= canvas->view_w ||
517                     cy < 0 || cy >= canvas->view_h )
518                         return 0;
519         }
520
521
522         switch( event->type ) {
523         case ButtonPress:
524                 if( dragging ) return 0;
525                 dragging = 1;
526                 break;
527         case ButtonRelease:
528                 dragging = 0;
529                 break;
530         case MotionNotify:
531                 if( dragging ) break;
532         default: // fall thru
533                 return 0;
534         }
535
536         cursor_x = cx, cursor_y = cy;
537         canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
538         position = plugin->get_source_position();
539         Track *track = plugin->server->plugin->track;
540         track_w = track->track_w;
541         track_h = track->track_h;
542         track->automation->get_projector(
543                 &projector_x, &projector_y, &projector_z,
544                 position, PLAY_FORWARD);
545         projector_x += mwindow->edl->session->output_w / 2;
546         projector_y += mwindow->edl->session->output_h / 2;
547         output_x = (cursor_x - projector_x) / projector_z + track_w / 2;
548         output_y = (cursor_y - projector_y) / projector_z + track_h / 2;
549         state = event->xmotion.state;
550
551         if( event->type == MotionNotify ) {
552                 memcpy(&motion_event, event, sizeof(motion_event));
553                 pending_motion = 1;
554                 return 1;
555         }
556         if( grab_cursor_motion() )
557                 pending_config = 1;
558
559         switch( event->type ) {
560         case ButtonPress:
561                 pending_config = grab_button_press(event);
562                 break;
563         case ButtonRelease:
564                 new_points = 0;
565                 break;
566         }
567
568         return 1;
569 }
570
571 int SketcherWindow::grab_button_press(XEvent *event)
572 {
573         SketcherConfig &config = plugin->config;
574         int ci = config.cv_selected;
575         if( ci < 0 || ci >= plugin->config.curves.size() )
576                 return 0;
577         SketcherCurves &curves = config.curves;
578         SketcherCurve *cv = curves[ci];
579         SketcherPoints &points = cv->points;
580         int pi = config.pt_selected;
581
582         int button_no = event->xbutton.button;
583         switch( button_no ) {
584         case LEFT_BUTTON: {
585                 if( (state & ShiftMask) ) { // create new point/string
586                         ++new_points;
587                         pi = plugin->new_point(cv,
588                                 !(state & ControlMask) ? ARC_LINE : ARC_FILL,
589                                 output_x, output_y, pi+1);
590                         point_list->update(pi);
591                         break;
592                 }
593                 SketcherPoint *pt = 0; // select point
594                 double dist = cv->nearest_point(pi, output_x,output_y);
595                 if( dist >= 0 ) {
596                         pt = points[pi];
597                         Track *track = plugin->server->plugin->track;
598                         int track_w = track->track_w, track_h = track->track_h;
599                         float px = (pt->x - track_w / 2) * projector_z + projector_x;
600                         float py = (pt->y - track_h / 2) * projector_z + projector_y;
601                         float pix = DISTANCE(px, py, cursor_x,cursor_y);
602                         if( (state & ControlMask) && pix >= HANDLE_W ) { pi = -1;  pt = 0; }
603                 }
604                 point_list->set_selected(pi);
605                 break; }
606         case RIGHT_BUTTON: {
607                 if( (state & ShiftMask) ) { // create new curve point
608                         ++new_points;
609                         pi = plugin->new_point(cv,
610                                 !(state & ControlMask) ? ARC_CURVE : ARC_OFF,
611                                 output_x, output_y, pi+1);
612                         point_list->update(pi);
613                         break;
614                 }
615                 if( (state & ControlMask) && (state & AltMask) ) { // create new curve
616                         ci = plugin->new_curve(cv->pen, cv->width, curve_color->color);
617                         curve_list->update(ci);
618                         point_list->update(-1);
619                         break;
620                 }
621                 SketcherPoint *pt = 0;
622                 double dist = config.nearest_point(ci, pi, output_x,output_y);
623                 if( dist >= 0 ) {
624                         pt = curves[ci]->points[pi];
625                         Track *track = plugin->server->plugin->track;
626                         int track_w = track->track_w, track_h = track->track_h;
627                         float px = (pt->x - track_w / 2) * projector_z + projector_x;
628                         float py = (pt->y - track_h / 2) * projector_z + projector_y;
629                         float pix = DISTANCE(px, py, cursor_x,cursor_y);
630                         if( (state & ControlMask) && pix >= HANDLE_W ) { ci = pi = -1;  pt = 0; }
631                 }
632                 if( pt ) {
633                         curve_list->update(ci);
634                         point_list->update(pi);
635                 }
636                 break; }
637         }
638         return 1;
639 }
640
641 int SketcherWindow::grab_cursor_motion()
642 {
643         if( !pending_motion )
644                 return 0;
645         pending_motion = 0;
646         SketcherConfig &config = plugin->config;
647         int ci = config.cv_selected;
648         if( ci < 0 || ci >= plugin->config.curves.size() )
649                 return 0;
650         SketcherCurves &curves = config.curves;
651         SketcherCurve *cv = curves[ci];
652         SketcherPoints &points = cv->points;
653         int pi = config.pt_selected;
654
655         if( (state & ShiftMask) ) {  // string of points
656                 if( (state & (Button1Mask|Button3Mask)) ) {
657                         SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
658                         if( pt ) {
659                                 float dist = DISTANCE(pt->x, pt->y, output_x, output_y);
660                                 if( dist < get_w()*0.1 ) return 0; // tolerance w/10
661                         }
662                         ++new_points;
663                         int arc = (state & Button1Mask) ? ARC_LINE : ARC_CURVE;
664                         pi = plugin->new_point(cv, arc, output_x, output_y, pi+1);
665                         point_list->update(pi);
666                 }
667                 return 1;
668         }
669         if( (state & Button1Mask) ) {
670                 if( (state & ControlMask) && !(state & AltMask) ) { // drag selected point
671                         SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
672                         if( pt ) {
673                                 point_list->set_point(pi, PT_X, pt->x = output_x);
674                                 point_list->set_point(pi, PT_Y, pt->y = output_y);
675                                 point_list->update_list(pi);
676                                 point_x->update(pt->x);
677                                 point_y->update(pt->y);
678                         }
679                         return 1;
680                 }
681                 if( (state & ControlMask) && (state & AltMask) ) { // drag all curves
682                         int dx = round(output_x - last_x);
683                         int dy = round(output_y - last_y);
684                         for( int i=0; i<curves.size(); ++i ) {
685                                 SketcherCurve *crv = plugin->config.curves[i];
686                                 int pts = crv->points.size();
687                                 for( int k=0; k<pts; ++k ) {
688                                         SketcherPoint *pt = crv->points[k];
689                                         pt->x += dx;  pt->y += dy;
690                                 }
691                         }
692                         SketcherPoint *pt = pi >= 0 && pi < points.size() ?
693                                 points[pi] : 0;
694                         point_x->update(pt ? pt->x : 0.f);
695                         point_y->update(pt ? pt->y : 0.f);
696                         point_id->update(pt ? pt->id : 0);
697                         point_list->update(pi);
698                         return 1;
699                 }
700                 double dist = cv->nearest_point(pi, output_x,output_y);
701                 if( dist >= 0 )
702                         point_list->set_selected(pi);
703                 return 1;
704         }
705         if( (state & Button3Mask) ) {
706                 if( (state & (ControlMask | AltMask)) ) { // drag selected curve(s)
707                         int dx = round(output_x - last_x);
708                         int dy = round(output_y - last_y);
709                         for( int i=0; i<points.size(); ++i ) {
710                                 SketcherPoint *pt = points[i];
711                                 pt->x += dx;  pt->y += dy;
712                         }
713                         SketcherPoint *pt = pi >= 0 && pi < points.size() ?
714                                 points[pi] : 0;
715                         point_x->update(pt ? pt->x : 0.f);
716                         point_y->update(pt ? pt->y : 0.f);
717                         point_id->update(pt ? pt->id : 0);
718                         point_list->update(pi);
719                         return 1;
720                 }
721                 double dist = config.nearest_point(ci, pi, output_x,output_y);
722                 if( dist >= 0 ) {
723                         curve_list->update(ci);
724                         point_list->update(pi);
725                 }
726                 return 1;
727         }
728         return 0;
729 }
730
731 int SketcherWindow::keypress_event()
732 {
733         int key = get_keypress();
734         switch( key ) {
735         case DELETE: return shift_down() ?
736                         del_curve->handle_event() :
737                         del_point->handle_event() ;
738         }
739         return 0;
740 }
741
742
743 SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
744  : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
745 {
746         this->gui = gui;
747         this->plugin = plugin;
748         col_titles[CV_ID] = _("ID");      col_widths[CV_ID] = 64;
749         col_titles[CV_RAD] = _("width");  col_widths[CV_RAD] = 64;
750         col_titles[CV_PEN] = _("pen");    col_widths[CV_PEN] = 64;
751         col_titles[CV_CLR] = _("color");  col_widths[CV_CLR] = 80;
752         col_titles[CV_ALP] = _("alpha");  col_widths[CV_ALP] = 64;
753 }
754 SketcherCurveList::~SketcherCurveList()
755 {
756         clear();
757 }
758 void SketcherCurveList::clear()
759 {
760         for( int i=CV_SZ; --i>=0; )
761                 cols[i].remove_all_objects();
762 }
763
764 int SketcherCurveList::column_resize_event()
765 {
766         for( int i=CV_SZ; --i>=0; )
767                 col_widths[i] = get_column_width(i);
768         return 1;
769 }
770
771 int SketcherCurveList::handle_event()
772 {
773         int ci = get_selection_number(0, 0);
774         set_selected(ci);
775         gui->point_list->update(0);
776         gui->send_configure_change();
777         return 1;
778 }
779
780 int SketcherCurveList::selection_changed()
781 {
782         gui->curve_color->close_picker();
783         handle_event();
784         return 1;
785 }
786
787 void SketcherCurveList::set_selected(int k)
788 {
789         int ci = -1;
790         if( k >= 0 && k < plugin->config.curves.size() ) {
791                 SketcherCurve *cv = plugin->config.curves[k];
792                 gui->curve_width->update(cv->width);
793                 gui->curve_pen->update(cv->pen);
794                 gui->curve_color->update_gui(cv->color);
795                 ci = k;
796         }
797         plugin->config.cv_selected = ci;
798         update_list(ci);
799 }
800
801 void SketcherCurveList::update_list(int k)
802 {
803         int xpos = get_xposition(), ypos = get_yposition();
804         if( k >= 0 ) update_selection(&cols[0], k);
805         BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],CV_SZ, xpos,ypos,k);
806         center_selection();
807 }
808
809 void SketcherCurveList::update(int k)
810 {
811         clear();
812         SketcherCurves &curves = plugin->config.curves;
813         int sz = curves.size();
814         for( int i=0; i<sz; ++i ) {
815                 SketcherCurve *cv = curves[i];
816                 char itxt[BCSTRLEN];  sprintf(itxt,"%d", cv->id);
817                 char ptxt[BCSTRLEN];  sprintf(ptxt,"%s", cv_pen[cv->pen]);
818                 char rtxt[BCSTRLEN];  sprintf(rtxt,"%d", cv->width);
819                 int color = cv->color;
820                 int r = (color>>16)&0xff;
821                 int g = (color>> 8)&0xff;
822                 int b = (color>> 0)&0xff;
823                 int a = (~color>>24)&0xff;
824                 char ctxt[BCSTRLEN];  sprintf(ctxt,"#%02x%02x%02x", r, g, b);
825                 char atxt[BCSTRLEN];  sprintf(atxt,"%5.3f", a/255.);
826                 add_curve(itxt, ptxt, rtxt, ctxt, atxt);
827         }
828         set_selected(k);
829 }
830
831 void SketcherCurveList::add_curve(const char *id, const char *pen,
832                 const char *width, const char *color, const char *alpha)
833 {
834         cols[CV_ID].append(new BC_ListBoxItem(id));
835         cols[CV_RAD].append(new BC_ListBoxItem(width));
836         cols[CV_PEN].append(new BC_ListBoxItem(pen));
837         cols[CV_CLR].append(new BC_ListBoxItem(color));
838         cols[CV_ALP].append(new BC_ListBoxItem(alpha));
839 }
840
841 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
842  : BC_GenericButton(x, y, 64, _("New"))
843 {
844         this->gui = gui;
845         this->plugin = plugin;
846 }
847 SketcherNewCurve::~SketcherNewCurve()
848 {
849 }
850 int SketcherNewCurve::handle_event()
851 {
852         int pen = gui->curve_pen->pen;
853         int color = gui->curve_color->color;
854         int width = gui->curve_width->width;
855         int ci = plugin->config.cv_selected;
856         if( ci >= 0 && ci < plugin->config.curves.size() ) {
857                 SketcherCurve *cv = plugin->config.curves[ci];
858                 pen = cv->pen;  width = cv->width;  color = cv->color;
859         }
860         ci = plugin->new_curve(pen, width, color);
861         gui->curve_list->update(ci);
862         gui->point_list->update(-1);
863         gui->send_configure_change();
864         return 1;
865 }
866
867 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
868  : BC_GenericButton(x, y, 64, C_("Del"))
869 {
870         this->gui = gui;
871         this->plugin = plugin;
872 }
873 SketcherDelCurve::~SketcherDelCurve()
874 {
875 }
876 int SketcherDelCurve::handle_event()
877 {
878         SketcherConfig &config = plugin->config;
879         int ci = config.cv_selected;
880         SketcherCurves &curves = config.curves;
881         if( ci >= 0 && ci < curves.size() ) {
882                 curves.remove_object_number(ci--);
883                 if( ci < 0 ) ci = 0;
884                 if( !curves.size() )
885                         ci = plugin->new_curve();
886                 gui->curve_list->update(ci);
887                 gui->point_list->update(-1);
888                 gui->send_configure_change();
889         }
890         return 1;
891 }
892
893 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
894  : BC_GenericButton(x, y, _("Up"))
895 {
896         this->gui = gui;
897 }
898 SketcherCurveUp::~SketcherCurveUp()
899 {
900 }
901
902 int SketcherCurveUp::handle_event()
903 {
904         SketcherConfig &config = gui->plugin->config;
905         int ci = config.cv_selected;
906         SketcherCurves &curves = config.curves;
907         if( ci > 0 && ci < curves.size() ) {
908                 SketcherCurve *&cv0 = curves[ci];
909                 SketcherCurve *&cv1 = curves[--ci];
910                 SketcherCurve *t = cv0;  cv0 = cv1;  cv1 = t;
911                 gui->curve_list->update(ci);
912         }
913         gui->send_configure_change();
914         return 1;
915 }
916
917 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
918  : BC_GenericButton(x, y, _("Dn"))
919 {
920         this->gui = gui;
921 }
922 SketcherCurveDn::~SketcherCurveDn()
923 {
924 }
925
926 int SketcherCurveDn::handle_event()
927 {
928         SketcherConfig &config = gui->plugin->config;
929         int ci = config.cv_selected;
930         SketcherCurves &curves = config.curves;
931         if( ci >= 0 && ci < curves.size()-1 ) {
932                 SketcherCurve *&cv0 = curves[ci];
933                 SketcherCurve *&cv1 = curves[++ci];
934                 SketcherCurve *t = cv0;  cv0 = cv1;  cv1 = t;
935                 gui->curve_list->update(ci);
936         }
937         gui->send_configure_change();
938         return 1;
939 }
940
941
942 SketcherPointTypeItem::SketcherPointTypeItem(int arc)
943  : BC_MenuItem(_(pt_type[arc]))
944 {
945         this->arc = arc;
946 }
947 int SketcherPointTypeItem::handle_event()
948 {
949         SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
950         popup->update(arc);
951         SketcherWindow *gui = popup->gui;
952         SketcherConfig &config = gui->plugin->config;
953         SketcherCurves &curves = config.curves;
954         int ci = config.cv_selected;
955         if( ci < 0 || ci >= curves.size() )
956                 return 1;
957         SketcherCurve *cv = curves[ci];
958         SketcherPoints &points = cv->points;
959         int pi = config.pt_selected;
960
961         ArrayList<int> selected;
962         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
963                 selected.append(v);
964
965         for( int i=selected.size(); --i>=0; ) {
966                 int k = selected[i];
967                 if( k < 0 || k >= points.size() ) continue;
968                 SketcherPoint *pt = cv->points[k];
969                 pt->arc = arc;
970                 gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
971         }
972
973         gui->point_list->update_list(pi);
974         gui->send_configure_change();
975         return 1;
976 }
977
978 SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc)
979  : BC_PopupMenu(x,y,100,_(pt_type[arc]))
980 {
981         this->gui = gui;
982         this->type = arc;
983 }
984 void SketcherPointType::create_objects()
985 {
986         for( int arc=0; arc<PT_SZ; ++arc )
987                 add_item(new SketcherPointTypeItem(arc));
988 }
989 void SketcherPointType::update(int arc)
990 {
991         set_text(_(pt_type[this->type=arc]));
992 }
993
994
995 SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
996  : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
997 {
998         this->gui = gui;
999         this->plugin = plugin;
1000         col_titles[PT_ID] = _("ID");    col_widths[PT_ID] = 50;
1001         col_titles[PT_TY] = _("Type");  col_widths[PT_TY] = 80;
1002         col_titles[PT_X] = _("X");      col_widths[PT_X] = 90;
1003         col_titles[PT_Y] = _("Y");      col_widths[PT_Y] = 90;
1004         set_selection_mode(LISTBOX_MULTIPLE);
1005 }
1006 SketcherPointList::~SketcherPointList()
1007 {
1008         clear();
1009 }
1010 void SketcherPointList::clear()
1011 {
1012         for( int i=PT_SZ; --i>=0; )
1013                 cols[i].remove_all_objects();
1014 }
1015
1016 int SketcherPointList::column_resize_event()
1017 {
1018         for( int i=PT_SZ; --i>=0; )
1019                 col_widths[i] = get_column_width(i);
1020         return 1;
1021 }
1022
1023 int SketcherPointList::handle_event()
1024 {
1025         int pi = get_selection_number(0, 0);
1026         if( get_selection_number(0, 1) >= 0 ) pi = -1;
1027         set_selected(pi);
1028         gui->send_configure_change();
1029         return 1;
1030 }
1031
1032 int SketcherPointList::selection_changed()
1033 {
1034         handle_event();
1035         return 1;
1036 }
1037
1038 void SketcherPointList::add_point(const char *id, const char *ty, const char *xp, const char *yp)
1039 {
1040         cols[PT_ID].append(new BC_ListBoxItem(id));
1041         cols[PT_TY].append(new BC_ListBoxItem(ty));
1042         cols[PT_X].append(new BC_ListBoxItem(xp));
1043         cols[PT_Y].append(new BC_ListBoxItem(yp));
1044 }
1045
1046 void SketcherPointList::set_point(int i, int c, int v)
1047 {
1048         char stxt[BCSTRLEN];
1049         sprintf(stxt,"%d",v);
1050         set_point(i,c,stxt);
1051 }
1052 void SketcherPointList::set_point(int i, int c, coord v)
1053 {
1054         char stxt[BCSTRLEN];
1055         sprintf(stxt,"%0.1f",v);
1056         set_point(i,c,stxt);
1057 }
1058 void SketcherPointList::set_point(int i, int c, const char *cp)
1059 {
1060         cols[c].get(i)->set_text(cp);
1061 }
1062
1063 void SketcherPointList::set_selected(int k)
1064 {
1065         SketcherPoint *pt = 0;
1066         int ci = plugin->config.cv_selected, pi = -1;
1067         if( ci >= 0 && ci < plugin->config.curves.size() ) {
1068                 SketcherCurve *cv = plugin->config.curves[ci];
1069                 pt = k >= 0 && k < cv->points.size() ? cv->points[pi=k] : 0;
1070         }
1071         gui->point_type->update(pt ? pt->arc : ARC_OFF);
1072         gui->point_x->update(pt ? pt->x : 0.f);
1073         gui->point_y->update(pt ? pt->y : 0.f);
1074         gui->point_id->update(pt ? pt->id : 0);
1075         plugin->config.pt_selected = pi;
1076         update_list(pi);
1077 }
1078 void SketcherPointList::update_list(int k)
1079 {
1080         int xpos = get_xposition(), ypos = get_yposition();
1081         if( k >= 0 ) update_selection(&cols[0], k);
1082         BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],PT_SZ, xpos,ypos,k);
1083         center_selection();
1084 }
1085 void SketcherPointList::update(int k)
1086 {
1087         clear();
1088         int ci = plugin->config.cv_selected, sz = 0;
1089         if( ci >= 0 && ci < plugin->config.curves.size() ) {
1090                 SketcherCurve *cv = plugin->config.curves[ci];
1091                 SketcherPoints &points = cv->points;
1092                 sz = points.size();
1093                 for( int i=0; i<sz; ++i ) {
1094                         SketcherPoint *pt = points[i];
1095                         char itxt[BCSTRLEN];  sprintf(itxt,"%d", pt->id);
1096                         char ttxt[BCSTRLEN];  sprintf(ttxt,"%s", _(pt_type[pt->arc]));
1097                         char xtxt[BCSTRLEN];  sprintf(xtxt,"%0.1f", pt->x);
1098                         char ytxt[BCSTRLEN];  sprintf(ytxt,"%0.1f", pt->y);
1099                         add_point(itxt, ttxt, xtxt, ytxt);
1100                 }
1101         }
1102         set_selected(k);
1103 }
1104
1105 void SketcherWindow::update_gui()
1106 {
1107         SketcherConfig &config = plugin->config;
1108         int ci = config.cv_selected;
1109         int pi = config.pt_selected;
1110         curve_list->update(ci);
1111         point_list->update(pi);
1112         SketcherCurve *cv = ci >= 0 ? config.curves[ci] : 0;
1113         curve_width->update(cv ? cv->width : 1);
1114         curve_pen->update(cv ? cv->pen : PEN_SQUARE);
1115         curve_color->set_color(cv ? cv->color : CV_COLOR);
1116         SketcherPoint *pt = pi >= 0 ? cv->points[pi] : 0;
1117         point_x->update(pt ? pt->x : 0);
1118         point_y->update(pt ? pt->y : 0);
1119         point_id->update(pt ? pt->id : 0);
1120         drag->update(plugin->config.drag);
1121 }
1122
1123
1124 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
1125  : BC_GenericButton(x, y, _("Up"))
1126 {
1127         this->gui = gui;
1128 }
1129 SketcherPointUp::~SketcherPointUp()
1130 {
1131 }
1132
1133 int SketcherPointUp::handle_event()
1134 {
1135         SketcherConfig &config = gui->plugin->config;
1136         int ci = config.cv_selected;
1137         if( ci < 0 || ci >= config.curves.size() )
1138                 return 1;
1139         SketcherCurve *cv = config.curves[ci];
1140         SketcherPoints &points = cv->points;
1141         if( points.size() < 2 )
1142                 return 1;
1143         int pi = config.pt_selected;
1144
1145         ArrayList<int> selected;
1146         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1147                 selected.append(v);
1148
1149         for( int i=0; i<selected.size(); ++i ) {
1150                 int k = selected[i];
1151                 if( k <= 0 ) continue;
1152                 if( k == pi ) --pi;
1153                 SketcherPoint *&pt0 = points[k];
1154                 SketcherPoint *&pt1 = points[--k];
1155                 SketcherPoint *t = pt0;  pt0 = pt1;  pt1 = t;
1156         }
1157         gui->point_list->update(pi);
1158         gui->send_configure_change();
1159         return 1;
1160 }
1161
1162 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
1163  : BC_GenericButton(x, y, _("Dn"))
1164 {
1165         this->gui = gui;
1166 }
1167 SketcherPointDn::~SketcherPointDn()
1168 {
1169 }
1170
1171 int SketcherPointDn::handle_event()
1172 {
1173         SketcherConfig &config = gui->plugin->config;
1174         int ci = config.cv_selected;
1175         if( ci < 0 || ci >= config.curves.size() )
1176                 return 1;
1177         SketcherCurve *cv = config.curves[ci];
1178         SketcherPoints &points = cv->points;
1179         int sz1 = points.size()-1;
1180         if( sz1 < 1 )
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=selected.size(); --i>=0; ) {
1189                 int k = selected[i];
1190                 if( k >= sz1 ) 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 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
1202  : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
1203 {
1204         this->gui = gui;
1205 }
1206 int SketcherDrag::handle_event()
1207 {
1208         CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
1209         int value = get_value();
1210         if( value ) {
1211                 if( !gui->grab(cwindow_gui) ) {
1212                         update(value = 0);
1213                         flicker(10,50);
1214                 }
1215         }
1216         else
1217                 gui->ungrab(cwindow_gui);
1218         gui->plugin->config.drag = value;
1219         gui->send_configure_change();
1220         return 1;
1221 }
1222
1223 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1224  : BC_GenericButton(x, y, 64, _("New"))
1225 {
1226         this->gui = gui;
1227         this->plugin = plugin;
1228 }
1229 SketcherNewPoint::~SketcherNewPoint()
1230 {
1231 }
1232 int SketcherNewPoint::handle_event()
1233 {
1234         int pi = plugin->config.pt_selected;
1235         int arc = gui->point_type->type;
1236         int k = plugin->new_point(pi+1, arc);
1237         gui->point_list->update(k);
1238         gui->send_configure_change();
1239         return 1;
1240 }
1241
1242 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1243  : BC_GenericButton(x, y, 64, C_("Del"))
1244 {
1245         this->gui = gui;
1246         this->plugin = plugin;
1247 }
1248 SketcherDelPoint::~SketcherDelPoint()
1249 {
1250 }
1251 int SketcherDelPoint::handle_event()
1252 {
1253         SketcherConfig &config = gui->plugin->config;
1254         SketcherCurves &curves = config.curves;
1255         int ci = config.cv_selected;
1256         if( ci < 0 || ci >= curves.size() )
1257                 return 1;
1258         SketcherCurve *cv = curves[ci];
1259         SketcherPoints &points = cv->points;
1260         int pi = config.pt_selected;
1261
1262         ArrayList<int> selected;
1263         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1264                 selected.append(v);
1265
1266         for( int i=selected.size(); --i>=0; ) {
1267                 int k = selected[i];
1268                 if( k < 0 || k >= points.size() ) continue;
1269                 points.remove_object_number(k);
1270                 if( k == pi && --pi < 0 && points.size() > 0 ) pi = 0;
1271         }
1272         gui->point_list->update(pi);
1273         gui->send_configure_change();
1274         return 1;
1275 }
1276
1277 SketcherResetCurves::SketcherResetCurves(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1278  : BC_GenericButton(x, y, _("Reset"))
1279 {
1280         this->gui = gui;
1281         this->plugin = plugin;
1282 }
1283 SketcherResetCurves::~SketcherResetCurves()
1284 {
1285 }
1286 int SketcherResetCurves::handle_event()
1287 {
1288         SketcherConfig &config = plugin->config;
1289         config.curves.remove_all_objects();
1290         int ci = plugin->new_curve();
1291         gui->curve_list->update(ci);
1292         gui->point_list->update(-1);
1293         gui->send_configure_change();
1294         return 1;
1295 }
1296
1297 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1298  : BC_GenericButton(x, y, _("Reset"))
1299 {
1300         this->gui = gui;
1301         this->plugin = plugin;
1302 }
1303 SketcherResetPoints::~SketcherResetPoints()
1304 {
1305 }
1306 int SketcherResetPoints::handle_event()
1307 {
1308         SketcherConfig &config = gui->plugin->config;
1309         int ci = config.cv_selected;
1310         if( ci >= 0 && ci < config.curves.size() ) {
1311                 SketcherCurve *cv = config.curves[ci];
1312                 cv->points.remove_all_objects();
1313                 gui->point_list->update(-1);
1314                 gui->send_configure_change();
1315         }
1316         return 1;
1317 }
1318