Board index FlightGear Development Canvas

osgText backdrop

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

osgText backdrop

Postby Gijs » Sun Jul 06, 2014 9:47 pm

Hi,

is it possible to set a backdrop outline color for Canvas text? That is done on real life displays to make overlapping text easier to read (and other geometries; but text would benefit the most). The code is there in osgText, but looking at SimGear, Canvas does not seem to support it (yet). I could try to implement it, but maybe Tom has already something in the works? Or there might be a reason why we don't use it...

Cheers,
Gijs
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9543
Joined: Tue Jul 03, 2007 3:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: osgText backdrop

Postby Philosopher » Sun Jul 06, 2014 10:50 pm

Use this: canvas.Text.setDrawMode(canvas.Text.TEXT | canvas.Text.FILLEDBOUNDINGBOX).setColorFill(0,0,0);
Philosopher
 
Posts: 1593
Joined: Sun Aug 12, 2012 7:29 pm

Re: osgText backdrop

Postby Gijs » Mon Jul 07, 2014 10:15 am

If I'm not mistaken that gives a rectangular background (the bounding box), while I'm looking for an outline that follows the shape of the text, which is what backdrop provides. Like this:

Image
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9543
Joined: Tue Jul 03, 2007 3:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: osgText backdrop

Postby Gijs » Mon Jul 07, 2014 4:19 pm

And this is how it looks in FlightGear now :-) Notice how the overlapping waypoints are easier to read (this image is a little exaggerated with all those fixes).

Image
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9543
Joined: Tue Jul 03, 2007 3:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: osgText backdrop

Postby Hooray » Mon Jul 07, 2014 4:26 pm

looking really good - but at some point we may want to revisit the whole Canvas: Label uncluttering debate, or we'll probably implement a pathetic bounding-box based scripted scheme in Nasal which will not be good for the reputation of Nasal/Canvas and the whole performance debate. :lol:

If not for the ND, we'll surely require it for the map-canvas dialog which has quite some other information to be displayed there (which we don't currently do yet)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: osgText backdrop

Postby TheTom » Mon Jul 07, 2014 4:54 pm

Sooner or later I want to add much more styling options to text. How have you realized the backdrop effect?
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: osgText backdrop

Postby Gijs » Mon Jul 07, 2014 5:29 pm

See diffs below. I didn't add the full range of backdrop options, just outline for now.
Code: Select all
commit 5cc0adc778bda1773189b0119d24fbaf5ecd4500
Author: Gijs de Rooy
Date:   Mon Jul 7 18:26:16 2014 +0200

    Canvas: add backdrop option to text

diff --git a/simgear/canvas/elements/CanvasText.cxx b/simgear/canvas/elements/CanvasText.cxx
index d99760a..3a986e1 100644
--- a/simgear/canvas/elements/CanvasText.cxx
+++ b/simgear/canvas/elements/CanvasText.cxx
@@ -39,6 +39,7 @@ namespace canvas
       void setLineHeight(float factor);
       void setFill(const std::string& fill);
       void setBackgroundColor(const std::string& fill);
+      void setOutlineColor(const std::string& backdrop);
 
       SGVec2i sizeForWidth(int w) const;
       osg::Vec2 handleHit(const osg::Vec2f& pos);
@@ -97,6 +98,15 @@ namespace canvas
   }
 
   //----------------------------------------------------------------------------
+  void Text::TextOSG::setOutlineColor(const std::string& backdrop)
+  {
+    osg::Vec4 color;
+    setBackdropType(osgText::Text::OUTLINE);
+    if( parseColor(backdrop, color) )
+      setBackdropColor( color );
+  }
+
+  //----------------------------------------------------------------------------
   // simplified version of osgText::Text::computeGlyphRepresentation() to
   // just calculate the size for a given weight. Glpyh calculations/creating
   // is not necessary for this...
@@ -546,6 +556,7 @@ namespace canvas
 
     addStyle("fill", "color", &TextOSG::setFill, text);
     addStyle("background", "color", &TextOSG::setBackgroundColor, text);
