<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><DIV>Hakki,</DIV>
<DIV> </DIV>
<DIV>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. :)</DIV>
<DIV> </DIV>
<DIV>Sean<BR> </DIV>--
<DIV style="FONT-SIZE: 10pt; FONT-FAMILY: arial, helvetica, sans-serif"><BR><BR>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">----- Original Message ----<BR>From: Hakki Dogusan <dogusanh@tr.net><BR>To: cairo@cairographics.org<BR>Sent: Saturday, January 26, 2008 1:48:35 PM<BR>Subject: Re: [cairo] Cairo + Win32 GDI + wxWidgets?<BR><BR>Hi,<BR><BR>(Code modified inline)<BR><BR>Sean Dunn yazmış:<BR>> Hi all,<BR>> <BR>> <BR>> <BR>> I just started using wxWidgets with Cairo. My target platform right now <BR>> is Win32. I'm pretty new to wxWidgets, Cairo, and GDI, and I'm madly <BR>> trying to grok it all.<BR>> <BR>> <BR>> <BR>> I'm having trouble getting the following code to show anything, and I'm <BR>> not sure what's wrong. It's supposed to create a Cairo surface based on <BR>> the win32 surface, draw to it, and then bitblt it back to my window (a <BR>> combination of gradients that cover the surface). Nothing shows up, <BR>> though.
This sample is based on the Docview wxWidgets sample, and the <BR>> Gradient Cairo sample.<BR>> <BR>> <BR>> <BR>> I'm looking for pointers and perhaps any online resources that discuss <BR>> using Cairo/Win32GDI/wxWidgets all at once (it doesn't seem to be a <BR>> popular combination, most seem to be using GTK/Cairo). Also, what is the <BR>> most efficient manner for drawing to GDI surfaces? In this case, I'm <BR>> doing a bitblt of a buffer.. But is there a way to draw directly with <BR>> double buffering?<BR>> <BR>> <BR>> <BR><BR>cairo_t* CreateContext(wxDC* dc)<BR>{<BR>#ifdef __WXMSW__<BR>//#if CAIRO_HAS_WIN32_SURFACE<BR> HDC hdc = (HDC)dc->GetHDC();<BR> cairo_t *cr = cairo_create(cairo_win32_surface_create( hdc ));<BR> return cr;<BR>#endif<BR><BR>#ifdef __WXGTK__<BR>//#ifdef GDK_WINDOWING_X11<BR> GdkDrawable *drawable =
dc->m_window;<BR> cairo_t *cr = gdk_cairo_create( drawable ) ;<BR> return cr;<BR>#endif<BR><BR> return NULL;<BR>}<BR><BR><BR>> void MyView::OnDraw(wxDC *dc)<BR>> {<BR><BR>/*******************************************************************<BR><BR>> // wxFrame* m_frame<BR>> HWND hWnd = (HWND)m_frame->GetHWND();<BR>> <BR>> PAINTSTRUCT ps;<BR>> HDC hDc = BeginPaint(hWnd, &ps);<BR>> RECT rc;<BR>> BOOL succ = GetClientRect(hWnd, &rc);<BR>> <BR>> long width = rc.right - rc.left;<BR>> long height = rc.bottom - rc.top;<BR>> long x = rc.left;<BR>> long y = rc.top;<BR>> <BR>> HDC hBuffer = CreateCompatibleDC(hDc);<BR>>
HBITMAP hBitmap = CreateCompatibleBitmap(hDc,width,height);<BR>> HGDIOBJ hOldBitmap = SelectObject(hBuffer, hBitmap);<BR>> <BR>> <BR>> <BR>> //cairo<BR>> <BR>> cairo_surface_t* surf = cairo_win32_surface_create(hBuffer);<BR>> cairo_t* ctx = cairo_create(surf);<BR><BR>*******************************************************************/<BR><BR> wxCoord x = 0, y = 0;<BR> wxCoord width, height;<BR> dc.GetSize(&width, &height);<BR><BR> cairo_t* ctx = CreateContext(dc);<BR> if (ctx == NULL) return;<BR><BR>> <BR>> cairo_pattern_t *pat;<BR>> <BR>> pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, (double)height);<BR>> cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0,
1);<BR>> cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);<BR>> cairo_rectangle (ctx, 0, 0, (double)width, (double)height);<BR>> cairo_set_source (ctx, pat);<BR>> cairo_fill (ctx);<BR>> cairo_pattern_destroy (pat);<BR>> <BR>> pat = cairo_pattern_create_radial (115.2, 102.4, 25.6,<BR>> 102.4, 102.4, 128.0);<BR>> cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);<BR>> cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);<BR>> cairo_set_source (ctx, pat);<BR>> cairo_arc (ctx, 128.0, 128.0, 76.8, 0, 2 * M_PI);<BR>> cairo_fill (ctx);<BR>> cairo_pattern_destroy (pat);<BR>>
<BR><BR>/******************************************************************<BR>> cairo_surface_finish(surf);<BR>> <BR>> <BR>> <BR>> BitBlt(hDc, 0, 0, width, height, hBuffer, x, y, SRCCOPY);<BR>> <BR>> SelectObject( hBuffer, hOldBitmap );<BR>> DeleteObject( hBitmap );<BR>> DeleteDC( hBuffer );<BR>> <BR>> EndPaint(hWnd, &ps); <BR>*******************************************************************/<BR> cairo_destroy (ctx);<BR><BR>> }<BR>> <BR>> <BR>> <BR>> Any help is appreciated..!<BR>> <BR>> <BR>> <BR>> Thank you,<BR>> Sean<BR>> <BR>> <BR><BR>--<BR>Regards,<BR>Hakki Dogusan<BR><BR>_______________________________________________<BR>cairo mailing list<BR><A href="mailto:cairo@cairographics.org"
ymailto="mailto:cairo@cairographics.org">cairo@cairographics.org</A><BR><A href="http://lists.cairographics.org/mailman/listinfo/cairo" target=_blank>http://lists.cairographics.org/mailman/listinfo/cairo</A></DIV><BR></DIV></div></body></html>