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 <vector>
22 
23 #include <gtkmm.h>
24 
25 #include "cursormanager.h"
26 #include "curvelistener.h"
27 #include "mycurve.h"
28 
29 #include "../rtengine/diagonalcurvetypes.h"
30 
31 template<typename T>
32 class LUT;
33 
34 using LUTf = LUT<float>;
35 
36 class DiagonalCurveDescr
37 {
38 
39 public:
40     DiagonalCurveType type;
41     std::vector<double> x, y;   // in case of parametric curves the curve parameters are stored in vector x. In other cases these vectors store the coordinates of the bullets.
42 };
43 
44 class MyDiagonalCurve : public MyCurve
45 {
46 private:
47     IdleRegister idle_register;
48 
49 protected:
50     DiagonalCurveDescr curve;
51     int grab_point;     // the point that the user is moving by mouse
52     int closest_point;  // the point that is the closest from the cursor
53     int lit_point;      // the point that is lit when the cursor is near it
54     double clampedX;    // clamped grabbed point X coordinates in the [0;1] range
55     double clampedY;    // clamped grabbed point Y coordinates in the [0;1] range
56     double deltaX;      // signed X distance of the cursor between two consecutive MOTION_NOTIFY
57     double deltaY;      // signed Y distance of the cursor between two consecutive MOTION_NOTIFY
58     double distanceX;   // X distance from the cursor to the closest point
59     double distanceY;   // Y distance from the cursor to the closest point
60     double ugpX;        // unclamped grabbed point X coordinate in the graph
61     double ugpY;        // unclamped grabbed point Y coordinate in the graph
62     int activeParam;
63     unsigned int* bghist;   // histogram values
64     bool bghistvalid;
65 
66     void draw (int handle);
67     void interpolate ();
68     void findClosestPoint();
69     CursorShape motionNotify(CursorShape type, double minDistanceX, double minDistanceY, int num);
70     std::vector<double> get_vector (int veclen) override;
71     void get_LUT (LUTf &lut);
72     // Get the cursor position and unclamped position from the curve given an X value ; BEWARE: can be time consuming, use with care
73     void getCursorPositionFromCurve(float x);
74     void getCursorPositionFromCurve(int x);
75     // Get the cursor position and unclamped value depending on cursor's position in the graph
76     void getCursorPosition(Gdk::EventType evType, bool isHint, int evX, int evY, Gdk::ModifierType modifierKey);
77 
78 public:
79     MyDiagonalCurve ();
80     ~MyDiagonalCurve () override;
81     std::vector<double> getPoints () override;
82     void setPoints (const std::vector<double>& p) override;
83     void setType (DiagonalCurveType t);
84     bool on_draw(const ::Cairo::RefPtr< Cairo::Context> &cr) override;
85     bool handleEvents (GdkEvent* event) override;
86     void setActiveParam (int ac);
87     void reset (const std::vector<double> &resetCurve, double identityValue = 0.5) override;
88     void updateBackgroundHistogram (const LUTu & hist);
89 
90     void pipetteMouseOver (CurveEditor *ce, EditDataProvider *provider, int modifierKey) override;
91     bool pipetteButton1Pressed(EditDataProvider *provider, int modifierKey) override;
92     void pipetteButton1Released(EditDataProvider *provider) override;
93     void pipetteDrag(EditDataProvider *provider, int modifierKey) override;
94 
95     void setPos(double pos, int chanIdx) override;
96     void stopNumericalAdjustment() override;
97 };
98