Jump to content
  • Advertisement
Sign in to follow this  
mike44

C++ use class

Recommended Posts

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

 

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

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.

 

 

Share this post


Link to post
Share on other sites
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");

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites
Posted (edited)

@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;
}

 

Edited by GoliathForge
missed const char* quotations

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!