X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1d156af3247c862e51a7c62f569a3fd302052a42..a8123c1359cb21b246cc9f97d96993d8cff685fe:/include/wx/graphics.h diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 6e7cf27fe3..46f60b6884 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -5,7 +5,6 @@ // Modified by: // Created: // Copyright: (c) Stefan Csomor -// RCS-ID: $Id$ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -19,6 +18,7 @@ #include "wx/geometry.h" #include "wx/dynarray.h" #include "wx/dc.h" +#include "wx/image.h" #include "wx/vector.h" enum wxAntialiasMode @@ -106,6 +106,7 @@ class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap; // class WXDLLIMPEXP_FWD_CORE wxGraphicsObjectRefData; +class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmapData; class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrixData; class WXDLLIMPEXP_FWD_CORE wxGraphicsPathData; @@ -166,6 +167,21 @@ class WXDLLIMPEXP_CORE wxGraphicsBitmap : public wxGraphicsObject public: wxGraphicsBitmap() {} virtual ~wxGraphicsBitmap() {} + + // Convert bitmap to wxImage: this is more efficient than converting to + // wxBitmap first and then to wxImage and also works without X server + // connection under Unix that wxBitmap requires. +#if wxUSE_IMAGE + wxImage ConvertToImage() const; +#endif // wxUSE_IMAGE + + void* GetNativeBitmap() const; + + const wxGraphicsBitmapData* GetBitmapData() const + { return (const wxGraphicsBitmapData*) GetRefData(); } + wxGraphicsBitmapData* GetBitmapData() + { return (wxGraphicsBitmapData*) GetRefData(); } + private: DECLARE_DYNAMIC_CLASS(wxGraphicsBitmap) }; @@ -381,7 +397,7 @@ public: void Add(wxColour col, float pos) { Add(wxGraphicsGradientStop(col, pos)); } // Get the number of stops. - unsigned GetCount() const { return m_stops.size(); } + size_t GetCount() const { return m_stops.size(); } // Return the stop at the given index (which must be valid). wxGraphicsGradientStop Item(unsigned n) const { return m_stops.at(n); } @@ -425,6 +441,13 @@ public: static wxGraphicsContext* Create( wxWindow* window ); +#if wxUSE_IMAGE + // Create a context for drawing onto a wxImage. The image life time must be + // greater than that of the context itself as when the context is destroyed + // it will copy its contents to the specified image. + static wxGraphicsContext* Create(wxImage& image); +#endif // wxUSE_IMAGE + // create a context that can be used for measuring texts only, no drawing allowed static wxGraphicsContext * Create(); @@ -474,11 +497,18 @@ public: wxDouble xc, wxDouble yc, wxDouble radius, const wxGraphicsGradientStops& stops) const; - // sets the font + // creates a font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) const; + virtual wxGraphicsFont CreateFont(double sizeInPixels, + const wxString& facename, + int flags = wxFONTFLAG_DEFAULT, + const wxColour& col = *wxBLACK) const; // create a native bitmap representation virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) const; +#if wxUSE_IMAGE + wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image) const; +#endif // wxUSE_IMAGE // create a native bitmap representation virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) const; @@ -487,6 +517,16 @@ public: virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, wxDouble tx=0.0, wxDouble ty=0.0) const; + wxGraphicsMatrix CreateMatrix( const wxAffineMatrix2DBase& mat ) const + { + wxMatrix2D mat2D; + wxPoint2DDouble tr; + mat.Get(&mat2D, &tr); + + return CreateMatrix(mat2D.m_11, mat2D.m_12, mat2D.m_21, mat2D.m_22, + tr.m_x, tr.m_y); + } + // push the current state of the context, ie the transformation matrix on a stack virtual void PushState() = 0; @@ -524,7 +564,7 @@ public: virtual bool SetCompositionMode(wxCompositionMode op) = 0; // returns the size of the graphics context in device coordinates - void GetSize(wxDouble* width, wxDouble* height) + void GetSize(wxDouble* width, wxDouble* height) const { if ( width ) *width = m_width; @@ -772,6 +812,10 @@ public: virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0; +#if wxUSE_IMAGE + virtual wxGraphicsContext * CreateContextFromImage(wxImage& image) = 0; +#endif // wxUSE_IMAGE + // create a context that can be used for measuring texts only, no drawing allowed virtual wxGraphicsContext * CreateMeasuringContext() = 0; @@ -806,9 +850,17 @@ public: // sets the font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) = 0; + virtual wxGraphicsFont CreateFont(double sizeInPixels, + const wxString& facename, + int flags = wxFONTFLAG_DEFAULT, + const wxColour& col = *wxBLACK) = 0; // create a native bitmap representation virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) = 0; +#if wxUSE_IMAGE + virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image) = 0; + virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp) = 0; +#endif // wxUSE_IMAGE // create a graphics bitmap from a native bitmap virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap ) = 0; @@ -821,6 +873,16 @@ private: DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer) }; -#endif + +#if wxUSE_IMAGE +inline +wxImage wxGraphicsBitmap::ConvertToImage() const +{ + wxGraphicsRenderer* renderer = GetRenderer(); + return renderer ? renderer->CreateImageFromBitmap(*this) : wxNullImage; +} +#endif // wxUSE_IMAGE + +#endif // wxUSE_GRAPHICS_CONTEXT #endif // _WX_GRAPHICS_H_