diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 050084b56b..2a28b633cf 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -27,6 +27,7 @@ #include "slic3r/Utils/UndoRedo.hpp" #include "slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp" #include "slic3r/GUI/BitmapCache.hpp" +#include "slic3r/Utils/MacDarkMode.hpp" #include "GUI_App.hpp" #include "GUI_ObjectList.hpp" @@ -2139,6 +2140,9 @@ void GLCanvas3D::bind_event_handlers() m_canvas->Bind(wxEVT_GESTURE_ZOOM, &GLCanvas3D::on_gesture, this); m_canvas->Bind(wxEVT_GESTURE_ROTATE, &GLCanvas3D::on_gesture, this); m_canvas->EnableTouchEvents(wxTOUCH_ZOOM_GESTURE | wxTOUCH_ROTATE_GESTURE); +#if __WXOSX__ + initGestures(m_canvas->GetHandle(), m_canvas); // for UIPanGestureRecognizer allowedScrollTypesMask +#endif } } diff --git a/src/slic3r/Utils/MacDarkMode.hpp b/src/slic3r/Utils/MacDarkMode.hpp index b3574035e5..8a5dd30afe 100644 --- a/src/slic3r/Utils/MacDarkMode.hpp +++ b/src/slic3r/Utils/MacDarkMode.hpp @@ -1,6 +1,8 @@ #ifndef slic3r_MacDarkMode_hpp_ #define slic3r_MacDarkMode_hpp_ +#include + namespace Slic3r { namespace GUI { @@ -8,6 +10,9 @@ namespace GUI { extern bool mac_dark_mode(); extern double mac_max_scaling_factor(); extern void set_miniaturizable(void * window); + +void initGestures(void * view, wxEvtHandler * handler); + #endif diff --git a/src/slic3r/Utils/MacDarkMode.mm b/src/slic3r/Utils/MacDarkMode.mm index 8a85322e9c..040bebc2fd 100644 --- a/src/slic3r/Utils/MacDarkMode.mm +++ b/src/slic3r/Utils/MacDarkMode.mm @@ -6,6 +6,8 @@ #import #import +#include + @interface MacDarkMode : NSObject {} @end @@ -76,6 +78,8 @@ void set_miniaturizable(void * window) @end +/* edit column for wxTableView */ + #include #include #include @@ -98,6 +102,7 @@ void set_miniaturizable(void * window) @end +/* remove focused border for wxTextCtrl */ @implementation NSTextField (FocusRing) @@ -107,3 +112,93 @@ void set_miniaturizable(void * window) } @end + +/* gesture handle for Canvas3D */ + +@interface wxNSCustomOpenGLView : NSOpenGLView +{ +} +@end + + +@implementation wxNSCustomOpenGLView (Gesture) + +wxEvtHandler * _gestureHandler = nullptr; + +- (void) onGestureMove: (NSPanGestureRecognizer*) gesture +{ + wxPanGestureEvent evt; + NSPoint tr = [gesture translationInView: self]; + evt.SetDelta({(int) tr.x, (int) tr.y}); + [self postEvent:evt withGesture:gesture]; +} + +- (void) onGestureScale: (NSMagnificationGestureRecognizer*) gesture +{ + wxZoomGestureEvent evt; + evt.SetZoomFactor(gesture.magnification + 1.0); + [self postEvent:evt withGesture:gesture]; +} + +- (void) onGestureRotate: (NSRotationGestureRecognizer*) gesture +{ + wxRotateGestureEvent evt; + evt.SetRotationAngle(-gesture.rotation); + [self postEvent:evt withGesture:gesture]; +} + +- (void) postEvent: (wxGestureEvent &) evt withGesture: (NSGestureRecognizer* ) gesture +{ + NSPoint pos = [gesture locationInView: self]; + evt.SetPosition({(int) pos.x, (int) pos.y}); + if (gesture.state == NSGestureRecognizerStateBegan) + evt.SetGestureStart(); + else if (gesture.state == NSGestureRecognizerStateEnded) + evt.SetGestureEnd(); + _gestureHandler->ProcessEvent(evt); +} + +- (void) scrollWheel2:(NSEvent *)event +{ + if (_gestureHandler && event.hasPreciseScrollingDeltas) { + wxPanGestureEvent evt; + evt.SetDelta({(int)[event scrollingDeltaX], -(int)[event scrollingDeltaY]}); + _gestureHandler->ProcessEvent(evt); + } else { + [self scrollWheel2: event]; + } +} + ++ (void) load +{ + Method scrollWheel = class_getInstanceMethod([wxNSCustomOpenGLView class], @selector(scrollWheel:)); + Method scrollWheel2 = class_getInstanceMethod([wxNSCustomOpenGLView class], @selector(scrollWheel2:)); + method_exchangeImplementations(scrollWheel, scrollWheel2); +} + +- (void) initGesturesWithHandler: (wxEvtHandler*) handler +{ +// NSPanGestureRecognizer * pan = [[NSPanGestureRecognizer alloc] initWithTarget: self action: @selector(onGestureMove:)]; +// pan.numberOfTouchesRequired = 2; +// pan.allowedTouchTypes = 0; +// NSMagnificationGestureRecognizer * magnification = [[NSMagnificationGestureRecognizer alloc] initWithTarget: self action: @selector(onGestureScale:)]; +// NSRotationGestureRecognizer * rotation = [[NSRotationGestureRecognizer alloc] initWithTarget: self action: @selector(onGestureRotate:)]; +// [self addGestureRecognizer:pan]; +// [self addGestureRecognizer:magnification]; +// [self addGestureRecognizer:rotation]; + _gestureHandler = handler; +} + +@end + +namespace Slic3r { +namespace GUI { + +void initGestures(void * view, wxEvtHandler * handler) +{ + NSOpenGLView * glView = (NSOpenGLView *) view; + [glView initGesturesWithHandler: handler]; +} + +} +}