int CriKeyPointX::handle_event()
{
if( !CriKeyNum::handle_event() ) return 0;
- CriKeyPoints *points = gui->points;
- int hot_point = points->get_selection_number(0, 0);
- if( hot_point >= 0 && hot_point < gui->plugin->config.points.size() ) {
+ CriKeyPointList *point_list = gui->point_list;
+ int hot_point = point_list->get_selection_number(0, 0);
+ CriKeyPoints &points = gui->plugin->config.points;
+ int sz = points.size();
+ if( hot_point >= 0 && hot_point < sz ) {
float v = atof(get_text());
- gui->plugin->config.points[hot_point]->x = v;
- points->set_point(hot_point, PT_X, v);
+ points[hot_point]->x = v;
+ point_list->set_point(hot_point, PT_X, v);
}
- points->update_list();
+ point_list->update_list(hot_point);
gui->send_configure_change();
return 1;
}
int CriKeyPointY::handle_event()
{
if( !CriKeyNum::handle_event() ) return 0;
- CriKeyPoints *points = gui->points;
- int hot_point = points->get_selection_number(0, 0);
- if( hot_point >= 0 && hot_point < gui->plugin->config.points.size() ) {
+ CriKeyPointList *point_list = gui->point_list;
+ int hot_point = point_list->get_selection_number(0, 0);
+ CriKeyPoints &points = gui->plugin->config.points;
+ int sz = points.size();
+ if( hot_point >= 0 && hot_point < sz ) {
float v = atof(get_text());
- gui->plugin->config.points[hot_point]->y = v;
- points->set_point(hot_point, PT_Y, v);
+ points[hot_point]->y = v;
+ point_list->set_point(hot_point, PT_Y, v);
}
- points->update_list();
+ point_list->update_list(hot_point);
gui->send_configure_change();
return 1;
}
if( send ) gui->send_configure_change();
}
-CriKeyColorButton::CriKeyColorButton(CriKeyWindow *gui, int x, int y)
- : BC_GenericButton(x, y, _("Color"))
-{
- this->gui = gui;
-}
-int CriKeyColorButton::handle_event()
-{
- gui->start_color_thread();
- return 1;
-}
-
-CriKeyColorPicker::CriKeyColorPicker(CriKeyColorButton *color_button)
- : ColorPicker(0, _("Color"))
-{
- this->color_button = color_button;
-}
-
-void CriKeyColorPicker::start(int color)
-{
- orig_color = this->color = color;
- start_window(color, 0, 1);
-}
-
-void CriKeyColorPicker::handle_done_event(int result)
-{
- if( result ) color = orig_color;
- CriKeyWindow *gui = color_button->gui;
- gui->lock_window("CriKeyColorPicker::handle_done_event");
- gui->update_color(color);
- gui->plugin->config.color = color;
- gui->send_configure_change();
- gui->unlock_window();
-}
-
-int CriKeyColorPicker::handle_new_color(int color, int alpha)
-{
- CriKeyWindow *gui = color_button->gui;
- gui->lock_window("CriKeyColorPicker::handle_new_color");
- gui->update_color(this->color = color);
- gui->flush();
- gui->plugin->config.color = color;
- gui->send_configure_change();
- gui->unlock_window();
- return 1;
-}
-
-
-void CriKeyWindow::start_color_thread()
-{
- unlock_window();
- delete color_picker;
- color_picker = new CriKeyColorPicker(color_button);
- color_picker->start(plugin->config.color);
- lock_window("CriKeyWindow::start_color_thread");
-}
-
CriKeyWindow::CriKeyWindow(CriKey *plugin)
- : PluginClientWindow(plugin, 380, 360, 380, 360, 0)
+ : PluginClientWindow(plugin, 380, 400, 380, 400, 0)
{
this->plugin = plugin;
- this->color_button = 0;
- this->color_picker = 0;
this->title_x = 0; this->point_x = 0;
this->title_y = 0; this->point_y = 0;
this->new_point = 0; this->del_point = 0;
this->point_up = 0; this->point_dn = 0;
this->drag = 0; this->dragging = 0;
this->last_x = 0; this->last_y = 0;
- this->points = 0; this->cur_point = 0;
- this->pending_config = 0;
+ this->point_list = 0; this->pending_config = 0;
}
CriKeyWindow::~CriKeyWindow()
{
- delete color_picker;
- delete points;
}
void CriKeyWindow::create_objects()
int x = 10, y = 10;
int margin = plugin->get_theme()->widget_border;
BC_Title *title;
- add_subwindow(title = new BC_Title(x, y, _("Threshold:")));
- y += title->get_h() + margin;
- add_subwindow(threshold = new CriKeyThreshold(this, x, y, get_w() - x * 2));
- y += threshold->get_h() + margin;
- add_subwindow(color_button = new CriKeyColorButton(this, x, y));
- int x1 = x + color_button->get_w() + margin;
- color_x = x1; color_y = y;
- update_color(plugin->config.color);
- y += COLOR_H + 10 + margin ;
add_subwindow(title = new BC_Title(x, y+5, _("Draw mode:")));
- x1 = x + title->get_w() + 10 + margin;
+ int x1 = x + title->get_w() + 10 + margin;
add_subwindow(draw_mode = new CriKeyDrawMode(this, x1, y));
draw_mode->create_objects();
y += draw_mode->get_h() + 10 + margin;
x1 += del_point->get_w() + margin;
add_subwindow(point_dn = new CriKeyPointDn(this, x1, y));
y += point_y->get_h() + margin + 10;
+ add_subwindow(title = new BC_Title(x, y, _("Threshold:")));
+ y += title->get_h() + margin;
+ add_subwindow(threshold = new CriKeyThreshold(this, x, y, get_w() - x * 2));
+ y += threshold->get_h() + margin;
add_subwindow(drag = new CriKeyDrag(this, x, y));
if( plugin->config.drag ) {
if( !grab(plugin->server->mwindow->cwindow->gui) )
eprintf("drag enabled, but compositor already grabbed\n");
}
-
- x1 = x + drag->get_w() + margin + 20;
- add_subwindow(cur_point = new CriKeyCurPoint(this, plugin, x1, y+3));
- cur_point->update(plugin->config.selected);
+ x1 = x + drag->get_w() + margin + 32;
+ add_subwindow(reset = new CriKeyReset(this, plugin, x1, y+3));
y += drag->get_h() + margin;
- add_subwindow(points = new CriKeyPoints(this, plugin, x, y));
- points->update(plugin->config.selected);
+ add_subwindow(point_list = new CriKeyPointList(this, plugin, x, y));
+ point_list->update(plugin->config.selected);
+
+ y += point_list->get_h() + 10;
+ add_subwindow(notes = new BC_Title(x, y,
+ _("Right click in composer: create new point\n"
+ "Shift-left click in Enable field:\n"
+ " if any off, turns all on\n"
+ " if all on, turns rest off.")));
show_window(1);
}
switch( event->type ) {
case ButtonPress:
if( dragging ) return check_configure_change(0);
+ if( event->xbutton.button == WHEEL_UP ) return threshold->wheel_event(1);
+ if( event->xbutton.button == WHEEL_DOWN ) return threshold->wheel_event(-1);
dragging = event->xbutton.state & ShiftMask ? -1 : 1;
break;
case ButtonRelease:
float output_y = (cursor_y - projector_y) / projector_z + track_h / 2;
point_x->update((int64_t)(output_x));
point_y->update((int64_t)(output_y));
+ CriKeyPoints &points = plugin->config.points;
if( dragging > 0 ) {
switch( event->type ) {
case ButtonPress: {
+ int button_no = event->xbutton.button;
int hot_point = -1;
- int n = plugin->config.points.size();
- if( n > 0 ) {
- CriKeyPoint *pt = plugin->config.points[hot_point=0];
+ if( button_no == RIGHT_BUTTON ) {
+ hot_point = plugin->new_point();
+ CriKeyPoint *pt = points[hot_point];
+ pt->x = output_x; pt->y = output_y;
+ point_list->update(hot_point);
+ break;
+ }
+ int sz = points.size();
+ if( hot_point < 0 && sz > 0 ) {
+ CriKeyPoint *pt = points[hot_point=0];
double dist = DISTANCE(output_x,output_y, pt->x,pt->y);
- for( int i=1; i<n; ++i ) {
- pt = plugin->config.points[i];
+ for( int i=1; i<sz; ++i ) {
+ pt = points[i];
double d = DISTANCE(output_x,output_y, pt->x,pt->y);
if( d >= dist ) continue;
dist = d; hot_point = i;
}
+ pt = points[hot_point];
+ float px = (pt->x - track_w / 2) * projector_z + projector_x;
+ float py = (pt->y - track_h / 2) * projector_z + projector_y;
+ dist = DISTANCE(px, py, cursor_x,cursor_y);
+ if( dist >= HANDLE_W ) hot_point = -1;
}
- if( hot_point >= 0 ) {
- CriKeyPoint *pt = plugin->config.points[hot_point];
- if( pt->x == output_x && pt->y == output_y ) break;
- points->set_point(hot_point, PT_X, pt->x = output_x);
- points->set_point(hot_point, PT_Y, pt->y = output_y);
- plugin->config.selected = hot_point;
- points->set_selected(hot_point);
- points->update_list();
+ if( hot_point >= 0 && sz > 0 ) {
+ CriKeyPoint *pt = points[hot_point];
+ point_list->set_point(hot_point, PT_X, pt->x = output_x);
+ for( int i=0; i<sz; ++i ) {
+ pt = points[i];
+ pt->e = i==hot_point ? !pt->e : 0;
+ point_list->set_point(i, PT_E, pt->e ? "*" : "");
+ }
+ point_list->update_list(hot_point);
}
break; }
case MotionNotify: {
- int hot_point = points->get_selection_number(0, 0);
- if( hot_point >= 0 && hot_point < plugin->config.points.size() ) {
- CriKeyPoint *pt = plugin->config.points[hot_point];
+ int hot_point = point_list->get_selection_number(0, 0);
+ if( hot_point >= 0 && hot_point < points.size() ) {
+ CriKeyPoint *pt = points[hot_point];
if( pt->x == output_x && pt->y == output_y ) break;
- points->set_point(hot_point, PT_X, pt->x = output_x);
- points->set_point(hot_point, PT_Y, pt->y = output_y);
+ point_list->set_point(hot_point, PT_X, pt->x = output_x);
+ point_list->set_point(hot_point, PT_Y, pt->y = output_y);
point_x->update(pt->x);
point_y->update(pt->y);
- points->update_list();
+ point_list->update_list(hot_point);
}
break; }
}
switch( event->type ) {
case MotionNotify: {
float dx = output_x - last_x, dy = output_y - last_y;
- int n = plugin->config.points.size();
- for( int i=0; i<n; ++i ) {
- CriKeyPoint *pt = plugin->config.points[i];
- points->set_point(i, PT_X, pt->x += dx);
- points->set_point(i, PT_Y, pt->y += dy);
+ int sz = points.size();
+ for( int i=0; i<sz; ++i ) {
+ CriKeyPoint *pt = points[i];
+ point_list->set_point(i, PT_X, pt->x += dx);
+ point_list->set_point(i, PT_Y, pt->y += dy);
}
- int hot_point = points->get_selection_number(0, 0);
- if( hot_point >= 0 && hot_point < n ) {
- CriKeyPoint *pt = plugin->config.points[hot_point];
+ int hot_point = point_list->get_selection_number(0, 0);
+ if( hot_point >= 0 && hot_point < sz ) {
+ CriKeyPoint *pt = points[hot_point];
point_x->update(pt->x);
point_y->update(pt->y);
- points->update_list();
+ point_list->update_list(hot_point);
}
break; }
}
void CriKeyWindow::done_event(int result)
{
ungrab(client->server->mwindow->cwindow->gui);
- if( color_picker ) color_picker->close_window();
}
-CriKeyPoints::CriKeyPoints(CriKeyWindow *gui, CriKey *plugin, int x, int y)
+CriKeyPointList::CriKeyPointList(CriKeyWindow *gui, CriKey *plugin, int x, int y)
: BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
{
this->gui = gui;
this->plugin = plugin;
- titles[PT_E] = _("E"); widths[PT_E] = 40;
- titles[PT_X] = _("X"); widths[PT_X] = 120;
- titles[PT_Y] = _("Y"); widths[PT_Y] = 120;
- titles[PT_T] = _("Tag"); widths[PT_T] = 60;
+ titles[PT_E] = _("E"); widths[PT_E] = 50;
+ titles[PT_X] = _("X"); widths[PT_X] = 90;
+ titles[PT_Y] = _("Y"); widths[PT_Y] = 90;
+ titles[PT_T] = _("T"); widths[PT_T] = 70;
+ titles[PT_TAG] = _("Tag"); widths[PT_TAG] = 50;
}
-CriKeyPoints::~CriKeyPoints()
+CriKeyPointList::~CriKeyPointList()
{
clear();
}
-void CriKeyPoints::clear()
+void CriKeyPointList::clear()
{
for( int i=PT_SZ; --i>=0; )
cols[i].remove_all_objects();
}
-int CriKeyPoints::column_resize_event()
+int CriKeyPointList::column_resize_event()
{
for( int i=PT_SZ; --i>=0; )
widths[i] = get_column_width(i);
return 1;
}
-int CriKeyPoints::handle_event()
+int CriKeyPointList::handle_event()
{
int hot_point = get_selection_number(0, 0);
const char *x_text = "", *y_text = "";
- if( hot_point >= 0 && hot_point < plugin->config.points.size() ) {
+ float t = plugin->config.threshold;
+ CriKeyPoints &points = plugin->config.points;
+
+ int sz = points.size();
+ if( hot_point >= 0 && sz > 0 ) {
if( get_cursor_x() < widths[0] ) {
- plugin->config.points[hot_point]->e =
- !plugin->config.points[hot_point]->e;
+ if( shift_down() ) {
+ int all_on = points[0]->e;
+ for( int i=1; i<sz && all_on; ++i ) all_on = points[i]->e;
+ int e = !all_on ? 1 : 0;
+ for( int i=0; i<sz; ++i ) points[i]->e = e;
+ points[hot_point]->e = 1;
+ }
+ else
+ points[hot_point]->e = !points[hot_point]->e;
}
- x_text = gui->points->cols[PT_X].get(hot_point)->get_text();
- y_text = gui->points->cols[PT_Y].get(hot_point)->get_text();
+ x_text = gui->point_list->cols[PT_X].get(hot_point)->get_text();
+ y_text = gui->point_list->cols[PT_Y].get(hot_point)->get_text();
+ t = points[hot_point]->t;
}
- else
- hot_point = 0;
gui->point_x->update(x_text);
gui->point_y->update(y_text);
- plugin->config.selected = hot_point;
+ gui->threshold->update(t);
update(hot_point);
gui->send_configure_change();
return 1;
}
-int CriKeyPoints::selection_changed()
+int CriKeyPointList::selection_changed()
{
handle_event();
return 1;
}
-void CriKeyPoints::new_point(const char *ep, const char *xp, const char *yp, const char *tp)
+void CriKeyPointList::new_point(const char *ep, const char *xp, const char *yp,
+ const char *tp, const char *tag)
{
cols[PT_E].append(new BC_ListBoxItem(ep));
cols[PT_X].append(new BC_ListBoxItem(xp));
cols[PT_Y].append(new BC_ListBoxItem(yp));
cols[PT_T].append(new BC_ListBoxItem(tp));
+ cols[PT_TAG].append(new BC_ListBoxItem(tag));
}
-void CriKeyPoints::del_point(int i)
+void CriKeyPointList::del_point(int i)
{
- for( int n=cols[0].size()-1, c=PT_SZ; --c>=0; )
- cols[c].remove_object_number(n-i);
+ for( int sz1=cols[0].size()-1, c=PT_SZ; --c>=0; )
+ cols[c].remove_object_number(sz1-i);
}
-void CriKeyPoints::set_point(int i, int c, float v)
+void CriKeyPointList::set_point(int i, int c, float v)
{
char s[BCSTRLEN]; sprintf(s,"%0.4f",v);
set_point(i,c,s);
}
-void CriKeyPoints::set_point(int i, int c, const char *cp)
+void CriKeyPointList::set_point(int i, int c, const char *cp)
{
cols[c].get(i)->set_text(cp);
}
-int CriKeyPoints::set_selected(int k)
+int CriKeyPointList::set_selected(int k)
{
- int sz = gui->plugin->config.points.size();
+ CriKeyPoints &points = plugin->config.points;
+ int sz = points.size();
if( !sz ) return -1;
bclamp(k, 0, sz-1);
- int n = gui->points->get_selection_number(0, 0);
- if( n >= 0 ) {
- for( int i=0; i<PT_SZ; ++i )
- cols[i].get(n)->set_selected(0);
- }
- for( int i=0; i<PT_SZ; ++i )
- cols[i].get(k)->set_selected(1);
- gui->cur_point->update(k);
+ for( int i=0; i<sz; ++i ) points[i]->e = 0;
+ points[k]->e = 1;
+ update_selection(&cols[0], k);
return k;
}
-void CriKeyPoints::update_list()
+void CriKeyPointList::update_list(int k)
{
- int xpos = get_xposition(), ypos = get_xposition();
- int k = get_selection_number(0, 0);
+ int xpos = get_xposition(), ypos = get_yposition();
+ if( k < 0 ) k = get_selection_number(0, 0);
+ update_selection(&cols[0], k);
BC_ListBox::update(&cols[0], &titles[0],&widths[0],PT_SZ, xpos,ypos,k);
+ center_selection();
}
-void CriKeyPoints::update(int k)
+void CriKeyPointList::update(int k)
{
- if( k < 0 ) k = get_selection_number(0, 0);
- gui->cur_point->update(k);
- int xpos = get_xposition(), ypos = get_xposition();
-
clear();
- ArrayList<CriKeyPoint*> &points = plugin->config.points;
- int n = points.size();
- for( int i=0; i<n; ++i ) {
+ CriKeyPoints &points = plugin->config.points;
+ int sz = points.size();
+ for( int i=0; i<sz; ++i ) {
CriKeyPoint *pt = points[i];
char etxt[BCSTRLEN]; sprintf(etxt,"%s", pt->e ? "*" : "");
char xtxt[BCSTRLEN]; sprintf(xtxt,"%0.4f", pt->x);
char ytxt[BCSTRLEN]; sprintf(ytxt,"%0.4f", pt->y);
- char ttxt[BCSTRLEN]; sprintf(ttxt,"%d", pt->t);
- new_point(etxt, xtxt, ytxt, ttxt);
+ char ttxt[BCSTRLEN]; sprintf(ttxt,"%0.4f", pt->t);
+ char ttag[BCSTRLEN]; sprintf(ttag,"%d", pt->tag);
+ new_point(etxt, xtxt, ytxt, ttxt, ttag);
}
- if( k < n ) {
- for( int i=PT_SZ; --i>=0; )
- cols[i].get(k)->set_selected(1);
- gui->point_x->update(gui->points->cols[PT_X].get(k)->get_text());
- gui->point_y->update(gui->points->cols[PT_Y].get(k)->get_text());
+ if( k >= 0 && k < sz ) {
+ gui->point_x->update(gui->point_list->cols[PT_X].get(k)->get_text());
+ gui->point_y->update(gui->point_list->cols[PT_Y].get(k)->get_text());
+ plugin->config.selected = k;
}
- BC_ListBox::update(&cols[0], &titles[0],&widths[0],PT_SZ, xpos,ypos,k);
-}
-
-void CriKeyWindow::update_color(int color)
-{
- set_color(color);
- draw_box(color_x, color_y, COLOR_W, COLOR_H);
- set_color(BLACK);
- draw_rectangle(color_x, color_y, COLOR_W, COLOR_H);
- flash(color_x, color_y, COLOR_W, COLOR_H);
+ update_list(k);
}
void CriKeyWindow::update_gui()
{
draw_mode->update(plugin->config.draw_mode);
- update_color(plugin->config.color);
threshold->update(plugin->config.threshold);
- cur_point->update(plugin->config.selected);
drag->update(plugin->config.drag);
- points->update(plugin->config.selected);
+ point_list->update(-1);
}
{
this->gui = gui;
set_precision(0.005);
+ set_pagination(0.01, 0.1);
+}
+
+int CriKeyThreshold::wheel_event(int v)
+{
+ if( v > 0 ) increase_value();
+ else if( v < 0 ) decrease_value();
+ handle_event();
+ enable();
+ return 1;
}
int CriKeyThreshold::handle_event()
{
float v = get_value();
gui->plugin->config.threshold = v;
+ int hot_point = gui->point_list->get_selection_number(0, 0);
+ if( hot_point >= 0 ) {
+ CriKeyPoints &points = gui->plugin->config.points;
+ CriKeyPoint *pt = points[hot_point];
+ pt->t = v; pt->e = 1;
+ gui->point_list->update(hot_point);
+ }
gui->send_configure_change();
return 1;
}
int CriKeyPointUp::handle_event()
{
- int n = gui->plugin->config.points.size();
- int hot_point = gui->points->get_selection_number(0, 0);
+ CriKeyPoints &points = gui->plugin->config.points;
+ int sz = points.size();
+ int hot_point = gui->point_list->get_selection_number(0, 0);
- if( n > 1 && hot_point > 0 ) {
- CriKeyPoint *&pt0 = gui->plugin->config.points[hot_point];
- CriKeyPoint *&pt1 = gui->plugin->config.points[--hot_point];
+ if( sz > 1 && hot_point > 0 ) {
+ CriKeyPoint *&pt0 = points[hot_point];
+ CriKeyPoint *&pt1 = points[--hot_point];
CriKeyPoint *t = pt0; pt0 = pt1; pt1 = t;
- gui->plugin->config.selected = hot_point;
- gui->points->update(hot_point);
+ gui->point_list->update(hot_point);
}
gui->send_configure_change();
return 1;
int CriKeyPointDn::handle_event()
{
- int n = gui->plugin->config.points.size();
- int hot_point = gui->points->get_selection_number(0, 0);
- if( n > 1 && hot_point < n-1 ) {
- CriKeyPoint *&pt0 = gui->plugin->config.points[hot_point];
- CriKeyPoint *&pt1 = gui->plugin->config.points[++hot_point];
+ CriKeyPoints &points = gui->plugin->config.points;
+ int sz = points.size();
+ int hot_point = gui->point_list->get_selection_number(0, 0);
+ if( sz > 1 && hot_point < sz-1 ) {
+ CriKeyPoint *&pt0 = points[hot_point];
+ CriKeyPoint *&pt1 = points[++hot_point];
CriKeyPoint *t = pt0; pt0 = pt1; pt1 = t;
- gui->plugin->config.selected = hot_point;
- gui->points->update(hot_point);
+ gui->point_list->update(hot_point);
}
gui->send_configure_change();
return 1;
int CriKeyNewPoint::handle_event()
{
int k = plugin->new_point();
- gui->points->update(k);
+ gui->point_list->update(k);
gui->send_configure_change();
return 1;
}
}
int CriKeyDelPoint::handle_event()
{
- int hot_point = gui->points->get_selection_number(0, 0);
- if( hot_point >= 0 && hot_point < gui->plugin->config.points.size() ) {
+ int hot_point = gui->point_list->get_selection_number(0, 0);
+ CriKeyPoints &points = plugin->config.points;
+ if( hot_point >= 0 && hot_point < points.size() ) {
plugin->config.del_point(hot_point);
- if( !plugin->config.points.size() ) plugin->new_point();
- int n = gui->plugin->config.points.size();
- if( hot_point >= n && hot_point > 0 ) --hot_point;
- gui->plugin->config.selected = hot_point;
- gui->points->update(hot_point);
+ if( !points.size() ) plugin->new_point();
+ int sz = points.size();
+ if( hot_point >= sz && hot_point > 0 ) --hot_point;
+ gui->point_list->update(hot_point);
gui->send_configure_change();
}
return 1;
}
-CriKeyCurPoint::CriKeyCurPoint(CriKeyWindow *gui, CriKey *plugin, int x, int y)
- : BC_Title(x, y, "")
+CriKeyReset::CriKeyReset(CriKeyWindow *gui, CriKey *plugin, int x, int y)
+ : BC_GenericButton(x, y, _("Reset"))
{
this->gui = gui;
this->plugin = plugin;
}
-CriKeyCurPoint::~CriKeyCurPoint()
+CriKeyReset::~CriKeyReset()
{
}
-void CriKeyCurPoint::update(int n)
+int CriKeyReset::handle_event()
{
- char string[BCSTRLEN];
- sprintf(string, _("Selected: %d "), n);
- BC_Title::update(string);
+ CriKeyPoints &points = plugin->config.points;
+ points.remove_all_objects();
+ plugin->new_point();
+ gui->point_list->update(0);
+ gui->send_configure_change();
+ return 1;
}