cannot declare variable `receiver' to be of type `MyEventRec

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
humbrol
Posts: 83
Joined: Sun Nov 18, 2007 8:22 pm

cannot declare variable `receiver' to be of type `MyEventRec

Post by humbrol »

just upgraded to irrlicht 1.4 and when i tried the gui tutorial i get this error
the movement tutorial gets the same error message.

also is direct3d no longer compiled in the included dlls?

cannot declare variable `receiver' to be of type `MyEventReceiver'

is something new with 1.4?

Code: Select all

#include <irrlicht.h>

#include <iostream>


using namespace irr;

using namespace core;

using namespace scene;

using namespace video;

using namespace io;

using namespace gui;

#pragma comment(lib, "Irrlicht.lib")

IrrlichtDevice *device = 0;

s32 cnt = 0;

IGUIListBox* listbox = 0;

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if (event.EventType == EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			IGUIEnvironment* env = device->getGUIEnvironment();

            switch(event.GUIEvent.EventType)

            {
             case EGET_SCROLL_BAR_CHANGED:
	              if (id == 104)
	                 {
                     		s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
					
                		for (s32 i=0; i<EGDC_COUNT ; ++i)
		                 {
                        		SColor col = env->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
                          		col.setAlpha(pos);
                       			env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
                          }
	                  }
                   break;
       case EGET_BUTTON_CLICKED:

              if (id == 101)

              {

                 device->closeDevice();

                 return true;

              }

              if (id == 102)

              {

                 listbox->addItem(L"Window created");

                 cnt += 30;

                 if (cnt > 200) 

                   cnt = 0;

                 IGUIWindow* window = env->addWindow(

                       rect<s32>(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt), 
                       false, // modal?

                       L"Test window");

                 env->addStaticText(L"Please close me", 

                       rect<s32>(35,35,140,50),

                       true, // border?,

                       false, // wordwrap?

                       window);



                 return true;

              }

              if (id == 103)

              {

                 listbox->addItem(L"File open");

                 env->addFileOpenDialog(L"Please choose a file.");

                 return true;

              }

              break;

          }

       }

       return false;

    }

 };
 int main()

{

  // ask user for driver

  video::E_DRIVER_TYPE driverType;





  printf("Please select the driver you want for this example:\n"\
    " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
    " (d) Software Renderer\n (e) Apfelbaum Software Renderer\n"\
    " (f) NullDevice\n (otherKey) exit\n\n");


  char i;
  std::cin >> i;


  switch(i)
  {
    case 'a': driverType = video::EDT_DIRECT3D9;break;
    case 'b': driverType = video::EDT_DIRECT3D8;break;
    case 'c': driverType = video::EDT_OPENGL;   break;
    case 'd': driverType = video::EDT_SOFTWARE; break;
    case 'e': driverType = video::EDT_NULL;     break;
    default: return 1;
  }	

  

  // create device and exit if creation failed

  device = createDevice(driverType, core::dimension2d<s32>(640, 480));


  if (device == 0)

     return 1;
     MyEventReceiver receiver;

device->setEventReceiver(&receiver);

device->setWindowCaption(L"Irrlicht Engine - User Inferface Demo");

video::IVideoDriver* driver = device->getVideoDriver();

IGUIEnvironment* env = device->getGUIEnvironment();

env->addButton(rect<s32>(10,210,100,240), 0, 101, L"Quit");
env->addButton(rect<s32>(10,250,100,290), 0, 102, L"New Window");
env->addButton(rect<s32>(10,300,100,340), 0, 103, L"File Open");

env->addStaticText(L"Transparent Control:", rect<s32>(150,20,350,40), true);
IGUIScrollBar* scrollbar = env->addScrollBar(true,

               rect<s32>(150, 45, 350, 60), 0, 104);
scrollbar->setMax(255);

env->addStaticText(L"Logging ListBox:", rect<s32>(50,80,250,100), true);

listbox = env->addListBox(rect<s32>(50, 110, 250, 180));
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->getFont("media/fonthaettenschweiler.bmp");
if (font)
	skin->setFont(font);

IGUIImage* img = env->addImage(
		driver->getTexture("media/irrlichtlogoalpha.tga"),
		position2d<int>(10,10));
		
		  while(device->run() && driver)
  if (device->isWindowActive()) 
  {
      driver->beginScene(true, true, SColor(0,122,65,171));

      env->drawAll();

      driver->endScene();

  }



  device->drop();

  return 0;

}
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Uh, yeah. You could probably help yourself by looking at the complete error message text... Your compiler will likely tell you that the class MyEventReceiver doesn't implement virtual bool OnEvent(const SEvent&). You implement the function virtual bool OnEvent(SEvent event), do you see the difference? If you don't, maybe you should have a look at the event receivers in the examples/demo, or maybe a search...

