add BC_SCALE env var for hi def monitors, cleanup theme data
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / crikey / crikeywindow.C
index eaaa0b5ca3c01c33269688d22ee172c289fc7ff8..4295d6d3b7e829c625e9a3e95562c3576536db18 100644 (file)
 #include "theme.h"
 #include "track.h"
 
-#define COLOR_W 50
-#define COLOR_H 30
+#define COLOR_W xS(50)
+#define COLOR_H yS(30)
 
 CriKeyNum::CriKeyNum(CriKeyWindow *gui, int x, int y, float output)
- : BC_TumbleTextBox(gui, output, -32767.0f, 32767.0f, x, y, 120)
+ : BC_TumbleTextBox(gui, output, -32767.0f, 32767.0f, x, y, xS(120))
 {
        this->gui = gui;
        set_increment(1);
@@ -90,7 +90,7 @@ int CriKeyDrawModeItem::handle_event()
        return 1;
 }
 CriKeyDrawMode::CriKeyDrawMode(CriKeyWindow *gui, int x, int y)
- : BC_PopupMenu(x, y, 100, "", 1)
+ : BC_PopupMenu(x, y, xS(100), "", 1)
 {
        this->gui = gui;
        draw_modes[DRAW_ALPHA]     = _("Alpha");
@@ -115,7 +115,7 @@ void CriKeyDrawMode::update(int mode, int send)
 
 
 CriKeyWindow::CriKeyWindow(CriKey *plugin)
- : PluginClientWindow(plugin, 380, 400, 380, 400, 0)
+ : PluginClientWindow(plugin, xS(380), yS(400), xS(380), yS(400), 0)
 {
        this->plugin = plugin;
        this->title_x = 0;    this->point_x = 0;
@@ -129,18 +129,22 @@ CriKeyWindow::CriKeyWindow(CriKey *plugin)
 
 CriKeyWindow::~CriKeyWindow()
 {
+       delete point_x;
+       delete point_y;
 }
 
 void CriKeyWindow::create_objects()
 {
+       int xs10 = xS(10), xs32 = xS(32);
+       int ys5 = yS(5), ys10 = yS(10);
        int x = 10, y = 10;
        int margin = plugin->get_theme()->widget_border;
        BC_Title *title;
-       add_subwindow(title = new BC_Title(x, y+5, _("Draw mode:")));
-       int x1 = x + title->get_w() + 10 + margin;
+       add_subwindow(title = new BC_Title(x, y+ys5, _("Draw mode:")));
+       int x1 = x + title->get_w() + xs10 + margin;
        add_subwindow(draw_mode = new CriKeyDrawMode(this, x1, y));
        draw_mode->create_objects();
-       y += draw_mode->get_h() + 10 + margin;
+       y += draw_mode->get_h() + ys10 + margin;
 
        CriKeyPoint *pt = plugin->config.points[plugin->config.selected];
        add_subwindow(title_x = new BC_Title(x, y, _("X:")));
@@ -160,7 +164,7 @@ void CriKeyWindow::create_objects()
        add_subwindow(del_point = new CriKeyDelPoint(this, plugin, x1, y));
        x1 += del_point->get_w() + margin;
        add_subwindow(point_dn = new CriKeyPointDn(this, x1, y));
-       y += point_y->get_h() + margin + 10;
+       y += point_y->get_h() + margin + ys10;
        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));
@@ -171,14 +175,14 @@ void CriKeyWindow::create_objects()
                if( !grab(plugin->server->mwindow->cwindow->gui) )
                        eprintf("drag enabled, but compositor already grabbed\n");
        }
-       x1 = x + drag->get_w() + margin + 32;
-       add_subwindow(reset = new CriKeyReset(this, plugin, x1, y+3));
+       x1 = x + drag->get_w() + margin + xs32;
+       add_subwindow(reset = new CriKeyReset(this, plugin, x1, y+yS(3)));
        y += drag->get_h() + margin;
 
        add_subwindow(point_list = new CriKeyPointList(this, plugin, x, y));
        point_list->update(plugin->config.selected);
 
