Menu

qEventReceiver

Benedict Jäggi

qEventReceiver

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.

static qEngine* engine

Pointer to the engine singleton so we can use it directly.

static qiVideoDriver* video

Pointer to the video driver to be used in OnDraw for drawing stuff.

virtual void OnKeyDown(qKeyCode key)

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.

virtual void OnKeyUp(qKeyCode key)

Gets called once when you release a keyboard key.

virtual void OnMouseDown(qEMouseButton which, int x, int y)

Gets called when the mouse button is down once.
It gets the button and the mouse position as parameters.

virtual void OnMouseUp(qEMouseButton which, int x, int y)

Gets called when the mouse button is up first after it was down.
It gets the button and mouse position as parameters

virtual void OnDraw()

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.

virtual void OnGUIButtonClick(int id)

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.

virtual void OnFileDialogOK(int id, qString absolutePath, qString relativePath)

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.

virtual void OnFileDialogCancel(int id)

Gets called when the Cancel button on a file dialog is clicked.

virtual void OnListboxEntryChanged(int id, int index)

Called when a listbox entry is clicked or selected.
Gets the ID of the Listbox and the index of the clicked entry.

virtual void OnGetEntitityToLoad(qString classname)

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.

Example:

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);
...

Related

Wiki: Home
Wiki: qEngine