diff --git a/toonz/sources/include/tools/cursors.h b/toonz/sources/include/tools/cursors.h index f81c0e33..2069bbd6 100644 --- a/toonz/sources/include/tools/cursors.h +++ b/toonz/sources/include/tools/cursors.h @@ -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. diff --git a/toonz/sources/tnztools/Resources/ex_freepick.png b/toonz/sources/tnztools/Resources/ex_freepick.png new file mode 100644 index 00000000..b47c3ca8 Binary files /dev/null and b/toonz/sources/tnztools/Resources/ex_freepick.png differ diff --git a/toonz/sources/tnztools/Resources/ex_freepick_left.png b/toonz/sources/tnztools/Resources/ex_freepick_left.png new file mode 100644 index 00000000..3aabc356 Binary files /dev/null and b/toonz/sources/tnztools/Resources/ex_freepick_left.png differ diff --git a/toonz/sources/tnztools/cursormanager.cpp b/toonz/sources/tnztools/cursormanager.cpp index 95cc5f1c..da14dc84 100644 --- a/toonz/sources/tnztools/cursormanager.cpp +++ b/toonz/sources/tnztools/cursormanager.cpp @@ -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 diff --git a/toonz/sources/tnztools/filltool.cpp b/toonz/sources/tnztools/filltool.cpp index 456e141d..38fe9ac4 100644 --- a/toonz/sources/tnztools/filltool.cpp +++ b/toonz/sources/tnztools/filltool.cpp @@ -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); diff --git a/toonz/sources/tnztools/filltool.h b/toonz/sources/tnztools/filltool.h index 00ef46f7..b529e315 100644 --- a/toonz/sources/tnztools/filltool.h +++ b/toonz/sources/tnztools/filltool.h @@ -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, diff --git a/toonz/sources/tnztools/tnztools.qrc b/toonz/sources/tnztools/tnztools.qrc index 9ad798d2..5cdaeb24 100644 --- a/toonz/sources/tnztools/tnztools.qrc +++ b/toonz/sources/tnztools/tnztools.qrc @@ -1,5 +1,5 @@ - + Resources/brush.png Resources/bender.png Resources/cutter.png @@ -33,67 +33,69 @@ Resources/selection_add.png Resources/selection_convert.png Resources/selection_distort.png - Resources/move_ew.png - Resources/move_ns.png - Resources/disable.png - Resources/move_z.png - Resources/picker_style_line.png - Resources/picker_style_area.png - Resources/picker_style.png - Resources/scale_global.png - Resources/scale_hv.png - Resources/normaleraser.png - Resources/recteraser.png - Resources/picker_style_organize.png - Resources/picker_rgb.png - Resources/picker_rgb_white.png - Resources/pointing_hand.png - Resources/karasu.png - Resources/ruler_modify.png - Resources/ruler_new.png - Resources/ex_freehand.png - Resources/ex_freehand_left.png - Resources/ex_polyline.png - Resources/ex_polyline_left.png - Resources/ex_rectangle.png - Resources/ex_rectangle_left.png - Resources/ex_line.png - Resources/ex_line_left.png - Resources/ex_area.png - Resources/ex_area_left.png - Resources/ex_fill_no_autopaint.png - Resources/ex_fill_no_autopaint_left.png - Resources/edit_FX_notext.png - Resources/move_z_notext.png - Resources/scale_hv_notext.png - Resources/ex_FX.png - Resources/ex_FX_left.png - Resources/ex_hv.png - Resources/ex_hv_left.png - Resources/ex_rgb.png - Resources/ex_rgb_left.png - Resources/ex_style_area.png - Resources/ex_style_area_left.png - Resources/ex_style_line.png - Resources/ex_style_line_left.png - Resources/ex_z.png - Resources/ex_z_left.png - Resources/ex_precise.png - Resources/ex_precise_left.png - Resources/brush_large.png - Resources/brush_crosshair.png - Resources/brush_triangle_top_left.png - Resources/brush_triangle_top_right.png - Resources/brush_triangle_bottom_left.png - Resources/brush_triangle_bottom_right.png - Resources/brush_triangle_up.png - Resources/brush_triangle_down.png - Resources/brush_triangle_left.png - Resources/brush_triangle_right.png - Resources/tracker.png - Resources/ex_prev.png - Resources/ex_prev_left.png - Resources/ex_next.png - Resources/ex_next_left.png - + Resources/move_ew.png + Resources/move_ns.png + Resources/disable.png + Resources/move_z.png + Resources/picker_style_line.png + Resources/picker_style_area.png + Resources/picker_style.png + Resources/scale_global.png + Resources/scale_hv.png + Resources/normaleraser.png + Resources/recteraser.png + Resources/picker_style_organize.png + Resources/picker_rgb.png + Resources/picker_rgb_white.png + Resources/pointing_hand.png + Resources/karasu.png + Resources/ruler_modify.png + Resources/ruler_new.png + Resources/ex_freehand.png + Resources/ex_freehand_left.png + Resources/ex_polyline.png + Resources/ex_polyline_left.png + Resources/ex_rectangle.png + Resources/ex_rectangle_left.png + Resources/ex_line.png + Resources/ex_line_left.png + Resources/ex_area.png + Resources/ex_area_left.png + Resources/ex_fill_no_autopaint.png + Resources/ex_fill_no_autopaint_left.png + Resources/edit_FX_notext.png + Resources/move_z_notext.png + Resources/scale_hv_notext.png + Resources/ex_FX.png + Resources/ex_FX_left.png + Resources/ex_hv.png + Resources/ex_hv_left.png + Resources/ex_rgb.png + Resources/ex_rgb_left.png + Resources/ex_style_area.png + Resources/ex_style_area_left.png + Resources/ex_style_line.png + Resources/ex_style_line_left.png + Resources/ex_freepick.png + Resources/ex_freepick_left.png + Resources/ex_z.png + Resources/ex_z_left.png + Resources/ex_precise.png + Resources/ex_precise_left.png + Resources/brush_large.png + Resources/brush_crosshair.png + Resources/brush_triangle_top_left.png + Resources/brush_triangle_top_right.png + Resources/brush_triangle_bottom_left.png + Resources/brush_triangle_bottom_right.png + Resources/brush_triangle_up.png + Resources/brush_triangle_down.png + Resources/brush_triangle_left.png + Resources/brush_triangle_right.png + Resources/tracker.png + Resources/ex_prev.png + Resources/ex_prev_left.png + Resources/ex_next.png + Resources/ex_next_left.png + \ No newline at end of file diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index 9f46b384..7028f155 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -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")); diff --git a/toonz/sources/toonz/menubarcommandids.h b/toonz/sources/toonz/menubarcommandids.h index 124b6696..45fb3aca 100644 --- a/toonz/sources/toonz/menubarcommandids.h +++ b/toonz/sources/toonz/menubarcommandids.h @@ -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" diff --git a/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp b/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp index 9fd3153f..9d71f695 100644 --- a/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp +++ b/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp @@ -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(); diff --git a/toonz/sources/toonz/tooloptionsshortcutinvoker.h b/toonz/sources/toonz/tooloptionsshortcutinvoker.h index 532b9302..5db1902d 100644 --- a/toonz/sources/toonz/tooloptionsshortcutinvoker.h +++ b/toonz/sources/toonz/tooloptionsshortcutinvoker.h @@ -203,6 +203,7 @@ protected slots: void toggleFillRectangular(); void toggleFillFreehand(); void toggleFillPolyline(); + void toggleFillFreepick(); void toggleFillNextMode(); void toggleFillAreas(); void toggleFillLines(); diff --git a/toonz/sources/toonz/toonz.qrc b/toonz/sources/toonz/toonz.qrc index 00f3f21d..5185440f 100644 --- a/toonz/sources/toonz/toonz.qrc +++ b/toonz/sources/toonz/toonz.qrc @@ -459,6 +459,7 @@ icons/dark/actions/20/selection_freehand.svg icons/dark/actions/20/type_lasso.svg + icons/dark/actions/20/type_pickerlasso.svg icons/dark/actions/20/type_rectangular.svg icons/dark/actions/20/type_polyline.svg icons/dark/actions/20/type_normal.svg