Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify behaviour of mouse-wheel and mouse-drag image scrolling #353

Open
wants to merge 18 commits into
base: horos
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f019988
Refactor DCMView image scrolling to establish scroll direction
DD-P Jun 16, 2018
84fb4a4
DCMView mouse drag-image scrolling conforms to reversed mouse wheel s…
DD-P Jun 16, 2018
1bb9be5
MPRDCMView reuses super's establishScrollModeFromInitialDragWithPoint
DD-P Jun 16, 2018
6c3ef0c
MPR image drag scroll delta defaults to 0.0
DD-P Jun 16, 2018
6dff1e7
MPR mouse drag-image scroll conforms to reversed mouse wheel setting
DD-P Jun 16, 2018
90c2c84
Corrected MPR mouse drag-image scrolling to use height when vertical
DD-P Jun 16, 2018
a2c86fb
CPRMPRDCMView reuses establishScrollModeFromInitialDragWithPoint
DD-P Jun 16, 2018
da38f17
CPRMPRDCMView mouse drag-image scrolling conforms to reversed mouse w…
DD-P Jun 16, 2018
d30c144
Corrected CPRMPRDCMView's mouse drag-image scrolling use of height / …
DD-P Jun 16, 2018
fb87548
Refactor OrthogonalMPRView for ScrollMode
DD-P Jun 16, 2018
64875f7
OrthogonalMPRView mouse drag-image scrolling conforms to reversed mou…
DD-P Jun 16, 2018
1d8606c
DCMView corrected: mouse wheel and drag image scrolls in normal and n…
DD-P Jun 16, 2018
68e6b33
Orthogonal view corrected for normal / natural scroll settings
DD-P Jun 16, 2018
030c0b5
Browser scrolling works with normal and natural system scroll settings
DD-P Jun 16, 2018
23e0058
MPR DCMView works with normal and natural system scroll settings
DD-P Jun 16, 2018
7847b0b
Curved MPR DCMView works with normal and natural system scroll settings
DD-P Jun 16, 2018
e2c7490
Tidy up
DD-P Jun 16, 2018
225ab21
Finalise corrections to mouse-wheel / mouse-drag behaviour
DD-P Jun 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Horos/Sources/BrowserController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9263,10 +9263,11 @@ - (void)scrollWheel: (NSEvent *)theEvent
{
float reverseScrollWheel;

if ([[NSUserDefaults standardUserDefaults] boolForKey: @"Scroll Wheel Reversed"])
reverseScrollWheel = -1.0;
else
reverseScrollWheel = 1.0;
if ([imageView shouldReverseScrollDirectionForMouseWheel]) {
reverseScrollWheel = -1.0;
} else {
reverseScrollWheel = 1.0;
}

float change = reverseScrollWheel * [theEvent deltaY];

Expand Down
28 changes: 14 additions & 14 deletions Horos/Sources/CPRMPRDCMView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1977,30 +1977,30 @@ - (void) mouseUp:(NSEvent *)theEvent
dontCheckRoiChange = NO;
}


// Probably could use MPRDCMView's method if refactored to a shared parent class as code is identical

- (void) mouseDraggedImageScroll:(NSEvent *) event
{
[self checkCursor];

NSPoint current = [self currentPointInView: event];

if( scrollMode == 0)
if (scrollMode == ScrollModeReady)
{
if( fabs( start.x - current.x) < fabs( start.y - current.y))
{
if( fabs( start.y - current.y) > 3) scrollMode = 1;
}
else if( fabs( start.x - current.x) >= fabs( start.y - current.y))
{
if( fabs( start.x - current.x) > 3) scrollMode = 2;
}
[self establishScrollModeFromInitialDragWithPoint: current];
}

float delta;
float delta = 0.0;

if( scrollMode == 1)
delta = ((previous.y - current.y) * 512. )/ ([self convertSizeToBacking: self.frame.size].width/2);
else
if (scrollMode == ScrollModeVertical) {
delta = ((previous.y - current.y) * 512. )/ ([self convertSizeToBacking: self.frame.size].height/2);
} else if (scrollMode == ScrollModeHorizontal) {
delta = ((current.x - previous.x) * 512. )/ ([self convertSizeToBacking: self.frame.size].width/2);
}

if ([self shouldReverseScrollDirectionForMouseDrag]) {
delta *= -1.0;
}

[self restoreCamera];
windowController.lowLOD = YES;
Expand Down
9 changes: 9 additions & 0 deletions Horos/Sources/DCMView.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ typedef NS_ENUM(short, ToolMode)
//tOvalAngle // 31
};

typedef NS_ENUM(NSUInteger, ScrollMode) {
ScrollModeReady = 0,
ScrollModeVertical,
ScrollModeHorizontal
};

