X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da249bc35920bd7781f3d2284004fd5162c27670..9e06a15fc2f2144f7161dc813941e5c5ccd41132:/include/wx/dc.h diff --git a/include/wx/dc.h b/include/wx/dc.h index 3acc88d47b..465d2e9588 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -26,7 +26,6 @@ #include "wx/brush.h" #include "wx/pen.h" #include "wx/palette.h" -#include "wx/list.h" // we use wxList in inline functions #include "wx/dynarray.h" #include "wx/math.h" #include "wx/image.h" @@ -35,6 +34,79 @@ #define wxUSE_NEW_DC 0 +#if wxUSE_NEW_DC +class WXDLLIMPEXP_FWD_CORE wxDC; +class WXDLLIMPEXP_FWD_CORE wxClientDC; +class WXDLLIMPEXP_FWD_CORE wxPaintDC; +class WXDLLIMPEXP_FWD_CORE wxWindowDC; +class WXDLLIMPEXP_FWD_CORE wxScreenDC; +class WXDLLIMPEXP_FWD_CORE wxMemoryDC; +#else +class WXDLLIMPEXP_FWD_CORE wxDCBase; +#endif + +class WXDLLEXPORT wxDrawObject +{ +public: + + wxDrawObject() + : m_isBBoxValid(false) + , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0) + { } + + virtual ~wxDrawObject() { } + +#if wxUSE_NEW_DC + virtual void Draw(wxDC&) const { } +#else + virtual void Draw(wxDCBase&) const { } +#endif + + virtual void CalcBoundingBox(wxCoord x, wxCoord y) + { + if ( m_isBBoxValid ) + { + if ( x < m_minX ) m_minX = x; + if ( y < m_minY ) m_minY = y; + if ( x > m_maxX ) m_maxX = x; + if ( y > m_maxY ) m_maxY = y; + } + else + { + m_isBBoxValid = true; + + m_minX = x; + m_minY = y; + m_maxX = x; + m_maxY = y; + } + } + + void ResetBoundingBox() + { + m_isBBoxValid = false; + + m_minX = m_maxX = m_minY = m_maxY = 0; + } + + // Get the final bounding box of the PostScript or Metafile picture. + + wxCoord MinX() const { return m_minX; } + wxCoord MaxX() const { return m_maxX; } + wxCoord MinY() const { return m_minY; } + wxCoord MaxY() const { return m_maxY; } + + //to define the type of object for derived objects + virtual int GetType()=0; + +protected: + //for boundingbox calculation + bool m_isBBoxValid:1; + //for boundingbox calculation + wxCoord m_minX, m_minY, m_maxX, m_maxY; +}; + + #if wxUSE_NEW_DC //----------------------------------------------------------------------------- @@ -49,15 +121,16 @@ public: wxDCFactory() {} virtual ~wxDCFactory() {} - virtual wxImplDC* CreateWindowDC() = 0; - virtual wxImplDC* CreateWindowDC( wxWindow *window ) = 0; - virtual wxImplDC* CreateClientDC() = 0; - virtual wxImplDC* CreateClientDC( wxWindow *window ) = 0; - virtual wxImplDC* CreatePaintDC() = 0; - virtual wxImplDC* CreatePaintDC( wxWindow *window ) = 0; - virtual wxImplDC* CreateMemoryDC() = 0; - virtual wxImplDC* CreateMemoryDC( wxBitmap &bitmap ) = 0; - virtual wxImplDC* CreateMemoryDC( wxDC *dc ) = 0; + virtual wxImplDC* CreateWindowDC( wxWindowDC *owner ) = 0; + virtual wxImplDC* CreateWindowDC( wxWindowDC *owner, wxWindow *window ) = 0; + virtual wxImplDC* CreateClientDC( wxClientDC *owner ) = 0; + virtual wxImplDC* CreateClientDC( wxClientDC *owner, wxWindow *window ) = 0; + virtual wxImplDC* CreatePaintDC( wxPaintDC *owner ) = 0; + virtual wxImplDC* CreatePaintDC( wxPaintDC *owner, wxWindow *window ) = 0; + virtual wxImplDC* CreateMemoryDC( wxMemoryDC *owner ) = 0; + virtual wxImplDC* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap ) = 0; + virtual wxImplDC* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc ) = 0; + virtual wxImplDC* CreateScreenDC( wxScreenDC *owner ) = 0; static void SetDCFactory( wxDCFactory *factory ); static wxDCFactory *GetFactory(); @@ -69,77 +142,21 @@ private: // wxNativeDCFactory //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxDCFactory +class WXDLLIMPEXP_CORE wxNativeDCFactory: public wxDCFactory { public: wxNativeDCFactory() {} - virtual wxImplDC* CreateWindowDC(); - virtual wxImplDC* CreateWindowDC( wxWindow *window ); - virtual wxImplDC* CreateClientDC(); - virtual wxImplDC* CreateClientDC( wxWindow *window ); - virtual wxImplDC* CreatePaintDC(); - virtual wxImplDC* CreatePaintDC( wxWindow *window ); - virtual wxImplDC* CreateMemoryDC(); - virtual wxImplDC* CreateMemoryDC( wxBitmap &bitmap ); - virtual wxImplDC* CreateMemoryDC( wxDC *dc ); -}; - -//----------------------------------------------------------------------------- -// wxWindowDC -//----------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxWindowDC : public wxDC -{ -public: - wxWindowDC(); - wxWindowDC( wxWindow *win ); - -private: - DECLARE_DYNAMIC_CLASS(wxWindowDC) -}; - -//----------------------------------------------------------------------------- -// wxClientDC -//----------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxClientDC : public wxDC -{ -public: - wxClientDC(); - wxClientDC( wxWindow *win ); - -private: - DECLARE_DYNAMIC_CLASS(wxClientDC) -}; - -//----------------------------------------------------------------------------- -// wxMemoryDC -//----------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxMemoryDC: public wxDC -{ -public: - wxMemoryDC(); - wxMemoryDC( wxBitmap& bitmap ); - wxMemoryDC( wxDC *dc ); - -private: - DECLARE_DYNAMIC_CLASS(wxMemoryDC) -}; - -//----------------------------------------------------------------------------- -// wxPaintDC -//----------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxPaintDC : public wxDC -{ -public: - wxPaintDC(); - wxPaintDC( wxWindow *win ); - -private: - DECLARE_DYNAMIC_CLASS(wxPaintDC) + virtual wxImplDC* CreateWindowDC( wxWindowDC *owner ); + virtual wxImplDC* CreateWindowDC( wxWindowDC *owner, wxWindow *window ); + virtual wxImplDC* CreateClientDC( wxClientDC *owner ); + virtual wxImplDC* CreateClientDC( wxClientDC *owner, wxWindow *window ); + virtual wxImplDC* CreatePaintDC( wxPaintDC *owner ); + virtual wxImplDC* CreatePaintDC( wxPaintDC *owner, wxWindow *window ); + virtual wxImplDC* CreateMemoryDC( wxMemoryDC *owner ); + virtual wxImplDC* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap ); + virtual wxImplDC* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc ); + virtual wxImplDC* CreateScreenDC( wxScreenDC *owner ); }; //----------------------------------------------------------------------------- @@ -152,7 +169,7 @@ public: wxImplDC( wxDC *owner ); ~wxImplDC(); - wxDC *GetOwner() { return m_owner; } + wxDC *GetOwner() const { return m_owner; } virtual bool IsOk() const { return m_ok; } @@ -184,7 +201,7 @@ public: // bounding box - virtual void CalcBoundingBox(wxCoord x, wxCoord y); + virtual void CalcBoundingBox(wxCoord x, wxCoord y) { if ( m_isBBoxValid ) { @@ -203,7 +220,7 @@ public: m_maxY = y; } } - void ResetBoundingBox(); + void ResetBoundingBox() { m_isBBoxValid = false; @@ -421,7 +438,9 @@ public: #if wxUSE_SPLINES - virtual void DoDrawSpline(wxList *points); + virtual void DoDrawSpline(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord x3, wxCoord y3); + virtual void DoDrawSpline(int n, wxPoint points[]); + virtual void DoDrawSpline(const wxPointList *points); #endif private: @@ -486,7 +505,7 @@ protected: private: DECLARE_ABSTRACT_CLASS(wxImplDC) -} +}; class wxDC: public wxObject @@ -494,6 +513,9 @@ class wxDC: public wxObject public: wxDC() { m_pimpl = NULL; } + wxImplDC *GetImpl() + { return m_pimpl; } + bool IsOk() const { return m_pimpl && m_pimpl->IsOk(); } @@ -588,9 +610,9 @@ public: { return m_pimpl->GetBackground(); } void SetBackgroundMode(int mode) - { m_pimpl->SetBackground( mode ); } + { m_pimpl->SetBackgroundMode( mode ); } int GetBackgroundMode() const - { return m_pimpl->GetBackground(); } + { return m_pimpl->GetBackgroundMode(); } void SetTextForeground(const wxColour& colour) { m_pimpl->SetTextForeground(colour); } @@ -680,19 +702,19 @@ public: wxCoord DeviceToLogicalX(wxCoord x) const { return m_pimpl->DeviceToLogicalX(x); } - wxCoord DeviceToLogicalY(wxCoord y) const; + wxCoord DeviceToLogicalY(wxCoord y) const { return m_pimpl->DeviceToLogicalY(y); } - wxCoord DeviceToLogicalXRel(wxCoord x) const; + wxCoord DeviceToLogicalXRel(wxCoord x) const { return m_pimpl->DeviceToLogicalXRel(x); } - wxCoord DeviceToLogicalYRel(wxCoord y) const; + wxCoord DeviceToLogicalYRel(wxCoord y) const { return m_pimpl->DeviceToLogicalYRel(y); } - wxCoord LogicalToDeviceX(wxCoord x) const; + wxCoord LogicalToDeviceX(wxCoord x) const { return m_pimpl->LogicalToDeviceX(x); } - wxCoord LogicalToDeviceY(wxCoord y) const; + wxCoord LogicalToDeviceY(wxCoord y) const { return m_pimpl->LogicalToDeviceY(y); } - wxCoord LogicalToDeviceXRel(wxCoord x) const; + wxCoord LogicalToDeviceXRel(wxCoord x) const { return m_pimpl->LogicalToDeviceXRel(x); } - wxCoord LogicalToDeviceYRel(wxCoord y) const; + wxCoord LogicalToDeviceYRel(wxCoord y) const { return m_pimpl->LogicalToDeviceYRel(y); } void SetMapMode(int mode) @@ -756,9 +778,9 @@ public: void GradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour) - { m_pimpl->GradientFillConcentric(rect, initialColour, destColour, - wxPoint(rect.GetWidth() / 2, - rect.GetHeight() / 2)); } + { m_pimpl->DoGradientFillConcentric( rect, initialColour, destColour, + wxPoint(rect.GetWidth() / 2, + rect.GetHeight() / 2)); } void GradientFillConcentric(const wxRect& rect, const wxColour& initialColour, @@ -815,19 +837,25 @@ public: void DrawLines(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0) { m_pimpl->DoDrawLines(n, points, xoffset, yoffset); } - void DrawLines(const wxList *list, + +#if 0 + // needs to be removed + void DrawLines(const wxPointList *list, wxCoord xoffset = 0, wxCoord yoffset = 0) - { m_pimpl->DrawLines( list, xoffset, yoffset ); } +#endif void DrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle = wxODDEVEN_RULE) { m_pimpl->DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); } - void DrawPolygon(const wxList *list, +#if 0 + // needs to be removed + void DrawPolygon(const wxPointList *list, wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle = wxODDEVEN_RULE) { m_pimpl->DrawPolygon( list, xoffset, yoffset, fillStyle ); } +#endif void DrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, @@ -853,7 +881,7 @@ public: void DrawCircle(wxCoord x, wxCoord y, wxCoord radius) { m_pimpl->DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); } void DrawCircle(const wxPoint& pt, wxCoord radius) - { m_pimpl->DrawCircle(pt.x, pt.y, radius); } + { m_pimpl->DoDrawEllipse(pt.x - radius, pt.y - radius, 2*radius, 2*radius); } void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { m_pimpl->DoDrawEllipse(x, y, width, height); } @@ -893,13 +921,12 @@ public: const wxRect& rect, int alignment = wxALIGN_LEFT | wxALIGN_TOP, int indexAccel = -1, - wxRect *rectBounding = NULL) - { m_pimpl->DrawLabel( text, image, rect, alignment, indexAccel, rectBounding ); } + wxRect *rectBounding = NULL); void DrawLabel(const wxString& text, const wxRect& rect, int alignment = wxALIGN_LEFT | wxALIGN_TOP, int indexAccel = -1) - { m_pimpl->DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); } + { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); } bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, @@ -941,15 +968,13 @@ public: } #if wxUSE_SPLINES - // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?) void DrawSpline(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord x3, wxCoord y3) - { m_pimpl->DrawSpline(x1,y1,x2,y2,x3,y3); } + { m_pimpl->DoDrawSpline(x1,y1,x2,y2,x3,y3); } void DrawSpline(int n, wxPoint points[]) - { m_pimpl->DrawSpline(n,points); } - - void DrawSpline(wxList *points) + { m_pimpl->DoDrawSpline(n,points); } + void DrawSpline(const wxPointList *points) { m_pimpl->DoDrawSpline(points); } #endif // wxUSE_SPLINES @@ -972,71 +997,55 @@ protected: private: DECLARE_ABSTRACT_CLASS(wxImplDC) -} - - -#else // wxUSE_NEW_DC +}; -class WXDLLIMPEXP_FWD_CORE wxDC; -class WXDLLIMPEXP_FWD_CORE wxDCBase; +//----------------------------------------------------------------------------- +// wxWindowDC +//----------------------------------------------------------------------------- -class WXDLLEXPORT wxDrawObject +class WXDLLIMPEXP_CORE wxWindowDC : public wxDC { public: + wxWindowDC(); + wxWindowDC( wxWindow *win ); - wxDrawObject() - : m_isBBoxValid(false) - , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0) - { } - - virtual ~wxDrawObject() { } +private: + DECLARE_DYNAMIC_CLASS(wxWindowDC) +}; - virtual void Draw(wxDCBase&) const { } +//----------------------------------------------------------------------------- +// wxClientDC +//----------------------------------------------------------------------------- - virtual void CalcBoundingBox(wxCoord x, wxCoord y) - { - if ( m_isBBoxValid ) - { - if ( x < m_minX ) m_minX = x; - if ( y < m_minY ) m_minY = y; - if ( x > m_maxX ) m_maxX = x; - if ( y > m_maxY ) m_maxY = y; - } - else - { - m_isBBoxValid = true; +class WXDLLIMPEXP_CORE wxClientDC : public wxDC +{ +public: + wxClientDC(); + wxClientDC( wxWindow *win ); - m_minX = x; - m_minY = y; - m_maxX = x; - m_maxY = y; - } - } +private: + DECLARE_DYNAMIC_CLASS(wxClientDC) +}; - void ResetBoundingBox() - { - m_isBBoxValid = false; +//----------------------------------------------------------------------------- +// wxPaintDC +//----------------------------------------------------------------------------- - m_minX = m_maxX = m_minY = m_maxY = 0; - } +class WXDLLIMPEXP_CORE wxPaintDC : public wxDC +{ +public: + wxPaintDC(); + wxPaintDC( wxWindow *win ); - // Get the final bounding box of the PostScript or Metafile picture. +private: + DECLARE_DYNAMIC_CLASS(wxPaintDC) +}; - wxCoord MinX() const { return m_minX; } - wxCoord MaxX() const { return m_maxX; } - wxCoord MinY() const { return m_minY; } - wxCoord MaxY() const { return m_maxY; } +#else // wxUSE_NEW_DC - //to define the type of object for derived objects - virtual int GetType()=0; -protected: - //for boundingbox calculation - bool m_isBBoxValid:1; - //for boundingbox calculation - wxCoord m_minX, m_minY, m_maxX, m_maxY; -}; +class WXDLLIMPEXP_FWD_CORE wxDC; // --------------------------------------------------------------------------- // global variables @@ -1062,6 +1071,8 @@ public: CalcBoundingBox(drawobject->MaxX(),drawobject->MaxY()); } + wxDC *GetOwner() const { return (wxDC*) this; } + bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE) { return DoFloodFill(x, y, col, style); } @@ -1133,18 +1144,30 @@ public: void DrawLines(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0) { DoDrawLines(n, points, xoffset, yoffset); } - void DrawLines(const wxList *list, + void DrawLines(const wxPointList *list, wxCoord xoffset = 0, wxCoord yoffset = 0); +#if WXWIN_COMPATIBILITY_2_8 + wxDEPRECATED( void DrawLines(const wxList *list, + wxCoord xoffset = 0, wxCoord yoffset = 0) ); +#endif // WXWIN_COMPATIBILITY_2_8 + + void DrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle = wxODDEVEN_RULE) { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); } - void DrawPolygon(const wxList *list, + void DrawPolygon(const wxPointList *list, wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle = wxODDEVEN_RULE); +#if WXWIN_COMPATIBILITY_2_8 + wxDEPRECATED( void DrawPolygon(const wxList *list, + wxCoord xoffset = 0, wxCoord yoffset = 0, + int fillStyle = wxODDEVEN_RULE) ); +#endif // WXWIN_COMPATIBILITY_2_8 + void DrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle = wxODDEVEN_RULE) @@ -1256,13 +1279,17 @@ public: } #if wxUSE_SPLINES - // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?) void DrawSpline(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord x3, wxCoord y3); void DrawSpline(int n, wxPoint points[]); - void DrawSpline(wxList *points) { DoDrawSpline(points); } + void DrawSpline(const wxPointList *points) { DoDrawSpline(points); } + +#if WXWIN_COMPATIBILITY_2_8 + wxDEPRECATED( void DrawSpline(const wxList *points) ); +#endif // WXWIN_COMPATIBILITY_2_8 + #endif // wxUSE_SPLINES // Eventually we will have wxUSE_GENERIC_DRAWELLIPSE @@ -1303,11 +1330,11 @@ public: * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle). * \param center Center of rotation. */ - void Rotate( wxList* points, double angle, wxPoint center = wxPoint(0,0) ); + void Rotate( wxPointList* points, double angle, wxPoint center = wxPoint(0,0) ); // used by DrawEllipticArcRot // Careful: wxList gets filled with points you have to delete later. - void CalculateEllipticPoints( wxList* points, + void CalculateEllipticPoints( wxPointList* points, wxCoord xStart, wxCoord yStart, wxCoord w, wxCoord h, double sa, double ea ); @@ -1694,7 +1721,7 @@ protected: virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; #if wxUSE_SPLINES - virtual void DoDrawSpline(wxList *points); + virtual void DoDrawSpline(const wxPointList *points); #endif protected: