1 /** -*- C++ -*-
2  *
3  *  This file is part of RawTherapee.
4  *
5  *  Copyright (c) 2018 Alberto Griggio <alberto.griggio@gmail.com>
6  *
7  *  RawTherapee is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  RawTherapee is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with RawTherapee.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 #pragma once
21 
22 #include <gtkmm.h>
23 #include "edit.h"
24 #include "../rtengine/procparams.h"
25 
26 
27 using rteMaskShape = rtengine::procparams::AreaMask::Shape;
28 using rteMaskRect = rtengine::procparams::AreaMask::Rectangle;
29 using rteMaskPoly = rtengine::procparams::AreaMask::Polygon;
30 
31 class AreaMask: public EditSubscriber {
32 public:
33     enum class DraggedElement {
34         NONE,
35         POINT,
36         ROUNDNESS,
37         SEGMENT,
38         WHOLE
39     };
40 
41     AreaMask();
42     ~AreaMask();
43 
44     CursorShape getCursor(int objectID) override;
45     bool mouseOver(int modifierKey) override;
46     bool button1Pressed(int modifierKey) override;
47     bool button1Released() override;
48     bool drag1(int modifierKey) override;
49     bool button3Pressed(int modifierKey) override;
50     bool pick3(bool picked) override;
51     bool scroll(int modifierKey, GdkScrollDirection direction, double deltaX, double deltaY, bool &propagateEvent) override;
52 
53     size_t getPolygonSize();
54     void setPolygon(const std::vector<rteMaskPoly::Knot> &new_poly);
55     std::vector<rteMaskPoly::Knot> getPolygon();
56     void clearPolygon();
57     void setGeometryType(rteMaskShape::Type newType);
58     rteMaskShape::Type getGeometryType();
59     void deleteGeometry();
60     void createRectangleGeometry();
61     void createPolygonGeometry();
62     void createGradientGeometry();
63     void updateGeometry(const int fullWidth=-1, const int fullHeight=-1);
64 
65 protected:
66     int last_object_;
67     double dragged_point_old_angle_;
68     double dragged_point_adjuster_angle_;
69     double dragged_feather_offset_;
70     rtengine::Coord dragged_center_;
71     double center_x_;
72     double center_y_;
73     double width_;
74     double height_;
75     double strength_start_;
76     double strength_end_;
77     double feather_;
78     double angle_;
79 
80     int top_id_;
81     int bottom_id_;
82     int left_id_;
83     int right_id_;
84     int rotate_w_id_;
85     int rotate_h_id_;
86     int center_id_;
87 
88     // Visible (and MouseOver) geometry for Polygon
89     Line *insertion_line;            // [0]    visible
90     PolyLine *curve;                 // [1]    visible
91     PolyLine *cage;                  // [2]    visible
92     std::vector<Line *> segments_MO;  // [3, n]           hoverable
93     Circle *sel_knot;                // [n+1]  visible / hoverable
94     Circle *sel_knot_bg_;
95     Circle *prev_knot;               // [n+2]  visible / hoverable
96     Circle *next_knot;               // [n+3]  visible / hoverable
97 
98     int hovered_line_id_;            // range identical to poly_knots_
99     int sel_poly_knot_id_;           // range identical to poly_knots_
100     int prev_poly_knot_id_;          // range identical to poly_knots_
101     int next_poly_knot_id_;          // range identical to poly_knots_
102     DraggedElement dragged_element_; // true if adjusting the Roundness value
103     std::vector<rtengine::CoordD> dragged_points_;  // copy of initial points for dragging and bounds handling
104 
105     // Gradient geometry IDs
106     int h_line_id_;
107     int v_line_id_;
108     int feather_line1_id_;
109     int feather_line2_id_;
110     int center_circle_id_;
111 
112 private:
113     void setPolylineSize(size_t newSize);
114     void initHoverGeometry();
115 
116     std::vector<rteMaskPoly::Knot> poly_knots_;
117     rteMaskShape::Type geomType;
118 };
119