+    addStyle("backdrop", "color", &TextOSG::setOutlineColor, text);
     addStyle("character-size",
              "numeric",
              static_cast<

Code: Select all
commit 838cabd2a551834cbcac2b3edd21500409ff2e98
Author: Gijs de Rooy
Date:   Mon Jul 7 18:27:50 2014 +0200

    Canvas: add backdrop option to text

diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas
index 8bc12d8..3047dbf 100644
--- a/Nasal/canvas/api.nas
+++ b/Nasal/canvas/api.nas
@@ -634,6 +634,8 @@ var Text = {
 
   setColorFill: func me.set('background', _getColor(arg)),
   getColorFill: func me.get('background'),

+  setBackdropColor: func me.set('backdrop', _getColor(arg)),
 };
 
 # Path
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9543
Joined: Tue Jul 03, 2007 3:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: osgText backdrop

Postby Hooray » Mon Jul 07, 2014 5:52 pm

good job there, you even used Tom's styling system - we should take your code and add it to the wiki as a little tutorial !
(will do that shortly!)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: osgText backdrop

Postby TheTom » Mon Jul 07, 2014 10:56 pm

I don't think it's a good idea to add this to the wiki. It is of no use to non core developers, and for core developers it should be quite obvious from just reading the code. If not we should improve the (doxygen) comments. The wiki already contains too much outdated information and code snippets.
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: osgText backdrop

Postby Johan G » Mon Jul 07, 2014 11:15 pm

That is probably a very good point. (As is the note about comments. ;) )

Personally I prefer if the code snippets in the wiki is used for examples, though not as copy and paste samples, but rather as "illustrations" to documentation on how to use and/or implement stuff.
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6625
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: osgText backdrop

Postby Hooray » Mon Jul 07, 2014 11:20 pm

maybe, but that's only true because of TheTom, and the fact that he is now among the top 2 committers and maintaining and extending Canvas almost daily - otherwise, most FlightGear coding docs tend to be "good enough" for at least a decade, especially anything related to glass avionics :lol:

If the "Canvas Development" article contains outdated code snippets, I'll try to update those shortly - we've been getting lots of feedback in response to such articles, i.e. that particular article has seen over 9k views, and the MapStructure article is close to 20k now - and even the NavDisplay article is way beyond 5k - which still is interesting given that there are apparently more people interested in extending the Canvas system than aircraft developers who want to adopt the ND ... i.e. potential core contributors.

I could obviously just delete outdated paragraphs and remove obsolete information, but I'd rather keep things up to date there - we've been seeing only a handful of feature requests in the context of future canvas developments (and sooner or later the thing will be pretty much complete), and we should make sure that people are aware of those discussions, to avoid wasted efforts, or even just conflicting approaches. And you cannot possibly implement all these feature requests by yourself - still, some people have different priorities obviously. I've seen two guys who played with hacking viewmgr.cxx to render to a canvas, and they asked for even more information than we've got there already ... so, I'll probably extend things over time to cover at least those examples that are unlikely to make it into Canvas anytime soon. The GLSL/Effects code would be another code snippet that I could add there.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: osgText backdrop

Postby Johan G » Mon Jul 07, 2014 11:27 pm

To avoid any misunderstandings maybe I should mention that I have only read through some very few coding examples. ;) In essence my post above is my general opinion.
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6625
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: osgText backdrop

Postby Gijs » Tue Jul 08, 2014 11:13 am

@Tom: is my diff acceptable, or did I miss some implementation method? You're the expert :-)
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9543
Joined: Tue Jul 03, 2007 3:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: osgText backdrop

Postby TheTom » Tue Jul 08, 2014 12:42 pm

Looks good :-) I will add it after the feature freeze. I will probably change it a bit to match the SVG properties 'stroke' and 'stroke-width'.
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: osgText backdrop

Postby Hooray » Tue Jul 08, 2014 5:00 pm

indeed, it looks very clean and compact - which is a testimony to all the template/boost/bind machinery in the background that Tom added there to make this work - normally, doing this kind of thing would require at least 30-50 lines of boilerplate code for each exposed method, as can be seen in all the non-canvas code that's using the SGPropertyChangeListener API - this is pretty freakin' elegant in comparison and very maintainable. :D
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Next

Return to Canvas

Who is online

Users browsing this forum: No registered users and 1 guest