-
Notifications
You must be signed in to change notification settings - Fork 47
/
CamWnd.h
202 lines (148 loc) · 5.59 KB
/
CamWnd.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
#pragma once
#include "iscenegraph.h"
#include "imousetool.h"
#include "icameraview.h"
#include "irender.h"
#include "wxutil/GLWidget.h"
#include "wxutil/FreezePointer.h"
#include "wxutil/WindowPosition.h"
#include "wxutil/XmlResourceBasedWidget.h"
#include "wxutil/event/KeyEventFilter.h"
#include "wxutil/MouseToolHandler.h"
#include <wx/wxprec.h>
#include <wx/glcanvas.h>
#include <wx/timer.h>
#include "render/View.h"
#include "Camera.h"
#include "Rectangle.h"
#include <memory>
#include "util/Noncopyable.h"
#include <sigc++/connection.h>
#include "tools/CameraMouseToolEvent.h"
const int CAMWND_MINSIZE_X = 240;
const int CAMWND_MINSIZE_Y = 200;
class SelectionTest;
namespace ui
{
class CamWnd :
public wxEvtHandler,
public ICameraView,
public IFreeMoveView,
public scene::Graph::Observer,
public util::Noncopyable,
public sigc::trackable,
private wxutil::XmlResourceBasedWidget,
protected wxutil::MouseToolHandler
{
private:
// Overall panel including toolbar and GL widget
wxPanel* _mainWxWidget;
// The ID of this window
int _id;
static int _maxId;
render::View _view;
// The contained camera
Camera _camera;
static ShaderPtr _faceHighlightShader;
static ShaderPtr _primitiveHighlightShader;
wxutil::FreezePointer _freezePointer;
// Is true during an active drawing process
bool _drawing;
// The GL widget
wxutil::GLWidget* _wxGLWidget;
std::size_t _mapValidHandle;
wxTimer _timer;
bool _timerLock; // to avoid double-timer-firings
sigc::connection _glExtensionsInitialisedNotifier;
wxutil::KeyEventFilterPtr _escapeListener;
public:
// Constructor and destructor
CamWnd(wxWindow* parent);
virtual ~CamWnd();
// The unique ID of this camwindow
int getId();
// ICameraView implementation
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;
void update();
// The callback when the scene gets changed
void onSceneGraphChange() override;
static void captureStates();
static void releaseStates();
Camera& getCamera();
const Vector3& getCameraOrigin() const override;
void setCameraOrigin(const Vector3& origin) override;
const Vector3& getRightVector() const override;
const Vector3& getUpVector() const override;
const Vector3& getForwardVector() const override;
const Vector3& getCameraAngles() const override;
void setCameraAngles(const Vector3& angles) override;
const Frustum& getViewFrustum() const;
// greebo: This measures the rendering time during a 360° turn of the camera.
void benchmark();
// This tries to find brushes above/below the current camera position and moves the view upwards/downwards
void changeFloor(const bool up);
wxutil::GLWidget* getwxGLWidget() const { return _wxGLWidget; }
wxWindow* getMainWidget() const;
void enableFreeMove() override;
void disableFreeMove() override;
bool freeMoveEnabled() const override;
void jumpToObject(SelectionTest& selectionTest);
// Enables/disables the (ordinary) camera movement (non-freelook)
void addHandlersMove();
void removeHandlersMove();
// Increases/decreases the far clip plane distance
void farClipPlaneIn();
void farClipPlaneOut();
void startRenderTime();
void stopRenderTime();
void onForwardKey(KeyEventType eventType);
void onBackwardKey(KeyEventType eventType);
void onLeftKey(KeyEventType eventType);
void onRightKey(KeyEventType eventType);
void onUpKey(KeyEventType eventType);
void onDownKey(KeyEventType eventType);
protected:
void handleFreeMoveKeyEvent(KeyEventType eventType, unsigned int movementFlags);
// 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:
void constructGUIComponents();
void constructToolbar();
void setFarClipButtonSensitivity();
void onRenderModeButtonsChanged(wxCommandEvent& ev);
void updateActiveRenderModeButton();
void onFarClipPlaneOutClick(wxCommandEvent& ev);
void onFarClipPlaneInClick(wxCommandEvent& ev);
void onStartTimeButtonClick(wxCommandEvent& ev);
void onStopTimeButtonClick(wxCommandEvent& ev);
void updateToolbarVisibility();
void Cam_Draw();
bool onRender();
void drawTime();
CameraMouseToolEvent createMouseEvent(const Vector2& point, const Vector2& delta = Vector2(0, 0));
void onGLResize(wxSizeEvent& ev);
void onMouseScroll(wxMouseEvent& ev);
void onGLMouseButtonPress(wxMouseEvent& ev);
void onGLMouseButtonRelease(wxMouseEvent& ev);
void onGLMouseMove(wxMouseEvent& ev);
// Mouse motion callback used in freelook mode only, processes deltas
void handleGLMouseMoveFreeMoveDelta(int x, int y, unsigned int state);
void onGLExtensionsInitialised();
void onFrame(wxTimerEvent& ev);
};
/**
* Shared pointer typedef.
*/
typedef std::shared_ptr<CamWnd> CamWndPtr;
typedef std::weak_ptr<CamWnd> CamWndWeakPtr;
} // namespace