|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/tool.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/cursors.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/stylepicker.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshsimplelevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "drawutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttoonzimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tundo.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tpalettehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/stage2.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tproperty.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/tselectionhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/styleselection.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheethandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/preferences.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tcolumnhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/dpiscale.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/palettecontroller.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define LINES L"Lines"
|
|
Toshihiro Shimizu |
890ddd |
#define AREAS L"Areas"
|
|
Toshihiro Shimizu |
890ddd |
#define ALL L"Lines & Areas"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================================
|
|
Toshihiro Shimizu |
890ddd |
// Pick Style Tool
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class StylePickerTool : public TTool
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int m_oldStyleId, m_currentStyleId;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEnumProperty m_colorType;
|
|
Toshihiro Shimizu |
890ddd |
TPropertyGroup m_prop;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TBoolProperty m_passivePick;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TPropertyGroup *getProperties(int targetType) { return &m_prop; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
StylePickerTool()
|
|
Toshihiro Shimizu |
890ddd |
: TTool("T_StylePicker"), m_currentStyleId(0), m_colorType("Mode:"), m_passivePick("Passive Pick", false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_colorType);
|
|
Toshihiro Shimizu |
890ddd |
m_colorType.addValue(AREAS);
|
|
Toshihiro Shimizu |
890ddd |
m_colorType.addValue(LINES);
|
|
Toshihiro Shimizu |
890ddd |
m_colorType.addValue(ALL);
|
|
Toshihiro Shimizu |
890ddd |
m_colorType.setId("Mode");
|
|
Toshihiro Shimizu |
890ddd |
bind(TTool::CommonLevels);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_passivePick);
|
|
Toshihiro Shimizu |
890ddd |
m_passivePick.setId("PassivePick");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ToolType getToolType() const { return TTool::LevelReadTool; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void draw()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void leftButtonDown(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_oldStyleId = m_currentStyleId = getApplication()->getCurrentLevelStyleIndex();
|
|
Toshihiro Shimizu |
890ddd |
pick(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
pick(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void pick(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//Area = 0, Line = 1, All = 2
|
|
Toshihiro Shimizu |
890ddd |
int modeValue = m_colorType.getIndex();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// MultiLayerStylePicker
|
|
Toshihiro Shimizu |
890ddd |
/*---
|
|
Toshihiro Shimizu |
890ddd |
PickしたStyleId = 0、かつ
|
|
Toshihiro Shimizu |
890ddd |
Preference で MultiLayerStylePickerが有効、かつ
|
|
Toshihiro Shimizu |
890ddd |
Scene編集モード、かつ
|
|
Toshihiro Shimizu |
890ddd |
下のカラムから拾った色がTransparentでない場合、
|
|
Toshihiro Shimizu |
890ddd |
→ カレントLevelを移動する。
|
|
Toshihiro Shimizu |
890ddd |
---*/
|
|
Toshihiro Shimizu |
890ddd |
if (Preferences::instance()->isMultiLayerStylePickerEnabled() &&
|
|
Toshihiro Shimizu |
890ddd |
getApplication()->getCurrentFrame()->isEditingScene()) {
|
|
Toshihiro Shimizu |
890ddd |
int superPickedColumnId = getViewer()->posToColumnIndex(e.m_pos, getPixelSize() * getPixelSize(), false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (superPickedColumnId >= 0 /*-- 何かColumnに当たった場合 --*/
|
|
Toshihiro Shimizu |
890ddd |
&& getApplication()->getCurrentColumn()->getColumnIndex() != superPickedColumnId) /*-- かつ、Current Columnでない場合 --*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*-- そのColumnからPickを試みる --*/
|
|
Toshihiro Shimizu |
890ddd |
int currentFrame = getApplication()->getCurrentFrame()->getFrame();
|
|
Toshihiro Shimizu |
890ddd |
TXshCell pickedCell = getApplication()->getCurrentXsheet()->getXsheet()->getCell(currentFrame, superPickedColumnId);
|
|
Toshihiro Shimizu |
890ddd |
TImageP pickedImage = pickedCell.getImage(false).getPointer();
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP picked_ti = pickedImage;
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP picked_vi = pickedImage;
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *picked_level = pickedCell.getSimpleLevel();
|
|
Toshihiro Shimizu |
890ddd |
if ((picked_ti || picked_vi) && picked_level) {
|
|
Toshihiro Shimizu |
890ddd |
TPointD tmpMousePosition = getColumnMatrix(superPickedColumnId).inv() * getViewer()->winToWorld(e.m_pos);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD tmpDpiScale = getCurrentDpiScale(picked_level, getCurrentFid());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tmpMousePosition.x /= tmpDpiScale.x;
|
|
Toshihiro Shimizu |
890ddd |
tmpMousePosition.y /= tmpDpiScale.y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
StylePicker superPicker(pickedImage);
|
|
Toshihiro Shimizu |
890ddd |
int picked_subsampling = picked_level->getImageSubsampling(pickedCell.getFrameId());
|
|
Toshihiro Shimizu |
890ddd |
int superPicked_StyleId = superPicker.pickStyleId(TScale(1.0 / picked_subsampling) * tmpMousePosition + TPointD(-0.5, -0.5),
|
|
Toshihiro Shimizu |
890ddd |
getPixelSize() * getPixelSize(),
|
|
Toshihiro Shimizu |
890ddd |
modeValue);
|
|
Toshihiro Shimizu |
890ddd |
/*-- 何かStyleが拾えて、Transparentでない場合 --*/
|
|
Toshihiro Shimizu |
890ddd |
if (superPicked_StyleId > 0) {
|
|
Toshihiro Shimizu |
890ddd |
/*-- Levelの移動 --*/
|
|
Toshihiro Shimizu |
890ddd |
getApplication()->getCurrentLevel()->setLevel(picked_level);
|
|
Toshihiro Shimizu |
890ddd |
/*-- Columnの移動 --*/
|
|
Toshihiro Shimizu |
890ddd |
getApplication()->getCurrentColumn()->setColumnIndex(superPickedColumnId);
|
|
Toshihiro Shimizu |
890ddd |
/*-- 選択の解除 --*/
|
|
Toshihiro Shimizu |
890ddd |
if (getApplication()->getCurrentSelection()->getSelection())
|
|
Toshihiro Shimizu |
890ddd |
getApplication()->getCurrentSelection()->getSelection()->selectNone();
|
|
Toshihiro Shimizu |
890ddd |
/*-- StyleIdの移動 --*/
|
|
Toshihiro Shimizu |
890ddd |
getApplication()->setCurrentLevelStyleIndex(superPicked_StyleId);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*-- MultiLayerStylePicker ここまで --*/
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
TImageP image = getImage(false);
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = image;
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP vi = image;
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *level = getApplication()->getCurrentLevel()->getSimpleLevel();
|
|
Toshihiro Shimizu |
890ddd |
if ((!ti && !vi) || !level)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- 画面外をpickしても拾えないようにする --*/
|
|
Toshihiro Shimizu |
890ddd |
if (!m_viewer->getGeometry().contains(pos))
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int subsampling = level->getImageSubsampling(getCurrentFid());
|
|
Toshihiro Shimizu |
890ddd |
StylePicker picker(image);
|
|
Toshihiro Shimizu |
890ddd |
int styleId = picker.pickStyleId(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5), getPixelSize() * getPixelSize(), modeValue);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (styleId < 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (modeValue == 1) //LINES
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*-- pickLineモードのとき、取得Styleが0の場合はカレントStyleを変えない。 --*/
|
|
Toshihiro Shimizu |
890ddd |
if (styleId == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
/*-- pickLineモードのとき、PurePaintの部分をクリックしてもカレントStyleを変えない --*/
|
|
Toshihiro Shimizu |
890ddd |
if (ti && picker.pickTone(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5)) == 255)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*--- Styleを選択している場合は選択を解除する ---*/
|
|
Toshihiro Shimizu |
890ddd |
TSelection *selection = TTool::getApplication()->getCurrentSelection()->getSelection();
|
|
Toshihiro Shimizu |
890ddd |
if (selection) {
|
|
Toshihiro Shimizu |
890ddd |
TStyleSelection *styleSelection = dynamic_cast<tstyleselection *="">(selection);</tstyleselection>
|
|
Toshihiro Shimizu |
890ddd |
if (styleSelection)
|
|
Toshihiro Shimizu |
890ddd |
styleSelection->selectNone();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
getApplication()->setCurrentLevelStyleIndex(styleId);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void mouseMove(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_passivePick.getValue())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
/*--- PassiveにStyleを拾う機能 ---*/
|
|
Toshihiro Shimizu |
890ddd |
PaletteController *controller = TTool::getApplication()->getPaletteController();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP image = getImage(false);
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = image;
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP vi = image;
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *level = getApplication()->getCurrentLevel()->getSimpleLevel();
|
|
Toshihiro Shimizu |
890ddd |
if ((!ti && !vi) || !level || !m_viewer->getGeometry().contains(pos)) {
|
|
Toshihiro Shimizu |
890ddd |
controller->notifyStylePassivePicked(-1, -1, -1);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int subsampling = level->getImageSubsampling(getCurrentFid());
|
|
Toshihiro Shimizu |
890ddd |
StylePicker picker(image);
|
|
Toshihiro Shimizu |
890ddd |
TPointD pickPos(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5));
|
|
Toshihiro Shimizu |
890ddd |
int inkStyleId = picker.pickStyleId(pickPos, getPixelSize() * getPixelSize(), 1);
|
|
Toshihiro Shimizu |
890ddd |
int paintStyleId = picker.pickStyleId(pickPos, getPixelSize() * getPixelSize(), 0);
|
|
Toshihiro Shimizu |
890ddd |
int tone = picker.pickTone(pickPos);
|
|
Toshihiro Shimizu |
890ddd |
controller->notifyStylePassivePicked(inkStyleId, paintStyleId, tone);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void onActivate()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getCursorId() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isBlackBG = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_colorType.getValue() == LINES)
|
|
Toshihiro Shimizu |
890ddd |
return (isBlackBG) ? ToolCursor::PickerCursorWhiteLine : ToolCursor::PickerCursorLine;
|
|
Toshihiro Shimizu |
890ddd |
else if (m_colorType.getValue() == AREAS)
|
|
Toshihiro Shimizu |
890ddd |
return (isBlackBG) ? ToolCursor::PickerCursorWhiteArea : ToolCursor::PickerCursorArea;
|
|
Toshihiro Shimizu |
890ddd |
else //line&areas
|
|
Toshihiro Shimizu |
890ddd |
return (isBlackBG) ? ToolCursor::PickerCursorWhite : ToolCursor::PickerCursor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} stylePickerTool;
|
|
Toshihiro Shimizu |
890ddd |
}
|