6 posts / 0 new
Last post
TheDesktopIsDead
TheDesktopIsDead's picture
Offline
Joined: 4 Sep 2011
Posts:
What am I doing wrong?

Hello All,
I am a MoSync newbie so please bear with me while I get to grips with creating and managing a MoSync project.

Having gotten past the HelloWorld example and not being very good at reading readymade code I decided to try out a simple MAUI project. The first issue I ran into was with font resources. Creating a .mof file was easy enough. I then created the corresponding .lst file as explained here. However, the MoSync help talks of the resource compiler automatically creating the MAHeaders.h file. Not quite sure where and when this happens. Presumably not whilst I am building the project. So I ended up creating the .h file manually and got the project to compile.

When I tried to run it I got a MALLOC warning regarding insufficient memory so I increased it to 128 Kb and ran the app again. Much to my surprise instead of seeing "Hello World" against a blue background I get a blank screen. What am I doing wrong.

My main.cpp code is given below

#include
#include
#include
#include
#include "MAHeaders.h"
using namespace MAUtil;
using namespace MAUI;
class MyScreen : public Screen {
public:
MyScreen() {
label = new Label(
10, // set the top-left corner
10, // to be in the top-left corner of the lcd display.
100, // the width and height are set to the width and height of the lcd display
30, // automatically for the root widget in a screen.
NULL, // this widget has no parent widget
"123Hello World!", // the caption of the label
255, // use background color 0 (black)
new Font(myfonts) // create a new instance of the font stored as the
// resource MY_FONT and set the font of the label to that font.
);
setMain(label); // set the root widget to be the label we just created
}
void keyPressEvent(int key) {
if(key == MAK_0) {
maExit(0); // exit the application when key 0 has been pressed
}
}

private:
Label *label;
};
class MyMoblet : public Moblet {
public:
MyMoblet() {
myScreen = new MyScreen();
myScreen->show();
}
private:
MyScreen *myScreen;
};
// Since this is a C++ program, the main function
// needs to be declared extern "C"
extern "C" int MAMain() {
Moblet::run(new MyMoblet());
}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi,

You've explained your problem clearly, but have a look at this thread http://www.mosync.com/node/6977 to see how to post source code so we can all read it.

MAHeaders is created automatically at build time. Delete the one you've made. What colour did you make the font? Your code seems to be OK.

Thanks

TheDesktopIsDead
TheDesktopIsDead's picture
Offline
Joined: 4 Sep 2011
Posts:

rival wrote:

Hi,
You've explained your problem clearly, but have a look at this thread http://www.mosync.com/node/6977 to see how to post source code so we can all read it.
MAHeaders is created automatically at build time. Delete the one you've made. What colour did you make the font? Your code seems to be OK.
Thanks

Thank you, Sam.  I'll make sure I put in future code samples the right way.

The issue I have found is that, contrary to what is claimed, BMFont needs to be given a font color or else you end up with a blank screen like I did.  Once I had specified a color, 0xFFFFFFFF, all was well.  That apart the fontset you export has to be extended ASCII - this could be a concern for me later.

Before I created my own MAHeaders.h I did try to build the project in the hope of seeing it being created by the compiler.  However, compilation stopped with the message

error: `myfonts' was not declared in this scope

A somewhat unrelated comment

I looked at a range of options - Marmalade etc - before settling on MoSync.  While it is good there appear to be rough edges and minor inconsistencies in the documentation.    Is this simply because it has not quite matured yet?

 

 

 

 

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi,
Have you got this in your resource file?

.res myfonts 
.bin 
.include "myfont.mof"

The documentation is always a massive work in progress. We try to publish as much accurate API documentation and as many tutorials and guides as we can, but MoSync moves on so quickly its really difficult to keep it aligned.

sanfrancisco
sanfrancisco's picture
Offline
Joined: 10 Dec 2011
Posts:

Hi!
I have the same problem as TheDesktopIsDead. Fortunately I found a way around it:
File res.lst contains:

.res MYFONT1
.bin
.include "..\\..\\examples\\MapDemo\\Res\\verdana16white.mof"

Then in main.cpp, after the "using namespace" I add:

Font* knk = new Font(1); // note i don't use the font name but number 1 instead.

And later,

labelle->setFont(knk);
labelle->setCaption("Hello galaxy, we love you.");

It works although I don't even specify any font color.

PS i'm new here. Yes Sam i'll have a look at the standard code formatting for this forum.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

I've seen this sometimes when people try to copy MAHeaders into their project folder. Make sure that you've not got a file in your source code folders called MAHeaders. It will be generated when you build and on a valid path.