rework canvas zoom, add 3 plugins from 7.2, tweak cwdw boundry, vdevicex11 dupl close...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / whirl / whirl.C
index af514fe74f748440bd666e9bbc133a908a6dfc2b..ac598991d75abeb9d93fc8aaff8a1466a60deae0 100644 (file)
@@ -28,6 +28,7 @@
 #include "language.h"
 #include "loadbalance.h"
 #include "pluginvclient.h"
+#include "theme.h"
 #include "vframe.h"
 
 
 class WhirlEffect;
 class WhirlWindow;
 class WhirlEngine;
+class WhirlReset;
+class WhirlDefaultSettings;
+class WhirlSliderClr;
 
 #define MAXRADIUS 100
 #define MAXPINCH 100
 
-
-
-
+#define RESET_DEFAULT_SETTINGS 10
+#define RESET_ALL    0
+#define RESET_RADIUS 1
+#define RESET_PINCH  2
+#define RESET_ANGLE  3
 
 
 class WhirlConfig
 {
 public:
        WhirlConfig();
+       void reset(int clear);
 
        void copy_from(WhirlConfig &src);
        int equivalent(WhirlConfig &src);
@@ -94,15 +101,53 @@ public:
        WhirlEffect *plugin;
 };
 
+
+class WhirlReset : public BC_GenericButton
+{
+public:
+       WhirlReset(WhirlEffect *plugin, WhirlWindow *window, int x, int y);
+       ~WhirlReset();
+       int handle_event();
+       WhirlEffect *plugin;
+       WhirlWindow *window;
+};
+
+class WhirlDefaultSettings : public BC_GenericButton
+{
+public:
+       WhirlDefaultSettings(WhirlEffect *plugin, WhirlWindow *window, int x, int y, int w);
+       ~WhirlDefaultSettings();
+       int handle_event();
+       WhirlEffect *plugin;
+       WhirlWindow *window;
+};
+
+class WhirlSliderClr : public BC_Button
+{
+public:
+       WhirlSliderClr(WhirlEffect *plugin, WhirlWindow *window, int x, int y, int w, int clear);
+       ~WhirlSliderClr();
+       int handle_event();
+       WhirlEffect *plugin;
+       WhirlWindow *window;
+       int clear;
+};
+
+
+
 class WhirlWindow : public PluginClientWindow
 {
 public:
        WhirlWindow(WhirlEffect *plugin);
        void create_objects();
+       void update_gui(int clear);
        WhirlEffect *plugin;
        WhirlRadius *radius;
        WhirlPinch *pinch;
        WhirlAngle *angle;
+       WhirlReset *reset;
+       WhirlDefaultSettings *default_settings;
+       WhirlSliderClr *radiusClr, *pinchClr, *angleClr;
 };
 
 
@@ -178,13 +223,32 @@ REGISTER_PLUGIN(WhirlEffect)
 
 
 
-
-
 WhirlConfig::WhirlConfig()
 {
-       angle = 0.0;
-       pinch = 0.0;
-       radius = 0.0;
+       reset(RESET_ALL);
+}
+
+void WhirlConfig::reset(int clear)
+{
+       switch(clear) {
+               case RESET_ALL :
+                       radius = 0.0;
+                       pinch = 0.0;
+                       angle = 0.0;
+                       break;
+               case RESET_RADIUS : radius = 0.0;
+                       break;
+               case RESET_PINCH : pinch = 0.0;
+                       break;
+               case RESET_ANGLE : angle = 0.0;
+                       break;
+               case RESET_DEFAULT_SETTINGS :
+               default:
+                       radius = 50.0;
+                       pinch = 10.0;
+                       angle = 180.0;
+                       break;
+       }
 }
 
 void WhirlConfig::copy_from(WhirlConfig &src)
