modify clr btn 16 plugins, add regdmp for sigtraps, rework mask_engine, mask rotate...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / huesaturation / huesaturation.C
index 727f54f26d28b5a12dee0925d12a454e7565b301..ce1e1512dc28849f982712f1914ece4a5f92aeb5 100644 (file)
 #include "clip.h"
 #include "bchash.h"
 #include "filexml.h"
+#include "huesaturation.h"
 #include "guicast.h"
 #include "language.h"
 #include "loadbalance.h"
 #include "bccolors.h"
 #include "playback3d.h"
 #include "pluginvclient.h"
+#include "theme.h"
 #include "vframe.h"
 
 #include <stdint.h>
 #include <string.h>
 
 
-class HueEffect;
 
-#define MINHUE -180
-#define MAXHUE 180
-#define MINSATURATION -100
-#define MAXSATURATION 100
-#define MINVALUE -100
-#define MAXVALUE 100
-
-
-
-
-
-
-class HueConfig
-{
-public:
-       HueConfig();
-
-       void copy_from(HueConfig &src);
-       int equivalent(HueConfig &src);
-       void interpolate(HueConfig &prev,
-               HueConfig &next,
-               long prev_frame,
-               long next_frame,
-               long current_frame);
-       float hue, saturation, value;
-};
-
-class HueSlider : public BC_FSlider
-{
-public:
-       HueSlider(HueEffect *plugin, int x, int y, int w);
-       int handle_event();
-       HueEffect *plugin;
-};
-
-class SaturationSlider : public BC_FSlider
-{
-public:
-       SaturationSlider(HueEffect *plugin, int x, int y, int w);
-       int handle_event();
-       char* get_caption();
-       HueEffect *plugin;
-       char string[BCTEXTLEN];
-};
-
-class ValueSlider : public BC_FSlider
-{
-public:
-       ValueSlider(HueEffect *plugin, int x, int y, int w);
-       int handle_event();
-       char* get_caption();
-       HueEffect *plugin;
-       char string[BCTEXTLEN];
-};
-
-class HueWindow : public PluginClientWindow
-{
-public:
-       HueWindow(HueEffect *plugin);
-       void create_objects();
-       HueEffect *plugin;
-       HueSlider *hue;
-       SaturationSlider *saturation;
-       ValueSlider *value;
-};
+REGISTER_PLUGIN(HueEffect)
 
 
 
-class HueEngine : public LoadServer
-{
-public:
-       HueEngine(HueEffect *plugin, int cpus);
-       void init_packages();
-       LoadClient* new_client();
-       LoadPackage* new_package();
-       HueEffect *plugin;
-};
 
-class HuePackage : public LoadPackage
-{
-public:
-       HuePackage();
-       int row1, row2;
-};
-
-class HueUnit : public LoadClient
-{
-public:
-       HueUnit(HueEffect *plugin, HueEngine *server);
-       void process_package(LoadPackage *package);
-       HueEffect *plugin;
-};
 
-class HueEffect : public PluginVClient
+HueConfig::HueConfig()
 {
-public:
-       HueEffect(PluginServer *server);
-       ~HueEffect();
-
-
-       PLUGIN_CLASS_MEMBERS(HueConfig);
-       int process_buffer(VFrame *frame,
-               int64_t start_position,
-               double frame_rate);
-       int is_realtime();
-       void save_data(KeyFrame *keyframe);
-       void read_data(KeyFrame *keyframe);
-       void update_gui();
-       int handle_opengl();
-
-       VFrame *input, *output;
-       HueEngine *engine;
-};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+       reset(RESET_ALL);
+}
 
-HueConfig::HueConfig()
+void HueConfig::reset(int clear)
 {
-       hue = saturation = value = 0;
+       switch(clear) {
+               case RESET_HUV : hue = 0;
+                       break;
+               case RESET_SAT : saturation = 0;
+                       break;
+               case RESET_VAL : value = 0;
+                       break;
+               case RESET_ALL :
+               default:
+                       hue = saturation = value = 0;
+                       break;
+       }
 }
 
 void HueConfig::copy_from(HueConfig &src)
@@ -294,33 +184,98 @@ char* ValueSlider::get_caption()
 }
 
 
+HueReset::HueReset(HueEffect *plugin, HueWindow *gui, int x, int y)
+ : BC_GenericButton(x, y, _("Reset"))
+{
+       this->plugin = plugin;
+       this->gui = gui;
+}
+HueReset::~HueReset()
+{
+}
+int HueReset::handle_event()
+{
+       plugin->config.reset(RESET_ALL); // clear=0 ==> reset all
+       gui->update_gui(RESET_ALL);
+       plugin->send_configure_change();
+       return 1;
+}
 
 
+HueSliderClr::HueSliderClr(HueEffect *plugin, HueWindow *gui, 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->gui = gui;
+       this->clear = clear;
+}
+HueSliderClr::~HueSliderClr()
+{
+}
+int HueSliderClr::handle_event()
+{
+       // clear==1 ==> Hue slider
+       // clear==2 ==> Saturation slider
+       // clear==3 ==> Value slider
+       plugin->config.reset(clear);
+       gui->update_gui(clear);
+       plugin->send_configure_change();
+       return 1;
+}
+
 
 
 
 HueWindow::HueWindow(HueEffect *plugin)
- : PluginClientWindow(plugin, 345, 100, 345, 100, 0)
+ : PluginClientWindow(plugin, 370, 140, 370, 140, 0)
 {
        this->plugin = plugin;
 }
 void HueWindow::create_objects()
 {
        int x = 10, y = 10, x1 = 100;
+       int x2 = 0; int clrBtn_w = 50;
+
        add_subwindow(new BC_Title(x, y, _("Hue:")));
        add_subwindow(hue = new HueSlider(plugin, x1, y, 200));
+       x2 = x1 + hue->get_w() + 10;
+       add_subwindow(hueClr = new HueSliderClr(plugin, this, x2, y, clrBtn_w, RESET_HUV));
+
        y += 30;
        add_subwindow(new BC_Title(x, y, _("Saturation:")));
        add_subwindow(saturation = new SaturationSlider(plugin, x1, y, 200));
+       add_subwindow(satClr = new HueSliderClr(plugin, this, x2, y, clrBtn_w, RESET_SAT));
+
        y += 30;
        add_subwindow(new BC_Title(x, y, _("Value:")));
        add_subwindow(value = new ValueSlider(plugin, x1, y, 200));
+       add_subwindow(valClr = new HueSliderClr(plugin, this, x2, y, clrBtn_w, RESET_VAL));
+
+       y += 40;
+       add_subwindow(reset = new HueReset(plugin, this, x, y));
        show_window();
        flush();
 }
 
 
-
+// for Reset button
+void HueWindow::update_gui(int clear)
+{
+       switch(clear) {
+               case RESET_HUV : hue->update(plugin->config.hue);
+                       break;
+               case RESET_SAT : saturation->update(plugin->config.saturation);
+                       break;
+               case RESET_VAL : value->update(plugin->config.value);
+                       break;
+               case RESET_ALL :
+               default:
+                       hue->update(plugin->config.hue);
+                       saturation->update(plugin->config.saturation);
+                       value->update(plugin->config.value);
+                       break;
+       }
+}
 
 
 
@@ -519,7 +474,6 @@ void HueUnit::process_package(LoadPackage *package)
 
 
 
-REGISTER_PLUGIN(HueEffect)
 
 
 HueEffect::HueEffect(PluginServer *server)