X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Fsketcher%2Fsketcherwindow.C;h=dfb7e956b6dfef1d044bd38b7da7943f90862902;hp=dd917e4b48cb97ee8bccb4de0826ddf94b817280;hb=052becff04e4f4a4240a87c6b2f2f4023b65d247;hpb=8fd64d1d3770c95e2a7cba1049e909cadb4e1fbf diff --git a/cinelerra-5.1/plugins/sketcher/sketcherwindow.C b/cinelerra-5.1/plugins/sketcher/sketcherwindow.C index dd917e4b..dfb7e956 100644 --- a/cinelerra-5.1/plugins/sketcher/sketcherwindow.C +++ b/cinelerra-5.1/plugins/sketcher/sketcherwindow.C @@ -39,8 +39,8 @@ #define AltMask Mod1Mask -#define COLOR_W 40 -#define COLOR_H 24 +#define COLOR_W xS(40) +#define COLOR_H yS(24) const char *SketcherPoint::types[] = { N_("off"), @@ -79,7 +79,7 @@ int SketcherCurvePenItem::handle_event() } SketcherCurvePen::SketcherCurvePen(SketcherWindow *gui, int x, int y, int pen) - : BC_PopupMenu(x,y,100,_(cv_pen[pen])) + : BC_PopupMenu(x,y,xS(100),_(cv_pen[pen])) { this->gui = gui; this->pen = pen; @@ -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); @@ -255,8 +255,53 @@ void SketcherCurveWidth::update(int width) } +SketcherAliasItem::SketcherAliasItem(SketcherAliasing *popup, int v) + : BC_MenuItem(popup->alias_to_text(v)) +{ + this->popup = popup; + this->v = v; +} + +int SketcherAliasItem::handle_event() +{ + popup->set_text(get_text()); + popup->plugin->config.aliasing = v; + popup->gui->send_configure_change(); + return 1; +} + + +SketcherAliasing::SketcherAliasing(SketcherWindow *gui, Sketcher *plugin, + int x, int y) + : 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() +{ +} + +void SketcherAliasing::create_objects() +{ + add_item(new SketcherAliasItem(this, -1)); + add_item(new SketcherAliasItem(this, 0)); + add_item(new SketcherAliasItem(this, 1)); +} + +const char *SketcherAliasing::alias_to_text(int alias) +{ + if( alias < 0 ) return _("Off"); + if( alias > 0 ) return _("Double"); + return _("On"); +} + + + SketcherWindow::SketcherWindow(Sketcher *plugin) - : PluginClientWindow(plugin, 380, 620, 380, 620, 0) + : PluginClientWindow(plugin, xS(460), yS(680), xS(460), yS(680), 0) { this->plugin = plugin; this->title_pen = 0; this->curve_pen = 0; @@ -282,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() @@ -293,7 +341,7 @@ SketcherWindow::~SketcherWindow() void SketcherWindow::create_objects() { - int x = 10, y = 10, dy = 0, x1, y1; + 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; @@ -301,7 +349,7 @@ void SketcherWindow::create_objects() ci = plugin->new_curve(); SketcherCurve *cv = plugin->config.curves[ci]; - reset_curves = new SketcherResetCurves(this, plugin, x1=x, y+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"); @@ -310,6 +358,10 @@ void SketcherWindow::create_objects() x1 += title_width->get_w() + margin; curve_width = new SketcherCurveWidth(this, x1, y, cv->width); curve_width->create_objects(); + x1 += curve_width->get_w() + margin; + aliasing = new SketcherAliasing(this, plugin, x1, y); + add_subwindow(aliasing); dy = bmax(dy,aliasing->get_h()); + aliasing->create_objects(); y += dy + 2*margin; dy = 0; x1 = get_w()-x - BC_Title::calculate_w(this, curve_text, LARGEFONT); @@ -328,9 +380,9 @@ void SketcherWindow::create_objects() add_subwindow(curve_up); dy = bmax(dy,curve_up->get_h()); x1 += curve_up->get_w() + 4*margin; y1 = BC_Title::calculate_h(this, _("Pen:")); - title_pen = new BC_Title(x1+30, y+dy-y1, _("Pen:")); + title_pen = new BC_Title(x1+xS(30), y+dy-y1, _("Pen:")); add_subwindow(title_pen); dy = bmax(dy,title_pen->get_h()); - int x2 = (get_w()+x1)/2 + 20; + int x2 = (get_w()+x1)/2 + xS(20); y1 = BC_Title::calculate_h(this, _("Color:")); title_color = new BC_Title(x2, y+dy-y1, _("Color:")); add_subwindow(title_color); dy = bmax(dy,title_color->get_h()); @@ -352,17 +404,17 @@ void SketcherWindow::create_objects() curve_list->update(ci); BC_Bar *bar; - bar = new BC_Bar(x, y, get_w()-2*x); + bar = new BC_Bar(x, y, get_w()-xS(2)*x); add_subwindow(bar); dy = bmax(dy,bar->get_h()); - bar = new BC_Bar(x, y+=dy, get_w()-2*x); + bar = new BC_Bar(x, y+=dy, get_w()-xS(2)*x); add_subwindow(bar); dy = bmax(dy,bar->get_h()); - y += dy + 2*margin; + y += dy + yS(2)*margin; int pi = plugin->config.pt_selected; SketcherPoint *pt = pi >= 0 && pi < cv->points.size() ? cv->points[pi] : 0; - reset_points = new SketcherResetPoints(this, plugin, x1=x, y+3); + 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() + 2*margin; + x1 += reset_points->get_w() + xS(2)*margin; if( plugin->config.drag ) { if( !grab(plugin->server->mwindow->cwindow->gui) ) { eprintf("drag enabled, but compositor already grabbed\n"); @@ -371,7 +423,7 @@ void SketcherWindow::create_objects() } drag = new SketcherDrag(this, x1, y); add_subwindow(drag); dy = bmax(dy,drag->get_h()); - x1 += drag->get_w() + 2*margin; + x1 += drag->get_w() + xS(2)*margin; int arc = pt ? pt->arc : ARC_LINE; point_type = new SketcherPointType(this, x1, y, arc); add_subwindow(point_type); dy = bmax(dy,point_type->get_h()); @@ -392,15 +444,15 @@ void SketcherWindow::create_objects() x1 += new_point->get_w() + margin; point_up = new SketcherPointUp(this, x1, y); add_subwindow(point_up); dy = bmax(dy,point_up->get_h()); - x1 += point_up->get_w() + 2*margin; + x1 += point_up->get_w() + xS(2)*margin; title_x = new BC_Title(x1, y, _("X:")); add_subwindow(title_x); dy = bmax(dy,title_x->get_h()); x1 += title_x->get_w() + margin; point_x = new SketcherPointX(this, x1, y, !pt ? 0.f : pt->x); point_x->create_objects(); dy = bmax(dy, point_x->get_h()); - x2 = x1 + point_x->get_w() + 2*margin + 10; + x2 = x1 + point_x->get_w() + xS(2)*margin + xS(10); y1 = BC_Title::calculate_h(this, _("ID:")); - title_id = new BC_Title(x2+16, y+dy-y1, _("ID:")); + title_id = new BC_Title(x2+xS(16), y+dy-y1, _("ID:")); add_subwindow(title_id); dy = bmax(dy, title_id->get_h()); y += dy + margin; dy = 0; @@ -409,7 +461,7 @@ void SketcherWindow::create_objects() x1 += del_point->get_w() + margin; point_dn = new SketcherPointDn(this, x1, y); add_subwindow(point_dn); dy = bmax(dy,point_dn->get_h()); - x1 += point_dn->get_w() + 2*margin; + x1 += point_dn->get_w() + xS(2)*margin; title_y = new BC_Title(x1, y, _("Y:")); add_subwindow(title_y); dy = bmax(dy,title_y->get_h()); x1 += title_y->get_w() + margin; @@ -417,12 +469,15 @@ void SketcherWindow::create_objects() point_y->create_objects(); dy = bmax(dy, point_y->get_h()); point_id = new SketcherPointId(this, x2, y, !pt ? 0 : pt->id); point_id->create_objects(); dy = bmax(dy, point_id->get_h()); - y += dy + margin + 5; dy = 0; + y += dy + margin + yS(5); dy = 0; point_list->update(pi); - bar = new BC_Bar(x, y, get_w()-2*x); + 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 + 2*margin; + y += dy + yS(2)*margin; add_subwindow(notes0 = new BC_Title(x, y, _("\n" @@ -431,24 +486,28 @@ void SketcherWindow::create_objects() "Ctrl=\n" "Ctrl+Alt=\n" "Ctrl+Shift="))); dy = bmax(dy, notes0->get_h()); - add_subwindow(notes1 = new BC_Title(x+100, y, + add_subwindow(notes1 = new BC_Title(x+xS(100), y, _(" LMB\n" "new line point\n" "select point\n" "drag point\n" "drag all curves\n" "new fill point"))); dy = bmax(dy, notes1->get_h()); - add_subwindow(notes2 = new BC_Title(x+220, y, + add_subwindow(notes2 = new BC_Title(x+xS(220), y, _(" RMB\n" "new arc point\n" "select curve\n" "drag curve\n" "new curve\n" "new off point"))); dy = bmax(dy, notes2->get_h()); - y += dy + margin + 10; + y += dy + margin + yS(10); add_subwindow(notes3 = new BC_Title(x, y, + "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); } @@ -472,7 +531,7 @@ int SketcherWindow::grab_event(XEvent *event) if( grab_cursor_motion() ) pending_config = 1; if( pending_config ) { - last_x = output_x; last_y = output_y; + last_x = track_x; last_y = track_y; send_configure_change(); } } @@ -566,8 +625,38 @@ int SketcherWindow::grab_button_press(XEvent *event) SketcherPoints &points = cv->points; int pi = config.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; ix - 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; @@ -732,15 +821,15 @@ int SketcherWindow::keypress_event() SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y) - : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT) + : BC_ListBox(x, y, xS(360), yS(130), LISTBOX_TEXT) { this->gui = gui; this->plugin = plugin; - col_titles[CV_ID] = _("ID"); col_widths[CV_ID] = 64; - col_titles[CV_RAD] = _("width"); col_widths[CV_RAD] = 64; - col_titles[CV_PEN] = _("pen"); col_widths[CV_PEN] = 64; - col_titles[CV_CLR] = _("color"); col_widths[CV_CLR] = 80; - col_titles[CV_ALP] = _("alpha"); col_widths[CV_ALP] = 64; + col_titles[CV_ID] = _("ID"); col_widths[CV_ID] = xS(64); + col_titles[CV_RAD] = _("width"); col_widths[CV_RAD] = xS(64); + col_titles[CV_PEN] = _("pen"); col_widths[CV_PEN] = xS(64); + col_titles[CV_CLR] = _("color"); col_widths[CV_CLR] = xS(80); + col_titles[CV_ALP] = _("alpha"); col_widths[CV_ALP] = xS(64); } SketcherCurveList::~SketcherCurveList() { @@ -830,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, 64, _("New")) + : BC_GenericButton(x, y, xS(96), _("New")) { this->gui = gui; this->plugin = plugin; @@ -856,7 +945,7 @@ int SketcherNewCurve::handle_event() } SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y) - : BC_GenericButton(x, y, 64, C_("Del")) + : BC_GenericButton(x, y, xS(96), C_("Del")) { this->gui = gui; this->plugin = plugin; @@ -882,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; } @@ -906,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; } @@ -967,7 +1056,7 @@ int SketcherPointTypeItem::handle_event() } SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc) - : BC_PopupMenu(x,y,100,_(pt_type[arc])) + : BC_PopupMenu(x,y,xS(100),_(pt_type[arc])) { this->gui = gui; this->type = arc; @@ -984,14 +1073,14 @@ void SketcherPointType::update(int arc) SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y) - : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT) + : BC_ListBox(x, y, xS(360), yS(130), LISTBOX_TEXT) { this->gui = gui; this->plugin = plugin; - col_titles[PT_ID] = _("ID"); col_widths[PT_ID] = 50; - col_titles[PT_TY] = _("Type"); col_widths[PT_TY] = 80; - col_titles[PT_X] = _("X"); col_widths[PT_X] = 90; - col_titles[PT_Y] = _("Y"); col_widths[PT_Y] = 90; + col_titles[PT_ID] = _("ID"); col_widths[PT_ID] = xS(50); + col_titles[PT_TY] = _("Type"); col_widths[PT_TY] = xS(80); + col_titles[PT_X] = _("X"); col_widths[PT_X] = xS(90); + col_titles[PT_Y] = _("Y"); col_widths[PT_Y] = xS(90); set_selection_mode(LISTBOX_MULTIPLE); } SketcherPointList::~SketcherPointList() @@ -1113,7 +1202,7 @@ void SketcherWindow::update_gui() SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y) - : BC_GenericButton(x, y, _("Up")) + : BC_GenericButton(x, y, xS(96), _("Up")) { this->gui = gui; } @@ -1151,7 +1240,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; } @@ -1212,7 +1301,7 @@ int SketcherDrag::handle_event() } SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y) - : BC_GenericButton(x, y, 64, _("New")) + : BC_GenericButton(x, y, xS(96), _("New")) { this->gui = gui; this->plugin = plugin; @@ -1231,7 +1320,7 @@ int SketcherNewPoint::handle_event() } SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y) - : BC_GenericButton(x, y, 64, C_("Del")) + : BC_GenericButton(x, y, xS(96), C_("Del")) { this->gui = gui; this->plugin = plugin; @@ -1286,7 +1375,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; @@ -1307,3 +1396,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; +} +