extern NSString * const HorosPasteboardType;
extern NSString * const HorosPasteboardTypePlugin;
// these older pasteboard keys are deprecated, but they still work
Expand Down Expand Up @@ -582,6 +588,9 @@ typedef enum {DCMViewTextAlignLeft, DCMViewTextAlignCenter, DCMViewTextAlignRigh
- (void)mouseDraggedZoom:(NSEvent *)event;
- (void)mouseDraggedTranslate:(NSEvent *)event;
- (void)mouseDraggedRotate:(NSEvent *)event;
- (void) establishScrollModeFromInitialDragWithPoint: (NSPoint) currentPoint;
- (BOOL) shouldReverseScrollDirectionForMouseWheel;
- (BOOL) shouldReverseScrollDirectionForMouseDrag;
- (void)mouseDraggedImageScroll:(NSEvent *)event;
- (void)mouseDraggedBlending:(NSEvent *)event;
- (void)mouseDraggedWindowLevel:(NSEvent *)event;
Expand Down
83 changes: 60 additions & 23 deletions Horos/Sources/DCMView.m
Original file line number Diff line number Diff line change
Expand Up @@ -4311,7 +4311,7 @@ - (void) mouseDown:(NSEvent *)event
startScaleValue = scaleValue;
rotationStart = rotation;
blendingFactorStart = blendingFactor;
scrollMode = 0;
scrollMode = ScrollModeReady;
resizeTotal = 1;

originStart = origin;
Expand Down Expand Up @@ -4913,10 +4913,12 @@ - (void)scrollWheel:(NSEvent *)theEvent

if( [[NSUserDefaults standardUserDefaults] boolForKey: @"ZoomWithHorizonScroll"] == NO) deltaX = 0;

if ([[NSUserDefaults standardUserDefaults] boolForKey: @"Scroll Wheel Reversed"])
reverseScrollWheel = -1.0;
else
if ([self shouldReverseScrollDirectionForMouseWheel])
{
reverseScrollWheel = -1.0;
} else {
reverseScrollWheel = 1.0;
}

if( flippedData) reverseScrollWheel *= -1.0;

Expand Down Expand Up @@ -5576,36 +5578,69 @@ - (void)mouseDraggedRotate:(NSEvent *)event
self.rotation = rot;
}

//Scrolling through images with Mouse
- (void) establishScrollModeFromInitialDragWithPoint: (NSPoint) currentPoint
{
if (fabs(start.x - currentPoint.x) < fabs(start.y - currentPoint.y))
{
if (fabs(start.y - currentPoint.y) > 3) { scrollMode = ScrollModeVertical; }
}
else if (fabs(start.x - currentPoint.x) >= fabs(start.y - currentPoint.y))
{
if (fabs(start.x - currentPoint.x) > 3) { scrollMode = ScrollModeHorizontal; }
}
}


- (BOOL) shouldReverseScrollDirectionForMouseWheel
{
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"com.apple.swipescrolldirection"]) {
return NO; // System scroll setting "natural" - no need to reverse.
}

// System scroll setting "normal", use app's scroll setting, which defaults to YES.

return [[NSUserDefaults standardUserDefaults] boolForKey: @"Scroll Wheel Reversed"];
}


- (BOOL) shouldReverseScrollDirectionForMouseDrag
{
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"com.apple.swipescrolldirection"]) {
return YES; // System scroll setting "natural" - reverse mouse drag to complement mouse-wheel.
}

// System scroll setting "normal", use app's scroll setting, to match mouse-wheel.

return [[NSUserDefaults standardUserDefaults] boolForKey: @"Scroll Wheel Reversed"];
}


// Scrolling through images with mouse
// could be cleaned up by subclassing DCMView
- (void)mouseDraggedImageScroll:(NSEvent *)event
- (void) mouseDraggedImageScroll: (NSEvent *)event
{
short previmage;
short previmage = curImage;
BOOL movie4Dmove = NO;
NSPoint current = [self currentPointInView:event];
if( scrollMode == 0)
if (scrollMode == ScrollModeReady)
{
if( fabs( start.x - current.x) < fabs( start.y - current.y))
{
if( fabs( start.y - current.y) > 3) scrollMode = 1;
}
else if( fabs( start.x - current.x) >= fabs( start.y - current.y))
{
if( fabs( start.x - current.x) > 3) scrollMode = 2;
}
[self establishScrollModeFromInitialDragWithPoint: current];
}

if( movie4Dmove == NO)
if (movie4Dmove == NO) // Currently always called. For future functionality.
{
previmage = curImage;

if( scrollMode == 2)
CGFloat scrollWheelDirection = 1.0;
if ([self shouldReverseScrollDirectionForMouseDrag]) {
scrollWheelDirection = -1.0;
}

if (scrollMode == ScrollModeHorizontal)
{
curImage = startImage + ((current.x - start.x) * [dcmPixList count] )/ ([self frame].size.width/2);
curImage = startImage + ((current.x - start.x) * [dcmPixList count] * scrollWheelDirection) / ([self frame].size.width/2);
}
else if( scrollMode == 1)
else if (scrollMode == ScrollModeVertical)
{
curImage = startImage + ((start.y - current.y) * [dcmPixList count] )/ ([self frame].size.height/2);
curImage = startImage + ((start.y - current.y) * [dcmPixList count] * scrollWheelDirection) / ([self frame].size.height/2);
}

if( curImage < 0) curImage = 0;
Expand All @@ -5632,6 +5667,8 @@ - (void)mouseDraggedImageScroll:(NSEvent *)event
}
}

