/* Irrlicht Library Wrapper Created by: Nathan Adams Denzel Morris Copyright (C) 2007 This software is licensed under the GNU/GPL. This software may not be used for commerical purposes. */ #include "IrrEventReciever.h" //#include "IrrLib.h" #include #include using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; using namespace std; /*void IrrEventReciever::setIrrLib(IrrLib& IrrLib) { this.callingIrrLib = IrrLib; }*/ IrrEventReciever::IrrEventReciever() { this->escexit = true; this->mouse.x = 0; this->mouse.y = 0; } bool IrrEventReciever::OnEvent(SEvent event) { // A button was clicked if (event.EventType == irr::EET_GUI_EVENT) { s32 id = event.GUIEvent.Caller->getID(); switch(event.GUIEvent.EventType){ case EGET_BUTTON_CLICKED: //cout << id << endl; buttonStates.push_back(id); break; case EGET_LISTBOX_CHANGED: //s32 id = event.GUIEvent.Caller->getID(); listStates.push_back(id); break; case EGET_LISTBOX_SELECTED_AGAIN: listStates.push_back(id); break; default: break; } } /*if (event.EventType == irr::EGET_SCROLL_BAR_CHANGED) { }*/ if (event.EventType == irr::EET_KEY_INPUT_EVENT) { if (!event.KeyInput.PressedDown){ this->keyStates[event.KeyInput.Key] = false; //cout << "Key was not hit " << this->keyStates[event.KeyInput.Key] << endl; } else{ if(event.KeyInput.Key == KEY_ESCAPE && escexit) this->device->closeDevice(); this->keyStates[event.KeyInput.Key] = true; //cout << "Key was hit: " << event.KeyInput.Key << " " << this->keyStates[event.KeyInput.Key] << endl; } } if (event.EventType == EET_MOUSE_INPUT_EVENT){ if (event.MouseInput.Event == EMIE_MOUSE_MOVED){ this->mouse.x = event.MouseInput.X; this->mouse.y = event.MouseInput.Y; } if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) this->mouseStates[0] = true; if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) this->mouseStates[0] = false; } return false; } void IrrEventReciever::SetEscExit(bool onoff) { this->escexit = onoff; } int IrrEventReciever::getMouseX() { return this->mouse.x; } int IrrEventReciever::getMouseY() { return this->mouse.y; } int IrrEventReciever::getButtonState() { if(!this->buttonStates.empty()){ int id; id = buttonStates.back(); this->buttonStates.pop_back(); return id; } else return -1; } int IrrEventReciever::getRevButtonState() { if(!this->buttonStates.empty()){ int id = buttonStates.front(); this->buttonStates.erase(buttonStates.begin()); return id; } else return -1; } void IrrEventReciever::clearButtonState() { this->buttonStates.clear(); } int IrrEventReciever::checkButtonState() { if(!this->buttonStates.empty()) return this->buttonStates.back(); else return -1; } void IrrEventReciever::delLastButtonStat() { if(!this->buttonStates.empty()) this->buttonStates.pop_back(); } bool IrrEventReciever::isButtonStateEmpty() { return this->buttonStates.empty(); } int IrrEventReciever::checkListState() { if(!this->listStates.empty()) return this->listStates.back(); else return -1; } void IrrEventReciever::delLastListStat() { if(!this->listStates.empty()) this->listStates.pop_back(); }