cin_db Makefile tweak, awdw vicon stop draw lock rework,
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / boxblur / boxblur.C
index 006439af39a3b8e998b7dede327185fc4ac7ad23..132c1d987f4c6744ab676ea92051fcd916506ffa 100644 (file)
@@ -227,6 +227,8 @@ public:
        ~BoxBlurEffect();
 
        PLUGIN_CLASS_MEMBERS(BoxBlurConfig)
+       void render_gui(void *data);
+       int is_dragging();
        int process_realtime(VFrame *input, VFrame *output);
        void update_gui();
        int is_realtime();
@@ -236,6 +238,7 @@ public:
 
        VFrame *input, *output;
        BoxBlur *box_blur;
+       int drag;
 };
 
 
@@ -244,7 +247,6 @@ void BoxBlurConfig::reset()
        horz_radius = 0;
        vert_radius = 0;
        power = 1;
-       drag = 0;
        box_x = box_y = 0.0;
        box_w = box_h = 0;
 }
@@ -254,7 +256,6 @@ void BoxBlurConfig::preset()
        horz_radius = 2;
        vert_radius = 2;
        power = 2;
-       drag = 0;
        box_x = box_y = 0.0;
        box_w = box_h = 0;
 }
@@ -270,7 +271,6 @@ void BoxBlurConfig::copy_from(BoxBlurConfig &that)
        horz_radius = that.horz_radius;
        vert_radius = that.vert_radius;
        power = that.power;
-       drag = that.drag;
        box_x = that.box_x;  box_y = that.box_y;
        box_w = that.box_w;  box_h = that.box_h;
 }
@@ -279,7 +279,7 @@ int BoxBlurConfig::equivalent(BoxBlurConfig &that)
 {
        return horz_radius == that.horz_radius &&
                vert_radius == that.vert_radius &&
-               power == that.power && // drag == that.drag &&
+               power == that.power &&
                EQUIV(box_x, that.box_x) && EQUIV(box_y, that.box_y) &&
                box_w == that.box_w && box_h == that.box_h;
 }
@@ -291,12 +291,11 @@ void BoxBlurConfig::interpolate(BoxBlurConfig &prev, BoxBlurConfig &next,
        double v = 1. - u;
        this->horz_radius = u*prev.horz_radius + v*next.horz_radius;
        this->vert_radius = u*prev.vert_radius + v*next.vert_radius;
-       this->power = u*prev.power + v*next.power;
-       this->drag = prev.drag;
+       this->power = u*prev.power + v*next.power + 1e-6; // avoid truncation jitter
        this->box_x = u*prev.box_x + v*next.box_x;
        this->box_y = u*prev.box_y + v*next.box_y;
-       this->box_w = u*prev.box_w + v*next.box_w;
-       this->box_h = u*prev.box_h + v*next.box_h;
+       this->box_w = u*prev.box_w + v*next.box_w + 1e-6;
+       this->box_h = u*prev.box_h + v*next.box_h + 1e-6;
 }
 
 
@@ -421,7 +420,7 @@ BoxBlurPower::BoxBlurPower(BoxBlurWindow *gui, int x, int y, int w,
 }
 
 BoxBlurWindow::BoxBlurWindow(BoxBlurEffect *plugin)
