Merge pull request #1558 from shun-iwasawa/autopaint_autoapply_undo

Enable Undo for Editing Styles
This commit is contained in:
Jeremy Bullock 2017-11-14 08:24:25 -07:00 committed by GitHub
commit f9b89b9c75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 238 additions and 188 deletions

View file

@ -104,6 +104,7 @@ bool TColorStyle::operator==(const TColorStyle &cs) const {
if (m_globalName != cs.getGlobalName()) return false;
if (m_isEditedFromOriginal != cs.getIsEditedFlag()) return false;
if (m_pickedPosition != cs.getPickedPosition()) return false;
if (m_flags != cs.getFlags()) return false;
for (int p = 0; p < colorParamCount; ++p)
if (getColorParamValue(p) != cs.getColorParamValue(p)) return false;

View file

@ -62,6 +62,8 @@ public:
void notifyPaletteDirtyFlagChanged() { emit paletteDirtyFlagChanged(); }
void notifyPaletteLockChanged() { emit paletteLockChanged(); }
void toggleAutopaint();
public:
signals:
@ -69,7 +71,7 @@ signals:
void paletteChanged();
void paletteTitleChanged();
void colorStyleSwitched();
void colorStyleChanged();
void colorStyleChanged(bool);
void colorStyleChangedOnMouseRelease();
void paletteDirtyFlagChanged();
void paletteLockChanged();
@ -89,7 +91,7 @@ signals:
void broadcastPaletteChanged();
void broadcastPaletteTitleChanged();
void broadcastColorStyleSwitched();
void broadcastColorStyleChanged();
void broadcastColorStyleChanged(bool);
void broadcastColorStyleChangedOnMouseRelease();
};

View file

@ -712,8 +712,8 @@ protected:
protected slots:
void onStyleSwitched();
void onStyleChanged();
void onCleanupStyleChanged();
void onStyleChanged(bool isDragging);
void onCleanupStyleChanged(bool isDragging);
void onOldStyleClicked(const TColorStyle &);
// called (e.g.) by PaletteController when an other StyleEditor change the

View file

