|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "fullcolorbrushtool.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzTools includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/tool.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/cursors.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/tooloptions.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "bluredbrush.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzQt includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/dvdialog.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tpalettehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheethandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tobjecthandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/ttileset.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/ttilesaver.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/strokegenerator.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tstageobject.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/palettecontroller.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tproperty.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tenv.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpalette.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstream.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstroke.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "timagecache.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Shinya Kitaoka |
120a6e |
#include <qcoreapplication> // Qt translation support</qcoreapplication>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar FullcolorBrushMinSize("FullcolorBrushMinSize", 1);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar FullcolorBrushMaxSize("FullcolorBrushMaxSize", 5);
|
|
Campbell Barton |
f49389 |
TEnv::IntVar FullcolorPressureSensitivity("FullcolorPressureSensitivity", 1);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar FullcolorBrushHardness("FullcolorBrushHardness", 100);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar FullcolorMinOpacity("FullcolorMinOpacity", 100);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar FullcolorMaxOpacity("FullcolorMaxOpacity", 100);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define CUSTOM_WSTR L"<custom>"</custom>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int computeThickness(int pressure, const TIntPairProperty &property,
|
|
Shinya Kitaoka |
120a6e |
bool isPath = false) {
|
|
Shinya Kitaoka |
120a6e |
if (isPath) return 0.0;
|
|
Shinya Kitaoka |
120a6e |
double p = pressure / 255.0;
|
|
Shinya Kitaoka |
120a6e |
double t = p * p * p;
|
|
Shinya Kitaoka |
120a6e |
int thick0 = property.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
int thick1 = property.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
return tround(thick0 + (thick1 - thick0) * t);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
double computeThickness(int pressure, const TDoublePairProperty &property,
|
|
Shinya Kitaoka |
120a6e |
bool isPath = false) {
|
|
Shinya Kitaoka |
120a6e |
if (isPath) return 0.0;
|
|
Shinya Kitaoka |
120a6e |
double p = pressure / 255.0;
|
|
Shinya Kitaoka |
120a6e |
double t = p * p * p;
|
|
Shinya Kitaoka |
120a6e |
double thick0 = property.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
double thick1 = property.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
if (thick1 < 0.0001) thick0 = thick1 = 0.0;
|
|
Shinya Kitaoka |
120a6e |
return (thick0 + (thick1 - thick0) * t);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class FullColorBrushUndo final : public ToolUtils::TFullColorRasterUndo {
|
|
Shinya Kitaoka |
120a6e |
TPoint m_offset;
|
|
Shinya Kitaoka |
120a6e |
QString m_id;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
FullColorBrushUndo(TTileSetFullColor *tileSet, TXshSimpleLevel *level,
|
|
Shinya Kitaoka |
120a6e |
const TFrameId &frameId, bool isFrameCreated,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &ras, const TPoint &offset)
|
|
Shinya Kitaoka |
120a6e |
: ToolUtils::TFullColorRasterUndo(tileSet, level, frameId, isFrameCreated,
|
|
Shinya Kitaoka |
120a6e |
false, 0)
|
|
Shinya Kitaoka |
120a6e |
, m_offset(offset) {
|
|
Shinya Kitaoka |
120a6e |
static int counter = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_id = QString("FullColorBrushUndo") + QString::number(counter++);
|
|
Shinya Kitaoka |
120a6e |
TImageCache::instance()->add(m_id.toStdString(), TRasterImageP(ras));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~FullColorBrushUndo() { TImageCache::instance()->remove(m_id); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
insertLevelAndFrameIfNeeded();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP image = getImage();
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = image->getRaster();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP srcImg =
|
|
Shinya Kitaoka |
120a6e |
TImageCache::instance()->get(m_id.toStdString(), false);
|
|
Shinya Kitaoka |
120a6e |
ras->copy(srcImg->getRaster(), m_offset);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
notifyImageChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override {
|
|
Shinya Kitaoka |
120a6e |
return sizeof(*this) + ToolUtils::TFullColorRasterUndo::getSize();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getToolName() override { return QString("Raster Brush Tool"); }
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::BrushTool; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// FullColor Brush Tool implementation
|
|
Toshihiro Shimizu |
890ddd |
//************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
FullColorBrushTool::FullColorBrushTool(std::string name)
|
|
Shinya Kitaoka |
120a6e |
: TTool(name)
|
|
Jeremy Bullock |
01e454 |
, m_thickness("Size", 1, 100, 1, 5, false)
|
|
Jeremy Bullock |
01e454 |
, m_pressure("Pressure", true)
|
|
Jeremy Bullock |
01e454 |
, m_opacity("Opacity", 0, 100, 100, 100, true)
|
|
Shinya Kitaoka |
120a6e |
, m_hardness("Hardness:", 0, 100, 100)
|
|
Shinya Kitaoka |
120a6e |
, m_preset("Preset:")
|
|
Shinya Kitaoka |
120a6e |
, m_styleId(0)
|
|
Shinya Kitaoka |
120a6e |
, m_oldOpacity(1)
|
|
Shinya Kitaoka |
120a6e |
, m_brush(0)
|
|
Shinya Kitaoka |
120a6e |
, m_tileSet(0)
|
|
Shinya Kitaoka |
120a6e |
, m_tileSaver(0)
|
|
Shinya Kitaoka |
120a6e |
, m_notifier(0)
|
|
Shinya Kitaoka |
120a6e |
, m_presetsLoaded(false)
|
|
Shinya Kitaoka |
120a6e |
, m_firstTime(true) {
|
|
Shinya Kitaoka |
120a6e |
bind(TTool::RasterImage | TTool::EmptyTarget);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_thickness);
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_hardness);
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_opacity);
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_pressure);
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_preset);
|
|
Shinya Kitaoka |
120a6e |
m_preset.setId("BrushPreset");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ToolOptionsBox *FullColorBrushTool::createOptionsBox() {
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *currPalette =
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getPaletteController()->getCurrentLevelPalette();
|
|
Shinya Kitaoka |
120a6e |
ToolHandle *currTool = TTool::getApplication()->getCurrentTool();
|
|
Shinya Kitaoka |
120a6e |
return new BrushToolOptionsBox(0, this, currPalette, currTool);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::onCanvasSizeChanged() {
|
|
Shinya Kitaoka |
120a6e |
onDeactivate();
|
|
Shinya Kitaoka |
120a6e |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::updateTranslation() {
|
|
Jeremy Bullock |
01e454 |
m_thickness.setQStringName(tr("Size"));
|
|
Jeremy Bullock |
01e454 |
m_pressure.setQStringName(tr("Pressure"));
|
|
Jeremy Bullock |
01e454 |
m_opacity.setQStringName(tr("Opacity"));
|
|
Shinya Kitaoka |
120a6e |
m_hardness.setQStringName(tr("Hardness:"));
|
|
Shinya Kitaoka |
120a6e |
m_preset.setQStringName(tr("Preset:"));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::onActivate() {
|
|
Shinya Kitaoka |
120a6e |
if (!m_notifier) m_notifier = new FullColorBrushToolNotifier(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
e3df22 |
updateCurrentColor();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_firstTime) {
|
|
Shinya Kitaoka |
120a6e |
m_firstTime = false;
|
|
Shinya Kitaoka |
120a6e |
m_thickness.setValue(
|
|
Shinya Kitaoka |
120a6e |
TIntPairProperty::Value(FullcolorBrushMinSize, FullcolorBrushMaxSize));
|
|
Campbell Barton |
f49389 |
m_pressure.setValue(FullcolorPressureSensitivity ? 1 : 0);
|
|
Shinya Kitaoka |
120a6e |
m_opacity.setValue(
|
|
Shinya Kitaoka |
120a6e |
TDoublePairProperty::Value(FullcolorMinOpacity, FullcolorMaxOpacity));
|
|
Shinya Kitaoka |
120a6e |
m_hardness.setValue(FullcolorBrushHardness);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_brushPad = ToolUtils::getBrushPad(m_thickness.getValue().second,
|
|
Shinya Kitaoka |
120a6e |
m_hardness.getValue() * 0.01);
|
|
Shinya Kitaoka |
120a6e |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::onDeactivate() {
|
|
Jeremy Bullock |
5af997 |
if (m_mousePressed) leftButtonUp(m_mousePos, m_mouseEvent);
|
|
Shinya Kitaoka |
120a6e |
m_workRaster = TRaster32P();
|
|
Shinya Kitaoka |
120a6e |
m_backUpRas = TRasterP();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::updateWorkAndBackupRasters(const TRect &rect) {
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = TImageP(getImage(false, 1));
|
|
Shinya Kitaoka |
120a6e |
if (!ri) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRect _rect = rect * ras->getBounds();
|
|
Shinya Kitaoka |
120a6e |
TRect _lastRect = m_lastRect * ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (_rect.isEmpty()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_lastRect.isEmpty()) {
|
|
Shinya Kitaoka |
120a6e |
m_workRaster->extract(_rect)->clear();
|
|
Shinya Kitaoka |
120a6e |
m_backUpRas->extract(_rect)->copy(ras->extract(_rect));
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QList<trect> rects = ToolUtils::splitRect(_rect, _lastRect);</trect>
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < rects.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
m_workRaster->extract(rects[i])->clear();
|
|
Shinya Kitaoka |
120a6e |
m_backUpRas->extract(rects[i])->copy(ras->extract(rects[i]));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool FullColorBrushTool::preLeftButtonDown() {
|
|
Shinya Kitaoka |
120a6e |
touchImage();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_isFrameCreated) setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::leftButtonDown(const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_brushPos = m_mousePos = pos;
|
|
Jeremy Bullock |
5af997 |
m_mousePressed = true;
|
|
Jeremy Bullock |
5af997 |
m_mouseEvent = e;
|
|
Jeremy Bullock |
5af997 |
Viewer *viewer = getViewer();
|
|
Shinya Kitaoka |
120a6e |
if (!viewer) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)getImage(true);
|
|
Shinya Kitaoka |
120a6e |
if (!ri) ri = (TRasterImageP)touchImage();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!ri) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
e3df22 |
/* update color here since the current style might be switched with numpad
|
|
shun_iwasawa |
e3df22 |
* shortcut keys */
|
|
shun_iwasawa |
e3df22 |
updateCurrentColor();
|
|
shun_iwasawa |
e3df22 |
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = ri->getRaster();
|
|
Shinya Kitaoka |
120a6e |
TDimension dim = ras->getSize();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!(m_workRaster && m_backUpRas)) setWorkAndBackupImages();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_workRaster->lock();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double maxThick = m_thickness.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
double thickness = m_pressure.getValue()
|
|
Shinya Kitaoka |
120a6e |
? computeThickness(e.m_pressure, m_thickness)
|
|
Shinya Kitaoka |
120a6e |
: maxThick;
|
|
Shinya Kitaoka |
120a6e |
double opacity =
|
|
Shinya Kitaoka |
120a6e |
(m_pressure.getValue() ? computeThickness(e.m_pressure, m_opacity)
|
|
Shinya Kitaoka |
120a6e |
: m_opacity.getValue().second) *
|
|
Shinya Kitaoka |
120a6e |
0.01;
|
|
Shinya Kitaoka |
120a6e |
TPointD rasCenter = TPointD(dim.lx * 0.5, dim.ly * 0.5);
|
|
Shinya Kitaoka |
120a6e |
TThickPoint point(pos + rasCenter, thickness);
|
|
Shinya Kitaoka |
120a6e |
TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
|
|
Shinya Kitaoka |
120a6e |
TRectD invalidateRect(pos - halfThick, pos + halfThick);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_points.clear();
|
|
Shinya Kitaoka |
120a6e |
m_points.push_back(point);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_tileSet = new TTileSetFullColor(ras->getSize());
|
|
Shinya Kitaoka |
120a6e |
m_tileSaver = new TTileSaverFullColor(ras, m_tileSet);
|
|
Shinya Kitaoka |
120a6e |
double hardness = m_hardness.getValue() * 0.01;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_brush =
|
|
Shinya Kitaoka |
120a6e |
new BluredBrush(m_workRaster, maxThick, m_brushPad, hardness == 1.0);
|
|
Shinya Kitaoka |
120a6e |
m_strokeRect = m_brush->getBoundFromPoints(m_points);
|
|
Shinya Kitaoka |
120a6e |
updateWorkAndBackupRasters(m_strokeRect);
|
|
Shinya Kitaoka |
120a6e |
m_tileSaver->save(m_strokeRect);
|
|
Shinya Kitaoka |
120a6e |
m_brush->addPoint(point, opacity);
|
|
Shinya Kitaoka |
120a6e |
m_brush->updateDrawing(ras, m_backUpRas, m_currentColor, m_strokeRect,
|
|
Shinya Kitaoka |
120a6e |
m_opacity.getValue().second * 0.01);
|
|
Shinya Kitaoka |
120a6e |
m_oldOpacity = opacity;
|
|
Shinya Kitaoka |
120a6e |
m_lastRect = m_strokeRect;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
invalidate(invalidateRect.enlarge(2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::leftButtonDrag(const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_brushPos = m_mousePos = pos;
|
|
Jeremy Bullock |
5af997 |
m_mouseEvent = e;
|
|
Jeremy Bullock |
5af997 |
TRasterImageP ri = (TRasterImageP)getImage(true);
|
|
Shinya Kitaoka |
120a6e |
if (!ri) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double maxThickness = m_thickness.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
double thickness = m_pressure.getValue()
|
|
Shinya Kitaoka |
120a6e |
? computeThickness(e.m_pressure, m_thickness)
|
|
Shinya Kitaoka |
120a6e |
: maxThickness;
|
|
Shinya Kitaoka |
120a6e |
double opacity =
|
|
Shinya Kitaoka |
120a6e |
(m_pressure.getValue() ? computeThickness(e.m_pressure, m_opacity)
|
|
Shinya Kitaoka |
120a6e |
: m_opacity.getValue().second) *
|
|
Shinya Kitaoka |
120a6e |
0.01;
|
|
Shinya Kitaoka |
120a6e |
TDimension size = m_workRaster->getSize();
|
|
Shinya Kitaoka |
120a6e |
TPointD rasCenter = TPointD(size.lx * 0.5, size.ly * 0.5);
|
|
Shinya Kitaoka |
120a6e |
TThickPoint point(pos + rasCenter, thickness);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TThickPoint old = m_points.back();
|
|
Shinya Kitaoka |
120a6e |
if (norm2(point - old) < 4) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);
|
|
Shinya Kitaoka |
120a6e |
m_points.push_back(mid);
|
|
Shinya Kitaoka |
120a6e |
m_points.push_back(point);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRect bbox;
|
|
Shinya Kitaoka |
120a6e |
int m = m_points.size();
|
|
Shinya Kitaoka |
120a6e |
TRectD invalidateRect;
|
|
Shinya Kitaoka |
120a6e |
if (m == 3) {
|
|
Shinya Kitaoka |
120a6e |
// ho appena cominciato. devo disegnare un segmento
|
|
Shinya Kitaoka |
120a6e |
TThickPoint pa = m_points.front();
|
|
Shinya Kitaoka |
120a6e |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Shinya Kitaoka |
120a6e |
points.push_back(pa);
|
|
Shinya Kitaoka |
120a6e |
points.push_back(mid);
|
|
Shinya Kitaoka |
120a6e |
invalidateRect = ToolUtils::getBounds(points, maxThickness);
|
|
Shinya Kitaoka |
120a6e |
bbox = m_brush->getBoundFromPoints(points);
|
|
Shinya Kitaoka |
120a6e |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
Shinya Kitaoka |
120a6e |
m_tileSaver->save(bbox);
|
|
Shinya Kitaoka |
120a6e |
m_brush->addArc(pa, (pa + mid) * 0.5, mid, m_oldOpacity, opacity);
|
|
Shinya Kitaoka |
120a6e |
m_lastRect += bbox;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
// caso generale: disegno un arco
|
|
Shinya Kitaoka |
120a6e |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[m - 4]);
|
|
Shinya Kitaoka |
120a6e |
points.push_back(old);
|
|
Shinya Kitaoka |
120a6e |
points.push_back(mid);
|
|
Shinya Kitaoka |
120a6e |
invalidateRect = ToolUtils::getBounds(points, maxThickness);
|
|
Shinya Kitaoka |
120a6e |
bbox = m_brush->getBoundFromPoints(points);
|
|
Shinya Kitaoka |
120a6e |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
Shinya Kitaoka |
120a6e |
m_tileSaver->save(bbox);
|
|
Shinya Kitaoka |
120a6e |
m_brush->addArc(m_points[m - 4], old, mid, m_oldOpacity, opacity);
|
|
Shinya Kitaoka |
120a6e |
m_lastRect += bbox;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_oldOpacity = opacity;
|
|
Shinya Kitaoka |
120a6e |
m_brush->updateDrawing(ri->getRaster(), m_backUpRas, m_currentColor, bbox,
|
|
Shinya Kitaoka |
120a6e |
m_opacity.getValue().second * 0.01);
|
|
Shinya Kitaoka |
120a6e |
invalidate(invalidateRect.enlarge(2) - rasCenter);
|
|
Shinya Kitaoka |
120a6e |
m_strokeRect += bbox;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::leftButtonUp(const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_brushPos = m_mousePos = pos;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)getImage(true);
|
|
Shinya Kitaoka |
120a6e |
if (!ri) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_points.size() != 1) {
|
|
Shinya Kitaoka |
120a6e |
double maxThickness = m_thickness.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
double thickness = m_pressure.getValue()
|
|
Shinya Kitaoka |
120a6e |
? computeThickness(e.m_pressure, m_thickness)
|
|
Shinya Kitaoka |
120a6e |
: maxThickness;
|
|
Shinya Kitaoka |
120a6e |
double opacity =
|
|
Shinya Kitaoka |
120a6e |
(m_pressure.getValue() ? computeThickness(e.m_pressure, m_opacity)
|
|
Shinya Kitaoka |
120a6e |
: m_opacity.getValue().second) *
|
|
Shinya Kitaoka |
120a6e |
0.01;
|
|
Shinya Kitaoka |
120a6e |
TPointD rasCenter = ri->getRaster()->getCenterD();
|
|
Shinya Kitaoka |
120a6e |
TThickPoint point(pos + rasCenter, thickness);
|
|
Shinya Kitaoka |
120a6e |
m_points.push_back(point);
|
|
Shinya Kitaoka |
120a6e |
int m = m_points.size();
|
|
Shinya Kitaoka |
120a6e |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[m - 3]);
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[m - 2]);
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[m - 1]);
|
|
Shinya Kitaoka |
120a6e |
TRect bbox = m_brush->getBoundFromPoints(points);
|
|
Shinya Kitaoka |
120a6e |
updateWorkAndBackupRasters(bbox);
|
|
Shinya Kitaoka |
120a6e |
m_tileSaver->save(bbox);
|
|
Shinya Kitaoka |
120a6e |
m_brush->addArc(points[0], points[1], points[2], m_oldOpacity, opacity);
|
|
Shinya Kitaoka |
120a6e |
m_brush->updateDrawing(ri->getRaster(), m_backUpRas, m_currentColor, bbox,
|
|
Shinya Kitaoka |
120a6e |
m_opacity.getValue().second * 0.01);
|
|
Shinya Kitaoka |
120a6e |
TRectD invalidateRect = ToolUtils::getBounds(points, maxThickness);
|
|
Shinya Kitaoka |
120a6e |
invalidate(invalidateRect.enlarge(2) - rasCenter);
|
|
Shinya Kitaoka |
120a6e |
m_strokeRect += bbox;
|
|
Shinya Kitaoka |
120a6e |
m_lastRect.empty();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_brush) {
|
|
Shinya Kitaoka |
120a6e |
delete m_brush;
|
|
Shinya Kitaoka |
120a6e |
m_brush = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_workRaster->unlock();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_tileSet->getTileCount() > 0) {
|
|
Shinya Kitaoka |
120a6e |
delete m_tileSaver;
|
|
Shinya Kitaoka |
120a6e |
TTool::Application *app = TTool::getApplication();
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
TFrameId frameId = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = ri->getRaster()->extract(m_strokeRect)->clone();
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(
|
|
Shinya Kitaoka |
120a6e |
new FullColorBrushUndo(m_tileSet, simLevel.getPointer(), frameId,
|
|
Shinya Kitaoka |
120a6e |
m_isFrameCreated, ras, m_strokeRect.getP00()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
notifyImageChanged();
|
|
Shinya Kitaoka |
120a6e |
m_strokeRect.empty();
|
|
Jeremy Bullock |
5af997 |
m_mousePressed = false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
struct Locals {
|
|
Shinya Kitaoka |
120a6e |
FullColorBrushTool *m_this;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void setValue(TIntPairProperty &prop,
|
|
Shinya Kitaoka |
120a6e |
const TIntPairProperty::Value &value) {
|
|
Shinya Kitaoka |
120a6e |
prop.setValue(value);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_this->onPropertyChanged(prop.getName());
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void addMinMax(TIntPairProperty &prop, double add) {
|
|
Shinya Kitaoka |
120a6e |
const TIntPairProperty::Range &range = prop.getRange();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TIntPairProperty::Value value = prop.getValue();
|
|
Shinya Kitaoka |
120a6e |
value.second =
|
|
Shinya Kitaoka |
120a6e |
tcrop<double>(value.second + add, range.first, range.second);</double>
|
|
Shinya Kitaoka |
120a6e |
value.first = tcrop<double>(value.first + add, range.first, range.second);</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setValue(prop, value);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jeremy Bullock |
01e454 |
void addMinMaxSeparate(TIntPairProperty &prop, double min, double max) {
|
|
Jeremy Bullock |
01e454 |
if (min == 0.0 && max == 0.0) return;
|
|
Jeremy Bullock |
01e454 |
const TIntPairProperty::Range &range = prop.getRange();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jeremy Bullock |
01e454 |
TIntPairProperty::Value value = prop.getValue();
|
|
Jeremy Bullock |
01e454 |
value.first += min;
|
|
Jeremy Bullock |
01e454 |
value.second += max;
|
|
Jeremy Bullock |
01e454 |
if (value.first > value.second) value.first = value.second;
|
|
Jeremy Bullock |
01e454 |
value.first = tcrop<double>(value.first, range.first, range.second);</double>
|
|
Jeremy Bullock |
01e454 |
value.second = tcrop<double>(value.second, range.first, range.second);</double>
|
|
Jeremy Bullock |
01e454 |
|
|
Jeremy Bullock |
01e454 |
setValue(prop, value);
|
|
Jeremy Bullock |
01e454 |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jeremy Bullock |
01e454 |
} locals = {this};
|
|
Shinya Kitaoka |
d4642c |
|
|
Jeremy Bullock |
01e454 |
// if (e.isAltPressed() && !e.isCtrlPressed()) {
|
|
Jeremy Bullock |
01e454 |
// const TPointD &diff = pos - m_mousePos;
|
|
Jeremy Bullock |
01e454 |
// double add = (fabs(diff.x) > fabs(diff.y)) ? diff.x : diff.y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jeremy Bullock |
01e454 |
// locals.addMinMax(m_thickness, int(add));
|
|
Jeremy Bullock |
01e454 |
//} else
|
|
Jeremy Bullock |
01e454 |
if (e.isCtrlPressed() && e.isAltPressed()) {
|
|
Jeremy Bullock |
01e454 |
const TPointD &diff = pos - m_mousePos;
|
|
Jeremy Bullock |
01e454 |
double max = diff.x / 2;
|
|
Jeremy Bullock |
01e454 |
double min = diff.y / 2;
|
|
Jeremy Bullock |
01e454 |
|
|
Jeremy Bullock |
01e454 |
locals.addMinMaxSeparate(m_thickness, int(min), int(max));
|
|
Jeremy Bullock |
01e454 |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_brushPos = pos;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_mousePos = pos;
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::draw() {
|
|
Shinya Kitaoka |
120a6e |
if (TRasterImageP ri = TRasterImageP(getImage(false))) {
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
glColor3d(1.0, 0.0, 0.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
tglDrawCircle(m_brushPos, (m_minThick + 1) * 0.5);
|
|
Shinya Kitaoka |
120a6e |
tglDrawCircle(m_brushPos, (m_maxThick + 1) * 0.5);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::onEnter() {
|
|
Shinya Kitaoka |
120a6e |
TImageP img = getImage(false);
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri(img);
|
|
Shinya Kitaoka |
120a6e |
if (ri) {
|
|
Shinya Kitaoka |
120a6e |
m_minThick = m_thickness.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
m_maxThick = m_thickness.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_minThick = 0;
|
|
Shinya Kitaoka |
120a6e |
m_maxThick = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
e3df22 |
updateCurrentColor();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::onLeave() {
|
|
Shinya Kitaoka |
120a6e |
m_minThick = 0;
|
|
Shinya Kitaoka |
120a6e |
m_maxThick = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPropertyGroup *FullColorBrushTool::getProperties(int targetType) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_presetsLoaded) initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return &m_prop;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::onImageChanged() { setWorkAndBackupImages(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::setWorkAndBackupImages() {
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)getImage(false, 1);
|
|
Shinya Kitaoka |
120a6e |
if (!ri) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = ri->getRaster();
|
|
Shinya Kitaoka |
120a6e |
TDimension dim = ras->getSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!m_workRaster || m_workRaster->getLx() > dim.lx ||
|
|
Shinya Kitaoka |
120a6e |
m_workRaster->getLy() > dim.ly)
|
|
Shinya Kitaoka |
120a6e |
m_workRaster = TRaster32P(dim);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!m_backUpRas || m_backUpRas->getLx() > dim.lx ||
|
|
Shinya Kitaoka |
120a6e |
m_backUpRas->getLy() > dim.ly ||
|
|
Shinya Kitaoka |
120a6e |
m_backUpRas->getPixelSize() != ras->getPixelSize())
|
|
Shinya Kitaoka |
120a6e |
m_backUpRas = ras->create(dim.lx, dim.ly);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_strokeRect.empty();
|
|
Shinya Kitaoka |
120a6e |
m_lastRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool FullColorBrushTool::onPropertyChanged(std::string propertyName) {
|
|
Shinya Kitaoka |
120a6e |
m_minThick = m_thickness.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
m_maxThick = m_thickness.getValue().second;
|
|
Jeremy Bullock |
01e454 |
if (propertyName == "Hardness:" || propertyName == "Thickness" ||
|
|
Jeremy Bullock |
01e454 |
propertyName == "Size") {
|
|
Shinya Kitaoka |
120a6e |
m_brushPad = ToolUtils::getBrushPad(m_thickness.getValue().second,
|
|
Shinya Kitaoka |
120a6e |
m_hardness.getValue() * 0.01);
|
|
Shinya Kitaoka |
120a6e |
TRectD rect(m_brushPos - TPointD(m_maxThick + 2, m_maxThick + 2),
|
|
Shinya Kitaoka |
120a6e |
m_brushPos + TPointD(m_maxThick + 2, m_maxThick + 2));
|
|
Shinya Kitaoka |
120a6e |
invalidate(rect);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
/*if(propertyName == "Hardness:" || propertyName == "Opacity:")
|
|
Shinya Kitaoka |
120a6e |
setWorkAndBackupImages();*/
|
|
Shinya Kitaoka |
120a6e |
FullcolorBrushMinSize = m_minThick;
|
|
Shinya Kitaoka |
120a6e |
FullcolorBrushMaxSize = m_maxThick;
|
|
Campbell Barton |
f49389 |
FullcolorPressureSensitivity = m_pressure.getValue();
|
|
Shinya Kitaoka |
120a6e |
FullcolorBrushHardness = m_hardness.getValue();
|
|
Shinya Kitaoka |
120a6e |
FullcolorMinOpacity = m_opacity.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
FullcolorMaxOpacity = m_opacity.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (propertyName == "Preset:") {
|
|
Shinya Kitaoka |
120a6e |
loadPreset();
|
|
Shinya Kitaoka |
120a6e |
getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_preset.getValue() != CUSTOM_WSTR) {
|
|
Shinya Kitaoka |
120a6e |
m_preset.setValue(CUSTOM_WSTR);
|
|
Shinya Kitaoka |
120a6e |
getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::initPresets() {
|
|
Shinya Kitaoka |
120a6e |
if (!m_presetsLoaded) {
|
|
Shinya Kitaoka |
120a6e |
// If necessary, load the presets from file
|
|
Shinya Kitaoka |
120a6e |
m_presetsLoaded = true;
|
|
Shinya Kitaoka |
120a6e |
m_presetsManager.load(TEnv::getConfigDir() + "brush_raster.txt");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Rebuild the presets property entries
|
|
Shinya Kitaoka |
120a6e |
const std::set<brushdata> &presets = m_presetsManager.presets();</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_preset.deleteAllValues();
|
|
Shinya Kitaoka |
120a6e |
m_preset.addValue(CUSTOM_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::set<brushdata>::const_iterator it, end = presets.end();</brushdata>
|
|
Shinya Kitaoka |
120a6e |
for (it = presets.begin(); it != end; ++it) m_preset.addValue(it->m_name);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::loadPreset() {
|
|
Shinya Kitaoka |
120a6e |
const std::set<brushdata> &presets = m_presetsManager.presets();</brushdata>
|
|
Shinya Kitaoka |
120a6e |
std::set<brushdata>::const_iterator it;</brushdata>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
it = presets.find(BrushData(m_preset.getValue()));
|
|
Shinya Kitaoka |
120a6e |
if (it == presets.end()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
const BrushData &preset = *it;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
try // Don't bother with RangeErrors
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_thickness.setValue(
|
|
Shinya Kitaoka |
120a6e |
TIntPairProperty::Value(std::max((int)preset.m_min, 1), preset.m_max));
|
|
Shinya Kitaoka |
120a6e |
m_brushPad = ToolUtils::getBrushPad(preset.m_max, preset.m_hardness * 0.01);
|
|
Shinya Kitaoka |
120a6e |
m_hardness.setValue(preset.m_hardness, true);
|
|
Shinya Kitaoka |
120a6e |
m_opacity.setValue(
|
|
Shinya Kitaoka |
120a6e |
TDoublePairProperty::Value(preset.m_opacityMin, preset.m_opacityMax));
|
|
Shinya Kitaoka |
120a6e |
m_pressure.setValue(preset.m_pressure);
|
|
Shinya Kitaoka |
120a6e |
} catch (...) {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::addPreset(QString name) {
|
|
Shinya Kitaoka |
120a6e |
// Build the preset
|
|
Shinya Kitaoka |
120a6e |
BrushData preset(name.toStdWString());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
preset.m_min = m_thickness.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
preset.m_max = m_thickness.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
preset.m_hardness = m_hardness.getValue();
|
|
Shinya Kitaoka |
120a6e |
preset.m_opacityMin = m_opacity.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
preset.m_opacityMax = m_opacity.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
preset.m_pressure = m_pressure.getValue();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Pass the preset to the manager
|
|
Shinya Kitaoka |
120a6e |
m_presetsManager.addPreset(preset);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Reinitialize the associated preset enum
|
|
Shinya Kitaoka |
120a6e |
initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Set the value to the specified one
|
|
Shinya Kitaoka |
120a6e |
m_preset.setValue(preset.m_name);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FullColorBrushTool::removePreset() {
|
|
Shinya Kitaoka |
120a6e |
std::wstring name(m_preset.getValue());
|
|
Shinya Kitaoka |
120a6e |
if (name == CUSTOM_WSTR) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_presetsManager.removePreset(name);
|
|
Shinya Kitaoka |
120a6e |
initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// No parameter change, and set the preset value to custom
|
|
Shinya Kitaoka |
120a6e |
m_preset.setValue(CUSTOM_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
e3df22 |
//------------------------------------------------------------------
|
|
shun_iwasawa |
e3df22 |
|
|
shun_iwasawa |
e3df22 |
void FullColorBrushTool::updateCurrentColor() {
|
|
shun_iwasawa |
e3df22 |
TTool::Application *app = getApplication();
|
|
shun_iwasawa |
e3df22 |
if (app->getCurrentObject()->isSpline()) {
|
|
shun_iwasawa |
e3df22 |
m_currentColor = TPixel32::Red;
|
|
shun_iwasawa |
e3df22 |
return;
|
|
shun_iwasawa |
e3df22 |
}
|
|
shun_iwasawa |
e3df22 |
TPalette *plt = app->getCurrentPalette()->getPalette();
|
|
shun_iwasawa |
e3df22 |
if (!plt) return;
|
|
shun_iwasawa |
e3df22 |
|
|
shun_iwasawa |
e3df22 |
int style = app->getCurrentLevelStyleIndex();
|
|
shun_iwasawa |
e3df22 |
TColorStyle *colorStyle = plt->getStyle(style);
|
|
shun_iwasawa |
e3df22 |
m_currentColor = colorStyle->getMainColor();
|
|
shun_iwasawa |
e3df22 |
}
|
|
shun_iwasawa |
e3df22 |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FullColorBrushToolNotifier::FullColorBrushToolNotifier(FullColorBrushTool *tool)
|
|
Shinya Kitaoka |
120a6e |
: m_tool(tool) {
|
|
Shinya Kitaoka |
120a6e |
TTool::Application *app = m_tool->getApplication();
|
|
Shinya Kitaoka |
120a6e |
TXshLevelHandle *levelHandle;
|
|
Shinya Kitaoka |
120a6e |
if (app) levelHandle = app->getCurrentLevel();
|
|
Shinya Kitaoka |
120a6e |
bool ret = false;
|
|
Shinya Kitaoka |
120a6e |
if (levelHandle) {
|
|
Shinya Kitaoka |
120a6e |
bool ret = connect(levelHandle, SIGNAL(xshCanvasSizeChanged()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onCanvasSizeChanged()));
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FullColorBrushTool fullColorPencil("T_Brush");
|