| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| namespace |
| { |
| |
| //======================================================================== |
| // Pick Style Tool |
| //------------------------------------------------------------------------ |
| |
| class StylePickerTool : public TTool |
| { |
| int m_oldStyleId, m_currentStyleId; |
| |
| TEnumProperty m_colorType; |
| TPropertyGroup m_prop; |
| |
| TBoolProperty m_passivePick; |
| |
| public: |
| TPropertyGroup *getProperties(int targetType) { return &m_prop; } |
| |
| StylePickerTool() |
| : TTool("T_StylePicker"), m_currentStyleId(0), m_colorType("Mode:"), m_passivePick("Passive Pick", false) |
| { |
| m_prop.bind(m_colorType); |
| m_colorType.addValue(AREAS); |
| m_colorType.addValue(LINES); |
| m_colorType.addValue(ALL); |
| m_colorType.setId("Mode"); |
| bind(TTool::CommonLevels); |
| |
| m_prop.bind(m_passivePick); |
| m_passivePick.setId("PassivePick"); |
| } |
| |
| ToolType getToolType() const { return TTool::LevelReadTool; } |
| |
| void draw() |
| { |
| } |
| |
| void leftButtonDown(const TPointD &pos, const TMouseEvent &e) |
| { |
| m_oldStyleId = m_currentStyleId = getApplication()->getCurrentLevelStyleIndex(); |
| pick(pos, e); |
| } |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) |
| { |
| pick(pos, e); |
| } |
| |
| void pick(const TPointD &pos, const TMouseEvent &e) |
| { |
| |
| int modeValue = m_colorType.getIndex(); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| if (Preferences::instance()->isMultiLayerStylePickerEnabled() && |
| getApplication()->getCurrentFrame()->isEditingScene()) { |
| int superPickedColumnId = getViewer()->posToColumnIndex(e.m_pos, getPixelSize() * getPixelSize(), false); |
| |
| if (superPickedColumnId >= 0 |
| && getApplication()->getCurrentColumn()->getColumnIndex() != superPickedColumnId) |
| { |
| |
| int currentFrame = getApplication()->getCurrentFrame()->getFrame(); |
| TXshCell pickedCell = getApplication()->getCurrentXsheet()->getXsheet()->getCell(currentFrame, superPickedColumnId); |
| TImageP pickedImage = pickedCell.getImage(false).getPointer(); |
| TToonzImageP picked_ti = pickedImage; |
| TVectorImageP picked_vi = pickedImage; |
| TXshSimpleLevel *picked_level = pickedCell.getSimpleLevel(); |
| if ((picked_ti || picked_vi) && picked_level) { |
| TPointD tmpMousePosition = getColumnMatrix(superPickedColumnId).inv() * getViewer()->winToWorld(e.m_pos); |
| |
| TPointD tmpDpiScale = getCurrentDpiScale(picked_level, getCurrentFid()); |
| |
| tmpMousePosition.x /= tmpDpiScale.x; |
| tmpMousePosition.y /= tmpDpiScale.y; |
| |
| StylePicker superPicker(pickedImage); |
| int picked_subsampling = picked_level->getImageSubsampling(pickedCell.getFrameId()); |
| int superPicked_StyleId = superPicker.pickStyleId(TScale(1.0 / picked_subsampling) * tmpMousePosition + TPointD(-0.5, -0.5), |
| getPixelSize() * getPixelSize(), |
| modeValue); |
| |
| if (superPicked_StyleId > 0) { |
| |
| getApplication()->getCurrentLevel()->setLevel(picked_level); |
| |
| getApplication()->getCurrentColumn()->setColumnIndex(superPickedColumnId); |
| |
| if (getApplication()->getCurrentSelection()->getSelection()) |
| getApplication()->getCurrentSelection()->getSelection()->selectNone(); |
| |
| getApplication()->setCurrentLevelStyleIndex(superPicked_StyleId); |
| return; |
| } |
| } |
| } |
| } |
| |
| |
| TImageP image = getImage(false); |
| TToonzImageP ti = image; |
| TVectorImageP vi = image; |
| TXshSimpleLevel *level = getApplication()->getCurrentLevel()->getSimpleLevel(); |
| if ((!ti && !vi) || !level) |
| return; |
| |
| |
| if (!m_viewer->getGeometry().contains(pos)) |
| return; |
| |
| int subsampling = level->getImageSubsampling(getCurrentFid()); |
| StylePicker picker(image); |
| int styleId = picker.pickStyleId(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5), getPixelSize() * getPixelSize(), modeValue); |
| |
| if (styleId < 0) |
| return; |
| |
| if (modeValue == 1) |
| { |
| |
| if (styleId == 0) |
| return; |
| |
| if (ti && picker.pickTone(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5)) == 255) |
| return; |
| } |
| |
| |
| TSelection *selection = TTool::getApplication()->getCurrentSelection()->getSelection(); |
| if (selection) { |
| TStyleSelection *styleSelection = dynamic_cast<TStyleSelection *>(selection); |
| if (styleSelection) |
| styleSelection->selectNone(); |
| } |
| |
| getApplication()->setCurrentLevelStyleIndex(styleId); |
| } |
| |
| void mouseMove(const TPointD &pos, const TMouseEvent &e) |
| { |
| if (!m_passivePick.getValue()) |
| return; |
| |
| PaletteController *controller = TTool::getApplication()->getPaletteController(); |
| |
| TImageP image = getImage(false); |
| TToonzImageP ti = image; |
| TVectorImageP vi = image; |
| TXshSimpleLevel *level = getApplication()->getCurrentLevel()->getSimpleLevel(); |
| if ((!ti && !vi) || !level || !m_viewer->getGeometry().contains(pos)) { |
| controller->notifyStylePassivePicked(-1, -1, -1); |
| return; |
| } |
| |
| int subsampling = level->getImageSubsampling(getCurrentFid()); |
| StylePicker picker(image); |
| TPointD pickPos(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5)); |
| int inkStyleId = picker.pickStyleId(pickPos, getPixelSize() * getPixelSize(), 1); |
| int paintStyleId = picker.pickStyleId(pickPos, getPixelSize() * getPixelSize(), 0); |
| int tone = picker.pickTone(pickPos); |
| controller->notifyStylePassivePicked(inkStyleId, paintStyleId, tone); |
| } |
| |
| void onActivate() |
| { |
| } |
| |
| int getCursorId() const |
| { |
| |
| bool isBlackBG = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg; |
| |
| if (m_colorType.getValue() == LINES) |
| return (isBlackBG) ? ToolCursor::PickerCursorWhiteLine : ToolCursor::PickerCursorLine; |
| else if (m_colorType.getValue() == AREAS) |
| return (isBlackBG) ? ToolCursor::PickerCursorWhiteArea : ToolCursor::PickerCursorArea; |
| else |
| return (isBlackBG) ? ToolCursor::PickerCursorWhite : ToolCursor::PickerCursor; |
| } |
| |
| } stylePickerTool; |
| } |
| |