Custom background for fltk widget

12 views
Skip to first unread message

anmol....@gmail.com

unread,
Oct 3, 2021, 10:59:34 AM10/3/21
to fltk.general
I've seen the example described by Ian - https://www.fltk.org/articles.php?L468 

However, both the methods described here replace the widget with a background image. For instance, using Fl_Text_Editor or Fl_Help_View and setting text->image() or view->image() will only render the background.

The behavior I want, is for a background image to be set for say, Fl_Help_View and then the contents of the buffer() to be rendered **on top** of the background image.

So, for instance you will have a text editor window with a custom background, and you can style type in the letters.

anmol....@gmail.com

unread,
Oct 3, 2021, 11:16:33 AM10/3/21
to fltk.general
A second reference is from Matthias' article - https://www.fltk.org/articles.php?L466+I0+T+P1+Q 

This article uses the data()[0] pointer from Fl_Image class and accesses the pipe buffer directly. This can be used to provide a background for Fl_Image derived classes.

However, for other classes - like Fl_Text_Editor and Fl_help_View this method is not useful as these are not derived from Fl_Image

Ian MacArthur

unread,
Oct 4, 2021, 6:31:38 AM10/4/21
to fltk.general
On Sunday, 3 October 2021 at 16:16:33 UTC+1 anmol.... wrote:

However, for other classes - like Fl_Text_Editor and Fl_help_View this method is not useful as these are not derived from Fl_Image

Yes... this is beyond what the "complex" fltk widgets will support. The "fast and light" ethos means these widgets don't have any way to do that really... I'm not sure about Fl_Help_View, but for Fl_Text_Editor, you'd basically have to derive your own class, then implement the ::draw and ::draw_*** methods yourself (copying the draw_*** code from Fl_Text_Display) and create a suitable background surface that way.
But even that would be a lot of work - there are several ::draw_*** methods involved, several of which will overwrite the background (text strings in the fltk text editor have both foreground and background attributes) so it would be hard to make that work out well, I suspect.

I'd speculate that, if you need that sort of visual effect, one of the more elaborate GUI toolkits might be your better choice, TBH, as they may have that ability already.

Reply all
Reply to author
Forward
0 new messages