Implemented wxCairoRenderer::CreateSubBitmap method.

This commit is contained in:
Artur Wieczorek
2016-03-24 21:12:40 +01:00
parent e37f1a84ce
commit d6afb66388
3 changed files with 38 additions and 11 deletions

View File

@@ -446,9 +446,6 @@ public:
/** /**
Extracts a sub-bitmap from an existing bitmap. Extracts a sub-bitmap from an existing bitmap.
Currently this function is implemented in the native MSW and OS X
versions but not when using Cairo.
*/ */
virtual wxGraphicsBitmap CreateSubBitmap(const wxGraphicsBitmap& bitmap, virtual wxGraphicsBitmap CreateSubBitmap(const wxGraphicsBitmap& bitmap,
wxDouble x, wxDouble y, wxDouble x, wxDouble y,

View File

@@ -168,6 +168,8 @@
(cairo_t *cr, double tx, double ty), (cr, tx, ty) ) \ (cairo_t *cr, double tx, double ty), (cr, tx, ty) ) \
m( cairo_surface_flush, \ m( cairo_surface_flush, \
(cairo_surface_t *surface), (surface) ) \ (cairo_surface_t *surface), (surface) ) \
m( cairo_set_source_surface, \
(cairo_t *cr, cairo_surface_t *surface, double x, double y), (cr, surface, x, y) ) \
#ifdef __WXMAC__ #ifdef __WXMAC__
#define wxCAIRO_PLATFORM_METHODS(m) \ #define wxCAIRO_PLATFORM_METHODS(m) \
@@ -230,6 +232,8 @@
(cairo_surface_t *surface), (surface), -1) \ (cairo_surface_t *surface), (surface), -1) \
m( const char *, cairo_version_string, \ m( const char *, cairo_version_string, \
(), () , NULL ) \ (), () , NULL ) \
m( cairo_surface_t*, cairo_surface_create_similar_image, \
(cairo_surface_t *other, cairo_format_t format, int width, int height), (other, format, width, height), NULL) \
wxCAIRO_PLATFORM_METHODS(m) wxCAIRO_PLATFORM_METHODS(m)
#define wxCAIRO_DECLARE_TYPE(rettype, name, args, argnames, defret) \ #define wxCAIRO_DECLARE_TYPE(rettype, name, args, argnames, defret) \

View File

@@ -2787,15 +2787,41 @@ wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap )
} }
wxGraphicsBitmap wxGraphicsBitmap
wxCairoRenderer::CreateSubBitmap(const wxGraphicsBitmap& WXUNUSED(bitmap), wxCairoRenderer::CreateSubBitmap(const wxGraphicsBitmap& bitmap,
wxDouble WXUNUSED(x), wxDouble x, wxDouble y,
wxDouble WXUNUSED(y), wxDouble w, wxDouble h)
wxDouble WXUNUSED(w),
wxDouble WXUNUSED(h))
{ {
wxGraphicsBitmap p; ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
wxFAIL_MSG("wxCairoRenderer::CreateSubBitmap is not implemented.");
return p; wxCHECK_MSG(!bitmap.IsNull(), wxNullGraphicsBitmap, wxS("Invalid bitmap"));
wxCairoBitmapData* dataSrc = static_cast<wxCairoBitmapData*>(bitmap.GetRefData());
cairo_surface_t* srcSurface = dataSrc->GetCairoSurface();
int srcWidth = cairo_image_surface_get_width(srcSurface);
int srcHeight = cairo_image_surface_get_height(srcSurface);
int dstWidth = wxRound(w);
int dstHeight = wxRound(h);
wxCHECK_MSG( x >= 0.0 && y >= 0.0 && dstWidth > 0 && dstHeight > 0 &&
x + dstWidth <= srcWidth && y + dstHeight <= srcHeight,
wxNullGraphicsBitmap, wxS("Invalid bitmap region"));
cairo_surface_t* dstSurface = cairo_surface_create_similar_image(srcSurface,
cairo_image_surface_get_format(srcSurface),
dstWidth, dstHeight);
cairo_t* cr = cairo_create(dstSurface);
cairo_set_source_surface(cr, srcSurface, -x, -y);
cairo_rectangle(cr, 0.0, 0.0, dstWidth, dstHeight);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_fill(cr);
cairo_destroy(cr);
wxGraphicsBitmap bmpRes;
bmpRes.SetRefData(new wxCairoBitmapData(this, dstSurface));
return bmpRes;
} }
wxString wxCairoRenderer::GetName() const wxString wxCairoRenderer::GetName() const