Commit 80c80539 authored by David Fuhrmann's avatar David Fuhrmann
Browse files

macosx: cleanup generic scrollwheel implementation

parent 04e7801f
......@@ -30,6 +30,9 @@
*****************************************************************************/
@interface VLCVoutView : NSView
{
NSInteger i_lastScrollWheelDirection;
NSTimeInterval t_lastScrollEvent;
CGFloat f_cumulated_magnification;
}
@end
......@@ -76,6 +76,7 @@ int DeviceCallback(vlc_object_t *p_this, const char *psz_variable,
{
[self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]];
i_lastScrollWheelDirection = 0;
f_cumulated_magnification = 0.0;
}
......@@ -118,12 +119,6 @@ int DeviceCallback(vlc_object_t *p_this, const char *psz_variable,
}
}
- (void)scrollWheel:(NSEvent *)theEvent
{
VLCControls * o_controls = (VLCControls *)[[NSApp delegate] controls];
[o_controls scrollWheel: theEvent];
}
- (void)keyDown:(NSEvent *)o_event
{
unichar key = 0;
......@@ -220,6 +215,70 @@ int DeviceCallback(vlc_object_t *p_this, const char *psz_variable,
[super mouseMoved: o_event];
}
- (void)resetScrollWheelDirection
{
/* release the scroll direction 0.8 secs after the last event */
if (([NSDate timeIntervalSinceReferenceDate] - t_lastScrollEvent) >= 0.80)
i_lastScrollWheelDirection = 0;
}
- (void)scrollWheel:(NSEvent *)theEvent
{
intf_thread_t * p_intf = VLCIntf;
CGFloat f_deltaX = [theEvent deltaX];
CGFloat f_deltaY = [theEvent deltaY];
if (!OSX_SNOW_LEOPARD && [theEvent isDirectionInvertedFromDevice]) {
f_deltaX = -f_deltaX;
f_deltaY = -f_deltaY;
}
CGFloat f_yabsvalue = f_deltaY > 0.0f ? f_deltaY : -f_deltaY;
CGFloat f_xabsvalue = f_deltaX > 0.0f ? f_deltaX : -f_deltaX;
int i_yvlckey, i_xvlckey = 0;
if (f_deltaY < 0.0f)
i_yvlckey = KEY_MOUSEWHEELDOWN;
else
i_yvlckey = KEY_MOUSEWHEELUP;
if (f_deltaX < 0.0f)
i_xvlckey = KEY_MOUSEWHEELRIGHT;
else
i_xvlckey = KEY_MOUSEWHEELLEFT;
/* in the following, we're forwarding either a x or a y event */
/* Multiple key events are send depending on the intensity of the event */
/* the opposite direction is being blocked for 0.8 secs */
if (f_yabsvalue > 0.05) {
if (i_lastScrollWheelDirection < 0) // last was a X
return;
i_lastScrollWheelDirection = 1; // Y
for (NSUInteger i = 0; i < (int)(f_yabsvalue/4.+1.); i++)
var_SetInteger(p_intf->p_libvlc, "key-pressed", i_yvlckey);
t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
[self performSelector:@selector(resetScrollWheelDirection)
withObject: NULL
afterDelay:1.00];
return;
}
if (f_xabsvalue > 0.05) {
if (i_lastScrollWheelDirection > 0) // last was a Y
return;
i_lastScrollWheelDirection = -1; // X
for (NSUInteger i = 0; i < (int)(f_xabsvalue/6.+1.); i++)
var_SetInteger(p_intf->p_libvlc, "key-pressed", i_xvlckey);
t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
[self performSelector:@selector(resetScrollWheelDirection)
withObject: NULL
afterDelay:1.00];
}
}
- (BOOL)mouseDownCanMoveWindow
{
return YES;
......
......@@ -39,10 +39,8 @@
IBOutlet id o_specificTime_sec_lbl;
IBOutlet id o_specificTime_stepper;
IBOutlet id o_specificTime_mi;
NSInteger i_lastScrollWheelDirection;
NSTimeInterval t_lastScrollEvent;
}
- (IBAction)play:(id)sender;
- (IBAction)stop:(id)sender;
......@@ -69,7 +67,6 @@
- (IBAction)addSubtitleFile:(id)sender;
- (BOOL)keyEvent:(NSEvent *)o_event;
- (void)scrollWheel: (NSEvent *)theEvent;
- (IBAction)goToSpecificTime:(id)sender;
@end
......
......@@ -54,8 +54,6 @@
[o_specificTime_ok_btn setTitle: _NS("OK")];
[o_specificTime_sec_lbl setStringValue: _NS("sec.")];
[o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
i_lastScrollWheelDirection = 0;
}
......@@ -252,88 +250,6 @@
vlc_object_release(p_input);
}
- (void)resetScrollWheelDirection
{
/* release the scroll direction 0.8 secs after the last event */
if (([NSDate timeIntervalSinceReferenceDate] - t_lastScrollEvent) >= 0.80)
i_lastScrollWheelDirection = 0;
}
- (void)scrollWheel:(NSEvent *)theEvent
{
intf_thread_t * p_intf = VLCIntf;
BOOL b_invertedEventFromDevice = NO;
CGFloat f_deltaY, f_deltaX = .0;
if (!OSX_SNOW_LEOPARD) {
if ([theEvent isDirectionInvertedFromDevice])
b_invertedEventFromDevice = YES;
}
f_deltaY = [theEvent deltaY];
f_deltaX = [theEvent deltaX];
CGFloat f_yabsvalue = f_deltaY > 0.0f ? f_deltaY : -f_deltaY;
CGFloat f_xabsvalue = f_deltaX > 0.0f ? f_deltaX : -f_deltaX;
int i_yvlckey, i_xvlckey = 0;
if (b_invertedEventFromDevice) {
if (f_deltaY > 0.0f)
i_yvlckey = KEY_MOUSEWHEELDOWN;
else
i_yvlckey = KEY_MOUSEWHEELUP;
if (f_deltaX > 0.0f)
i_xvlckey = KEY_MOUSEWHEELRIGHT;
else
i_xvlckey = KEY_MOUSEWHEELLEFT;
} else {
if (f_deltaY < 0.0f)
i_yvlckey = KEY_MOUSEWHEELDOWN;
else
i_yvlckey = KEY_MOUSEWHEELUP;
if (f_deltaX < 0.0f)
i_xvlckey = KEY_MOUSEWHEELRIGHT;
else
i_xvlckey = KEY_MOUSEWHEELLEFT;
}
/* in the following, we're forwarding either a x or a y event */
/* Multiple key events are send depending on the intensity of the event */
/* the opposite direction is being blocked for 0.8 secs */
if (f_yabsvalue > 0.05)
{
if (i_lastScrollWheelDirection < 0) // last was a X
return;
i_lastScrollWheelDirection = 1; // Y
for (NSUInteger i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
var_SetInteger(p_intf->p_libvlc, "key-pressed", i_yvlckey);
t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
[self performSelector:@selector(resetScrollWheelDirection)
withObject: NULL
afterDelay:1.00];
return;
}
if (f_xabsvalue > 0.05)
{
if (i_lastScrollWheelDirection > 0) // last was a Y
return;
i_lastScrollWheelDirection = -1; // X
for (NSUInteger i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
var_SetInteger(p_intf->p_libvlc, "key-pressed", i_xvlckey);
t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
[self performSelector:@selector(resetScrollWheelDirection)
withObject: NULL
afterDelay:1.00];
}
}
- (BOOL)keyEvent:(NSEvent *)o_event
{
BOOL eventHandled = NO;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment