📄 pseudodc.h
字号:
virtual void Translate(wxCoord dx, wxCoord dy)
{m_x+=dx; m_y+=dy;}
protected:
wxString m_text;
wxCoord m_x,m_y;
double m_angle;
};
class pdcDrawBitmapOp : public pdcOp
{
public:
pdcDrawBitmapOp(const wxBitmap &bmp, wxCoord x, wxCoord y,
bool useMask = false)
{m_bmp=bmp; m_x=x; m_y=y; m_useMask=useMask;}
virtual void DrawToDC(wxDC *dc) {dc->DrawBitmap(m_bmp,m_x,m_y,m_useMask);}
virtual void Translate(wxCoord dx, wxCoord dy)
{m_x+=dx; m_y+=dy;}
protected:
wxBitmap m_bmp;
wxCoord m_x,m_y;
bool m_useMask;
};
class pdcDrawLabelOp : public pdcOp
{
public:
pdcDrawLabelOp(const wxString& text,
const wxBitmap& image,
const wxRect& rect,
int alignment = wxALIGN_LEFT | wxALIGN_TOP,
int indexAccel = -1)
{m_text=text; m_image=image; m_rect=rect;
m_align=alignment; m_iAccel=indexAccel;}
virtual void DrawToDC(wxDC *dc)
{dc->DrawLabel(m_text,m_image,m_rect,m_align,m_iAccel);}
virtual void Translate(wxCoord dx, wxCoord dy)
{m_rect.x+=dx; m_rect.y+=dy;}
protected:
wxString m_text;
wxBitmap m_image;
wxRect m_rect;
int m_align;
int m_iAccel;
};
#if wxUSE_SPLINES
class pdcDrawSplineOp : public pdcOp
{
public:
pdcDrawSplineOp(int n, wxPoint points[]);
virtual ~pdcDrawSplineOp();
virtual void DrawToDC(wxDC *dc) {dc->DrawSpline(m_n,m_points);}
virtual void Translate(wxCoord dx, wxCoord dy)
{
int i;
for(i=0; i<m_n; i++)
m_points[i].x+=dx; m_points[i].y+=dy;
}
protected:
wxPoint *m_points;
int m_n;
};
#endif // wxUSE_SPLINES
#if wxUSE_PALETTE
class pdcSetPaletteOp : public pdcOp
{
public:
pdcSetPaletteOp(const wxPalette& palette) {m_palette=palette;}
virtual void DrawToDC(wxDC *dc) {dc->SetPalette(m_palette);}
protected:
wxPalette m_palette;
};
#endif // wxUSE_PALETTE
class pdcSetLogicalFunctionOp : public pdcOp
{
public:
pdcSetLogicalFunctionOp(int function) {m_function=function;}
virtual void DrawToDC(wxDC *dc) {dc->SetLogicalFunction(m_function);}
protected:
int m_function;
};
//----------------------------------------------------------------------------
// pdcObject type to contain list of operations for each real (Python) object
//----------------------------------------------------------------------------
class pdcObject
{
public:
pdcObject(int id)
{m_id=id; m_bounded=false; m_oplist.DeleteContents(true);}
virtual ~pdcObject() {m_oplist.Clear();}
// Protected Member Access
void SetId(int id) {m_id=id;}
int GetId() {return m_id;}
void SetBounds(wxRect& rect) {m_bounds=rect; m_bounded=true;}
wxRect GetBounds() {return m_bounds;}
void SetBounded(bool bounded) {m_bounded=bounded;}
bool IsBounded() {return m_bounded;}
// Op List Management Methods
void Clear() {m_oplist.Clear();}
void AddOp(pdcOp *op) {m_oplist.Append(op);}
int GetLen() {return m_oplist.GetCount();}
virtual void Translate(wxCoord dx, wxCoord dy);
// Drawing Method
virtual void DrawToDC(wxDC *dc);
protected:
int m_id; // id of object (associates this pdcObject
// with a Python object with same id)
wxRect m_bounds; // bounding rect of this object
bool m_bounded; // true if bounds is valid, false by default
pdcOpList m_oplist; // list of operations for this object
};
//----------------------------------------------------------------------------
// Declare a wxList to hold all the objects. List order reflects drawing
// order (Z order) and is the same order as objects are added to the list
//----------------------------------------------------------------------------
class pdcObjectList;
WX_DECLARE_LIST(pdcObject, pdcObjectList);
// ----------------------------------------------------------------------------
// wxPseudoDC class
// ----------------------------------------------------------------------------
// This is the actual PseudoDC class
// This class stores a list of recorded dc operations in m_list
// and plays them back to a real dc using DrawToDC or DrawToDCClipped.
// Drawing methods are mirrored from wxDC but add nodes to m_list
// instead of doing any real drawing.
// ----------------------------------------------------------------------------
class wxPseudoDC : public wxObject
{
public:
wxPseudoDC()
{m_currId=-1; m_lastObjNode=NULL; m_objectlist.DeleteContents(true);}
~wxPseudoDC();
// ------------------------------------------------------------------------
// List managment methods
//
void RemoveAll();
int GetLen();
// ------------------------------------------------------------------------
// methods for managing operations by ID
//
// Set the Id for all subsequent operations (until SetId is called again)
void SetId(int id) {m_currId = id;}
// Remove all the operations associated with an id so it can be redrawn
void ClearId(int id);
// Remove the object node (and all operations) associated with an id
void RemoveId(int id);
// Set the bounding rect of a given object
// This will create an object node if one doesn't exist
void SetIdBounds(int id, wxRect& rect);
void GetIdBounds(int id, wxRect& rect);
// Translate all the operations for this id
void TranslateId(int id, wxCoord dx, wxCoord dy);
// ------------------------------------------------------------------------
// Playback Methods
//
// draw to dc but skip objects known to be outside of rect
// This is a coarse level of clipping to speed things up
// when lots of objects are off screen and doesn't affect the dc level
// clipping
void DrawToDCClipped(wxDC *dc, const wxRect& rect);
void DrawToDCClippedRgn(wxDC *dc, const wxRegion& region);
// draw to dc with no clipping (well the dc will still clip)
void DrawToDC(wxDC *dc);
// draw a single object to the dc
void DrawIdToDC(int id, wxDC *dc);
// ------------------------------------------------------------------------
// Methods mirrored from wxDC
//
void FloodFill(wxCoord x, wxCoord y, const wxColour& col,
int style = wxFLOOD_SURFACE)
{AddToList(new pdcFloodFillOp(x,y,col,style));}
void FloodFill(const wxPoint& pt, const wxColour& col,
int style = wxFLOOD_SURFACE)
{ FloodFill(pt.x, pt.y, col, style); }
void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{AddToList(new pdcDrawLineOp(x1, y1, x2, y2));}
void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
{ DrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
void CrossHair(wxCoord x, wxCoord y)
{AddToList(new pdcCrossHairOp(x,y));}
void CrossHair(const wxPoint& pt)
{ CrossHair(pt.x, pt.y); }
void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
wxCoord xc, wxCoord yc)
{AddToList(new pdcDrawArcOp(x1,y1,x2,y2,xc,yc));}
void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
{ DrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
void DrawCheckMark(wxCoord x, wxCoord y,
wxCoord width, wxCoord height)
{AddToList(new pdcDrawCheckMarkOp(x,y,width,height));}
void DrawCheckMark(const wxRect& rect)
{ DrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
double sa, double ea)
{AddToList(new pdcDrawEllipticArcOp(x,y,w,h,sa,ea));}
void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
double sa, double ea)
{ DrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
void DrawPoint(wxCoord x, wxCoord y)
{AddToList(new pdcDrawPointOp(x,y));}
void DrawPoint(const wxPoint& pt)
{ DrawPoint(pt.x, pt.y); }
void DrawPolygon(int n, wxPoint points[],
wxCoord xoffset = 0, wxCoord yoffset = 0,
int fillStyle = wxODDEVEN_RULE)
{AddToList(new pdcDrawPolygonOp(n,points,xoffset,yoffset,fillStyle));}
void DrawPolyPolygon(int n, int count[], wxPoint points[],
wxCoord xoffset = 0, wxCoord yoffset = 0,
int fillStyle = wxODDEVEN_RULE)
{AddToList(new pdcDrawPolyPolygonOp(n,count,points,xoffset,yoffset,fillStyle));}
void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{AddToList(new pdcDrawRectangleOp(x, y, width, height));}
void DrawRectangle(const wxPoint& pt, const wxSize& sz)
{ DrawRectangle(pt.x, pt.y, sz.x, sz.y); }
void DrawRectangle(const wxRect& rect)
{ DrawRectangle(rect.x, rect.y, rect.width, rect.height); }
void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
double radius)
{AddToList(new pdcDrawRoundedRectangleOp(x,y,width,height,radius));}
void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
double radius)
{ DrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
void DrawRoundedRectangle(const wxRect& r, double radius)
{ DrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
{ DrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
void DrawCircle(const wxPoint& pt, wxCoord radius)
{ DrawCircle(pt.x, pt.y, radius); }
void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{AddToList(new pdcDrawEllipseOp(x,y,width,height));}
void DrawEllipse(const wxPoint& pt, const wxSize& sz)
{ DrawEllipse(pt.x, pt.y, sz.x, sz.y); }
void DrawEllipse(const wxRect& rect)
{ DrawEllipse(rect.x, rect.y, rect.width, rect.height); }
void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
{AddToList(new pdcDrawIconOp(icon,x,y));}
void DrawIcon(const wxIcon& icon, const wxPoint& pt)
{ DrawIcon(icon, pt.x, pt.y); }
void DrawLines(int n, wxPoint points[],
wxCoord xoffset = 0, wxCoord yoffset = 0)
{AddToList(new pdcDrawLinesOp(n,points,xoffset,yoffset));}
void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
bool useMask = false)
{AddToList(new pdcDrawBitmapOp(bmp,x,y,useMask));}
void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
bool useMask = false)
{ DrawBitmap(bmp, pt.x, pt.y, useMask); }
void DrawText(const wxString& text, wxCoord x, wxCoord y)
{AddToList(new pdcDrawTextOp(text, x, y));}
void DrawText(const wxString& text, const wxPoint& pt)
{ DrawText(text, pt.x, pt.y); }
void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
{AddToList(new pdcDrawRotatedTextOp(text,x,y,angle));}
void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)
{ DrawRotatedText(text, pt.x, pt.y, angle); }
// this version puts both optional bitmap and the text into the given
// rectangle and aligns is as specified by alignment parameter; it also
// will emphasize the character with the given index if it is != -1
void DrawLabel(const wxString& text,
const wxBitmap& image,
const wxRect& rect,
int alignment = wxALIGN_LEFT | wxALIGN_TOP,
int indexAccel = -1)
{AddToList(new pdcDrawLabelOp(text,image,rect,alignment,indexAccel));}
void DrawLabel(const wxString& text, const wxRect& rect,
int alignment = wxALIGN_LEFT | wxALIGN_TOP,
int indexAccel = -1)
{ DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); }
/*?????? I don't think that the source dc would stick around
void Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
wxDC *source, wxCoord xsrc, wxCoord ysrc,
int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
{AddToList(new pdcBlitOp(xdest,ydest,width,height,source,xsrc,
ysrc,rop,useMask,xsrcMask,ysrcMask));}
void Blit(const wxPoint& destPt, const wxSize& sz,
wxDC *source, const wxPoint& srcPt,
int rop = wxCOPY, bool useMask = false, const wxPoint& srcPtMask = wxDefaultPosition)
{
Blit(destPt.x, destPt.y, sz.x, sz.y, source, srcPt.x, srcPt.y,
rop, useMask, srcPtMask.x, srcPtMask.y);
}
??????*/
#if wxUSE_SPLINES
void DrawSpline(int n, wxPoint points[])
{AddToList(new pdcDrawSplineOp(n,points));}
#endif // wxUSE_SPLINES
#if wxUSE_PALETTE
void SetPalette(const wxPalette& palette)
{AddToList(new pdcSetPaletteOp(palette));}
#endif // wxUSE_PALETTE
void SetLogicalFunction(int function)
{AddToList(new pdcSetLogicalFunctionOp(function));}
void SetFont(const wxFont& font)
{AddToList(new pdcSetFontOp(font));}
void SetPen(const wxPen& pen)
{AddToList(new pdcSetPenOp(pen));}
void SetBrush(const wxBrush& brush)
{AddToList(new pdcSetBrushOp(brush));}
void SetBackground(const wxBrush& brush)
{AddToList(new pdcSetBackgroundOp(brush));}
void SetBackgroundMode(int mode)
{AddToList(new pdcSetBackgroundModeOp(mode));}
void SetTextBackground(const wxColour& colour)
{AddToList(new pdcSetTextBackgroundOp(colour));}
void SetTextForeground(const wxColour& colour)
{AddToList(new pdcSetTextForegroundOp(colour));}
void Clear()
{AddToList(new pdcClearOp());}
void BeginDrawing()
{AddToList(new pdcBeginDrawingOp());}
void EndDrawing()
{AddToList(new pdcEndDrawingOp());}
protected:
// ------------------------------------------------------------------------
// protected helper methods
void AddToList(pdcOp *newOp);
pdcObjectList::Node *FindObjNode(int id, bool create=false);
// ------------------------------------------------------------------------
// Data members
//
int m_currId; // id to use for operations done on the PseudoDC
pdcObjectList::Node *m_lastObjNode; // used to find last used object quickly
pdcObjectList m_objectlist; // list of objects
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -