Credit Goat for updates for Ubuntu build + txt
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / wave / wave.C
index 99e6dc43d2e31ff06c07e860eb9f928cb2a11ecd..86317bcea7e03c290dc2736e2c226409688b3030 100644 (file)
 
 WaveConfig::WaveConfig()
 {
-       reset();
+       reset(RESET_ALL);
 }
 
 
-void WaveConfig::reset()
+void WaveConfig::reset(int clear)
 {
-       mode = SMEAR;
-       reflective = 0;
-       amplitude = 10;
-       phase = 0;
-       wavelength = 10;
+       switch(clear) {
+               case RESET_ALL :
+                       mode = SMEAR;
+                       reflective = 0;
+                       amplitude = 0;
+                       phase = 0;
+                       wavelength = 0;
+                       break;
+               case RESET_AMPLITUDE : amplitude = 0;
+                       break;
+               case RESET_PHASE : phase = 0;
+                       break;
+               case RESET_WAVELENGTH : wavelength = 0;
+                       break;
+               case RESET_DEFAULT_SETTINGS :
+               default:
+                       mode = SMEAR;
+                       reflective = 0;
+                       amplitude = 10;
+                       phase = 0;
+                       wavelength = 10;
+                       break;
+       }
 }
 
 void WaveConfig::copy_from(WaveConfig &src)
@@ -134,65 +152,58 @@ int WaveReflective::handle_event()
 }
 
 
-WaveAmplitude::WaveAmplitude(WaveEffect *plugin, int x, int y)
- : BC_FSlider(x,
-                       y,
-                       0,
-                       200,
-                       200,
-                       (float)0,
-                       (float)100,
-                       plugin->config.amplitude)
+WaveFText::WaveFText(WaveWindow *gui, WaveEffect *plugin,
+       WaveFSlider *slider, float *output, int x, int y, float min, float max)
+ : BC_TumbleTextBox(gui, *output,
+       min, max, x, y, xS(60), 2)
 {
+       this->gui = gui;
        this->plugin = plugin;
+       this->output = output;
+       this->slider = slider;
+       this->min = min;
+       this->max = max;
+       set_increment(0.1);
+}
+
+WaveFText::~WaveFText()
+{
 }
-int WaveAmplitude::handle_event()
+
+int WaveFText::handle_event()
 {
-       plugin->config.amplitude = get_value();
+       *output = atof(get_text());
+       if(*output > max) *output = max;
+       if(*output < min) *output = min;
+       slider->update(*output);
        plugin->send_configure_change();
        return 1;
 }
 
 
-
-WavePhase::WavePhase(WaveEffect *plugin, int x, int y)
- : BC_FSlider(x,
-                       y,
-                       0,
-                       200,
-                       200,
-                       (float)0,
-                       (float)360,
-                       plugin->config.phase)
+WaveFSlider::WaveFSlider(WaveEffect *plugin,
+       WaveFText *text, float *output, int x, int y, float min, float max)
+ : BC_FSlider(x, y, 0, xS(180), xS(180), min, max, *output)
 {
        this->plugin = plugin;
-}
-int WavePhase::handle_event()
-{
-       plugin->config.phase = get_value();
-       plugin->send_configure_change();
-       return 1;
+       this->output = output;
+       this->text = text;
+       enable_show_value(0); // Hide caption
 }
 
-WaveLength::WaveLength(WaveEffect *plugin, int x, int y)
- : BC_FSlider(x,
-                       y,
-                       0,
-                       200,
-                       200,
-                       (float)0,
-                       (float)50,
-                       plugin->config.wavelength)
+WaveFSlider::~WaveFSlider()
 {
-       this->plugin = plugin;
 }
-int WaveLength::handle_event()
+
+int WaveFSlider::handle_event()
 {
-       plugin->config.wavelength = get_value();
+       *output = get_value();
+       text->update(*output);
        plugin->send_configure_change();
        return 1;
 }
 
