X-Git-Url: https://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Fwhirl%2Fwhirl.C;h=a5137e0eb1a0623c1c1109083b7f0b7d0c3ead18;hb=faaea1ce7a18979feba27c6e2127161995935a13;hp=af514fe74f748440bd666e9bbc133a908a6dfc2b;hpb=7fd85fb66168f6b518c5f2d73e04036e87faa0e1;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/plugins/whirl/whirl.C b/cinelerra-5.1/plugins/whirl/whirl.C index af514fe7..a5137e0e 100644 --- a/cinelerra-5.1/plugins/whirl/whirl.C +++ b/cinelerra-5.1/plugins/whirl/whirl.C @@ -28,6 +28,7 @@ #include "language.h" #include "loadbalance.h" #include "pluginvclient.h" +#include "theme.h" #include "vframe.h" @@ -38,12 +39,27 @@ class WhirlEffect; class WhirlWindow; class WhirlEngine; +class WhirlFText; +class WhirlFSlider; +class WhirlReset; +class WhirlDefaultSettings; +class WhirlClr; #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 - +#define RADIUS_MIN 0.00 +#define RADIUS_MAX 100.00 +#define PINCH_MIN 0.00 +#define PINCH_MAX 100.00 +#define ANGLE_MIN 0.00 +#define ANGLE_MAX 360.00 @@ -51,6 +67,7 @@ class WhirlConfig { public: WhirlConfig(); + void reset(int clear); void copy_from(WhirlConfig &src); int equivalent(WhirlConfig &src); @@ -66,43 +83,90 @@ public: }; -class WhirlAngle : public BC_FSlider +class WhirlFText : public BC_TumbleTextBox { public: - WhirlAngle(WhirlEffect *plugin, int x, int y); + WhirlFText(WhirlWindow *window, WhirlEffect *plugin, + WhirlFSlider *slider, float *output, int x, int y, float min, float max); + ~WhirlFText(); int handle_event(); + WhirlWindow *window; WhirlEffect *plugin; + WhirlFSlider *slider; + float *output; + float min, max; }; - -class WhirlPinch : public BC_FSlider +class WhirlFSlider : public BC_FSlider { public: - WhirlPinch(WhirlEffect *plugin, int x, int y); + WhirlFSlider(WhirlEffect *plugin, + WhirlFText *text, float *output, int x, int y, + float min, float max); + ~WhirlFSlider(); int handle_event(); WhirlEffect *plugin; + WhirlFText *text; + float *output; }; +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 WhirlRadius : public BC_FSlider +class WhirlClr : public BC_Button { public: - WhirlRadius(WhirlEffect *plugin, int x, int y); + WhirlClr(WhirlEffect *plugin, WhirlWindow *window, int x, int y, int clear); + ~WhirlClr(); 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; + + WhirlFText *radius_text; + WhirlFSlider *radius_slider; + WhirlClr *radius_Clr; + + WhirlFText *pinch_text; + WhirlFSlider *pinch_slider; + WhirlClr *pinch_Clr; + + WhirlFText *angle_text; + WhirlFSlider *angle_slider; + WhirlClr *angle_Clr; + + WhirlReset *reset; + WhirlDefaultSettings *default_settings; }; @@ -178,13 +242,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 +308,7 @@ void WhirlConfig::interpolate(WhirlConfig &prev, WhirlWindow::WhirlWindow(WhirlEffect *plugin) - : PluginClientWindow(plugin, - 220, - 200, - 220, - 200, - 0) + : PluginClientWindow(plugin, xS(420), yS(160), xS(420), yS(160), 0) { this->plugin = plugin; } @@ -239,104 +317,202 @@ WhirlWindow::WhirlWindow(WhirlEffect *plugin) void WhirlWindow::create_objects() { - int x = 10, y = 10; - add_subwindow(new BC_Title(x, y, _("Radius"))); - y += 20; - add_subwindow(radius = new WhirlRadius(plugin, x, y)); - y += 40; - add_subwindow(new BC_Title(x, y, _("Pinch"))); - y += 20; - add_subwindow(pinch = new WhirlPinch(plugin, x, y)); - y += 40; - add_subwindow(new BC_Title(x, y, _("Angle"))); - y += 20; - add_subwindow(angle = new WhirlAngle(plugin, x, y)); + int xs10 = xS(10), xs100 = xS(100); + int ys10 = yS(10), ys30 = yS(30), ys40 = yS(40); + int x = xs10, y = ys10; + int x2 = xS(80), x3 = xS(180); + int clr_x = get_w()-x - xS(22); // note: clrBtn_w = 22 + int defaultBtn_w = xs100; + + BC_Bar *bar; + + y += ys10; + add_subwindow(new BC_Title(x, y, _("Radius:"))); + radius_text = new WhirlFText(this, plugin, + 0, &plugin->config.radius, (x + x2), y, RADIUS_MIN, RADIUS_MAX); + radius_text->create_objects(); + radius_slider = new WhirlFSlider(plugin, + radius_text, &plugin->config.radius, x3, y, RADIUS_MIN, RADIUS_MAX); + add_subwindow(radius_slider); + radius_text->slider = radius_slider; + clr_x = x3 + radius_slider->get_w() + x; + add_subwindow(radius_Clr = new WhirlClr(plugin, this, clr_x, y, RESET_RADIUS)); + y += ys30; + + add_subwindow(new BC_Title(x, y, _("Pinch:"))); + pinch_text = new WhirlFText(this, plugin, + 0, &plugin->config.pinch, (x + x2), y, PINCH_MIN, PINCH_MAX); + pinch_text->create_objects(); + pinch_slider = new WhirlFSlider(plugin, + pinch_text, &plugin->config.pinch, x3, y, PINCH_MIN, PINCH_MAX); + add_subwindow(pinch_slider); + pinch_text->slider = pinch_slider; + add_subwindow(pinch_Clr = new WhirlClr(plugin, this, clr_x, y, RESET_PINCH)); + y += ys30; + + add_subwindow(new BC_Title(x, y, _("Angle:"))); + angle_text = new WhirlFText(this, plugin, + 0, &plugin->config.angle, (x + x2), y, ANGLE_MIN, ANGLE_MAX); + angle_text->create_objects(); + angle_slider = new WhirlFSlider(plugin, + angle_text, &plugin->config.angle, x3, y, ANGLE_MIN, ANGLE_MAX); + add_subwindow(angle_slider); + angle_text->slider = angle_slider; + add_subwindow(angle_Clr = new WhirlClr(plugin, this, clr_x, y, RESET_ANGLE)); + y += ys40; + +// Reset section + add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x)); + y += ys10; + add_subwindow(reset = new WhirlReset(plugin, this, x, y)); + add_subwindow(default_settings = new WhirlDefaultSettings(plugin, this, + (get_w() - xs10 - defaultBtn_w), y, defaultBtn_w)); show_window(); flush(); } +// for Reset button +void WhirlWindow::update_gui(int clear) +{ + switch(clear) { + case RESET_RADIUS : + radius_text->update(plugin->config.radius); + radius_slider->update(plugin->config.radius); + break; + case RESET_PINCH : + pinch_text->update(plugin->config.pinch); + pinch_slider->update(plugin->config.pinch); + break; + case RESET_ANGLE : + angle_text->update(plugin->config.angle); + angle_slider->update(plugin->config.angle); + break; + case RESET_ALL : + case RESET_DEFAULT_SETTINGS : + default: + radius_text->update(plugin->config.radius); + radius_slider->update(plugin->config.radius); + pinch_text->update(plugin->config.pinch); + pinch_slider->update(plugin->config.pinch); + angle_text->update(plugin->config.angle); + angle_slider->update(plugin->config.angle); + break; + } +} +WhirlFText::WhirlFText(WhirlWindow *window, WhirlEffect *plugin, + WhirlFSlider *slider, float *output, int x, int y, float min, float max) + : BC_TumbleTextBox(window, *output, + min, max, x, y, xS(60), 2) +{ + this->window = window; + this->plugin = plugin; + this->output = output; + this->slider = slider; + this->min = min; + this->max = max; + set_increment(0.1); +} +WhirlFText::~WhirlFText() +{ +} +int WhirlFText::handle_event() +{ + *output = atof(get_text()); + if(*output > max) *output = max; + if(*output < min) *output = min; + slider->update(*output); + plugin->send_configure_change(); + return 1; +} - - -WhirlAngle::WhirlAngle(WhirlEffect *plugin, int x, int y) - : BC_FSlider(x, - y, - 0, - 200, - 200, - (float)0, - (float)360, - plugin->config.angle) +WhirlFSlider::WhirlFSlider(WhirlEffect *plugin, + WhirlFText *text, float *output, int x, int y, float min, float max) + : BC_FSlider(x, y, 0, xS(200), xS(200), min, max, *output) { this->plugin = plugin; + this->output = output; + this->text = text; + enable_show_value(0); // Hide caption } -int WhirlAngle::handle_event() + +WhirlFSlider::~WhirlFSlider() +{ +} + +int WhirlFSlider::handle_event() { - plugin->config.angle = get_value(); + *output = get_value(); + text->update(*output); plugin->send_configure_change(); return 1; } - - -WhirlPinch::WhirlPinch(WhirlEffect *plugin, int x, int y) - : BC_FSlider(x, - y, - 0, - 200, - 200, - (float)0, - (float)MAXPINCH, - plugin->config.pinch) +WhirlReset::WhirlReset(WhirlEffect *plugin, WhirlWindow *window, int x, int y) + : BC_GenericButton(x, y, _("Reset")) { this->plugin = plugin; + this->window = window; +} +WhirlReset::~WhirlReset() +{ } -int WhirlPinch::handle_event() +int WhirlReset::handle_event() { - plugin->config.pinch = get_value(); + plugin->config.reset(RESET_ALL); + window->update_gui(RESET_ALL); plugin->send_configure_change(); return 1; } - - - -WhirlRadius::WhirlRadius(WhirlEffect *plugin, int x, int y) - : BC_FSlider(x, - y, - 0, - 200, - 200, - (float)0, - (float)MAXRADIUS, - plugin->config.radius) +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 WhirlRadius::handle_event() +int WhirlDefaultSettings::handle_event() { - plugin->config.radius = get_value(); + plugin->config.reset(RESET_DEFAULT_SETTINGS); + window->update_gui(RESET_DEFAULT_SETTINGS); plugin->send_configure_change(); return 1; } - - - - - +WhirlClr::WhirlClr(WhirlEffect *plugin, WhirlWindow *window, int x, int y, int clear) + : BC_Button(x, y, plugin->get_theme()->get_image_set("reset_button")) +{ + this->plugin = plugin; + this->window = window; + this->clear = clear; +} +WhirlClr::~WhirlClr() +{ +} +int WhirlClr::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; +} @@ -377,9 +553,12 @@ void WhirlEffect::update_gui() { load_configuration(); thread->window->lock_window(); - ((WhirlWindow*)thread->window)->angle->update(config.angle); - ((WhirlWindow*)thread->window)->pinch->update(config.pinch); - ((WhirlWindow*)thread->window)->radius->update(config.radius); + ((WhirlWindow*)thread->window)->angle_text->update(config.angle); + ((WhirlWindow*)thread->window)->angle_slider->update(config.angle); + ((WhirlWindow*)thread->window)->pinch_text->update(config.pinch); + ((WhirlWindow*)thread->window)->pinch_slider->update(config.pinch); + ((WhirlWindow*)thread->window)->radius_text->update(config.radius); + ((WhirlWindow*)thread->window)->radius_slider->update(config.radius); thread->window->unlock_window(); } } @@ -738,8 +917,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;