#define AltMask Mod1Mask
-#define COLOR_W 32
+#define COLOR_W 40
#define COLOR_H 24
const char *SketcherPoint::types[] = {
}
SketcherCurvePen::SketcherCurvePen(SketcherWindow *gui, int x, int y, int pen)
- : BC_PopupMenu(x,y,72,_(cv_pen[pen]))
+ : BC_PopupMenu(x,y,100,_(cv_pen[pen]))
{
this->gui = gui;
+ this->pen = pen;
}
void SketcherCurvePen::create_objects()
{
}
void SketcherCurvePen::update(int pen)
{
- set_text(_(cv_pen[pen]));
+ set_text(_(cv_pen[this->pen=pen]));
}
-SketcherCurveColor::SketcherCurveColor(SketcherWindow *gui, int x, int y, int w, int h)
- : BC_Button(x, y, w, vframes)
+SketcherCurveColor::SketcherCurveColor(SketcherWindow *gui,
+ int x, int y, int w, int h, int color, int alpha)
+ : ColorBoxButton(_("Curve Color"), x, y, w, h, color, alpha, 1)
{
this->gui = gui;
this->color = CV_COLOR;
delete vframes[i];
}
-void SketcherCurveColor::set_color(int color)
-{
- this->color = color;
- int r = (color>>16) & 0xff;
- int g = (color>>8) & 0xff;
- int b = (color>>0) & 0xff;
- for( int i=0; i<3; ++i ) {
- VFrame *vframe = vframes[i];
- int ww = vframe->get_w(), hh = vframe->get_h();
- uint8_t **rows = vframe->get_rows();
- int rr = r, gg = g, bb = b;
- switch( i ) {
- case BUTTON_UP:
- break;
- case BUTTON_UPHI:
- if( (rr+=48) > 0xff ) rr = 0xff;
- if( (gg+=48) > 0xff ) gg = 0xff;
- if( (bb+=48) > 0xff ) bb = 0xff;
- break;
- case BUTTON_DOWNHI:
- if( (rr-=48) < 0x00 ) rr = 0x00;
- if( (gg-=48) < 0x00 ) gg = 0x00;
- if( (bb-=48) < 0x00 ) bb = 0x00;
- break;
- }
- for( int y=0; y<hh; ++y ) {
- uint8_t *rp = rows[y];
- for( int x=0; x<ww; ++x ) {
- *rp++ = rr; *rp++ = gg; *rp++ = bb;
- }
- }
- }
- set_images(vframes);
-}
-
-void SketcherCurveColor::update_gui(int color)
-{
- set_color(color);
- draw_face();
-}
-
-int SketcherCurveColor::handle_event()
-{
- gui->start_color_thread(this);
- return 1;
-}
-
-SketcherCurveColorPicker::SketcherCurveColorPicker(SketcherWindow *gui, SketcherCurveColor *color_button)
- : ColorPicker(1, _("Color"))
-{
- this->gui = gui;
- this->color_button = color_button;
- this->color = CV_COLOR;
- color_update = new SketcherCurveColorThread(this);
-}
-
-SketcherCurveColorPicker::~SketcherCurveColorPicker()
+void SketcherCurveColor::handle_done_event(int result)
{
- delete color_update;
-}
-
-void SketcherCurveColorPicker::start(int color)
-{
- this->color = color;
- int alpha = (~color>>24) & 0xff;
- start_window(color & 0xffffff, alpha, 1);
- color_update->start();
-}
-
-void SketcherCurveColorPicker::handle_done_event(int result)
-{
- color_update->stop();
- gui->lock_window("SketcherCurveColorPicker::handle_done_event");
- if( result ) { color = orig_color | (~orig_alpha<<24); }
- color_button->update_gui(color);
- gui->unlock_window();
+ if( result ) color = orig_color | (~orig_alpha<<24);
SketcherConfig &config = gui->plugin->config;
int ci = config.cv_selected;
if( ci >= 0 && ci < config.curves.size() ) {
SketcherCurve *cv = config.curves[ci];
cv->color = color;
+ gui->lock_window("SketcherCurveColor::handle_done_event");
gui->curve_list->update(ci);
+ gui->unlock_window();
gui->send_configure_change();
}
}
-int SketcherCurveColorPicker::handle_new_color(int color, int alpha)
-{
- this->color = color | (~alpha<<24);
- color_update->update_lock->unlock();
- return 1;
-}
-
-void SketcherCurveColorPicker::update_gui()
+int SketcherCurveColor::handle_new_color(int color, int alpha)
{
- gui->lock_window("SketcherCurveColorPicker::update_gui");
- color_button->update_gui(color);
+ color |= ~alpha<<24; this->color = color;
+ gui->lock_window("SketcherCurveColor::update_gui");
+ update_gui(color);
SketcherConfig &config = gui->plugin->config;
int ci = config.cv_selected;
if( ci >= 0 ) {
gui->send_configure_change();
}
gui->unlock_window();
-}
-
-SketcherCurveColorThread::SketcherCurveColorThread(SketcherCurveColorPicker *color_picker)
- : Thread(1, 0, 0)
-{
- this->color_picker = color_picker;
- this->update_lock = new Condition(0,"SketcherCurveColorThread::update_lock");
- done = 1;
-}
-
-SketcherCurveColorThread::~SketcherCurveColorThread()
-{
- stop();
- delete update_lock;
-}
-
-void SketcherCurveColorThread::start()
-{
- if( done ) {
- done = 0;
- Thread::start();
- }
-}
-
-void SketcherCurveColorThread::stop()
-{
- if( !done ) {
- done = 1;
- update_lock->unlock();
- join();
- }
-}
-
-void SketcherCurveColorThread::run()
-{
- while( !done ) {
- update_lock->lock("SketcherCurveColorThread::run");
- if( done ) break;
- color_picker->update_gui();
- }
+ return 1;
}
return 1;
}
+SketcherCurveWidth::SketcherCurveWidth(SketcherWindow *gui, int x, int y, int width)
+ : SketcherNum(gui, x, y, width, 0, 255)
+{
+ this->width = width;
+}
+SketcherCurveWidth::~SketcherCurveWidth()
+{
+}
+
int SketcherCurveWidth::handle_event()
{
if( !SketcherNum::handle_event() ) return 0;
return 1;
}
+void SketcherCurveWidth::update(int width)
+{
+ SketcherNum::update(this->width=width);
+}
+
SketcherWindow::SketcherWindow(Sketcher *plugin)
- : PluginClientWindow(plugin, 380, 580, 380, 580, 0)
+ : PluginClientWindow(plugin, 380, 620, 380, 620, 0)
{
this->plugin = plugin;
this->title_pen = 0; this->curve_pen = 0;
this->title_color = 0; this->curve_color = 0;
- this->color_picker = 0; this->drag = 0;
+ this->drag = 0;
this->new_curve = 0; this->del_curve = 0;
this->curve_up = 0; this->curve_dn = 0;
this->title_x = 0; this->point_x = 0;
delete curve_width;
delete point_x;
delete point_y;
- delete color_picker;
}
void SketcherWindow::create_objects()
curve_up = new SketcherCurveUp(this, x1, y);
add_subwindow(curve_up); dy = bmax(dy,curve_up->get_h());
x1 += curve_up->get_w() + 4*margin;
- title_pen = new BC_Title(x1+30, y, _("Pen:"));
+ y1 = BC_Title::calculate_h(this, _("Pen:"));
+ title_pen = new BC_Title(x1+30, y+dy-y1, _("Pen:"));
add_subwindow(title_pen); dy = bmax(dy,title_pen->get_h());
- int x2 = (get_w()+x1)/2;
- title_color = new BC_Title(x2+10, y, _("Color:"));
+ int x2 = (get_w()+x1)/2 + 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());
y += dy + margin; dy = 0;
curve_pen = new SketcherCurvePen(this, x1, y, cv->pen);
add_subwindow(curve_pen); dy = bmax(dy,curve_pen->get_h());
curve_pen->create_objects();
- curve_color = new SketcherCurveColor(this, x2+20, y, COLOR_W, COLOR_H);
+ curve_color = new SketcherCurveColor(this, x2, y, COLOR_W, COLOR_H,
+ cv->color&0xffffff, (~cv->color>>24)&0xff);
add_subwindow(curve_color); dy = bmax(dy,curve_color->get_h());
- curve_color->set_color(cv->color);
- curve_color->draw_face();
y += dy + margin; dy = 0;
curve_list->update(ci);
BC_Bar *bar;
bar = new BC_Bar(x, y, get_w()-2*x);
add_subwindow(bar); dy = bmax(dy,bar->get_h());
+ bar = new BC_Bar(x, y+=dy, get_w()-2*x);
+ add_subwindow(bar); dy = bmax(dy,bar->get_h());
y += dy + 2*margin;
int pi = plugin->config.pt_selected;
drag = new SketcherDrag(this, x1, y);
add_subwindow(drag); dy = bmax(dy,drag->get_h());
x1 += drag->get_w() + 2*margin;
- int pty = pt ? pt->pty : PTY_LINE;
- point_type = new SketcherPointType(this, x1, y, pty);
+ 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());
point_type->create_objects();
y += dy + margin; dy = 0;
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;
- title_id = new BC_Title(x2, y, _("ID:"));
+ x2 = x1 + point_x->get_w() + 2*margin + 10;
+ y1 = BC_Title::calculate_h(this, _("ID:"));
+ title_id = new BC_Title(x2+16, y+dy-y1, _("ID:"));
add_subwindow(title_id); dy = bmax(dy, title_id->get_h());
y += dy + margin; dy = 0;
x1 += title_y->get_w() + margin;
point_y = new SketcherPointY(this, x1, y, !pt ? 0.f : pt->y);
point_y->create_objects(); dy = bmax(dy, point_y->get_h());
- point_id = new SketcherPointId(this, x2+10, y, !pt ? 0 : pt->id);
+ 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;
+ y += dy + margin + 5; dy = 0;
point_list->update(pi);
+ bar = new BC_Bar(x, y, get_w()-2*x);
+ add_subwindow(bar); dy = bmax(dy,bar->get_h());
+ y += dy + 2*margin;
+
add_subwindow(notes0 = new BC_Title(x, y,
_("\n"
"Shift=\n"
"None=\n"
"Ctrl=\n"
- "Alt=\n"
- "DEL=\n")));
- add_subwindow(notes1 = new BC_Title(x+80, y,
+ "Ctrl+Alt=\n"
+ "Ctrl+Shift="))); dy = bmax(dy, notes0->get_h());
+ add_subwindow(notes1 = new BC_Title(x+100, y,
_(" LMB\n"
"new line point\n"
"select point\n"
"drag point\n"
"drag all curves\n"
- "deletes point\n")));
- add_subwindow(notes2 = new BC_Title(x+200, y,
+ "new fill point"))); dy = bmax(dy, notes1->get_h());
+ add_subwindow(notes2 = new BC_Title(x+220, y,
_(" RMB\n"
"new arc point\n"
"select curve\n"
"drag curve\n"
"new curve\n"
- "deletes curve\n")));
+ "new off point"))); dy = bmax(dy, notes2->get_h());
+ y += dy + margin + 10;
+
+ add_subwindow(notes3 = new BC_Title(x, y,
+ "Key DEL= delete point, +Shift= delete curve\n"));
show_window(1);
}
+void SketcherWindow::done_event(int result)
+{
+ curve_color->close_picker();
+ ungrab(plugin->server->mwindow->cwindow->gui);
+}
+
void SketcherWindow::send_configure_change()
{
pending_config = 0;
{
int ret = do_grab_event(event);
if( !grab_event_count() ) {
- if( pending_motion && grab_cursor_motion(&motion_event) )
+ if( grab_cursor_motion() )
pending_config = 1;
- if( pending_config )
+ if( pending_config ) {
+ last_x = output_x; last_y = output_y;
send_configure_change();
+ }
}
- last_x = output_x; last_y = output_y;
return ret;
}
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;
+ cx -= canvas->view_x;
+ cy -= canvas->view_y;
if( !dragging ) {
- if( cx < 0 || cx >= mwindow->theme->ccanvas_w ||
- cy < 0 || cy >= mwindow->theme->ccanvas_h )
+ if( cx < 0 || cx >= canvas->view_w ||
+ cy < 0 || cy >= canvas->view_h )
return 0;
}
+
switch( event->type ) {
case ButtonPress:
if( dragging ) return 0;
output_y = (cursor_y - projector_y) / projector_z + track_h / 2;
state = event->xmotion.state;
+ if( event->type == MotionNotify ) {
+ memcpy(&motion_event, event, sizeof(motion_event));
+ pending_motion = 1;
+ return 1;
+ }
+ if( grab_cursor_motion() )
+ pending_config = 1;
+
switch( event->type ) {
case ButtonPress:
pending_config = grab_button_press(event);
case ButtonRelease:
new_points = 0;
break;
- case MotionNotify:
- memcpy(&motion_event, event, sizeof(motion_event));
- pending_motion = 1;
- break;
}
return 1;
case LEFT_BUTTON: {
if( (state & ShiftMask) ) { // create new point/string
++new_points;
- pi = plugin->new_point(cv, PTY_LINE, output_x, output_y, pi+1);
+ pi = plugin->new_point(cv,
+ !(state & ControlMask) ? ARC_LINE : ARC_FILL,
+ output_x, output_y, pi+1);
point_list->update(pi);
break;
}
case RIGHT_BUTTON: {
if( (state & ShiftMask) ) { // create new curve point
++new_points;
- pi = plugin->new_point(cv, PTY_CURVE,
- output_x, output_y, pi+1);
+ pi = plugin->new_point(cv,
+ !(state & ControlMask) ? ARC_CURVE : ARC_OFF,
+ output_x, output_y, pi+1);
point_list->update(pi);
break;
}
- if( (state & AltMask) ) { // create new curve
- ci = plugin->new_curve(cv->pen, cv->width, cv->color);
+ 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;
return 1;
}
-int SketcherWindow::grab_cursor_motion(XEvent *event)
+int SketcherWindow::grab_cursor_motion()
{
+ if( !pending_motion )
+ return 0;
pending_motion = 0;
SketcherConfig &config = plugin->config;
int ci = config.cv_selected;
if( dist < get_w()*0.1 ) return 0; // tolerance w/10
}
++new_points;
- int pty = (state & Button1Mask) ? PTY_LINE : PTY_CURVE;
- pi = plugin->new_point(cv, pty, output_x, output_y, pi+1);
+ int arc = (state & Button1Mask) ? ARC_LINE : ARC_CURVE;
+ pi = plugin->new_point(cv, arc, output_x, output_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);
}
return 1;
}
- if( (state & AltMask) ) { // drag all curves
+ if( (state & ControlMask) && (state & AltMask) ) { // drag all curves
int dx = round(output_x - last_x);
int dy = round(output_y - last_y);
for( int i=0; i<curves.size(); ++i ) {
return 0;
}
-void SketcherWindow::done_event(int result)
-{
- ungrab(client->server->mwindow->cwindow->gui);
-}
-
-void SketcherWindow::start_color_thread(SketcherCurveColor *color_button)
-{
- unlock_window();
- delete color_picker;
- color_picker = new SketcherCurveColorPicker(this, color_button);
- int color = CV_COLOR, ci = plugin->config.cv_selected;
- if( ci >= 0 && ci < plugin->config.curves.size() ) {
- SketcherCurve *cv = plugin->config.curves[ci];
- color = cv->color;
- }
- color_picker->start(color);
- lock_window("SketcherWindow::start_color_thread");
-}
-
SketcherCurveList::SketcherCurveList(SketcherWindow *gui, Sketcher *plugin, int x, int y)
: BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
int SketcherCurveList::selection_changed()
{
+ gui->curve_color->close_picker();
handle_event();
return 1;
}
}
int SketcherNewCurve::handle_event()
{
- int pen = PTY_LINE, width = 1, color = CV_COLOR;
+ int pen = gui->curve_pen->pen;
+ int color = gui->curve_color->color;
+ int width = gui->curve_width->width;
int ci = plugin->config.cv_selected;
if( ci >= 0 && ci < plugin->config.curves.size() ) {
SketcherCurve *cv = plugin->config.curves[ci];
}
-SketcherPointTypeItem::SketcherPointTypeItem(int pty)
- : BC_MenuItem(_(pt_type[pty]))
+SketcherPointTypeItem::SketcherPointTypeItem(int arc)
+ : BC_MenuItem(_(pt_type[arc]))
{
- this->pty = pty;
+ this->arc = arc;
}
int SketcherPointTypeItem::handle_event()
{
SketcherPointType *popup = (SketcherPointType*)get_popup_menu();
- popup->update(pty);
+ popup->update(arc);
SketcherWindow *gui = popup->gui;
SketcherConfig &config = gui->plugin->config;
SketcherCurves &curves = config.curves;
int k = selected[i];
if( k < 0 || k >= points.size() ) continue;
SketcherPoint *pt = cv->points[k];
- pt->pty = pty;
- gui->point_list->set_point(k, PT_TY, _(pt_type[pty]));
+ pt->arc = arc;
+ gui->point_list->set_point(k, PT_TY, _(pt_type[arc]));
}
gui->point_list->update_list(pi);
return 1;
}
-SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int pty)
- : BC_PopupMenu(x,y,64,_(pt_type[pty]))
+SketcherPointType::SketcherPointType(SketcherWindow *gui, int x, int y, int arc)
+ : BC_PopupMenu(x,y,100,_(pt_type[arc]))
{
this->gui = gui;
+ this->type = arc;
}
void SketcherPointType::create_objects()
{
- for( int pty=0; pty<PT_SZ; ++pty )
- add_item(new SketcherPointTypeItem(pty));
+ for( int arc=0; arc<PT_SZ; ++arc )
+ add_item(new SketcherPointTypeItem(arc));
}
-void SketcherPointType::update(int pty)
+void SketcherPointType::update(int arc)
{
- set_text(_(pt_type[pty]));
+ set_text(_(pt_type[this->type=arc]));
}
SketcherCurve *cv = plugin->config.curves[ci];
pt = k >= 0 && k < cv->points.size() ? cv->points[pi=k] : 0;
}
- gui->point_type->update(pt ? pt->pty : PTY_OFF);
+ gui->point_type->update(pt ? pt->arc : ARC_OFF);
gui->point_x->update(pt ? pt->x : 0.f);
gui->point_y->update(pt ? pt->y : 0.f);
gui->point_id->update(pt ? pt->id : 0);
for( int i=0; i<sz; ++i ) {
SketcherPoint *pt = points[i];
char itxt[BCSTRLEN]; sprintf(itxt,"%d", pt->id);
- char ttxt[BCSTRLEN]; sprintf(ttxt,"%s", _(pt_type[pt->pty]));
+ char ttxt[BCSTRLEN]; sprintf(ttxt,"%s", _(pt_type[pt->arc]));
char xtxt[BCSTRLEN]; sprintf(xtxt,"%0.1f", pt->x);
char ytxt[BCSTRLEN]; sprintf(ytxt,"%0.1f", pt->y);
add_point(itxt, ttxt, xtxt, ytxt);
int SketcherNewPoint::handle_event()
{
int pi = plugin->config.pt_selected;
- int k = plugin->new_point(pi+1);
+ int arc = gui->point_type->type;
+ int k = plugin->new_point(pi+1, arc);
gui->point_list->update(k);
gui->send_configure_change();
return 1;