Advertisement

use class

Started by January 09, 2018 08:37 AM
7 comments, last by NubDevice 6 years, 8 months ago

Hi

I want to use:

https://github.com/PhilippMuenzel/PPL/blob/master/src/fontmgr.h

but don't know how to get a FontHandle.

For now I do in appinitialization:

using namespace MichaelNS;
FontMgr m;
m.loadFont("./Ubuntu-B.ttf", NULL, NULL, 16, 0);

 

then later how to show a text?

I need to replace this:

    /* Finally we draw the text into the window, also using XPLMGraphics
     * routines.  The NULL indicates no word wrapping. */
    XPLMDrawString(color, left + 5, top - 20,
        (char*)(gClicked ? "I'm a plugin" : "Hello world"), NULL, xplmFont_Basic);

with something alike:

m.drawString(howtogetthis, #ffffff, 100, 100, align, Hello World);

Many thanks in advance and regards

 

19 minutes ago, mike44 said:

but don't know how to get a FontHandle

 

By just reading the file you have as a link ? Line 144.

Advertisement

Yes, thanks. Now with:

typedef struct FontInfo_t* FontHandle;
MichaelNS::FontMgr m;

initfunction:

m.loadFont("./Ubuntu-B.ttf", NULL, NULL, 16, 0);

drawfunction:

MichaelNS::FontHandle = m.drawString(FontInfo_t, color, 1600, 660, 1, "FPLN\n");

 

I get:

main.cpp:3841:25: error: expected unqualified-id before ‘=’ token

Many thanks again.

 

 

2 hours ago, mike44 said:

MichaelNS::FontHandle = m.drawString(FontInfo_t, color, 1600, 660, 1, "FPLN\n");

You're trying to assing something to the class-type "FontHandle".


MichaelNS::FontHandle handle = m.drawString(FontInfo_t, color, 1600, 660, 1, "FPLN\n");

 

2 hours ago, mike44 said:

typedef struct FontInfo_t* FontHandle;
MichaelNS::FontMgr m;

initfunction:

m.loadFont("./Ubuntu-B.ttf", NULL, NULL, 16, 0);

drawfunction:

MichaelNS::FontHandle = m.drawString(FontInfo_t, color, 1600, 660, 1, "FPLN\n");

You don't feel really comfortable with this programming language. I would like to suggest you taking some lessons before moving on.  This will definitely be a win-win.

with this:

m.drawString(FontInfo_t, color, 1600, 660, 1, "FPLN\n");

I get:

error: expected primary-expression before ‘,’ token

classes sure I need to look into...

Thanks

 

Advertisement

Unexpected tokens like that often mean issues on the line before the error, an expression that wasn't finished.

@mike44To me, it appears to be confusion of basic concepts. No disrespect intended. _Silence_ pointed to it from the beginning but you didn't pay attention to return types. FontMgr.drawString returns void. It's FontMgr.loadFont that returns the FontInfo_t* structure with FontHandle being a type alias. I think what you're looking for is 


FontHandle myFontHandle = m.loadFont("./Ubuntu-B.ttf", NULL, NULL, 16, 0);
m.drawString(myFontHandle, #ffffff, 100, 100, align, "Hello World");

A simplified example ignoring function arguments to show the layout of that library portion 


typedef struct FontInfo_t* FontHandle;

struct FontInfo_t
{
	int blah;
};

class FontMgr
{
public: 

	FontHandle loadFont() 
	{ 
		FontHandle info = new FontInfo_t;
		return info;
	}

	void unloadFont(FontHandle inFont)
	{
		delete inFont;
	}

	void drawString(FontHandle inFont)
	{
      // do..
	}
};


int _tmain(int argc, _TCHAR* argv[])
{
	FontMgr m;
	FontHandle myFontHandle = m.loadFont();

	// stuff my program does
    m.drawString(myFontHandle);
  
    // time to go...
	m.unloadFont(myFontHandle);
	return 0;
}

 

This topic is closed to new replies.

Advertisement