Topic: GUI clarification

When will 2D drawing functions be available?
I'm not sure if MGui will be used for games too or not.
In any case I wanted to know if there is an approximate release date for 2D drawing stuff (for e.g. game menus).
Thanks.

Re: GUI clarification

http://www.maratis3d.org/?page_id=53 < why not just use this for now...GUIDEMO at bottom of screen.

Re: GUI clarification

Of course, I've written myself this:
http://wiki.maratis3d.org/index.php?tit … ng_GUIDemo

Still, all these workarounds are temporary and inefficient ways to do something while waiting for the true thing.

Re: GUI clarification

I started rewriting MGui to be able to use it as dynamic library,
see this post : http://forum.maratis3d.com/viewtopic.php?id=723

but it's still experimental and seems to compile good on osx only (but it uses premake)
I didn't have time to check the linux and win compilation errors yet.

But, except if you need an interface with text editing and a classic GUI, as it's 2d only and doesn't use meshs,
I don't believe MGui is the best for game, it's use it to handle software GUI (like Maratis editor).

I still think that the good step would be to create a set of Behaviors to attach to entities,
a 'Button' behavior, a "Slide" behavior etc. But it sure depend of the final use.

Re: GUI clarification

So what external library do you suggest for doing game menus and debug windows?
Anyone can suggest their preferences.

Re: GUI clarification

If you want, you can try to use the new experimental MGui in c++ in your game plugin,
use the sources directly, the new version is stand-alone.

You will find everything in branches/Experimental/

Here are the headers :
https://code.google.com/p/maratis/sourc … 2FIncludes

You will also need tinyutf8 (one header lib) :
https://code.google.com/p/maratis/sourc … 2Ftinyutf8

To use it, create a MWindow :
- to send input events, use onKeyDown, onKeyUp etc
- use addNewWindow() to create MGuiWindow sub-windows
- call draw() in your custom game class to draw the GUI

To add an editable text with MGuiWindow :

MGuiEditText * text = guiwin->addNewEditText();
text->setPosition(MVector2(100, 100));
text->setFont(fontRef);
text->setTextSize(16);
text->setText("Hello world !");
text->setTextColor(MVector4(1, 1, 1, 1));

ps : fontRef is a font, you can get it from your current level :
MFontRef * fontRef = level->loadFont("/Library/Fonts/Arial.ttf");

Re: GUI clarification

Thanks I'll try that.

Last edited by 255 (2013-10-01 11:07:23)

Re: GUI clarification

Ok it took a while to compile correctly but now it works.
I see a white square which I enlarged using setScale();
I don't see the text though, even changing the color and setting up the font.
I also tried a button, but no luck, I don't see anything even after doing setText().
So I'm not sure how to actually use this. tongue

Re: GUI clarification

Did you create the MGuiWindow and set the size ?

MWindow * rootWindow = new MWindow();

MGuiWindow * guiwin = rootWindow->addNewWindow();
guiwin->setScale(MVector2(800, 600));
guiwin->setColor(MVector3(0.5f, 0.5f, 0.5f));

be sure also that the path to your font is correct
use a full path with c:/
or make a local path global using :

MEngine * engine = MEngine::getInstance();
MSystemContext * system = engine->getSystemContext();

char globalFilename[256];
getGlobalFilename(globalFilename, system->getWorkingDirectory(), "fonts/myFont.ttf"); // font is in project/fonts directory

10

Re: GUI clarification

Oh I didn't know it wanted the full path, I used local.
Now it works, thanks.

11

Re: GUI clarification

But... it's in 3D.
As I move the camera it moves. *scratches his head*
The text I mean. The window is fine.

Images and buttons backgrounds are also fine (still 2d objects), but the text is rendering in 3d with all the perspective in relation to camera view.

Also, I wonder how to load an image, for example to do a cursor.
I tried

