简体   繁体   中英

Printf erases the screen (using the MoSync library)

I have some simple code that looks like this:

printf("Press zero or back to exit\n");
maSetColor(0x0055ff);
maFillRect(10,10,100,100);
maUpdateScreen();

This runs, but when it's like this:

maSetColor(0x0055ff);
maFillRect(10,10,100,100);
maUpdateScreen();
printf("Press zero or back to exit\n");

printf erases the screen.

Why is this? Is this a normal property of printf() ? Is there a different print function I should use to print on top of everything, instead of erasing everything? I know I can use MoSync's MaDrawText() instead, but I was wondering if there was a print function that would also work.

This is expected behavior, printf() will display text in a seperate screen. The alternative is maDrawText(int left, int top, const char* str); which will allow you to draw the text in the paint area.

Your code could look like:

//Draw the Rectangle
maSetColor(0x0055ff);
maFillRect(10,10,100,100);

//Draw the text
maSetColor(0xffffff);
maDrawText(10,10,"Press zero or back to exit");

//Update the screen to reflect changes
maUpdateScreen(); 

Your first example works because you are calling the function before you update the screen and hence printf() will not draw on top of your current drawing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM