add include intersection option in selection tool

This commit is contained in:
pojienie 2020-06-27 08:35:53 +00:00
parent 22ad3653a8
commit f9b677d27d
2 changed files with 38 additions and 22 deletions

View file

@ -39,6 +39,8 @@ namespace {
VectorSelectionTool l_vectorSelectionTool(TTool::Vectors); VectorSelectionTool l_vectorSelectionTool(TTool::Vectors);
TEnv::IntVar l_strokeSelectConstantThickness("SelectionToolConstantThickness", TEnv::IntVar l_strokeSelectConstantThickness("SelectionToolConstantThickness",
0); 0);
TEnv::IntVar l_strokeSelectIncludeIntersection(
"SelectionToolIncludeIntersection", 0);
const int l_dragThreshold = 10; //!< Distance, in pixels, the user has to const int l_dragThreshold = 10; //!< Distance, in pixels, the user has to
//! move from a button press to trigger a //! move from a button press to trigger a
@ -63,7 +65,7 @@ FourPoints getFourPointsFromVectorImage(const TVectorImageP &img,
TStroke *s = img->getStroke(i); TStroke *s = img->getStroke(i);
for (int j = 0; j < s->getControlPointCount(); j++) { for (int j = 0; j < s->getControlPointCount(); j++) {
double thick = s->getControlPoint(j).thick; double thick = s->getControlPoint(j).thick;
if (maxThickness < thick) maxThickness = thick; if (maxThickness < thick) maxThickness = thick;
} }
} }
@ -80,7 +82,7 @@ FourPoints getFourPointsFromVectorImage(const TVectorImageP &img,
bbox += s->getBBox(); bbox += s->getBBox();
for (int j = 0; j < s->getControlPointCount(); j++) { for (int j = 0; j < s->getControlPointCount(); j++) {
double thick = s->getControlPoint(j).thick; double thick = s->getControlPoint(j).thick;
if (maxThickness < thick) maxThickness = thick; if (maxThickness < thick) maxThickness = thick;
} }
} }
@ -933,8 +935,8 @@ struct Data {
VectorChangeThicknessTool &m_tool; VectorChangeThicknessTool &m_tool;
const TVectorImage &m_vi; const TVectorImage &m_vi;
}; };
} } // namespace SetStrokeThickness
} // setStrokeThickness } // namespace
void DragSelectionTool::VectorChangeThicknessTool::setStrokesThickness( void DragSelectionTool::VectorChangeThicknessTool::setStrokesThickness(
TVectorImage &vi) { TVectorImage &vi) {
@ -987,8 +989,8 @@ struct Data {
TVectorImage &m_vi; TVectorImage &m_vi;
double m_newThickness; double m_newThickness;
}; };
} } // namespace ChangeImageThickness
} } // namespace
void DragSelectionTool::VectorChangeThicknessTool::changeImageThickness( void DragSelectionTool::VectorChangeThicknessTool::changeImageThickness(
TVectorImage &vi, double newThickness) { TVectorImage &vi, double newThickness) {
@ -1204,6 +1206,7 @@ public:
VectorSelectionTool::VectorSelectionTool(int targetType) VectorSelectionTool::VectorSelectionTool(int targetType)
: SelectionTool(targetType) : SelectionTool(targetType)
, m_selectionTarget("Mode:") , m_selectionTarget("Mode:")
, m_includeIntersection("Include Intersection", false)
, m_constantThickness("Preserve Thickness", false) , m_constantThickness("Preserve Thickness", false)
, m_levelSelection(m_strokeSelection) , m_levelSelection(m_strokeSelection)
, m_capStyle("Cap") , m_capStyle("Cap")
@ -1214,6 +1217,7 @@ VectorSelectionTool::VectorSelectionTool(int targetType)
, m_resetCenter(true) { , m_resetCenter(true) {
assert(targetType == TTool::Vectors); assert(targetType == TTool::Vectors);
m_prop.bind(m_selectionTarget); m_prop.bind(m_selectionTarget);
m_prop.bind(m_includeIntersection);
m_prop.bind(m_constantThickness); m_prop.bind(m_constantThickness);
m_selectionTarget.addValue(NORMAL_TYPE); m_selectionTarget.addValue(NORMAL_TYPE);
@ -1228,6 +1232,7 @@ VectorSelectionTool::VectorSelectionTool(int targetType)
m_strokeSelection.setView(this); m_strokeSelection.setView(this);
m_includeIntersection.setId("IncludeIntersection");
m_constantThickness.setId("PreserveThickness"); m_constantThickness.setId("PreserveThickness");
m_selectionTarget.setId("SelectionMode"); m_selectionTarget.setId("SelectionMode");
@ -1334,6 +1339,7 @@ void VectorSelectionTool::updateTranslation() {
m_selectionTarget.setItemUIName(BOUNDARY_LEVEL_TYPE, m_selectionTarget.setItemUIName(BOUNDARY_LEVEL_TYPE,
tr("Boundaries on Whole Level")); tr("Boundaries on Whole Level"));
m_includeIntersection.setQStringName(tr("Include Intersection"));
m_constantThickness.setQStringName(tr("Preserve Thickness")); m_constantThickness.setQStringName(tr("Preserve Thickness"));
m_capStyle.setQStringName(tr("Cap")); m_capStyle.setQStringName(tr("Cap"));
@ -1359,9 +1365,8 @@ void VectorSelectionTool::updateSelectionTarget() {
selectedStrokes.swap( selectedStrokes.swap(
m_strokeSelection.getSelection()); // current selection change m_strokeSelection.getSelection()); // current selection change
m_strokeSelection m_strokeSelection.makeCurrent(); // Empties any (different) previously
.makeCurrent(); // Empties any (different) previously current // current selection on its own
// selection on its own
selectedStrokes.swap(m_strokeSelection.getSelection()); selectedStrokes.swap(m_strokeSelection.getSelection());
return; return;
} }
@ -1478,8 +1483,8 @@ void VectorSelectionTool::modifySelectionOnClick(TImageP image,
bool modifiableSel = isModifiableSelectionType(), bool modifiableSel = isModifiableSelectionType(),
strokeAtPos = getStrokeIndexFromPos(index, vi, pos, getPixelSize(), strokeAtPos = getStrokeIndexFromPos(index, vi, pos, getPixelSize(),
getViewer()->getViewMatrix()), getViewer()->getViewMatrix()),
addStroke = strokeAtPos && !m_strokeSelection.isSelected(index), addStroke = strokeAtPos && !m_strokeSelection.isSelected(index),
toggleStroke = strokeAtPos && e.isShiftPressed(); toggleStroke = strokeAtPos && e.isShiftPressed();
m_selecting = m_selecting =
(modifiableSel && !strokeAtPos // There must be no stroke under cursor (modifiableSel && !strokeAtPos // There must be no stroke under cursor
@ -1488,9 +1493,8 @@ void VectorSelectionTool::modifySelectionOnClick(TImageP image,
|| (m_strokeSelectionType.getIndex() != || (m_strokeSelectionType.getIndex() !=
POLYLINE_SELECTION_IDX) // or the tool support immediate POLYLINE_SELECTION_IDX) // or the tool support immediate
// selection on clear // selection on clear
|| || m_strokeSelection
m_strokeSelection .isEmpty())); // or the strokes list was already cleared
.isEmpty())); // or the strokes list was already cleared
bool clearTargets = !(strokeAtPos || e.isShiftPressed() || m_selecting), bool clearTargets = !(strokeAtPos || e.isShiftPressed() || m_selecting),
clearSelection = (addStroke || !strokeAtPos) && !e.isShiftPressed(), clearSelection = (addStroke || !strokeAtPos) && !e.isShiftPressed(),
@ -1528,7 +1532,7 @@ void VectorSelectionTool::leftButtonDoubleClick(const TPointD &pos,
if (m_strokeSelectionType.getIndex() == POLYLINE_SELECTION_IDX && if (m_strokeSelectionType.getIndex() == POLYLINE_SELECTION_IDX &&
!m_polyline.empty()) { !m_polyline.empty()) {
closePolyline(pos); closePolyline(pos);
selectRegionVectorImage(); selectRegionVectorImage(m_includeIntersection.getValue());
m_selecting = false; m_selecting = false;
invalidate(); invalidate();
@ -1661,7 +1665,8 @@ void VectorSelectionTool::leftButtonUp(const TPointD &pos,
closeFreehand(pos); closeFreehand(pos);
if (m_stroke->getControlPointCount() > 3) selectRegionVectorImage(); if (m_stroke->getControlPointCount() > 3)
selectRegionVectorImage(m_includeIntersection.getValue());
delete m_stroke; // >:( delete m_stroke; // >:(
m_stroke = 0; m_stroke = 0;
@ -1927,6 +1932,7 @@ bool VectorSelectionTool::selectStroke(int index, bool toggle) {
void VectorSelectionTool::onActivate() { void VectorSelectionTool::onActivate() {
if (m_firstTime) { if (m_firstTime) {
m_includeIntersection.setValue(l_strokeSelectIncludeIntersection ? 1 : 0);
m_constantThickness.setValue(l_strokeSelectConstantThickness ? 1 : 0); m_constantThickness.setValue(l_strokeSelectConstantThickness ? 1 : 0);
m_strokeSelection.setSceneHandle( m_strokeSelection.setSceneHandle(
TTool::getApplication()->getCurrentScene()); TTool::getApplication()->getCurrentScene());
@ -1966,9 +1972,8 @@ void VectorSelectionTool::onImageChanged() {
m_strokeSelection.setImage(vi); m_strokeSelection.setImage(vi);
if (!(vi && selectedImg) // Retain the styles selection ONLY if (!(vi && selectedImg) // Retain the styles selection ONLY
|| || vi->getPalette() !=
vi->getPalette() != selectedImg->getPalette()) // if palettes still match
selectedImg->getPalette()) // if palettes still match
selectedStyles().clear(); selectedStyles().clear();
} else { } else {
// Remove any eventual stroke index outside the valid range // Remove any eventual stroke index outside the valid range
@ -2028,6 +2033,8 @@ bool VectorSelectionTool::onPropertyChanged(std::string propertyName) {
if (SelectionTool::onPropertyChanged(propertyName)) return true; if (SelectionTool::onPropertyChanged(propertyName)) return true;
if (propertyName == m_includeIntersection.getName())
l_strokeSelectIncludeIntersection = (int)(m_includeIntersection.getValue());
if (propertyName == m_constantThickness.getName()) if (propertyName == m_constantThickness.getName())
l_strokeSelectConstantThickness = (int)(m_constantThickness.getValue()); l_strokeSelectConstantThickness = (int)(m_constantThickness.getValue());
else if (propertyName == m_selectionTarget.getName()) else if (propertyName == m_selectionTarget.getName())
@ -2155,7 +2162,7 @@ void VectorSelectionTool::selectionOutlineStyle(int &capStyle, int &joinStyle) {
const TStroke::OutlineOptions &options = const TStroke::OutlineOptions &options =
vi->getStroke(*it)->outlineOptions(); vi->getStroke(*it)->outlineOptions();
if (capStyle != options.m_capStyle) capStyle = -1; if (capStyle != options.m_capStyle) capStyle = -1;
if (joinStyle != options.m_joinStyle) joinStyle = -1; if (joinStyle != options.m_joinStyle) joinStyle = -1;
if (capStyle < 0 && joinStyle < 0) return; if (capStyle < 0 && joinStyle < 0) return;
} }
@ -2163,7 +2170,7 @@ void VectorSelectionTool::selectionOutlineStyle(int &capStyle, int &joinStyle) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void VectorSelectionTool::selectRegionVectorImage() { void VectorSelectionTool::selectRegionVectorImage(bool includeIntersect) {
if (!m_stroke) return; if (!m_stroke) return;
TVectorImageP vi(getImage(false)); TVectorImageP vi(getImage(false));
@ -2189,6 +2196,14 @@ void VectorSelectionTool::selectRegionVectorImage() {
if (region->contains(*currentStroke, true)) if (region->contains(*currentStroke, true))
selectionChanged = selectStroke(s, false) || selectionChanged; selectionChanged = selectStroke(s, false) || selectionChanged;
} }
if (includeIntersect) {
std::vector<DoublePair> intersections;
intersect(m_stroke, currentStroke, intersections, false);
if (intersections.size() > 0) {
selectionChanged = selectStroke(s, false) || selectionChanged;
}
}
} }
if (selectionChanged) { if (selectionChanged) {

View file

@ -358,6 +358,7 @@ private:
private: private:
TEnumProperty m_selectionTarget; //!< Selected target content (strokes, whole TEnumProperty m_selectionTarget; //!< Selected target content (strokes, whole
//! image, styles...). //! image, styles...).
TBoolProperty m_includeIntersection;
TBoolProperty m_constantThickness; TBoolProperty m_constantThickness;
StrokeSelection m_strokeSelection; //!< Standard selection of a set of StrokeSelection m_strokeSelection; //!< Standard selection of a set of
@ -384,7 +385,7 @@ private:
void doOnActivate() override; void doOnActivate() override;
void doOnDeactivate() override; void doOnDeactivate() override;
void selectRegionVectorImage(); void selectRegionVectorImage(bool includeIntersect);
void updateTranslation() override; void updateTranslation() override;