diff --git a/uppsrc/Draw/Draw.cpp b/uppsrc/Draw/Draw.cpp index c5719a111..1ac228e83 100644 --- a/uppsrc/Draw/Draw.cpp +++ b/uppsrc/Draw/Draw.cpp @@ -336,6 +336,28 @@ bool Draw::IsPainting(int x, int y, int cx, int cy) const return IsPainting(RectC(x, y, cx, cy)); } +void (*DrawPaintingFn)(ImageBuffer& ib, const Painting& pw, Size sz, Point pos); + +void RegisterDrawPaintingFn(void (*fn)(ImageBuffer& ib, const Painting& pw, Size sz, Point pos)) +{ + DrawPaintingFn = fn; +} + +void Draw::DrawPaintingOp(const Rect& target, const Painting& pw) +{ + if(DrawPaintingFn) { + Size sz = target.GetSize(); + ImageBuffer ib(sz); + DrawPaintingFn(ib, pw, sz, Point(0, 0)); + DrawImage(target.left, target.top, ib); + } +} + +void Draw::DrawPainting(int x, int y, int cx, int cy, const Painting& ig) +{ + DrawPainting(RectC(x, y, cx, cy), ig); +} + // --------------------------- void NilDraw::BeginOp() {} diff --git a/uppsrc/Draw/Draw.h b/uppsrc/Draw/Draw.h index 738b8269e..31f25333b 100644 --- a/uppsrc/Draw/Draw.h +++ b/uppsrc/Draw/Draw.h @@ -88,6 +88,8 @@ enum { class Drawing; class Draw; +class Painting; + #ifdef PLATFORM_WIN32 HDC ScreenHDC(); #endif @@ -727,6 +729,7 @@ public: virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx); virtual void DrawDrawingOp(const Rect& target, const Drawing& w); + virtual void DrawPaintingOp(const Rect& target, const Painting& w); void Begin() { BeginOp(); } void End() { EndOp(); } @@ -828,6 +831,9 @@ public: void DrawDrawing(const Rect& r, const Drawing& iw) { DrawDrawingOp(r, iw); } void DrawDrawing(int x, int y, int cx, int cy, const Drawing& iw); + void DrawPainting(const Rect& r, const Painting& iw) { DrawPaintingOp(r, iw); } + void DrawPainting(int x, int y, int cx, int cy, const Painting& iw); + void DrawText(int x, int y, int angle, const wchar *text, Font font = StdFont(), Color ink = DefaultInk, int n = -1, const int *dx = NULL); void DrawText(int x, int y, const wchar *text, Font font = StdFont(), diff --git a/uppsrc/Painter/PaintPainting.cpp b/uppsrc/Painter/PaintPainting.cpp index 820278a74..c4e84bb73 100644 --- a/uppsrc/Painter/PaintPainting.cpp +++ b/uppsrc/Painter/PaintPainting.cpp @@ -223,15 +223,20 @@ void Painter::Paint(const Painting& pic) } } -Image AsImage(const Painting& p, Size sz, Size isz, Point pos) +void PaintImageBuffer(ImageBuffer& ib, const Painting& p, Size sz, Point pos) { - ImageBuffer ib(sz); BufferPainter sw(ib); Sizef psz = p.GetSize(); - sw.Scale(psz.cx / sz.cx, psz.cy / sz.cy); - sw.Clear(White()); + sw.Scale(sz.cx / psz.cx, sz.cy / psz.cy); + sw.Translate(-pos.x, -pos.y); sw.Paint(p); - return ib; +} + +void RegisterDrawPaintingFn(void (*fn)(ImageBuffer& ib, const Painting& pw, Size sz, Point pos)); + +INITBLOCK +{ + RegisterDrawPaintingFn(PaintImageBuffer); } END_UPP_NAMESPACE diff --git a/uppsrc/Painter/Painting.cpp b/uppsrc/Painter/Painting.cpp index 4dce62490..6ed8a6c3e 100644 --- a/uppsrc/Painter/Painting.cpp +++ b/uppsrc/Painter/Painting.cpp @@ -243,6 +243,7 @@ void PaintingPainter::Create(double cx, double cy) void PaintingPainter::Create(Sizef sz) { + Create(sz.cx, sz.cy); } END_UPP_NAMESPACE diff --git a/uppsrc/Painter/Painting.h b/uppsrc/Painter/Painting.h index 4893cfb14..5724a798e 100644 --- a/uppsrc/Painter/Painting.h +++ b/uppsrc/Painter/Painting.h @@ -137,4 +137,4 @@ public: PaintingPainter(Sizef sz) { Create(sz); } }; -Image AsImage(const Painting& p, Size sz); +void PaintImageBuffer(ImageBuffer& ib, const Painting& p, Size sz, Point pos);