#pragma mark -

- (void)mouseDraggedBlending:(NSEvent *)event
{
float WWAdapter = bdstartWW / 100.0;
Expand Down
28 changes: 12 additions & 16 deletions Horos/Sources/MPRDCMView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1764,24 +1764,20 @@ - (void) mouseDraggedImageScroll:(NSEvent *) event

NSPoint current = [self currentPointInView: event];

if( scrollMode == 0)
{
if( fabs( start.x - current.x) < fabs( start.y - current.y))
{
if( fabs( start.y - current.y) > 3) scrollMode = 1;
}
else if( fabs( start.x - current.x) >= fabs( start.y - current.y))
{
if( fabs( start.x - current.x) > 3) scrollMode = 2;
}
if (scrollMode == ScrollModeReady) {
[self establishScrollModeFromInitialDragWithPoint: current];
}

float delta;

if( scrollMode == 1)
delta = ((previous.y - current.y) * 512. )/ ([self convertSizeToBacking: self.frame.size].width/2);
else
delta = ((current.x - previous.x) * 512. )/ ([self convertSizeToBacking: self.frame.size].width/2);
float delta = 0.0;
if (scrollMode == ScrollModeVertical) {
delta = ((previous.y - current.y) * 512. ) / ([self convertSizeToBacking: self.frame.size].height/2);
} else if (scrollMode == ScrollModeHorizontal) {
delta = ((current.x - previous.x) * 512. ) / ([self convertSizeToBacking: self.frame.size].width/2);
}

if ([self shouldReverseScrollDirectionForMouseDrag]) {
delta *= -1.0;
}

[self restoreCamera];
windowController.lowLOD = YES;
Expand Down
54 changes: 24 additions & 30 deletions Horos/Sources/OrthogonalMPRView.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ - (void)scrollWheel:(NSEvent *)theEvent

if( [[NSUserDefaults standardUserDefaults] boolForKey: @"ZoomWithHorizonScroll"] == NO) deltaX = 0;

if ([[NSUserDefaults standardUserDefaults] boolForKey: @"Scroll Wheel Reversed"])
reverseScrollWheel = -1.0;
else
reverseScrollWheel = 1.0;
if ([self shouldReverseScrollDirectionForMouseWheel]) {
reverseScrollWheel = 1.0;
} else {
reverseScrollWheel = -1.0;
}

if( flippedData) reverseScrollWheel *= -1.0;

if( dcmPixList)
{
[[self controller] saveCrossPositions];
Expand Down Expand Up @@ -1037,49 +1038,42 @@ - (void)mouseDraggedCrosshair:(NSEvent *)event
}
}

- (void)mouseDraggedImageScroll:(NSEvent *) event {
short now, prev;
- (void) mouseDraggedImageScroll: (NSEvent*) event
{
BOOL movie4Dmove = NO;
NSPoint current = [self currentPointInView:event];
if( scrollMode == 0)
if (scrollMode == ScrollModeReady)
{
if( fabs( start.x - current.x) < fabs( start.y - current.y))
{
prev = start.y/2;
now = current.y/2;
if( fabs( start.y - current.y) > 3) scrollMode = 1;
}
else if( fabs( start.x - current.x) >= fabs( start.y - current.y))
{
prev = start.x/2;
now = current.x/2;
if( fabs( start.x - current.x) > 3) scrollMode = 2;
}

// NSLog(@"scrollMode : %d", scrollMode);
[self establishScrollModeFromInitialDragWithPoint: current];
}


if( movie4Dmove == NO)
if (movie4Dmove == NO) // Currently always passes, for future development.
{
long from, to;
if( scrollMode == 2)
if (scrollMode == ScrollModeHorizontal)
{
from = current.x;
to = start.x;
from = start.x;
to = current.x;
}
else if( scrollMode == 1)
else if (scrollMode == ScrollModeVertical)
{
from = start.y;
to = current.y;
from = current.y;
to = start.y;
}
else
{
from = 0;
to = 0;
}

if ([self shouldReverseScrollDirectionForMouseDrag]) {
long temp = to;
to = from;
from = temp;
}

if ( abs((int)(from-to)) >= 1) {
if (abs((int)(from-to)) >= 1) {
[self scrollTool: from : to];
}
}
Expand Down
10 changes: 9 additions & 1 deletion Horos/Sources/VRView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2983,7 +2983,15 @@ - (void) scrollWheel:(NSEvent *)theEvent
{
if ([self eventToPlugins:theEvent]) return;

return [self scrollInStack: [theEvent deltaY]];
float delta = [theEvent deltaY];
// Match behaviour of -[DCMView shouldReverseScrollDirectionForMouseWheel]
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"com.apple.swipescrolldirection"]) {
delta *= -1.0;
} else if (![[NSUserDefaults standardUserDefaults] boolForKey: @"Scroll Wheel Reversed"]) {
delta *= -1.0;
}

return [self scrollInStack: delta];
}

- (void)otherMouseDown:(NSEvent *)theEvent
Expand Down