Board index FlightGear Development Canvas

Canvas/OSG(::)Text Capabilities

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.

Canvas/OSG(::)Text Capabilities

Postby Philosopher » Sun Feb 23, 2014 4:01 pm

Hey, regarding Text capabilities, I'm wondering what/if/how we can do these things (I want them for my REPL interpreter, possibly a custom class to manage text for my widget, since the code is a mess right now):
  • position a cursor accurately anywhere on the text - i.e. so it can move left/right with arrows.
  • make a path to show selected text, like one of the original demonstrations.
  • split lines of text up into several elements (for efficiency on the Nasal side). My current prototype has some hacks to prepend newlines but it destroys elements with more than one line, and I don't particularly want to use the bounding box to detect if it's more than one line.
  • color characters within a single text element, or split up the element yet still have proper kerning/spacing...?
  • and a monospace font - open-source Inconsolata should do, but there wasn't a nice one included already from what I saw (7-segment doesn't cut it ;)).

I might think of other things, but these come to mind now. I'll add answers to the wiki article so that they don't get lost!
Thanks,
Philosopher
(inactive but lurking occasionally...)
Philosopher
 
Posts: 1590
Joined: Sun Aug 12, 2012 6:29 pm
Location: Stuck in my head...
Callsign: AFTI
Version: Git
OS: Mac OS X 10.7.5

Re: Canvas/OSG(::)Text Capabilities

Postby Hooray » Sun Feb 23, 2014 4:49 pm

Regarding mouse selection, check out tom's fgdata clone, it's all there (including scrollbars) - I think inside menubar.xml IIRC

I am not sure if keyboard support can be considered "complete" already, but I noticed that there were some issues with keyboard handling in the REPL.

color characters within a single text element, or split up the element yet still have proper kerning/spacing...?


Actually, osgText was the very first "element" supported by the Canvas system, so we played around with it quite a bit - back then, we were even talking about supporting simple syntax highlighting funnily ... The thing is, osg::Text is not really designed for that - if I remember correctly, Tom even had to sub-class it and extend osg::Text to support some things done in FG now for the selection/copy&paste demo

Normally, a canvas-element is property-driven - so we would have a single property that determines the "state" of the element, splitting things up for efficiency reasons would be sensible, but doesn't align too well with the property tree interface we've established currently.

So we would need to introduce some form of "pseudo element" in order to have a pre-processing stage that turns a single text property into tokens and matching canvas/osgText nodes, because each token may have a different style/color/size - Tom's styling support in Canvas::Element could actually be extended to support that, so that a handful of default styles could be applied to each token/glyph.

Without touching any C++ code, I would probably add a single top-level group and then pre-allocate ~100-200 placeholders for tokens under that group, and then parse the input stream (a non canvas property/source, i.e. via io.readfile() ) and assign a matching canvas/text node to each, basically building a parse tree within the property tree.

To see what's supported, check out the osgText APIs: http://trac.openscenegraph.org/document ... 00871.html

But this could become complex very soon, so if this is something that we want to explore, it may be easier to look for a standalone/zero-dependencies parsing/syntax highlighting library and integrate that with Canvas::Text/osgText: http://colorer.sourceforge.net/


Right, it's a good idea to add stuff to the wiki, this isn't something that's going to be supported too soon, but some of these ideas are definitely interesting.
Having basic text editing support with syntax highlighting would be kinda cool - also for all those XML files and GLSL files.
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: 11968
Joined: Tue Mar 25, 2008 8:40 am

Re: Canvas/OSG(::)Text Capabilities

Postby Johan G » Mon Feb 24, 2014 7:38 am

As for fonts I had a look around in the directories of 3.0.0 the other day and found data/Fonts/LiberationFonts. In particular have a look at LiberationMono-Regular.ttf, which so far looks very nice if you ask me.
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)
Johan G
Moderator
 
Posts: 6021
Joined: Fri Aug 06, 2010 5:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.2
OS: Windows 10, 64 bit

Re: Canvas/OSG(::)Text Capabilities

Postby Philosopher » Sat Mar 01, 2014 12:23 pm

Lol, I checked out Tom's canvas branch, merged it with master, and discovered that the code is incompatible. First of all, there evidently was no such thing as "addEventListener", so it was instead using property listeners on special nodes (which do not exist anymore :lol:), and secondly, it does look like there's a few extra properties exposed to control the cursor and such: canvas::Text.getNode("cursor-x" or "cursor-y"). Unfortunately I wasn't able to find any source changes in his flghtgear clone, so I don't know what to do. But it does look like there was support for cursor and highlighting text, which would be very nice to have.

P.S. Thanks Johan, I'm using the mono spaced bold currently (and even the italic IIRC). I adjusted the aspect ratio to 1.5 (aka narrower) because it looks a little nicer and Canvas allows it ;).
Thanks,
Philosopher
(inactive but lurking occasionally...)
Philosopher
 
Posts: 1590
Joined: Sun Aug 12, 2012 6:29 pm
Location: Stuck in my head...
Callsign: AFTI
Version: Git
OS: Mac OS X 10.7.5

Re: Canvas/OSG(::)Text Capabilities

Postby ludomotico » Sat Mar 01, 2014 1:03 pm

Regarding to OSG::Text and LiberationSans, I'm having trouble with them since two weeks ago. More or less since FlightGear moved to OpenSceneGraph 3.2

After loading some aircrafts (ufo, 777...), I got a message "canvas::Text: Failed to open font file /opt/fgdata/Fonts/LiberationFonts/LiberationSans-Bold.ttf". Apparently, they have no impact on the aircraft and everything works as expected. The only exception is the "extra 500" ( viewtopic.php?f=71&t=22183 ): literally hundreds of these messages appear, and the instruments do not show anything.

Am I missing some library? I'm using the last git version and OpenSceneGraph 3.2. libosgText is present in my system. None of the fgfs components (OpenSceneGraph, Simgear, FlightGear) seems to report a missing library after a cmake and all of them are built flawlessly. The font file is present in the filesystem, and can be loaded with a ttf font viewer.
User avatar
ludomotico
 
Posts: 1130
Joined: Tue Apr 24, 2012 1:01 pm
Version: nightly
OS: Windows 10

Re: Canvas/OSG(::)Text Capabilities

Postby Hooray » Sat Mar 01, 2014 10:35 pm

seems to be a dependency problem that shows up under some circumstances according to google: http://forums.openmandriva.org/en/discu ... age-broken
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: 11968
Joined: Tue Mar 25, 2008 8:40 am


Return to Canvas

Who is online

Users browsing this forum: No registered users and 1 guest