From 2c1e6a8ca165374cd505b8c8f5b0b3447e89c39a Mon Sep 17 00:00:00 2001 From: Lawrence Lee <45837045+Lawrence37@users.noreply.github.com> Date: Sun, 30 May 2021 18:02:29 -0700 Subject: [PATCH 1/2] Make control lines buttons react to line counts Set the "apply" and "delete all" button sensitivity based on the number of control lines. Add extra tooltip text to the apply button when editing and there is not enough lines. The text explains there must be enough vertical or horizontal control lines. --- rtdata/languages/default | 1 + rtgui/controllines.cc | 33 +++++++++++++++++++++++++++++++++ rtgui/controllines.h | 5 +++++ rtgui/perspective.cc | 23 +++++++++++++++++++++++ rtgui/perspective.h | 1 + 5 files changed, 63 insertions(+) diff --git a/rtdata/languages/default b/rtdata/languages/default index 773f7768b..821a6fb60 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -3320,6 +3320,7 @@ TP_PCVIGNETTE_ROUNDNESS_TOOLTIP;Roundness:\n0 = rectangle,\n50 = fitted ellipse, TP_PCVIGNETTE_STRENGTH;Strength TP_PCVIGNETTE_STRENGTH_TOOLTIP;Filter strength in stops (reached in corners). TP_PDSHARPENING_LABEL;Capture Sharpening +TP_PERSPECTIVE_CONTROL_LINE_APPLY_INVALID_TOOLTIP;At least two horizontal or two vertical control lines required. TP_PERSPECTIVE_CAMERA_CROP_FACTOR;Crop factor TP_PERSPECTIVE_CAMERA_FOCAL_LENGTH;Focal length TP_PERSPECTIVE_CAMERA_FRAME;Correction diff --git a/rtgui/controllines.cc b/rtgui/controllines.cc index c078b4322..e4ef9e9f7 100644 --- a/rtgui/controllines.cc +++ b/rtgui/controllines.cc @@ -36,6 +36,7 @@ ControlLineManager::ControlLineManager(): draw_mode(false), drawing_line(false), edited(false), + horizontalCount(0), verticalCount(0), prev_obj(-1), selected_object(-1) { @@ -84,6 +85,16 @@ size_t ControlLineManager::size(void) const return control_lines.size(); } +size_t ControlLineManager::getHorizontalCount(void) const +{ + return horizontalCount; +} + +size_t ControlLineManager::getVerticalCount(void) const +{ + return verticalCount; +} + bool ControlLineManager::button1Pressed(int modifierKey) { EditDataProvider* dataProvider = getEditProvider(); @@ -164,9 +175,13 @@ bool ControlLineManager::pick1(bool picked) if (line.type == rtengine::ControlLine::HORIZONTAL) { line.icon = line.icon_v; line.type = rtengine::ControlLine::VERTICAL; + horizontalCount--; + verticalCount++; } else if (line.type == rtengine::ControlLine::VERTICAL) { line.icon = line.icon_h; line.type = rtengine::ControlLine::HORIZONTAL; + horizontalCount++; + verticalCount--; } visibleGeometry[object_id - 1] = line.icon.get(); @@ -405,6 +420,11 @@ void ControlLineManager::addLine(Coord begin, Coord end, EditSubscriber::mouseOverGeometry.push_back(control_line->end.get()); control_lines.push_back(std::move(control_line)); + if (type == rtengine::ControlLine::HORIZONTAL) { + horizontalCount++; + } else { + verticalCount++; + } } void ControlLineManager::autoSetLineType(int object_id) @@ -437,6 +457,13 @@ void ControlLineManager::autoSetLineType(int object_id) if (type != line.type) { // Need to update line type. line.type = type; line.icon = icon; + if (type == rtengine::ControlLine::HORIZONTAL) { + horizontalCount++; + verticalCount--; + } else { + horizontalCount--; + verticalCount++; + } visibleGeometry[line_id * ::ControlLine::OBJ_COUNT + 1] = line.icon.get(); } @@ -448,6 +475,7 @@ void ControlLineManager::removeAll(void) mouseOverGeometry.erase(mouseOverGeometry.begin() + 1, mouseOverGeometry.end()); control_lines.clear(); + horizontalCount = verticalCount = 0; prev_obj = -1; selected_object = -1; edited = true; @@ -470,6 +498,11 @@ void ControlLineManager::removeLine(size_t line_id) mouseOverGeometry.begin() + ::ControlLine::OBJ_COUNT * line_id + ::ControlLine::OBJ_COUNT + 1 ); + if (control_lines[line_id]->type == rtengine::ControlLine::HORIZONTAL) { + horizontalCount--; + } else { + verticalCount--; + } control_lines.erase(control_lines.begin() + line_id); edited = true; diff --git a/rtgui/controllines.h b/rtgui/controllines.h index 2b2d179a4..578118eb7 100644 --- a/rtgui/controllines.h +++ b/rtgui/controllines.h @@ -52,6 +52,7 @@ protected: bool draw_mode; bool drawing_line; bool edited; + size_t horizontalCount, verticalCount; Cairo::RefPtr line_icon_h, line_icon_v; Cairo::RefPtr line_icon_h_prelight, line_icon_v_prelight; int prev_obj; @@ -87,6 +88,10 @@ public: ~ControlLineManager(); bool getEdited(void) const; + /** Returns the number of horizontal control lines. */ + size_t getHorizontalCount(void) const; + /** Returns the number of vertical control lines. */ + size_t getVerticalCount(void) const; void removeAll(void); /** Sets whether or not the lines are visible and interact-able. */ void setActive(bool active); diff --git a/rtgui/perspective.cc b/rtgui/perspective.cc index 8db91ee2e..e77c622cd 100644 --- a/rtgui/perspective.cc +++ b/rtgui/perspective.cc @@ -351,6 +351,8 @@ void PerspCorrection::read (const ProcParams* pp, const ParamsEdited* pedited) method->set_active (1); } + updateApplyDeleteButtons(); + enableListener (); } @@ -739,11 +741,29 @@ void PerspCorrection::setEditProvider(EditDataProvider* provider) void PerspCorrection::lineChanged(void) { + updateApplyDeleteButtons(); + if (listener) { listener->panelChanged(EvPerspControlLines, M("HISTORY_CHANGED")); } } +void PerspCorrection::updateApplyDeleteButtons(void) +{ + if (batchMode) { + return; + } + + bool edit_mode = lines_button_edit->get_active(); + bool enough_lines = lines->getHorizontalCount() >= 2 || lines->getVerticalCount() >= 2; + const auto &tooltip = M("GENERAL_APPLY") + + ((edit_mode && !enough_lines) ? "\n\n" + M("TP_PERSPECTIVE_CONTROL_LINE_APPLY_INVALID_TOOLTIP") : ""); + + lines_button_apply->set_sensitive(edit_mode && enough_lines); + lines_button_apply->set_tooltip_text(tooltip); + lines_button_erase->set_sensitive(edit_mode && lines->size() > 0); +} + void PerspCorrection::linesApplyButtonPressed(void) { if (method->get_active_row_number() == 1) { @@ -784,6 +804,7 @@ void PerspCorrection::linesEditButtonPressed(void) panel_listener->controlLineEditModeChanged(false); } } + updateApplyDeleteButtons(); } void PerspCorrection::linesEraseButtonPressed(void) @@ -795,6 +816,8 @@ void PerspCorrection::requestApplyControlLines(void) { if (lines_button_apply->is_sensitive()) { linesApplyButtonPressed(); + } else if (lines_button_edit->get_active()) { + lines_button_edit->set_active(false); } } diff --git a/rtgui/perspective.h b/rtgui/perspective.h index 6f4a4ff52..3368b6282 100644 --- a/rtgui/perspective.h +++ b/rtgui/perspective.h @@ -96,6 +96,7 @@ protected: void tweakParams(rtengine::procparams::ProcParams &pparams) override; void setCamBasedEventsActive (bool active = true); void setFocalLengthValue (const rtengine::procparams::ProcParams* pparams, const rtengine::FramesMetaData* metadata); + void updateApplyDeleteButtons(void); public: From e7e6dd1cb5882bbef714396b301af001470c3795 Mon Sep 17 00:00:00 2001 From: Lawrence Lee <45837045+Lawrence37@users.noreply.github.com> Date: Mon, 31 May 2021 11:20:01 -0700 Subject: [PATCH 2/2] Clean up rtgui perspective.* and controllines.* Change size_t to std::size_t, remove void from function parameters, use constants to represent the minimum required number of control lines, and change const auto & to const auto. --- rtgui/controllines.cc | 8 ++++---- rtgui/controllines.h | 10 +++++----- rtgui/perspective.cc | 20 +++++++------------- rtgui/perspective.h | 7 ++++++- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/rtgui/controllines.cc b/rtgui/controllines.cc index e4ef9e9f7..84175af28 100644 --- a/rtgui/controllines.cc +++ b/rtgui/controllines.cc @@ -80,17 +80,17 @@ void ControlLineManager::setDrawMode(bool draw) draw_mode = draw; } -size_t ControlLineManager::size(void) const +std::size_t ControlLineManager::size() const { return control_lines.size(); } -size_t ControlLineManager::getHorizontalCount(void) const +std::size_t ControlLineManager::getHorizontalCount() const { return horizontalCount; } -size_t ControlLineManager::getVerticalCount(void) const +std::size_t ControlLineManager::getVerticalCount() const { return verticalCount; } @@ -482,7 +482,7 @@ void ControlLineManager::removeAll(void) callbacks->lineChanged(); } -void ControlLineManager::removeLine(size_t line_id) +void ControlLineManager::removeLine(std::size_t line_id) { if (line_id >= control_lines.size()) { return; diff --git a/rtgui/controllines.h b/rtgui/controllines.h index 578118eb7..81c4c7b8a 100644 --- a/rtgui/controllines.h +++ b/rtgui/controllines.h @@ -52,7 +52,7 @@ protected: bool draw_mode; bool drawing_line; bool edited; - size_t horizontalCount, verticalCount; + std::size_t horizontalCount, verticalCount; Cairo::RefPtr line_icon_h, line_icon_v; Cairo::RefPtr line_icon_h_prelight, line_icon_v_prelight; int prev_obj; @@ -68,7 +68,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(std::size_t line_id); public: class Callbacks @@ -89,9 +89,9 @@ public: bool getEdited(void) const; /** Returns the number of horizontal control lines. */ - size_t getHorizontalCount(void) const; + std::size_t getHorizontalCount() const; /** Returns the number of vertical control lines. */ - size_t getVerticalCount(void) const; + std::size_t getVerticalCount() const; void removeAll(void); /** Sets whether or not the lines are visible and interact-able. */ void setActive(bool active); @@ -101,7 +101,7 @@ public: void setEditProvider(EditDataProvider* provider); void setLines(const std::vector& lines); /** Returns the number of lines. */ - size_t size(void) const; + std::size_t size() const; /** * Allocates a new array and populates it with copies of the control lines. */ diff --git a/rtgui/perspective.cc b/rtgui/perspective.cc index e77c622cd..c845c272b 100644 --- a/rtgui/perspective.cc +++ b/rtgui/perspective.cc @@ -519,22 +519,16 @@ void PerspCorrection::applyControlLines(void) } std::vector control_lines; - int h_count = 0, v_count = 0; double rot = camera_roll->getValue(); double pitch = camera_pitch->getValue(); double yaw = camera_yaw->getValue(); lines->toControlLines(control_lines); - for (unsigned int i = 0; i < lines->size(); i++) { - if (control_lines[i].type == rtengine::ControlLine::HORIZONTAL) { - h_count++; - } else if (control_lines[i].type == rtengine::ControlLine::VERTICAL) { - v_count++; - } - } - lens_geom_listener->autoPerspRequested(v_count > 1, h_count > 1, rot, pitch, - yaw, &control_lines); + lens_geom_listener->autoPerspRequested( + lines->getVerticalCount() >= MIN_VERT_LINES, + lines->getHorizontalCount() >= MIN_HORIZ_LINES, + rot, pitch, yaw, &control_lines); disableListener(); camera_pitch->setValue(pitch); @@ -748,15 +742,15 @@ void PerspCorrection::lineChanged(void) } } -void PerspCorrection::updateApplyDeleteButtons(void) +void PerspCorrection::updateApplyDeleteButtons() { if (batchMode) { return; } bool edit_mode = lines_button_edit->get_active(); - bool enough_lines = lines->getHorizontalCount() >= 2 || lines->getVerticalCount() >= 2; - const auto &tooltip = M("GENERAL_APPLY") + bool enough_lines = lines->getHorizontalCount() >= MIN_HORIZ_LINES || lines->getVerticalCount() >= MIN_VERT_LINES; + const auto tooltip = M("GENERAL_APPLY") + ((edit_mode && !enough_lines) ? "\n\n" + M("TP_PERSPECTIVE_CONTROL_LINE_APPLY_INVALID_TOOLTIP") : ""); lines_button_apply->set_sensitive(edit_mode && enough_lines); diff --git a/rtgui/perspective.h b/rtgui/perspective.h index 3368b6282..404b02010 100644 --- a/rtgui/perspective.h +++ b/rtgui/perspective.h @@ -96,10 +96,15 @@ protected: void tweakParams(rtengine::procparams::ProcParams &pparams) override; void setCamBasedEventsActive (bool active = true); void setFocalLengthValue (const rtengine::procparams::ProcParams* pparams, const rtengine::FramesMetaData* metadata); - void updateApplyDeleteButtons(void); + void updateApplyDeleteButtons(); public: + /** Minimum number of horizontal lines for horizontal/full correction. */ + static constexpr std::size_t MIN_HORIZ_LINES = 2; + /** Minimum number of vertical lines for vertical/full correction. */ + static constexpr std::size_t MIN_VERT_LINES = 2; + PerspCorrection (); void read (const rtengine::procparams::ProcParams* pp, const ParamsEdited* pedited = nullptr) override;