On 4/6/25 6:15 PM, david allen wrote:
I am trying to use Fl_Cairo_Window as a popup window. The attached zip is a cmake project that is designed to create an executable draw-x and an executable popup. draw-x is from the examples directory of the fltk distribution and works perfectly. popup fails to compile, giving the message
```
/home/david/test-cairo-window/src/popup/CairoWindow.cpp:36:28:
error: expected primary-expression before ‘)’ token
36 | set_draw_cb(cairo_draw_cb);
| ^
```
I am at a loss as to what to do.
I changed two things to get it to build:
1) Changed the name of the callback "cairo_draw_cb"
to "my_cairo_draw_cb"
2) Changed the CairoWindow *window to Fl_Cairo_Window
*window in the callback signature
Regarding #1, I think "cairo_draw_cb" was colliding
with the internals, so I used a more unique name.
Regarding #2, the Fl_Cairo_Window::set_draw_cb()
method wants that first arg to be an Fl_Cairo_Window*, not
a CairoWindow*.
If you want access to your CairoWindow, you might want to
maintain a pointer to it as "user data".
I also removed the prototype declaration for the static
callback from CairoWindow.h just to keep things simple, but you
can leave it in if you update the prototype as described above.
In patch format, the changes are as follows, note the
red/green changes in bold:
--- old/CairoWindow.cpp 2025-04-06 17:11:46.000000000
-0700
+++ new/CairoWindow.cpp 2025-04-06 21:56:22.419461819 -0700
@@ -5,7 +5,7 @@
// Cairo rendering cb called during Fl_Cairo_Window::draw()
// static void cairo_draw_cb(Fl_Cairo_Window *window, cairo_t
*cr)
-static void cairo_draw_cb(CairoWindow *window, cairo_t *cr)
+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);
@@ -33,7 +33,7 @@
{
resizable();
size_range(50,50,-1,-1); // allow resize 50,50 and up
- set_draw_cb(cairo_draw_cb);
+ set_draw_cb(my_cairo_draw_cb);
show();
color(FL_WHITE);
}
--- old/CairoWindow.h 2025-04-06 17:11:46.000000000
-0700
+++ new/CairoWindow.h 2025-04-06 21:58:53.091060862 -0700
@@ -7,6 +7,3 @@
public:
CairoWindow(int w, int h, const char* title = 0);
};
-
-static void cairo_draw_cb(CairoWindow *window, cairo_t *cr);
-