[vlc-commits] macosx: cleanup generic scrollwheel implementation
David Fuhrmann
git at videolan.org
Fri Sep 7 23:09:23 CEST 2012
vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Fri Sep 7 23:08:25 2012 +0200| [80c805395538a60e93e825745d1d3d3d094658f9] | committer: David Fuhrmann
macosx: cleanup generic scrollwheel implementation
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=80c805395538a60e93e825745d1d3d3d094658f9
---
modules/gui/macosx/VideoView.h | 3 ++
modules/gui/macosx/VideoView.m | 71 ++++++++++++++++++++++++++++++---
modules/gui/macosx/controls.h | 5 +--
modules/gui/macosx/controls.m | 84 ----------------------------------------
4 files changed, 69 insertions(+), 94 deletions(-)
diff --git a/modules/gui/macosx/VideoView.h b/modules/gui/macosx/VideoView.h
index a10057b..51c599d 100644
--- a/modules/gui/macosx/VideoView.h
+++ b/modules/gui/macosx/VideoView.h
@@ -30,6 +30,9 @@
*****************************************************************************/
@interface VLCVoutView : NSView
{
+ NSInteger i_lastScrollWheelDirection;
+ NSTimeInterval t_lastScrollEvent;
+
CGFloat f_cumulated_magnification;
}
@end
diff --git a/modules/gui/macosx/VideoView.m b/modules/gui/macosx/VideoView.m
index 78e08ea..b84debd 100644
--- a/modules/gui/macosx/VideoView.m
+++ b/modules/gui/macosx/VideoView.m
@@ -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;
diff --git a/modules/gui/macosx/controls.h b/modules/gui/macosx/controls.h
index 122e293..6f3b8aa 100644
--- a/modules/gui/macosx/controls.h
+++ b/modules/gui/macosx/controls.h
@@ -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
diff --git a/modules/gui/macosx/controls.m b/modules/gui/macosx/controls.m
index fb20d9c..c39067e 100644
--- a/modules/gui/macosx/controls.m
+++ b/modules/gui/macosx/controls.m
@@ -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;
More information about the vlc-commits
mailing list