Credit Andrea improved comments in render format
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / sketcher / sketcherwindow.C
index ff97dd14dc14343348ec09cb8cee330319fbd786..c022ecddb947fb6b38b8e73ff41631d06908e817 100644 (file)
@@ -68,7 +68,7 @@ int SketcherCurvePenItem::handle_event()
        popup->update(pen);
        SketcherWindow *gui = popup->gui;
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci >= 0 && ci < config.curves.size() ) {
                SketcherCurve *cv = config.curves[ci];
                cv->pen = pen;
@@ -112,7 +112,7 @@ void SketcherCurveColor::handle_done_event(int result)
 {
        if( result ) color = orig_color | (~orig_alpha<<24);
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci >= 0 && ci < config.curves.size() ) {
                SketcherCurve *cv = config.curves[ci];
                cv->color = color;
@@ -129,7 +129,7 @@ int SketcherCurveColor::handle_new_color(int color, int alpha)
        gui->lock_window("SketcherCurveColor::update_gui");
        update_gui(color);
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci >= 0 ) {
                SketcherCurve *cv = config.curves[ci];
                cv->color = color;
@@ -143,7 +143,7 @@ int SketcherCurveColor::handle_new_color(int color, int alpha)
 
 SketcherCoord::SketcherCoord(SketcherWindow *gui, int x, int y,
                coord output, coord mn, coord mx)
- : BC_TumbleTextBox(gui, output, mn, mx, x, y, 64, 1)
+ : BC_TumbleTextBox(gui, output, mn, mx, x, y, xS(80), 1)
 {
        this->gui = gui;
        set_increment(1);
@@ -154,7 +154,7 @@ SketcherCoord::~SketcherCoord()
 
 SketcherNum::SketcherNum(SketcherWindow *gui, int x, int y,
                int output, int mn, int mx)
- : BC_TumbleTextBox(gui, output, mn, mx, x, y, 54)
+ : BC_TumbleTextBox(gui, output, mn, mx, x, y, xS(54))
 {
        this->gui = gui;
        set_increment(1);
@@ -167,11 +167,11 @@ int SketcherPointX::handle_event()
 {
        if( !SketcherCoord::handle_event() ) return 0;
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci >= 0 && ci < config.curves.size() ) {
                SketcherCurve *cv = config.curves[ci];
                SketcherPointList *point_list = gui->point_list;
-               int pi = config.pt_selected;
+               int pi = gui->plugin->pt_selected;
                SketcherPoints &points = cv->points;
                if( pi >= 0 && pi < points.size() ) {
                        coord v = atof(get_text());
@@ -187,11 +187,11 @@ int SketcherPointY::handle_event()
 {
        if( !SketcherCoord::handle_event() ) return 0;
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci >= 0 && ci < config.curves.size() ) {
                SketcherCurve *cv = config.curves[ci];
                SketcherPointList *point_list = gui->point_list;
-               int pi = config.pt_selected;
+               int pi = gui->plugin->pt_selected;
                SketcherPoints &points = cv->points;
                if( pi >= 0 && pi < points.size() ) {
                        coord v = atof(get_text());
@@ -208,11 +208,11 @@ int SketcherPointId::handle_event()
 {
        if( !SketcherNum::handle_event() ) return 0;
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci >= 0 && ci < config.curves.size() ) {
                SketcherCurve *cv = config.curves[ci];
                SketcherPointList *point_list = gui->point_list;
-               int pi = config.pt_selected;
+               int pi = gui->plugin->pt_selected;
                SketcherPoints &points = cv->points;
                if( pi >= 0 && pi < points.size() ) {
                        int id = atoi(get_text());
@@ -238,7 +238,7 @@ int SketcherCurveWidth::handle_event()
 {
        if( !SketcherNum::handle_event() ) return 0;
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci >= 0 && ci < config.curves.size() ) {
                SketcherCurve *cv = config.curves[ci];
                int v = atoi(get_text());
@@ -273,11 +273,12 @@ int SketcherAliasItem::handle_event()
 
 SketcherAliasing::SketcherAliasing(SketcherWindow *gui, Sketcher *plugin,
                int x, int y)
- : BC_PopupMenu(x, y, xS(64),
+ : BC_PopupMenu(x, y, xS(80),
                alias_to_text(plugin->config.aliasing), 1, 0, xS(3))
 {
        this->gui = gui;
        this->plugin = plugin;
+       set_tooltip(_("Anti-Aliasing"));
 }
 SketcherAliasing::~SketcherAliasing()
 {
@@ -293,14 +294,14 @@ void SketcherAliasing::create_objects()
 const char *SketcherAliasing::alias_to_text(int alias)
 {
        if( alias < 0 ) return _("Off");
-       if( alias > 0 ) return _("Dbl");
+       if( alias > 0 ) return _("Double");
        return _("On");
 }
 
 
 
 SketcherWindow::SketcherWindow(Sketcher *plugin)
- : PluginClientWindow(plugin, xS(400), yS(620), xS(400), yS(620), 0)
+ : PluginClientWindow(plugin, xS(460), yS(680), xS(460), yS(680), 0)
 {
        this->plugin = plugin;
        this->title_pen = 0;  this->curve_pen = 0;
@@ -326,6 +327,9 @@ SketcherWindow::SketcherWindow(Sketcher *plugin)
        new_points = 0;
        pending_motion = 0;
        pending_config = 0;
+       helped = 0;
+       help_h = get_h();
+       last_time = 0;
 }
 
 SketcherWindow::~SketcherWindow()
@@ -340,12 +344,12 @@ void SketcherWindow::create_objects()
        int x = xS(10), y = yS(10), dy = 0, x1, y1;
        int margin = plugin->get_theme()->widget_border;
        BC_Title *title;
-       int ci = plugin->config.cv_selected;
+       int ci = plugin->cv_selected;
        if( ci < 0 || ci >= plugin->config.curves.size() )
                ci = plugin->new_curve();
        SketcherCurve *cv = plugin->config.curves[ci];
 
-       reset_curves = new SketcherResetCurves(this, plugin, x1=x, y+yS(3));
+       reset_curves = new SketcherResetCurves(this, plugin, x1=x, y);
        add_subwindow(reset_curves);    dy = bmax(dy,reset_curves->get_h());
        x1 += reset_curves->get_w() + 2*margin;
        const char *curve_text = _("Curve");
@@ -406,15 +410,15 @@ void SketcherWindow::create_objects()
        add_subwindow(bar);             dy = bmax(dy,bar->get_h());
        y += dy + yS(2)*margin;
 
-       int pi = plugin->config.pt_selected;
+       int pi = plugin->pt_selected;
        SketcherPoint *pt = pi >= 0 && pi < cv->points.size() ? cv->points[pi] : 0;
        reset_points = new SketcherResetPoints(this, plugin, x1=x, y+yS(3));
        add_subwindow(reset_points);    dy = bmax(dy,reset_points->get_h());
        x1 += reset_points->get_w() + xS(2)*margin;
-       if( plugin->config.drag ) {
+       if( plugin->drag ) {
                if( !grab(plugin->server->mwindow->cwindow->gui) ) {
                        eprintf("drag enabled, but compositor already grabbed\n");
-                       plugin->config.drag = 0;
+                       plugin->drag = 0;
                }
        }
        drag = new SketcherDrag(this, x1, y);
@@ -468,6 +472,9 @@ void SketcherWindow::create_objects()
        y += dy + margin + yS(5);               dy = 0;
        point_list->update(pi);
 
+       add_subwindow(help = new SketcherHelp(this, plugin, x, y));
+       y += help->get_h() + yS(5);
+       help_y = y;
        bar = new BC_Bar(x, y, get_w()-xS(2)*x);
        add_subwindow(bar);             dy = bmax(dy,bar->get_h());
        y += dy + yS(2)*margin;
@@ -486,7 +493,7 @@ void SketcherWindow::create_objects()
                   "drag point\n"
                   "drag all curves\n"
                   "new fill point"))); dy = bmax(dy, notes1->get_h());
-       add_subwindow(notes2 = new BC_Title(x+xS(220), y,
+       add_subwindow(notes2 = new BC_Title(x+xS(280), y,
                 _("      RMB\n"
                   "new arc point\n"
                   "select curve\n"
@@ -496,7 +503,11 @@ void SketcherWindow::create_objects()
        y += dy + margin + yS(10);
 
        add_subwindow(notes3 = new BC_Title(x, y,
-                  "Key DEL= delete point, +Shift= delete curve\n"));
+                _("Wheel: rotate, centered on cursor\n"
+                  "Wheel: shift: scale, centered on cursor\n"
+                  "Key DEL= delete point, +Shift= delete curve\n")));
+
+       resize_window(get_w(), help_y);
        show_window(1);
 }
 
@@ -602,7 +613,7 @@ int SketcherWindow::do_grab_event(XEvent *event)
 int SketcherWindow::grab_button_press(XEvent *event)
 {
        SketcherConfig &config = plugin->config;
-       int ci = config.cv_selected;
+       int ci = plugin->cv_selected;
        if( ci < 0 || ci >= plugin->config.curves.size() )
                return 0;
         MWindow *mwindow = plugin->server->mwindow;
@@ -612,10 +623,40 @@ int SketcherWindow::grab_button_press(XEvent *event)
        SketcherCurves &curves = config.curves;
        SketcherCurve *cv = curves[ci];
        SketcherPoints &points = cv->points;
-       int pi = config.pt_selected;
-
+       int pi = plugin->pt_selected;
+
+       float s = 1.001; // min scale
+       float th = 0.1 * M_PI/180.f; // min theta .1 deg per wheel_btn
+       int64_t ms = event->xbutton.time;
+       double dt = (ms - last_time) / 1000.;  // seconds
+       last_time = ms;
+       double mx_accel = 100., r = mx_accel / exp(1.);
+       double mx_dt = 1./2., mn_dt = 1./15.; // mn..mx period in sec/xev
+       bclip(dt, mn_dt, mx_dt);
+       double accel = r * exp(-(dt-mn_dt)/(mx_dt-mn_dt));
        int button_no = event->xbutton.button;
        switch( button_no ) {
+       case WHEEL_DOWN:
+               s = 2 - s;
+               th = -th;  // fall thru
+       case WHEEL_UP: { // shift_down scale, !shift_down rotate
+               s =  1 + (s-1)*accel;
+               th *= accel;
+               float st = sin(th), ct = cos(th);
+               int sz = points.size();
+               int shift_down = (state & ShiftMask) ? 1 : 0;
+               for( int i=0; i<sz; ++i ) {
+                       SketcherPoint *pt = points[i];
+                       float px = pt->x - track_x, py = pt->y - track_y;
+                       float nx = shift_down ? px*s : px*ct + py*st;
+                       float ny = shift_down ? py*s : py*ct - px*st;
+                       point_list->set_point(i, PT_X, pt->x = nx + track_x);
+                       point_list->set_point(i, PT_Y, pt->y = ny + track_y);
+               }
+               point_list->update(-1);
+               button_no = 0;
+               break; }
+
        case LEFT_BUTTON: {
                if( (state & ShiftMask) ) { // create new point/string
                        ++new_points;
@@ -683,13 +724,13 @@ int SketcherWindow::grab_cursor_motion()
                return 0;
        pending_motion = 0;
        SketcherConfig &config = plugin->config;
-       int ci = config.cv_selected;
+       int ci = plugin->cv_selected;
        if( ci < 0 || ci >= plugin->config.curves.size() )
                return 0;
        SketcherCurves &curves = config.curves;
        SketcherCurve *cv = curves[ci];
        SketcherPoints &points = cv->points;
-       int pi = config.pt_selected;
+       int pi = plugin->pt_selected;
 
        if( (state & ShiftMask) ) {  // string of points
                if( (state & (Button1Mask|Button3Mask)) ) {
@@ -775,7 +816,7 @@ int SketcherWindow::keypress_event()
                        del_curve->handle_event() :
                        del_point->handle_event() ;
        }
-       return 0;
+       return context_help_check_and_show();
 }
 
 
@@ -833,7 +874,7 @@ void SketcherCurveList::set_selected(int k)
                gui->curve_color->update_gui(cv->color);
                ci = k;
        }
-       plugin->config.cv_selected = ci;
+       plugin->cv_selected = ci;
        update_list(ci);
 }
 
@@ -878,7 +919,7 @@ void SketcherCurveList::add_curve(const char *id, const char *pen,
 }
 
 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
- : BC_GenericButton(x, y, xS(64), _("New"))
+ : BC_GenericButton(x, y, xS(96), _("New"))
 {
        this->gui = gui;
        this->plugin = plugin;
@@ -891,7 +932,7 @@ int SketcherNewCurve::handle_event()
        int pen = gui->curve_pen->pen;
        int color = gui->curve_color->color;
        int width = gui->curve_width->width;
-       int ci = plugin->config.cv_selected;
+       int ci = plugin->cv_selected;
        if( ci >= 0 && ci < plugin->config.curves.size() ) {
                SketcherCurve *cv = plugin->config.curves[ci];
                pen = cv->pen;  width = cv->width;  color = cv->color;
@@ -904,7 +945,7 @@ int SketcherNewCurve::handle_event()
 }
 
 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
- : BC_GenericButton(x, y, xS(64), C_("Del"))
+ : BC_GenericButton(x, y, xS(96), C_("Del"))
 {
        this->gui = gui;
        this->plugin = plugin;
@@ -915,7 +956,7 @@ SketcherDelCurve::~SketcherDelCurve()
 int SketcherDelCurve::handle_event()
 {
        SketcherConfig &config = plugin->config;
-       int ci = config.cv_selected;
+       int ci = plugin->cv_selected;
        SketcherCurves &curves = config.curves;
        if( ci >= 0 && ci < curves.size() ) {
                curves.remove_object_number(ci--);
@@ -930,7 +971,7 @@ int SketcherDelCurve::handle_event()
 }
 
 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
- : BC_GenericButton(x, y, _("Up"))
+ : BC_GenericButton(x, y, xS(96), _("Up"))
 {
        this->gui = gui;
 }
@@ -941,7 +982,7 @@ SketcherCurveUp::~SketcherCurveUp()
 int SketcherCurveUp::handle_event()
 {
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        SketcherCurves &curves = config.curves;
        if( ci > 0 && ci < curves.size() ) {
                SketcherCurve *&cv0 = curves[ci];
@@ -954,7 +995,7 @@ int SketcherCurveUp::handle_event()
 }
 
 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
- : BC_GenericButton(x, y, _("Dn"))
+ : BC_GenericButton(x, y, xS(96), _("Dn"))
 {
        this->gui = gui;
 }
@@ -965,7 +1006,7 @@ SketcherCurveDn::~SketcherCurveDn()
 int SketcherCurveDn::handle_event()
 {
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        SketcherCurves &curves = config.curves;
        if( ci >= 0 && ci < curves.size()-1 ) {
                SketcherCurve *&cv0 = curves[ci];
@@ -990,12 +1031,11 @@ int SketcherPointTypeItem::handle_event()
        SketcherWindow *gui = popup->gui;
        SketcherConfig &config = gui->plugin->config;
        SketcherCurves &curves = config.curves;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci < 0 || ci >= curves.size() )
                return 1;
        SketcherCurve *cv = curves[ci];
        SketcherPoints &points = cv->points;
-       int pi = config.pt_selected;
 
        ArrayList<int> selected;
        for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
@@ -1009,6 +1049,7 @@ int SketcherPointTypeItem::handle_event()
                gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
        }
 
+       int pi = gui->plugin->pt_selected;
        gui->point_list->update_list(pi);
        gui->send_configure_change();
        return 1;
@@ -1102,7 +1143,7 @@ void SketcherPointList::set_point(int i, int c, const char *cp)
 void SketcherPointList::set_selected(int k)
 {
        SketcherPoint *pt = 0;
-       int ci = plugin->config.cv_selected, pi = -1;
+       int ci = plugin->cv_selected, pi = -1;
        if( ci >= 0 && ci < plugin->config.curves.size() ) {
                SketcherCurve *cv = plugin->config.curves[ci];
                pt = k >= 0 && k < cv->points.size() ? cv->points[pi=k] : 0;
@@ -1111,7 +1152,7 @@ void SketcherPointList::set_selected(int k)
        gui->point_x->update(pt ? pt->x : 0.f);
        gui->point_y->update(pt ? pt->y : 0.f);
        gui->point_id->update(pt ? pt->id : 0);
-       plugin->config.pt_selected = pi;
+       plugin->pt_selected = pi;
        update_list(pi);
 }
 void SketcherPointList::update_list(int k)
@@ -1124,7 +1165,7 @@ void SketcherPointList::update_list(int k)
 void SketcherPointList::update(int k)
 {
        clear();
-       int ci = plugin->config.cv_selected, sz = 0;
+       int ci = plugin->cv_selected, sz = 0;
        if( ci >= 0 && ci < plugin->config.curves.size() ) {
                SketcherCurve *cv = plugin->config.curves[ci];
                SketcherPoints &points = cv->points;
@@ -1144,24 +1185,24 @@ void SketcherPointList::update(int k)
 void SketcherWindow::update_gui()
 {
        SketcherConfig &config = plugin->config;
-       int ci = config.cv_selected;
-       int pi = config.pt_selected;
-       curve_list->update(ci);
-       point_list->update(pi);
+       curve_list->update(plugin->cv_selected);
+       point_list->update(plugin->pt_selected);
+       int ci = plugin->cv_selected;
        SketcherCurve *cv = ci >= 0 ? config.curves[ci] : 0;
        curve_width->update(cv ? cv->width : 1);
        curve_pen->update(cv ? cv->pen : PEN_SQUARE);
        curve_color->set_color(cv ? cv->color : CV_COLOR);
-       SketcherPoint *pt = pi >= 0 ? cv->points[pi] : 0;
+       int pi = plugin->pt_selected;
+       SketcherPoint *pt = pi >= 0 && pi<cv->points.size() ? cv->points[pi] : 0;
        point_x->update(pt ? pt->x : 0);
        point_y->update(pt ? pt->y : 0);
        point_id->update(pt ? pt->id : 0);
-       drag->update(plugin->config.drag);
+       drag->update(plugin->drag);
 }
 
 
 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
- : BC_GenericButton(x, y, _("Up"))
+ : BC_GenericButton(x, y, xS(96), _("Up"))
 {
        this->gui = gui;
 }
@@ -1172,14 +1213,16 @@ SketcherPointUp::~SketcherPointUp()
 int SketcherPointUp::handle_event()
 {
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci < 0 || ci >= config.curves.size() )
                return 1;
        SketcherCurve *cv = config.curves[ci];
        SketcherPoints &points = cv->points;
        if( points.size() < 2 )
                return 1;
-       int pi = config.pt_selected;
+       int pi = gui->plugin->pt_selected;
+       if( pi < 0 || pi >= points.size() )
+               return 1;
 
        ArrayList<int> selected;
        for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
@@ -1199,7 +1242,7 @@ int SketcherPointUp::handle_event()
 }
 
 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
- : BC_GenericButton(x, y, _("Dn"))
+ : BC_GenericButton(x, y, xS(96), _("Dn"))
 {
        this->gui = gui;
 }
@@ -1210,7 +1253,7 @@ SketcherPointDn::~SketcherPointDn()
 int SketcherPointDn::handle_event()
 {
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci < 0 || ci >= config.curves.size() )
                return 1;
        SketcherCurve *cv = config.curves[ci];
@@ -1218,7 +1261,9 @@ int SketcherPointDn::handle_event()
        int sz1 = points.size()-1;
        if( sz1 < 1 )
                return 1;
-       int pi = config.pt_selected;
+       int pi = gui->plugin->pt_selected;
+       if( pi < 0 || pi >= points.size() )
+               return 1;
 
        ArrayList<int> selected;
        for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
@@ -1238,7 +1283,7 @@ int SketcherPointDn::handle_event()
 }
 
 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
- : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
+ : BC_CheckBox(x, y, gui->plugin->drag, (C_("Drag")))
 {
        this->gui = gui;
 }
@@ -1254,13 +1299,23 @@ int SketcherDrag::handle_event()
        }
        else
                gui->ungrab(cwindow_gui);
-       gui->plugin->config.drag = value;
+       gui->plugin->drag = value;
        gui->send_configure_change();
        return 1;
 }
+int SketcherWindow::handle_ungrab()
+{
+       CWindowGUI *cwindow_gui = plugin->server->mwindow->cwindow->gui;
+       int ret = ungrab(cwindow_gui);
+       if( ret ) {
+               drag->update(0);
+               plugin->drag = 0;
+       }
+       return ret;
+}
 
 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
- : BC_GenericButton(x, y, xS(64), _("New"))
+ : BC_GenericButton(x, y, xS(96), _("New"))
 {
        this->gui = gui;
        this->plugin = plugin;
@@ -1270,16 +1325,25 @@ SketcherNewPoint::~SketcherNewPoint()
 }
 int SketcherNewPoint::handle_event()
 {
-       int pi = plugin->config.pt_selected;
+       SketcherConfig &config = gui->plugin->config;
+       SketcherCurves &curves = config.curves;
+       int ci = gui->plugin->cv_selected;
+       if( ci < 0 || ci >= curves.size() )
+               return -1;
+       SketcherCurve *cv = curves[ci];
+       SketcherPoints &points = cv->points;
+       int pi = gui->plugin->pt_selected;
+       if( pi < 0 || pi >= points.size() )
+               return -1;
        int arc = gui->point_type->type;
-       int k = plugin->new_point(pi+1, arc);
+       int k = plugin->new_point(pi<0 ? 0 : pi+1, arc);
        gui->point_list->update(k);
        gui->send_configure_change();
        return 1;
 }
 
 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
- : BC_GenericButton(x, y, xS(64), C_("Del"))
+ : BC_GenericButton(x, y, xS(96), C_("Del"))
 {
        this->gui = gui;
        this->plugin = plugin;
@@ -1291,12 +1355,14 @@ int SketcherDelPoint::handle_event()
 {
        SketcherConfig &config = gui->plugin->config;
        SketcherCurves &curves = config.curves;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci < 0 || ci >= curves.size() )
                return 1;
        SketcherCurve *cv = curves[ci];
        SketcherPoints &points = cv->points;
-       int pi = config.pt_selected;
+       int pi = gui->plugin->pt_selected;
+       if( pi < 0 || pi >= points.size() )
+               return 1;
 
        ArrayList<int> selected;
        for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
@@ -1334,7 +1400,7 @@ int SketcherResetCurves::handle_event()
 }
 
 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
- : BC_GenericButton(x, y, _("Reset"))
+ : BC_GenericButton(x, y-yS(2), _("Reset"))
 {
        this->gui = gui;
        this->plugin = plugin;
@@ -1345,7 +1411,7 @@ SketcherResetPoints::~SketcherResetPoints()
 int SketcherResetPoints::handle_event()
 {
        SketcherConfig &config = gui->plugin->config;
-       int ci = config.cv_selected;
+       int ci = gui->plugin->cv_selected;
        if( ci >= 0 && ci < config.curves.size() ) {
                SketcherCurve *cv = config.curves[ci];
                cv->points.remove_all_objects();
@@ -1355,3 +1421,23 @@ int SketcherResetPoints::handle_event()
        return 1;
 }
 
+SketcherHelp::SketcherHelp(SketcherWindow *gui, Sketcher *plugin, int x, int y)
+ : BC_CheckBox(x, y, 0, _("Help"))
+{
+       this->gui = gui;
+       this->plugin = plugin;
+        set_tooltip(_("Show help text"));
+}
+SketcherHelp::~SketcherHelp()
+{
+}
+
+int SketcherHelp::handle_event()
+{
+        gui->helped = get_value();
+        gui->resize_window(gui->get_w(),
+                gui->helped ? gui->help_h : gui->help_y);
+        gui->update_gui();
+        return 1;
+}
+