df4d6d5903e53a1c6911fd5dd5dd0dc9a3d3ab9e
[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         ungrab(plugin->server->mwindow->cwindow->gui);
464 }
465
466 void SketcherWindow::send_configure_change()
467 {
468         pending_config = 0;
469         plugin->send_configure_change();
470 }
471
472
473 int SketcherWindow::grab_event(XEvent *event)
474 {
475         int ret = do_grab_event(event);
476         if( !grab_event_count() ) {
477                 if( grab_cursor_motion() )
478                         pending_config = 1;
479                 if( pending_config ) {
480                         last_x = output_x;  last_y = output_y;
481                         send_configure_change();
482                 }
483         }
484         return ret;
485 }
486
487 int SketcherWindow::do_grab_event(XEvent *event)
488 {
489         switch( event->type ) {
490         case ButtonPress: break;
491         case ButtonRelease: break;
492         case MotionNotify: break;
493         case KeyPress:
494                 if( keysym_lookup(event) > 0 ) {
495                         switch( get_keysym() ) {
496                         case XK_Delete:
497                                 pending_config = 1;
498                                 return (event->xkey.state & ShiftMask) ?
499                                         del_curve->handle_event() :
500                                         del_point->handle_event() ;
501                         }
502                 } // fall thru
503         default:
504                 return 0;
505         }
506
507         MWindow *mwindow = plugin->server->mwindow;
508         CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
509         CWindowCanvas *canvas = cwindow_gui->canvas;
510         int cx, cy;  cwindow_gui->get_relative_cursor(cx, cy);
511         cx -= canvas->view_x;
512         cy -= canvas->view_y;
513
514         if( !dragging ) {
515                 if( cx < 0 || cx >= canvas->view_w ||
516                     cy < 0 || cy >= canvas->view_h )
517                         return 0;
518         }
519
520
521         switch( event->type ) {
522         case ButtonPress:
523                 if( dragging ) return 0;
524                 dragging = 1;
525                 break;
526         case ButtonRelease:
527                 dragging = 0;
528                 break;
529         case MotionNotify:
530                 if( dragging ) break;
531         default: // fall thru
532                 return 0;
533         }
534
535         cursor_x = cx, cursor_y = cy;
536         canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
537         position = plugin->get_source_position();
538         Track *track = plugin->server->plugin->track;
539         track_w = track->track_w;
540         track_h = track->track_h;
541         track->automation->get_projector(
542                 &projector_x, &projector_y, &projector_z,
543                 position, PLAY_FORWARD);
544         projector_x += mwindow->edl->session->output_w / 2;
545         projector_y += mwindow->edl->session->output_h / 2;
546         output_x = (cursor_x - projector_x) / projector_z + track_w / 2;
547         output_y = (cursor_y - projector_y) / projector_z + track_h / 2;
548         state = event->xmotion.state;
549
550         if( event->type == MotionNotify ) {
551                 memcpy(&motion_event, event, sizeof(motion_event));
552                 pending_motion = 1;
553                 return 1;
554         }
555         if( grab_cursor_motion() )
556                 pending_config = 1;
557
558         switch( event->type ) {
559         case ButtonPress:
560                 pending_config = grab_button_press(event);
561                 break;
562         case ButtonRelease:
563                 new_points = 0;
564                 break;
565         }
566
567         return 1;
568 }
569
570 int SketcherWindow::grab_button_press(XEvent *event)
571 {
572         SketcherConfig &config = plugin->config;
573         int ci = config.cv_selected;
574         if( ci < 0 || ci >= plugin->config.curves.size() )
575                 return 0;
576         SketcherCurves &curves = config.curves;
577         SketcherCurve *cv = curves[ci];
578         SketcherPoints &points = cv->points;
579         int pi = config.pt_selected;
580
581         int button_no = event->xbutton.button;
582         switch( button_no ) {
583         case LEFT_BUTTON: {
584                 if( (state & ShiftMask) ) { // create new point/string
585                         ++new_points;
586                         pi = plugin->new_point(cv,
587                                 !(state & ControlMask) ? ARC_LINE : ARC_FILL,
588                                 output_x, output_y, pi+1);
589                         point_list->update(pi);
590                         break;
591                 }
592                 SketcherPoint *pt = 0; // select point
593                 double dist = cv->nearest_point(pi, output_x,output_y);
594                 if( dist >= 0 ) {
595                         pt = points[pi];
596                         Track *track = plugin->server->plugin->track;
597                         int track_w = track->track_w, track_h = track->track_h;
598                         float px = (pt->x - track_w / 2) * projector_z + projector_x;
599                         float py = (pt->y - track_h / 2) * projector_z + projector_y;
600                         float pix = DISTANCE(px, py, cursor_x,cursor_y);
601                         if( (state & ControlMask) && pix >= HANDLE_W ) { pi = -1;  pt = 0; }
602                 }
603                 point_list->set_selected(pi);
604                 break; }
605         case RIGHT_BUTTON: {
606                 if( (state & ShiftMask) ) { // create new curve point
607                         ++new_points;
608                         pi = plugin->new_point(cv,
609                                 !(state & ControlMask) ? ARC_CURVE : ARC_OFF,
610                                 output_x, output_y, pi+1);
611                         point_list->update(pi);
612                         break;
613                 }
614                 if( (state & ControlMask) && (state & AltMask) ) { // create new curve
615                         ci = plugin->new_curve(cv->pen, cv->width, curve_color->color);
616                         curve_list->update(ci);
617                         point_list->update(-1);
618                         break;
619                 }
620                 SketcherPoint *pt = 0;
621                 double dist = config.nearest_point(ci, pi, output_x,output_y);
622                 if( dist >= 0 ) {
623                         pt = curves[ci]->points[pi];
624                         Track *track = plugin->server->plugin->track;
625                         int track_w = track->track_w, track_h = track->track_h;
626                         float px = (pt->x - track_w / 2) * projector_z + projector_x;
627                         float py = (pt->y - track_h / 2) * projector_z + projector_y;
628                         float pix = DISTANCE(px, py, cursor_x,cursor_y);
629                         if( (state & ControlMask) && pix >= HANDLE_W ) { ci = pi = -1;  pt = 0; }
630                 }
631                 if( pt ) {
632                         curve_list->update(ci);
633                         point_list->update(pi);
634                 }
635                 break; }
636         }
637         return 1;
638 }
639
640 int SketcherWindow::grab_cursor_motion()
641 {
642         if( !pending_motion )
643                 return 0;
644         pending_motion = 0;
645         SketcherConfig &config = plugin->config;
646         int ci = config.cv_selected;
647         if( ci < 0 || ci >= plugin->config.curves.size() )
648                 return 0;
649         SketcherCurves &curves = config.curves;
650         SketcherCurve *cv = curves[ci];
651         SketcherPoints &points = cv->points;
652         int pi = config.pt_selected;
653
654         if( (state & ShiftMask) ) {  // string of points
655                 if( (state & (Button1Mask|Button3Mask)) ) {
656                         SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
657                         if( pt ) {
658                                 float dist = DISTANCE(pt->x, pt->y, output_x, output_y);
659                                 if( dist < get_w()*0.1 ) return 0; // tolerance w/10
660                         }
661                         ++new_points;
662                         int arc = (state & Button1Mask) ? ARC_LINE : ARC_CURVE;
663                         pi = plugin->new_point(cv, arc, output_x, output_y, pi+1);
664                         point_list->update(pi);
665                 }
666                 return 1;
667         }
668         if( (state & Button1Mask) ) {
669                 if( (state & ControlMask) && !(state & AltMask) ) { // drag selected point
670                         SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
671                         if( pt ) {
672                                 point_list->set_point(pi, PT_X, pt->x = output_x);
673                                 point_list->set_point(pi, PT_Y, pt->y = output_y);
674                                 point_list->update_list(pi);
675                                 point_x->update(pt->x);
676                                 point_y->update(pt->y);
677                         }
678                         return 1;
679                 }
680                 if( (state & ControlMask) && (state & AltMask) ) { // drag all curves
681                         int dx = round(output_x - last_x);
682                         int dy = round(output_y - last_y);
683                         for( int i=0; i<curves.size(); ++i ) {
684                                 SketcherCurve *crv = plugin->config.curves[i];
685                                 int pts = crv->points.size();
686                                 for( int k=0; k<pts; ++k ) {
687                                         SketcherPoint *pt = crv->points[k];
688                                         pt->x += dx;  pt->y += dy;
689                                 }
690                         }
691                         SketcherPoint *pt = pi >= 0 && pi < points.size() ?
692                                 points[pi] : 0;
693                         point_x->update(pt ? pt->x : 0.f);
694                         point_y->update(pt ? pt->y : 0.f);
695                         point_id->update(pt ? pt->id : 0);
696                         point_list->update(pi);
697                         return 1;
698                 }
699                 double dist = cv->nearest_point(pi, output_x,output_y);
700                 if( dist >= 0 )
701                         point_list->set_selected(pi);
702                 return 1;
703         }
704         if( (state & Button3Mask) ) {
705                 if( (state & (ControlMask | AltMask)) ) { // drag selected curve(s)
706                         int dx = round(output_x - last_x);
707                         int dy = round(output_y - last_y);
708                         for( int i=0; i<points.size(); ++i ) {
709                                 SketcherPoint *pt = points[i];
710                                 pt->x += dx;  pt->y += dy;
711                         }
712                         SketcherPoint *pt = pi >= 0 && pi < points.size() ?
713                                 points[pi] : 0;
714                         point_x->update(pt ? pt->x : 0.f);
715                         point_y->update(pt ? pt->y : 0.f);
716                         point_id->update(pt ? pt->id : 0);
717                         point_list->update(pi);
718                         return 1;
719                 }
720                 double dist = config.nearest_point(ci, pi, output_x,output_y);
721                 if( dist >= 0 ) {
722                         curve_list->update(ci);
723                         point_list->update(pi);
724                 }
725                 return 1;
726         }
727         return 0;
728 }
729
730 int SketcherWindow::keypress_event()
731 {
732         int key = get_keypress();
733         switch( key ) {
734         case DELETE: return shift_down() ?
735                         del_curve->handle_event() :
736                         del_point->handle_event() ;
737         }
738         return 0;
739 }
740
741
742 SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
743  : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
744 {
745         this->gui = gui;
746         this->plugin = plugin;
747         col_titles[CV_ID] = _("ID");      col_widths[CV_ID] = 64;
748         col_titles[CV_RAD] = _("width");  col_widths[CV_RAD] = 64;
749         col_titles[CV_PEN] = _("pen");    col_widths[CV_PEN] = 64;
750         col_titles[CV_CLR] = _("color");  col_widths[CV_CLR] = 80;
751         col_titles[CV_ALP] = _("alpha");  col_widths[CV_ALP] = 64;
752 }
753 SketcherCurveList::~SketcherCurveList()
754 {
755         clear();
756 }
757 void SketcherCurveList::clear()
758 {
759         for( int i=CV_SZ; --i>=0; )
760                 cols[i].remove_all_objects();
761 }
762
763 int SketcherCurveList::column_resize_event()
764 {
765         for( int i=CV_SZ; --i>=0; )
766                 col_widths[i] = get_column_width(i);
767         return 1;
768 }
769
770 int SketcherCurveList::handle_event()
771 {
772         int ci = get_selection_number(0, 0);
773         set_selected(ci);
774         gui->point_list->update(0);
775         gui->send_configure_change();
776         return 1;
777 }
778
779 int SketcherCurveList::selection_changed()
780 {
781         handle_event();
782         return 1;
783 }
784
785 void SketcherCurveList::set_selected(int k)
786 {
787         int ci = -1;
788         if( k >= 0 && k < plugin->config.curves.size() ) {
789                 SketcherCurve *cv = plugin->config.curves[k];
790                 gui->curve_width->update(cv->width);
791                 gui->curve_pen->update(cv->pen);
792                 gui->curve_color->update_gui(cv->color);
793                 ci = k;
794         }
795         plugin->config.cv_selected = ci;
796         update_list(ci);
797 }
798
799 void SketcherCurveList::update_list(int k)
800 {
801         int xpos = get_xposition(), ypos = get_yposition();
802         if( k >= 0 ) update_selection(&cols[0], k);
803         BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],CV_SZ, xpos,ypos,k);
804         center_selection();
805 }
806
807 void SketcherCurveList::update(int k)
808 {
809         clear();
810         SketcherCurves &curves = plugin->config.curves;
811         int sz = curves.size();
812         for( int i=0; i<sz; ++i ) {
813                 SketcherCurve *cv = curves[i];
814                 char itxt[BCSTRLEN];  sprintf(itxt,"%d", cv->id);
815                 char ptxt[BCSTRLEN];  sprintf(ptxt,"%s", cv_pen[cv->pen]);
816                 char rtxt[BCSTRLEN];  sprintf(rtxt,"%d", cv->width);
817                 int color = cv->color;
818                 int r = (color>>16)&0xff;
819                 int g = (color>> 8)&0xff;
820                 int b = (color>> 0)&0xff;
821                 int a = (~color>>24)&0xff;
822                 char ctxt[BCSTRLEN];  sprintf(ctxt,"#%02x%02x%02x", r, g, b);
823                 char atxt[BCSTRLEN];  sprintf(atxt,"%5.3f", a/255.);
824                 add_curve(itxt, ptxt, rtxt, ctxt, atxt);
825         }
826         set_selected(k);
827 }
828
829 void SketcherCurveList::add_curve(const char *id, const char *pen,
830                 const char *width, const char *color, const char *alpha)
831 {
832         cols[CV_ID].append(new BC_ListBoxItem(id));
833         cols[CV_RAD].append(new BC_ListBoxItem(width));
834         cols[CV_PEN].append(new BC_ListBoxItem(pen));
835         cols[CV_CLR].append(new BC_ListBoxItem(color));
836         cols[CV_ALP].append(new BC_ListBoxItem(alpha));
837 }
838
839 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
840  : BC_GenericButton(x, y, 64, _("New"))
841 {
842         this->gui = gui;
843         this->plugin = plugin;
844 }
845 SketcherNewCurve::~SketcherNewCurve()
846 {
847 }
848 int SketcherNewCurve::handle_event()
849 {
850         int pen = gui->curve_pen->pen;
851         int color = gui->curve_color->color;
852         int width = gui->curve_width->width;
853         int ci = plugin->config.cv_selected;
854         if( ci >= 0 && ci < plugin->config.curves.size() ) {
855                 SketcherCurve *cv = plugin->config.curves[ci];
856                 pen = cv->pen;  width = cv->width;  color = cv->color;
857         }
858         ci = plugin->new_curve(pen, width, color);
859         gui->curve_list->update(ci);
860         gui->point_list->update(-1);
861         gui->send_configure_change();
862         return 1;
863 }
864
865 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
866  : BC_GenericButton(x, y, 64, C_("Del"))
867 {
868         this->gui = gui;
869         this->plugin = plugin;
870 }
871 SketcherDelCurve::~SketcherDelCurve()
872 {
873 }
874 int SketcherDelCurve::handle_event()
875 {
876         SketcherConfig &config = plugin->config;
877         int ci = config.cv_selected;
878         SketcherCurves &curves = config.curves;
879         if( ci >= 0 && ci < curves.size() ) {
880                 curves.remove_object_number(ci--);
881                 if( ci < 0 ) ci = 0;
882                 if( !curves.size() )
883                         ci = plugin->new_curve();
884                 gui->curve_list->update(ci);
885                 gui->point_list->update(-1);
886                 gui->send_configure_change();
887         }
888         return 1;
889 }
890
891 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
892  : BC_GenericButton(x, y, _("Up"))
893 {
894         this->gui = gui;
895 }
896 SketcherCurveUp::~SketcherCurveUp()
897 {
898 }
899
900 int SketcherCurveUp::handle_event()
901 {
902         SketcherConfig &config = gui->plugin->config;
903         int ci = config.cv_selected;
904         SketcherCurves &curves = config.curves;
905         if( ci > 0 && ci < curves.size() ) {
906                 SketcherCurve *&cv0 = curves[ci];
907                 SketcherCurve *&cv1 = curves[--ci];
908                 SketcherCurve *t = cv0;  cv0 = cv1;  cv1 = t;
909                 gui->curve_list->update(ci);
910         }
911         gui->send_configure_change();
912         return 1;
913 }
914
915 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
916  : BC_GenericButton(x, y, _("Dn"))
917 {
918         this->gui = gui;
919 }
920 SketcherCurveDn::~SketcherCurveDn()
921 {
922 }
923
924 int SketcherCurveDn::handle_event()
925 {
926         SketcherConfig &config = gui->plugin->config;
927         int ci = config.cv_selected;
928         SketcherCurves &curves = config.curves;
929         if( ci >= 0 && ci < curves.size()-1 ) {
930                 SketcherCurve *&cv0 = curves[ci];
931                 SketcherCurve *&cv1 = curves[++ci];
932                 SketcherCurve *t = cv0;  cv0 = cv1;  cv1 = t;
933                 gui->curve_list->update(ci);
934         }
935         gui->send_configure_change();
936         return 1;
937 }
938
939
940 SketcherPointTypeItem::SketcherPointTypeItem(int arc)
941  : BC_MenuItem(_(pt_type[arc]))
942 {
943         this->arc = arc;
944 }
945 int SketcherPointTypeItem::handle_event()
946 {
947         SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
948         popup->update(arc);
949         SketcherWindow *gui = popup->gui;
950         SketcherConfig &config = gui->plugin->config;
951         SketcherCurves &curves = config.curves;
952         int ci = config.cv_selected;
953         if( ci < 0 || ci >= curves.size() )
954                 return 1;
955         SketcherCurve *cv = curves[ci];
956         SketcherPoints &points = cv->points;
957         int pi = config.pt_selected;
958
959         ArrayList<int> selected;
960         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
961                 selected.append(v);
962
963         for( int i=selected.size(); --i>=0; ) {
964                 int k = selected[i];
965                 if( k < 0 || k >= points.size() ) continue;
966                 SketcherPoint *pt = cv->points[k];
967                 pt->arc = arc;
968                 gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
969         }
970
971         gui->point_list->update_list(pi);
972         gui->send_configure_change();
973         return 1;
974 }
975
976 SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc)
977  : BC_PopupMenu(x,y,100,_(pt_type[arc]))
978 {
979         this->gui = gui;
980         this->type = arc;
981 }
982 void SketcherPointType::create_objects()
983 {
984         for( int arc=0; arc<PT_SZ; ++arc )
985                 add_item(new SketcherPointTypeItem(arc));
986 }
987 void SketcherPointType::update(int arc)
988 {
989         set_text(_(pt_type[this->type=arc]));
990 }
991
992
993 SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
994  : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
995 {
996         this->gui = gui;
997         this->plugin = plugin;
998         col_titles[PT_ID] = _("ID");    col_widths[PT_ID] = 50;
999         col_titles[PT_TY] = _("Type");  col_widths[PT_TY] = 80;
1000         col_titles[PT_X] = _("X");      col_widths[PT_X] = 90;
1001         col_titles[PT_Y] = _("Y");      col_widths[PT_Y] = 90;
1002         set_selection_mode(LISTBOX_MULTIPLE);
1003 }
1004 SketcherPointList::~SketcherPointList()
1005 {
1006         clear();
1007 }
1008 void SketcherPointList::clear()
1009 {
1010         for( int i=PT_SZ; --i>=0; )
1011                 cols[i].remove_all_objects();
1012 }
1013
1014 int SketcherPointList::column_resize_event()
1015 {
1016         for( int i=PT_SZ; --i>=0; )
1017                 col_widths[i] = get_column_width(i);
1018         return 1;
1019 }
1020
1021 int SketcherPointList::handle_event()
1022 {
1023         int pi = get_selection_number(0, 0);
1024         if( get_selection_number(0, 1) >= 0 ) pi = -1;
1025         set_selected(pi);
1026         gui->send_configure_change();
1027         return 1;
1028 }
1029
1030 int SketcherPointList::selection_changed()
1031 {
1032         handle_event();
1033         return 1;
1034 }
1035
1036 void SketcherPointList::add_point(const char *id, const char *ty, const char *xp, const char *yp)
1037 {
1038         cols[PT_ID].append(new BC_ListBoxItem(id));
1039         cols[PT_TY].append(new BC_ListBoxItem(ty));
1040         cols[PT_X].append(new BC_ListBoxItem(xp));
1041         cols[PT_Y].append(new BC_ListBoxItem(yp));
1042 }
1043
1044 void SketcherPointList::set_point(int i, int c, int v)
1045 {
1046         char stxt[BCSTRLEN];
1047         sprintf(stxt,"%d",v);
1048         set_point(i,c,stxt);
1049 }
1050 void SketcherPointList::set_point(int i, int c, coord v)
1051 {
1052         char stxt[BCSTRLEN];
1053         sprintf(stxt,"%0.1f",v);
1054         set_point(i,c,stxt);
1055 }
1056 void SketcherPointList::set_point(int i, int c, const char *cp)
1057 {
1058         cols[c].get(i)->set_text(cp);
1059 }
1060
1061 void SketcherPointList::set_selected(int k)
1062 {
1063         SketcherPoint *pt = 0;
1064         int ci = plugin->config.cv_selected, pi = -1;
1065         if( ci >= 0 && ci < plugin->config.curves.size() ) {
1066                 SketcherCurve *cv = plugin->config.curves[ci];
1067                 pt = k >= 0 && k < cv->points.size() ? cv->points[pi=k] : 0;
1068         }
1069         gui->point_type->update(pt ? pt->arc : ARC_OFF);
1070         gui->point_x->update(pt ? pt->x : 0.f);
1071         gui->point_y->update(pt ? pt->y : 0.f);
1072         gui->point_id->update(pt ? pt->id : 0);
1073         plugin->config.pt_selected = pi;
1074         update_list(pi);
1075 }
1076 void SketcherPointList::update_list(int k)
1077 {
1078         int xpos = get_xposition(), ypos = get_yposition();
1079         if( k >= 0 ) update_selection(&cols[0], k);
1080         BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],PT_SZ, xpos,ypos,k);
1081         center_selection();
1082 }
1083 void SketcherPointList::update(int k)
1084 {
1085         clear();
1086         int ci = plugin->config.cv_selected, sz = 0;
1087         if( ci >= 0 && ci < plugin->config.curves.size() ) {
1088                 SketcherCurve *cv = plugin->config.curves[ci];
1089                 SketcherPoints &points = cv->points;
1090                 sz = points.size();
1091                 for( int i=0; i<sz; ++i ) {
1092                         SketcherPoint *pt = points[i];
1093                         char itxt[BCSTRLEN];  sprintf(itxt,"%d", pt->id);
1094                         char ttxt[BCSTRLEN];  sprintf(ttxt,"%s", _(pt_type[pt->arc]));
1095                         char xtxt[BCSTRLEN];  sprintf(xtxt,"%0.1f", pt->x);
1096                         char ytxt[BCSTRLEN];  sprintf(ytxt,"%0.1f", pt->y);
1097                         add_point(itxt, ttxt, xtxt, ytxt);
1098                 }
1099         }
1100         set_selected(k);
1101 }
1102
1103 void SketcherWindow::update_gui()
1104 {
1105         SketcherConfig &config = plugin->config;
1106         int ci = config.cv_selected;
1107         int pi = config.pt_selected;
1108         curve_list->update(ci);
1109         point_list->update(pi);
1110         SketcherCurve *cv = ci >= 0 ? config.curves[ci] : 0;
1111         curve_width->update(cv ? cv->width : 1);
1112         curve_pen->update(cv ? cv->pen : PEN_SQUARE);
1113         curve_color->set_color(cv ? cv->color : CV_COLOR);
1114         SketcherPoint *pt = pi >= 0 ? cv->points[pi] : 0;
1115         point_x->update(pt ? pt->x : 0);
1116         point_y->update(pt ? pt->y : 0);
1117         point_id->update(pt ? pt->id : 0);
1118         drag->update(plugin->config.drag);
1119 }
1120
1121
1122 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
1123  : BC_GenericButton(x, y, _("Up"))
1124 {
1125         this->gui = gui;
1126 }
1127 SketcherPointUp::~SketcherPointUp()
1128 {
1129 }
1130
1131 int SketcherPointUp::handle_event()
1132 {
1133         SketcherConfig &config = gui->plugin->config;
1134         int ci = config.cv_selected;
1135         if( ci < 0 || ci >= config.curves.size() )
1136                 return 1;
1137         SketcherCurve *cv = config.curves[ci];
1138         SketcherPoints &points = cv->points;
1139         if( points.size() < 2 )
1140                 return 1;
1141         int pi = config.pt_selected;
1142
1143         ArrayList<int> selected;
1144         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1145                 selected.append(v);
1146
1147         for( int i=0; i<selected.size(); ++i ) {
1148                 int k = selected[i];
1149                 if( k <= 0 ) continue;
1150                 if( k == pi ) --pi;
1151                 SketcherPoint *&pt0 = points[k];
1152                 SketcherPoint *&pt1 = points[--k];
1153                 SketcherPoint *t = pt0;  pt0 = pt1;  pt1 = t;
1154         }
1155         gui->point_list->update(pi);
1156         gui->send_configure_change();
1157         return 1;
1158 }
1159
1160 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
1161  : BC_GenericButton(x, y, _("Dn"))
1162 {
1163         this->gui = gui;
1164 }
1165 SketcherPointDn::~SketcherPointDn()
1166 {
1167 }
1168
1169 int SketcherPointDn::handle_event()
1170 {
1171         SketcherConfig &config = gui->plugin->config;
1172         int ci = config.cv_selected;
1173         if( ci < 0 || ci >= config.curves.size() )
1174                 return 1;
1175         SketcherCurve *cv = config.curves[ci];
1176         SketcherPoints &points = cv->points;
1177         int sz1 = points.size()-1;
1178         if( sz1 < 1 )
1179                 return 1;
1180         int pi = config.pt_selected;
1181
1182         ArrayList<int> selected;
1183         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1184                 selected.append(v);
1185
1186         for( int i=selected.size(); --i>=0; ) {
1187                 int k = selected[i];
1188                 if( k >= sz1 ) continue;
1189                 if( k == pi ) ++pi;
1190                 SketcherPoint *&pt0 = points[k];
1191                 SketcherPoint *&pt1 = points[++k];
1192                 SketcherPoint *t = pt0;  pt0 = pt1;  pt1 = t;
1193         }
1194         gui->point_list->update(pi);
1195         gui->send_configure_change();
1196         return 1;
1197 }
1198
1199 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
1200  : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
1201 {
1202         this->gui = gui;
1203 }
1204 int SketcherDrag::handle_event()
1205 {
1206         CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
1207         int value = get_value();
1208         if( value ) {
1209                 if( !gui->grab(cwindow_gui) ) {
1210                         update(value = 0);
1211                         flicker(10,50);
1212                 }
1213         }
1214         else
1215                 gui->ungrab(cwindow_gui);
1216         gui->plugin->config.drag = value;
1217         gui->send_configure_change();
1218         return 1;
1219 }
1220
1221 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1222  : BC_GenericButton(x, y, 64, _("New"))
1223 {
1224         this->gui = gui;
1225         this->plugin = plugin;
1226 }
1227 SketcherNewPoint::~SketcherNewPoint()
1228 {
1229 }
1230 int SketcherNewPoint::handle_event()
1231 {
1232         int pi = plugin->config.pt_selected;
1233         int arc = gui->point_type->type;
1234         int k = plugin->new_point(pi+1, arc);
1235         gui->point_list->update(k);
1236         gui->send_configure_change();
1237         return 1;
1238 }
1239
1240 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1241  : BC_GenericButton(x, y, 64, C_("Del"))
1242 {
1243         this->gui = gui;
1244         this->plugin = plugin;
1245 }
1246 SketcherDelPoint::~SketcherDelPoint()
1247 {
1248 }
1249 int SketcherDelPoint::handle_event()
1250 {
1251         SketcherConfig &config = gui->plugin->config;
1252         SketcherCurves &curves = config.curves;
1253         int ci = config.cv_selected;
1254         if( ci < 0 || ci >= curves.size() )
1255                 return 1;
1256         SketcherCurve *cv = curves[ci];
1257         SketcherPoints &points = cv->points;
1258         int pi = config.pt_selected;
1259
1260         ArrayList<int> selected;
1261         for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1262                 selected.append(v);
1263
1264         for( int i=selected.size(); --i>=0; ) {
1265                 int k = selected[i];
1266                 if( k < 0 || k >= points.size() ) continue;
1267                 points.remove_object_number(k);
1268                 if( k == pi && --pi < 0 && points.size() > 0 ) pi = 0;
1269         }
1270         gui->point_list->update(pi);
1271         gui->send_configure_change();
1272         return 1;
1273 }
1274
1275 SketcherResetCurves::SketcherResetCurves(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1276  : BC_GenericButton(x, y, _("Reset"))
1277 {
1278         this->gui = gui;
1279         this->plugin = plugin;
1280 }
1281 SketcherResetCurves::~SketcherResetCurves()
1282 {
1283 }
1284 int SketcherResetCurves::handle_event()
1285 {
1286         SketcherConfig &config = plugin->config;
1287         config.curves.remove_all_objects();
1288         int ci = plugin->new_curve();
1289         gui->curve_list->update(ci);
1290         gui->point_list->update(-1);
1291         gui->send_configure_change();
1292         return 1;
1293 }
1294
1295 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1296  : BC_GenericButton(x, y, _("Reset"))
1297 {
1298         this->gui = gui;
1299         this->plugin = plugin;
1300 }
1301 SketcherResetPoints::~SketcherResetPoints()
1302 {
1303 }
1304 int SketcherResetPoints::handle_event()
1305 {
1306         SketcherConfig &config = gui->plugin->config;
1307         int ci = config.cv_selected;
1308         if( ci >= 0 && ci < config.curves.size() ) {
1309                 SketcherCurve *cv = config.curves[ci];
1310                 cv->points.remove_all_objects();
1311                 gui->point_list->update(-1);
1312                 gui->send_configure_change();
1313         }
1314         return 1;
1315 }
1316