- : PluginClientWindow(plugin, xS(360), yS(246), xS(360), yS(246), 0)
+ : PluginClientWindow(plugin, xS(360), yS(260), xS(360), yS(260), 0)
 {
        this->plugin = plugin;
        blur_horz = 0;
@@ -445,18 +444,21 @@ BoxBlurWindow::~BoxBlurWindow()
 void BoxBlurWindow::create_objects()
 {
        int x = xS(10), y = yS(10);
+       int ys10 = yS(10), ys20 = yS(20), ys30 = yS(30), ys40 = yS(40);
        int t1 = x, t2 = t1+xS(24), t3 = t2+xS(100), t4 = t3+xS(24);
        int ww = get_w() - 2*x, bar_o = xS(30), bar_m = xS(15);
        int margin = plugin->get_theme()->widget_border;
 
-        BC_TitleBar *tbar;
-        add_subwindow(tbar = new BC_TitleBar(x, y, ww, bar_o, bar_m, _("Position & Size")));
-        y += tbar->get_h() + margin;
+       BC_TitleBar *tbar;
+       add_subwindow(tbar = new BC_TitleBar(x, y, ww, bar_o, bar_m, _("Position & Size")));
+       y += ys20;
        int x1 = ww - BoxBlurDrag::calculate_w(this) - margin;
+       if( plugin->drag && drag->drag_activate() ) {
+               eprintf("drag enabled, but compositor already grabbed\n");
+               plugin->drag = 0;
+       }
        add_subwindow(drag = new BoxBlurDrag(this, plugin, x1, y));
        drag->create_objects();
-       if( plugin->config.drag && drag->drag_activate() )
-               eprintf("drag enabled, but compositor already grabbed\n");
 
        BC_Title *title;
        add_subwindow(title = new BC_Title(t1, y, _("X:")));
@@ -465,32 +467,32 @@ void BoxBlurWindow::create_objects()
        add_subwindow(title = new BC_Title(t3, y, _("W:")));
        box_w = new BoxBlurW(this, t4, y);
        box_w->create_objects();
-       y += bmax(title->get_h(), box_w->get_h()) + margin;
+       y += ys30;
        add_subwindow(title = new BC_Title(t1, y, _("Y:")));
        box_y = new BoxBlurY(this, t2, y);
        box_y->create_objects();
        add_subwindow(title = new BC_Title(t3, y, _("H:")));
        box_h = new BoxBlurH(this, t4, y);
        box_h->create_objects();
-       y += bmax(title->get_h(), box_h->get_h()) + 2*margin;
+       y += ys40;
 
        add_subwindow(tbar = new BC_TitleBar(x, y, ww, bar_o, bar_m, _("Blur")));
-       y += tbar->get_h() + margin;
+       y += ys20;
        blur_horz = new BoxBlurRadius(this, x, y, ww, _("Horz:"),
                        &plugin->config.horz_radius);
        blur_horz->create_objects();
-       y += blur_horz->get_h() + margin;
+       y += ys30;
        blur_vert = new BoxBlurRadius(this, x, y, ww, _("Vert:"),
                        &plugin->config.vert_radius);
        blur_vert->create_objects();
-       y += blur_vert->get_h() + margin;
+       y += ys30;
        blur_power = new BoxBlurPower(this, x, y, ww, _("Power:"),
                        &plugin->config.power);
        blur_power->create_objects();
-       y += blur_power->get_h() + margin + yS(8);
+       y += ys40;
        BC_Bar *bar;
        add_subwindow(bar = new BC_Bar(x, y, ww));
-       y += bar->get_h() + 2*margin;
+       y += ys10;
 
        add_subwindow(reset = new BoxBlurReset(this, x, y));
        x1 = x + ww - BoxBlurPreset::calculate_w(this);
@@ -520,11 +522,25 @@ REGISTER_PLUGIN(BoxBlurEffect)
 NEW_WINDOW_MACRO(BoxBlurEffect, BoxBlurWindow)
 LOAD_CONFIGURATION_MACRO(BoxBlurEffect, BoxBlurConfig)
 
+void BoxBlurEffect::render_gui(void *data)
+{
+       BoxBlurEffect *box_blur = (BoxBlurEffect *)data;
+       box_blur->drag = drag;
+}
+
+int BoxBlurEffect::is_dragging()
+{
+       drag = 0;
+       send_render_gui(this);
+       return drag;
+}
+
 
 BoxBlurEffect::BoxBlurEffect(PluginServer *server)
  : PluginVClient(server)
 {
        box_blur = 0;
+       drag = 0;
 }
 
 BoxBlurEffect::~BoxBlurEffect()
@@ -544,7 +560,6 @@ void BoxBlurEffect::save_data(KeyFrame *keyframe)
        output.tag.set_property("HORZ_RADIUS", config.horz_radius);
        output.tag.set_property("VERT_RADIUS", config.vert_radius);
        output.tag.set_property("POWER", config.power);
-       output.tag.set_property("DRAG", config.drag);
        output.tag.set_property("BOX_X", config.box_x);
        output.tag.set_property("BOX_Y", config.box_y);
        output.tag.set_property("BOX_W", config.box_w);
@@ -567,7 +582,6 @@ void BoxBlurEffect::read_data(KeyFrame *keyframe)
                        config.horz_radius = input.tag.get_property("HORZ_RADIUS", config.horz_radius);
                        config.vert_radius = input.tag.get_property("VERT_RADIUS", config.vert_radius);
                        config.power = input.tag.get_property("POWER", config.power);
-                       config.drag = input.tag.get_property("DRAG", config.drag);
                        config.box_x = input.tag.get_property("BOX_X", config.box_x);
                        config.box_y = input.tag.get_property("BOX_Y", config.box_y);
                        config.box_w = input.tag.get_property("BOX_W", config.box_w);
@@ -609,7 +623,7 @@ int BoxBlurEffect::process_realtime(VFrame *input, VFrame *output)
                        -1, x,y, ow, oh);
        }
 
-       if( config.drag )
+       if( is_dragging() )
                draw_boundry();
 
        return 1;
@@ -681,7 +695,7 @@ int BoxBlurH::handle_event()
 }
 
 BoxBlurDrag::BoxBlurDrag(BoxBlurWindow *gui, BoxBlurEffect *plugin, int x, int y)
- : DragCheckBox(plugin->server->mwindow, x, y, _("Drag"), &plugin->config.drag,
+ : DragCheckBox(plugin->server->mwindow, x, y, _("Drag"), &plugin->drag,
                plugin->config.box_x, plugin->config.box_y,
                plugin->config.box_w, plugin->config.box_h)
 {
@@ -710,7 +724,7 @@ int64_t BoxBlurDrag::get_drag_position()
 
 void BoxBlurDrag::update_gui()
 {
-       plugin->config.drag = get_value();
+       plugin->drag = get_value();
        plugin->config.box_x = drag_x;
        plugin->config.box_y = drag_y;
        plugin->config.box_w = drag_w+0.5;
@@ -725,6 +739,7 @@ void BoxBlurDrag::update_gui()
 int BoxBlurDrag::handle_event()
 {
        int ret = DragCheckBox::handle_event();
+       plugin->drag = get_value();
        plugin->send_configure_change();
        return ret;
 }