+#if wxUSE_GRAPHICS_CONTEXT
+
+class MyGraphicsFrame : public wxFrame
+{
+public:
+ enum
+ {
+ WIDTH = 256,
+ HEIGHT = 90
+ };
+
+ MyGraphicsFrame(wxWindow* parent) :
+ wxFrame(parent, wxID_ANY, "Graphics context test"),
+ m_image(WIDTH, HEIGHT, false)
+ {
+ // Create a test image: it has 3 horizontal primary colour bands with
+ // alpha increasing from left to right.
+ m_image.SetAlpha();
+ unsigned char* alpha = m_image.GetAlpha();
+ unsigned char* data = m_image.GetData();
+
+ for ( int y = 0; y < HEIGHT; y++ )
+ {
+ unsigned char r = 0,
+ g = 0,
+ b = 0;
+ if ( y < HEIGHT/3 )
+ r = 0xff;
+ else if ( y < (2*HEIGHT)/3 )
+ g = 0xff;
+ else
+ b = 0xff;
+
+ for ( int x = 0; x < WIDTH; x++ )
+ {
+ *alpha++ = x;
+ *data++ = r;
+ *data++ = g;
+ *data++ = b;
+ }
+ }
+
+ m_bitmap = wxBitmap(m_image);
+
+ Connect(wxEVT_PAINT, wxPaintEventHandler(MyGraphicsFrame::OnPaint));
+
+ Show();
+ }
+
+private:
+ void OnPaint(wxPaintEvent& WXUNUSED(event))
+ {
+ wxPaintDC dc(this);
+ wxScopedPtr<wxGraphicsContext> gc(wxGraphicsContext::Create(dc));
+ wxGraphicsBitmap gb(gc->CreateBitmapFromImage(m_image));
+
+ gc->SetFont(*wxNORMAL_FONT, *wxBLACK);
+ gc->DrawText("Bitmap", 0, HEIGHT/2);
+ gc->DrawBitmap(m_bitmap, 0, 0, WIDTH, HEIGHT);
+
+ wxGraphicsFont gf = gc->CreateFont(wxNORMAL_FONT->GetPixelSize().y, "");
+ gc->SetFont(gf);
+ gc->DrawText("Graphics bitmap", 0, (3*HEIGHT)/2);
+ gc->DrawBitmap(gb, 0, HEIGHT, WIDTH, HEIGHT);
+ }
+
+ wxImage m_image;
+ wxBitmap m_bitmap;
+
+ wxDECLARE_NO_COPY_CLASS(MyGraphicsFrame);
+};
+
+void MyFrame::OnTestGraphics(wxCommandEvent& WXUNUSED(event))
+{
+ new MyGraphicsFrame(this);
+}
+
+#endif // wxUSE_GRAPHICS_CONTEXT
+