Reputation: 5289
I have class Paintable
that is able to paint itself with QPainter
provided as an argument:
class Paintable
{
public:
virtual void paint(QPainter*) = 0;
};
Instances of this class are being painted on a single QImage:
QImage paint(const std::vector<Paintable*>& paintables) {
QImage result;
QPainter p(&result);
for(int i = 0; i < paintables.size(); ++i) {
paintables[i]->paint(&p);
}
return result;
}
What I want to achieve is that function paint
could also form a matrix of size equal to result
image size in which each cell contains a pointer to Paintable
which has drawn corresponding pixel in result
image (something like z-buffer).
It could be achieved easily if draw methods of QPainter
somehow let me know of which pixels of QPaintDevice
were changed during last draw operation. Any ideas of how to do it? Should I create class derived from QPaintDevice
or QPaintEngine
?
I am using Qt 4.6.4.
Thanks.
Upvotes: 3
Views: 423
Reputation: 73304
Perhaps instead of having all your Paintables paint onto the same QImage, have each one paint onto a temporary blank QImage -- i.e. a QImage with all pixels set to RGBA=(0,0,0,0). That way, after a given Paintable's paint() method returns, you know that any pixels in the QImage that are now non-transparent must have been painted by that Paintable object. You could then update your own z-buffer like data-structure based on that information, and then drawImage() the QImage over to a separate "accumulation QImage" (assuming you also want the composited result), clear the temporary QImage again, and repeat as necessary.
Upvotes: 3