As for the D3D drivers not being in there by default, you're mistaken. The D3D9 driver is in there. The D3D8 driver is disabled via IrrCompileConfig.h. You just have to look...

Travis
humbrol
Posts: 83
Joined: Sun Nov 18, 2007 8:22 pm

Post by humbrol »

thats the cut and copy from the tutorials. was able to run it just fine before i upgraded to 1.4 =/
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Sure. 1.4 was released like 8 hours ago and you're getting all bent out of shape that the online tutorials are out of date wrt the latest version of the library. The tutorials are part of the Irrlicht distribution. They can be found in the examples directory. Surprise... they compile!

Travis
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Phew, fortunately we won't have to answer this question again!

;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
humbrol
Posts: 83
Joined: Sun Nov 18, 2007 8:22 pm

Post by humbrol »

to educate my ignorant ass, what was i missing that was throwing it out as a error, did syntax change or?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

vitek wrote:Your compiler will likely tell you that the class MyEventReceiver doesn't implement virtual bool OnEvent(const SEvent&). You implement the function virtual bool OnEvent(SEvent event), do you see the difference? If you don't, maybe you should have a look at the event receivers in the examples/demo, or maybe a search...
That's a pretty clear yes to syntax change. There are also others (you might see some changes in material use and a few parameter changes in other user methods). And in case you have made custom scene nodes you will notice many changes to interface methods which changed to const or const parameter, or from s32 to u32.
Tumbleweed
Posts: 6
Joined: Sat Dec 01, 2007 3:41 pm

Post by Tumbleweed »

Since I am an extreme newbie with C++ (been working with VB6 for years though... big change there {gulp}) and new to Irrlicht as well, maybe this can help add to the good info the previous replies offered. I had to compare the Irrlicht 1.3 examples with the 1.4 examples of the same project to fully understand the changes documented for the 1.4 version, especially considering the syntax of C++. Probably like you, I'm used to software that releases with new version changes that are not reflected in their supporting tutorials or examples, so I just assumed we had old code in the 1.4 version. I was very happy to see version 1.4 examples were updated to reflect the changes... thanks vitek; the advice helped a lot.

As for your errors, in your code, the line:

Code: Select all

virtual bool OnEvent(SEvent event)
should just be replaced with:

Code: Select all

virtual bool OnEvent(const SEvent& event)

I suggest taking a look at the text file, "upgrade-guide.txt" that is located in the 1.4 version's "irrlicht-1.4\doc" folder. This information helps a lot with the new changes implemented in this version. Searching for "OnEvent", you'll see:

Changes for Version 1.4
-----------------------
This release had many changes in API method signatures. Many methods have been made const, also several parameter types were changed. The two most noticeable changes (which almost every user of the Irrlicht API will come across) are the renaming of IUnknown to IReferenceCounted and const-ref change of the SEvent structure of the OnEvent method. Another important change: DirectX8 support is now by default disabled, enable the define in IrrCompileConfig.h to restore the old behavior.
and specifically to OnEvent:
IEventReceiver.h
Changed signature (made const)

Code: Select all

virtual bool OnEvent(const SEvent& event) = 0;
Hope it helps.
Starving graphic artist will UV Map for code.
Post Reply