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