Added implementation of Window::hasFocus() on iOS

This commit is contained in:
Laurent 2014-11-07 22:26:24 +01:00 committed by Lukas Dürrenberger
parent e257909a65
commit 6ef3cb27a1
3 changed files with 33 additions and 13 deletions

View File

@ -103,7 +103,7 @@ namespace
{ {
sf::Event event; sf::Event event;
event.type = sf::Event::LostFocus; event.type = sf::Event::LostFocus;
sfWindow->pushEvent(event); sfWindow->forwardEvent(event);
} }
} }
@ -127,7 +127,7 @@ namespace
{ {
sf::Event event; sf::Event event;
event.type = sf::Event::GainedFocus; event.type = sf::Event::GainedFocus;
sfWindow->pushEvent(event); sfWindow->forwardEvent(event);
} }
} }
@ -147,7 +147,7 @@ namespace
{ {
sf::Event event; sf::Event event;
event.type = sf::Event::Closed; event.type = sf::Event::Closed;
sfWindow->pushEvent(event); sfWindow->forwardEvent(event);
} }
} }
@ -176,7 +176,7 @@ namespace
event.type = sf::Event::Resized; event.type = sf::Event::Resized;
event.size.width = size.x; event.size.width = size.x;
event.size.height = size.y; event.size.height = size.y;
sfWindow->pushEvent(event); sfWindow->forwardEvent(event);
} }
} }
} }
@ -215,7 +215,7 @@ namespace
event.touch.finger = index; event.touch.finger = index;
event.touch.x = position.x; event.touch.x = position.x;
event.touch.y = position.y; event.touch.y = position.y;
sfWindow->pushEvent(event); sfWindow->forwardEvent(event);
} }
} }
@ -236,7 +236,7 @@ namespace
event.touch.finger = index; event.touch.finger = index;
event.touch.x = position.x; event.touch.x = position.x;
event.touch.y = position.y; event.touch.y = position.y;
sfWindow->pushEvent(event); sfWindow->forwardEvent(event);
} }
} }
@ -256,7 +256,7 @@ namespace
event.touch.finger = index; event.touch.finger = index;
event.touch.x = position.x; event.touch.x = position.x;
event.touch.y = position.y; event.touch.y = position.y;
sfWindow->pushEvent(event); sfWindow->forwardEvent(event);
} }
} }
@ -269,7 +269,7 @@ namespace
sf::Event event; sf::Event event;
event.type = sf::Event::TextEntered; event.type = sf::Event::TextEntered;
event.text.unicode = character; event.text.unicode = character;
sfWindow->pushEvent(event); sfWindow->forwardEvent(event);
} }
} }

View File

@ -174,7 +174,13 @@ public:
public: public:
using WindowImpl::pushEvent; ////////////////////////////////////////////////////////////
/// \brief Notify an event
///
/// \param event Evenet to forward
///
////////////////////////////////////////////////////////////
void forwardEvent(Event event);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the window's view /// \brief Get the window's view
@ -208,6 +214,7 @@ private:
UIWindow* m_window; ///< Pointer to the internal UIKit window UIWindow* m_window; ///< Pointer to the internal UIKit window
SFView* m_view; ///< OpenGL view of the window SFView* m_view; ///< OpenGL view of the window
SFViewController* m_viewController; ///< Controller attached to the view SFViewController* m_viewController; ///< Controller attached to the view
bool m_hasFocus; ///< Current focus state of the window
}; };
} // namespace priv } // namespace priv

View File

@ -41,6 +41,7 @@ namespace priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
WindowImplUIKit::WindowImplUIKit(WindowHandle handle) WindowImplUIKit::WindowImplUIKit(WindowHandle handle)
{ {
// Not implemented
} }
@ -62,6 +63,7 @@ WindowImplUIKit::WindowImplUIKit(VideoMode mode,
// Create the window // Create the window
CGRect frame = [UIScreen mainScreen].bounds; // Ignore user size, it wouldn't make sense to use something else CGRect frame = [UIScreen mainScreen].bounds; // Ignore user size, it wouldn't make sense to use something else
m_window = [[UIWindow alloc] initWithFrame:frame]; m_window = [[UIWindow alloc] initWithFrame:frame];
m_hasFocus = true;
// Assign it to the application delegate // Assign it to the application delegate
[SFAppDelegate getInstance].sfWindow = this; [SFAppDelegate getInstance].sfWindow = this;
@ -173,15 +175,26 @@ void WindowImplUIKit::setKeyRepeatEnabled(bool enabled)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplUIKit::requestFocus() void WindowImplUIKit::requestFocus()
{ {
// Not applicable // To implement
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool WindowImplUIKit::hasFocus() const bool WindowImplUIKit::hasFocus() const
{ {
// Not applicable return m_hasFocus;
return false; }
////////////////////////////////////////////////////////////
void WindowImplUIKit::forwardEvent(Event event)
{
if (event.type == Event::GainedFocus)
m_hasFocus = true;
else if (event.type == Event::LostFocus)
m_hasFocus = false;
pushEvent(event);
} }