Undo and Redo and KisPainter
Patrick Julien
freak at codepimps.org
Thu Dec 11 22:23:25 CET 2003
> }
> KisPaintDeviceSP device = currentImage -> activeDevice();
> if (device) {
> KisPainter p( device );
> // This is the interesting bit, I guess.
> p.bitBlt( pos.x(), pos.y(), COMPOSITE_NORMAL, tmpLayer.data() );
> device->anchor();
> }
Your problem is right here, you need to actually continue your transaction.
The transaction is limited to the lifetime of your KisPainter. If your
KisPainter goes out of scope, then it's over and done with. You simply need
to do:
So you either keep the KisPainter alive between mouse presses.
Or, following the strategy you have:
// mouse press
if (m_macro) {
delete m_macro;
m_macro = 0; // When using raw pointers, you should reset the pointer to 0
}
m_macro = new KMacroCommand(...);
// No need to use KisPainter
// mouse move
KisPainter gc(dev);
gc.beginTransaction(m_macro);
// paint something
// when gc goes out of scope, endTransaction is called.
// mouse release
KisUndoAdapter *adapter = currentImage -> undoAdapter();
if (adapter) {
// If painting in mouse release, make sure painter is destructed or end()ed
adapter -> addCommand(m_macro);
m_macro = 0;
} else {
delete m_macro;
m_macro = 0;
}
More information about the kimageshop
mailing list