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,100,_(cv_pen[pen]))
87 void SketcherCurvePen::create_objects()
89 int n = sizeof(cv_pen)/sizeof(cv_pen[0]);
90 for( int pen=0; pen<n; ++pen )
91 add_item(new SketcherCurvePenItem(pen));
93 void SketcherCurvePen::update(int pen)
95 set_text(_(cv_pen[this->pen=pen]));
99 SketcherCurveColor::SketcherCurveColor(SketcherWindow *gui,
100 int x, int y, int w, int h, int color, int alpha)
101 : ColorBoxButton(_("Curve Color"), x, y, w, h, color, alpha, 1)
104 this->color = CV_COLOR;
107 SketcherCurveColor::~SketcherCurveColor()
111 void SketcherCurveColor::handle_done_event(int result)
113 if( result ) color = orig_color | (~orig_alpha<<24);
114 SketcherConfig &config = gui->plugin->config;
115 int ci = config.cv_selected;
116 if( ci >= 0 && ci < config.curves.size() ) {
117 SketcherCurve *cv = config.curves[ci];
119 gui->lock_window("SketcherCurveColor::handle_done_event");
120 gui->curve_list->update(ci);
121 gui->unlock_window();
122 gui->send_configure_change();
126 int SketcherCurveColor::handle_new_color(int color, int alpha)
128 color |= ~alpha<<24; this->color = color;
129 gui->lock_window("SketcherCurveColor::update_gui");
131 SketcherConfig &config = gui->plugin->config;
132 int ci = config.cv_selected;
134 SketcherCurve *cv = config.curves[ci];
136 gui->curve_list->update(ci);
137 gui->send_configure_change();
139 gui->unlock_window();
144 SketcherCoord::SketcherCoord(SketcherWindow *gui, int x, int y,
145 coord output, coord mn, coord mx)
146 : BC_TumbleTextBox(gui, output, mn, mx, x, y, 64, 1)
151 SketcherCoord::~SketcherCoord()
155 SketcherNum::SketcherNum(SketcherWindow *gui, int x, int y,
156 int output, int mn, int mx)
157 : BC_TumbleTextBox(gui, output, mn, mx, x, y, 54)
162 SketcherNum::~SketcherNum()
166 int SketcherPointX::handle_event()
168 if( !SketcherCoord::handle_event() ) return 0;
169 SketcherConfig &config = gui->plugin->config;
170 int ci = config.cv_selected;
171 if( ci >= 0 && ci < config.curves.size() ) {
172 SketcherCurve *cv = config.curves[ci];
173 SketcherPointList *point_list = gui->point_list;
174 int pi = config.pt_selected;
175 SketcherPoints &points = cv->points;
176 if( pi >= 0 && pi < points.size() ) {
177 coord v = atof(get_text());
179 point_list->set_point(pi, PT_X, v);
180 point_list->update_list(pi);
181 gui->send_configure_change();
186 int SketcherPointY::handle_event()
188 if( !SketcherCoord::handle_event() ) return 0;
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 SketcherPointList *point_list = gui->point_list;
194 int pi = config.pt_selected;
195 SketcherPoints &points = cv->points;
196 if( pi >= 0 && pi < points.size() ) {
197 coord v = atof(get_text());
199 point_list->set_point(pi, PT_Y, v);
200 point_list->update_list(pi);
201 gui->send_configure_change();
207 int SketcherPointId::handle_event()
209 if( !SketcherNum::handle_event() ) return 0;
210 SketcherConfig &config = gui->plugin->config;
211 int ci = config.cv_selected;
212 if( ci >= 0 && ci < config.curves.size() ) {
213 SketcherCurve *cv = config.curves[ci];
214 SketcherPointList *point_list = gui->point_list;
215 int pi = config.pt_selected;
216 SketcherPoints &points = cv->points;
217 if( pi >= 0 && pi < points.size() ) {
218 int id = atoi(get_text());
220 point_list->set_point(pi, PT_ID, id);
221 point_list->update_list(pi);
222 gui->send_configure_change();
228 SketcherCurveWidth::SketcherCurveWidth(SketcherWindow *gui, int x, int y, int width)
229 : SketcherNum(gui, x, y, width, 0, 255)
233 SketcherCurveWidth::~SketcherCurveWidth()
237 int SketcherCurveWidth::handle_event()
239 if( !SketcherNum::handle_event() ) return 0;
240 SketcherConfig &config = gui->plugin->config;
241 int ci = config.cv_selected;
242 if( ci >= 0 && ci < config.curves.size() ) {
243 SketcherCurve *cv = config.curves[ci];
244 int v = atoi(get_text());
246 gui->curve_list->update(ci);
247 gui->send_configure_change();
252 void SketcherCurveWidth::update(int width)
254 SketcherNum::update(this->width=width);
258 SketcherWindow::SketcherWindow(Sketcher *plugin)
259 : PluginClientWindow(plugin, 380, 620, 380, 620, 0)
261 this->plugin = plugin;
262 this->title_pen = 0; this->curve_pen = 0;
263 this->title_color = 0; this->curve_color = 0;
265 this->new_curve = 0; this->del_curve = 0;
266 this->curve_up = 0; this->curve_dn = 0;
267 this->title_x = 0; this->point_x = 0;
268 this->title_y = 0; this->point_y = 0;
269 this->title_id = 0; this->point_id = 0;
270 this->new_point = 0; this->del_point = 0;
271 this->point_up = 0; this->point_dn = 0;
272 this->point_list = 0; this->notes0 = 0;
273 this->notes1 = 0; this->notes2 = 0;
276 track_w = track_h -1;
277 output_x = output_y = -1;
278 track_x = track_y = -1;
279 last_x = last_y = -1;
280 projector_x = projector_y = projector_z = -1;
281 state = 0; dragging = 0;
287 SketcherWindow::~SketcherWindow()
294 void SketcherWindow::create_objects()
296 int x = 10, y = 10, dy = 0, x1, y1;
297 int margin = plugin->get_theme()->widget_border;
299 int ci = plugin->config.cv_selected;
300 if( ci < 0 || ci >= plugin->config.curves.size() )
301 ci = plugin->new_curve();
302 SketcherCurve *cv = plugin->config.curves[ci];
304 reset_curves = new SketcherResetCurves(this, plugin, x1=x, y+3);
305 add_subwindow(reset_curves); dy = bmax(dy,reset_curves->get_h());
306 x1 += reset_curves->get_w() + 2*margin;
307 const char *curve_text = _("Curve");
308 title_width = new BC_Title(x1, y, _("Width:"));
309 add_subwindow(title_width); dy = bmax(dy,title_width->get_h());
310 x1 += title_width->get_w() + margin;
311 curve_width = new SketcherCurveWidth(this, x1, y, cv->width);
312 curve_width->create_objects();
313 y += dy + 2*margin; dy = 0;
315 x1 = get_w()-x - BC_Title::calculate_w(this, curve_text, LARGEFONT);
316 y1 = y-margin - BC_Title::calculate_h(this, curve_text, LARGEFONT);
317 title = new BC_Title(x1, y1, curve_text, LARGEFONT,
318 get_resources()->menu_highlighted_fontcolor);
319 add_subwindow(title); dy = bmax(dy,title->get_h());
320 curve_list = new SketcherCurveList(this, plugin, x, y);
321 add_subwindow(curve_list); dy = bmax(dy,curve_list->get_h());
322 y += dy + margin; dy = 0;
324 new_curve = new SketcherNewCurve(this, plugin, x1=x, y);
325 add_subwindow(new_curve); dy = bmax(dy,new_curve->get_h());
326 x1 += new_curve->get_w() + margin;
327 curve_up = new SketcherCurveUp(this, x1, y);
328 add_subwindow(curve_up); dy = bmax(dy,curve_up->get_h());
329 x1 += curve_up->get_w() + 4*margin;
330 y1 = BC_Title::calculate_h(this, _("Pen:"));
331 title_pen = new BC_Title(x1+30, y+dy-y1, _("Pen:"));
332 add_subwindow(title_pen); dy = bmax(dy,title_pen->get_h());
333 int x2 = (get_w()+x1)/2 + 20;
334 y1 = BC_Title::calculate_h(this, _("Color:"));
335 title_color = new BC_Title(x2, y+dy-y1, _("Color:"));
336 add_subwindow(title_color); dy = bmax(dy,title_color->get_h());
337 y += dy + margin; dy = 0;
339 del_curve = new SketcherDelCurve(this, plugin, x1=x, y);
340 add_subwindow(del_curve); dy = bmax(dy,del_curve->get_h());
341 x1 += del_curve->get_w() + margin;
342 curve_dn = new SketcherCurveDn(this, x1, y);
343 add_subwindow(curve_dn); dy = bmax(dy,curve_dn->get_h());
344 x1 += curve_dn->get_w() + 4*margin;
345 curve_pen = new SketcherCurvePen(this, x1, y, cv->pen);
346 add_subwindow(curve_pen); dy = bmax(dy,curve_pen->get_h());
347 curve_pen->create_objects();
348 curve_color = new SketcherCurveColor(this, x2, y, COLOR_W, COLOR_H,
349 cv->color&0xffffff, (~cv->color>>24)&0xff);
350 add_subwindow(curve_color); dy = bmax(dy,curve_color->get_h());
351 y += dy + margin; dy = 0;
352 curve_list->update(ci);
355 bar = new BC_Bar(x, y, get_w()-2*x);
356 add_subwindow(bar); dy = bmax(dy,bar->get_h());
357 bar = new BC_Bar(x, y+=dy, get_w()-2*x);
358 add_subwindow(bar); dy = bmax(dy,bar->get_h());
361 int pi = plugin->config.pt_selected;
362 SketcherPoint *pt = pi >= 0 && pi < cv->points.size() ? cv->points[pi] : 0;
363 reset_points = new SketcherResetPoints(this, plugin, x1=x, y+3);
364 add_subwindow(reset_points); dy = bmax(dy,reset_points->get_h());
365 x1 += reset_points->get_w() + 2*margin;
366 if( plugin->config.drag ) {
367 if( !grab(plugin->server->mwindow->cwindow->gui) ) {
368 eprintf("drag enabled, but compositor already grabbed\n");
369 plugin->config.drag = 0;
372 drag = new SketcherDrag(this, x1, y);
373 add_subwindow(drag); dy = bmax(dy,drag->get_h());
374 x1 += drag->get_w() + 2*margin;
375 int arc = pt ? pt->arc : ARC_LINE;
376 point_type = new SketcherPointType(this, x1, y, arc);
377 add_subwindow(point_type); dy = bmax(dy,point_type->get_h());
378 point_type->create_objects();
379 y += dy + margin; dy = 0;
381 const char *point_text = _("Point");
382 x1 = get_w()-x - BC_Title::calculate_w(this, point_text, LARGEFONT);
383 y1 = y-margin - BC_Title::calculate_h(this, point_text, LARGEFONT);
384 add_subwindow(title = new BC_Title(x1, y1, point_text, LARGEFONT,
385 get_resources()->menu_highlighted_fontcolor));
386 point_list = new SketcherPointList(this, plugin, x, y);
387 add_subwindow(point_list); dy = bmax(dy,point_list->get_h());
388 y += dy + margin; dy = 0;
390 new_point = new SketcherNewPoint(this, plugin, x1=x, y);
391 add_subwindow(new_point); dy = bmax(dy,new_point->get_h());
392 x1 += new_point->get_w() + margin;
393 point_up = new SketcherPointUp(this, x1, y);
394 add_subwindow(point_up); dy = bmax(dy,point_up->get_h());
395 x1 += point_up->get_w() + 2*margin;
396 title_x = new BC_Title(x1, y, _("X:"));
397 add_subwindow(title_x); dy = bmax(dy,title_x->get_h());
398 x1 += title_x->get_w() + margin;
399 point_x = new SketcherPointX(this, x1, y, !pt ? 0.f : pt->x);
400 point_x->create_objects(); dy = bmax(dy, point_x->get_h());
401 x2 = x1 + point_x->get_w() + 2*margin + 10;
402 y1 = BC_Title::calculate_h(this, _("ID:"));
403 title_id = new BC_Title(x2+16, y+dy-y1, _("ID:"));
404 add_subwindow(title_id); dy = bmax(dy, title_id->get_h());
405 y += dy + margin; dy = 0;
407 del_point = new SketcherDelPoint(this, plugin, x1=x, y);
408 add_subwindow(del_point); dy = bmax(dy,del_point->get_h());
409 x1 += del_point->get_w() + margin;
410 point_dn = new SketcherPointDn(this, x1, y);
411 add_subwindow(point_dn); dy = bmax(dy,point_dn->get_h());
412 x1 += point_dn->get_w() + 2*margin;
413 title_y = new BC_Title(x1, y, _("Y:"));
414 add_subwindow(title_y); dy = bmax(dy,title_y->get_h());
415 x1 += title_y->get_w() + margin;
416 point_y = new SketcherPointY(this, x1, y, !pt ? 0.f : pt->y);
417 point_y->create_objects(); dy = bmax(dy, point_y->get_h());
418 point_id = new SketcherPointId(this, x2, y, !pt ? 0 : pt->id);
419 point_id->create_objects(); dy = bmax(dy, point_id->get_h());
420 y += dy + margin + 5; dy = 0;
421 point_list->update(pi);
423 bar = new BC_Bar(x, y, get_w()-2*x);
424 add_subwindow(bar); dy = bmax(dy,bar->get_h());
427 add_subwindow(notes0 = new BC_Title(x, y,
433 "Ctrl+Shift="))); dy = bmax(dy, notes0->get_h());
434 add_subwindow(notes1 = new BC_Title(x+100, y,
440 "new fill point"))); dy = bmax(dy, notes1->get_h());
441 add_subwindow(notes2 = new BC_Title(x+220, y,
447 "new off point"))); dy = bmax(dy, notes2->get_h());
448 y += dy + margin + 10;
450 add_subwindow(notes3 = new BC_Title(x, y,
451 "Key DEL= delete point, +Shift= delete curve\n"));
455 void SketcherWindow::done_event(int result)
457 curve_color->close_picker();
458 ungrab(plugin->server->mwindow->cwindow->gui);
461 void SketcherWindow::send_configure_change()
464 plugin->send_configure_change();
468 int SketcherWindow::grab_event(XEvent *event)
470 int ret = do_grab_event(event);
471 if( !grab_event_count() ) {
472 if( grab_cursor_motion() )
474 if( pending_config ) {
475 last_x = track_x; last_y = track_y;
476 send_configure_change();
482 int SketcherWindow::do_grab_event(XEvent *event)
484 switch( event->type ) {
485 case ButtonPress: break;
486 case ButtonRelease: break;
487 case MotionNotify: break;
489 if( keysym_lookup(event) > 0 ) {
490 switch( get_keysym() ) {
493 return (event->xkey.state & ShiftMask) ?
494 del_curve->handle_event() :
495 del_point->handle_event() ;
502 MWindow *mwindow = plugin->server->mwindow;
503 CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
504 CWindowCanvas *canvas = cwindow_gui->canvas;
505 cwindow_gui->get_relative_cursor(cursor_x, cursor_y);
506 output_x = cursor_x - canvas->view_x;
507 output_y = cursor_y - canvas->view_y;
510 if( output_x < 0 || output_x >= canvas->view_w ||
511 output_y < 0 || output_y >= canvas->view_h )
516 switch( event->type ) {
518 if( dragging ) return 0;
525 if( dragging ) break;
526 default: // fall thru
530 canvas->canvas_to_output(mwindow->edl, 0, output_x, output_y);
531 plugin->output_to_track(output_x, output_y, track_x, track_y);
532 state = event->xmotion.state;
534 if( event->type == MotionNotify ) {
535 memcpy(&motion_event, event, sizeof(motion_event));
539 if( grab_cursor_motion() )
542 switch( event->type ) {
544 pending_config = grab_button_press(event);
554 int SketcherWindow::grab_button_press(XEvent *event)
556 SketcherConfig &config = plugin->config;
557 int ci = config.cv_selected;
558 if( ci < 0 || ci >= plugin->config.curves.size() )
560 MWindow *mwindow = plugin->server->mwindow;
561 CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
562 CWindowCanvas *canvas = cwindow_gui->canvas;
564 SketcherCurves &curves = config.curves;
565 SketcherCurve *cv = curves[ci];
566 SketcherPoints &points = cv->points;
567 int pi = config.pt_selected;
569 int button_no = event->xbutton.button;
570 switch( button_no ) {
572 if( (state & ShiftMask) ) { // create new point/string
574 pi = plugin->new_point(cv,
575 !(state & ControlMask) ? ARC_LINE : ARC_FILL,
576 track_x, track_y, pi+1);
577 point_list->update(pi);
580 SketcherPoint *pt = 0; // select point
581 double dist = cv->nearest_point(pi, track_x,track_y);
585 plugin->track_to_output(pt->x, pt->y, cx, cy);
586 canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
587 cx += canvas->view_x; cy += canvas->view_y;
588 dist = DISTANCE(cx,cy, cursor_x,cursor_y);
589 if( (state & ControlMask) && dist >= HANDLE_W ) {
593 point_list->set_selected(pi);
596 if( (state & ShiftMask) ) { // create new curve point
598 pi = plugin->new_point(cv,
599 !(state & ControlMask) ? ARC_CURVE : ARC_OFF,
600 track_x, track_y, pi+1);
601 point_list->update(pi);
604 if( (state & ControlMask) && (state & AltMask) ) { // create new curve
605 ci = plugin->new_curve(cv->pen, cv->width, curve_color->color);
606 curve_list->update(ci);
607 point_list->update(-1);
610 SketcherPoint *pt = 0;
611 double dist = config.nearest_point(ci, pi, track_x,track_y);
613 pt = curves[ci]->points[pi];
615 plugin->track_to_output(pt->x, pt->y, cx, cy);
616 canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
617 cx += canvas->view_x; cy += canvas->view_y;
618 dist = DISTANCE(cx,cy, cursor_x,cursor_y);
619 if( (state & ControlMask) && dist >= HANDLE_W ) {
620 ci = pi = -1; pt = 0;
624 curve_list->update(ci);
625 point_list->update(pi);
632 int SketcherWindow::grab_cursor_motion()
634 if( !pending_motion )
637 SketcherConfig &config = plugin->config;
638 int ci = config.cv_selected;
639 if( ci < 0 || ci >= plugin->config.curves.size() )
641 SketcherCurves &curves = config.curves;
642 SketcherCurve *cv = curves[ci];
643 SketcherPoints &points = cv->points;
644 int pi = config.pt_selected;
646 if( (state & ShiftMask) ) { // string of points
647 if( (state & (Button1Mask|Button3Mask)) ) {
648 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
650 float dist = DISTANCE(pt->x, pt->y, track_x, track_y);
651 if( dist < get_w()*0.1 ) return 0; // tolerance w/10
654 int arc = (state & Button1Mask) ? ARC_LINE : ARC_CURVE;
655 pi = plugin->new_point(cv, arc, track_x, track_y, pi+1);
656 point_list->update(pi);
660 if( (state & Button1Mask) ) {
661 if( (state & ControlMask) && !(state & AltMask) ) { // drag selected point
662 SketcherPoint *pt = pi >= 0 && pi < points.size() ? points[pi] : 0;
664 point_list->set_point(pi, PT_X, pt->x = track_x);
665 point_list->set_point(pi, PT_Y, pt->y = track_y);
666 point_list->update_list(pi);
667 point_x->update(pt->x);
668 point_y->update(pt->y);
672 if( (state & ControlMask) && (state & AltMask) ) { // drag all curves
673 int dx = round(track_x - last_x);
674 int dy = round(track_y - last_y);
675 for( int i=0; i<curves.size(); ++i ) {
676 SketcherCurve *crv = plugin->config.curves[i];
677 int pts = crv->points.size();
678 for( int k=0; k<pts; ++k ) {
679 SketcherPoint *pt = crv->points[k];
680 pt->x += dx; pt->y += dy;
683 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
685 point_x->update(pt ? pt->x : 0.f);
686 point_y->update(pt ? pt->y : 0.f);
687 point_id->update(pt ? pt->id : 0);
688 point_list->update(pi);
691 double dist = cv->nearest_point(pi, track_x,track_y);
693 point_list->set_selected(pi);
696 if( (state & Button3Mask) ) {
697 if( (state & (ControlMask | AltMask)) ) { // drag selected curve(s)
698 int dx = round(track_x - last_x);
699 int dy = round(track_y - last_y);
700 for( int i=0; i<points.size(); ++i ) {
701 SketcherPoint *pt = points[i];
702 pt->x += dx; pt->y += dy;
704 SketcherPoint *pt = pi >= 0 && pi < points.size() ?
706 point_x->update(pt ? pt->x : 0.f);
707 point_y->update(pt ? pt->y : 0.f);
708 point_id->update(pt ? pt->id : 0);
709 point_list->update(pi);
712 double dist = config.nearest_point(ci, pi, track_x,track_y);
714 curve_list->update(ci);
715 point_list->update(pi);
722 int SketcherWindow::keypress_event()
724 int key = get_keypress();
726 case DELETE: return shift_down() ?
727 del_curve->handle_event() :
728 del_point->handle_event() ;
734 SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
735 : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
738 this->plugin = plugin;
739 col_titles[CV_ID] = _("ID"); col_widths[CV_ID] = 64;
740 col_titles[CV_RAD] = _("width"); col_widths[CV_RAD] = 64;
741 col_titles[CV_PEN] = _("pen"); col_widths[CV_PEN] = 64;
742 col_titles[CV_CLR] = _("color"); col_widths[CV_CLR] = 80;
743 col_titles[CV_ALP] = _("alpha"); col_widths[CV_ALP] = 64;
745 SketcherCurveList::~SketcherCurveList()
749 void SketcherCurveList::clear()
751 for( int i=CV_SZ; --i>=0; )
752 cols[i].remove_all_objects();
755 int SketcherCurveList::column_resize_event()
757 for( int i=CV_SZ; --i>=0; )
758 col_widths[i] = get_column_width(i);
762 int SketcherCurveList::handle_event()
764 int ci = get_selection_number(0, 0);
766 gui->point_list->update(0);
767 gui->send_configure_change();
771 int SketcherCurveList::selection_changed()
773 gui->curve_color->close_picker();
778 void SketcherCurveList::set_selected(int k)
781 if( k >= 0 && k < plugin->config.curves.size() ) {
782 SketcherCurve *cv = plugin->config.curves[k];
783 gui->curve_width->update(cv->width);
784 gui->curve_pen->update(cv->pen);
785 gui->curve_color->update_gui(cv->color);
788 plugin->config.cv_selected = ci;
792 void SketcherCurveList::update_list(int k)
794 int xpos = get_xposition(), ypos = get_yposition();
795 if( k >= 0 ) update_selection(&cols[0], k);
796 BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],CV_SZ, xpos,ypos,k);
800 void SketcherCurveList::update(int k)
803 SketcherCurves &curves = plugin->config.curves;
804 int sz = curves.size();
805 for( int i=0; i<sz; ++i ) {
806 SketcherCurve *cv = curves[i];
807 char itxt[BCSTRLEN]; sprintf(itxt,"%d", cv->id);
808 char ptxt[BCSTRLEN]; sprintf(ptxt,"%s", cv_pen[cv->pen]);
809 char rtxt[BCSTRLEN]; sprintf(rtxt,"%d", cv->width);
810 int color = cv->color;
811 int r = (color>>16)&0xff;
812 int g = (color>> 8)&0xff;
813 int b = (color>> 0)&0xff;
814 int a = (~color>>24)&0xff;
815 char ctxt[BCSTRLEN]; sprintf(ctxt,"#%02x%02x%02x", r, g, b);
816 char atxt[BCSTRLEN]; sprintf(atxt,"%5.3f", a/255.);
817 add_curve(itxt, ptxt, rtxt, ctxt, atxt);
822 void SketcherCurveList::add_curve(const char *id, const char *pen,
823 const char *width, const char *color, const char *alpha)
825 cols[CV_ID].append(new BC_ListBoxItem(id));
826 cols[CV_RAD].append(new BC_ListBoxItem(width));
827 cols[CV_PEN].append(new BC_ListBoxItem(pen));
828 cols[CV_CLR].append(new BC_ListBoxItem(color));
829 cols[CV_ALP].append(new BC_ListBoxItem(alpha));
832 SketcherNewCurve::SketcherNewCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
833 : BC_GenericButton(x, y, 64, _("New"))
836 this->plugin = plugin;
838 SketcherNewCurve::~SketcherNewCurve()
841 int SketcherNewCurve::handle_event()
843 int pen = gui->curve_pen->pen;
844 int color = gui->curve_color->color;
845 int width = gui->curve_width->width;
846 int ci = plugin->config.cv_selected;
847 if( ci >= 0 && ci < plugin->config.curves.size() ) {
848 SketcherCurve *cv = plugin->config.curves[ci];
849 pen = cv->pen; width = cv->width; color = cv->color;
851 ci = plugin->new_curve(pen, width, color);
852 gui->curve_list->update(ci);
853 gui->point_list->update(-1);
854 gui->send_configure_change();
858 SketcherDelCurve::SketcherDelCurve(SketcherWindow *gui, Sketcher *plugin, int x, int y)
859 : BC_GenericButton(x, y, 64, C_("Del"))
862 this->plugin = plugin;
864 SketcherDelCurve::~SketcherDelCurve()
867 int SketcherDelCurve::handle_event()
869 SketcherConfig &config = plugin->config;
870 int ci = config.cv_selected;
871 SketcherCurves &curves = config.curves;
872 if( ci >= 0 && ci < curves.size() ) {
873 curves.remove_object_number(ci--);
876 ci = plugin->new_curve();
877 gui->curve_list->update(ci);
878 gui->point_list->update(-1);
879 gui->send_configure_change();
884 SketcherCurveUp::SketcherCurveUp(SketcherWindow *gui, int x, int y)
885 : BC_GenericButton(x, y, _("Up"))
889 SketcherCurveUp::~SketcherCurveUp()
893 int SketcherCurveUp::handle_event()
895 SketcherConfig &config = gui->plugin->config;
896 int ci = config.cv_selected;
897 SketcherCurves &curves = config.curves;
898 if( ci > 0 && ci < curves.size() ) {
899 SketcherCurve *&cv0 = curves[ci];
900 SketcherCurve *&cv1 = curves[--ci];
901 SketcherCurve *t = cv0; cv0 = cv1; cv1 = t;
902 gui->curve_list->update(ci);
904 gui->send_configure_change();
908 SketcherCurveDn::SketcherCurveDn(SketcherWindow *gui, int x, int y)
909 : BC_GenericButton(x, y, _("Dn"))
913 SketcherCurveDn::~SketcherCurveDn()
917 int SketcherCurveDn::handle_event()
919 SketcherConfig &config = gui->plugin->config;
920 int ci = config.cv_selected;
921 SketcherCurves &curves = config.curves;
922 if( ci >= 0 && ci < curves.size()-1 ) {
923 SketcherCurve *&cv0 = curves[ci];
924 SketcherCurve *&cv1 = curves[++ci];
925 SketcherCurve *t = cv0; cv0 = cv1; cv1 = t;
926 gui->curve_list->update(ci);
928 gui->send_configure_change();
933 SketcherPointTypeItem::SketcherPointTypeItem(int arc)
934 : BC_MenuItem(_(pt_type[arc]))
938 int SketcherPointTypeItem::handle_event()
940 SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
942 SketcherWindow *gui = popup->gui;
943 SketcherConfig &config = gui->plugin->config;
944 SketcherCurves &curves = config.curves;
945 int ci = config.cv_selected;
946 if( ci < 0 || ci >= curves.size() )
948 SketcherCurve *cv = curves[ci];
949 SketcherPoints &points = cv->points;
950 int pi = config.pt_selected;
952 ArrayList<int> selected;
953 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
956 for( int i=selected.size(); --i>=0; ) {
958 if( k < 0 || k >= points.size() ) continue;
959 SketcherPoint *pt = cv->points[k];
961 gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
964 gui->point_list->update_list(pi);
965 gui->send_configure_change();
969 SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc)
970 : BC_PopupMenu(x,y,100,_(pt_type[arc]))
975 void SketcherPointType::create_objects()
977 for( int arc=0; arc<PT_SZ; ++arc )
978 add_item(new SketcherPointTypeItem(arc));
980 void SketcherPointType::update(int arc)
982 set_text(_(pt_type[this->type=arc]));
986 SketcherPointList::SketcherPointList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
987 : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
990 this->plugin = plugin;
991 col_titles[PT_ID] = _("ID"); col_widths[PT_ID] = 50;
992 col_titles[PT_TY] = _("Type"); col_widths[PT_TY] = 80;
993 col_titles[PT_X] = _("X"); col_widths[PT_X] = 90;
994 col_titles[PT_Y] = _("Y"); col_widths[PT_Y] = 90;
995 set_selection_mode(LISTBOX_MULTIPLE);
997 SketcherPointList::~SketcherPointList()
1001 void SketcherPointList::clear()
1003 for( int i=PT_SZ; --i>=0; )
1004 cols[i].remove_all_objects();
1007 int SketcherPointList::column_resize_event()
1009 for( int i=PT_SZ; --i>=0; )
1010 col_widths[i] = get_column_width(i);
1014 int SketcherPointList::handle_event()
1016 int pi = get_selection_number(0, 0);
1017 if( get_selection_number(0, 1) >= 0 ) pi = -1;
1019 gui->send_configure_change();
1023 int SketcherPointList::selection_changed()
1029 void SketcherPointList::add_point(const char *id, const char *ty, const char *xp, const char *yp)
1031 cols[PT_ID].append(new BC_ListBoxItem(id));
1032 cols[PT_TY].append(new BC_ListBoxItem(ty));
1033 cols[PT_X].append(new BC_ListBoxItem(xp));
1034 cols[PT_Y].append(new BC_ListBoxItem(yp));
1037 void SketcherPointList::set_point(int i, int c, int v)
1039 char stxt[BCSTRLEN];
1040 sprintf(stxt,"%d",v);
1041 set_point(i,c,stxt);
1043 void SketcherPointList::set_point(int i, int c, coord v)
1045 char stxt[BCSTRLEN];
1046 sprintf(stxt,"%0.1f",v);
1047 set_point(i,c,stxt);
1049 void SketcherPointList::set_point(int i, int c, const char *cp)
1051 cols[c].get(i)->set_text(cp);
1054 void SketcherPointList::set_selected(int k)
1056 SketcherPoint *pt = 0;
1057 int ci = plugin->config.cv_selected, pi = -1;
1058 if( ci >= 0 && ci < plugin->config.curves.size() ) {
1059 SketcherCurve *cv = plugin->config.curves[ci];
1060 pt = k >= 0 && k < cv->points.size() ? cv->points[pi=k] : 0;
1062 gui->point_type->update(pt ? pt->arc : ARC_OFF);
1063 gui->point_x->update(pt ? pt->x : 0.f);
1064 gui->point_y->update(pt ? pt->y : 0.f);
1065 gui->point_id->update(pt ? pt->id : 0);
1066 plugin->config.pt_selected = pi;
1069 void SketcherPointList::update_list(int k)
1071 int xpos = get_xposition(), ypos = get_yposition();
1072 if( k >= 0 ) update_selection(&cols[0], k);
1073 BC_ListBox::update(&cols[0], &col_titles[0],&col_widths[0],PT_SZ, xpos,ypos,k);
1076 void SketcherPointList::update(int k)
1079 int ci = plugin->config.cv_selected, sz = 0;
1080 if( ci >= 0 && ci < plugin->config.curves.size() ) {
1081 SketcherCurve *cv = plugin->config.curves[ci];
1082 SketcherPoints &points = cv->points;
1084 for( int i=0; i<sz; ++i ) {
1085 SketcherPoint *pt = points[i];
1086 char itxt[BCSTRLEN]; sprintf(itxt,"%d", pt->id);
1087 char ttxt[BCSTRLEN]; sprintf(ttxt,"%s", _(pt_type[pt->arc]));
1088 char xtxt[BCSTRLEN]; sprintf(xtxt,"%0.1f", pt->x);
1089 char ytxt[BCSTRLEN]; sprintf(ytxt,"%0.1f", pt->y);
1090 add_point(itxt, ttxt, xtxt, ytxt);
1096 void SketcherWindow::update_gui()
1098 SketcherConfig &config = plugin->config;
1099 int ci = config.cv_selected;
1100 int pi = config.pt_selected;
1101 curve_list->update(ci);
1102 point_list->update(pi);
1103 SketcherCurve *cv = ci >= 0 ? config.curves[ci] : 0;
1104 curve_width->update(cv ? cv->width : 1);
1105 curve_pen->update(cv ? cv->pen : PEN_SQUARE);
1106 curve_color->set_color(cv ? cv->color : CV_COLOR);
1107 SketcherPoint *pt = pi >= 0 ? cv->points[pi] : 0;
1108 point_x->update(pt ? pt->x : 0);
1109 point_y->update(pt ? pt->y : 0);
1110 point_id->update(pt ? pt->id : 0);
1111 drag->update(plugin->config.drag);
1115 SketcherPointUp::SketcherPointUp(SketcherWindow *gui, int x, int y)
1116 : BC_GenericButton(x, y, _("Up"))
1120 SketcherPointUp::~SketcherPointUp()
1124 int SketcherPointUp::handle_event()
1126 SketcherConfig &config = gui->plugin->config;
1127 int ci = config.cv_selected;
1128 if( ci < 0 || ci >= config.curves.size() )
1130 SketcherCurve *cv = config.curves[ci];
1131 SketcherPoints &points = cv->points;
1132 if( points.size() < 2 )
1134 int pi = config.pt_selected;
1136 ArrayList<int> selected;
1137 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1140 for( int i=0; i<selected.size(); ++i ) {
1141 int k = selected[i];
1142 if( k <= 0 ) continue;
1144 SketcherPoint *&pt0 = points[k];
1145 SketcherPoint *&pt1 = points[--k];
1146 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1148 gui->point_list->update(pi);
1149 gui->send_configure_change();
1153 SketcherPointDn::SketcherPointDn(SketcherWindow *gui, int x, int y)
1154 : BC_GenericButton(x, y, _("Dn"))
1158 SketcherPointDn::~SketcherPointDn()
1162 int SketcherPointDn::handle_event()
1164 SketcherConfig &config = gui->plugin->config;
1165 int ci = config.cv_selected;
1166 if( ci < 0 || ci >= config.curves.size() )
1168 SketcherCurve *cv = config.curves[ci];
1169 SketcherPoints &points = cv->points;
1170 int sz1 = points.size()-1;
1173 int pi = config.pt_selected;
1175 ArrayList<int> selected;
1176 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1179 for( int i=selected.size(); --i>=0; ) {
1180 int k = selected[i];
1181 if( k >= sz1 ) continue;
1183 SketcherPoint *&pt0 = points[k];
1184 SketcherPoint *&pt1 = points[++k];
1185 SketcherPoint *t = pt0; pt0 = pt1; pt1 = t;
1187 gui->point_list->update(pi);
1188 gui->send_configure_change();
1192 SketcherDrag::SketcherDrag(SketcherWindow *gui, int x, int y)
1193 : BC_CheckBox(x, y, gui->plugin->config.drag, _("Drag"))
1197 int SketcherDrag::handle_event()
1199 CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
1200 int value = get_value();
1202 if( !gui->grab(cwindow_gui) ) {
1208 gui->ungrab(cwindow_gui);
1209 gui->plugin->config.drag = value;
1210 gui->send_configure_change();
1214 SketcherNewPoint::SketcherNewPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1215 : BC_GenericButton(x, y, 64, _("New"))
1218 this->plugin = plugin;
1220 SketcherNewPoint::~SketcherNewPoint()
1223 int SketcherNewPoint::handle_event()
1225 int pi = plugin->config.pt_selected;
1226 int arc = gui->point_type->type;
1227 int k = plugin->new_point(pi+1, arc);
1228 gui->point_list->update(k);
1229 gui->send_configure_change();
1233 SketcherDelPoint::SketcherDelPoint(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1234 : BC_GenericButton(x, y, 64, C_("Del"))
1237 this->plugin = plugin;
1239 SketcherDelPoint::~SketcherDelPoint()
1242 int SketcherDelPoint::handle_event()
1244 SketcherConfig &config = gui->plugin->config;
1245 SketcherCurves &curves = config.curves;
1246 int ci = config.cv_selected;
1247 if( ci < 0 || ci >= curves.size() )
1249 SketcherCurve *cv = curves[ci];
1250 SketcherPoints &points = cv->points;
1251 int pi = config.pt_selected;
1253 ArrayList<int> selected;
1254 for( int v,i=0; (v=gui->point_list->get_selection_number(0, i))>=0; ++i )
1257 for( int i=selected.size(); --i>=0; ) {
1258 int k = selected[i];
1259 if( k < 0 || k >= points.size() ) continue;
1260 points.remove_object_number(k);
1261 if( k == pi && --pi < 0 && points.size() > 0 ) pi = 0;
1263 gui->point_list->update(pi);
1264 gui->send_configure_change();
1268 SketcherResetCurves::SketcherResetCurves(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1269 : BC_GenericButton(x, y, _("Reset"))
1272 this->plugin = plugin;
1274 SketcherResetCurves::~SketcherResetCurves()
1277 int SketcherResetCurves::handle_event()
1279 SketcherConfig &config = plugin->config;
1280 config.curves.remove_all_objects();
1281 int ci = plugin->new_curve();
1282 gui->curve_list->update(ci);
1283 gui->point_list->update(-1);
1284 gui->send_configure_change();
1288 SketcherResetPoints::SketcherResetPoints(SketcherWindow *gui, Sketcher *plugin, int x, int y)
1289 : BC_GenericButton(x, y, _("Reset"))
1292 this->plugin = plugin;
1294 SketcherResetPoints::~SketcherResetPoints()
1297 int SketcherResetPoints::handle_event()
1299 SketcherConfig &config = gui->plugin->config;
1300 int ci = config.cv_selected;
1301 if( ci >= 0 && ci < config.curves.size() ) {
1302 SketcherCurve *cv = config.curves[ci];
1303 cv->points.remove_all_objects();
1304 gui->point_list->update(-1);
1305 gui->send_configure_change();