• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX [c++] for-loop to generate strings?

Vitus

Resource contributor
Messages
1,480
Country
newzealand
Hi,

I am currently working on a gauge that contains a lot of dynamic text. I found that programming it using STRING macros is extremely tedious and I was wondering if there's a way to automate it. So, instead of manually typing three dozens of STRING macros, is it possible to have a for-loop generate the gauge elements?
 
Don't use gauge macros period. Use the GDI+ example instead.
 
Even the GDI+ example uses a gauge macro... just sayin'... though I agree that a GDI+ approach would support his needs the best.
 
The straight answer to your question is no, you can't do that.
 
Hi guys,
Thank you all for chiming in! It took me the whole day, but I switched to a GDI+ scheme. It seems to work so far - I can create multiple lines of text using for-loops. Fun!

Generally speaking, what's the advantage of using GDI+ over a pure macro-based gauge?
 
I see.
I always had trouble with transparency using the default macros. Is there a way to get a proper alpha-channel rendering done using GDI+? Similar issues with the rendering of strings - they all get a black outline where it should be semi-transparent. I currently avoid that problem by first drawing a filled-in rectangle, but I'd much rather see some proper transparency.
 
Another thing I noticed is that my fonts are not used any more. With XML strings as well as with the normal string macros, I was able to use custom fonts that are copied to the <sim>/Fonts folder. Using GDI+, those fonts don't seem to work. I initialize the font with this:
Code:
    mMachineFont = new Font(L"Veteran Typewriter", 24.0f, FontStyleRegular, UnitPixel);
 
In GDI+ the fonts available are the ones installed in the OS, unless you have a font resource you load directly. It's far easier to install the font to the OS.
As for transparency... if you're taking about a transparent gauge... that requires a few changes (24-bit images, etc), but is possible.
 
I don't want to install the font automatically, I feel that's a bit invasive. . In the meantime, I found this:
https://docs.microsoft.com/en-us/wi...diplus-creating-a-private-font-collection-use
will have a look and see if it works. But now I've got another issue: in order to load the font, I need to locate the "font" folder of the sim. gnnnaaaa....

Transparency: for now the problem lies with the strings. They all have rugged edges, unless I draw a rectangle under them, which I'd like to avoid if at all possible. Maybe I should mention that I am drawing the C++ gauge on top of another XML gauge, I don't know if that affects the outcome.
 
I have never, in my insanely long career writing software ever heard anyone call installing a font invasive. That is indeed a first. LOL
Check out SetTextRenderingHint and SetSmoothingMode.
Overlapping gauges can have visual side effects.
 
Well... I really dislike the fact that my system fonts are filled with symbol libraries from some programs. That makes it so much harder to find what you're looking for.

Here's what I found:
Code:
std::wstring tmp_wstr = path_sim.wstring()+L"\\fonts\\veteran typewriter.ttf";
PrivateFontCollection privateFontCollection.AddFontFile(tmp_wstr.c_str());
int count = privateFontCollection.GetFamilyCount();
if (count == 0)
    debug_log("Could not load custom fonts.");

Font * mMachineFont = new Font(L"Veteran Typewriter", 18.0f, FontStyleRegular, UnitPixel, &privateFontCollection);
where path_sim is a string that holds the directory of the sim, obtained through GetModuleFileNameA().




I tried doing this:
Code:
                    mGraphics->SetTextRenderingHint(TextRenderingHintAntiAlias);
                    mGraphics->SetSmoothingMode(SmoothingModeAntiAlias);

I call those functions in the PANEL_SERVICE_PRE_DRAW before all the strings are set. Doesn't work, though. Any idea what could be wrong?
 
ezDOwQb.jpg


The background is an image loaded with an XML gauge. The text is the C++ gauge in question.
 
That looks correct. Have you reviewed the actual appearance of the font itself?
 
Not sure if this is related, but I also have an issue with the redrawing of the gauge. When I open the next page in the book, a new set of data is loaded from an SQLite database to populate the page. Currently the new data is drawn on top of the old one, without deleting it first. The MAKE_STATIC macro of the gauge has those flags set:
IMAGE_CREATE_DIBSECTION | IMAGE_USE_TRANSPARENCY | IMAGE_USE_ALPHA | IMAGE_USE_ERASE

I didn't set the IMAGE_ERASE_ALWAYS, because otherwise the underlying XML gauge gets deleted as well.
 
In comparison, here's how the font looks like when placed on a FillRectangle background:
SaWMbqF.jpg
 
Ok... before you do any rendering... always do a FillRectangle with the default background color to 'erase'. There is a GDI+ Clear() method... but it's horribly inefficient by comparison and should only be used when doing a transparent gauge.
 
Is there a way around this? I don't want to fill anything, I want the gauge to be transparent so that the underlying XML gauge can render the background image. I tried to do a FillRectangle with an alpha value of '0', hoping that the call itself would cause the panel to redraw. But noooo...

edit: I currently have a Clear() call in there as well. Doesn't help.
 
Back
Top