@ -226,9 +226,9 @@ void FullColorBrushTool::updateWorkAndBackupRasters(const TRect &rect) {
TRasterP ras = ri->getRaster();
const int denominator = 8;
TRect enlargedRect = rect + m_lastRect;
int dx = (enlargedRect.getLx()-1)/denominator+1;
int dy = (enlargedRect.getLy()-1)/denominator+1;
TRect enlargedRect = rect + m_lastRect;
int dx = (enlargedRect.getLx() - 1) / denominator + 1;
int dy = (enlargedRect.getLy() - 1) / denominator + 1;
if (m_lastRect.isEmpty()) {
enlargedRect.x0 -= dx;
@ -236,7 +236,7 @@ void FullColorBrushTool::updateWorkAndBackupRasters(const TRect &rect) {
enlargedRect.x1 += dx;
enlargedRect.y1 += dy;
TRect _rect = enlargedRect*ras->getBounds();
TRect _rect = enlargedRect * ras->getBounds();
if (_rect.isEmpty()) return;
m_workRaster->extract(_rect)->copy(ras->extract(_rect));
@ -247,10 +247,10 @@ void FullColorBrushTool::updateWorkAndBackupRasters(const TRect &rect) {
if (enlargedRect.x1 > m_lastRect.x1) enlargedRect.x1 += dx;
if (enlargedRect.y1 > m_lastRect.y1) enlargedRect.y1 += dy;
TRect _rect = enlargedRect*ras->getBounds();
TRect _rect = enlargedRect * ras->getBounds();
if (_rect.isEmpty()) return;
TRect _lastRect = m_lastRect * ras->getBounds();
TRect _lastRect = m_lastRect * ras->getBounds();
QList<TRect> rects = ToolUtils::splitRect(_rect, _lastRect);
for (int i = 0; i < rects.size(); i++) {
m_workRaster->extract(rects[i])->copy(ras->extract(rects[i]));
@ -263,9 +263,7 @@ void FullColorBrushTool::updateWorkAndBackupRasters(const TRect &rect) {
//--------------------------------------------------------------------------------------------------
bool FullColorBrushTool::askRead(const TRect &rect) {
return askWrite(rect);
}
bool FullColorBrushTool::askRead(const TRect &rect) { return askWrite(rect); }
//--------------------------------------------------------------------------------------------------
@ -316,10 +314,11 @@ void FullColorBrushTool::leftButtonDown(const TPointD &pos,
TPointD rasCenter = ras->getCenterD();
TPointD point(pos + rasCenter);
double pressure = m_enabledPressure && e.isTablet() ? e.m_pressure/255.0 : 0.5;
double pressure =
m_enabledPressure && e.isTablet() ? e.m_pressure / 255.0 : 0.5;
m_tileSet = new TTileSetFullColor(ras->getSize());
m_tileSaver = new TTileSaverFullColor(ras, m_tileSet);
m_tileSet = new TTileSetFullColor(ras->getSize());
m_tileSaver = new TTileSaverFullColor(ras, m_tileSet);
mypaint::Brush mypaintBrush;
applyToonzBrushSettings(mypaintBrush);
@ -329,14 +328,15 @@ void FullColorBrushTool::leftButtonDown(const TPointD &pos,
m_strokeSegmentRect.empty();
m_toonz_brush->beginStroke();
m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
TRect updateRect = m_strokeSegmentRect*ras->getBounds();
TRect updateRect = m_strokeSegmentRect * ras->getBounds();
if (!updateRect.isEmpty())
ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
TPointD thickOffset(m_maxCursorThick*0.5, m_maxCursorThick*0.5);
TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
TRectD invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
invalidateRect += TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
invalidateRect += TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
invalidateRect +=
TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
invalidate(invalidateRect.enlarge(2.0));
}
@ -350,21 +350,23 @@ void FullColorBrushTool::leftButtonDrag(const TPointD &pos,
TRasterImageP ri = (TRasterImageP)getImage(true);
if (!ri) return;
TRasterP ras = ri->getRaster();
TRasterP ras = ri->getRaster();
TPointD rasCenter = ras->getCenterD();
TPointD point(pos + rasCenter);
double pressure = m_enabledPressure && e.isTablet() ? e.m_pressure/255.0 : 0.5;
double pressure =
m_enabledPressure && e.isTablet() ? e.m_pressure / 255.0 : 0.5;
m_strokeSegmentRect.empty();
m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
TRect updateRect = m_strokeSegmentRect*ras->getBounds();
TRect updateRect = m_strokeSegmentRect * ras->getBounds();
if (!updateRect.isEmpty())
ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
TPointD thickOffset(m_maxCursorThick*0.5, m_maxCursorThick*0.5);
TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
TRectD invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
invalidateRect += TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
invalidateRect += TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
invalidateRect +=
TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
invalidate(invalidateRect.enlarge(2.0));
}
@ -378,22 +380,24 @@ void FullColorBrushTool::leftButtonUp(const TPointD &pos,
TRasterImageP ri = (TRasterImageP)getImage(true);
if (!ri) return;
TRasterP ras = ri->getRaster();
TRasterP ras = ri->getRaster();
TPointD rasCenter = ras->getCenterD();
TPointD point(pos + rasCenter);
double pressure = m_enabledPressure && e.isTablet() ? e.m_pressure/255.0 : 0.5;
double pressure =
m_enabledPressure && e.isTablet() ? e.m_pressure / 255.0 : 0.5;
m_strokeSegmentRect.empty();
m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
m_toonz_brush->endStroke();
TRect updateRect = m_strokeSegmentRect*ras->getBounds();
TRect updateRect = m_strokeSegmentRect * ras->getBounds();
if (!updateRect.isEmpty())
ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
TPointD thickOffset(m_maxCursorThick*0.5, m_maxCursorThick*0.5);
TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
TRectD invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
invalidateRect += TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
invalidateRect += TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
invalidateRect +=
TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
invalidate(invalidateRect.enlarge(2.0));
if (m_toonz_brush) {
@ -411,9 +415,9 @@ void FullColorBrushTool::leftButtonUp(const TPointD &pos,
TXshSimpleLevelP simLevel = level->getSimpleLevel();
TFrameId frameId = getCurrentFid();
TRasterP subras = ras->extract(m_strokeRect)->clone();
TUndoManager::manager()->add(
new FullColorBrushUndo(m_tileSet, simLevel.getPointer(), frameId,
m_isFrameCreated, subras, m_strokeRect.getP00()));
TUndoManager::manager()->add(new FullColorBrushUndo(
m_tileSet, simLevel.getPointer(), frameId, m_isFrameCreated, subras,
m_strokeRect.getP00()));
}
notifyImageChanged();
@ -488,16 +492,16 @@ void FullColorBrushTool::draw() {
if (TRasterImageP ri = TRasterImageP(getImage(false))) {
TRasterP ras = ri->getRaster();
double alpha = 1.0;
double alpha = 1.0;
double alphaRadius = 3.0;
double pixelSize = sqrt(tglGetPixelSize2());
double pixelSize = sqrt(tglGetPixelSize2());
// circles with lesser radius looks more bold
// to avoid these effect we'll reduce alpha for small radiuses
double minX = m_minCursorThick/(alphaRadius*pixelSize);
double maxX = m_maxCursorThick/(alphaRadius*pixelSize);
double minAlpha = alpha*(1.0 - 1.0/(1.0 + minX));
double maxAlpha = alpha*(1.0 - 1.0/(1.0 + maxX));
double minX = m_minCursorThick / (alphaRadius * pixelSize);
double maxX = m_maxCursorThick / (alphaRadius * pixelSize);
double minAlpha = alpha * (1.0 - 1.0 / (1.0 + minX));
double maxAlpha = alpha * (1.0 - 1.0 / (1.0 + maxX));
glPushAttrib(GL_ALL_ATTRIB_BITS);
tglEnableBlending();
@ -505,15 +509,15 @@ void FullColorBrushTool::draw() {
if (m_minCursorThick < m_maxCursorThick - pixelSize) {
glColor4d(1.0, 1.0, 1.0, minAlpha);
tglDrawCircle(m_brushPos, (m_minCursorThick + 1)*0.5 - pixelSize);
tglDrawCircle(m_brushPos, (m_minCursorThick + 1) * 0.5 - pixelSize);
glColor4d(0.0, 0.0, 0.0, minAlpha);
tglDrawCircle(m_brushPos, (m_minCursorThick + 1)*0.5);
tglDrawCircle(m_brushPos, (m_minCursorThick + 1) * 0.5);
}
glColor4d(1.0, 1.0, 1.0, maxAlpha);
tglDrawCircle(m_brushPos, (m_maxCursorThick + 1)*0.5 - pixelSize);
tglDrawCircle(m_brushPos, (m_maxCursorThick + 1) * 0.5 - pixelSize);
glColor4d(0.0, 0.0, 0.0, maxAlpha);
tglDrawCircle(m_brushPos, (m_maxCursorThick + 1)*0.5);
tglDrawCircle(m_brushPos, (m_maxCursorThick + 1) * 0.5);
glPopAttrib();
}
@ -521,9 +525,7 @@ void FullColorBrushTool::draw() {
//--------------------------------------------------------------------------------------------------------------
void FullColorBrushTool::onEnter() {
updateCurrentStyle();
}
void FullColorBrushTool::onEnter() { updateCurrentStyle(); }
//----------------------------------------------------------------------------------------------------------
@ -688,8 +690,7 @@ void FullColorBrushTool::updateCurrentStyle() {
if (TTool::Application *app = getApplication()) {
if (app->getCurrentObject()->isSpline()) {
m_currentColor = TPixel32::Red;
} else
if (TPalette *plt = app->getCurrentPalette()->getPalette()) {
} else if (TPalette *plt = app->getCurrentPalette()->getPalette()) {
int style = app->getCurrentLevelStyleIndex();
TColorStyle *colorStyle = plt->getStyle(style);
m_currentColor = colorStyle->getMainColor();
@ -701,25 +702,29 @@ void FullColorBrushTool::updateCurrentStyle() {
m_enabledPressure = m_pressure.getValue();
if (TMyPaintBrushStyle *brushStyle = getBrushStyle()) {
double radiusLog = brushStyle->getBrush().getBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC)
+ m_modifierSize.getValue()*log(2.0);
double radius = exp(radiusLog);
m_minCursorThick = m_maxCursorThick = (int)round(2.0*radius);
double radiusLog = brushStyle->getBrush().getBaseValue(
MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC) +
m_modifierSize.getValue() * log(2.0);
double radius = exp(radiusLog);
m_minCursorThick = m_maxCursorThick = (int)round(2.0 * radius);
} else {
m_minCursorThick = std::max(m_thickness.getValue().first, 1);
m_maxCursorThick = std::max(m_thickness.getValue().second, m_minCursorThick);
m_maxCursorThick =
std::max(m_thickness.getValue().second, m_minCursorThick);
if (!m_enabledPressure) {
double minRadiusLog = log(0.5*m_minCursorThick);
double maxRadiusLog = log(0.5*m_maxCursorThick);
double avgRadiusLog = 0.5*(minRadiusLog + maxRadiusLog);
double avgRadius = exp(avgRadiusLog);
m_minCursorThick = m_maxCursorThick = (int)round(2.0*avgRadius);
double minRadiusLog = log(0.5 * m_minCursorThick);
double maxRadiusLog = log(0.5 * m_maxCursorThick);
double avgRadiusLog = 0.5 * (minRadiusLog + maxRadiusLog);
double avgRadius = exp(avgRadiusLog);
m_minCursorThick = m_maxCursorThick = (int)round(2.0 * avgRadius);
}
}
if (m_minCursorThick != prevMinCursorThick || m_maxCursorThick != prevMaxCursorThick) {
TRectD rect(m_brushPos - TPointD(m_maxCursorThick + 2, m_maxCursorThick + 2),
m_brushPos + TPointD(m_maxCursorThick + 2, m_maxCursorThick + 2));
if (m_minCursorThick != prevMinCursorThick ||
m_maxCursorThick != prevMaxCursorThick) {
TRectD rect(
m_brushPos - TPointD(m_maxCursorThick + 2, m_maxCursorThick + 2),
m_brushPos + TPointD(m_maxCursorThick + 2, m_maxCursorThick + 2));
invalidate(rect);
}
}
@ -727,112 +732,100 @@ void FullColorBrushTool::updateCurrentStyle() {
//------------------------------------------------------------------
double FullColorBrushTool::restartBrushTimer() {
double dtime = m_brushTimer.nsecsElapsed()*1e-9;
double dtime = m_brushTimer.nsecsElapsed() * 1e-9;
m_brushTimer.restart();
return dtime;
}
//------------------------------------------------------------------
TMyPaintBrushStyle* FullColorBrushTool::getBrushStyle() {
TMyPaintBrushStyle *FullColorBrushTool::getBrushStyle() {
if (TTool::Application *app = getApplication())
return dynamic_cast<TMyPaintBrushStyle*>( app->getCurrentLevelStyle() );
return dynamic_cast<TMyPaintBrushStyle *>(app->getCurrentLevelStyle());
return 0;
}
//------------------------------------------------------------------
void FullColorBrushTool::applyClassicToonzBrushSettings(mypaint::Brush &mypaintBrush) {
const double precision = 1e-5;
void FullColorBrushTool::applyClassicToonzBrushSettings(
mypaint::Brush &mypaintBrush) {
const double precision = 1e-5;
const double hardnessOpacity = 0.1;
double minThickness = 0.5*m_thickness.getValue().first;
double maxThickness = 0.5*m_thickness.getValue().second;
double minOpacity = 0.01*m_opacity.getValue().first;
double maxOpacity = 0.01*m_opacity.getValue().second;
double hardness = 0.01*m_hardness.getValue();
double minThickness = 0.5 * m_thickness.getValue().first;
double maxThickness = 0.5 * m_thickness.getValue().second;
double minOpacity = 0.01 * m_opacity.getValue().first;
double maxOpacity = 0.01 * m_opacity.getValue().second;
double hardness = 0.01 * m_hardness.getValue();
TPixelD color = PixelConverter<TPixelD>::from(m_currentColor);
double colorH = 0.0;
double colorS = 0.0;
double colorV = 0.0;
TPixelD color = PixelConverter<TPixelD>::from(m_currentColor);
double colorH = 0.0;
double colorS = 0.0;
double colorV = 0.0;
RGB2HSV(color.r, color.g, color.b, &colorH, &colorS, &colorV);
// avoid log(0)
if (minThickness < precision)
minThickness = precision;
if (maxThickness < precision)
maxThickness = precision;
if (minThickness < precision) minThickness = precision;
if (maxThickness < precision) maxThickness = precision;
// tune hardness opacity for better visual softness
hardness *= hardness;
double opacityAmplifier = 1.0 - hardnessOpacity + hardness*hardnessOpacity;
double opacityAmplifier = 1.0 - hardnessOpacity + hardness * hardnessOpacity;
minOpacity *= opacityAmplifier;
maxOpacity *= opacityAmplifier;
// reset
mypaintBrush.fromDefaults();
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, 1.0);
mypaintBrush.setMappingN(
MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY,
MYPAINT_BRUSH_INPUT_PRESSURE,
0 );
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY,
MYPAINT_BRUSH_INPUT_PRESSURE, 0);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_HARDNESS, 0.5*hardness + 0.5);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_H, colorH/360.0);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_S, colorS);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_V, colorV);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_DABS_PER_ACTUAL_RADIUS, 5.0 + hardness*10.0);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_HARDNESS,
0.5 * hardness + 0.5);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_H, colorH / 360.0);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_S, colorS);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_V, colorV);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_DABS_PER_ACTUAL_RADIUS,
5.0 + hardness * 10.0);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_DABS_PER_BASIC_RADIUS, 0.0);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_DABS_PER_SECOND, 0.0);
// thickness may be dynamic
if (minThickness + precision >= maxThickness) {
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC, log(maxThickness));
mypaintBrush.setMappingN(
MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
MYPAINT_BRUSH_INPUT_PRESSURE,
0 );
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
log(maxThickness));
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
MYPAINT_BRUSH_INPUT_PRESSURE, 0);
} else {
double minThicknessLog = log(minThickness);
double maxThicknessLog = log(maxThickness);
double baseThicknessLog = 0.5*(minThicknessLog + maxThicknessLog);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC, baseThicknessLog);
mypaintBrush.setMappingN(
MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
MYPAINT_BRUSH_INPUT_PRESSURE,
2 );
mypaintBrush.setMappingPoint(
MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
MYPAINT_BRUSH_INPUT_PRESSURE,
0, 0.0, minThicknessLog - baseThicknessLog);
mypaintBrush.setMappingPoint(
MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
MYPAINT_BRUSH_INPUT_PRESSURE,
1, 1.0, maxThicknessLog - baseThicknessLog);
double minThicknessLog = log(minThickness);
double maxThicknessLog = log(maxThickness);
double baseThicknessLog = 0.5 * (minThicknessLog + maxThicknessLog);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
baseThicknessLog);
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
MYPAINT_BRUSH_INPUT_PRESSURE, 2);
mypaintBrush.setMappingPoint(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
MYPAINT_BRUSH_INPUT_PRESSURE, 0, 0.0,
minThicknessLog - baseThicknessLog);
mypaintBrush.setMappingPoint(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
MYPAINT_BRUSH_INPUT_PRESSURE, 1, 1.0,
maxThicknessLog - baseThicknessLog);
}
// opacity may be dynamic
if (minOpacity + precision >= maxOpacity) {
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE, maxOpacity);
mypaintBrush.setMappingN(
MYPAINT_BRUSH_SETTING_OPAQUE,
MYPAINT_BRUSH_INPUT_PRESSURE,
0 );
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_OPAQUE,
MYPAINT_BRUSH_INPUT_PRESSURE, 0);
} else {
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE, minOpacity);
mypaintBrush.setMappingN(
MYPAINT_BRUSH_SETTING_OPAQUE,
MYPAINT_BRUSH_INPUT_PRESSURE,
2 );
mypaintBrush.setMappingPoint(
MYPAINT_BRUSH_SETTING_OPAQUE,
MYPAINT_BRUSH_INPUT_PRESSURE,
0, 0.0, 0.0);
mypaintBrush.setMappingPoint(
MYPAINT_BRUSH_SETTING_OPAQUE,
MYPAINT_BRUSH_INPUT_PRESSURE,
1, 1.0, maxOpacity - minOpacity);
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_OPAQUE,
MYPAINT_BRUSH_INPUT_PRESSURE, 2);
mypaintBrush.setMappingPoint(MYPAINT_BRUSH_SETTING_OPAQUE,
MYPAINT_BRUSH_INPUT_PRESSURE, 0, 0.0, 0.0);
mypaintBrush.setMappingPoint(MYPAINT_BRUSH_SETTING_OPAQUE,
MYPAINT_BRUSH_INPUT_PRESSURE, 1, 1.0,
maxOpacity - minOpacity);
}
}
@ -842,27 +835,30 @@ void FullColorBrushTool::applyToonzBrushSettings(mypaint::Brush &mypaintBrush) {
if (mypaintStyle) {
const double precision = 1e-5;
double modifierSize = m_modifierSize.getValue()*log(2.0);
double modifierOpacity = 0.01*m_modifierOpacity.getValue();
bool modifierEraser = m_modifierEraser.getValue();
bool modifierLockAlpha = m_modifierLockAlpha.getValue();
double modifierSize = m_modifierSize.getValue() * log(2.0);
double modifierOpacity = 0.01 * m_modifierOpacity.getValue();
bool modifierEraser = m_modifierEraser.getValue();
bool modifierLockAlpha = m_modifierLockAlpha.getValue();
TPixelD color = PixelConverter<TPixelD>::from(m_currentColor);
double colorH = 0.0;
double colorS = 0.0;
double colorV = 0.0;
TPixelD color = PixelConverter<TPixelD>::from(m_currentColor);
double colorH = 0.0;
double colorS = 0.0;
double colorV = 0.0;
RGB2HSV(color.r, color.g, color.b, &colorH, &colorS, &colorV);
mypaintBrush.fromBrush(mypaintStyle->getBrush());
float baseSize = mypaintBrush.getBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC);
float baseSize =
mypaintBrush.getBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC);
float baseOpacity = mypaintBrush.getBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC, baseSize + modifierSize);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE, baseOpacity*modifierOpacity);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_H, colorH/360.0);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_S, colorS);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_V, colorV);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
baseSize + modifierSize);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE,
baseOpacity * modifierOpacity);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_H, colorH / 360.0);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_S, colorS);
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_V, colorV);
if (modifierEraser) {
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_ERASER, 1.0);
@ -876,7 +872,6 @@ void FullColorBrushTool::applyToonzBrushSettings(mypaint::Brush &mypaintBrush) {
}
}
//==========================================================================================================
FullColorBrushToolNotifier::FullColorBrushToolNotifier(FullColorBrushTool *tool)
@ -889,7 +884,7 @@ FullColorBrushToolNotifier::FullColorBrushToolNotifier(FullColorBrushTool *tool)
}
if (TPaletteHandle *paletteHandle = app->getCurrentPalette()) {
bool ret;
ret = connect(paletteHandle, SIGNAL(colorStyleChanged()), this,
ret = connect(paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
SLOT(onColorStyleChanged()));
assert(ret);
ret = connect(paletteHandle, SIGNAL(colorStyleSwitched()), this,

View file

@ -767,7 +767,7 @@ StyleIndexFieldAndChip::StyleIndexFieldAndChip(TTool *tool,
setPaletteHandle(pltHandle);
connect(pltHandle, SIGNAL(colorStyleSwitched()), SLOT(updateColor()));
connect(pltHandle, SIGNAL(colorStyleChanged()), SLOT(updateColor()));
connect(pltHandle, SIGNAL(colorStyleChanged(bool)), SLOT(updateColor()));
}
//-----------------------------------------------------------------------------

View file

@ -87,8 +87,8 @@ CleanupPaletteViewer::CleanupPaletteViewer(QWidget *parent)
bool ret = true;
ret = ret && connect(m_ph, SIGNAL(paletteSwitched()), SLOT(buildGUI()));
ret = ret && connect(m_ph, SIGNAL(paletteChanged()), SLOT(buildGUI()));
ret = ret &&
connect(m_ph, SIGNAL(colorStyleChanged()), SLOT(onColorStyleChanged()));
ret = ret && connect(m_ph, SIGNAL(colorStyleChanged(bool)),
SLOT(onColorStyleChanged()));
ret = ret && connect(m_add, SIGNAL(clicked(bool)), SLOT(onAddClicked(bool)));
ret = ret &&

View file

@ -98,8 +98,8 @@ void PreviewToggleCommand::enable() {
TPaletteHandle *ph =
TApp::instance()->getPaletteController()->getCurrentCleanupPalette();
ret =
ret && connect(ph, SIGNAL(colorStyleChanged()), &m_timer, SLOT(start()));
ret = ret &&
connect(ph, SIGNAL(colorStyleChanged(bool)), &m_timer, SLOT(start()));
ret = ret && connect(ph, SIGNAL(paletteChanged()), &m_timer, SLOT(start()));
assert(ret);
@ -129,8 +129,8 @@ void PreviewToggleCommand::disable() {
// involve the model.
TPaletteHandle *ph =
TApp::instance()->getPaletteController()->getCurrentCleanupPalette();
ret = ret &&
disconnect(ph, SIGNAL(colorStyleChanged()), &m_timer, SLOT(start()));
ret = ret && disconnect(ph, SIGNAL(colorStyleChanged(bool)), &m_timer,
SLOT(start()));
ret =
ret && disconnect(ph, SIGNAL(paletteChanged()), &m_timer, SLOT(start()));
assert(ret);

View file

@ -250,7 +250,7 @@ void CleanupSettingsModel::connectSignals() {
SLOT(onCellChanged()), Qt::QueuedConnection);
ret = ret && connect(columnHandle, SIGNAL(columnIndexSwitched()),
SLOT(onCellChanged()), Qt::QueuedConnection);
ret = ret && connect(paletteHandle, SIGNAL(colorStyleChanged()),
ret = ret && connect(paletteHandle, SIGNAL(colorStyleChanged(bool)),
SLOT(onPaletteChanged()), Qt::QueuedConnection);
ret = ret && connect(paletteHandle, SIGNAL(paletteChanged()),
SLOT(onPaletteChanged()), Qt::QueuedConnection);

View file

@ -350,7 +350,7 @@ void ColorModelViewer::hideEvent(QHideEvent *e) {
SLOT(showCurrentImage()));
disconnect(paletteHandle, SIGNAL(paletteChanged()), this,
SLOT(showCurrentImage()));
disconnect(paletteHandle, SIGNAL(colorStyleChanged()), this,
disconnect(paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
SLOT(showCurrentImage()));
disconnect(toolHandle, SIGNAL(toolSwitched()), this, SLOT(changePickType()));
@ -370,7 +370,7 @@ void ColorModelViewer::showEvent(QShowEvent *e) {
SLOT(showCurrentImage()));
ret = ret && connect(paletteHandle, SIGNAL(paletteChanged()), this,
SLOT(showCurrentImage()));
ret = ret && connect(paletteHandle, SIGNAL(colorStyleChanged()), this,
ret = ret && connect(paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
SLOT(showCurrentImage()));
/*- ツールのTypeに合わせてPickのタイプも変え、カーソルも切り替える -*/
ret = ret && connect(toolHandle, SIGNAL(toolSwitched()), this,

View file

@ -1096,12 +1096,7 @@ void MainWindow::onAbout() {
void MainWindow::autofillToggle() {
TPaletteHandle *h = TApp::instance()->getCurrentPalette();
int index = h->getStyleIndex();
if (index > 0) {
TColorStyle *s = h->getPalette()->getStyle(index);
s->setFlags(s->getFlags() == 0 ? 1 : 0);
h->notifyColorStyleChanged();
}
h->toggleAutopaint();
}
void MainWindow::resetRoomsLayout() {

View file

@ -713,7 +713,7 @@ void SceneViewer::showEvent(QShowEvent *) {
TPaletteHandle *paletteHandle =
app->getPaletteController()->getCurrentLevelPalette();
connect(paletteHandle, SIGNAL(colorStyleChanged()), this, SLOT(update()));
connect(paletteHandle, SIGNAL(colorStyleChanged(bool)), this, SLOT(update()));
connect(app->getCurrentObject(), SIGNAL(objectSwitched()), this,
SLOT(onObjectSwitched()));

View file

@ -671,14 +671,14 @@ void ColorFieldEditorController::edit(DVGui::ColorField *colorField) {
connect(m_currentColorField, SIGNAL(colorChanged(const TPixel32 &, bool)),
SLOT(onColorChanged(const TPixel32 &, bool)));
connect(m_colorFieldHandle, SIGNAL(colorStyleChanged()),
connect(m_colorFieldHandle, SIGNAL(colorStyleChanged(bool)),
SLOT(onColorStyleChanged()));
}
//-----------------------------------------------------------------------------
void ColorFieldEditorController::hide() {
disconnect(m_colorFieldHandle, SIGNAL(colorStyleChanged()), this,
disconnect(m_colorFieldHandle, SIGNAL(colorStyleChanged(bool)), this,
SLOT(onColorStyleChanged()));
}
@ -750,14 +750,14 @@ void CleanupColorFieldEditorController::edit(
TApp::instance()->getPaletteController()->setCurrentPalette(
m_colorFieldHandle);
connect(m_colorFieldHandle, SIGNAL(colorStyleChanged()),
connect(m_colorFieldHandle, SIGNAL(colorStyleChanged(bool)),
SLOT(onColorStyleChanged()));
}
//-----------------------------------------------------------------------------
void CleanupColorFieldEditorController::hide() {
disconnect(m_colorFieldHandle, SIGNAL(colorStyleChanged()), this,
disconnect(m_colorFieldHandle, SIGNAL(colorStyleChanged(bool)), this,
SLOT(onColorStyleChanged()));
}
@ -959,9 +959,9 @@ void FlipbookPanel::initializeTitleBar(TPanelTitleBar *titleBar) {
int iconWidth = 20;
// safe area button
TPanelTitleBarButtonForSafeArea *safeAreaButton =
new TPanelTitleBarButtonForSafeArea(titleBar, ":Resources/pane_safe_off.svg",
":Resources/pane_safe_over.svg",
":Resources/pane_safe_on.svg");
new TPanelTitleBarButtonForSafeArea(
titleBar, ":Resources/pane_safe_off.svg",
":Resources/pane_safe_over.svg", ":Resources/pane_safe_on.svg");
safeAreaButton->setToolTip("Safe Area (Right Click to Select)");
titleBar->add(QPoint(x, 0), safeAreaButton);
ret = ret && connect(safeAreaButton, SIGNAL(toggled(bool)),

View file

@ -2,6 +2,51 @@
#include "toonz/tpalettehandle.h"
#include "tundo.h"
#include "historytypes.h"
//=============================================================================
// AutopaintToggleUndo
//-----------------------------------------------------------------------------
namespace {
class AutopaintToggleUndo final : public TUndo {
TPaletteHandle *m_paletteHandle;
TPaletteP m_palette;
int m_styleId;
bool m_flag;
public:
AutopaintToggleUndo(TPaletteHandle *paletteHandle, int styleId)
: m_paletteHandle(paletteHandle)
, m_palette(paletteHandle->getPalette())
, m_styleId(styleId) {}
void toggleAutopaint() const {
TColorStyle *s = m_palette->getStyle(m_styleId);
s->setFlags(s->getFlags() == 0 ? 1 : 0);
m_paletteHandle->notifyColorStyleChanged();
}
void undo() const override { toggleAutopaint(); }
void redo() const override { toggleAutopaint(); }
void onAdd() { redo(); }
int getSize() const override { return sizeof(*this); }
QString getHistoryString() override {
return QObject::tr("Toggle Autopaint Option Palette : %1 Style#%2")
.arg(QString::fromStdWString(m_palette->getPaletteName()))
.arg(QString::number(m_styleId));
}
int getHistoryType() override { return HistoryType::Palette; }
};
} // namespace
//=============================================================================
// TPaletteHandle
//-----------------------------------------------------------------------------
@ -48,8 +93,8 @@ bool TPaletteHandle::connectBroadcasts(const QObject *receiver) {
ret = connect(this, SIGNAL(broadcastColorStyleSwitched()), receiver,
SIGNAL(colorStyleSwitched())) &&
ret;
ret = connect(this, SIGNAL(broadcastColorStyleChanged()), receiver,
SIGNAL(colorStyleChanged())) &&
ret = connect(this, SIGNAL(broadcastColorStyleChanged(bool)), receiver,
SIGNAL(colorStyleChanged(bool))) &&
ret;
ret = connect(this, SIGNAL(broadcastColorStyleChangedOnMouseRelease()),
receiver, SIGNAL(colorStyleChangedOnMouseRelease())) &&
@ -72,8 +117,8 @@ bool TPaletteHandle::disconnectBroadcasts(const QObject *receiver) {
ret = disconnect(this, SIGNAL(broadcastColorStyleSwitched()), receiver,
SIGNAL(colorStyleSwitched())) &&
ret;
ret = disconnect(this, SIGNAL(broadcastColorStyleChanged()), receiver,
SIGNAL(colorStyleChanged())) &&
ret = disconnect(this, SIGNAL(broadcastColorStyleChanged(bool)), receiver,
SIGNAL(colorStyleChanged(bool))) &&
ret;
ret = disconnect(this, SIGNAL(broadcastColorStyleChangedOnMouseRelease()),
receiver, SIGNAL(colorStyleChangedOnMouseRelease())) &&
@ -139,7 +184,16 @@ void TPaletteHandle::notifyColorStyleChanged(bool onDragging,
if (setDirtyFlag && getPalette() && !getPalette()->getDirtyFlag())
getPalette()->setDirtyFlag(true);
emit broadcastColorStyleChanged();
emit broadcastColorStyleChanged(onDragging);
if (!onDragging) emit broadcastColorStyleChangedOnMouseRelease();
}
//-----------------------------------------------------------------------------
void TPaletteHandle::toggleAutopaint() {
int index = getStyleIndex();
if (index > 0) {
TUndoManager::manager()->add(new AutopaintToggleUndo(this, index));
}
}

View file

@ -200,7 +200,7 @@ void PaletteViewer::setPaletteHandle(TPaletteHandle *paletteHandle) {
SLOT(changeWindowTitle()));
ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this,
SLOT(onColorStyleSwitched()));
ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged()), this,
ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
SLOT(changeWindowTitle()));
ret = ret && connect(m_paletteHandle, SIGNAL(paletteDirtyFlagChanged()),
this, SLOT(changeWindowTitle()));
@ -635,7 +635,7 @@ void PaletteViewer::showEvent(QShowEvent *) {
SLOT(changeWindowTitle()));
connect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this,
SLOT(onColorStyleSwitched()));
connect(m_paletteHandle, SIGNAL(colorStyleChanged()), this,
connect(m_paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
SLOT(changeWindowTitle()));
connect(m_paletteHandle, SIGNAL(paletteDirtyFlagChanged()), this,
SLOT(changeWindowTitle()));
@ -657,7 +657,7 @@ void PaletteViewer::hideEvent(QHideEvent *) {
SLOT(changeWindowTitle()));
disconnect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this,
SLOT(onColorStyleSwitched()));
disconnect(m_paletteHandle, SIGNAL(colorStyleChanged()), this,
disconnect(m_paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
SLOT(changeWindowTitle()));
disconnect(m_paletteHandle, SIGNAL(paletteDirtyFlagChanged()), this,
SLOT(changeWindowTitle()));

View file

@ -163,11 +163,11 @@ void PageViewer::setPaletteHandle(TPaletteHandle *paletteHandle) {
if (previousPalette == paletteHandle) return;
if (previousPalette)
disconnect(previousPalette, SIGNAL(colorStyleChanged()), this,
disconnect(previousPalette, SIGNAL(colorStyleChanged(bool)), this,
SLOT(update()));
m_styleSelection->setPaletteHandle(paletteHandle);
connect(paletteHandle, SIGNAL(colorStyleChanged()), SLOT(update()));
connect(paletteHandle, SIGNAL(colorStyleChanged(bool)), SLOT(update()));
if (m_styleNameEditor) m_styleNameEditor->setPaletteHandle(paletteHandle);
}
@ -1281,7 +1281,7 @@ void PageViewer::keyPressEvent(QKeyEvent *e) {
void PageViewer::showEvent(QShowEvent *) {
TPaletteHandle *paletteHandle = getPaletteHandle();
if (!paletteHandle) return;
connect(paletteHandle, SIGNAL(colorStyleChanged()), SLOT(update()),
connect(paletteHandle, SIGNAL(colorStyleChanged(bool)), SLOT(update()),
Qt::UniqueConnection);
}
@ -1290,7 +1290,8 @@ void PageViewer::showEvent(QShowEvent *) {
void PageViewer::hideEvent(QHideEvent *) {
TPaletteHandle *paletteHandle = getPaletteHandle();
if (!paletteHandle) return;
disconnect(paletteHandle, SIGNAL(colorStyleChanged()), this, SLOT(update()));
disconnect(paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
SLOT(update()));
}
//-----------------------------------------------------------------------------

View file

@ -3266,13 +3266,14 @@ void StyleEditor::showEvent(QShowEvent *) {
bool ret = true;
ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleSwitched()),
SLOT(onStyleSwitched()));
ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged()),
SLOT(onStyleChanged()));
ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged(bool)),
SLOT(onStyleChanged(bool)));
ret = ret && connect(m_paletteHandle, SIGNAL(paletteSwitched()), this,
SLOT(onStyleSwitched()));
if (m_cleanupPaletteHandle)
ret = ret && connect(m_cleanupPaletteHandle, SIGNAL(colorStyleChanged()),
SLOT(onCleanupStyleChanged()));
ret =
ret && connect(m_cleanupPaletteHandle, SIGNAL(colorStyleChanged(bool)),
SLOT(onCleanupStyleChanged(bool)));
ret = ret && connect(m_paletteController, SIGNAL(colorAutoApplyEnabled(bool)),
this, SLOT(enableColorAutoApply(bool)));
@ -3348,7 +3349,7 @@ void StyleEditor::onStyleSwitched() {
//-----------------------------------------------------------------------------
void StyleEditor::onStyleChanged() {
void StyleEditor::onStyleChanged(bool isDragging) {
TPalette *palette = getPalette();
if (!palette) return;
@ -3356,10 +3357,11 @@ void StyleEditor::onStyleChanged() {
assert(0 <= styleIndex && styleIndex < palette->getStyleCount());
setEditedStyleToStyle(palette->getStyle(styleIndex));
setOldStyleToStyle(
m_editedStyle
.getPointer()); // This line is needed for proper undo behavior
if (!isDragging) {
setOldStyleToStyle(
m_editedStyle
.getPointer()); // This line is needed for proper undo behavior
}
m_plainColorPage->setColor(*m_editedStyle, getColorParam());
m_colorParameterSelector->setStyle(*m_editedStyle);
m_settingsPage->setStyle(m_editedStyle);
@ -3370,10 +3372,10 @@ void StyleEditor::onStyleChanged() {
//-----------------------------------------------------------------------
void StyleEditor::onCleanupStyleChanged() {
void StyleEditor::onCleanupStyleChanged(bool isDragging) {
if (!m_cleanupPaletteHandle) return;
onStyleChanged();
onStyleChanged(isDragging);
}
//-----------------------------------------------------------------------------