Hi all,
I wanted to build a viewcontroller to mimic the Model-View-Controller design pattern in irrlicht.
But I hit a wall. If the GUI I load in the view controller is parented to the view controller, it won't render. I have to load it in the root for some reason to get it to draw on screen.
// Header file
#pragma once
#include <irrlicht.h>
class ViewController : public irr::gui::IGUIElement
{
public:
ViewController( irr::u32 viewControllerId, irr::gui::IGUIEnvironment* guiEnvironment, IGUIElement* parent );
virtual ~ViewController(void);
virtual bool loadView( const irr::core::stringw path, const irr::core::stringw filename );
virtual void unloadView();
virtual bool ProcessGUIEvents( const irr::SEvent& event );
private:
irr::gui::IGUIEnvironment* mpGUIEnvironment;
irr::core::rect<irr::s32> mRectangle;
};
// CPP file
#include "ViewController.h"
ViewController::ViewController( irr::u32 viewControllerId, irr::gui::IGUIEnvironment* guiEnvironment, IGUIElement* parent ) :
mpGUIEnvironment(guiEnvironment),
mRectangle(),
IGUIElement(irr::gui::EGUIET_ELEMENT, guiEnvironment, parent, viewControllerId, mRectangle)
{
mRectangle = irr::core::rect<irr::s32>(0, 0, 2000, 2000);
}
ViewController::~ViewController(void)
{
}
bool ViewController::loadView( const irr::core::stringw path, const irr::core::stringw filename )
{
//bool bLoaded = mpGUIEnvironment->loadGUI(path + filename, this); // THIS FAILS!
bool bLoaded = mpGUIEnvironment->loadGUI(path + filename, 0);
if( bLoaded )
{
//mpGUIEnvironment->addChildToEnd(this)
//mpGUIEnvironment->getRootGUIElement()->addChild(this);
//mpGUIEnvironment->addCheckBox();
this->setEnabled(true);
this->setVisible(true);
bringToFront(this);
}
return bLoaded;
}
void ViewController::unloadView()
{
remove();
}
bool ViewController::ProcessGUIEvents( const irr::SEvent& event )
{
return false;
}
Any idea why this is happening?
Richard.
ViewController class
Re: ViewController class
Make sure the rectangle you pass to IGUIElement is large enough as children are by default clipped by their parent. Also note that IGUIElement saves the rect already in the "RelativeRect", so you maybe don't need the mRectangle. Same for IGUIEnvironment which is in "Environment". Both variables are just protected so you can access them when deriving from IGUIElement.
It also might be a good idea to overload the following 2 functions to avoid any reactions on mouseclicks if that's not a real element:
It also might be a good idea to overload the following 2 functions to avoid any reactions on mouseclicks if that's not a real element:
Code: Select all
virtual bool isPointInside(const irr::core::position2d<irr::s32>& point) const
{
return false;
}
virtual bool bringToFront(IGUIElement* element)
{
bool result = IGUIElement::bringToFront(element);
// pass that on
if ( Parent )
{
Parent->bringToFront(this);
}
return result;
}
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 5
- Joined: Mon Feb 03, 2014 1:44 am
Re: ViewController class
Great!
Will give that a shot once back home tonight.
Hopefully this can come handy for other irrlicht users
Will give that a shot once back home tonight.
Hopefully this can come handy for other irrlicht users
-
- Posts: 5
- Joined: Mon Feb 03, 2014 1:44 am
Re: ViewController class
Thank you CuteAlien. This solved my problem.