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