C:/irrlicht/IrrLib/IrrEventReciever.cpp

Go to the documentation of this file.
00001 /*
00002     Irrlicht Library Wrapper
00003     Created by:
00004         Nathan Adams
00005         Denzel Morris
00006     Copyright (C) 2007
00007 
00008     This software is licensed under the GNU/GPL.
00009     This software may not be used for commerical purposes.
00010 */
00011 
00012 #include "IrrEventReciever.h"
00013 #include "IrrData.h"
00014 //#include "IrrLib.h"
00015 #include <irrlicht.h>
00016 #include <iostream>
00017 
00018 using namespace irr;
00019 using namespace core;
00020 using namespace scene;
00021 using namespace video;
00022 using namespace io;
00023 using namespace gui;
00024 
00025 using namespace std;
00026 
00027 /*void IrrEventReciever::setIrrLib(IrrLib& IrrLib)
00028 {
00029     this.callingIrrLib = IrrLib;
00030 }*/
00031 
00032 IrrEventReciever::IrrEventReciever()
00033 {
00034         this->escexit = true;
00035         this->mouse.x = 0;
00036         this->mouse.y = 0;
00037 }
00038 
00039 bool IrrEventReciever::OnEvent(SEvent event)
00040 {
00041         // A button was clicked
00042         if (event.EventType == irr::EET_GUI_EVENT)
00043         {
00044         s32 id = event.GUIEvent.Caller->getID();
00045             switch(event.GUIEvent.EventType){
00046                 case EGET_BUTTON_CLICKED:
00047                 //cout << id << endl;
00048                 buttonStates.push_back(id);
00049                 break;
00050             case EGET_LISTBOX_CHANGED:
00051                 //s32 id = event.GUIEvent.Caller->getID();
00052                 listStates.push_back(id);
00053                 break;
00054             case EGET_LISTBOX_SELECTED_AGAIN:
00055                 listStates.push_back(id);
00056                 break;
00057             default:
00058                 break;
00059             }
00060         }
00061         /*if (event.EventType == irr::EGET_SCROLL_BAR_CHANGED)
00062         {
00063 
00064         }*/
00065         if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
00066                 if (!event.KeyInput.PressedDown){
00067                         this->keyStates[event.KeyInput.Key] = false;
00068                         //cout << "Key was not hit " << this->keyStates[event.KeyInput.Key] << endl;
00069                 }
00070                 else{
00071                         if(event.KeyInput.Key == KEY_ESCAPE && escexit)
00072                                 this->device->closeDevice();
00073                         this->keyStates[event.KeyInput.Key] = true;
00074             //cout << "Key was hit: " << event.KeyInput.Key << " " << this->keyStates[event.KeyInput.Key] << endl;
00075                 }
00076         }
00077         if (event.EventType == EET_MOUSE_INPUT_EVENT){
00078                 if (event.MouseInput.Event == EMIE_MOUSE_MOVED){
00079                         this->mouse.x = event.MouseInput.X;
00080                         this->mouse.y = event.MouseInput.Y;
00081                 }
00082                 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
00083                         this->mouseStates[0] = true;
00084                 if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
00085                         this->mouseStates[0] = false;
00086         }
00087         return false;
00088 }
00089 
00090 void IrrEventReciever::SetEscExit(bool onoff)
00091 {
00092         this->escexit = onoff;
00093 }
00094 
00095 int IrrEventReciever::getMouseX()
00096 {
00097         return this->mouse.x;
00098 }
00099 
00100 int IrrEventReciever::getMouseY()
00101 {
00102         return this->mouse.y;
00103 }
00104 
00105 int IrrEventReciever::getButtonState()
00106 {
00107     if(!this->buttonStates.empty()){
00108         int id;
00109         id = buttonStates.back();
00110         this->buttonStates.pop_back();
00111         return id;
00112     }
00113     else
00114         return -1;
00115 }
00116 
00117 int IrrEventReciever::getRevButtonState()
00118 {
00119     if(!this->buttonStates.empty()){
00120         int id = buttonStates.front();
00121         this->buttonStates.erase(buttonStates.begin());
00122         return id;
00123     }
00124     else
00125     return -1;
00126 }
00127 
00128 void IrrEventReciever::clearButtonState()
00129 {
00130         this->buttonStates.clear();
00131 }
00132 
00133 int IrrEventReciever::checkButtonState(IrrObj obj)
00134 {
00135     if(!this->buttonStates.empty()){
00136         int tmp = this->buttonStates.back();
00137         if (tmp == obj.eventid)
00138         {
00139             this->delLastButtonState();
00140             return 1;
00141         }
00142         else
00143         {
00144             return 0;
00145         }
00146     }
00147     else
00148     {
00149         return -1;
00150     }
00151 }
00152 
00153 void IrrEventReciever::delLastButtonState()
00154 {
00155     if(!this->buttonStates.empty())
00156         this->buttonStates.pop_back();
00157 }
00158 
00159 bool IrrEventReciever::isButtonStateEmpty()
00160 {
00161         return this->buttonStates.empty();
00162 }
00163 
00164 int IrrEventReciever::checkListState(IrrObj obj)
00165 {
00166     if(!this->listStates.empty())
00167     {
00168         int tmp = this->listStates.back();
00169         //cout << tmp << endl;
00170         if (tmp == obj.eventid)
00171         {
00172             this->delLastListState();
00173             return 1;
00174         }
00175         else
00176         {
00177             return 0;
00178         }
00179     }
00180     else
00181     {
00182         return 0;
00183     }
00184 }
00185 
00186 void IrrEventReciever::delLastListState()
00187 {
00188     if(!this->listStates.empty())
00189         this->listStates.pop_back();
00190 }

Generated on Thu Dec 27 18:25:19 2007 for IrrLib by  doxygen 1.5.4