/
XYWnd.h
211 lines (153 loc) · 5.49 KB
/
XYWnd.h
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#pragma once
#include "iscenegraph.h"
#include "iorthoview.h"
#include "igl.h"
#include "math/Vector3.h"
#include "math/Matrix4.h"
#include "math/Vector4.h"
#include "wxutil/FreezePointer.h"
#include "wxutil/event/KeyEventFilter.h"
#include "wxutil/GLWidget.h"
#include <wx/cursor.h>
#include <wx/stopwatch.h>
#include <sigc++/connection.h>
#include "render/View.h"
#include "imousetool.h"
#include "tools/XYMouseToolEvent.h"
#include "wxutil/MouseToolHandler.h"
#include "XYRenderer.h"
namespace ui
{
class XYWnd :
public wxEvtHandler,
public IOrthoView,
public scene::Graph::Observer,
protected wxutil::MouseToolHandler
{
protected:
// Unique ID of this XYWnd
int _id;
wxutil::GLWidget* _wxGLWidget;
bool _drawing;
bool _updateRequested;
// The maximum/minimum values of a coordinate
double _minWorldCoord;
double _maxWorldCoord;
// The timer used for chase mouse xyview movements
wxStopWatch _chaseMouseTimer;
wxutil::FreezePointer _freezePointer;
wxCursor _defaultCursor;
wxCursor _crossHairCursor;
bool _chasingMouse;
double _scale;
Vector3 _origin;
render::View _view;
// Shaders used for highlighting nodes
static XYRenderer::HighlightShaders _highlightShaders;
Vector3 _mousePosition;
EViewType _viewType;
int _contextMenu_x;
int _contextMenu_y;
bool _contextMenu;
wxutil::KeyEventFilterPtr _escapeListener;
// Save the current button state
unsigned int _eventState;
bool _isActive;
int _chasemouseCurrentX;
int _chasemouseCurrentY;
int _chasemouseDeltaX;
int _chasemouseDeltaY;
Matrix4 _projection;
Matrix4 _modelView;
int _width;
int _height;
sigc::connection _sigCameraChanged;
IGLFont::Ptr _font;
public:
// Constructor, this allocates the GL widget
XYWnd(int uniqueId, wxWindow* parent);
// Destructor
virtual ~XYWnd();
int getId() const;
wxutil::GLWidget* getGLWidget() const { return _wxGLWidget; }
SelectionTestPtr createSelectionTestForPoint(const Vector2& point) override;
const VolumeTest& getVolumeTest() const override;
int getDeviceWidth() const override;
int getDeviceHeight() const override;
void queueDraw() override;
void forceRedraw() override;
// Capture and release the selected shader
static void captureStates();
static void releaseStates();
// Returns the long type string ("XY Top", "YZ Side", "XZ Front") for use in window titles
static const std::string getViewTypeTitle(EViewType viewtype);
// Returns the short type string (XY, XZ, YZ)
static const std::string getViewTypeStr(EViewType viewtype);
void positionView(const Vector3& position);
const Vector3& getOrigin() const override;
void setOrigin(const Vector3& origin) override;
void scroll(int x, int y) override;
Vector4 getWindowCoordinates();
void draw();
void drawBlockGrid();
void drawGrid();
Vector3 convertXYToWorld(int x, int y);
void snapToGrid(Vector3& point) override;
void mouseToPoint(int x, int y, Vector3& point);
void zoomIn() override;
void zoomOut() override;
void zoomInOn( wxPoint cursor, int zoom );
void setActive(bool b);
bool isActive() const;
void setCursorType(IOrthoView::CursorType type) override;
void updateModelview();
void updateProjection();
virtual void setViewType(EViewType n);
EViewType getViewType() const override;
void setScale(float f);
float getScale() const override;
int getWidth() const override;
int getHeight() const override;
// greebo: This gets called upon scene change
void onSceneGraphChange() override;
void updateFont();
protected:
// Disconnects all widgets and unsubscribes as observer
void destroyXYView();
// Required overrides being a MouseToolHandler
virtual MouseTool::Result processMouseDownEvent(const MouseToolPtr& tool, const Vector2& point) override;
virtual MouseTool::Result processMouseUpEvent(const MouseToolPtr& tool, const Vector2& point) override;
virtual MouseTool::Result processMouseMoveEvent(const MouseToolPtr& tool, int x, int y) override;
virtual void startCapture(const MouseToolPtr& tool) override;
virtual void endCapture() override;
virtual IInteractiveView& getInteractiveView() override;
private:
XYMouseToolEvent createMouseEvent(const Vector2& point, const Vector2& delta = Vector2(0, 0));
void ensureFont();
void onContextMenu();
void drawSizeInfo(int nDim1, int nDim2, const Vector3& vMinBounds, const Vector3& vMaxBounds);
void drawCameraIcon();
float getZoomedScale(int steps);
// callbacks
bool checkChaseMouse(unsigned int state);
void performChaseMouse();
void onIdle(wxIdleEvent& ev);
void onCameraMoved();
// The method responsible for mouseMove situations according to <event>
void handleGLMouseMotion(int x, int y, unsigned int state, bool isDelta);
// Active mousetools might capture the mouse, this is handled here
void handleGLCapturedMouseMotion(const MouseToolPtr& tool, int x, int y, unsigned int state);
// wxGLWidget-attached render method
bool onRender();
void onGLResize(wxSizeEvent& ev);
void onGLWindowScroll(wxMouseEvent& ev);
void onGLMouseButtonPress(wxMouseEvent& ev);
void onGLMouseButtonRelease(wxMouseEvent& ev);
void onGLMouseMove(wxMouseEvent& ev);
};
/**
* Shared pointer typedefs.
*/
typedef std::shared_ptr<XYWnd> XYWndPtr;
typedef std::weak_ptr<XYWnd> XYWndWeakPtr;
}