A belated thanks for this. It works nicely and I am able to use it as a starting point for my project. > > > > I'm interested in having a cairo window as a member of a=20 > > group. the cairo example in the test directory has the cairo=20 > > window as the main window. Since the constructor has only=20 > > width and height arguments, i don't see a way to put it in a group. > >=20 > >=20 > > To be honest, when I want a cairo "subwindow" I don't=20 > > generally use the "native" fltk cairo hooks - they were added=20 > > after a lot of my codebase was written, so I have a heap of=20 > > code that already did it differently anyway... > > Coffe-break, so here's a simple demo of this approach, in the hope that > it may be useful... > > > ------------------- > /* > * Demo of a simple cairo_box in a (nested) group > */ > #include <FL/Fl.H> > #include <FL/Fl_Group.H> > #include <FL/Fl_Double_Window.H> > #include <FL/Fl_Box.H> > #include <FL/x.H> > #include <FL/fl_draw.H> > #include <FL/Fl_Button.H> > > #include <cairo.h> > > #ifdef WIN32 > # include <cairo-win32.h> > #elif defined (__APPLE__) > # include <cairo-quartz.h> > #else > # include <cairo-xlib.h> > #endif > > Fl_Double_Window *main_win=3D(Fl_Double_Window *)0; > Fl_Group *outer_group=3D(Fl_Group *)0; > Fl_Group *inner_grp1=3D(Fl_Group *)0; > Fl_Group *inner_grp2=3D(Fl_Group *)0; > Fl_Group *inner_grp3=3D(Fl_Group *)0; > > /*************************************************************/ > class cairo_box : public Fl_Box { > void draw(void); // draw method > cairo_surface_t *surface; > cairo_t *cairo_context; > float rr, gg, bb, aa; > void set_cairo_cxt(int wo, int ho); > public: > // constructor > cairo_box(int x, int y, int w, int h) : Fl_Box(x,y,w,h) { > surface =3D NULL; cairo_context =3D NULL; > rr =3D gg =3D bb =3D aa =3D 0.0;} > > void set_rgb(float RR, float GG, float BB, float AA) > {rr =3D RR; gg =3D GG; bb =3D BB; aa =3D AA;} > }; > /*************************************************************/ > void cairo_box::set_cairo_cxt(int wo, int ho) { > #ifdef WIN32 > #warning win32 mode > /* Get a Cairo surface for the current DC */ > HDC dc =3D fl_gc; /* Exported by fltk */ > surface =3D cairo_win32_surface_create(dc); > #elif defined (__APPLE__) > #warning Apple Quartz mode > /* Get a Cairo surface for the current CG context */ > CGContext *ctx =3D fl_gc; > surface =3D cairo_quartz_surface_create_for_cg_context(ctx, wo, > ho); > #else > #warning X windows mode > /* Get a Cairo surface for the current display */ > surface =3D cairo_xlib_surface_create(fl_display, fl_window, > fl_visual->visual, wo, ho); > #endif > /* Store the cairo context */ > cairo_context =3D cairo_create(surface); > > /* All Cairo co-ordinates are shifted by 0.5 pixels to correct > anti-aliasing */ > cairo_translate(cairo_context, 0.5, 0.5); > } > /*************************************************************/ > void cairo_box::draw(void) { > int xo =3D x(); // origin is current window position for Fl_Box > int yo =3D y(); > int wo =3D w(); > int ho =3D h(); > > /* draw the base widget */ > fl_push_no_clip(); /* remove any clipping region set by the > expose events... */ > fl_push_clip(xo, yo, wo, ho); /* reset local clipping */ > > fl_color(FL_CYAN); > fl_rectf(xo, yo, wo, ho); > // set cairo context > set_cairo_cxt(wo, ho); > // draw a triangle pointing upwards > int x1, y1, x2, y2, x3, y3; > x1 =3D xo + wo/2; y1 =3D yo; > x2 =3D xo + wo; y2 =3D yo + ho; > x3 =3D xo; y3 =3D y2; > cairo_set_source_rgba(cairo_context, rr, gg, bb, aa); > 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); > // release the cairo context > cairo_destroy(cairo_context); > cairo_surface_destroy(surface); > cairo_context =3D NULL; > > fl_pop_clip(); // remove the local clip region > fl_pop_clip(); // remove the "no_clip" region > } // draw method > > /*************************************************************/ > cairo_box *cairo1=3D(cairo_box *)0; > cairo_box *cairo2=3D(cairo_box *)0; > cairo_box *cairo3=3D(cairo_box *)0; > /*************************************************************/ > static void cb_Quit(Fl_Button*, void*) { > main_win->hide(); > } > > /*************************************************************/ > int main(int argc, char **argv) { > main_win =3D new Fl_Double_Window(500, 500); > main_win->begin(); > > Fl_Button* o =3D new Fl_Button(430, 460, 60, 30, "Quit"); > o->box(FL_THIN_UP_BOX); > o->callback((Fl_Callback*)cb_Quit); > > outer_group =3D new Fl_Group(5, 5, 490, 450); > outer_group->begin(); > > inner_grp1 =3D new Fl_Group(5, 5, 160, 450); > inner_grp1->begin(); > cairo1 =3D new cairo_box(7, 7, 156, 446); > cairo1->box(FL_FLAT_BOX); > cairo1->set_rgb(1.0,0,0,0.7); > inner_grp1->end(); > inner_grp1->box(FL_DOWN_BOX); > > inner_grp2 =3D new Fl_Group(165, 5, 160, 450); > inner_grp2->begin(); > cairo2 =3D new cairo_box(167, 7, 156, 446); > cairo2->box(FL_FLAT_BOX); > cairo2->set_rgb(0,1.0,0,0.9); > inner_grp2->end(); > inner_grp2->box(FL_DOWN_BOX); > > inner_grp3 =3D new Fl_Group(325, 5, 170, 450); > inner_grp3->begin(); > cairo3 =3D new cairo_box(327, 7, 166, 446); > cairo3->box(FL_FLAT_BOX); > cairo3->set_rgb(0,0,1.0, 0.3); > inner_grp3->end(); > inner_grp3->box(FL_DOWN_BOX); > > outer_group->end(); > // outer_group->resizable(inner_grp2); > > main_win->end(); > main_win->resizable(cairo1); > main_win->label("Cairo Box Test"); > main_win->show(argc, argv); > > return Fl::run(); > } > /* end of file */ > > > > > SELEX Galileo Ltd > Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS= > 14 3EL > A company registered in England & Wales. Company no. 02426132 > ******************************************************************** > This email and any attachments are confidential to the intended > recipient and may also be privileged. If you are not the intended > recipient please delete it from your system and notify the sender. > You should not copy it or use it for any purpose nor disclose or > distribute its contents to any other person. > ******************************************************************** >
_______________________________________________ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk