1 /*
2  *  This file is part of RawTherapee.
3  *
4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
5  *
6  *  RawTherapee is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  RawTherapee is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 #pragma once
20 
21 #include <gtkmm.h>
22 
23 #include "coloredbar.h"
24 
25 class SHCListener
26 {
27 public:
28     virtual ~SHCListener() = default;
29     virtual void shcChanged() = 0;
30 };
31 
32 class SHCSelector : public Gtk::DrawingArea, BackBuffer
33 {
34 
35 protected:
36 
37     int movingPosition;
38     double tmpX, tmpPos;
39 
40     double defaults[3];
41     double positions[3];
42     double wslider;
43 
44     // left margin, essentially a workaround to take care of an eventual right colored bar (e.g. for curves)
45     int leftMargin;
46     // right margin, essentially a workaround to take care of an eventual right colored bar
47     int rightMargin;
48 
49     const static int hb = 3;  // horizontal border
50     const static int vb = 4;  // vertical border
51 
52     SHCListener* cl;
53 
54     Gtk::SizeRequestMode get_request_mode_vfunc () const override;
55     void get_preferred_height_vfunc (int& minimum_height, int& natural_height) const override;
56     void get_preferred_width_vfunc (int &minimum_width, int &natural_width) const override;
57     void get_preferred_height_for_width_vfunc (int width, int &minimum_height, int &natural_height) const override;
58     void get_preferred_width_for_height_vfunc (int height, int &minimum_width, int &natural_width) const override;
59     void on_realize() override;
60     bool on_draw(const ::Cairo::RefPtr< Cairo::Context> &cr) override;
61     bool on_button_press_event (GdkEventButton* event) override;
62     bool on_button_release_event (GdkEventButton* event) override;
63     bool on_motion_notify_event (GdkEventMotion* event) override;
64     void updateBackBuffer();
65 
66 public:
67 
68     ColoredBar coloredBar;
69 
70     SHCSelector();
71 
setSHCListener(SHCListener * l)72     void setSHCListener (SHCListener* l)
73     {
74         cl = l;;
75     }
76 
77     void setMargins(int left, int right);
78     void setDefaults (double spos, double cpos, double hpos);
79     void setPositions (double spos, double cpos, double hpos);
80     void getPositions (double& spos, double& cpos, double& hpos);
81     void styleChanged (const Glib::RefPtr<Gtk::Style>& style);
82     bool reset ();
83     void refresh();
84 };
85