mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-22 06:12:32 -06:00
Draw: Developing SDraw
git-svn-id: svn://ultimatepp.org/upp/trunk@6118 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
a5e716a613
commit
e47ef44972
9 changed files with 67 additions and 11 deletions
|
|
@ -411,19 +411,27 @@ bool Draw::IsPainting(int x, int y, int cx, int cy) const
|
|||
return IsPainting(RectC(x, y, cx, cy));
|
||||
}
|
||||
|
||||
static void (*sIgfn)(ImageBuffer& ib, const Painting& pw, Size sz, Point pos, int mode);
|
||||
static void (*sIwfn)(ImageBuffer& ib, const Drawing& p, int mode);
|
||||
static void (*sIgfn)(ImageBuffer& ib, const Painting& pw, Size sz, Point pos, int mode);
|
||||
static void (*sIwfn)(ImageBuffer& ib, const Drawing& p, int mode);
|
||||
static Image (*sRG)(Point at, int angle, int chr, Font fnt, Color color, Size sz);
|
||||
|
||||
void RegisterPaintingFns__(void (*ig)(ImageBuffer& ib, const Painting& pw, Size sz, Point pos, int mode),
|
||||
void (*iw)(ImageBuffer& ib, const Drawing& p, int mode))
|
||||
void (*iw)(ImageBuffer& ib, const Drawing& p, int mode),
|
||||
Image (*rg)(Point at, int angle, int chr, Font fnt, Color color, Size sz))
|
||||
{
|
||||
sIgfn = ig;
|
||||
sIwfn = iw;
|
||||
sRG = rg;
|
||||
}
|
||||
|
||||
bool HasPainter()
|
||||
{
|
||||
return sIgfn && sIwfn;
|
||||
return sIgfn && sIwfn && sRG;
|
||||
}
|
||||
|
||||
Image RenderGlyphByPainter(Point at, int angle, int chr, Font fnt, Color color, Size sz)
|
||||
{
|
||||
return sRG ? (*sRG)(at, angle, chr, fnt, color, sz) : Image();
|
||||
}
|
||||
|
||||
void PaintImageBuffer(ImageBuffer& ib, const Painting& p, Size sz, Point pos, int mode)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ file
|
|||
Image readonly separator,
|
||||
Image.h,
|
||||
Image.cpp,
|
||||
ImageBlit.cpp,
|
||||
ImageBlit.cpp optimize_speed,
|
||||
Raster.h,
|
||||
RasterFormat.cpp,
|
||||
RasterWrite.cpp,
|
||||
|
|
@ -47,7 +47,7 @@ file
|
|||
Raster.cpp,
|
||||
RasterEncoder.cpp,
|
||||
ImageOp.h,
|
||||
ImageOp.cpp,
|
||||
ImageOp.cpp optimize_speed,
|
||||
ImageChOp.cpp,
|
||||
ImageScale.cpp optimize_speed,
|
||||
BiCubic.cpp optimize_speed,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ Image CreateImage(Size sz, Color color)
|
|||
return CreateImage(sz, (RGBA)color);
|
||||
}
|
||||
|
||||
Size DstSrc(ImageBuffer& dest, Point& p, const Image& src, Rect& sr)
|
||||
force_inline Size DstSrc(ImageBuffer& dest, Point& p, const Image& src, Rect& sr)
|
||||
{
|
||||
if(p.x < 0) {
|
||||
sr.left += -p.x;
|
||||
|
|
@ -49,7 +49,7 @@ Size DstSrc(ImageBuffer& dest, Point& p, const Image& src, Rect& sr)
|
|||
}
|
||||
|
||||
void DstSrcOp(ImageBuffer& dest, Point p, const Image& src, const Rect& srect,
|
||||
void (*op)(RGBA *t, const RGBA *s, int n))
|
||||
void (*op)(RGBA *t, const RGBA *s, int n))
|
||||
{
|
||||
Rect sr = srect;
|
||||
Size sz = DstSrc(dest, p, src, sr);
|
||||
|
|
@ -68,6 +68,15 @@ void Over(ImageBuffer& dest, Point p, const Image& src, const Rect& srect)
|
|||
DstSrcOp(dest, p, src, srect, AlphaBlend);
|
||||
}
|
||||
|
||||
void Fill(ImageBuffer& dest, const Rect& rect, RGBA color)
|
||||
{
|
||||
Rect r = dest.GetSize() & rect;
|
||||
int cx = r.GetWidth();
|
||||
if(cx)
|
||||
for(int y = r.top; y < r.bottom; y++)
|
||||
Fill(dest[y] + r.left, color, cx);
|
||||
}
|
||||
|
||||
void OverStraightOpaque(ImageBuffer& dest, Point p, const Image& src, const Rect& srect)
|
||||
{
|
||||
DstSrcOp(dest, p, src, srect, AlphaBlendStraightOpaque);
|
||||
|
|
@ -89,6 +98,13 @@ void Over(Image& dest, Point p, const Image& _src, const Rect& srect)
|
|||
dest = b;
|
||||
}
|
||||
|
||||
void Fill(Image& dest, const Rect& rect, RGBA color)
|
||||
{
|
||||
ImageBuffer b(dest);
|
||||
Fill(b, rect, color);
|
||||
dest = b;
|
||||
}
|
||||
|
||||
void OverStraightOpaque(Image& dest, Point p, const Image& _src, const Rect& srect)
|
||||
{
|
||||
Image src = _src;
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ Image WithHotSpot(const Image& m, int x1, int y1);
|
|||
|
||||
void Over(ImageBuffer& dest, Point p, const Image& src, const Rect& srect);
|
||||
void Copy(ImageBuffer& dest, Point p, const Image& src, const Rect& srect);
|
||||
void Fill(ImageBuffer& dest, const Rect& rect, RGBA color);
|
||||
|
||||
void Copy(Image& dest, Point p, const Image& src, const Rect& srect);
|
||||
void Over(Image& dest, Point p, const Image& src, const Rect& srect);
|
||||
void Fill(Image& dest, const Rect& rect, RGBA color);
|
||||
|
||||
void OverStraightOpaque(ImageBuffer& dest, Point p, const Image& src, const Rect& srect);
|
||||
void OverStraightOpaque(Image& dest, Point p, const Image& _src, const Rect& srect);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ private:
|
|||
public:
|
||||
virtual void PutImage(Point p, const Image& m, const Rect& src) = 0;
|
||||
virtual void PutRect(const Rect& r, Color color) = 0;
|
||||
virtual Image RenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz) = 0;
|
||||
virtual Image RenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz);
|
||||
|
||||
void Init(const Rect& r);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ NAMESPACE_UPP
|
|||
|
||||
void SDraw::Init(const Rect& r)
|
||||
{
|
||||
Cy(r.GetWidth());
|
||||
Cloff& c = cloff.Add();
|
||||
c.clip.Add(r);
|
||||
c.offset = Point(0, 0);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,14 @@
|
|||
|
||||
NAMESPACE_UPP
|
||||
|
||||
Image RenderGlyphByPainter(Point at, int angle, int chr, Font fnt, Color color, Size sz);
|
||||
|
||||
Image SDraw::RenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz)
|
||||
{
|
||||
ASSERT(HasPainter());
|
||||
return RenderGlyphByPainter(at, angle, chr, fnt, color, sz);
|
||||
}
|
||||
|
||||
struct sMakeTextGlyph : public ImageMaker
|
||||
{
|
||||
int chr;
|
||||
|
|
|
|||
|
|
@ -254,6 +254,12 @@ t][@(0.0.255) `&]_[*@3 srect])&]
|
|||
of ImageBuffer [%-*@3 dest].&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:Fill`(ImageBuffer`&`,const Rect`&`,RGBA`): [@(0.0.255) void]_[* Fill]([_^ImageBuffer^ I
|
||||
mageBuffer][@(0.0.255) `&]_[*@3 dest], [@(0.0.255) const]_[_^Rect^ Rect][@(0.0.255) `&]_[*@3 r
|
||||
ect], [_^RGBA^ RGBA]_[*@3 color])&]
|
||||
[s2;%% Fills rectangular are [%-*@3 rect] with [%-*@3 color] .&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:Copy`(Image`&`,Point`,const Image`&`,const Rect`&`): [@(0.0.255) void]_[* Copy]([_^Image^ I
|
||||
mage][@(0.0.255) `&]_[*@3 dest], [_^Point^ Point]_[*@3 p], [@(0.0.255) const]_[_^Image^ Image
|
||||
][@(0.0.255) `&]_[*@3 src], [@(0.0.255) const]_[_^Rect^ Rect][@(0.0.255) `&]_[*@3 srect])&]
|
||||
|
|
@ -276,6 +282,12 @@ mage][@(0.0.255) `&]_[*@3 dest], [_^Point^ Point]_[*@3 p], [@(0.0.255) const]_[_
|
|||
into Point [%-*@3 p] of Image [%-*@3 dest].&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:Fill`(Image`&`,const Rect`&`,RGBA`): [@(0.0.255) void]_[* Fill]([_^Image^ Image][@(0.0.255) `&
|
||||
]_[*@3 dest], [@(0.0.255) const]_[_^Rect^ Rect][@(0.0.255) `&]_[*@3 rect],
|
||||
[_^RGBA^ RGBA]_[*@3 color])&]
|
||||
[s2;%% Fills rectangular are [%-*@3 rect] with [%-*@3 color].&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:OverStraightOpaque`(ImageBuffer`&`,Point`,const Image`&`,const Rect`&`): [@(0.0.255) v
|
||||
oid]_[* OverStraightOpaque]([_^ImageBuffer^ ImageBuffer][@(0.0.255) `&]_[*@3 dest],
|
||||
[_^Point^ Point]_[*@3 p], [@(0.0.255) const]_[_^Image^ Image][@(0.0.255) `&]_[*@3 src],
|
||||
|
|
|
|||
|
|
@ -261,7 +261,8 @@ void PaintImageBufferDrawingFn(ImageBuffer& ib, const Drawing& iw, int mode)
|
|||
}
|
||||
|
||||
void RegisterPaintingFns__(void (*ig)(ImageBuffer& ib, const Painting& pw, Size sz, Point pos, int mode),
|
||||
void (*iw)(ImageBuffer& ib, const Drawing& p, int mode));
|
||||
void (*iw)(ImageBuffer& ib, const Drawing& p, int mode),
|
||||
Image (*rg)(Point at, int angle, int chr, Font fnt, Color color, Size sz));
|
||||
|
||||
void ImageAnyDrawPainter(Draw *(*f)(Size sz), Image (*e)(Draw *w));
|
||||
|
||||
|
|
@ -276,10 +277,18 @@ static Image sEP(Draw *w)
|
|||
return ip ? (Image)(*ip) : Image();
|
||||
}
|
||||
|
||||
static Image sRenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz)
|
||||
{
|
||||
ImageBuffer ib(sz);
|
||||
BufferPainter sw(ib);
|
||||
sw.Clear(RGBAZero());
|
||||
sw.DrawText(at.x, at.y, angle, WString(chr, 1), fnt, color);
|
||||
return ib;
|
||||
}
|
||||
|
||||
INITBLOCK
|
||||
{
|
||||
RegisterPaintingFns__(PaintImageBufferPaintingFn, PaintImageBufferDrawingFn);
|
||||
RegisterPaintingFns__(PaintImageBufferPaintingFn, PaintImageBufferDrawingFn, sRenderGlyph);
|
||||
ImageAnyDrawPainter(sCP, sEP);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue