public:
void drawRle(const VPoint &pos, const VRle &rle);
void drawRle(const VRle &rle, const VRle &clip);
-
+ void setCompositionMode(VPainter::CompositionMode mode) { mSpanData.mCompositionMode = mode;}
+ void drawBitmapUntransform(const VRect &target, const VBitmap &bitmap, const VRect &source);
public:
VRasterBuffer mBuffer;
VSpanData mSpanData;
&mSpanData);
}
+static void fillRect(const VRect &r, VSpanData *data)
+{
+ int x1, x2, y1, y2;
+
+ x1 = std::max(r.x(), 0);
+ x2 = std::min(r.x() + r.width(), data->mRasterBuffer->width());
+ y1 = std::max(r.y(), 0);
+ y2 = std::min(r.y() + r.height(), data->mRasterBuffer->height());
+
+ if (x2 <= x1 || y2 <= y1)
+ return;
+
+ const int nspans = 256;
+ VRle::Span spans[nspans];
+
+ int y = y1;
+ while (y < y2) {
+ int n = std::min(nspans, y2 - y);
+ int i = 0;
+ while (i < n) {
+ spans[i].x = x1;
+ spans[i].len = x2 - x1;
+ spans[i].y = y + i;
+ spans[i].coverage = 255;
+ ++i;
+ }
+
+ data->mUnclippedBlendFunc(n, spans, data);
+ y += n;
+ }
+}
+
+void VPainterImpl::drawBitmapUntransform(const VRect &target,
+ const VBitmap &bitmap,
+ const VRect &source)
+{
+ mSpanData.initTexture(&bitmap, 255, VBitmapData::Plain, source);
+ if (!mSpanData.mUnclippedBlendFunc)
+ return;
+ mSpanData.dx = -target.x();
+ mSpanData.dy = -target.y();
+
+ VRect rr = source.translated(target.x(), target.y());
+
+ fillRect(rr, &mSpanData);
+}
+
+
VPainter::~VPainter()
{
mImpl->mSpanData.setup(brush);
}
+void VPainter::setCompositionMode(CompositionMode mode)
+{
+ mImpl->setCompositionMode(mode);
+}
+
void VPainter::drawRle(const VPoint &pos, const VRle &rle)
{
mImpl->drawRle(pos, rle);
return mImpl->mSpanData.mSystemClip;
}
+void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap, const VRect &source)
+{
+ if (!bitmap.valid()) return;
+
+ drawBitmap(VRect(point.x(), point.y(), bitmap.width(), bitmap.height()),
+ bitmap, source);
+}
+
+void VPainter::drawBitmap(const VRect &target, const VBitmap &bitmap, const VRect &source)
+{
+ if (!bitmap.valid()) return;
+
+ if (target.size() == source.size()) {
+ mImpl->drawBitmapUntransform(target, bitmap, source);
+ } else {
+ // @TODO scaling
+ }
+}
+
+void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap)
+{
+ if (!bitmap.valid()) return;
+
+ drawBitmap(VRect(point.x(), point.y(), bitmap.width(), bitmap.height()),
+ bitmap, VRect(0, 0, bitmap.width(), bitmap.height()));
+}
+
+void VPainter::drawBitmap(const VRect &rect, const VBitmap &bitmap)
+{
+ if (!bitmap.valid()) return;
+
+ drawBitmap(rect, bitmap, VRect(0, 0, bitmap.width(), bitmap.height()));
+}
+
V_END_NAMESPACE
class VPainterImpl;
class VPainter {
public:
- enum CompositionMode { CompModeSrc, CompModeSrcOver };
+ enum CompositionMode {
+ CompModeSrc,
+ CompModeSrcOver,
+ CompModeDestIn,
+ CompModeDestOut
+ };
~VPainter();
VPainter();
VPainter(VBitmap *buffer);
bool begin(VBitmap *buffer);
void end();
void setBrush(const VBrush &brush);
+ void setCompositionMode(CompositionMode mode);
void drawRle(const VPoint &pos, const VRle &rle);
void drawRle(const VRle &rle, const VRle &clip);
VRect clipBoundingRect() const;
+ void drawBitmap(const VPoint &point, const VBitmap &bitmap, const VRect &source);
+ void drawBitmap(const VRect &target, const VBitmap &bitmap, const VRect &source);
+ void drawBitmap(const VPoint &point, const VBitmap &bitmap);
+ void drawBitmap(const VRect &rect, const VBitmap &bitmap);
private:
VPainterImpl *mImpl;
};