1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <stdio.h>
#include <stdlib.h>
#include <vector>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
#include <irrlicht.h>
#include <map>
#include "callbackhandeler.hpp"
using namespace irr;
using namespace gui;
using namespace std;
extern lua_State* L;
std::map<IGUIElement*,std::map<EGUI_EVENT_TYPE, void(*)(irr::SEvent)> > guifuncs;
//IrrlichtDevice* device;
void registerguicallback(IGUIElement* element, EGUI_EVENT_TYPE event, void (*func)(irr::SEvent)){
printf("Callback registered\n");
guifuncs[element][event] = func;
}
GlobalEventReceiver::GlobalEventReceiver(IrrlichtDevice* d){
//device = d;
}
bool GlobalEventReceiver::OnEvent(const SEvent& e){
EEVENT_TYPE type = e.EventType;
switch (type){
case EET_GUI_EVENT:{
IGUIElement* caller = e.GUIEvent.Caller;
EGUI_EVENT_TYPE get = e.GUIEvent.EventType;
printf("detected gui event...\n");
bool callerregistered = guifuncs.find(caller) != guifuncs.end();
bool callerhasfunc = guifuncs[caller].find(get) != guifuncs[caller].end();
if (callerregistered && callerhasfunc){
guifuncs[caller][get](e);
printf("sucessfully called a gui event\n");
return true;
}
return false;
break;
}
case EET_MOUSE_INPUT_EVENT:{
SEvent::SMouseInput se = e.MouseInput;
//printf("X: %d Y: %d\n",se.X, se.Y);
lua_getglobal(L,"GAME");
lua_getfield(L,-1,"onMouseMove");
if(!lua_isnil(L,-1)){
lua_pushnumber(L,se.X);
lua_pushnumber(L,se.Y);
lua_call(L,2,0);
}
}
default:
//printf("Called an unknown event\n");
return false;
}
}
|