Developing ImageAnyDraw

git-svn-id: svn://ultimatepp.org/upp/trunk@1433 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-07-18 06:37:44 +00:00
parent dccd7fa738
commit 48402c08b2
6 changed files with 296 additions and 0 deletions

View file

@ -0,0 +1,160 @@
#include "AnyImageDraw.h"
dword ImageAnyDraw::GetInfo() const
{
return draw->GetInfo();
}
Size ImageAnyDraw::GetPageSize() const
{
return draw->GetPageSize();
}
void ImageAnyDraw::BeginOp()
{
return draw->BeginOp();
}
void ImageAnyDraw::EndOp()
{
return draw->EndOp();
}
void ImageAnyDraw::OffsetOp(Point p)
{
return draw->OffsetOp(p);
}
bool ImageAnyDraw::ClipOp(const Rect& r)
{
return draw->ClipOp(r);
}
bool ImageAnyDraw::ClipoffOp(const Rect& r)
{
return draw->ClipoffOp(r);
}
bool ImageAnyDraw::ExcludeClipOp(const Rect& r)
{
return draw->ExcludeClipOp(r);
}
bool ImageAnyDraw::IntersectClipOp(const Rect& r)
{
return draw->IntersectClipOp(r);
}
bool ImageAnyDraw::IsPaintingOp(const Rect& r) const
{
return draw->IsPaintingOp(r);
}
Rect ImageAnyDraw::GetPaintRect() const
{
return draw->GetPaintRect();
}
void ImageAnyDraw::DrawRectOp(int x, int y, int cx, int cy, Color color)
{
draw->DrawRectOp(x, y, cx, cy, color);
}
void ImageAnyDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color)
{
draw->DrawImageOp(x, y, cx, cy, img, src, color);
}
void ImageAnyDraw::DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id)
{
draw->DrawDataOp(x, y, cx, cy, data, id);
}
void ImageAnyDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color)
{
draw->DrawLineOp(x1, y1, x2, y2, width, color);
}
void ImageAnyDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count,
const int *counts, int count_count, int width,
Color color, Color doxor)
{
draw->DrawPolyPolylineOp(vertices, vertex_count, counts, count_count, width, color, doxor);
}
void ImageAnyDraw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, const int *subpolygon_counts, int scc, const int *disjunct_polygon_counts, int dpcc, Color color, int width, Color outline, uint64 pattern, Color doxor)
{
draw->DrawPolyPolyPolygonOp(vertices, vertex_count, subpolygon_counts, scc,
disjunct_polygon_counts, dpcc, color, width, outline,
pattern, doxor);
}
void ImageAnyDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color)
{
draw->DrawArcOp(rc, start, end, width, color);
}
void ImageAnyDraw::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor)
{
draw->DrawEllipseOp(r, color, pen, pencolor);
}
void ImageAnyDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink,
int n, const int *dx)
{
draw->DrawTextOp(x, y, angle, text, font, ink, n, dx);
}
void ImageAnyDraw::DrawDrawingOp(const Rect& target, const Drawing& w)
{
draw->DrawDrawingOp(target, w);
}
void ImageAnyDraw::DrawPaintingOp(const Rect& target, const Painting& w)
{
draw->DrawPaintingOp(target, w);
}
Draw *(*sCreateImageDraw)(Size sz);
Image (*sExtractImageDraw)(Draw *w);
void ImageAnyDrawPainter(Draw *(*f)(Size sz), Image (*e)(Draw *w))
{
sCreateImageDraw = f;
sExtractImageDraw = e;
}
void ImageAnyDrawSystem(Draw *(*f)(Size sz), Image (*e)(Draw *w))
{
if(!sCreateImageDraw) {
sCreateImageDraw = f;
sExtractImageDraw = e;
}
}
void ImageAnyDraw::Init(Size sz)
{
ASSERT(sCreateImageDraw);
draw = (*sCreateImageDraw)(sz);
ASSERT(draw);
}
ImageAnyDraw::operator Image() const
{
return (*sExtractImageDraw)(draw);
}
ImageAnyDraw::ImageAnyDraw(Size sz)
{
Init(sz);
}
ImageAnyDraw::ImageAnyDraw(int cx, int cy)
{
Init(Size(cx, cy));
}
ImageAnyDraw::~ImageAnyDraw()
{
delete draw;
}