@@ -225,12 +289,7 @@ void WhirlConfig::interpolate(WhirlConfig &prev,
 
 
 WhirlWindow::WhirlWindow(WhirlEffect *plugin)
- : PluginClientWindow(plugin,
-       220,
-       200,
-       220,
-       200,
-       0)
+ : PluginClientWindow(plugin, xS(280), yS(195), xS(280), yS(195), 0)
 {
        this->plugin = plugin;
 }
@@ -239,25 +298,58 @@ WhirlWindow::WhirlWindow(WhirlEffect *plugin)
 
 void WhirlWindow::create_objects()
 {
-       int x = 10, y = 10;
+       int xs10 = xS(10), xs50 = xS(50), xs100 = xS(100);
+       int ys10 = yS(10), ys20 = yS(20), ys30 = yS(30), ys35 = yS(35);
+       int x = xs10, y = ys10;
+       int x1 = 0; int clrBtn_w = xs50;
+       int defaultBtn_w = xs100;
+
        add_subwindow(new BC_Title(x, y, _("Radius")));
-       y += 20;
+       y += ys20;
        add_subwindow(radius = new WhirlRadius(plugin, x, y));
-       y += 40;
+       x1 = x + radius->get_w() + xs10;
+       add_subwindow(radiusClr = new WhirlSliderClr(plugin, this, x1, y, clrBtn_w, RESET_RADIUS));
+
+       y += ys30;
        add_subwindow(new BC_Title(x, y, _("Pinch")));
-       y += 20;
+       y += ys20;
        add_subwindow(pinch = new WhirlPinch(plugin, x, y));
-       y += 40;
+       add_subwindow(pinchClr = new WhirlSliderClr(plugin, this, x1, y, clrBtn_w, RESET_PINCH));
+
+       y += ys30;
        add_subwindow(new BC_Title(x, y, _("Angle")));
-       y += 20;
+       y += ys20;
        add_subwindow(angle = new WhirlAngle(plugin, x, y));
+       add_subwindow(angleClr = new WhirlSliderClr(plugin, this, x1, y, clrBtn_w, RESET_ANGLE));
 
+       y += ys35;
+       add_subwindow(reset = new WhirlReset(plugin, this, x, y));
+       add_subwindow(default_settings = new WhirlDefaultSettings(plugin, this,
+               (xS(280) - xs10 - defaultBtn_w), y, defaultBtn_w));
        show_window();
        flush();
 }
 
 
-
+// for Reset button
+void WhirlWindow::update_gui(int clear)
+{
+       switch(clear) {
+               case RESET_RADIUS : radius->update(plugin->config.radius);
+                       break;
+               case RESET_PINCH : pinch->update(plugin->config.pinch);
+                       break;
+               case RESET_ANGLE : angle->update(plugin->config.angle);
+                       break;
+               case RESET_ALL :
+               case RESET_DEFAULT_SETTINGS :
+               default:
+                       radius->update(plugin->config.radius);
+                       pinch->update(plugin->config.pinch);
+                       angle->update(plugin->config.angle);
+                       break;
+       }
+}
 
 
 
@@ -273,8 +365,8 @@ WhirlAngle::WhirlAngle(WhirlEffect *plugin, int x, int y)
  : BC_FSlider(x,
                y,
                0,
-               200,
-               200,
+               xS(200),
+               yS(200),
                (float)0,
                (float)360,
                plugin->config.angle)
@@ -295,8 +387,8 @@ WhirlPinch::WhirlPinch(WhirlEffect *plugin, int x, int y)
  : BC_FSlider(x,
                y,
                0,
-               200,
-               200,
+               xS(200),
+               yS(200),
                (float)0,
                (float)MAXPINCH,
                plugin->config.pinch)
@@ -317,8 +409,8 @@ WhirlRadius::WhirlRadius(WhirlEffect *plugin, int x, int y)
  : BC_FSlider(x,
                y,
                0,
-               200,
-               200,
+               xS(200),
+               yS(200),
                (float)0,
                (float)MAXRADIUS,
                plugin->config.radius)
@@ -334,9 +426,60 @@ int WhirlRadius::handle_event()
 
 
 
+WhirlReset::WhirlReset(WhirlEffect *plugin, WhirlWindow *window, int x, int y)
+ : BC_GenericButton(x, y, _("Reset"))
+{
+       this->plugin = plugin;
+       this->window = window;
+}
+WhirlReset::~WhirlReset()
+{
+}
+int WhirlReset::handle_event()
+{
+       plugin->config.reset(RESET_ALL);
+       window->update_gui(RESET_ALL);
+       plugin->send_configure_change();
+       return 1;
+}
 
+WhirlDefaultSettings::WhirlDefaultSettings(WhirlEffect *plugin, WhirlWindow *window, int x, int y, int w)
+ : BC_GenericButton(x, y, w, _("Default"))
+{
+       this->plugin = plugin;
+       this->window = window;
+}
+WhirlDefaultSettings::~WhirlDefaultSettings()
+{
+}
+int WhirlDefaultSettings::handle_event()
+{
+       plugin->config.reset(RESET_DEFAULT_SETTINGS);
+       window->update_gui(RESET_DEFAULT_SETTINGS);
+       plugin->send_configure_change();
+       return 1;
+}
 
-
+WhirlSliderClr::WhirlSliderClr(WhirlEffect *plugin, WhirlWindow *window, int x, int y, int w, int clear)
+ : BC_Button(x, y, w, plugin->get_theme()->get_image_set("reset_button"))
+{
+       this->plugin = plugin;
+       this->window = window;
+       this->clear = clear;
+}
+WhirlSliderClr::~WhirlSliderClr()
+{
+}
+int WhirlSliderClr::handle_event()
+{
+       // clear==1 ==> Radius slider
+       // clear==2 ==> Pinch slider
+       // clear==3 ==> Angle slider
+       plugin->config.reset(clear);
+       window->update_gui(clear);
+       plugin->send_configure_change();
+       return 1;
+}
 
 
 
@@ -738,8 +881,8 @@ void WhirlUnit::process_package(LoadPackage *package)
        double pinch = plugin->config.pinch / MAXPINCH;
        double cx, cy;
     int ix, iy;
-       double cen_x = (double)(w - 1) / 2.0;
-       double cen_y = (double)(h - 1) / 2.0;
+       double cen_x = (double)(w-1) / 2.0;
+       double cen_y = (double)(h-1) / 2.0;
        double radius = MAX(w, h);
        double radius3 = plugin->config.radius / MAXRADIUS;
        double radius2 = radius * radius * radius3;