Apply astyle to rtgui/controllines.*
This commit is contained in:
@@ -43,10 +43,14 @@ ControlLineManager::ControlLineManager():
|
||||
canvas_area->topLeft = Coord(0, 0);
|
||||
mouseOverGeometry.push_back(canvas_area.get());
|
||||
|
||||
line_icon_h = Cairo::RefPtr<RTSurface>(new RTSurface("bidirectional-arrow-horizontal-hicontrast.png"));
|
||||
line_icon_v = Cairo::RefPtr<RTSurface>(new RTSurface("bidirectional-arrow-vertical-hicontrast.png"));
|
||||
line_icon_h_prelight = Cairo::RefPtr<RTSurface>(new RTSurface("bidirectional-arrow-horizontal-prelight.png"));
|
||||
line_icon_v_prelight = Cairo::RefPtr<RTSurface>(new RTSurface("bidirectional-arrow-vertical-prelight.png"));
|
||||
line_icon_h = Cairo::RefPtr<RTSurface>(new RTSurface(
|
||||
"bidirectional-arrow-horizontal-hicontrast.png"));
|
||||
line_icon_v = Cairo::RefPtr<RTSurface>(new RTSurface(
|
||||
"bidirectional-arrow-vertical-hicontrast.png"));
|
||||
line_icon_h_prelight = Cairo::RefPtr<RTSurface>(new RTSurface(
|
||||
"bidirectional-arrow-horizontal-prelight.png"));
|
||||
line_icon_v_prelight = Cairo::RefPtr<RTSurface>(new RTSurface(
|
||||
"bidirectional-arrow-vertical-prelight.png"));
|
||||
}
|
||||
|
||||
ControlLineManager::~ControlLineManager() = default;
|
||||
@@ -91,6 +95,7 @@ bool ControlLineManager::button1Pressed(int modifierKey)
|
||||
drag_delta = Coord(0, 0);
|
||||
|
||||
const int object = dataProvider->getObject();
|
||||
|
||||
if (object > 0) { // A control line.
|
||||
if (object % ::ControlLine::OBJ_COUNT == 2) { // Icon.
|
||||
action = Action::PICKING;
|
||||
@@ -111,9 +116,11 @@ bool ControlLineManager::button1Pressed(int modifierKey)
|
||||
bool ControlLineManager::button1Released(void)
|
||||
{
|
||||
action = Action::NONE;
|
||||
|
||||
if (selected_object > 0) {
|
||||
mouseOverGeometry[selected_object]->state = Geometry::NORMAL;
|
||||
}
|
||||
|
||||
edited = true;
|
||||
callbacks->lineChanged();
|
||||
drawing_line = false;
|
||||
@@ -151,7 +158,8 @@ bool ControlLineManager::pick1(bool picked)
|
||||
|
||||
// Change line type.
|
||||
int object_id = provider->getObject();
|
||||
::ControlLine& line = *control_lines[(object_id - 1) / ::ControlLine::OBJ_COUNT];
|
||||
::ControlLine& line =
|
||||
*control_lines[(object_id - 1) / ::ControlLine::OBJ_COUNT];
|
||||
|
||||
if (line.type == rtengine::ControlLine::HORIZONTAL) {
|
||||
line.icon = line.icon_v;
|
||||
@@ -197,8 +205,10 @@ bool ControlLineManager::drag1(int modifierKey)
|
||||
return false;
|
||||
}
|
||||
|
||||
::ControlLine& control_line = *control_lines[(selected_object - 1) / ::ControlLine::OBJ_COUNT];
|
||||
int component = selected_object % ::ControlLine::OBJ_COUNT; // 0 == end, 1 == line, 2 == icon, 3 == begin
|
||||
::ControlLine& control_line =
|
||||
*control_lines[(selected_object - 1) / ::ControlLine::OBJ_COUNT];
|
||||
// 0 == end, 1 == line, 2 == icon, 3 == begin
|
||||
int component = selected_object % ::ControlLine::OBJ_COUNT;
|
||||
Coord mouse = provider->posImage + provider->deltaImage;
|
||||
Coord delta = provider->deltaImage - drag_delta;
|
||||
int ih, iw;
|
||||
@@ -211,6 +221,7 @@ bool ControlLineManager::drag1(int modifierKey)
|
||||
control_line.line->end = control_line.end->center;
|
||||
control_line.end->state = Geometry::DRAGGED;
|
||||
break;
|
||||
|
||||
case (1): { // line
|
||||
// Constrain delta so the end stays above the image.
|
||||
Coord new_delta = control_line.end->center + delta;
|
||||
@@ -229,6 +240,7 @@ bool ControlLineManager::drag1(int modifierKey)
|
||||
control_line.line->state = Geometry::DRAGGED;
|
||||
break;
|
||||
}
|
||||
|
||||
case (3): // begin
|
||||
control_line.begin->center = mouse;
|
||||
control_line.begin->center.clip(iw, ih);
|
||||
@@ -237,8 +249,10 @@ bool ControlLineManager::drag1(int modifierKey)
|
||||
break;
|
||||
}
|
||||
|
||||
control_line.icon_h->position.x = (control_line.begin->center.x + control_line.end->center.x) / 2;
|
||||
control_line.icon_h->position.y = (control_line.begin->center.y + control_line.end->center.y) / 2;
|
||||
control_line.icon_h->position.x = (control_line.begin->center.x +
|
||||
control_line.end->center.x) / 2;
|
||||
control_line.icon_h->position.y = (control_line.begin->center.y +
|
||||
control_line.end->center.y) / 2;
|
||||
control_line.icon_v->position.x = control_line.icon_h->position.x;
|
||||
control_line.icon_v->position.y = control_line.icon_h->position.y;
|
||||
|
||||
@@ -288,6 +302,7 @@ bool ControlLineManager::mouseOver(int modifierKey)
|
||||
if (prev_obj != cur_obj && prev_obj > 0) {
|
||||
visibleGeometry[prev_obj - 1]->state = Geometry::NORMAL;
|
||||
}
|
||||
|
||||
prev_obj = cur_obj;
|
||||
|
||||
return true;
|
||||
@@ -310,9 +325,11 @@ void ControlLineManager::setEditProvider(EditDataProvider* provider)
|
||||
EditSubscriber::setEditProvider(provider);
|
||||
}
|
||||
|
||||
void ControlLineManager::setLines(const std::vector<rtengine::ControlLine>& lines)
|
||||
void ControlLineManager::setLines(const std::vector<rtengine::ControlLine>&
|
||||
lines)
|
||||
{
|
||||
removeAll();
|
||||
|
||||
for (auto&& line : lines) {
|
||||
Coord start(line.x1, line.y1);
|
||||
Coord end(line.x2, line.y2);
|
||||
@@ -320,7 +337,8 @@ void ControlLineManager::setLines(const std::vector<rtengine::ControlLine>& line
|
||||
}
|
||||
}
|
||||
|
||||
void ControlLineManager::addLine(Coord begin, Coord end, rtengine::ControlLine::Type type)
|
||||
void ControlLineManager::addLine(Coord begin, Coord end,
|
||||
rtengine::ControlLine::Type type)
|
||||
{
|
||||
constexpr int line_width = 2;
|
||||
constexpr int handle_radius = 6;
|
||||
@@ -334,14 +352,19 @@ void ControlLineManager::addLine(Coord begin, Coord end, rtengine::ControlLine::
|
||||
line->begin = begin;
|
||||
line->end = end;
|
||||
|
||||
const Cairo::RefPtr<RTSurface> null_surface = Cairo::RefPtr<RTSurface>(nullptr);
|
||||
const Cairo::RefPtr<RTSurface> null_surface =
|
||||
Cairo::RefPtr<RTSurface>(nullptr);
|
||||
|
||||
icon_h = std::make_shared<OPIcon>(line_icon_h, null_surface, line_icon_h_prelight,
|
||||
null_surface, null_surface, Geometry::DP_CENTERCENTER);
|
||||
icon_h = std::make_shared<OPIcon>(line_icon_h, null_surface,
|
||||
line_icon_h_prelight,
|
||||
null_surface, null_surface,
|
||||
Geometry::DP_CENTERCENTER);
|
||||
icon_h->position = Coord((begin.x + end.x) / 2, (begin.y + end.y) / 2);
|
||||
|
||||
icon_v = std::make_shared<OPIcon>(line_icon_v, null_surface, line_icon_v_prelight,
|
||||
null_surface, null_surface, Geometry::DP_CENTERCENTER);
|
||||
icon_v = std::make_shared<OPIcon>(line_icon_v, null_surface,
|
||||
line_icon_v_prelight,
|
||||
null_surface, null_surface,
|
||||
Geometry::DP_CENTERCENTER);
|
||||
icon_v->position = Coord((begin.x + end.x) / 2, (begin.y + end.y) / 2);
|
||||
|
||||
begin_c = std::unique_ptr<Circle>(new Circle());
|
||||
@@ -361,11 +384,13 @@ void ControlLineManager::addLine(Coord begin, Coord end, rtengine::ControlLine::
|
||||
control_line->end = std::move(end_c);
|
||||
control_line->icon_h = icon_h;
|
||||
control_line->icon_v = icon_v;
|
||||
|
||||
if (type == rtengine::ControlLine::HORIZONTAL) {
|
||||
control_line->icon = icon_h;
|
||||
} else {
|
||||
control_line->icon = icon_v;
|
||||
}
|
||||
|
||||
control_line->line = std::move(line);
|
||||
control_line->type = type;
|
||||
|
||||
@@ -393,6 +418,7 @@ void ControlLineManager::autoSetLineType(int object_id)
|
||||
if (dx < 0) {
|
||||
dx = -dx;
|
||||
}
|
||||
|
||||
if (dy < 0) {
|
||||
dy = -dy;
|
||||
}
|
||||
@@ -411,14 +437,16 @@ void ControlLineManager::autoSetLineType(int object_id)
|
||||
if (type != line.type) { // Need to update line type.
|
||||
line.type = type;
|
||||
line.icon = icon;
|
||||
visibleGeometry[line_id * ::ControlLine::OBJ_COUNT + 1] = line.icon.get();
|
||||
visibleGeometry[line_id * ::ControlLine::OBJ_COUNT + 1] =
|
||||
line.icon.get();
|
||||
}
|
||||
}
|
||||
|
||||
void ControlLineManager::removeAll(void)
|
||||
{
|
||||
visibleGeometry.clear();
|
||||
mouseOverGeometry.erase(mouseOverGeometry.begin() + 1, mouseOverGeometry.end());
|
||||
mouseOverGeometry.erase(mouseOverGeometry.begin() + 1,
|
||||
mouseOverGeometry.end());
|
||||
control_lines.clear();
|
||||
prev_obj = -1;
|
||||
selected_object = -1;
|
||||
@@ -432,17 +460,24 @@ void ControlLineManager::removeLine(size_t line_id)
|
||||
return;
|
||||
}
|
||||
|
||||
visibleGeometry.erase(visibleGeometry.begin() + ::ControlLine::OBJ_COUNT * line_id,
|
||||
visibleGeometry.begin() + ::ControlLine::OBJ_COUNT * line_id + ::ControlLine::OBJ_COUNT);
|
||||
mouseOverGeometry.erase(mouseOverGeometry.begin() + ::ControlLine::OBJ_COUNT * line_id + 1,
|
||||
mouseOverGeometry.begin() + ::ControlLine::OBJ_COUNT * line_id + ::ControlLine::OBJ_COUNT + 1);
|
||||
visibleGeometry.erase(
|
||||
visibleGeometry.begin() + ::ControlLine::OBJ_COUNT * line_id,
|
||||
visibleGeometry.begin() + ::ControlLine::OBJ_COUNT * line_id
|
||||
+ ::ControlLine::OBJ_COUNT
|
||||
);
|
||||
mouseOverGeometry.erase(
|
||||
mouseOverGeometry.begin() + ::ControlLine::OBJ_COUNT * line_id + 1,
|
||||
mouseOverGeometry.begin() + ::ControlLine::OBJ_COUNT * line_id
|
||||
+ ::ControlLine::OBJ_COUNT + 1
|
||||
);
|
||||
control_lines.erase(control_lines.begin() + line_id);
|
||||
|
||||
edited = true;
|
||||
callbacks->lineChanged();
|
||||
}
|
||||
|
||||
void ControlLineManager::toControlLines(std::vector<rtengine::ControlLine>& converted) const
|
||||
void ControlLineManager::toControlLines(std::vector<rtengine::ControlLine>&
|
||||
converted) const
|
||||
{
|
||||
converted.clear();
|
||||
converted.resize(control_lines.size());
|
||||
|
@@ -29,8 +29,7 @@ class OPIcon;
|
||||
class Rectangle;
|
||||
class RTSurface;
|
||||
|
||||
struct ControlLine
|
||||
{
|
||||
struct ControlLine {
|
||||
static constexpr int OBJ_COUNT = 4;
|
||||
std::unique_ptr<Line> line;
|
||||
std::shared_ptr<OPIcon> icon;
|
||||
@@ -58,8 +57,8 @@ protected:
|
||||
int prev_obj;
|
||||
int selected_object;
|
||||
|
||||
void addLine (rtengine::Coord begin, rtengine::Coord end,
|
||||
rtengine::ControlLine::Type type = rtengine::ControlLine::VERTICAL);
|
||||
void addLine(rtengine::Coord begin, rtengine::Coord end,
|
||||
rtengine::ControlLine::Type type = rtengine::ControlLine::VERTICAL);
|
||||
/**
|
||||
* Set the line type of the line containing the object according to the
|
||||
* line's angle.
|
||||
@@ -68,7 +67,7 @@ protected:
|
||||
* line, inclusive, the line type is set to vertical. Otherwise, horizontal.
|
||||
*/
|
||||
void autoSetLineType(int object_id);
|
||||
void removeLine (size_t line_id);
|
||||
void removeLine(size_t line_id);
|
||||
|
||||
public:
|
||||
class Callbacks
|
||||
@@ -76,9 +75,9 @@ public:
|
||||
public:
|
||||
virtual ~Callbacks() {};
|
||||
/** Called when a line changed (added, removed, moved, etc.). */
|
||||
virtual void lineChanged (void) {};
|
||||
virtual void lineChanged(void) {};
|
||||
/** Called when the EditSubscriber's switchOffEditMode is called. */
|
||||
virtual void switchOffEditMode (void) {};
|
||||
virtual void switchOffEditMode(void) {};
|
||||
};
|
||||
|
||||
/** Callbacks to invoke. */
|
||||
@@ -87,30 +86,30 @@ public:
|
||||
ControlLineManager();
|
||||
~ControlLineManager();
|
||||
|
||||
bool getEdited (void) const;
|
||||
void removeAll (void);
|
||||
bool getEdited(void) const;
|
||||
void removeAll(void);
|
||||
/** Sets whether or not the lines are visible and interact-able. */
|
||||
void setActive (bool active);
|
||||
void setActive(bool active);
|
||||
/** Set whether or not lines can be drawn and deleted. */
|
||||
void setDrawMode (bool draw);
|
||||
void setEdited (bool edited);
|
||||
void setEditProvider (EditDataProvider* provider);
|
||||
void setLines (const std::vector<rtengine::ControlLine>& lines);
|
||||
void setDrawMode(bool draw);
|
||||
void setEdited(bool edited);
|
||||
void setEditProvider(EditDataProvider* provider);
|
||||
void setLines(const std::vector<rtengine::ControlLine>& lines);
|
||||
/** Returns the number of lines. */
|
||||
size_t size (void) const;
|
||||
size_t size(void) const;
|
||||
/**
|
||||
* Allocates a new array and populates it with copies of the control lines.
|
||||
*/
|
||||
void toControlLines (std::vector<rtengine::ControlLine>& converted) const;
|
||||
void toControlLines(std::vector<rtengine::ControlLine>& converted) const;
|
||||
|
||||
// EditSubscriber overrides
|
||||
bool button1Pressed (int modifierKey) override;
|
||||
bool button1Released (void) override;
|
||||
bool button3Pressed (int modifierKey) override;
|
||||
bool pick1 (bool picked) override;
|
||||
bool pick3 (bool picked) override;
|
||||
bool drag1 (int modifierKey) override;
|
||||
CursorShape getCursor (int objectID) const override;
|
||||
bool mouseOver (int modifierKey) override;
|
||||
void switchOffEditMode (void) override;
|
||||
bool button1Pressed(int modifierKey) override;
|
||||
bool button1Released(void) override;
|
||||
bool button3Pressed(int modifierKey) override;
|
||||
bool pick1(bool picked) override;
|
||||
bool pick3(bool picked) override;
|
||||
bool drag1(int modifierKey) override;
|
||||
CursorShape getCursor(int objectID) const override;
|
||||
bool mouseOver(int modifierKey) override;
|
||||
void switchOffEditMode(void) override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user