/
TexTool.h
292 lines (224 loc) · 8.14 KB
/
TexTool.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#pragma once
#include "icommandsystem.h"
#include "wxutil/window/TransientWindow.h"
#include "math/Vector3.h"
#include "math/AABB.h"
#include "ishaders.h"
#include "iinteractiveview.h"
#include "iradiant.h"
#include "iselection.h"
#include "iregistry.h"
#include <sigc++/connection.h>
#include <sigc++/trackable.h>
#include "wxutil/MouseToolHandler.h"
#include "tools/TextureToolMouseEvent.h"
#include "render/View.h"
#include "TexToolItem.h"
class Winding;
class Patch;
namespace wxutil { class GLWidget; }
namespace ui
{
namespace
{
const std::string RKEY_TEXTOOL_ROOT = "user/ui/textures/texTool/";
const std::string RKEY_FACE_VERTEX_SCALE_PIVOT_IS_CENTROID = RKEY_TEXTOOL_ROOT + "faceVertexScalePivotIsCentroid";
}
class TexTool;
typedef std::shared_ptr<TexTool> TexToolPtr;
class TexTool :
public wxutil::TransientWindow,
public IInteractiveView,
public sigc::trackable,
protected wxutil::MouseToolHandler
{
private:
// GL widget
wxutil::GLWidget* _glWidget;
render::View _view;
// The shader we're working with (shared ptr)
MaterialPtr _shader;
// A reference to the SelectionInfo structure (with the counters)
const SelectionInfo& _selectionInfo;
// The extents of the selected objects in texture space
AABB _selAABB;
// The extents of the visible rectangle in texture space
AABB _texSpaceAABB;
// The dimensions of the GL widget in pixels.
Vector2 _windowDims;
// The zoomfactor of this window (default = 1.1)
float _zoomFactor;
// The currently active objects in the textool window
textool::TexToolItemVec _items;
// The draggable selection rectangle
textool::Rectangle _selectionRectangle;
// The rectangle defining the manipulation's start and end point
textool::Rectangle _manipulateRectangle;
// The rectangle defining the moveOrigin operation's start and end point
textool::Rectangle _moveOriginRectangle;
// TRUE if we are in selection mode
bool _dragRectangle;
// TRUE if a manipulation is currently ongoing
bool _manipulatorMode;
// TRUE if the texspace center is being dragged around
bool _viewOriginMove;
// The current grid size
float _grid;
// TRUE if the grid is active
bool _gridActive;
// For idle callbacks
bool _updateNeeded;
sigc::connection _selectionChanged;
sigc::connection _undoHandler;
sigc::connection _redoHandler;
private:
// This is where the static shared_ptr of the singleton instance is held.
static TexToolPtr& InstancePtr();
/* TransientWindow callbacks */
virtual void _preHide();
virtual void _preShow();
void setGridActive(bool active);
/** greebo: Selects all items that are related / connected
* to the currently selected ones. E.g. if one patch
* vertex is selected, all the vertices of the patch
* get selected as well.
*/
void selectRelatedItems();
/** greebo: Helper methods that start/end an undoable operation.
*/
void beginOperation();
void endOperation(const std::string& commandName);
// Creates, packs and connects the child widgets
void populateWindow();
/** greebo: Calculates the extents the selection has in
* texture space.
*
* @returns: the reference to the internal AABB with the z-component set to 0.
* Can return an invalid AABB as well (if no selection was found).
*/
AABB& getExtents();
/** greebo: Returns the AABB of the currently visible texture space.
*/
AABB& getVisibleTexSpace();
/** greebo: Recalculates and relocates the visible texture space.
* It's basically centered onto the current selection
* with the extents multiplied by the default zoomFactor.
*/
void recalculateVisibleTexSpace();
/** greebo: Visualises the U/V coordinates by drawing the points
* into the "texture space".
*/
void drawUVCoords();
/** greebo: Draws the grid into the visible texture space.
*/
void drawGrid();
/** greebo: Loads all the relevant data from the
* selectionsystem and prepares the member variables for drawing.
*/
void update();
/** greebo: Passes the given visitor to every Item in the hierarchy.
*/
void foreachItem(textool::ItemVisitor& visitor);
/** greebo: Returns the number of selected TexToolItems.
*/
int countSelected();
/** greebo: Sets all selectables to <selected>
* If selected == false and no items are selected,
* the call is propagated to the main window to
* trigger a scene deselection.
*/
bool setAllSelected(bool selected);
/** greebo: Returns a list of selectables for the given rectangle.
*/
textool::TexToolItemVec getSelectables(const textool::Rectangle& rectangle);
/** greebo: Returns a list of selectables for the given point.
* (A small rectangle is constructed to perform the selection test)
*/
textool::TexToolItemVec getSelectables(const Vector2& coords);
/** greebo: These two get called by the callback and handle the event
*
* @coords: this has already been converted into texture space.
*/
void doMouseUp(const Vector2& coords, wxMouseEvent& event);
void doMouseDown(const Vector2& coords, wxMouseEvent& event);
void doMouseMove(const Vector2& coords, wxMouseEvent& event);
/** greebo: Converts the mouse/window coordinates into texture coords.
*/
Vector2 getTextureCoords(const double& x, const double& y);
bool onGLDraw();
void onGLResize(wxSizeEvent& ev);
// The callbacks for capturing the mouse events
void onMouseUp(wxMouseEvent& ev);
void onMouseDown(wxMouseEvent& ev);
void onMouseMotion(wxMouseEvent& ev);
void onMouseScroll(wxMouseEvent& ev);
// The keyboard callback to catch the ESC key
void onKeyPress(wxKeyEvent& ev);
// UndoSystem event handler
void onUndoRedoOperation();
public:
TexTool();
/**
* greebo: Shutdown listeners de-registering from
* the SelectionSystem, saving the window state, etc.
*/
void onMainFrameShuttingDown();
/** greebo: This is the static accessor method containing
* the static instance of the TexTool class. Use this to access
* the public member methods like toggle() and shutdown().
*/
static TexTool& Instance();
SelectionTestPtr createSelectionTestForPoint(const Vector2& point) override;
int getDeviceWidth() const override;
int getDeviceHeight() const override;
const VolumeTest& getVolumeTest() const override;
// Request a deferred update of the UI elements
void queueDraw() override;
void forceRedraw() override;
/** greebo: Updates the GL window
*/
void draw();
/** greebo: Increases/Decreases the grid size.
*/
void gridUp();
void gridDown();
// Idle callback, used for deferred updates
void onIdle(wxIdleEvent& ev);
/** greebo: Snaps the current TexTool selection to the active grid.
*/
void snapToGrid();
/** greebo: Merges the selected items in terms of their UV coordinates.
* Mainly useful for stitching patch control vertices.
*/
void mergeSelectedItems();
/** greebo: This flips the selection in texture space. This is the equivalent
* of the according buttons in the Surface Inspector, but it only affects
* the items selected in the TexTool.
*
* @axis: 0 = s-Axis flip, 1 = t-axis flip
*/
void flipSelected(int axis);
/** greebo: Static command targets
*/
static void toggle(const cmd::ArgumentList& args);
static void texToolGridUp(const cmd::ArgumentList& args);
static void texToolGridDown(const cmd::ArgumentList& args);
static void texToolSnapToGrid(const cmd::ArgumentList& args);
static void texToolMergeItems(const cmd::ArgumentList& args);
static void texToolFlipS(const cmd::ArgumentList& args);
static void texToolFlipT(const cmd::ArgumentList& args);
static void selectRelated(const cmd::ArgumentList& args);
/** greebo: Registers the commands in the EventManager
*/
static void registerCommands();
protected:
MouseTool::Result processMouseDownEvent(const MouseToolPtr& tool, const Vector2& point) override;
MouseTool::Result processMouseUpEvent(const MouseToolPtr& tool, const Vector2& point) override;
MouseTool::Result processMouseMoveEvent(const MouseToolPtr& tool, int x, int y) override;
void startCapture(const MouseToolPtr& tool) override;
void endCapture() override;
IInteractiveView& getInteractiveView() override;
private:
TextureToolMouseEvent createMouseEvent(const Vector2& point, const Vector2& delta = Vector2(0, 0));
};
} // namespace ui