>> It would really help if you send us a small non working
>> example of your code :)
>
> OK :-)
>
> I'm not near a Mac right now, I'll try and put something together  
> later
> on and post it...
> It may not be all that small, given the complexity of pulling in  
> all the
> Cairo cruft and etc.!

Right, as requested, here's a "minimal" example - but still quite  
long - of my cairo window Not Working on OSX.

This code works "fine" on linux, does not work on OSX, and has not  
been tested on win32 (although I coded in the hooks so folks can see  
what I was doing.) The "real" code does work fine on win32 so this  
may also.

The base widget from which I derive my "cairo test window" can be  
either Fl_Window or Fl_Box depending on setting the WIN_BASE define  
at compile time.
On a good day, this draws a 70% alpha red triangle pointing upwards.

----------------------
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/x.H>
#include <FL/fl_draw.H>

#  include <cairo.h>
#  ifdef WIN32
#    include <cairo-win32.h>
#  elif defined (__APPLE__)
#    include <cairo-quartz.h>
#  else
#    include <cairo-xlib.h>
#  endif

#ifdef WIN_BASE
#  warning Fl_Window base
#  define BOX Fl_Window
#else
#  define BOX Fl_Box
#endif

class test_box : public BOX {
        void draw(void); // draw method
        cairo_surface_t *surface;
        cairo_t *cairo_context;
public:
        // constructor
        test_box(int x, int y, int w, int h) : BOX(x,y,w,h) { }
};

void test_box::draw(void)
{
#ifdef WIN_BASE
        int xo = 0; // origin is (0,0) for Fl_Window
        int yo = 0;
#else
        int xo = x(); // origin is current window position for Fl_Box
        int yo = y();
#endif
        int wo = w();
        int ho = h();

#ifdef WIN32
#warning win32 mode
        /* Get a Cairo surface for the current DC */
        HDC dc = fl_gc;         /* Exported by fltk */
        context->surface = cairo_win32_surface_create(dc);
#elif defined (__APPLE__)
#warning Apple Quartz mode
        /* Get a Cairo surface for the current CG context */
        CGContext *ctx = fl_gc;
        surface = cairo_quartz_surface_create_for_cg_context(ctx, wo, ho);
#else
#warning X windows mode
        /* Get a Cairo surface for the current display */
        surface = cairo_xlib_surface_create(fl_display, fl_window, fl_visual- 
 >visual, wo, ho);
#endif
        /* Store the cairo context */
        cairo_context = cairo_create(surface);

#ifdef __APPLE___
//      cairo_scale(cairo_context, 1, -1);
#endif
        /* All Cairo co-ordinates are shifted by 0.5 pixels to correct anti- 
aliasing */
        cairo_translate(cairo_context, 0.5, 0.5);

        int x1, y1, x2, y2, x3, y3;
        x1 = xo + wo/2; y1 = yo;
        x2 = xo + wo; y2 = yo + ho;
        x3 = xo; y3 = y2;

        // draw a 70% red triangle pointng upwards
        cairo_set_source_rgba(cairo_context, 1.0, 0.0, 0.0, 0.7);
        cairo_new_path(cairo_context);
        cairo_move_to(cairo_context, x1, y1);
        cairo_line_to(cairo_context, x2, y2);
        cairo_line_to(cairo_context, x3, y3);
        cairo_line_to(cairo_context, x1, y1);
        cairo_fill(cairo_context);

        cairo_destroy(cairo_context);
        cairo_surface_destroy(surface);
} // draw method

Fl_Double_Window *main_win=(Fl_Double_Window *)0;
test_box *test=(test_box *)0;

int main(int argc, char **argv) {
        main_win = new Fl_Double_Window(547, 469, "Cairo Triangle");
        main_win->end();
        main_win->resizable(main_win);
        main_win->show(argc, argv);
        Fl::check();

        main_win->begin();
        test = new test_box(25, 25, 485, 386);
        test->box(FL_FLAT_BOX);
        main_win->end();
        test->show();
        
        return Fl::run();
}
/* end of file */

----------------------


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

Reply via email to