+
 WaveReset::WaveReset(WaveEffect *plugin, WaveWindow *gui, int x, int y)
  : BC_GenericButton(x, y, _("Reset"))
 {
@@ -204,20 +215,55 @@ WaveReset::~WaveReset()
 }
 int WaveReset::handle_event()
 {
-       plugin->config.reset();
-       gui->update();
+       plugin->config.reset(RESET_ALL);
+       gui->update_gui(RESET_ALL);
        plugin->send_configure_change();
        return 1;
 }
 
+WaveDefaultSettings::WaveDefaultSettings(WaveEffect *plugin, WaveWindow *gui, int x, int y, int w)
+ : BC_GenericButton(x, y, w, _("Default"))
+{
+       this->plugin = plugin;
+       this->gui = gui;
+}
+WaveDefaultSettings::~WaveDefaultSettings()
+{
+}
+int WaveDefaultSettings::handle_event()
+{
+       plugin->config.reset(RESET_DEFAULT_SETTINGS);
+       gui->update_gui(RESET_DEFAULT_SETTINGS);
+       plugin->send_configure_change();
+       return 1;
+}
 
-
+WaveClr::WaveClr(WaveEffect *plugin, WaveWindow *gui, int x, int y, int clear)
+ : BC_Button(x, y, plugin->get_theme()->get_image_set("reset_button"))
+{
+       this->plugin = plugin;
+       this->gui = gui;
+       this->clear = clear;
+}
+WaveClr::~WaveClr()
+{
+}
+int WaveClr::handle_event()
+{
+       // clear==1 ==> Amplitude slider
+       // clear==2 ==> Phase slider
+       // clear==3 ==> Steps slider
+       plugin->config.reset(clear);
+       gui->update_gui(clear);
+       plugin->send_configure_change();
+       return 1;
+}
 
 
 
 
 WaveWindow::WaveWindow(WaveEffect *plugin)
- : PluginClientWindow(plugin, 335, 140, 335, 140, 0)
+ : PluginClientWindow(plugin, xS(420), yS(160), xS(420), yS(160), 0)
 {
        this->plugin = plugin;
 }
@@ -228,25 +274,64 @@ WaveWindow::~WaveWindow()
 
 void WaveWindow::create_objects()
 {
-       int x = 10, y = 10, x1 = 115;
+       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(100), x3 = xS(200);
+       int clr_x = get_w()-x - xS(22); // note: clrBtn_w = 22
+       int defaultBtn_w = xs100;
+
+       BC_Bar *bar;
 
 //     add_subwindow(new BC_Title(x, y, _("Mode:")));
 //     add_subwindow(smear = new WaveSmear(plugin, this, x1, y));
-//     y += 20;
+//     y += ys20;
 //     add_subwindow(blacken = new WaveBlacken(plugin, this, x1, y));
-//     y += 30;
+//     y += ys30;
 //     add_subwindow(reflective = new WaveReflective(plugin, x1, y));
-//     y += 30;
+//     y += ys30;
+
+       y += ys10;
        add_subwindow(new BC_Title(x, y, _("Amplitude:")));
-       add_subwindow(amplitude = new WaveAmplitude(plugin, x1, y));
-       y += 30;
+       amplitude_text = new WaveFText(this, plugin,
+               0, &plugin->config.amplitude, (x + x2), y, AMPLITUDE_MIN, AMPLITUDE_MAX);
+       amplitude_text->create_objects();
+       amplitude_slider = new WaveFSlider(plugin,
+               amplitude_text, &plugin->config.amplitude, x3, y, AMPLITUDE_MIN, AMPLITUDE_MAX);
+       add_subwindow(amplitude_slider);
+       amplitude_text->slider = amplitude_slider;
+       clr_x = x3 + amplitude_slider->get_w() + x;
+       add_subwindow(amplitude_Clr = new WaveClr(plugin, this, clr_x, y, RESET_AMPLITUDE));
+       y += ys30;
+
        add_subwindow(new BC_Title(x, y, _("Phase:")));
-       add_subwindow(phase = new WavePhase(plugin, x1, y));
-       y += 30;
+       phase_text = new WaveFText(this, plugin,
+               0, &plugin->config.phase, (x + x2), y, PHASE_MIN, PHASE_MAX);
+       phase_text->create_objects();
+       phase_slider = new WaveFSlider(plugin,
+               phase_text, &plugin->config.phase, x3, y, PHASE_MIN, PHASE_MAX);
+       add_subwindow(phase_slider);
+       phase_text->slider = phase_slider;
+       add_subwindow(phase_Clr = new WaveClr(plugin, this, clr_x, y, RESET_PHASE));
+       y += ys30;
+
        add_subwindow(new BC_Title(x, y, _("Wavelength:")));
-       add_subwindow(wavelength = new WaveLength(plugin, x1, y));
-       y += 40;
+       wavelength_text = new WaveFText(this, plugin,
+               0, &plugin->config.wavelength, (x + x2), y, WAVELENGTH_MIN, WAVELENGTH_MAX);
+       wavelength_text->create_objects();
+       wavelength_slider = new WaveFSlider(plugin,
+               wavelength_text, &plugin->config.wavelength, x3, y, WAVELENGTH_MIN, WAVELENGTH_MAX);
+       add_subwindow(wavelength_slider);
+       wavelength_text->slider = wavelength_slider;
+       add_subwindow(wavelength_Clr = new WaveClr(plugin, this, clr_x, y, RESET_WAVELENGTH));
+       y += ys40;
+
+// Reset section
+       add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
+       y += ys10;
        add_subwindow(reset = new WaveReset(plugin, this, x, y));
+       add_subwindow(default_settings = new WaveDefaultSettings(plugin, this,
+               (get_w() - xs10 - defaultBtn_w), y, defaultBtn_w));
 
        show_window();
        flush();
@@ -259,11 +344,32 @@ void WaveWindow::update_mode()
 }
 
 // for Reset button
