File indexing completed on 2024-05-26 04:33:49
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KisColorSmudgeInterstrokeData.h" 0008 0009 #include <KoColorSpaceRegistry.h> 0010 0011 #include "kis_transaction.h" 0012 #include "kis_paint_device.h" 0013 0014 KisColorSmudgeInterstrokeData::KisColorSmudgeInterstrokeData(KisPaintDeviceSP source) 0015 : KisInterstrokeData(source) 0016 , overlayDeviceWrapper(source, 2, KisOverlayPaintDeviceWrapper::PreciseMode) 0017 { 0018 projectionDevice = overlayDeviceWrapper.overlay(0); 0019 colorBlendDevice = overlayDeviceWrapper.overlay(1); 0020 heightmapDevice = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0021 heightmapDevice->setDefaultBounds(source->defaultBounds()); 0022 heightmapDevice->setSupportsWraparoundMode(source->supportsWraproundMode()); 0023 } 0024 0025 KisColorSmudgeInterstrokeData::~KisColorSmudgeInterstrokeData() 0026 { 0027 KIS_SAFE_ASSERT_RECOVER(!m_parentCommand) { 0028 (void) overlayDeviceWrapper.endTransaction(); 0029 } 0030 } 0031 0032 void KisColorSmudgeInterstrokeData::beginTransaction() 0033 { 0034 KIS_SAFE_ASSERT_RECOVER_RETURN(!m_parentCommand); 0035 0036 m_parentCommand.reset(new KUndo2Command()); 0037 m_heightmapDeviceTransaction.reset(new KisTransaction(heightmapDevice, m_parentCommand.data())); 0038 overlayDeviceWrapper.beginTransaction(m_parentCommand.data()); 0039 } 0040 0041 KUndo2Command *KisColorSmudgeInterstrokeData::endTransaction() 0042 { 0043 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_parentCommand, 0); 0044 0045 // the internal undo commands are owned by m_parentCommand 0046 (void) m_heightmapDeviceTransaction->endAndTake(); 0047 (void) overlayDeviceWrapper.endTransaction(); 0048 0049 return m_parentCommand.take(); 0050 }