3 * Copyright (C) 2014 Adam Williams <broadcast at earthling dot net>
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.
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.
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
21 #include "automation.h"
22 #include "bcdisplayinfo.h"
25 #include "sketcherwindow.h"
28 #include "cwindowgui.h"
30 #include "edlsession.h"
33 #include "mainerror.h"
36 #include "pluginserver.h"
40 #define AltMask Mod1Mask
45 const char *SketcherPoint::types[] = {
51 const char *SketcherCurve::pens[] = {
60 SketcherCurvePenItem::SketcherCurvePenItem(int pen)
61 : BC_MenuItem(_(SketcherCurve::pens[pen]))
65 int SketcherCurvePenItem::handle_event()
67 SketcherCurvePen *popup = (SketcherCurvePen*)get_popup_menu();
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];
75 gui->curve_list->update(ci);
76 gui->send_configure_change();
81 SketcherCurvePen::SketcherCurvePen(SketcherWindow *gui, int x, int y, int pen)
82 : BC_PopupMenu(x,y,72,_(cv_pen[pen]))
86 void SketcherCurvePen::create_objects()
88 int n = sizeof(cv_pen)/sizeof(cv_pen[0]);
89 for( int pen=0; pen<n; ++pen )
90 add_item(new SketcherCurvePenItem(pen));
92 void SketcherCurvePen::update(int pen)
94 set_text(_(cv_pen[pen]));
98 SketcherCurveColor::SketcherCurveColor(SketcherWindow *gui, int x, int y, int w, int h)
99 : BC_Button(x, y, w, vframes)
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();
109 SketcherCurveColor::~SketcherCurveColor()
111 for( int i=0; i<3; ++i )
115 void SketcherCurveColor::set_color(int 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;
130 if( (rr+=48) > 0xff ) rr = 0xff;
131 if( (gg+=48) > 0xff ) gg = 0xff;
132 if( (bb+=48) > 0xff ) bb = 0xff;
135 if( (rr-=48) < 0x00 ) rr = 0x00;
136 if( (gg-=48) < 0x00 ) gg = 0x00;
137 if( (bb-=48) < 0x00 ) bb = 0x00;
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;
150 void SketcherCurveColor::update_gui(int color)
156 int SketcherCurveColor::handle_event()
158 gui->start_color_thread(this);
162 SketcherCurveColorPicker::SketcherCurveColorPicker(SketcherWindow *gui, SketcherCurveColor *color_button)
163 : ColorPicker(1, _("Color"))
166 this->color_button = color_button;
168 color_update = new SketcherCurveColorThread(this);
171 SketcherCurveColorPicker::~SketcherCurveColorPicker()
176 void SketcherCurveColorPicker::start(int color)
178 start_window(color & 0xffffff, ((~color>>24)&0xff), 1);
179 color_update->start();
182 void SketcherCurveColorPicker::handle_done_event(int result)
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];
194 gui->curve_list->update(ci);
195 gui->send_configure_change();
199 int SketcherCurveColorPicker::handle_new_color(int color, int alpha)
201 this->color = color | (~alpha<<24);
202 color_update->update_lock->unlock();
206 void SketcherCurveColorPicker::update_gui()
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;
213 SketcherCurve *cv = config.curves[ci];
215 gui->curve_list->update(ci);
216 gui->send_configure_change();
218 gui->unlock_window();
221 SketcherCurveColorThread::SketcherCurveColorThread(SketcherCurveColorPicker *color_picker)
224 this->color_picker = color_picker;
225 this->update_lock = new Condition(0,"SketcherCurveColorThread::update_lock");
229 SketcherCurveColorThread::~SketcherCurveColorThread()
235 void SketcherCurveColorThread::start()
243 void SketcherCurveColorThread::stop()
247 update_lock->unlock();
252 void SketcherCurveColorThread::run()
255 update_lock->lock("SketcherCurveColorThread::run");
257 color_picker->update_gui();
262 SketcherNum::SketcherNum(SketcherWindow *gui, int x, int y, int output,
264 : BC_TumbleTextBox(gui, output, mn, mx, x, y, 64)
270 SketcherNum::~SketcherNum()
274 int SketcherPointX::handle_event()
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());
287 point_list->set_point(pi, PT_X, v);
288 point_list->update_list(pi);
289 gui->send_configure_change();
294 int SketcherPointY::handle_event()
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());
307 point_list->set_point(pi, PT_Y, v);
308 point_list->update_list(pi);
309 gui->send_configure_change();
315 int SketcherCurveRadius::handle_event()
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());
324 gui->curve_list->update(ci);
325 gui->send_configure_change();
331 SketcherWindow::SketcherWindow(Sketcher *plugin)
332 : PluginClientWindow(plugin, 380, 580, 380, 580, 0)
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;
349 SketcherWindow::~SketcherWindow()
357 void SketcherWindow::create_objects()
359 int x = 10, y = 10, dy = 0, x1, y1;
360 int margin = plugin->get_theme()->widget_border;
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];
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;
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;
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;
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);
417 bar = new BC_Bar(x, y, get_w()-2*x);
418 add_subwindow(bar); dy = bmax(dy,bar->get_h());
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;
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;
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;
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;
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);
477 add_subwindow(notes0 = new BC_Title(x, y,
484 add_subwindow(notes1 = new BC_Title(x+80, y,
490 "deletes point\n")));
491 add_subwindow(notes2 = new BC_Title(x+200, y,
497 "deletes curve\n")));
501 void SketcherWindow::send_configure_change()
504 plugin->send_configure_change();
507 int SketcherWindow::grab_event(XEvent *event)
509 int ret = do_grab_event(event);
510 if( pending_config && !grab_event_count() )
511 send_configure_change();
515 int SketcherWindow::do_grab_event(XEvent *event)
517 switch( event->type ) {
518 case ButtonPress: break;
519 case ButtonRelease: break;
520 case MotionNotify: break;
522 if( keysym_lookup(event) > 0 ) {
523 switch( get_keysym() ) {
526 return (event->xkey.state & ShiftMask) ?
527 del_curve->handle_event() :
528 del_point->handle_event() ;
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;
543 if( cx < 0 || cx >= mwindow->theme->ccanvas_w ||
544 cy < 0 || cy >= mwindow->theme->ccanvas_h )
548 switch( event->type ) {
550 if( dragging ) return 0;
557 if( !dragging ) return 0;
563 SketcherConfig &config = plugin->config;
564 int ci = config.cv_selected;
565 if( ci < 0 || ci >= plugin->config.curves.size() )
568 SketcherCurves &curves = config.curves;
569 SketcherCurve *cv = curves[ci];
570 SketcherPoints &points = cv->points;
571 int pi = config.pt_selected;
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;
588 switch( event->type ) {
590 int button_no = event->xbutton.button;
591 switch( button_no ) {
593 if( (state & ShiftMask) ) { // create new point/string
595 pi = plugin->new_point(cv, PTY_LINE, output_x, output_y, pi+1);
596 point_list->update(pi);
599 SketcherPoint *pt = 0; // select point
600 double dist = cv->nearest_point(pi, output_x,output_y);
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; }
608 point_list->set_selected(pi);
611 if( (state & ShiftMask) ) { // create new curve point
613 pi = plugin->new_point(cv, PTY_CURVE,
614 output_x, output_y, pi+1);
615 point_list->update(pi);
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);
624 SketcherPoint *pt = 0;
625 double dist = config.nearest_point(ci, pi, output_x,output_y);
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; }
634 curve_list->update(ci);
635 point_list->update(pi);
641 if( (state & ShiftMask) ) { // string of points
642 if( (state & (Button1Mask|Button3Mask)) ) {
643 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
645 float dist = DISTANCE(pt->x, pt->y, output_x, output_y);
646 if( dist < get_w()*0.1 ) break; // tolerance w/10
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);
655 if( (state & Button1Mask) ) {
656 if( (state & ControlMask) ) { // drag selected point
657 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
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);
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;
678 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
680 point_x->update(pt ? pt->x : 0.f);
681 point_y->update(pt ? pt->y : 0.f);
682 point_list->update(pi);
685 double dist = cv->nearest_point(pi, output_x,output_y);
687 point_list->set_selected(pi);
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;
698 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
700 point_x->update(pt ? pt->x : 0.f);
701 point_y->update(pt ? pt->y : 0.f);
702 point_list->update(pi);
705 double dist = config.nearest_point(ci, pi, output_x,output_y);
707 curve_list->update(ci);
708 point_list->update(pi);
713 case ButtonRelease: {
718 last_x = output_x; last_y = output_y;
723 int SketcherWindow::keypress_event()
725 int key = get_keypress();
727 case DELETE: return shift_down() ?
728 del_curve->handle_event() :
729 del_point->handle_event() ;
734 void SketcherWindow::done_event(int result)
736 ungrab(client->server->mwindow->cwindow->gui);
739 void SketcherWindow::start_color_thread(SketcherCurveColor *color_button)
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];
749 color_picker->start(color);
750 lock_window("SketcherWindow::start_color_thread");
754 SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
755 : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
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;
764 SketcherCurveList::~SketcherCurveList()
768 void SketcherCurveList::clear()
770 for( int i=CV_SZ; --i>=0; )
771 cols[i].remove_all_objects();
774 int SketcherCurveList::column_resize_event()
776 for( int i=CV_SZ; --i>=0; )
777 widths[i] = get_column_width(i);
781 int SketcherCurveList::handle_event()
783 int ci = get_selection_number(0, 0);
785 gui->point_list->update(0);
786 gui->send_configure_change();
790 int SketcherCurveList::selection_changed()
796 void SketcherCurveList::set_curve(int i, int c, const char *cp)
798 cols[c].get(i)->set_text(cp);
801 void SketcherCurveList::set_selected(int k)
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);
811 plugin->config.cv_selected = ci;
815 void SketcherCurveList::update_list(int k)
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);
823 void SketcherCurveList::update(int k)
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);
841 void SketcherCurveList::add_curve(const char *id, const char *pen,
842 const char *radius, const char *color)
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));
850 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
851 : BC_GenericButton(x, y, 64, _("New"))
854 this->plugin = plugin;
856 SketcherNewCurve::~SketcherNewCurve()
859 int SketcherNewCurve::handle_event()
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;
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();
874 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
875 : BC_GenericButton(x, y, 64, C_("Del"))
878 this->plugin = plugin;
880 SketcherDelCurve::~SketcherDelCurve()
883 int SketcherDelCurve::handle_event()
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--);
892 ci = plugin->new_curve();
893 gui->curve_list->update(ci);
894 gui->point_list->update(-1);
895 gui->send_configure_change();
900 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
901 : BC_GenericButton(x, y, _("Up"))
905 SketcherCurveUp::~SketcherCurveUp()
909 int SketcherCurveUp::handle_event()
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);
920 gui->send_configure_change();
924 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
925 : BC_GenericButton(x, y, _("Dn"))
929 SketcherCurveDn::~SketcherCurveDn()
933 int SketcherCurveDn::handle_event()
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);
944 gui->send_configure_change();
949 SketcherPointTypeItem::SketcherPointTypeItem(int pty)
950 : BC_MenuItem(_(pt_type[pty]))
954 int SketcherPointTypeItem::handle_event()
956 SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
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() )
964 SketcherCurve *cv = curves[ci];
965 SketcherPoints &points = cv->points;
966 int pi = config.pt_selected;
968 ArrayList<int> selected;
969 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
972 for( int i=selected.size(); --i>=0; ) {
974 if( k < 0 || k >= points.size() ) continue;
975 SketcherPoint *pt = cv->points[k];
977 gui->point_list->set_point(k, PT_TY, _(pt_type[pty]));
980 gui->point_list->update_list(pi);
981 gui->send_configure_change();
985 SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int pty)
986 : BC_PopupMenu(x,y,64,_(pt_type[pty]))
990 void SketcherPointType::create_objects()
992 for( int pty=0; pty<PT_SZ; ++pty )
993 add_item(new SketcherPointTypeItem(pty));
995 void SketcherPointType::update(int pty)
997 set_text(_(pt_type[pty]));
1001 SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1002 : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
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);
1012 SketcherPointList::~SketcherPointList()
1016 void SketcherPointList::clear()
1018 for( int i=PT_SZ; --i>=0; )
1019 cols[i].remove_all_objects();
1022 int SketcherPointList::column_resize_event()
1024 for( int i=PT_SZ; --i>=0; )
1025 widths[i] = get_column_width(i);
1029 int SketcherPointList::handle_event()
1031 int pi = get_selection_number(0, 0);
1032 if( get_selection_number(0, 1) >= 0 ) pi = -1;
1034 gui->send_configure_change();
1038 int SketcherPointList::selection_changed()
1044 void SketcherPointList::add_point(const char *id, const char *ty, const char *xp, const char *yp)
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));
1052 void SketcherPointList::set_point(int i, int c, int v)
1054 char stxt[BCSTRLEN];
1055 sprintf(stxt,"%d",v);
1056 set_point(i,c,stxt);
1058 void SketcherPointList::set_point(int i, int c, const char *cp)
1060 cols[c].get(i)->set_text(cp);
1063 void SketcherPointList::set_selected(int k)
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;
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;
1077 void SketcherPointList::update_list(int k)
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);
1084 void SketcherPointList::update(int k)
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;
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);
1104 void SketcherWindow::update_gui()
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);
1122 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
1123 : BC_GenericButton(x, y, _("Up"))
1127 SketcherPointUp::~SketcherPointUp()
1131 int SketcherPointUp::handle_event()
1133 SketcherConfig &config = gui->plugin->config;
1134 int ci = config.cv_selected;
1135 if( ci < 0 || ci >= config.curves.size() )
1137 SketcherCurve *cv = config.curves[ci];
1138 SketcherPoints &points = cv->points;
1139 if( points.size() < 2 )
1141 int pi = config.pt_selected;
1143 ArrayList<int> selected;
1144 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1147 for( int i=0; i<selected.size(); ++i ) {
1148 int k = selected[i];
1149 if( k <= 0 ) continue;
1151 SketcherPoint *&pt0 = points[k];
1152 SketcherPoint *&pt1 = points[--k];
1153 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1155 gui->point_list->update(pi);
1156 gui->send_configure_change();
1160 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
1161 : BC_GenericButton(x, y, _("Dn"))
1165 SketcherPointDn::~SketcherPointDn()
1169 int SketcherPointDn::handle_event()
1171 SketcherConfig &config = gui->plugin->config;
1172 int ci = config.cv_selected;
1173 if( ci < 0 || ci >= config.curves.size() )
1175 SketcherCurve *cv = config.curves[ci];
1176 SketcherPoints &points = cv->points;
1177 int sz1 = points.size()-1;
1180 int pi = config.pt_selected;
1182 ArrayList<int> selected;
1183 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1186 for( int i=selected.size(); --i>=0; ) {
1187 int k = selected[i];
1188 if( k >= sz1 ) continue;
1190 SketcherPoint *&pt0 = points[k];
1191 SketcherPoint *&pt1 = points[++k];
1192 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1194 gui->point_list->update(pi);
1195 gui->send_configure_change();
1199 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
1200 : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
1204 int SketcherDrag::handle_event()
1206 CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
1207 int value = get_value();
1209 if( !gui->grab(cwindow_gui) ) {
1215 gui->ungrab(cwindow_gui);
1216 gui->plugin->config.drag = value;
1217 gui->send_configure_change();
1221 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1222 : BC_GenericButton(x, y, 64, _("New"))
1225 this->plugin = plugin;
1227 SketcherNewPoint::~SketcherNewPoint()
1230 int SketcherNewPoint::handle_event()
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();
1239 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1240 : BC_GenericButton(x, y, 64, C_("Del"))
1243 this->plugin = plugin;
1245 SketcherDelPoint::~SketcherDelPoint()
1248 int SketcherDelPoint::handle_event()
1250 SketcherConfig &config = gui->plugin->config;
1251 SketcherCurves &curves = config.curves;
1252 int ci = config.cv_selected;
1253 if( ci < 0 || ci >= curves.size() )
1255 SketcherCurve *cv = curves[ci];
1256 SketcherPoints &points = cv->points;
1257 int pi = config.pt_selected;
1259 ArrayList<int> selected;
1260 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
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;
1269 gui->point_list->update(pi);
1270 gui->send_configure_change();
1274 SketcherResetCurves::SketcherResetCurves(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1275 : BC_GenericButton(x, y, _("Reset"))
1278 this->plugin = plugin;
1280 SketcherResetCurves::~SketcherResetCurves()
1283 int SketcherResetCurves::handle_event()
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();
1294 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1295 : BC_GenericButton(x, y, _("Reset"))
1298 this->plugin = plugin;
1300 SketcherResetPoints::~SketcherResetPoints()
1303 int SketcherResetPoints::handle_event()
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();