-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmEventDispacher.cpp
More file actions
125 lines (110 loc) · 4.29 KB
/
Copy pathmEventDispacher.cpp
File metadata and controls
125 lines (110 loc) · 4.29 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
#include <stdint.h>
#include "mEventDispatcher.h"
#include <linux/input.h>
#include <X11/extensions/XInput.h>
EventDispatcher::EventDispatcher(int winWidth, int winHeight) {
::winWidth = winWidth;
::winHeight = winHeight;
//EventDispatcher::GManager = GUImanager;
//GUImanager->setEventDispatcher(this);
GUImap = new uint_fast8_t[winWidth * winHeight + 1];
for (long int i = 0; i < winWidth * winHeight; i++)
GUImap[i] = 0;
}
EventDispatcher::~EventDispatcher() {
delete[] GUImap;
}
void EventDispatcher::registerGUImanager(GUIManager* Gmanager) {
EventDispatcher::GManager = Gmanager;
}
inline unsigned EventDispatcher::TranslatePosition(int x, int y) {
if (x > winWidth || y > winHeight || x < 0 || y < 0)
return 0;
return (unsigned) GUImap[winWidth * y + x];
}
uint8_t* EventDispatcher::getGUImap() {
return GUImap;
}
void EventDispatcher::fetchAndDispatchEvent(XEvent *event) {
unsigned curMapValue;
int pointerX;
int pointerY;
int buttonCode;
switch (event->type) {
case MotionNotify:
pointerX = event->xmotion.x;
pointerY = event->xmotion.y;
curMapValue = TranslatePosition(event->xmotion.x, event->xmotion.y);
if (eventState.buttonPressed) {
eventState.pointerMovedAfterPress = true;
eventState.dragEventOwner = eventState.activeComp;
GManager->operator[](eventState.dragEventOwner)->onDrag(pointerX, pointerY);
//[eventState.dragEventOwner]->onDrag(pointerX, pointerY);
std::cout << "onDrag() called on ID = " << eventState.dragEventOwner << " x: " << pointerX << " y: " << pointerY << std::endl;
break;
}
if (curMapValue != eventState.activeComp) {
eventState.currentActiveWidget = curMapValue;
GManager->operator[](eventState.activeComp)->onUnFocus();
GManager->operator[](curMapValue)->onFocus();
}
GManager->operator[](curMapValue)->onMotion(pointerX, pointerY);
eventState.activeComp = curMapValue;
break;
case ButtonPress:
buttonCode = event->xbutton.button;
pointerX = event->xmotion.x;
pointerY = event->xmotion.y;
curMapValue = TranslatePosition(event->xmotion.x, event->xmotion.y);
GManager->operator[](curMapValue)->onButtonPress(pointerX, pointerY, buttonCode);
eventState.activeComp = curMapValue;
std::cout << "onButtonPress() called on ID = " << unsigned(curMapValue) << " x: " << pointerX << " y: " << pointerY
<< " ButtonCode: " << buttonCode << std::endl;
eventState.pointerMovedAfterPress = false;
eventState.buttonPressed = true;
break;
case ButtonRelease:
pointerX = event->xmotion.x;
pointerY = event->xmotion.y;
curMapValue = TranslatePosition(event->xmotion.x, event->xmotion.y);
if (eventState.pointerMovedAfterPress) {
GManager->operator[](eventState.dragEventOwner)->onDrop(pointerX, pointerY);
std::cout << "onDrop() called on ID = " << eventState.dragEventOwner << " x: " << pointerX << " y: " << pointerY << std::endl;
if (curMapValue != eventState.dragEventOwner) {
GManager->operator[](eventState.dragEventOwner)->onUnFocus();
GManager->operator[](curMapValue)->onFocus();
eventState.activeComp = curMapValue;
}
eventState.pointerMovedAfterPress = false;
eventState.buttonPressed = false;
break;
}
GManager->operator[](curMapValue)->onClick(pointerX, pointerY);
std::cout << "onClick() called on ID = " << unsigned(curMapValue) << " x: " << pointerX << " y: " << pointerY << std::endl;
eventState.buttonPressed = false;
eventState.pointerMovedAfterPress = false;
break;
case KeyPress:
inputLength = XLookupString(&event->xkey, buffer, 1, &keysym, NULL);
GManager->operator[](eventState.currentActiveWidget)->onKeyPress(buffer[0]);
//std::cout<<keyCode<<std::endl;
break;
case KeyRelease:
inputLength = XLookupString(&event->xkey, buffer, 1, &keysym, NULL);
GManager->operator[](eventState.currentActiveWidget)->onKeyRelease(buffer[0]);
break;
case ConfigureNotify:
std::cout << "ReConfigured" << std::endl;
std::cout << event->xconfigure.width << " " << event->xconfigure.height << std::endl;
//std::cout<<event->xclient.data.<<" "<<event->xresizerequest.height<<std::endl;
break;
default:
std::cout << "Event not handled ID = " << event->type << std::endl;
break;
}
}