[cairo] Cairo + Win32 GDI + wxWidgets?

seanedunn at yahoo.com seanedunn at yahoo.com
Sun Jan 27 18:52:33 PST 2008


Hakki,

That worked perfectly -- I didn't realize I was making more work for myself than I realized. And I appreciate you making it more cross-platform.. Point noted. :)

Sean
 
--



----- Original Message ----
From: Hakki Dogusan <dogusanh at tr.net>
To: cairo at cairographics.org
Sent: Saturday, January 26, 2008 1:48:35 PM
Subject: Re: [cairo] Cairo + Win32 GDI + wxWidgets?

Hi,

(Code modified inline)

Sean Dunn yazmış:
> Hi all,
> 
>  
> 
> I just started using wxWidgets with Cairo. My target platform right now 
> is Win32. I'm pretty new to wxWidgets, Cairo, and GDI, and I'm madly 
> trying to grok it all.
> 
>  
> 
> I'm having trouble getting the following code to show anything, and I'm 
> not sure what's wrong. It's supposed to create a Cairo surface based on 
> the win32 surface, draw to it, and then bitblt it back to my window (a 
> combination of gradients that cover the surface). Nothing shows up, 
> though. This sample is based on the Docview wxWidgets sample, and the 
> Gradient Cairo sample.
> 
>  
> 
> I'm looking for pointers and perhaps any online resources that discuss 
> using Cairo/Win32GDI/wxWidgets all at once (it doesn't seem to be a 
> popular combination, most seem to be using GTK/Cairo). Also, what is the 
> most efficient manner for drawing to GDI surfaces? In this case, I'm 
> doing a bitblt of a buffer.. But is there a way to draw directly with 
> double buffering?
> 
>  
> 

cairo_t* CreateContext(wxDC* dc)
{
#ifdef __WXMSW__
//#if CAIRO_HAS_WIN32_SURFACE
    HDC hdc = (HDC)dc->GetHDC();
    cairo_t *cr = cairo_create(cairo_win32_surface_create( hdc ));
    return cr;
#endif

#ifdef __WXGTK__
//#ifdef GDK_WINDOWING_X11
    GdkDrawable *drawable = dc->m_window;
    cairo_t *cr = gdk_cairo_create( drawable ) ;
    return cr;
#endif

    return NULL;
}


> void MyView::OnDraw(wxDC *dc)
> {

/*******************************************************************

>      // wxFrame* m_frame
>      HWND hWnd = (HWND)m_frame->GetHWND();
> 
>      PAINTSTRUCT ps;
>      HDC hDc = BeginPaint(hWnd, &ps);
>      RECT rc;
>      BOOL succ = GetClientRect(hWnd, &rc);
> 
>      long width = rc.right - rc.left;
>      long height = rc.bottom - rc.top;
>      long x = rc.left;
>      long y = rc.top;
> 
>      HDC hBuffer = CreateCompatibleDC(hDc);
>      HBITMAP hBitmap = CreateCompatibleBitmap(hDc,width,height);
>      HGDIOBJ hOldBitmap = SelectObject(hBuffer, hBitmap);
> 
>  
> 
>      //cairo
> 
>      cairo_surface_t* surf = cairo_win32_surface_create(hBuffer);
>      cairo_t* ctx = cairo_create(surf);

*******************************************************************/

    wxCoord x = 0, y = 0;
    wxCoord width, height;
    dc.GetSize(&width, &height);

    cairo_t* ctx = CreateContext(dc);
    if (ctx == NULL) return;

> 
>      cairo_pattern_t *pat;
> 
>      pat = cairo_pattern_create_linear (0.0, 0.0,  0.0, (double)height);
>      cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
>      cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
>      cairo_rectangle (ctx, 0, 0, (double)width, (double)height);
>      cairo_set_source (ctx, pat);
>      cairo_fill (ctx);
>      cairo_pattern_destroy (pat);
> 
>      pat = cairo_pattern_create_radial (115.2, 102.4, 25.6,
>                102.4,  102.4, 128.0);
>      cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
>      cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
>      cairo_set_source (ctx, pat);
>      cairo_arc (ctx, 128.0, 128.0, 76.8, 0, 2 * M_PI);
>      cairo_fill (ctx);
>      cairo_pattern_destroy (pat);
> 

/******************************************************************
>      cairo_surface_finish(surf);
> 
>  
> 
>      BitBlt(hDc, 0, 0, width,  height, hBuffer, x, y, SRCCOPY);
> 
>      SelectObject( hBuffer, hOldBitmap );
>      DeleteObject( hBitmap );
>      DeleteDC( hBuffer );
> 
>      EndPaint(hWnd, &ps);      
*******************************************************************/
    cairo_destroy (ctx);

> }
> 
>  
> 
> Any help is appreciated..!
> 
>  
> 
> Thank you,
> Sean
> 
>  

--
Regards,
Hakki Dogusan

_______________________________________________
cairo mailing list
cairo at cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080127/7dca0fab/attachment.htm 


More information about the cairo mailing list