FLTK logo

[fltk.general] How to draw an "X" in cairo

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

How to draw an "X" in cairo Greg Ercolano Dec 31, 2021  
  Trying to just draw a simple "X" to all four corners of the Fl_Cairo_Window.
Having trouble getting this working.

My understanding is the default coordinate space of cairo is:

    (0.0, 0.0) = top/left
    (1.0, 1.0) = bottom/right

..and to use FLTK's coordinate space, you'd use cairo_scale(cr, w(), h())
to convert to the window's integer coordinate space.

Here's what I have (it doesn't work - weird behavior).
Am I missing something?


#include <FL/Fl.H>
#include <FL/Fl_Cairo_Window.H>

static void my_cairo_draw_cb(Fl_Cairo_Window *window, cairo_t *cr) {
    const double xmax = (window->w() - 1);
    const double ymax = (window->h() - 1);

    // Draw green "X"
    //     Draw an X to four corners of resizable window.
    //
    cairo_scale(cr, window->w(), window->h());                    // use FLTK's coordinate space 0,0,w(),h()
    cairo_set_line_width(cr, 0.01);                               // line width for drawing
    cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);                      // green
    cairo_move_to(cr, 0.0, 0.0);  cairo_line_to(cr, xmax, ymax);  // draw diagonal "\" in fltk coord space
    cairo_move_to(cr, 0.0, ymax); cairo_line_to(cr, xmax, 0.0);   // draw diagonal "/" in fltk coord space
    cairo_stroke(cr);                                             // stroke the lines
}

int main(int argc, char **argv) {
  Fl_Cairo_Window window(300, 300, "Cairo Draw 'X'");
  window.color(FL_BLACK);
  window.resizable(&window);
  window.set_draw_cb(my_cairo_draw_cb);
  window.show(argc, argv);
  return Fl::run();
}


    

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/920bf31c-bbba-438b-cf58-12fa95548c3b%40seriss.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.