#include "wx/graphics.h"
+#if wxUSE_CAIRO
+
+#include "wx/cairo.h"
+
#ifndef WX_PRECOMP
#include "wx/bitmap.h"
#include "wx/icon.h"
#endif
#include <cairo.h>
+#ifdef __WXMSW__
+#include <cairo-win32.h>
+#endif
+
#ifdef __WXGTK__
#include <gtk/gtk.h>
#include "wx/fontutil.h"
cairo_font_slant_t m_slant;
cairo_font_weight_t m_weight;
#endif
+#ifdef __WXMSW__
+ wxCairoContext( wxGraphicsRenderer* renderer, HDC context );
+#endif
};
class wxCairoBitmapData : public wxGraphicsObjectRefData
{
public:
wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp );
+ wxCairoBitmapData( wxGraphicsRenderer* renderer, cairo_surface_t* bitmap );
~wxCairoBitmapData();
virtual cairo_surface_t* GetCairoSurface() { return m_surface; }
}
virtual void Clip( const wxRegion ®ion );
+#ifdef __WXMSW__
+ cairo_surface_t* m_mswSurface;
+#endif
// clips drawings to the rect
virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
// wxCairoBitmap implementation
//-----------------------------------------------------------------------------
+wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, cairo_surface_t* bitmap ) :
+ wxGraphicsObjectRefData( renderer )
+{
+ m_surface = bitmap;
+ m_pattern = cairo_pattern_create_for_surface(m_surface);
+}
+
wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp ) : wxGraphicsObjectRefData( renderer )
{
wxCHECK_RET( bmp.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap"));
- int bw = bmp.GetWidth();
- int bh = bmp.GetHeight();
+ int bw = m_width = bmp.GetWidth();
+ int bh = m_height = bmp.GetHeight();
wxBitmap bmpSource = bmp; // we need a non-const instance
m_buffer = new unsigned char[bw*bh*4];
wxUint32* data = (wxUint32*)m_buffer;
p.OffsetY(pixData, 1);
}
}
+ m_pattern = cairo_pattern_create_for_surface(m_surface);
}
wxCairoBitmapData::~wxCairoBitmapData()
{
- cairo_pattern_destroy(m_pattern);
- cairo_surface_destroy(m_surface);
+ if (m_pattern)
+ cairo_pattern_destroy(m_pattern);
+
+ if (m_surface)
+ cairo_surface_destroy(m_surface);
+
delete [] m_buffer;
}
}
#endif
+#ifdef __WXMSW__
+wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, HDC handle )
+: wxGraphicsContext(renderer)
+{
+ m_mswSurface = cairo_win32_surface_create(handle);
+ m_context = cairo_create(m_mswSurface);
+ PushState();
+ PushState();
+}
+#endif
+
+
wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, cairo_t *context )
: wxGraphicsContext(renderer)
{
if ( m_context )
{
PopState();
+#ifdef __WXMSW__
+ m_mswSurface = cairo_win32_surface_create((HDC)window->GetHandle());
+ m_context = cairo_create(m_mswSurface);
+#endif
PopState();
cairo_destroy(m_context);
}
+#ifdef __WXMSW__
+ if ( m_mswSurface )
+ cairo_surface_destroy(m_mswSurface);
+#endif
}
void wxCairoContext::Init(cairo_t *context)
// create a native bitmap representation
virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap );
+ // create a graphics bitmap from a native bitmap
+ virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap );
+
// create a subimage from a native image representation
virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
extern wxGraphicsRenderer* gCairoRenderer;
wxGraphicsRenderer* gCairoRenderer = &gs_cairoGraphicsRenderer;
-#ifdef __WXGTK__
-wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer()
-{
- return &gs_cairoGraphicsRenderer;
-}
-#endif
-
wxGraphicsContext * wxCairoRenderer::CreateContext( const wxWindowDC& dc)
{
return new wxCairoContext(this,dc);
wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeContext( void * context )
{
+#ifdef __WXMSW__
+ return new wxCairoContext(this,(HDC)context);
+#endif
+#ifdef __WXGTK__
return new wxCairoContext(this,(cairo_t*)context);
+#endif
}
return wxNullGraphicsBitmap;
}
+wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap )
+{
+ if ( bitmap != NULL )
+ {
+ wxGraphicsBitmap p;
+ p.SetRefData(new wxCairoBitmapData( this , (cairo_surface_t*) bitmap ));
+ return p;
+ }
+ else
+ return wxNullGraphicsBitmap;
+}
+
wxGraphicsBitmap
wxCairoRenderer::CreateSubBitmap(const wxGraphicsBitmap& WXUNUSED(bitmap),
wxDouble WXUNUSED(x),
return wxNullGraphicsBitmap;
}
-#endif // wxUSE_GRAPHICS_CONTEXT
+wxGraphicsRenderer* wxGraphicsRenderer::GetCairoRenderer()
+{
+ return &gs_cairoGraphicsRenderer;
+}
+
+#else // !wxUSE_CAIRO
+
+wxGraphicsRenderer* wxGraphicsRenderer::GetCairoRenderer()
+{
+ return NULL;
+}
+
+#endif // wxUSE_CAIRO/!wxUSE_CAIRO
+
+// MSW and OS X have their own native default renderers, but the other ports
+// use Cairo by default
+#if !(defined(__WXMSW__) || defined(__WXOSX__))
+wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer()
+{
+ return GetCairoRenderer();
+}
+#endif // !(__WXMSW__ || __WXOSX__)
+
+#endif // wxUSE_GRAPHICS_CONTEXT