MGuiImage* img = guiwin->addNewImage();
img->setPosition(MVector2(50,50));//random
img->setScale(MVector2(40,40));//random
MTextureRef* myTexture = MTextureRef::getNew(0,"C:/blahblah/cursor.jpg",false);
img->setNormalTexture(myTexture);

Last edited by 255 (2013-10-01 16:26:00)

Re: GUI clarification

To load a texture, use "level->loadTexture" like for level->loadFont.

For the text moving with the camera, is it working if you use the fixed renderer instead of the standard renderer ?
Is yes, I know what it is but I have to modify some code.

13

Re: GUI clarification

Yes with fixed renderer it works.

Re: GUI clarification

ok, I'm modifying something in the renderer,
you'll just have to recompile maratis editor with the svn sources.

15

Re: GUI clarification

No problem, had to do it anyway (as in other thread).

Re: GUI clarification

A fix (to be tested) is on svn.

17

Re: GUI clarification

Woah game now crashes. Maybe because of other things due to modifications in trunk/, because MGui is not even ON at the start of my scene; I could try with a more basic project. I'll let you know.
Other projects (maratis demos) work so the compilation is fine.

Last edited by 255 (2013-10-01 18:39:41)

Re: GUI clarification

you have to recompile the game.dll

19

Re: GUI clarification

Yes I did "clean solution" and then rebuild from scratch, it's not that.

Last edited by 255 (2013-10-01 19:38:59)

20

Re: GUI clarification

Looks like if the plugin is compiled with VC 2010 it doesn't work with Maratis build with VC 2008.
Can you confirm that?

Re: GUI clarification

mh, I'm not sure, it's possible.

Did you use the new MCore.lib/dll and MEngine.lib/dll to rebuild the game.dll ?

22

Re: GUI clarification

anael wrote:

Did you use the new MCore.lib/dll and MEngine.lib/dll to rebuild the game.dll ?

Yes.

I tried again compiling Maratis with VS2010, finished right now. I tested my game plugin and it works.
I'm puzzled though: shouldn't a user be allowed to write a plugin DLL for Maratis regardless of how it was compiled?
This is what I would expect.

BTW, I confirm that your fix works. Now I see 2D text.
Thank you.

23

Re: GUI clarification

How does MGuiButton work?
I've created my eventButtonTest() function which does work if called manually.
Then I've done

button->setEventCallback(eventButtonTest);

But clicking on the button does anything.

Re: GUI clarification

You have to feed your MWindow with events,
we have to find a better way, but for now you can do this in your game update :

MSystemContext * system = engine->getSystemContext();
MInputContext * input = engine->getInputContext();

unsigned int width, height;
system->getScreenSize(&width, &height);

// mouse button
if(input->onKeyDown("MOUSE_BUTTON1"))
    window->onMouseButtonDown(MMOUSE_BUTTON_LEFT);

if(input->onKeyUp("MOUSE_BUTTON1"))
    window->onMouseButtonUp(MMOUSE_BUTTON_LEFT);

// and mouse move
int mx = input->getAxis("MOUSE_X")*width;
int my = input->getAxis("MOUSE_Y")*height;

window->onMouseMove(MVector2(mx, my)); // [EDIT] : sorry for the bad example

I'll start to think of a semi automatic way to send events to MWindow

25

Re: GUI clarification

Hrm... it still doesn't work.

Debugging in old style (putting while(1) loops around) I've seen that the event actually reaches the button, so it's a problem with the callback. It's like if m_eventCallback is null, despite me having assigned it.
I think this is due to the fact that my class is assigning the callback function to a function outside its class. I'm obliged to do this otherwise the compiler will throw an error though.
Maybe I should change that method to static and create an handle, etc., how the internet suggests regarding this messy topic.

--------

Tried, no luck even with a static method which retrieves the class doing

MEngine * engine = MEngine::getInstance();
MyGame* my_game = (MyGame*)engine->getGame();
my_game->my_method();

Last edited by 255 (2013-10-02 16:52:53)