|
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
|
|
Toshihiro Shimizu |
890ddd |
#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);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar FullcolorPressureSensibility("FullcolorPressureSensibility", 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 |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int computeThickness(int pressure, const TIntPairProperty &property, bool isPath = false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (isPath)
|
|
Toshihiro Shimizu |
890ddd |
return 0.0;
|
|
Toshihiro Shimizu |
890ddd |
double p = pressure / 255.0;
|
|
Toshihiro Shimizu |
890ddd |
double t = p * p * p;
|
|
Toshihiro Shimizu |
890ddd |
int thick0 = property.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
int thick1 = property.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
return tround(thick0 + (thick1 - thick0) * t);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double computeThickness(int pressure, const TDoublePairProperty &property, bool isPath = false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (isPath)
|
|
Toshihiro Shimizu |
890ddd |
return 0.0;
|
|
Toshihiro Shimizu |
890ddd |
double p = pressure / 255.0;
|
|
Toshihiro Shimizu |
890ddd |
double t = p * p * p;
|
|
Toshihiro Shimizu |
890ddd |
double thick0 = property.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
double thick1 = property.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
if (thick1 < 0.0001)
|
|
Toshihiro Shimizu |
890ddd |
thick0 = thick1 = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
return (thick0 + (thick1 - thick0) * t);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class FullColorBrushUndo : public ToolUtils::TFullColorRasterUndo
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPoint m_offset;
|
|
Toshihiro Shimizu |
890ddd |
QString m_id;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
FullColorBrushUndo(TTileSetFullColor *tileSet,
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *level, const TFrameId &frameId, bool isFrameCreated,
|
|
Toshihiro Shimizu |
890ddd |
const TRasterP &ras, const TPoint &offset)
|
|
Toshihiro Shimizu |
890ddd |
: ToolUtils::TFullColorRasterUndo(tileSet, level, frameId, isFrameCreated, false, 0), m_offset(offset)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static int counter = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_id = QString("FullColorBrushUndo") + QString::number(counter++);
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::instance()->add(m_id.toStdString(), TRasterImageP(ras));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~FullColorBrushUndo()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::instance()->remove(m_id);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void redo() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
insertLevelAndFrameIfNeeded();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP image = getImage();
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = image->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP srcImg = TImageCache::instance()->get(m_id.toStdString(), false);
|
|
Toshihiro Shimizu |
890ddd |
ras->copy(srcImg->getRaster(), m_offset);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getSize() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return sizeof(*this) + ToolUtils::TFullColorRasterUndo::getSize();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual QString getToolName()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return QString("Raster Brush Tool");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
int getHistoryType()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return HistoryType::BrushTool;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// FullColor Brush Tool implementation
|
|
Toshihiro Shimizu |
890ddd |
//************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FullColorBrushTool::FullColorBrushTool(string name)
|
|
Toshihiro Shimizu |
890ddd |
: TTool(name), m_thickness("Thickness", 1, 100, 1, 5, false), m_pressure("Pressure Sensitivity", true), m_opacity("Opacity:", 0, 100, 100, 100, true), m_hardness("Hardness:", 0, 100, 100), m_preset("Preset:"), m_styleId(0), m_oldOpacity(1), m_brush(0), m_tileSet(0), m_tileSaver(0), m_notifier(0), m_presetsLoaded(false), m_firstTime(true)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bind(TTool::RasterImage | TTool::EmptyTarget);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_thickness);
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_hardness);
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_opacity);
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_pressure);
|
|
Toshihiro Shimizu |
890ddd |
#ifndef STUDENT
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_preset);
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setId("BrushPreset");
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ToolOptionsBox *FullColorBrushTool::createOptionsBox()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPaletteHandle *currPalette = TTool::getApplication()->getPaletteController()->getCurrentLevelPalette();
|
|
Toshihiro Shimizu |
890ddd |
ToolHandle *currTool = TTool::getApplication()->getCurrentTool();
|
|
Toshihiro Shimizu |
890ddd |
return new BrushToolOptionsBox(0, this, currPalette, currTool);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::onCanvasSizeChanged()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
onDeactivate();
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::updateTranslation()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_thickness.setQStringName(tr("Thickness"));
|
|
Toshihiro Shimizu |
890ddd |
m_pressure.setQStringName(tr("Pressure Sensitivity"));
|
|
Toshihiro Shimizu |
890ddd |
m_opacity.setQStringName(tr("Opacity:"));
|
|
Toshihiro Shimizu |
890ddd |
m_hardness.setQStringName(tr("Hardness:"));
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setQStringName(tr("Preset:"));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::onActivate()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_notifier)
|
|
Toshihiro Shimizu |
890ddd |
m_notifier = new FullColorBrushToolNotifier(this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TTool::Application *app = getApplication();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (app->getCurrentObject()->isSpline()) {
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = TPixel32::Red;
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int styleIndex = app->getCurrentLevelStyleIndex();
|
|
Toshihiro Shimizu |
890ddd |
TPalette *plt = app->getCurrentPalette()->getPalette();
|
|
Toshihiro Shimizu |
890ddd |
if (plt) {
|
|
Toshihiro Shimizu |
890ddd |
int style = app->getCurrentLevelStyleIndex();
|
|
Toshihiro Shimizu |
890ddd |
TColorStyle *colorStyle = plt->getStyle(style);
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = colorStyle->getMainColor();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_firstTime) {
|
|
Toshihiro Shimizu |
890ddd |
m_firstTime = false;
|
|
Toshihiro Shimizu |
890ddd |
m_thickness.setValue(TIntPairProperty::Value(FullcolorBrushMinSize, FullcolorBrushMaxSize));
|
|
Toshihiro Shimizu |
890ddd |
m_pressure.setValue(FullcolorPressureSensibility ? 1 : 0);
|
|
Toshihiro Shimizu |
890ddd |
m_opacity.setValue(TDoublePairProperty::Value(FullcolorMinOpacity, FullcolorMaxOpacity));
|
|
Toshihiro Shimizu |
890ddd |
m_hardness.setValue(FullcolorBrushHardness);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_brushPad = ToolUtils::getBrushPad(m_thickness.getValue().second, m_hardness.getValue() * 0.01);
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::onDeactivate()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_workRaster = TRaster32P();
|
|
Toshihiro Shimizu |
890ddd |
m_backUpRas = TRasterP();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::updateWorkAndBackupRasters(const TRect &rect)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = TImageP(getImage(false, 1));
|
|
Toshihiro Shimizu |
890ddd |
if (!ri)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect _rect = rect * ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
TRect _lastRect = m_lastRect * ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (_rect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_lastRect.isEmpty()) {
|
|
Toshihiro Shimizu |
890ddd |
m_workRaster->extract(_rect)->clear();
|
|
Toshihiro Shimizu |
890ddd |
m_backUpRas->extract(_rect)->copy(ras->extract(_rect));
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QList<trect> rects = ToolUtils::splitRect(_rect, _lastRect);</trect>
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < rects.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
m_workRaster->extract(rects[i])->clear();
|
|
Toshihiro Shimizu |
890ddd |
m_backUpRas->extract(rects[i])->copy(ras->extract(rects[i]));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool FullColorBrushTool::preLeftButtonDown()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
touchImage();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_isFrameCreated)
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_brushPos = m_mousePos = pos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Viewer *viewer = getViewer();
|
|
Toshihiro Shimizu |
890ddd |
if (!viewer)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = (TRasterImageP)getImage(true);
|
|
Toshihiro Shimizu |
890ddd |
if (!ri)
|
|
Toshihiro Shimizu |
890ddd |
ri = (TRasterImageP)touchImage();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!ri)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TDimension dim = ras->getSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!(m_workRaster && m_backUpRas))
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_workRaster->lock();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double maxThick = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
double thickness = m_pressure.getValue() ? computeThickness(e.m_pressure, m_thickness) : maxThick;
|
|
Toshihiro Shimizu |
890ddd |
double opacity = (m_pressure.getValue() ? computeThickness(e.m_pressure, m_opacity) : m_opacity.getValue().second) * 0.01;
|
|
Toshihiro Shimizu |
890ddd |
TPointD rasCenter = TPointD(dim.lx * 0.5, dim.ly * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint point(pos + rasCenter, thickness);
|
|
Toshihiro Shimizu |
890ddd |
TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
TRectD invalidateRect(pos - halfThick, pos + halfThick);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_points.clear();
|
|
Toshihiro Shimizu |
890ddd |
m_points.push_back(point);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_tileSet = new TTileSetFullColor(ras->getSize());
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver = new TTileSaverFullColor(ras, m_tileSet);
|
|
Toshihiro Shimizu |
890ddd |
double hardness = m_hardness.getValue() * 0.01;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_brush = new BluredBrush(m_workRaster, maxThick, m_brushPad, hardness == 1.0);
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect = m_brush->getBoundFromPoints(m_points);
|
|
Toshihiro Shimizu |
890ddd |
updateWorkAndBackupRasters(m_strokeRect);
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(m_strokeRect);
|
|
Toshihiro Shimizu |
890ddd |
m_brush->addPoint(point, opacity);
|
|
Toshihiro Shimizu |
890ddd |
m_brush->updateDrawing(ras, m_backUpRas, m_currentColor, m_strokeRect, m_opacity.getValue().second * 0.01);
|
|
Toshihiro Shimizu |
890ddd |
m_oldOpacity = opacity;
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect = m_strokeRect;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
invalidate(invalidateRect.enlarge(2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_brushPos = m_mousePos = pos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = (TRasterImageP)getImage(true);
|
|
Toshihiro Shimizu |
890ddd |
if (!ri)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double maxThickness = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
double thickness = m_pressure.getValue() ? computeThickness(e.m_pressure, m_thickness) : maxThickness;
|
|
Toshihiro Shimizu |
890ddd |
double opacity = (m_pressure.getValue() ? computeThickness(e.m_pressure, m_opacity) : m_opacity.getValue().second) * 0.01;
|
|
Toshihiro Shimizu |
890ddd |
TDimension size = m_workRaster->getSize();
|
|
Toshihiro Shimizu |
890ddd |
TPointD rasCenter = TPointD(size.lx * 0.5, size.ly * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint point(pos + rasCenter, thickness);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint old = m_points.back();
|
|
Toshihiro Shimizu |
890ddd |
if (norm2(point - old) < 4)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
m_points.push_back(mid);
|
|
Toshihiro Shimizu |
890ddd |
m_points.push_back(point);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect bbox;
|
|
Toshihiro Shimizu |
890ddd |
int m = m_points.size();
|
|
Toshihiro Shimizu |
890ddd |
TRectD invalidateRect;
|
|
Toshihiro Shimizu |
890ddd |
if (m == 3) {
|
|
Toshihiro Shimizu |
890ddd |
// ho appena cominciato. devo disegnare un segmento
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint pa = m_points.front();
|
|
Toshihiro Shimizu |
890ddd |
vector<tthickpoint> points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(pa);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(mid);
|
|
Toshihiro Shimizu |
890ddd |
invalidateRect = ToolUtils::getBounds(points, maxThickness);
|
|
Toshihiro Shimizu |
890ddd |
bbox = m_brush->getBoundFromPoints(points);
|
|
Toshihiro Shimizu |
890ddd |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(bbox);
|
|
Toshihiro Shimizu |
890ddd |
m_brush->addArc(pa, (pa + mid) * 0.5, mid, m_oldOpacity, opacity);
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect += bbox;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
// caso generale: disegno un arco
|
|
Toshihiro Shimizu |
890ddd |
vector<tthickpoint> points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[m - 4]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(old);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(mid);
|
|
Toshihiro Shimizu |
890ddd |
invalidateRect = ToolUtils::getBounds(points, maxThickness);
|
|
Toshihiro Shimizu |
890ddd |
bbox = m_brush->getBoundFromPoints(points);
|
|
Toshihiro Shimizu |
890ddd |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(bbox);
|
|
Toshihiro Shimizu |
890ddd |
m_brush->addArc(m_points[m - 4], old, mid, m_oldOpacity, opacity);
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect += bbox;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_oldOpacity = opacity;
|
|
Toshihiro Shimizu |
890ddd |
m_brush->updateDrawing(ri->getRaster(), m_backUpRas, m_currentColor, bbox, m_opacity.getValue().second * 0.01);
|
|
Toshihiro Shimizu |
890ddd |
invalidate(invalidateRect.enlarge(2) - rasCenter);
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect += bbox;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_brushPos = m_mousePos = pos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = (TRasterImageP)getImage(true);
|
|
Toshihiro Shimizu |
890ddd |
if (!ri)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_points.size() != 1) {
|
|
Toshihiro Shimizu |
890ddd |
double maxThickness = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
double thickness = m_pressure.getValue() ? computeThickness(e.m_pressure, m_thickness) : maxThickness;
|
|
Toshihiro Shimizu |
890ddd |
double opacity = (m_pressure.getValue() ? computeThickness(e.m_pressure, m_opacity) : m_opacity.getValue().second) * 0.01;
|
|
Toshihiro Shimizu |
890ddd |
TPointD rasCenter = ri->getRaster()->getCenterD();
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint point(pos + rasCenter, thickness);
|
|
Toshihiro Shimizu |
890ddd |
m_points.push_back(point);
|
|
Toshihiro Shimizu |
890ddd |
int m = m_points.size();
|
|
Toshihiro Shimizu |
890ddd |
vector<tthickpoint> points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[m - 3]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[m - 2]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[m - 1]);
|
|
Toshihiro Shimizu |
890ddd |
TRect bbox = m_brush->getBoundFromPoints(points);
|
|
Toshihiro Shimizu |
890ddd |
updateWorkAndBackupRasters(bbox);
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(bbox);
|
|
Toshihiro Shimizu |
890ddd |
m_brush->addArc(points[0], points[1], points[2], m_oldOpacity, opacity);
|
|
Toshihiro Shimizu |
890ddd |
m_brush->updateDrawing(ri->getRaster(), m_backUpRas, m_currentColor, bbox, m_opacity.getValue().second * 0.01);
|
|
Toshihiro Shimizu |
890ddd |
TRectD invalidateRect = ToolUtils::getBounds(points, maxThickness);
|
|
Toshihiro Shimizu |
890ddd |
invalidate(invalidateRect.enlarge(2) - rasCenter);
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect += bbox;
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_brush) {
|
|
Toshihiro Shimizu |
890ddd |
delete m_brush;
|
|
Toshihiro Shimizu |
890ddd |
m_brush = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_workRaster->unlock();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_tileSet->getTileCount() > 0) {
|
|
Toshihiro Shimizu |
890ddd |
delete m_tileSaver;
|
|
Toshihiro Shimizu |
890ddd |
TTool::Application *app = TTool::getApplication();
|
|
Toshihiro Shimizu |
890ddd |
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
Toshihiro Shimizu |
890ddd |
TFrameId frameId = getCurrentFid();
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ri->getRaster()->extract(m_strokeRect)->clone();
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->add(new FullColorBrushUndo(m_tileSet, simLevel.getPointer(), frameId,
|
|
Toshihiro Shimizu |
890ddd |
m_isFrameCreated, ras, m_strokeRect.getP00()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
struct Locals {
|
|
Toshihiro Shimizu |
890ddd |
FullColorBrushTool *m_this;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setValue(TIntPairProperty &prop, const TIntPairProperty::Value &value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
prop.setValue(value);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_this->onPropertyChanged(prop.getName());
|
|
Toshihiro Shimizu |
890ddd |
TTool::getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addMinMax(TIntPairProperty &prop, double add)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const TIntPairProperty::Range &range = prop.getRange();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIntPairProperty::Value value = prop.getValue();
|
|
Toshihiro Shimizu |
890ddd |
value.second = tcrop<double>(value.second + add, range.first, range.second);</double>
|
|
Toshihiro Shimizu |
890ddd |
value.first = tcrop<double>(value.first + add, range.first, range.second);</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
setValue(prop, value);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} locals = {this};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (e.getModifiersMask()) {
|
|
Toshihiro Shimizu |
890ddd |
/*-- Altキー+マウス移動で、ブラシサイズ(Min/Maxとも)を変える(CtrlやShiftでは誤操作の恐れがある) --*/
|
|
Toshihiro Shimizu |
890ddd |
case TMouseEvent::ALT_KEY: {
|
|
Toshihiro Shimizu |
890ddd |
// User wants to alter the minimum brush size
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &diff = pos - m_mousePos;
|
|
Toshihiro Shimizu |
890ddd |
double add = (fabs(diff.x) > fabs(diff.y)) ? diff.x : diff.y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
locals.addMinMax(m_thickness, int(add));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DEFAULT:
|
|
Toshihiro Shimizu |
890ddd |
m_brushPos = pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_mousePos = pos;
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::draw()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (TRasterImageP ri = TRasterImageP(getImage(false))) {
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glColor3d(1.0, 0.0, 0.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(m_brushPos, (m_minThick + 1) * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(m_brushPos, (m_maxThick + 1) * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::onEnter()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TImageP img = getImage(false);
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri(img);
|
|
Toshihiro Shimizu |
890ddd |
if (ri) {
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = m_thickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
Application *app = getApplication();
|
|
Toshihiro Shimizu |
890ddd |
if (app->getCurrentObject()->isSpline()) {
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = TPixel32::Red;
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPalette *plt = app->getCurrentPalette()->getPalette();
|
|
Toshihiro Shimizu |
890ddd |
if (!plt)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int style = app->getCurrentLevelStyleIndex();
|
|
Toshihiro Shimizu |
890ddd |
TColorStyle *colorStyle = plt->getStyle(style);
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = colorStyle->getMainColor();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::onLeave()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPropertyGroup *FullColorBrushTool::getProperties(int targetType)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_presetsLoaded)
|
|
Toshihiro Shimizu |
890ddd |
initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return &m_prop;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::onImageChanged()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::setWorkAndBackupImages()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = (TRasterImageP)getImage(false, 1);
|
|
Toshihiro Shimizu |
890ddd |
if (!ri)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TDimension dim = ras->getSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_workRaster || m_workRaster->getLx() > dim.lx || m_workRaster->getLy() > dim.ly)
|
|
Toshihiro Shimizu |
890ddd |
m_workRaster = TRaster32P(dim);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_backUpRas || m_backUpRas->getLx() > dim.lx || m_backUpRas->getLy() > dim.ly ||
|
|
Toshihiro Shimizu |
890ddd |
m_backUpRas->getPixelSize() != ras->getPixelSize())
|
|
Toshihiro Shimizu |
890ddd |
m_backUpRas = ras->create(dim.lx, dim.ly);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool FullColorBrushTool::onPropertyChanged(string propertyName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = m_thickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
if (propertyName == "Hardness:" || propertyName == "Thickness") {
|
|
Toshihiro Shimizu |
890ddd |
m_brushPad = ToolUtils::getBrushPad(m_thickness.getValue().second, m_hardness.getValue() * 0.01);
|
|
Toshihiro Shimizu |
890ddd |
TRectD rect(m_brushPos - TPointD(m_maxThick + 2, m_maxThick + 2),
|
|
Toshihiro Shimizu |
890ddd |
m_brushPos + TPointD(m_maxThick + 2, m_maxThick + 2));
|
|
Toshihiro Shimizu |
890ddd |
invalidate(rect);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*if(propertyName == "Hardness:" || propertyName == "Opacity:")
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();*/
|
|
Toshihiro Shimizu |
890ddd |
FullcolorBrushMinSize = m_minThick;
|
|
Toshihiro Shimizu |
890ddd |
FullcolorBrushMaxSize = m_maxThick;
|
|
Toshihiro Shimizu |
890ddd |
FullcolorPressureSensibility = m_pressure.getValue();
|
|
Toshihiro Shimizu |
890ddd |
FullcolorBrushHardness = m_hardness.getValue();
|
|
Toshihiro Shimizu |
890ddd |
FullcolorMinOpacity = m_opacity.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
FullcolorMaxOpacity = m_opacity.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (propertyName == "Preset:") {
|
|
Toshihiro Shimizu |
890ddd |
loadPreset();
|
|
Toshihiro Shimizu |
890ddd |
getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_preset.getValue() != CUSTOM_WSTR) {
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setValue(CUSTOM_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::initPresets()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_presetsLoaded) {
|
|
Toshihiro Shimizu |
890ddd |
//If necessary, load the presets from file
|
|
Toshihiro Shimizu |
890ddd |
m_presetsLoaded = true;
|
|
Toshihiro Shimizu |
890ddd |
m_presetsManager.load(TEnv::getConfigDir() + "brush_raster.txt");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Rebuild the presets property entries
|
|
Toshihiro Shimizu |
890ddd |
const std::set<brushdata> &presets = m_presetsManager.presets();</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_preset.deleteAllValues();
|
|
Toshihiro Shimizu |
890ddd |
m_preset.addValue(CUSTOM_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::set<brushdata>::const_iterator it, end = presets.end();</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
for (it = presets.begin(); it != end; ++it)
|
|
Toshihiro Shimizu |
890ddd |
m_preset.addValue(it->m_name);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::loadPreset()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const std::set<brushdata> &presets = m_presetsManager.presets();</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
std::set<brushdata>::const_iterator it;</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
it = presets.find(BrushData(m_preset.getValue()));
|
|
Toshihiro Shimizu |
890ddd |
if (it == presets.end())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const BrushData &preset = *it;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
try //Don't bother with RangeErrors
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_thickness.setValue(TIntPairProperty::Value(tmax((int)preset.m_min, 1), preset.m_max));
|
|
Toshihiro Shimizu |
890ddd |
m_brushPad = ToolUtils::getBrushPad(preset.m_max, preset.m_hardness * 0.01);
|
|
Toshihiro Shimizu |
890ddd |
m_hardness.setValue(preset.m_hardness, true);
|
|
Toshihiro Shimizu |
890ddd |
m_opacity.setValue(TDoublePairProperty::Value(preset.m_opacityMin, preset.m_opacityMax));
|
|
Toshihiro Shimizu |
890ddd |
m_pressure.setValue(preset.m_pressure);
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::addPreset(QString name)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//Build the preset
|
|
Toshihiro Shimizu |
890ddd |
BrushData preset(name.toStdWString());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
preset.m_min = m_thickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
preset.m_max = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
preset.m_hardness = m_hardness.getValue();
|
|
Toshihiro Shimizu |
890ddd |
preset.m_opacityMin = m_opacity.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
preset.m_opacityMax = m_opacity.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
preset.m_pressure = m_pressure.getValue();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Pass the preset to the manager
|
|
Toshihiro Shimizu |
890ddd |
m_presetsManager.addPreset(preset);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Reinitialize the associated preset enum
|
|
Toshihiro Shimizu |
890ddd |
initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Set the value to the specified one
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setValue(preset.m_name);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FullColorBrushTool::removePreset()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
wstring name(m_preset.getValue());
|
|
Toshihiro Shimizu |
890ddd |
if (name == CUSTOM_WSTR)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_presetsManager.removePreset(name);
|
|
Toshihiro Shimizu |
890ddd |
initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//No parameter change, and set the preset value to custom
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setValue(CUSTOM_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FullColorBrushToolNotifier::FullColorBrushToolNotifier(FullColorBrushTool *tool)
|
|
Toshihiro Shimizu |
890ddd |
: m_tool(tool)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TTool::Application *app = m_tool->getApplication();
|
|
Toshihiro Shimizu |
890ddd |
TXshLevelHandle *levelHandle;
|
|
Toshihiro Shimizu |
890ddd |
if (app)
|
|
Toshihiro Shimizu |
890ddd |
levelHandle = app->getCurrentLevel();
|
|
Toshihiro Shimizu |
890ddd |
bool ret = false;
|
|
Toshihiro Shimizu |
890ddd |
if (levelHandle) {
|
|
Toshihiro Shimizu |
890ddd |
bool ret = connect(levelHandle, SIGNAL(xshCanvasSizeChanged()), this, SLOT(onCanvasSizeChanged()));
|
|
Toshihiro Shimizu |
890ddd |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FullColorBrushTool fullColorPencil("T_Brush");
|