X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ea76a6a5ca75f8e623982de97f7f7b2746b5ee50..8736cc485b94318d9c5d1e4bb443f16de9b8c9b4:/include/wx/dc.h?ds=sidebyside diff --git a/include/wx/dc.h b/include/wx/dc.h index bb485c7aca..7551b99905 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: dc.h +// Name: wx/dc.h // Purpose: wxDC class // Author: Vadim Zeitlin // Modified by: @@ -12,16 +12,13 @@ #ifndef _WX_DC_H_BASE_ #define _WX_DC_H_BASE_ -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma interface "dcbase.h" -#endif - // ---------------------------------------------------------------------------- // headers which we must include here // ---------------------------------------------------------------------------- #include "wx/object.h" // the base class +#include "wx/intl.h" // for wxLayoutDirection #include "wx/cursor.h" // we have member variables of these classes #include "wx/font.h" // so we can't do without them #include "wx/colour.h" @@ -31,6 +28,7 @@ #include "wx/palette.h" #include "wx/list.h" // we use wxList in inline functions #include "wx/dynarray.h" +#include "wx/math.h" class WXDLLEXPORT wxDC; class WXDLLEXPORT wxDCBase; @@ -96,8 +94,6 @@ protected: // global variables // --------------------------------------------------------------------------- -WXDLLEXPORT_DATA(extern int) wxPageNumber; - // --------------------------------------------------------------------------- // wxDC is the device context - object on which any drawing is done // --------------------------------------------------------------------------- @@ -137,10 +133,7 @@ public: ResetClipping(); } - ~wxDCBase() { } - - virtual void BeginDrawing() { } - virtual void EndDrawing() { } + virtual ~wxDCBase() { } // graphic primitives // ------------------ @@ -159,6 +152,28 @@ public: int style = wxFLOOD_SURFACE) { return DoFloodFill(pt.x, pt.y, col, style); } + // fill the area specified by rect with a radial gradient, starting from + // initialColour in the centre of the cercle and fading to destColour. + void GradientFillConcentric(const wxRect& rect, + const wxColour& initialColour, + const wxColour& destColour) + { GradientFillConcentric(rect, initialColour, destColour, + wxPoint(rect.GetWidth() / 2, + rect.GetHeight() / 2)); } + + void GradientFillConcentric(const wxRect& rect, + const wxColour& initialColour, + const wxColour& destColour, + const wxPoint& circleCenter) + { DoGradientFillConcentric(rect, initialColour, destColour, circleCenter); } + + // fill the area specified by rect with a linear gradient + void GradientFillLinear(const wxRect& rect, + const wxColour& initialColour, + const wxColour& destColour, + wxDirection nDirection = wxEAST) + { DoGradientFillLinear(rect, initialColour, destColour, nDirection); } + bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const { return DoGetPixel(x, y, col); } bool GetPixel(const wxPoint& pt, wxColour *col) const @@ -299,6 +314,30 @@ public: source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y); } + bool StretchBlit(wxCoord dstX, wxCoord dstY, + wxCoord dstWidth, wxCoord dstHeight, + wxDC *source, + wxCoord srcX, wxCoord srcY, + wxCoord srcWidth, wxCoord srcHeight, + int rop = wxCOPY, bool useMask = false, + wxCoord srcMaskX = wxDefaultCoord, wxCoord srcMaskY = wxDefaultCoord) + { + return DoStretchBlit(dstX, dstY, dstWidth, dstHeight, + source, srcX, srcY, srcWidth, srcHeight, rop, useMask, srcMaskX, srcMaskY); + } + bool StretchBlit(const wxPoint& dstPt, const wxSize& dstSize, + wxDC *source, const wxPoint& srcPt, const wxSize& srcSize, + int rop = wxCOPY, bool useMask = false, const wxPoint& srcMaskPt = wxDefaultPosition) + { + return DoStretchBlit(dstPt.x, dstPt.y, dstSize.x, dstSize.y, + source, srcPt.x, srcPt.y, srcSize.x, srcSize.y, rop, useMask, srcMaskPt.x, srcMaskPt.y); + } + + wxBitmap GetAsBitmap(const wxRect *subrect = (const wxRect *) NULL) const + { + return DoGetAsBitmap(subrect); + } + #if wxUSE_SPLINES // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?) void DrawSpline(wxCoord x1, wxCoord y1, @@ -347,7 +386,7 @@ 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() ); + void Rotate( wxList* points, double angle, wxPoint center = wxPoint(0,0) ); // used by DrawEllipticArcRot // Careful: wxList gets filled with points you have to delete later. @@ -368,6 +407,12 @@ public: virtual void StartPage() { } virtual void EndPage() { } +#if WXWIN_COMPATIBILITY_2_6 + wxDEPRECATED( void BeginDrawing() ); + wxDEPRECATED( void EndDrawing() ); +#endif // WXWIN_COMPATIBILITY_2_6 + + // set objects to use for drawing // ------------------------------ @@ -412,15 +457,29 @@ public: wxCoord *x, wxCoord *y, wxCoord *descent = NULL, wxCoord *externalLeading = NULL, - wxFont *theFont = NULL) const + const wxFont *theFont = NULL) const { DoGetTextExtent(string, x, y, descent, externalLeading, theFont); } + wxSize GetTextExtent(const wxString& string) const + { + wxCoord w, h; + DoGetTextExtent(string, &w, &h); + return wxSize(w, h); + } + // works for single as well as multi-line strings - virtual void GetMultiLineTextExtent(const wxString& text, + virtual void GetMultiLineTextExtent(const wxString& string, wxCoord *width, wxCoord *height, wxCoord *heightLine = NULL, - wxFont *font = NULL); + const wxFont *font = NULL) const; + + wxSize GetMultiLineTextExtent(const wxString& string) const + { + wxCoord w, h; + GetMultiLineTextExtent(string, &w, &h); + return wxSize(w, h); + } // Measure cumulative width of text after each character bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const @@ -478,25 +537,26 @@ public: // Resolution in Pixels per inch virtual wxSize GetPPI() const = 0; - virtual bool Ok() const { return m_ok; } + virtual bool Ok() const { return IsOk(); } + virtual bool IsOk() const { return m_ok; } // accessors and setters // --------------------- - int GetBackgroundMode() const { return m_backgroundMode; } - const wxBrush& GetBackground() const { return m_backgroundBrush; } - const wxBrush& GetBrush() const { return m_brush; } - const wxFont& GetFont() const { return m_font; } - const wxPen& GetPen() const { return m_pen; } + virtual int GetBackgroundMode() const { return m_backgroundMode; } + virtual const wxBrush& GetBackground() const { return m_backgroundBrush; } + virtual const wxBrush& GetBrush() const { return m_brush; } + virtual const wxFont& GetFont() const { return m_font; } + virtual const wxPen& GetPen() const { return m_pen; } - const wxColour& GetTextForeground() const { return m_textForegroundColour; } - const wxColour& GetTextBackground() const { return m_textBackgroundColour; } + virtual const wxColour& GetTextForeground() const { return m_textForegroundColour; } + virtual const wxColour& GetTextBackground() const { return m_textBackgroundColour; } virtual void SetTextForeground(const wxColour& colour) { m_textForegroundColour = colour; } virtual void SetTextBackground(const wxColour& colour) { m_textBackgroundColour = colour; } - int GetMapMode() const { return m_mappingMode; } + virtual int GetMapMode() const { return m_mappingMode; } virtual void SetMapMode(int mode) = 0; virtual void GetUserScale(double *x, double *y) const @@ -529,16 +589,13 @@ public: { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); } virtual void SetDeviceOrigin(wxCoord x, wxCoord y) = 0; + virtual void ComputeScaleAndOrigin() {} + virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0; - int GetLogicalFunction() const { return m_logicalFunction; } + virtual int GetLogicalFunction() const { return m_logicalFunction; } virtual void SetLogicalFunction(int function) = 0; -#if WXWIN_COMPATIBILITY_2_4 - virtual void SetOptimization(bool WXUNUSED(opt)) { } - virtual bool GetOptimization() { return false; } -#endif - // bounding box // ------------ @@ -583,7 +640,7 @@ public: long *x, long *y, long *descent = NULL, long *externalLeading = NULL, - wxFont *theFont = NULL) const + const wxFont *theFont = NULL) const { wxCoord x2, y2, descent2, externalLeading2; DoGetTextExtent(string, &x2, &y2, @@ -628,11 +685,31 @@ public: if (h) *h = hh; } + // RTL related functions + // --------------------- + + // get or change the layout direction (LTR or RTL) for this dc, + // wxLayout_Default is returned if layout direction is not supported + virtual wxLayoutDirection GetLayoutDirection() const + { return wxLayout_Default; } + virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir)) + { } + protected: // the pure virtual functions which should be implemented by wxDC virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE) = 0; + virtual void DoGradientFillLinear(const wxRect& rect, + const wxColour& initialColour, + const wxColour& destColour, + wxDirection nDirection = wxEAST); + + virtual void DoGradientFillConcentric(const wxRect& rect, + const wxColour& initialColour, + const wxColour& destColour, + const wxPoint& circleCenter); + virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0; virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0; @@ -665,8 +742,25 @@ protected: virtual bool DoBlit(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) = 0; + wxDC *source, + wxCoord xsrc, wxCoord ysrc, + int rop = wxCOPY, + bool useMask = false, + wxCoord xsrcMask = wxDefaultCoord, + wxCoord ysrcMask = wxDefaultCoord) = 0; + + virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest, + wxCoord dstWidth, wxCoord dstHeight, + wxDC *source, + wxCoord xsrc, wxCoord ysrc, + wxCoord srcWidth, wxCoord srcHeight, + int rop = wxCOPY, + bool useMask = false, + wxCoord xsrcMask = wxDefaultCoord, + wxCoord ysrcMask = wxDefaultCoord); + + virtual wxBitmap DoGetAsBitmap(const wxRect *WXUNUSED(subrect)) const + { return wxNullBitmap; } virtual void DoGetSize(int *width, int *height) const = 0; virtual void DoGetSizeMM(int* width, int* height) const = 0; @@ -684,13 +778,6 @@ protected: virtual void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0; -#if WXWIN_COMPATIBILITY_2_4 - // this was only for confusing people, use DoGetClippingBox only - virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y, - wxCoord *w, wxCoord *h) - { DoGetClippingBox(x, y, w, h); } -#endif - virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const { @@ -720,7 +807,7 @@ protected: wxCoord *x, wxCoord *y, wxCoord *descent = NULL, wxCoord *externalLeading = NULL, - wxFont *theFont = NULL) const = 0; + const wxFont *theFont = NULL) const = 0; virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; @@ -788,18 +875,22 @@ private: // now include the declaration of wxDC class // ---------------------------------------------------------------------------- -#if defined(__PALMOS__) +#if defined(__WXPALMOS__) #include "wx/palmos/dc.h" #elif defined(__WXMSW__) #include "wx/msw/dc.h" #elif defined(__WXMOTIF__) #include "wx/motif/dc.h" -#elif defined(__WXGTK__) +#elif defined(__WXGTK20__) #include "wx/gtk/dc.h" +#elif defined(__WXGTK__) + #include "wx/gtk1/dc.h" #elif defined(__WXX11__) #include "wx/x11/dc.h" #elif defined(__WXMGL__) #include "wx/mgl/dc.h" +#elif defined(__WXDFB__) + #include "wx/dfb/dc.h" #elif defined(__WXMAC__) #include "wx/mac/dc.h" #elif defined(__WXCOCOA__) @@ -808,6 +899,10 @@ private: #include "wx/os2/dc.h" #endif +#if wxUSE_GRAPHICS_CONTEXT + #include "wx/dcgraph.h" +#endif + // ---------------------------------------------------------------------------- // helper class: you can use it to temporarily change the DC text colour and // restore it automatically when the object goes out of scope @@ -818,6 +913,11 @@ class WXDLLEXPORT wxDCTextColourChanger public: wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { } + wxDCTextColourChanger(wxDC& dc, const wxColour& col) : m_dc(dc) + { + Set(col); + } + ~wxDCTextColourChanger() { if ( m_colFgOld.Ok() ) @@ -839,6 +939,60 @@ private: DECLARE_NO_COPY_CLASS(wxDCTextColourChanger) }; +// ---------------------------------------------------------------------------- +// helper class: you can use it to temporarily change the DC pen and +// restore it automatically when the object goes out of scope +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxDCPenChanger +{ +public: + wxDCPenChanger(wxDC& dc, const wxPen& pen) : m_dc(dc), m_penOld(dc.GetPen()) + { + m_dc.SetPen(pen); + } + + ~wxDCPenChanger() + { + if ( m_penOld.Ok() ) + m_dc.SetPen(m_penOld); + } + +private: + wxDC& m_dc; + + wxPen m_penOld; + + DECLARE_NO_COPY_CLASS(wxDCPenChanger) +}; + +// ---------------------------------------------------------------------------- +// helper class: you can use it to temporarily change the DC brush and +// restore it automatically when the object goes out of scope +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxDCBrushChanger +{ +public: + wxDCBrushChanger(wxDC& dc, const wxBrush& brush) : m_dc(dc), m_brushOld(dc.GetBrush()) + { + m_dc.SetBrush(brush); + } + + ~wxDCBrushChanger() + { + if ( m_brushOld.Ok() ) + m_dc.SetBrush(m_brushOld); + } + +private: + wxDC& m_dc; + + wxBrush m_brushOld; + + DECLARE_NO_COPY_CLASS(wxDCBrushChanger) +}; + // ---------------------------------------------------------------------------- // another small helper class: sets the clipping region in its ctor and // destroys it in the dtor @@ -847,6 +1001,8 @@ private: class WXDLLEXPORT wxDCClipper { public: + wxDCClipper(wxDC& dc, const wxRegion& r) : m_dc(dc) + { dc.SetClippingRegion(r); } wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc) { dc.SetClippingRegion(r.x, r.y, r.width, r.height); } wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc) @@ -860,5 +1016,4 @@ private: DECLARE_NO_COPY_CLASS(wxDCClipper) }; -#endif - // _WX_DC_H_BASE_ +#endif // _WX_DC_H_BASE_