new Fill Tool - Pick+Freehand

This commit is contained in:
justburner 2022-11-02 07:32:44 +00:00 committed by manongjohn
parent 046bdd4155
commit 6b41e56403
12 changed files with 150 additions and 72 deletions

View file

@ -107,6 +107,7 @@ enum {
Ex_Precise = 0x200000,
Ex_Prev = 0x400000,
Ex_Next = 0x800000,
Ex_FreePick = 0x1000000,
// This section is for cursors that have fixed text that needs to
// be handled separately when flipping for left-handed cursors.

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

View file

@ -135,6 +135,7 @@ const struct {
{ToolCursor::Ex_Precise, "ex_precise"},
{ToolCursor::Ex_Prev, "ex_prev"},
{ToolCursor::Ex_Next, "ex_next"},
{ToolCursor::Ex_FreePick, "ex_freepick"},
{0, 0}};
}; // namespace

View file

@ -63,6 +63,7 @@ using namespace ToolUtils;
#define RECTFILL L"Rectangular"
#define FREEHANDFILL L"Freehand"
#define POLYLINEFILL L"Polyline"
#define FREEPICKFILL L"Freepick"
TEnv::IntVar MinFillDepth("InknpaintMinFillDepth", 1);
TEnv::IntVar MaxFillDepth("InknpaintMaxFillDepth", 10);
@ -1577,7 +1578,8 @@ void AreaFillTool::draw() {
} else
drawRect(m_selectingRect, color, 0xFFFF, true);
}
} else if ((m_type == FREEHAND || m_type == POLYLINE) && m_frameRange) {
} else if ((m_type == FREEHAND || m_type == POLYLINE || m_type == FREEPICK) &&
m_frameRange) {
tglColor(color);
for(int i = 0; i < m_firstStrokes.size(); i++)
drawStrokeCenterline(*m_firstStrokes[i], 1);
@ -1587,7 +1589,7 @@ void AreaFillTool::draw() {
glPushMatrix();
m_polyline.drawPolyline(m_mousePosition, color);
glPopMatrix();
} else if (m_type == FREEHAND && !m_track.isEmpty()) {
} else if ((m_type == FREEHAND || m_type == FREEPICK) && !m_track.isEmpty()) {
tglColor(color);
glPushMatrix();
m_track.drawAllFragments();
@ -1595,6 +1597,36 @@ void AreaFillTool::draw() {
}
}
int AreaFillTool::pick(const TImageP &image, const TPointD &pos,
const int frame, int mode) {
TToonzImageP ti = image;
TVectorImageP vi = image;
if (!ti && !vi) return 0;
TTool::Viewer *viewer = m_parent->getViewer();
StylePicker picker(viewer->viewerWidget(), image);
double scale2 = 1.0;
if (vi) {
TAffine aff =
viewer->getViewMatrix() * m_parent->getCurrentColumnMatrix(frame);
scale2 = aff.det();
}
TPointD pickPos = pos;
// in case that the column is animated in scene-editing mode
if (frame > 0) {
TPointD dpiScale = viewer->getDpiScale();
pickPos.x *= dpiScale.x;
pickPos.y *= dpiScale.y;
TPointD worldPos = m_parent->getCurrentColumnMatrix() * pickPos;
pickPos = m_parent->getCurrentColumnMatrix(frame).inv() * worldPos;
pickPos.x /= dpiScale.x;
pickPos.y /= dpiScale.y;
}
// thin stroke can be picked with 10 pixel range
return picker.pickStyleId(pickPos, 10.0, scale2, mode);
}
void AreaFillTool::resetMulti() {
m_firstFrameSelected = false;
m_firstRect.empty();
@ -1606,7 +1638,7 @@ void AreaFillTool::resetMulti() {
m_firstStrokes.clear();
}
void AreaFillTool::leftButtonDown(const TPointD &pos, const TMouseEvent &,
void AreaFillTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e,
TImage *img) {
TVectorImageP vi = TImageP(img);
TToonzImageP ti = TToonzImageP(img);
@ -1621,6 +1653,16 @@ void AreaFillTool::leftButtonDown(const TPointD &pos, const TMouseEvent &,
TPointD dpiScale = m_parent->getViewer()->getDpiScale();
SymmetryObject symmObj = symmetryTool->getSymmetryObject();
if (m_type == FREEPICK) {
TTool::Application *app = TTool::getApplication();
if (!app) return;
int fllmode = e.isCtrlPressed() ? 2 : 0; // Line+Area : Area
int styleId = pick(img, pos, -1, fllmode);
if (!m_isLeftButtonPressed) m_bckStyleId = app->getCurrentLevelStyleIndex();
app->setCurrentLevelStyleIndex(styleId);
}
m_selecting = true;
if (m_type == RECT) {
m_selectingRect.x0 = pos.x;
@ -1638,7 +1680,7 @@ void AreaFillTool::leftButtonDown(const TPointD &pos, const TMouseEvent &,
TPointD(m_selectingRect.x1, m_selectingRect.y1));
m_mousePosition = pos;
}
} else if (m_type == FREEHAND || m_type == POLYLINE) {
} else if (m_type == FREEHAND || m_type == POLYLINE || m_type == FREEPICK) {
int col = TTool::getApplication()->getCurrentColumn()->getColumnIndex();
m_isPath = TTool::getApplication()
->getCurrentObject()
@ -1801,7 +1843,7 @@ void AreaFillTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
}
m_parent->invalidate();
} else if (m_type == FREEHAND) {
} else if (m_type == FREEHAND || m_type == FREEPICK) {
if (!m_enabled || !m_active) return;
double pixelSize2 = m_parent->getPixelSize() * m_parent->getPixelSize();
@ -1948,7 +1990,7 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e,
TTool *t = app->getCurrentTool()->getTool();
if (t) t->notifyImageChanged();
}
} else if (m_type == FREEHAND) {
} else if (m_type == FREEHAND || m_type == FREEPICK) {
#if defined(MACOSX)
// m_parent->m_viewer->enableRedraw(true);
#endif
@ -2058,6 +2100,8 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e,
}
m_track.reset();
}
if (m_type == FREEPICK) app->setCurrentLevelStyleIndex(m_bckStyleId);
}
void AreaFillTool::onImageChanged() {
@ -2075,7 +2119,7 @@ void AreaFillTool::onImageChanged() {
// stato iniziale
else { // cambio stato.
m_firstFrameSelected = true;
if (m_type != FREEHAND && m_type != POLYLINE) {
if (m_type != FREEHAND && m_type != POLYLINE && m_type != FREEPICK) {
assert(!m_selectingRect.isEmpty());
m_firstRect = m_selectingRect;
}
@ -2279,6 +2323,7 @@ FillTool::FillTool(int targetType)
m_fillType.addValue(RECTFILL);
m_fillType.addValue(FREEHANDFILL);
m_fillType.addValue(POLYLINEFILL);
m_fillType.addValue(FREEPICKFILL);
m_prop.bind(m_colorType);
m_colorType.addValue(LINES);
@ -2340,6 +2385,8 @@ int FillTool::getCursorId() const {
ret = ret | ToolCursor::Ex_PolyLine;
else if (m_fillType.getValue() == RECTFILL)
ret = ret | ToolCursor::Ex_Rectangle;
if (m_fillType.getValue() == FREEPICKFILL)
ret = ret | ToolCursor::Ex_FreePick;
if (ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg)
ret = ret | ToolCursor::Ex_Negate;
@ -2356,6 +2403,7 @@ void FillTool::updateTranslation() {
m_fillType.setItemUIName(RECTFILL, tr("Rectangular"));
m_fillType.setItemUIName(FREEHANDFILL, tr("Freehand"));
m_fillType.setItemUIName(POLYLINEFILL, tr("Polyline"));
m_fillType.setItemUIName(FREEPICKFILL, tr("Pick+Freehand"));
m_selective.setQStringName(tr("Selective"));
@ -2728,6 +2776,8 @@ bool FillTool::onPropertyChanged(std::string propertyName) {
type = AreaFillTool::FREEHAND;
else if (m_fillType.getValue() == POLYLINEFILL)
type = AreaFillTool::POLYLINE;
else if (m_fillType.getValue() == FREEPICKFILL)
type = AreaFillTool::FREEPICK;
else
assert(false);
@ -2951,6 +3001,8 @@ void FillTool::onActivate() {
type = AreaFillTool::FREEHAND;
else if (m_fillType.getValue() == POLYLINEFILL)
type = AreaFillTool::POLYLINE;
else if (m_fillType.getValue() == FREEPICKFILL)
type = AreaFillTool::FREEPICK;
else
assert(false);

View file

@ -30,7 +30,7 @@ namespace {
class AreaFillTool {
public:
enum Type { RECT, FREEHAND, POLYLINE };
enum Type { RECT, FREEHAND, POLYLINE, FREEPICK };
private:
bool m_frameRange;
@ -61,9 +61,12 @@ private:
bool m_autopaintLines;
bool m_fillOnlySavebox;
int m_bckStyleId;
public:
AreaFillTool(TTool *Parent);
void draw();
int pick(const TImageP &image, const TPointD &pos, const int frame, int mode);
void resetMulti();
void leftButtonDown(const TPointD &pos, const TMouseEvent &, TImage *img);
void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e,

View file

@ -76,6 +76,8 @@
<file>Resources/ex_style_area_left.png</file>
<file>Resources/ex_style_line.png</file>
<file>Resources/ex_style_line_left.png</file>
<file>Resources/ex_freepick.png</file>
<file>Resources/ex_freepick_left.png</file>
<file>Resources/ex_z.png</file>
<file>Resources/ex_z_left.png</file>
<file>Resources/ex_precise.png</file>

View file

@ -2740,6 +2740,8 @@ void MainWindow::defineActions() {
ToolCommandType, "fill_freehand");
createAction(MI_FillPolyline, QT_TR_NOOP("Fill Tool - Polyline"), "", "",
ToolCommandType, "fill_polyline");
createAction(MI_FillFreepick, QT_TR_NOOP("Fill Tool - Pick+Freehand"), "", "",
ToolCommandType, "fill_freepick");
createAction(MI_FillNextMode, QT_TR_NOOP("Fill Tool - Next Mode"), "", "",
ToolCommandType);
createAction(MI_FillAreas, QT_TR_NOOP("Fill Tool - Areas"), "", "",
@ -2969,6 +2971,10 @@ void MainWindow::defineActions() {
QT_TR_NOOP("Type - Polyline"), "");
menuAct->setIcon(createQIcon("type_polyline"));
menuAct = createToolOptionsAction("A_ToolOption_Type:Freepick",
QT_TR_NOOP("Type - Pick+Freehand"), "");
menuAct->setIcon(createQIcon("type_pickerlasso"));
menuAct = createToolOptionsAction("A_ToolOption_Type:Segment",
QT_TR_NOOP("Type - Segment"), "");
menuAct->setIcon(createQIcon("type_erase_segment"));

View file

@ -388,6 +388,7 @@
#define MI_FillRectangular "MI_FillRectangular"
#define MI_FillFreehand "MI_FillFreehand"
#define MI_FillPolyline "MI_FillPolyline"
#define MI_FillFreepick "MI_FillFreepick"
#define MI_FillNextMode "MI_FillNextMode"
#define MI_FillAreas "MI_FillAreas"
#define MI_FillLines "MI_FillLines"

View file

@ -502,6 +502,8 @@ void ToolOptionsShortcutInvoker::initialize() {
&ToolOptionsShortcutInvoker::toggleFillFreehand);
setCommandHandler(MI_FillPolyline, this,
&ToolOptionsShortcutInvoker::toggleFillPolyline);
setCommandHandler(MI_FillFreepick, this,
&ToolOptionsShortcutInvoker::toggleFillFreepick);
setCommandHandler(MI_FillNextMode, this,
&ToolOptionsShortcutInvoker::toggleFillNextMode);
setCommandHandler(MI_FillAreas, this,
@ -866,6 +868,14 @@ void ToolOptionsShortcutInvoker::toggleFillPolyline() {
->trigger();
}
void ToolOptionsShortcutInvoker::toggleFillFreepick() {
CommandManager::instance()->getAction(T_Fill)->trigger();
CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger();
CommandManager::instance()
->getAction("A_ToolOption_Type:Freepick")
->trigger();
}
void ToolOptionsShortcutInvoker::toggleFillNextMode() {
if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Fill)
CommandManager::instance()->getAction("A_ToolOption_Mode")->trigger();

View file

@ -203,6 +203,7 @@ protected slots:
void toggleFillRectangular();
void toggleFillFreehand();
void toggleFillPolyline();
void toggleFillFreepick();
void toggleFillNextMode();
void toggleFillAreas();
void toggleFillLines();

View file

@ -459,6 +459,7 @@
<file>icons/dark/actions/20/selection_freehand.svg</file>
<file>icons/dark/actions/20/type_lasso.svg</file>
<file>icons/dark/actions/20/type_pickerlasso.svg</file>
<file>icons/dark/actions/20/type_rectangular.svg</file>
<file>icons/dark/actions/20/type_polyline.svg</file>
<file>icons/dark/actions/20/type_normal.svg</file>