|
|
@ -88,53 +88,33 @@ class ThinScroller: NSScroller { |
|
|
|
|
|
|
|
|
|
|
|
class DraggableClipView: NSClipView { |
|
|
|
class DraggableClipView: NSClipView { |
|
|
|
private var clickPoint: NSPoint! |
|
|
|
private var clickPoint: NSPoint! |
|
|
|
private var originalOrigin: NSPoint! |
|
|
|
|
|
|
|
private var trackingArea: NSTrackingArea? |
|
|
|
private var trackingArea: NSTrackingArea? |
|
|
|
|
|
|
|
|
|
|
|
override func mouseDown(with event: NSEvent) { |
|
|
|
override func mouseDown(with event: NSEvent) { |
|
|
|
print("2") |
|
|
|
|
|
|
|
super.mouseDown(with: event) |
|
|
|
super.mouseDown(with: event) |
|
|
|
clickPoint = event.locationInWindow |
|
|
|
clickPoint = event.locationInWindow |
|
|
|
originalOrigin = bounds.origin |
|
|
|
|
|
|
|
print("Click point \(clickPoint!)") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let keepOn = true |
|
|
|
var gestureInProgress = true |
|
|
|
while keepOn { |
|
|
|
while gestureInProgress { |
|
|
|
let newEvent = window?.nextEvent(matching: [.leftMouseDragged, .leftMouseUp]) |
|
|
|
let newEvent = window?.nextEvent(matching: [.leftMouseDragged, .leftMouseUp, .leftMouseDown]) |
|
|
|
switch newEvent?.type { |
|
|
|
switch newEvent?.type { |
|
|
|
case .leftMouseDragged: |
|
|
|
case .leftMouseDragged: |
|
|
|
print("Hello 1") |
|
|
|
let newPoint = newEvent?.locationInWindow |
|
|
|
let scale = (superview as? NSScrollView)?.magnification ?? 1.0 |
|
|
|
let xCoOrdinate = clickPoint.x - (newPoint?.x ?? 0) |
|
|
|
let newPoint = event.locationInWindow |
|
|
|
let newOrigin = NSPoint(x: bounds.origin.x + xCoOrdinate, |
|
|
|
let newOrigin = NSPoint(x: originalOrigin.x + (clickPoint.x - newPoint.x) / scale, |
|
|
|
y: 0) |
|
|
|
y: originalOrigin.y + (clickPoint.y - newPoint.y) / scale) |
|
|
|
|
|
|
|
let constrainedRect = constrainBoundsRect(NSRect(origin: newOrigin, size: bounds.size)) |
|
|
|
let constrainedRect = constrainBoundsRect(NSRect(origin: newOrigin, size: bounds.size)) |
|
|
|
scroll(to: constrainedRect.origin) |
|
|
|
scroll(to: constrainedRect.origin) |
|
|
|
superview?.reflectScrolledClipView(self) |
|
|
|
superview?.reflectScrolledClipView(self) |
|
|
|
return |
|
|
|
case .leftMouseDown: |
|
|
|
|
|
|
|
clickPoint = event.locationInWindow |
|
|
|
|
|
|
|
case .leftMouseUp: |
|
|
|
|
|
|
|
clickPoint = nil |
|
|
|
|
|
|
|
gestureInProgress = false |
|
|
|
default: |
|
|
|
default: |
|
|
|
print("Hello2") |
|
|
|
print("Default case is happening \(event.type)") |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override func mouseDragged(with event: NSEvent) { |
|
|
|
|
|
|
|
print("1") |
|
|
|
|
|
|
|
super.mouseDragged(with: event) |
|
|
|
|
|
|
|
// Account for a magnified parent scrollview. |
|
|
|
|
|
|
|
let scale = (superview as? NSScrollView)?.magnification ?? 1.0 |
|
|
|
|
|
|
|
let newPoint = event.locationInWindow |
|
|
|
|
|
|
|
let newOrigin = NSPoint(x: originalOrigin.x + (clickPoint.x - newPoint.x) / scale, |
|
|
|
|
|
|
|
y: originalOrigin.y + (clickPoint.y - newPoint.y) / scale) |
|
|
|
|
|
|
|
let constrainedRect = constrainBoundsRect(NSRect(origin: newOrigin, size: bounds.size)) |
|
|
|
|
|
|
|
scroll(to: constrainedRect.origin) |
|
|
|
|
|
|
|
superview?.reflectScrolledClipView(self) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override func mouseUp(with event: NSEvent) { |
|
|
|
|
|
|
|
print("3") |
|
|
|
|
|
|
|
super.mouseUp(with: event) |
|
|
|
|
|
|
|
clickPoint = nil |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override func updateTrackingAreas() { |
|
|
|
override func updateTrackingAreas() { |
|
|
|