-
Notifications
You must be signed in to change notification settings - Fork 0
/
MouseListener.cpp
96 lines (90 loc) · 2.98 KB
/
MouseListener.cpp
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
#include "MouseListener.h"
void MouseListener::mouseDownEvent( vl::EMouseButton btn, int x, int y ) {
if ( btn == vl::MiddleButton ) {
m_mode = Mode_rotate;
m_x = x;
m_y = y;
} else if ( btn == vl::RightButton ) {
m_mode = Mode_translate;
m_x = x;
m_y = y;
m_window->screenToWorld( x, y, m_tile_x, m_tile_y );
} else if ( btn == vl::LeftButton ) {
int wx = 0;
int wy = 0;
m_window->screenToWorld( x, y, wx, wy );
m_window->place( wx, wy, true );
m_mode = Mode_highlight;
}
}
void MouseListener::mouseUpEvent( vl::EMouseButton btn, int x, int y ) {
if ( btn == vl::MiddleButton && m_mode == Mode_rotate ) {
m_mode = Mode_none;
} else if ( btn == vl::RightButton && m_mode == Mode_translate ) {
m_mode = Mode_none;
} else if ( btn == vl::LeftButton && m_mode == Mode_highlight ) {
m_mode = Mode_none;
}
}
void MouseListener::mouseMoveEvent( int x, int y ) {
switch ( m_mode ) {
case Mode_rotate:
if ( x - m_x > 10 ) {
if ( y > (mCamera->viewport()->height() / 2) ) {
m_window->rotateRight();
} else {
m_window->rotateLeft();
}
m_mode = Mode_none;
} else if ( m_x - x > 10 ) {
if ( y > (mCamera->viewport()->height() / 2) ) {
m_window->rotateLeft();
} else {
m_window->rotateRight();
}
m_mode = Mode_none;
} else if ( m_y - y > 10 ) {
if ( x > (mCamera->viewport()->width() / 2) ) {
m_window->rotateRight();
} else {
m_window->rotateLeft();
}
m_mode = Mode_none;
} else if ( y - m_y > 10 ) {
if ( x > (mCamera->viewport()->width() / 2) ) {
m_window->rotateLeft();
} else {
m_window->rotateRight();
}
m_mode = Mode_none;
}
break;
case Mode_translate:
m_window->focusTileAt( m_tile_x, m_tile_y, x, y );
break;
case Mode_highlight: {
int wx = 0;
int wy = 0;
m_window->screenToWorld( x, y, wx, wy );
m_window->highlight( wx, wy );
m_window->place( wx, wy, false );
break;
}
default: {
int wx = 0;
int wy = 0;
m_window->screenToWorld( x, y, wx, wy );
m_window->highlight( wx, wy );
break;
}
}
}
void MouseListener::enableEvent( bool enabled ) {
}
void MouseListener::mouseWheelEvent( int rotation ) {
if ( rotation > 0 ) {
m_window->zoomIn();
} else {
m_window->zoomOut();
}
}