On 31 Oct 2011, at 21:33, David Allen wrote:

> I'm interested in having a cairo window as a member of a group. the cairo 
> example in the test directory has the cairo window as the main window. Since 
> the constructor has only width and height arguments, i don't see a way to put 
> it in a group.


To be honest, when I want a cairo "subwindow" I don't generally use the 
"native" fltk cairo hooks - they were added after a lot of my codebase was 
written, so I have a heap of code that already did it differently anyway...

So, what I do is derive my own widget from Fl_Box, then in the draw() method of 
that box, I do something like (paraphrasing wildly...)

At the top of the draw method, make sure I have a valid cairo surface and 
context to draw into, something like...

#ifdef WIN32
        /* Get a Cairo surface for the current DC */
        HDC dc = fl_gc;         /* Exported by fltk */
        surface = cairo_win32_surface_create(dc);
#else
#  ifdef __APPLE__
#    ifdef __APPLE_QUARTZ__
        /* Get a Cairo surface for the current CG context */
        CGContext *ctx = (CGContext *)fl_gc;
        surface = cairo_quartz_surface_create_for_cg_context(ctx, (int)w, 
(int)h);
#    else
       /* Fatal compile time error */
#      error Apple quartz platform not defined
#    endif
#  else
        /* Get a Cairo surface for the current display */
        surface = cairo_xlib_surface_create(fl_display, fl_window, 
fl_visual->visual, (int)w, (int)h);
#  endif
#endif
        /* Store the cairo context */
        cairo_context = cairo_create(context->surface);

        /* All Cairo co-ordinates are shifted by 0.5 pixels for anti-aliasing */
#ifndef __APPLE__ // Apple Quartz does not need the offset nudge
        cairo_translate(cairo_context, 0.5, 0.5);
#endif



And at that point I have a usable cairo state I can draw into... "normal" cairo 
drawing follows...

Then I dispose of the context like...

        /* Destroy the Cairo surface */
        cairo_destroy(cairo_context);
        cairo_surface_destroy(surface);

And that pretty much seems to work.

Since the widget derives from Fl_Box, embedding it into an Fl_Group is 
straightforward...

Any use?

HTH,
-- 
Ian



_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to