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
|
#ifndef shaveCursorCtx_h
#define shaveCursorCtx_h
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
//Qt headers must be included before any others !!!
#include <QtCore/QEvent>
#include <QtCore/QElapsedTimer>
#include <QtGui/QMouseEvent>
#include <QtGui/QTabletEvent>
#if QT_VERSION < 0x050000
# include <QtGui/QApplication>
# include <QtGui/QWidget>
#else
# include <QtWidgets/QApplication>
# include <QtWidgets/QWidget>
#endif
#include <vector>
#include <maya/M3dView.h>
#include <maya/MCursor.h>
#include <maya/MDagPathArray.h>
#include <maya/MEventMessage.h>
#include <maya/MGlobal.h>
#include <maya/MPxContext.h>
#include <maya/MString.h>
#include <maya/MMatrix.h>
#include "shaveHairShape.h"
#include "shaveSDKTYPES.h"
#if MAYA_API_VERSION < 20180000
class MEvent;
#endif
class shaveBrushManip;
class shaveCursorCtx;
//Qt mouse test -- vlad|17Mar2010
class shaveQtMouseWatcher : public QObject
{
public:
shaveQtMouseWatcher(shaveCursorCtx* ctx)
{
m_ctx = ctx;
m_busy = false;
}
virtual ~shaveQtMouseWatcher(){}
static bool IsBusy() {return m_busy;}
protected:
bool eventFilter(QObject* obj, QEvent* event);
private:
shaveCursorCtx* m_ctx;
static bool m_busy;
};
void CheckGlobalQtViewport20Tracker();
class globalQtViewport20Tracker : public QObject
{
public:
globalQtViewport20Tracker(){}
virtual ~globalQtViewport20Tracker(){}
protected:
bool eventFilter(QObject* obj, QEvent* event);
MMatrix worldToCam;
};
//#define GLOBAL_FALLBACK
#ifdef GLOBAL_FALLBACK
void CheckAndSetGlobalQtWatcher();
void SetEventsHappen();
bool GetEventsHappen();
void ClearEvents();
bool IsMouseDown();
bool IsToolActive();
class globalQtMouseWatcher : public QObject
{
public:
globalQtMouseWatcher(){}
virtual ~globalQtMouseWatcher(){}
protected:
bool eventFilter(QObject* obj, QEvent* event);
};
void StartQTimer();
QElapsedTimer& GetQTimer();
qint64 GetLastMoveTime();
void SetLastMoveTime(qint64 t);
#endif
class NotBusyEvent : public QEvent {
public:
enum {aType = 4500};
NotBusyEvent():QEvent((QEvent::Type)aType){};
};
//LARGE_INTEGER GetLastMoveTime();
class shaveCursorCtx : public MPxContext
{
friend class shaveQtMouseWatcher;
public:
shaveCursorCtx();
virtual ~shaveCursorCtx();
virtual void deleteAction() {}
void enableFalloff(bool enable) { mFalloffEnabled = enable; }
float getBrushSize() const { return mBrushSize; }
float getBrushStren() const { return mBrushStren; }
virtual void getClassName(MString& name) const = 0;
bool isFalloffEnabled() const { return mFalloffEnabled; }
bool isResizing() const { return mIsResizing; }
void resizeKeyPressed(bool isPressed);
void setBrushSize(float size);
void setBrushStren(float stren) { mBrushStren = stren; }
//
// 'screenPos' is normalized to the range 0.0 to 1.0 for both view
// dimensions. Thus (0, 0) is the lower left corner of the view and
// (1, 1) is the upper right.
//
// If a derived class is only interested in mouse clicks, not strokes,
// then it should perform its click operation in this method and then
// return MS::kEndOfFile to indicate that the remainder of the stroke
// can be ignored. Otherwise it should return MS::kSuccess on success
// or any of the other failure codes for failure.
//
virtual MStatus strokeBegin(
VERT& eyePoint,
VERT& viewDir,
VERT& upDir,
VERT& screenPos,
VERT& worldPos
) { return MS::kSuccess; }
//
// 'screenPos' and 'screenDelta' are normalized to the range 0.0 to 1.0
// for both view dimensions. Thus (0, 0) is the lower left corner of
// the view and (1, 1) is the upper right. If the drag extends beyond
// the edges of the view then the values passed in may lie outside that
// range.
//
// Derived classes are guaranteed that the position of the cursor in
// the final strokeDrag() will be identical to that when strokeEnd() is
// called.
//
virtual MStatus strokeDrag(
VERT& screenPos,
VERT& worldPos,
VERT& screenDelta,
VERT& worldDelta
) { return MS::kSuccess; }
virtual MStatus strokeEnd() { return MS::kSuccess; }
protected:
typedef enum
{
kMouseMoved,
kMouseLeftWindow
} MouseEventType;
typedef struct
{
MouseEventType type;
MNativeWindowHdl window;
int x;
int y;
} EventData;
//
// Internal Methods
//
static void activeViewChanged(void* clientData);
void catchActiveViewEvents();
void cleanupStroke();
static shaveCursorCtx*
getActiveCtx() { return mActiveCtx; }
MPoint getWorldPt(
const M3dView& view, short viewX, short viewY
) const;
void hideHair();
void leaveWindow(MNativeWindowHdl window, int x, int y);
void pointerMoved(MNativeWindowHdl window, int x, int y);
void motionEventHandler(EventData* event);
void uncatchActiveViewEvents();
void unhideHair();
#if defined _WIN32
static LRESULT CALLBACK
WinEventHandler(int nCode, WPARAM wParam, LPARAM lParam);
#elif defined LINUX
static void XEventHandler(
Widget widget,
XtPointer clientData,
XEvent* event,
Boolean* continueDispatch
);
#elif defined OSMac_
//Qt stuff should be used
#endif
static shaveCursorCtx* mActiveCtx;
MCallbackId mActiveViewChangedId;
float mBrushSize;
float mBrushStren;
double mCentroidFraction;
bool mDoingStroke;
static MCursor mDoubleArrowCursor;
MNativeWindowHdl mEventWindow;
bool mFalloffEnabled;
bool mFastBrush;
MDagPathArray mHiddenHairNodes;
bool mIsActive;
bool mIsResizing;
shaveBrushManip* mManip;
MDagPath mProxyPath;
bool mResizeKeyPressed;
short mStrokeLastX;
short mStrokeLastY;
float mStrokeStartBrushSize;
VERT mStrokeStartWorld;
short mStrokeStartX;
short mStrokeStartY;
shaveHairShape::HairDisplayMode
mTargetDisplayMode;
shaveHairShape* mTargetShape;
#ifdef _WIN32
HHOOK mMouseHookId;
bool mTrackingLeaveWindow;
#endif
private:
virtual MStatus doPress (MEvent& event, MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context){ return doPress(event);}
virtual MStatus doDrag (MEvent& event, MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context){ return doDrag(event);}
virtual MStatus doRelease (MEvent& event, MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context){ return doRelease(event);}
virtual MStatus doDrag(MEvent& event);
virtual MStatus doPress(MEvent& event);
virtual MStatus doRelease(MEvent& event);
virtual void toolOffCleanup();
virtual void toolOnSetup(MEvent& event);
};
#endif
|