Okay, I am back with the results of my latest attempts. The solutions that have been proposed before are mainly:
1 - Specify a color with alpha and draw it (need GL support?)
Schlosser mentioned that
> A new method can be seen in test/cube.cxx which draws a semi-transparent
> widget over an OpenGL scene. This is work in progress, and I don't know
> if you can utilize the underlying method (already) for normal widget
> (rectangle) drawing.
It works even on a normal overlay, with OpenGL support enabled, at least on X11 and Wayland. I have not yet figured out why it still works without an Fl_GL_Window, but... it does seem to. I wrote a short demo in Rust to show that:
```
let app = app::App::default();
let mut overlay_window = OverlayWindow::new(0, 0, 400, 300, "Overlay Window");
overlay_window.draw_overlay(move |_| {
// This callback is to override the draw_overlay() for overlay_window.
set_color_with_alpha(Color::Free, 0, 255, 0, 127);
draw_rect_fill(0, 0, 200, 200, Color::Free);
set_color_with_alpha(Color::Free, 255, 0, 0, 127);
draw_rect_fill(100,100, 200, 200, Color::Free);
});
overlay_window.end();
overlay_window.show();
overlay_window.redraw_overlay();
app.run().unwrap();
```
This is quite flat and straightforward so I suppose it is not difficult to translate it into the corresponding C codes ;)
2 - Draw with the underlying Cairo context and primitives
Because Mo has implemented advanced Cairo interface for fltk-rs bindings (thank you!), it is possible to do this now. See
this issue for an example to draw some semi-transparent rectangles.
However, in my particular situation (i.e. drawing shapes onto the overlay of an OverlayWindow), since Fl_X11_Window_Driver only sets the current Cairo context when flush_double()... (at drivers/X11/Fl_X11_Window_Driver.cxx, line 176-179):
```
((Fl_X11_Cairo_Graphics_Driver*)fl_graphics_driver)->set_cairo(cairo_);
// ...
# if defined(FLTK_HAVE_CAIROEXT)
if (Fl::cairo_autolink_context()) Fl::cairo_make_current(pWindow);
# endif
draw();
```
... but not when flush_overlay()... (at drivers/X11/Fl_X11_Window_Driver.cxx, line 203-205):
```
((Fl_X11_Cairo_Graphics_Driver*)fl_graphics_driver)->set_cairo(overlay_cairo);
// ...
pWindow->as_overlay_window()->draw_overlay();
```
... so in the draw_overlay() callback, Fl::cairo_cc() will always return the old context, and thus will not draw anything actually. In this case, fl_cairo_gc() exported by X11.H has to be used to get an effective context. I would like to know if this is an intentional behavior or an oversight?
> Are you creating your own text handling widgets or are you using the Fl_Text_Editor et al for this?
I am creating my own widgets without using any text widget provided by FLTK (e.g. Fl_Text_Editor, Fl_Multiline_Input, etc.), because I expect the editor to handle different types of text blocks (plain text, images, code blocks, videos, etc.) and the built-in widgets are obviously too basic for this task. I just use drawing primitives like draw_text(), draw_image() to create new widget and handle events on my own.
> Though you do need to watch out: for example for the box or frame
types - for technical reasons in the porting, Mo has used the name
"Frame-types" in the fltk-rs port to refer to what we would call
"box-types" in the C++ FLTK code. In C++ FLTK, the "frame-types" are a
different (albeit related) thing.
> For example, if you use
"frame-types" in the C++ code it can produce very strange rendering
artefacts, so the "fltk-rs" <-> "fltk" code is not a 1-1 mapping
when setting up widget properties as a result.
> There are a number of things like that to be aware of...
I will keep an eye for those. Thanks for the reminder.