-void WaveWindow::update()
+void WaveWindow::update_gui(int clear)
 {
-       amplitude->update(plugin->config.amplitude);
-       phase->update(plugin->config.phase);
-       wavelength->update(plugin->config.wavelength);
+       switch(clear) {
+               case RESET_AMPLITUDE :
+                       amplitude_text->update(plugin->config.amplitude);
+                       amplitude_slider->update(plugin->config.amplitude);
+                       break;
+               case RESET_PHASE :
+                       phase_text->update(plugin->config.phase);
+                       phase_slider->update(plugin->config.phase);
+                       break;
+               case RESET_WAVELENGTH :
+                       wavelength_text->update(plugin->config.wavelength);
+                       wavelength_slider->update(plugin->config.wavelength);
+                       break;
+               case RESET_ALL :
+               case RESET_DEFAULT_SETTINGS :
+               default:
+                       amplitude_text->update(plugin->config.amplitude);
+                       amplitude_slider->update(plugin->config.amplitude);
+                       phase_text->update(plugin->config.phase);
+                       phase_slider->update(plugin->config.phase);
+                       wavelength_text->update(plugin->config.wavelength);
+                       wavelength_slider->update(plugin->config.wavelength);
+                       break;
+       }
 }
 
 
@@ -310,9 +416,12 @@ void WaveEffect::update_gui()
                load_configuration();
                ((WaveWindow*)thread->window)->update_mode();
 //             thread->window->reflective->update(config.reflective);
-               ((WaveWindow*)thread->window)->amplitude->update(config.amplitude);
-               ((WaveWindow*)thread->window)->phase->update(config.phase);
-               ((WaveWindow*)thread->window)->wavelength->update(config.wavelength);
+               ((WaveWindow*)thread->window)->amplitude_text->update(config.amplitude);
+               ((WaveWindow*)thread->window)->amplitude_slider->update(config.amplitude);
+               ((WaveWindow*)thread->window)->phase_text->update(config.phase);
+               ((WaveWindow*)thread->window)->phase_slider->update(config.phase);
+               ((WaveWindow*)thread->window)->wavelength_text->update(config.wavelength);
+               ((WaveWindow*)thread->window)->wavelength_slider->update(config.wavelength);
                thread->window->unlock_window();
        }
 }