If you want to catch clicks on GUI buttons (created with engine->addButton(...)
), mouse clicks and keyboard presses and some other stuff, you need to derive a class from qEventReceiver
and set it to the engine with engine->setEventReceiver(myReceiverPtr)
.
You can even exchange them on runtime.
Pointer to the engine singleton so we can use it directly.
Pointer to the video driver to be used in OnDraw
for drawing stuff.
Gets called ONCE when a keyboard key is pressed.
If you want to check for it continuousely, use engine->getKeyDown(key)
in your main loop.
Gets called once when you release a keyboard key.
Gets called when the mouse button is down once.
It gets the button and the mouse position as parameters.
Gets called when the mouse button is up first after it was down.
It gets the button and mouse position as parameters
Draw stuff here with video. Note that mesh entities are added to the root scene node of the graphics engine's scene manager.
A basic entity will be drawed as 3d cross of lines.
A qMeshNodeEntity does NOT need the OnDraw function, but it gets called.
Use video
for drawing stuff.
Gets called when a GUI button is clicked.
Also gets called when a menu item gets selected.
It gets the gui buttons id or the menu items commandID as parameter.
Gets called when the OK button on a file dialog is clicked.
id
is the id of the FileDialog.
absolutePath
is the absolute path to the file.
relativePath
is the path relative to the directory of the application.
Use relative paths if possible.
Gets called when the Cancel button on a file dialog is clicked.
Called when a listbox entry is clicked or selected.
Gets the ID of the Listbox and the index of the clicked entry.
This is used for deserizalizing (loading) entities.
It first loads the class name, then calls this function with that name.
This function should return a new instance with your given class, which must be derived from qEntity
or qMeshNodeEntity
.
class cr : public qEventReceiver
{
public:
virtual void OnGUIButtonClick(int id)
{
printf("Button with id %d was clicked.", id);
}
virtual void OnMouseUp(qEMouseButton which, int x, int y)
{
printf("Mouse button %d was released at %d, %d", which, x, y);
}
virtual void OnGetEntityToLoad(std::string classname)
{
if(classname=="MyNewClass")
return new MyNewClass("myName");
printf("WARNING: Could not create entity with class name %s.\n", classname.c_str());
return NULL;
}
};
And then in main:
qEngine *e=qEngine::getInstance();
cr g;
e->setEventReceiver(&g);
...