-       y += point_list->get_h() + 10;
+       y += point_list->get_h() + ys10;
        add_subwindow(notes = new BC_Title(x, y,
                 _("Right click in composer: create new point\n"
                   "Shift-left click in Enable field:\n"
@@ -192,69 +196,62 @@ void CriKeyWindow::send_configure_change()
        pending_config = 0;
        plugin->send_configure_change();
 }
-int CriKeyWindow::check_configure_change(int ret)
+
+int CriKeyWindow::grab_event(XEvent *event)
 {
+       int ret = do_grab_event(event);
        if( pending_config && !grab_event_count() )
                send_configure_change();
        return ret;
 }
 
-int CriKeyWindow::grab_event(XEvent *event)
+int CriKeyWindow::do_grab_event(XEvent *event)
 {
        switch( event->type ) {
        case ButtonPress: break;
        case ButtonRelease: break;
        case MotionNotify: break;
        default:
-               return check_configure_change(0);
+               return 0;
        }
 
        MWindow *mwindow = plugin->server->mwindow;
        CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
        CWindowCanvas *canvas = cwindow_gui->canvas;
-       int cx, cy;  cwindow_gui->get_relative_cursor(cx, cy);
-       cx -= mwindow->theme->ccanvas_x;
-       cy -= mwindow->theme->ccanvas_y;
+       int cursor_x, cursor_y;
+       cwindow_gui->get_relative_cursor(cursor_x, cursor_y);
+       float output_x = cursor_x - canvas->view_x;
+       float output_y = cursor_y - canvas->view_y;
 
        if( !dragging ) {
-               if( cx < 0 || cx >= mwindow->theme->ccanvas_w ||
-                   cy < 0 || cy >= mwindow->theme->ccanvas_h )
-                       return check_configure_change(0);
+               if( output_x < 0 || output_x >= canvas->view_w ||
+                   output_y < 0 || output_y >= canvas->view_h )
+                       return 0;
        }
 
        switch( event->type ) {
        case ButtonPress:
-               if( dragging ) return check_configure_change(0);
+               if( dragging ) return 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:
-               if( !dragging ) return check_configure_change(0);
+               if( !dragging ) return 0;
                dragging = 0;
                return 1;
        case MotionNotify:
-               if( !dragging ) return check_configure_change(0);
+               if( !dragging ) return 0;
                break;
        default:
-               return check_configure_change(0);
+               return 0;
        }
 
-       float cursor_x = cx, cursor_y = cy;
-       canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
-       int64_t position = plugin->get_source_position();
-       float projector_x, projector_y, projector_z;
-       Track *track = plugin->server->plugin->track;
-       int track_w = track->track_w, track_h = track->track_h;
-       track->automation->get_projector(
-               &projector_x, &projector_y, &projector_z,
-               position, PLAY_FORWARD);
-       projector_x += mwindow->edl->session->output_w / 2;
-       projector_y += mwindow->edl->session->output_h / 2;
-       float output_x = (cursor_x - projector_x) / projector_z + track_w / 2;
-       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));
+       float track_x, track_y;
+       canvas->canvas_to_output(mwindow->edl, 0, output_x, output_y);
+       plugin->output_to_track(output_x, output_y, track_x, track_y);
+       point_x->update((int64_t)track_x);
+       point_y->update((int64_t)track_y);
        CriKeyPoints &points = plugin->config.points;
 
        if( dragging > 0 ) {
@@ -265,29 +262,33 @@ int CriKeyWindow::grab_event(XEvent *event)
                        if( button_no == RIGHT_BUTTON ) {
                                hot_point = plugin->new_point();
                                CriKeyPoint *pt = points[hot_point];
-                               pt->x = output_x;  pt->y = output_y;
+                               pt->x = track_x;  pt->y = track_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);
+                               double dist = DISTANCE(track_x,track_y, pt->x,pt->y);
                                for( int i=1; i<sz; ++i ) {
                                        pt = points[i];
-                                       double d = DISTANCE(output_x,output_y, pt->x,pt->y);
+                                       double d = DISTANCE(track_x,track_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;
+                               float cx, cy;
+                               plugin->track_to_output(pt->x, pt->y, cx, cy);
+                               canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
+                               cx += canvas->view_x;  cy += canvas->view_y;
+                               dist = DISTANCE(cx,cy, cursor_x,cursor_y);
+                               if( dist >= HANDLE_W )
+                                       hot_point = -1;
                        }
                        if( hot_point >= 0 && sz > 0 ) {
                                CriKeyPoint *pt = points[hot_point];
-                               point_list->set_point(hot_point, PT_X, pt->x = output_x);
+                               point_list->set_point(hot_point, PT_X, pt->x = track_x);
+                               point_list->set_point(hot_point, PT_Y, pt->y = track_y);
                                for( int i=0; i<sz; ++i ) {
                                        pt = points[i];
                                        pt->e = i==hot_point ? !pt->e : 0;
@@ -300,9 +301,9 @@ int CriKeyWindow::grab_event(XEvent *event)
                        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;
-                               point_list->set_point(hot_point, PT_X, pt->x = output_x);
-                               point_list->set_point(hot_point, PT_Y, pt->y = output_y);
+                               if( pt->x == track_x && pt->y == track_y ) break;
+                               point_list->set_point(hot_point, PT_X, pt->x = track_x);
+                               point_list->set_point(hot_point, PT_Y, pt->y = track_y);
                                point_x->update(pt->x);
                                point_y->update(pt->y);
                                point_list->update_list(hot_point);
@@ -313,7 +314,7 @@ int CriKeyWindow::grab_event(XEvent *event)
        else {
                switch( event->type ) {
                case MotionNotify: {
-                       float dx = output_x - last_x, dy = output_y - last_y;
+                       float dx = track_x - last_x, dy = track_y - last_y;
                        int sz = points.size();
                        for( int i=0; i<sz; ++i ) {
                                CriKeyPoint *pt = points[i];
@@ -331,11 +332,8 @@ int CriKeyWindow::grab_event(XEvent *event)
                }
        }
 
-       last_x = output_x;  last_y = output_y;
-       if( !grab_event_count() ) 
-               send_configure_change();
-       else
-               pending_config = 1;
+       last_x = track_x;  last_y = track_y;
+       pending_config = 1;
        return 1;
 }
 
@@ -345,15 +343,15 @@ void CriKeyWindow::done_event(int result)
 }
 
 CriKeyPointList::CriKeyPointList(CriKeyWindow *gui, CriKey *plugin, int x, int y)
- : BC_ListBox(x, y, 360, 130, LISTBOX_TEXT)
+ : BC_ListBox(x, y, xS(360), yS(130), LISTBOX_TEXT)
 {
        this->gui = gui;
        this->plugin = plugin;
-       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;
+       titles[PT_E] = _("E");    widths[PT_E] = xS(50);
+       titles[PT_X] = _("X");    widths[PT_X] = xS(90);
+       titles[PT_Y] = _("Y");    widths[PT_Y] = xS(90);
+       titles[PT_T] = _("T");    widths[PT_T] = xS(70);
+       titles[PT_TAG] = _("Tag");  widths[PT_TAG] = xS(50);
 }
 CriKeyPointList::~CriKeyPointList()
 {
@@ -592,7 +590,7 @@ int CriKeyDrag::handle_event()
 }
 
 CriKeyNewPoint::CriKeyNewPoint(CriKeyWindow *gui, CriKey *plugin, int x, int y)
- : BC_GenericButton(x, y, 80, _("New"))
+ : BC_GenericButton(x, y, xS(80), _("New"))
 {
        this->gui = gui;
        this->plugin = plugin;
@@ -609,7 +607,7 @@ int CriKeyNewPoint::handle_event()
 }
 
 CriKeyDelPoint::CriKeyDelPoint(CriKeyWindow *gui, CriKey *plugin, int x, int y)
- : BC_GenericButton(x, y, 80, C_("Del"))
+ : BC_GenericButton(x, y, xS(80), C_("Del"))
 {
        this->gui = gui;
        this->plugin = plugin;