View file

@ -0,0 +1,67 @@
#ifndef _AnyImageDraw_AnyImageDraw_h
#define _AnyImageDraw_AnyImageDraw_h
#include <CtrlLib/CtrlLib.h>
#include <Painter/Painter.h>
using namespace Upp;
#define LAYOUTFILE <AnyImageDraw/AnyImageDraw.lay>
#include <CtrlCore/lay.h>
class ImageAnyDraw : public Draw {
Draw *draw;
void Init(Size sz);
public:
virtual dword GetInfo() const;
virtual Size GetPageSize() const;
virtual void BeginOp();
virtual void EndOp();
virtual void OffsetOp(Point p);
virtual bool ClipOp(const Rect& r);
virtual bool ClipoffOp(const Rect& r);
virtual bool ExcludeClipOp(const Rect& r);
virtual bool IntersectClipOp(const Rect& r);
virtual bool IsPaintingOp(const Rect& r) const;
virtual Rect GetPaintRect() const;
virtual void DrawRectOp(int x, int y, int cx, int cy, Color color);
virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id);
virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);
virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
const int *counts, int count_count,
int width, Color color, Color doxor);
virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
const int *subpolygon_counts, int scc,
const int *disjunct_polygon_counts, int dpcc,
Color color, int width, Color outline,
uint64 pattern, Color doxor);
virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color);
virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
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);
public:
operator Image() const;
ImageAnyDraw(Size sz);
ImageAnyDraw(int cx, int cy);
~ImageAnyDraw();
};
class AnyImageDraw : public TopWindow {
virtual void Paint(Draw& w);
public:
typedef AnyImageDraw CLASSNAME;
AnyImageDraw();
};
#endif

View file

@ -0,0 +1,3 @@
LAYOUT(AnyImageDrawLayout, 200, 100)
END_LAYOUT

View file

@ -0,0 +1,13 @@
uses
CtrlLib,
Painter;
file
AnyImageDraw.h,
AnyImageDraw.cpp,
main.cpp,
AnyImageDraw.lay;
mainconfig
"" = "GUI";

5
uppdev/AnyImageDraw/init Normal file
View file

@ -0,0 +1,5 @@
#ifndef _AnyImageDraw_icpp_init_stub
#define _AnyImageDraw_icpp_init_stub
#include "CtrlLib/init"
#include "Painter/init"
#endif

View file

@ -0,0 +1,48 @@
#include "AnyImageDraw.h"
void ImageAnyDrawPainter(Draw *(*f)(Size sz), Image (*e)(Draw *w));
void ImageAnyDrawSystem(Draw *(*f)(Size sz), Image (*e)(Draw *w));
static Draw *sCP(Size sz)
{
return new ImagePainter(sz);
}
static Image sEP(Draw *w)
{
ImagePainter *ip = dynamic_cast<ImagePainter *>(w);
return ip ? (Image)(*ip) : Image();
}
static Draw *sCD(Size sz)
{
return new ImageDraw(sz);
}
static Image sED(Draw *w)
{
ImageDraw *ip = dynamic_cast<ImageDraw *>(w);
return ip ? (Image)(*ip) : Image();
}
INITBLOCK {
ImageAnyDrawPainter(sCP, sEP);
ImageAnyDrawSystem(sCD, sED);
}
void AnyImageDraw::Paint(Draw& w)
{
ImageAnyDraw iw(200, 200);
iw.DrawRect(0, 0, 200, 200, White());
iw.DrawText(0, 0, "X", Roman(200));
w.DrawImage(0, 0, iw);
}
AnyImageDraw::AnyImageDraw()
{
}
GUI_APP_MAIN
{
AnyImageDraw().Run();
}