summaryrefslogtreecommitdiff
path: root/src/SFML/Window/OSX/SFOpenGLView.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/SFML/Window/OSX/SFOpenGLView.h')
-rw-r--r--src/SFML/Window/OSX/SFOpenGLView.h65
1 files changed, 57 insertions, 8 deletions
diff --git a/src/SFML/Window/OSX/SFOpenGLView.h b/src/SFML/Window/OSX/SFOpenGLView.h
index 6a0d0b0..41d0c76 100644
--- a/src/SFML/Window/OSX/SFOpenGLView.h
+++ b/src/SFML/Window/OSX/SFOpenGLView.h
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com),
+// Copyright (C) 2007-2016 Marco Antognini (antognini.marco@gmail.com),
// Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
@@ -47,6 +47,24 @@ namespace sf {
/// Modifiers keys (cmd, ctrl, alt, shift) are handled by this class
/// but the actual logic is done in SFKeyboardModifiersHelper.(h|mm).
///
+/// The interface is subdivided into several categories in order
+/// to have multiple implementation files to divide this monolithic
+/// implementation. However, all attributes are defined in the main
+/// interface declaration right below.
+///
+/// Note about deltaXBuffer and deltaYBuffer: when grabbing the cursor
+/// for the first time, either by entering fullscreen or through
+/// setCursorGrabbed:, the cursor might be projected into the view.
+/// Doing this will result in a big delta (relative movement) in the
+/// next move event (cursorPositionFromEvent:), because no move event
+/// is generated, which in turn will give the impression that the user
+/// want to move the cursor by the same distance it was projected. To
+/// prevent the cursor to fly twice the distance we keep track of how
+/// much the cursor was projected in deltaXBuffer and deltaYBuffer. In
+/// cursorPositionFromEvent: we can then reduce/augment those buffers
+/// to determine when a move event should result in an actual move of
+/// the cursor (that was disconnected from the system).
+///
////////////////////////////////////////////////////////////
@interface SFOpenGLView : NSOpenGLView
{
@@ -56,6 +74,9 @@ namespace sf {
NSTrackingArea* m_trackingArea; ///< Mouse tracking area
BOOL m_fullscreen; ///< Indicate whether the window is fullscreen or not
CGFloat m_scaleFactor; ///< Display scale factor (e.g. 1x for classic display, 2x for retina)
+ BOOL m_cursorGrabbed; ///< Is the mouse cursor trapped?
+ CGFloat m_deltaXBuffer; ///< See note about cursor grabbing above
+ CGFloat m_deltaYBuffer; ///< See note about cursor grabbing above
// Hidden text view used to convert key event to actual chars.
// We use a silent responder to prevent sound alerts.
@@ -106,6 +127,18 @@ namespace sf {
-(NSPoint)computeGlobalPositionOfRelativePoint:(NSPoint)point;
////////////////////////////////////////////////////////////
+/// \brief Get the display scale factor
+///
+/// \return e.g. 1.0 for classic display, 2.0 for retina display
+///
+////////////////////////////////////////////////////////////
+-(CGFloat)displayScaleFactor;
+
+@end
+
+@interface SFOpenGLView (keyboard)
+
+////////////////////////////////////////////////////////////
/// \brief Enable key repeat
///
////////////////////////////////////////////////////////////
@@ -117,19 +150,17 @@ namespace sf {
////////////////////////////////////////////////////////////
-(void)disableKeyRepeat;
-////////////////////////////////////////////////////////////
-/// \brief Get the display scale factor
-///
-/// \return e.g. 1.0 for classic display, 2.0 for retina display
-///
-////////////////////////////////////////////////////////////
--(CGFloat)displayScaleFactor;
+@end
+
+@interface SFOpenGLView (mouse)
////////////////////////////////////////////////////////////
/// \brief Compute the position of the cursor
///
/// \param eventOrNil if nil the cursor position is the current one
///
+/// \return the mouse position in SFML coord system
+///
////////////////////////////////////////////////////////////
-(NSPoint)cursorPositionFromEvent:(NSEvent*)eventOrNil;
@@ -141,4 +172,22 @@ namespace sf {
////////////////////////////////////////////////////////////
-(BOOL)isMouseInside;
+////////////////////////////////////////////////////////////
+/// Clips or releases the mouse cursor
+///
+/// Generate a MouseEntered event when it makes sense.
+///
+/// \param grabbed YES to grab, NO to release
+///
+////////////////////////////////////////////////////////////
+-(void)setCursorGrabbed:(BOOL)grabbed;
+
+////////////////////////////////////////////////////////////
+/// Update the cursor position according to the grabbing behaviour
+///
+/// This function has to be called when the window's state change
+///
+////////////////////////////////////////////////////////////
+-(void)updateCursorGrabbed;
+
@end