X-Git-Url: https://cinelerra-gg.org/git/?a=blobdiff_plain;ds=sidebyside;f=cinelerra-5.1%2Fplugins%2Fsketcher%2Fsketcherwindow.C;h=f62802a73abc048eef894c6a50f70fc22bc3ad97;hb=0df48ad2d876409c5beeae2e21933a728ea76c33;hp=4a0f18f9a439b5adc8294e478bfdbe0b78ae3943;hpb=824ab396d0db646c64d57a75b08e80fbc0b5de8e;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/plugins/sketcher/sketcherwindow.C b/cinelerra-5.1/plugins/sketcher/sketcherwindow.C index 4a0f18f9..f62802a7 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,72,_(cv_pen[pen])) + : BC_PopupMenu(x,y,xS(100),_(cv_pen[pen])) { this->gui = gui; this->pen = pen; @@ -102,16 +102,10 @@ SketcherCurveColor::SketcherCurveColor(SketcherWindow *gui, { this->gui = gui; this->color = CV_COLOR; - for( int i=0; i<3; ++i ) { - vframes[i] = new VFrame(w, h, BC_RGB888); - vframes[i]->clear_frame(); - } } SketcherCurveColor::~SketcherCurveColor() { - for( int i=0; i<3; ++i ) - delete vframes[i]; } void SketcherCurveColor::handle_done_event(int result) @@ -262,7 +256,7 @@ void SketcherCurveWidth::update(int width) SketcherWindow::SketcherWindow(Sketcher *plugin) - : PluginClientWindow(plugin, 380, 620, 380, 620, 0) + : PluginClientWindow(plugin, xS(380), yS(620), xS(380), yS(620), 0) { this->plugin = plugin; this->title_pen = 0; this->curve_pen = 0; @@ -280,8 +274,8 @@ SketcherWindow::SketcherWindow(Sketcher *plugin) position = -1; track_w = track_h -1; - cursor_x = cursor_y = -1; output_x = output_y = -1; + track_x = track_y = -1; last_x = last_y = -1; projector_x = projector_y = projector_z = -1; state = 0; dragging = 0; @@ -299,7 +293,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; @@ -307,7 +301,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+yS(3)); add_subwindow(reset_curves); dy = bmax(dy,reset_curves->get_h()); x1 += reset_curves->get_w() + 2*margin; const char *curve_text = _("Curve"); @@ -334,9 +328,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()); @@ -358,17 +352,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"); @@ -377,7 +371,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()); @@ -398,15 +392,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; @@ -415,7 +409,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; @@ -423,35 +417,35 @@ 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); + 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" "Shift=\n" "None=\n" "Ctrl=\n" - "Alt=\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, "Key DEL= delete point, +Shift= delete curve\n")); @@ -460,6 +454,8 @@ void SketcherWindow::create_objects() void SketcherWindow::done_event(int result) { + curve_color->close_picker(); + ungrab(plugin->server->mwindow->cwindow->gui); } void SketcherWindow::send_configure_change() @@ -476,7 +472,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(); } } @@ -506,16 +502,17 @@ int SketcherWindow::do_grab_event(XEvent *event) MWindow *mwindow = plugin->server->mwindow; CWindowGUI *cwindow_gui = mwindow->cwindow->gui; CWindowCanvas *canvas = cwindow_gui->canvas; - int cx, cy; cwindow_gui->get_relative_cursor(cx, cy); - cx -= mwindow->theme->ccanvas_x; - cy -= mwindow->theme->ccanvas_y; + cwindow_gui->get_relative_cursor(cursor_x, cursor_y); + output_x = cursor_x - canvas->view_x; + output_y = cursor_y - canvas->view_y; if( !dragging ) { - if( cx < 0 || cx >= mwindow->theme->ccanvas_w || - cy < 0 || cy >= mwindow->theme->ccanvas_h ) + if( output_x < 0 || output_x >= canvas->view_w || + output_y < 0 || output_y >= canvas->view_h ) return 0; } + switch( event->type ) { case ButtonPress: if( dragging ) return 0; @@ -530,19 +527,8 @@ int SketcherWindow::do_grab_event(XEvent *event) return 0; } - cursor_x = cx, cursor_y = cy; - canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y); - position = plugin->get_source_position(); - Track *track = plugin->server->plugin->track; - track_w = track->track_w; - track_h = track->track_h; - track->automation->get_projector( - &projector_x, &projector_y, &projector_z, - position, PLAY_FORWARD); - projector_x += mwindow->edl->session->output_w / 2; - projector_y += mwindow->edl->session->output_h / 2; - output_x = (cursor_x - projector_x) / projector_z + track_w / 2; - output_y = (cursor_y - projector_y) / projector_z + track_h / 2; + canvas->canvas_to_output(mwindow->edl, 0, output_x, output_y); + plugin->output_to_track(output_x, output_y, track_x, track_y); state = event->xmotion.state; if( event->type == MotionNotify ) { @@ -571,6 +557,10 @@ int SketcherWindow::grab_button_press(XEvent *event) int ci = config.cv_selected; if( ci < 0 || ci >= plugin->config.curves.size() ) return 0; + MWindow *mwindow = plugin->server->mwindow; + CWindowGUI *cwindow_gui = mwindow->cwindow->gui; + CWindowCanvas *canvas = cwindow_gui->canvas; + SketcherCurves &curves = config.curves; SketcherCurve *cv = curves[ci]; SketcherPoints &points = cv->points; @@ -583,20 +573,22 @@ int SketcherWindow::grab_button_press(XEvent *event) ++new_points; pi = plugin->new_point(cv, !(state & ControlMask) ? ARC_LINE : ARC_FILL, - output_x, output_y, pi+1); + track_x, track_y, pi+1); point_list->update(pi); break; } SketcherPoint *pt = 0; // select point - double dist = cv->nearest_point(pi, output_x,output_y); + double dist = cv->nearest_point(pi, track_x,track_y); if( dist >= 0 ) { pt = points[pi]; - Track *track = plugin->server->plugin->track; - int track_w = track->track_w, track_h = track->track_h; - float px = (pt->x - track_w / 2) * projector_z + projector_x; - float py = (pt->y - track_h / 2) * projector_z + projector_y; - float pix = DISTANCE(px, py, cursor_x,cursor_y); - if( (state & ControlMask) && pix >= HANDLE_W ) { pi = -1; pt = 0; } + float cx, cy; + plugin->track_to_output(pt->x, pt->y, cx, cy); + canvas->output_to_canvas(mwindow->edl, 0, cx, cy); + cx += canvas->view_x; cy += canvas->view_y; + dist = DISTANCE(cx,cy, cursor_x,cursor_y); + if( (state & ControlMask) && dist >= HANDLE_W ) { + pi = -1; pt = 0; + } } point_list->set_selected(pi); break; } @@ -605,26 +597,28 @@ int SketcherWindow::grab_button_press(XEvent *event) ++new_points; pi = plugin->new_point(cv, !(state & ControlMask) ? ARC_CURVE : ARC_OFF, - output_x, output_y, pi+1); + track_x, track_y, pi+1); point_list->update(pi); break; } - if( (state & AltMask) ) { // create new curve + if( (state & ControlMask) && (state & AltMask) ) { // create new curve ci = plugin->new_curve(cv->pen, cv->width, curve_color->color); curve_list->update(ci); point_list->update(-1); break; } SketcherPoint *pt = 0; - double dist = config.nearest_point(ci, pi, output_x,output_y); + double dist = config.nearest_point(ci, pi, track_x,track_y); if( dist >= 0 ) { pt = curves[ci]->points[pi]; - Track *track = plugin->server->plugin->track; - int track_w = track->track_w, track_h = track->track_h; - float px = (pt->x - track_w / 2) * projector_z + projector_x; - float py = (pt->y - track_h / 2) * projector_z + projector_y; - float pix = DISTANCE(px, py, cursor_x,cursor_y); - if( (state & ControlMask) && pix >= HANDLE_W ) { ci = pi = -1; pt = 0; } + float cx, cy; + plugin->track_to_output(pt->x, pt->y, cx, cy); + canvas->output_to_canvas(mwindow->edl, 0, cx, cy); + cx += canvas->view_x; cy += canvas->view_y; + dist = DISTANCE(cx,cy, cursor_x,cursor_y); + if( (state & ControlMask) && dist >= HANDLE_W ) { + ci = pi = -1; pt = 0; + } } if( pt ) { curve_list->update(ci); @@ -653,31 +647,31 @@ int SketcherWindow::grab_cursor_motion() if( (state & (Button1Mask|Button3Mask)) ) { SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0; if( pt ) { - float dist = DISTANCE(pt->x, pt->y, output_x, output_y); + float dist = DISTANCE(pt->x, pt->y, track_x, track_y); if( dist < get_w()*0.1 ) return 0; // tolerance w/10 } ++new_points; int arc = (state & Button1Mask) ? ARC_LINE : ARC_CURVE; - pi = plugin->new_point(cv, arc, output_x, output_y, pi+1); + pi = plugin->new_point(cv, arc, track_x, track_y, pi+1); point_list->update(pi); } return 1; } if( (state & Button1Mask) ) { - if( (state & ControlMask) ) { // drag selected point + if( (state & ControlMask) && !(state & AltMask) ) { // drag selected point SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0; if( pt ) { - point_list->set_point(pi, PT_X, pt->x = output_x); - point_list->set_point(pi, PT_Y, pt->y = output_y); + point_list->set_point(pi, PT_X, pt->x = track_x); + point_list->set_point(pi, PT_Y, pt->y = track_y); point_list->update_list(pi); point_x->update(pt->x); point_y->update(pt->y); } return 1; } - if( (state & AltMask) ) { // drag all curves - int dx = round(output_x - last_x); - int dy = round(output_y - last_y); + if( (state & ControlMask) && (state & AltMask) ) { // drag all curves + int dx = round(track_x - last_x); + int dy = round(track_y - last_y); for( int i=0; iconfig.curves[i]; int pts = crv->points.size(); @@ -694,15 +688,15 @@ int SketcherWindow::grab_cursor_motion() point_list->update(pi); return 1; } - double dist = cv->nearest_point(pi, output_x,output_y); + double dist = cv->nearest_point(pi, track_x,track_y); if( dist >= 0 ) point_list->set_selected(pi); return 1; } if( (state & Button3Mask) ) { if( (state & (ControlMask | AltMask)) ) { // drag selected curve(s) - int dx = round(output_x - last_x); - int dy = round(output_y - last_y); + int dx = round(track_x - last_x); + int dy = round(track_y - last_y); for( int i=0; ix += dx; pt->y += dy; @@ -715,7 +709,7 @@ int SketcherWindow::grab_cursor_motion() point_list->update(pi); return 1; } - double dist = config.nearest_point(ci, pi, output_x,output_y); + double dist = config.nearest_point(ci, pi, track_x,track_y); if( dist >= 0 ) { curve_list->update(ci); point_list->update(pi); @@ -738,15 +732,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() { @@ -776,6 +770,7 @@ int SketcherCurveList::handle_event() int SketcherCurveList::selection_changed() { + gui->curve_color->close_picker(); handle_event(); return 1; } @@ -835,7 +830,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(64), _("New")) { this->gui = gui; this->plugin = plugin; @@ -861,7 +856,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(64), C_("Del")) { this->gui = gui; this->plugin = plugin; @@ -972,7 +967,7 @@ int SketcherPointTypeItem::handle_event() } SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc) - : BC_PopupMenu(x,y,64,_(pt_type[arc])) + : BC_PopupMenu(x,y,xS(100),_(pt_type[arc])) { this->gui = gui; this->type = arc; @@ -989,14 +984,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() @@ -1217,7 +1212,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(64), _("New")) { this->gui = gui; this->plugin = plugin; @@ -1236,7 +1231,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(64), C_("Del")) { this->gui = gui; this->plugin = plugin;