I have to admit, I did do this when I was n00b that first entered the Irrlicht community. It's funny that you would bring this subject up though, some 1 year later... (close to it)Midnight wrote:lol these copyrights just keep getting better.
there is almost not a single thing you can claim on this because it's all irrlicht code.
not to mention I beat you by a few months with my MasterReceiver I've been keeping a secret.
your thing has more functionality appearently but it's a different layer.
EDIT: in fact at a second glance this thing is no where near as good as my master receiver.. awsome lol
(C++) CIrrEventReceiver
TheQuestion = 2B || !2B
-
IH3ARTN0085
- Posts: 1
- Joined: Fri Nov 16, 2007 7:04 pm
Well my suggestions are either use one of the other event receivers on this forum, don't download those old files and get the new ones that are posted on this thread, or post some code so I can see exactly what you are doing.IH3ARTN0085 wrote:hi, I am still kind of new here, but I downloaded these files, and updated everything to the most recent. but when I compile and run, the up arrow key still doesn't exit the program as it was supposed too.
TheQuestion = 2B || !2B
-
Legars2101
- Posts: 8
- Joined: Fri Mar 07, 2008 11:34 am
- Location: Rouen, FR
HI, I did some modification on this class. I wanted to a little more about the mousewheel : direction and if it moves.
So I added method in same ways of yours, and post it here. May be usefull for anyone
The CIrrEventReceiver header file:
The source file:
So I added method in same ways of yours, and post it here. May be usefull for anyone
The CIrrEventReceiver header file:
Code: Select all
/******************************************************************************
* CIrrEventReceiver
* =================
*
* CIrrEventReceiver has no restrictions. Credit would be appreciated, but not
* required.
******************************************************************************/
#ifndef __CIRREVENTRECEIVER_H__
#define __CIRREVENTRECEIVER_H__
#include <Irrlicht.h>
#include <iostream>
#include <sstream>
using namespace irr;
using namespace core;
using namespace gui;
using namespace io;
using namespace std;
/* I doubt the number of keys will go above 255 ;), but it is there for compatibility issues */
#define NUMBER_OF_KEYS KEY_KEY_CODES_COUNT
#define NUMBER_OF_MOUSE_BUTTONS 3
#define NUMBER_OF_GUI_ELEMENTS 21
enum buttonState
{
BS_UP,
BS_DOWN,
BS_PRESSED,
BS_RELEASED
};
enum mouseButton
{
MBLEFT,
MBMIDDLE,
MBRIGHT
};
enum mouseButtonState
{
MBS_UP,
MBS_DOWN,
MBS_PRESSED,
MBS_RELEASED
};
enum mouseWheelDirection
{
MWD_UP,
MWD_DOWN,
};
struct mouseInformation
{
s32 x, y, lx, ly, cx, cy;
f32 wheelPos, lwheelPos;
};
// Enumeration for Event Handling State.
enum ProcessEventState
{
STARTED,
ENDED
};
// this enum is for setting the gui events to true or false.
enum ElementStatus
{
TRUE,
FALSE
};
class CIrrEventReceiver : public IEventReceiver
{
public:
CIrrEventReceiver();
~CIrrEventReceiver();
// GUI events:
bool getEventCallerByElement(EGUI_EVENT_TYPE);
int getEventCallerOfMenuByID();
int getEventCallerByID();
// Keyboard events:
bool isKeyUp(EKEY_CODE key);
bool isKeyDown(EKEY_CODE key);
bool isKeyPressed(EKEY_CODE key);
bool isKeyReleased(EKEY_CODE key);
// Mouse events:
bool isMouseButtonUp(mouseButton mb);
bool isMouseButtonDown(mouseButton mb);
bool isMouseButtonPressed(mouseButton mb);
bool isMouseButtonReleased(mouseButton mb);
bool mouseMoved();
bool mouseWheelMoved();
// Processing functions:
void startEventProcess();
void endEventProcess();
int getDeltaMousePosX();
int getDeltaMousePosY();
inline int getMouseX() { return MouseData.x; }
inline int getMouseY() { return MouseData.y; }
inline int getLastMouseX() { return MouseData.lx; }
inline int getLastMouseY() { return MouseData.ly; }
inline s32 getDeltaMouseX()
{
s32 a = MouseData.x - MouseData.lx;
return (s32)(a < 0 ? -a : a);
}
inline s32 getDeltaMouseY()
{
s32 a = MouseData.y - MouseData.ly;
return (s32)(a < 0 ? -a : a);
}
inline u32 getClickedMouseX() { return MouseData.cx; }
inline u32 getClickedMouseY() { return MouseData.cy; }
inline f32 getMouseWheelPosition() { return MouseData.wheelPos; }
inline f32 getLastMouseWheelPosition() { return MouseData.lwheelPos; }
inline f32 getDeltaMouseWheelPosition()
{
f32 a = MouseData.wheelPos - MouseData.lwheelPos;
return (f32)(a < 0 ? -a : a);
}
inline mouseWheelDirection getMouseWheelDirection()
{
f32 a = MouseData.wheelPos - MouseData.lwheelPos;
return (a < 0 ? mouseWheelDirection::MWD_DOWN : mouseWheelDirection::MWD_UP);
}
bool OnEvent(const SEvent& event);
protected:
buttonState Keys[NUMBER_OF_KEYS];
mouseButtonState Mouse[NUMBER_OF_MOUSE_BUTTONS];
ElementStatus elementStatus[NUMBER_OF_GUI_ELEMENTS];
mouseInformation MouseData;
ProcessEventState procesState;
IGUIContextMenu* menu;
s32 menuItemSelectedID;
s32 generalCallerID;
int deltaMouseX;
int deltaMouseY;
bool mouseHasMoved;
bool mouseWheelHasMoved;
// for converting anything to string (good for debug to console).
template <class T>
inline std::string ToString(const T& t)
{
std::stringstream ss;
ss << t;
return ss.str();
}
};
#endif /* __CIRREVENTRECEIVER_HEADER__ */
Code: Select all
/******************************************************************************
* CIrrEventReceiver
* =================
*
* CIrrEventReceiver has no restrictions. Credit would be appreciated, but not
* required.
******************************************************************************/
#include "StdAfx.h"
#include <stdio.h>
#include "CIrrEventReceiver.h"
CIrrEventReceiver::CIrrEventReceiver()
{
for(u32 i = 0; i < NUMBER_OF_KEYS; i++)
Keys[i] = BS_UP;
// Mouse Key States
for(u32 i = 0; i < NUMBER_OF_MOUSE_BUTTONS; i++)
Mouse[i] = MBS_UP;
MouseData.x = MouseData.y = MouseData.lx = MouseData.ly = MouseData.cx = MouseData.cy = 0;
MouseData.wheelPos = MouseData.lwheelPos = 0;
deltaMouseX = deltaMouseY = 0;
mouseHasMoved = false;
mouseWheelHasMoved = false;
generalCallerID = menuItemSelectedID = 0;
menu = NULL;
elementStatus[EGET_ELEMENT_FOCUS_LOST] = elementStatus[EGET_ELEMENT_FOCUSED] =
elementStatus[EGET_ELEMENT_HOVERED] = elementStatus[EGET_ELEMENT_LEFT] =
elementStatus[EGET_ELEMENT_CLOSED] = elementStatus[EGET_BUTTON_CLICKED] =
elementStatus[EGET_SCROLL_BAR_CHANGED] = elementStatus[EGET_CHECKBOX_CHANGED] =
elementStatus[EGET_LISTBOX_CHANGED] = elementStatus[EGET_LISTBOX_SELECTED_AGAIN] =
elementStatus[EGET_FILE_SELECTED] = elementStatus[EGET_FILE_CHOOSE_DIALOG_CANCELLED] =
elementStatus[EGET_MESSAGEBOX_YES] = elementStatus[EGET_MESSAGEBOX_NO] =
elementStatus[EGET_MESSAGEBOX_OK] = elementStatus[EGET_MESSAGEBOX_CANCEL] =
elementStatus[EGET_EDITBOX_ENTER] = elementStatus[EGET_TAB_CHANGED] =
elementStatus[EGET_MENU_ITEM_SELECTED] = elementStatus[EGET_COMBO_BOX_CHANGED] =
elementStatus[EGET_SPINBOX_CHANGED] = FALSE; // << set all gui elements to false
}
CIrrEventReceiver::~CIrrEventReceiver()
{
}
bool CIrrEventReceiver::isKeyUp(EKEY_CODE key)
{
if (Keys[key] == BS_UP)
return true;
return false;
}
bool CIrrEventReceiver::isKeyDown(EKEY_CODE key)
{
if (Keys[key] == BS_DOWN)
return true;
return false;
}
bool CIrrEventReceiver::isKeyPressed(EKEY_CODE key)
{
if(Keys[key] == BS_PRESSED)
return true;
return false;
}
bool CIrrEventReceiver::isKeyReleased(EKEY_CODE key)
{
if(Keys[key] == BS_RELEASED)
return true;
return false;
}
bool CIrrEventReceiver::isMouseButtonUp(mouseButton mb)
{
if (Mouse[mb] == MBS_UP)
return true;
return false;
}
bool CIrrEventReceiver::isMouseButtonDown(mouseButton mb)
{
if (Mouse[mb] == MBS_DOWN)
return true;
return false;
}
bool CIrrEventReceiver::isMouseButtonPressed(mouseButton mb)
{
if (Mouse[mb] == MBS_PRESSED)
return true;
return false;
}
bool CIrrEventReceiver::isMouseButtonReleased(mouseButton mb)
{
if (Mouse[mb] == MBS_RELEASED)
return true;
return false;
}
int CIrrEventReceiver::getDeltaMousePosX()
{
return deltaMouseX;
}
int CIrrEventReceiver::getDeltaMousePosY()
{
return deltaMouseY;
}
bool CIrrEventReceiver::mouseMoved()
{
if(mouseHasMoved)
{
// set its state back to false.
mouseHasMoved = false;
return true;
}
return false;
}
bool CIrrEventReceiver::mouseWheelMoved()
{
if(mouseWheelHasMoved)
{
// set its state back to false.
mouseWheelHasMoved = false;
return true;
}
return false;
}
bool CIrrEventReceiver::getEventCallerByElement(EGUI_EVENT_TYPE guiEventType)
{
if(elementStatus[guiEventType] == TRUE)
return true;
return false;
}
// This function will be used to get the ID of a gui element.
// This is a general function for getting the ID.
// It works for a lot of gui events but not all.
// Like getting the ID of the context menu wont work with this function
// Instead, use this function: getEventCallerOfMenuByID()
int CIrrEventReceiver::getEventCallerByID()
{
return generalCallerID;
}
// meant for event: EGET_MENU_ITEM_SELECTED
// because IGUIContextMenu does not have the function: getID()
// in this line: event.GUIEvent.Caller->getID()
// So I had to make a custome one for the EGET_MENU_ITEM_SELECTED events.
int CIrrEventReceiver::getEventCallerOfMenuByID()
{
return menuItemSelectedID;
}
// This is used so that the Key States will not be changed during execution of your Main game loop.
// Place this function at the END of your Main Loop.
void CIrrEventReceiver::startEventProcess()
{
procesState = STARTED;
// Keyboard Key States
for(int i = 0; i < KEY_KEY_CODES_COUNT; i++)
{
if(Keys[i] == BS_RELEASED)
Keys[i] = BS_UP;
if(Keys[i] == BS_PRESSED)
Keys[i] = BS_DOWN;
}
// Mouse Key States
for(int i = 0; i < NUMBER_OF_MOUSE_BUTTONS; i++)
{
if(Mouse[i] == MBS_RELEASED)
Mouse[i] = MBS_UP;
if(Mouse[i] == MBS_PRESSED)
Mouse[i] = MBS_DOWN;
}
elementStatus[EGET_ELEMENT_FOCUS_LOST] = elementStatus[EGET_ELEMENT_FOCUSED] =
elementStatus[EGET_ELEMENT_HOVERED] = elementStatus[EGET_ELEMENT_LEFT] =
elementStatus[EGET_ELEMENT_CLOSED] = elementStatus[EGET_BUTTON_CLICKED] =
elementStatus[EGET_SCROLL_BAR_CHANGED] = elementStatus[EGET_CHECKBOX_CHANGED] =
elementStatus[EGET_LISTBOX_CHANGED] = elementStatus[EGET_LISTBOX_SELECTED_AGAIN] =
elementStatus[EGET_FILE_SELECTED] = elementStatus[EGET_FILE_CHOOSE_DIALOG_CANCELLED] =
elementStatus[EGET_MESSAGEBOX_YES] = elementStatus[EGET_MESSAGEBOX_NO] =
elementStatus[EGET_MESSAGEBOX_OK] = elementStatus[EGET_MESSAGEBOX_CANCEL] =
elementStatus[EGET_EDITBOX_ENTER] = elementStatus[EGET_TAB_CHANGED] =
elementStatus[EGET_MENU_ITEM_SELECTED] = elementStatus[EGET_COMBO_BOX_CHANGED] =
elementStatus[EGET_SPINBOX_CHANGED] = FALSE; // << set all gui elements to false
}
// This is used so that the Key States will not be changed during execution of your Main game loop.
// Place this at the very START of your Main Loop
void CIrrEventReceiver::endEventProcess()
{
procesState = ENDED;
}
bool CIrrEventReceiver::OnEvent(const SEvent& event)
{
switch (event.EventType)
{
case EET_KEY_INPUT_EVENT:
{
if(procesState == STARTED)
{
if(event.KeyInput.PressedDown)
{
// If key was not down before
if(Keys[event.KeyInput.Key] != BS_DOWN)
Keys[event.KeyInput.Key] = BS_PRESSED; // Set key to Pressed
else
Keys[event.KeyInput.Key] = BS_DOWN;
break;
}
else
{
// if the key is down
if(Keys[event.KeyInput.Key] != BS_UP)
Keys[event.KeyInput.Key] = BS_RELEASED; // Set key to Released
else
Keys[event.KeyInput.Key] = BS_UP;
break;
}
}
}
break;
case EET_MOUSE_INPUT_EVENT:
{
switch(event.MouseInput.Event)
{
case EMIE_MOUSE_MOVED:
{
deltaMouseX = event.MouseInput.X - MouseData.lx;
deltaMouseY = event.MouseInput.Y - MouseData.ly;
MouseData.x = event.MouseInput.X;
MouseData.y = event.MouseInput.Y;
MouseData.lx = MouseData.x;
MouseData.ly = MouseData.y;
mouseHasMoved = true;
break;
}
case EMIE_MOUSE_WHEEL:
{
MouseData.lwheelPos = MouseData.wheelPos;
MouseData.wheelPos += event.MouseInput.Wheel;
mouseWheelHasMoved = true;
break;
}
// Left Mouse Button Pressed
case EMIE_LMOUSE_PRESSED_DOWN:
{
if(Mouse[MBLEFT] == MBS_UP || Mouse[MBLEFT] == MBS_RELEASED)
Mouse[MBLEFT] = MBS_PRESSED;
else
Mouse[MBLEFT] = MBS_DOWN;
break;
}
// Left Mouse Button Rleased
case EMIE_LMOUSE_LEFT_UP:
{
if(Mouse[MBLEFT] != MBS_UP)
Mouse[MBLEFT] = MBS_RELEASED;
break;
}
// Middle Mouse Button Pressed
case EMIE_MMOUSE_PRESSED_DOWN:
{
if(Mouse[MBMIDDLE] == MBS_UP || Mouse[MBMIDDLE] == MBS_RELEASED)
Mouse[MBMIDDLE] = MBS_PRESSED;
else
Mouse[MBMIDDLE] = MBS_DOWN;
break;
}
// Middle Mouse Button Rleased
case EMIE_MMOUSE_LEFT_UP:
{
if (Mouse[MBMIDDLE] != MBS_UP)
Mouse[MBMIDDLE] = MBS_RELEASED;
break;
}
// Right Mouse Button Pressed
case EMIE_RMOUSE_PRESSED_DOWN:
{
if (Mouse[MBRIGHT] == MBS_UP || Mouse[MBRIGHT] == MBS_RELEASED)
Mouse[MBRIGHT] = MBS_PRESSED;
else
Mouse[MBRIGHT] = MBS_DOWN;
break;
}
// Right Mouse Button Rleased
case EMIE_RMOUSE_LEFT_UP:
{
if(Mouse[MBRIGHT] != MBS_UP)
Mouse[MBRIGHT] = MBS_RELEASED;
break;
}
default:
break;
}
}
break;
case EET_GUI_EVENT:
{
generalCallerID = event.GUIEvent.Caller->getID();
switch(event.GUIEvent.EventType)
{
case EGET_ELEMENT_FOCUS_LOST:
case EGET_ELEMENT_FOCUSED:
case EGET_ELEMENT_HOVERED:
case EGET_ELEMENT_LEFT:
case EGET_ELEMENT_CLOSED:
case EGET_BUTTON_CLICKED:
case EGET_SCROLL_BAR_CHANGED:
case EGET_CHECKBOX_CHANGED:
case EGET_LISTBOX_CHANGED:
case EGET_LISTBOX_SELECTED_AGAIN:
case EGET_FILE_SELECTED:
case EGET_FILE_CHOOSE_DIALOG_CANCELLED:
case EGET_MESSAGEBOX_YES:
case EGET_MESSAGEBOX_NO:
case EGET_MESSAGEBOX_OK:
case EGET_MESSAGEBOX_CANCEL:
case EGET_EDITBOX_ENTER:
case EGET_TAB_CHANGED:
case EGET_COMBO_BOX_CHANGED:
case EGET_SPINBOX_CHANGED:
elementStatus[event.GUIEvent.EventType] = TRUE;
break;
case EGET_MENU_ITEM_SELECTED:
elementStatus[EGET_MENU_ITEM_SELECTED] = TRUE;
menu = (IGUIContextMenu*)event.GUIEvent.Caller;
menuItemSelectedID = menu->getItemCommandId(menu->getSelectedItem());
break;
}
}
default:
break;
}
return false;
}
Sorry, I have to bump this. I am just curious as to what copyright's you were referring to, because at my second glance, I see no copyrights in this program at all.Midnight wrote:lol these copyrights just keep getting better.
there is almost not a single thing you can claim on this because it's all irrlicht code.
not to mention I beat you by a few months with my MasterReceiver I've been keeping a secret.
your thing has more functionality appearently but it's a different layer.
EDIT: in fact at a second glance this thing is no where near as good as my master receiver.. awsome lol
TheQuestion = 2B || !2B
Sorry for replying to this old thread but I would love to know whats the difference between
And

Code: Select all
CIrrEventReceiver::isMouseButtonDown(mouseButton mb) Code: Select all
CIrrEventReceiver::isMouseButtonPressed(mouseButton mb) Working on game: Marrbles (Currently stopped).
-
shadowslair
- Posts: 758
- Joined: Mon Mar 31, 2008 3:32 pm
- Location: Bulgaria
Probably one of them (at least should) return true if the mouse button is pressed within the last step, or is hold for some time. Like if you want you character to shoot each time you press the mouse button you use CIrrEventReceiver::isMouseButtonPressed(mouseButton mb)
Then, when you press and hold your button you`ll shoot only once until you release and press the button once again.
CIrrEventReceiver::isMouseButtonDown(mouseButton mb) will make your character shoot one bullet for each step until you release the key. Simple as that.
Then, when you press and hold your button you`ll shoot only once until you release and press the button once again.
CIrrEventReceiver::isMouseButtonDown(mouseButton mb) will make your character shoot one bullet for each step until you release the key. Simple as that.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."