Skip to content

Commit

Permalink
Added implementation of Window::hasFocus() on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentGomila authored and eXpl0it3r committed Nov 11, 2014
1 parent e257909 commit 6ef3cb2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/SFML/Window/iOS/SFAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ - (void)applicationWillResignActive:(UIApplication *)application
{
sf::Event event;
event.type = sf::Event::LostFocus;
sfWindow->pushEvent(event);
sfWindow->forwardEvent(event);
}
}

Expand All @@ -127,7 +127,7 @@ - (void)applicationDidBecomeActive:(UIApplication *)application
{
sf::Event event;
event.type = sf::Event::GainedFocus;
sfWindow->pushEvent(event);
sfWindow->forwardEvent(event);
}
}

Expand All @@ -147,7 +147,7 @@ - (void)applicationWillTerminate:(UIApplication *)application
{
sf::Event event;
event.type = sf::Event::Closed;
sfWindow->pushEvent(event);
sfWindow->forwardEvent(event);
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ - (void)deviceOrientationDidChange:(NSNotification *)notification
event.type = sf::Event::Resized;
event.size.width = size.x;
event.size.height = size.y;
sfWindow->pushEvent(event);
sfWindow->forwardEvent(event);
}
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ - (void)notifyTouchBegin:(unsigned int)index atPosition:(sf::Vector2i)position;
event.touch.finger = index;
event.touch.x = position.x;
event.touch.y = position.y;
sfWindow->pushEvent(event);
sfWindow->forwardEvent(event);
}
}

Expand All @@ -236,7 +236,7 @@ - (void)notifyTouchMove:(unsigned int)index atPosition:(sf::Vector2i)position;
event.touch.finger = index;
event.touch.x = position.x;
event.touch.y = position.y;
sfWindow->pushEvent(event);
sfWindow->forwardEvent(event);
}
}

Expand All @@ -256,7 +256,7 @@ - (void)notifyTouchEnd:(unsigned int)index atPosition:(sf::Vector2i)position;
event.touch.finger = index;
event.touch.x = position.x;
event.touch.y = position.y;
sfWindow->pushEvent(event);
sfWindow->forwardEvent(event);
}
}

Expand All @@ -269,7 +269,7 @@ - (void)notifyCharacter:(sf::Uint32)character
sf::Event event;
event.type = sf::Event::TextEntered;
event.text.unicode = character;
sfWindow->pushEvent(event);
sfWindow->forwardEvent(event);
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/SFML/Window/iOS/WindowImplUIKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ class WindowImplUIKit : public WindowImpl

public:

using WindowImpl::pushEvent;
////////////////////////////////////////////////////////////
/// \brief Notify an event
///
/// \param event Evenet to forward
///
////////////////////////////////////////////////////////////
void forwardEvent(Event event);

////////////////////////////////////////////////////////////
/// \brief Get the window's view
Expand Down Expand Up @@ -208,6 +214,7 @@ class WindowImplUIKit : public WindowImpl
UIWindow* m_window; ///< Pointer to the internal UIKit window
SFView* m_view; ///< OpenGL view of the window
SFViewController* m_viewController; ///< Controller attached to the view
bool m_hasFocus; ///< Current focus state of the window
};

} // namespace priv
Expand Down
21 changes: 17 additions & 4 deletions src/SFML/Window/iOS/WindowImplUIKit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
////////////////////////////////////////////////////////////
WindowImplUIKit::WindowImplUIKit(WindowHandle handle)
{
// Not implemented
}


Expand All @@ -62,6 +63,7 @@
// Create the window
CGRect frame = [UIScreen mainScreen].bounds; // Ignore user size, it wouldn't make sense to use something else
m_window = [[UIWindow alloc] initWithFrame:frame];
m_hasFocus = true;

// Assign it to the application delegate
[SFAppDelegate getInstance].sfWindow = this;
Expand Down Expand Up @@ -173,18 +175,29 @@
////////////////////////////////////////////////////////////
void WindowImplUIKit::requestFocus()
{
// Not applicable
// To implement
}


////////////////////////////////////////////////////////////
bool WindowImplUIKit::hasFocus() const
{
// Not applicable
return false;
return m_hasFocus;
}



////////////////////////////////////////////////////////////
void WindowImplUIKit::forwardEvent(Event event)
{
if (event.type == Event::GainedFocus)
m_hasFocus = true;
else if (event.type == Event::LostFocus)
m_hasFocus = false;

pushEvent(event);
}


////////////////////////////////////////////////////////////
SFView* WindowImplUIKit::getGlView() const
{
Expand Down

0 comments on commit 6ef3cb2

Please sign in to comment.