Extracting paint operations from KisPainter

Boudewijn Rempt boud at valdyas.org
Thu Aug 26 22:36:39 CEST 2004


I've extracted all the actual paint operations -- brush, pen, erase, airbrush, 
filter -- from KisPainter each into their own little class.

This is nice, because now the set of paint operations is extensible, and it 
becomes possible to write cool paint operations as plugins, or to present a 
list of paint operations in the options widget of the geometric tools -- 
line, rectangle, ellipse, poly.

It's also not all that nice, because KisPainter needs to keep a lot of state 
during its lifetime, which meant I had to extend the KisPainter api with lots 
of getters & setters. And paintAt is now virtual, which might cause a 
performance hit.

And it makes clear that there's still a lot of shared code in the paintAt 
methods that I'd like to put in one place. Stuff like:

 if (!m_painter) return;
 
 KisFilterSP filter = m_painter -> filter();
 if (!filter) return;

 KisPaintDeviceSP device = m_painter -> device();
 if (!device) return;

 KisBrush * brush = m_painter -> brush();
 if (!brush) return;

 KisPoint hotSpot = brush -> hotSpot(pressure);
 KisPoint pt = pos - hotSpot;

 // Split the coordinates into integer plus fractional parts. The integer
 // is where the dab will be positioned and the fractional part determines
 // the sub-pixel positioning.
 Q_INT32 x;
 double xFraction;
 Q_INT32 y;
 double yFraction;

 splitCoordinate(pt.x(), &x, &xFraction);
 splitCoordinate(pt.y(), &y, &yFraction);

 KisPaintDeviceSP dab = 0;
 if (brush -> brushType() == IMAGE || brush -> brushType() == PIPE_IMAGE) {
  return;
 }
 else {
  KisAlphaMaskSP mask = brush -> mask(pressure, xFraction, yFraction);
  dab = computeDab(mask);
 }
 
 m_painter -> setPressure(pressure);


.... Do the actual painting

 m_painter -> bitBlt( x,  y,  m_painter -> compositeOp(), srcdev, m_painter -> 
opacity(), sx, sy, srcdev -> width(),srcdev -> width());

 m_painter -> addDirtyRect(QRect(x, y, dab -> width(), dab -> height()));

Haven't got a solution to that, though.

Worse, KisPaintOp needs KisPainter, and KisPainter needs KisPaintOp. 
Apparently, #including each other in each others header is something that 
doesn't work.

TODO:

 * Create a factory wrapper around each paintOp
 * Create a PaintOp registry that knows which paintops are available, 
 can return a list of same, and call the right paintop factory on request.

Oh, and why was I doing this again... Ah, yes, I wanted to make it easier to 
make use of selections. And this will make it easier to do the selection 
tools. Need to do them all & simplify them considerably.

Ps. I am afraid, Cyrille, that if you were working on the filterAt code, you 
will have a merge conflict... Sorry for that.
-- 
Boudewijn Rempt | http://www.valdyas.org/fading/index.cgi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kimageshop/attachments/20040826/9cb99581/attachment.pgp


More information about the kimageshop mailing list