mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
[Android] Got rid of the unnecessary additional event container
This commit is contained in:
parent
57ca180d8d
commit
c462f7cd0a
@ -207,7 +207,7 @@ static void onResume(ANativeActivity* activity)
|
|||||||
sf::Event event;
|
sf::Event event;
|
||||||
event.type = sf::Event::MouseEntered;
|
event.type = sf::Event::MouseEntered;
|
||||||
|
|
||||||
states->pendingEvents.push_back(event);
|
states->forwardEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ static void onPause(ANativeActivity* activity)
|
|||||||
sf::Event event;
|
sf::Event event;
|
||||||
event.type = sf::Event::MouseLeft;
|
event.type = sf::Event::MouseLeft;
|
||||||
|
|
||||||
states->pendingEvents.push_back(event);
|
states->forwardEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ static void onDestroy(ANativeActivity* activity)
|
|||||||
sf::Event event;
|
sf::Event event;
|
||||||
event.type = sf::Event::Closed;
|
event.type = sf::Event::Closed;
|
||||||
|
|
||||||
states->pendingEvents.push_back(event);
|
states->forwardEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,12 +288,12 @@ static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* wind
|
|||||||
states->window = window;
|
states->window = window;
|
||||||
|
|
||||||
// Notify SFML mechanism
|
// Notify SFML mechanism
|
||||||
|
states->updated = false;
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
event.type = sf::Event::GainedFocus;
|
event.type = sf::Event::GainedFocus;
|
||||||
states->pendingEvents.push_back(event);
|
states->forwardEvent(event);
|
||||||
|
|
||||||
// Wait for the event to be taken into account by SFML
|
// Wait for the event to be taken into account by SFML
|
||||||
states->updated = false;
|
|
||||||
while(!states->updated)
|
while(!states->updated)
|
||||||
{
|
{
|
||||||
states->mutex.unlock();
|
states->mutex.unlock();
|
||||||
@ -313,12 +313,12 @@ static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* wi
|
|||||||
states->window = NULL;
|
states->window = NULL;
|
||||||
|
|
||||||
// Notify SFML mechanism
|
// Notify SFML mechanism
|
||||||
|
states->updated = false;
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
event.type = sf::Event::LostFocus;
|
event.type = sf::Event::LostFocus;
|
||||||
states->pendingEvents.push_back(event);
|
states->forwardEvent(event);
|
||||||
|
|
||||||
// Wait for the event to be taken into account by SFML
|
// Wait for the event to be taken into account by SFML
|
||||||
states->updated = false;
|
|
||||||
while(!states->updated)
|
while(!states->updated)
|
||||||
{
|
{
|
||||||
states->mutex.unlock();
|
states->mutex.unlock();
|
||||||
@ -391,7 +391,7 @@ static void onContentRectChanged(ANativeActivity* activity, const ARect* rect)
|
|||||||
event.size.width = ANativeWindow_getWidth(states->window);
|
event.size.width = ANativeWindow_getWidth(states->window);
|
||||||
event.size.height = ANativeWindow_getHeight(states->window);
|
event.size.height = ANativeWindow_getHeight(states->window);
|
||||||
|
|
||||||
states->pendingEvents.push_back(event);
|
states->forwardEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ struct ActivityStates
|
|||||||
|
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
|
|
||||||
std::vector<Event> pendingEvents;
|
void (*forwardEvent)(const Event& event);
|
||||||
int (*processEvent)(int fd, int events, void* data);
|
int (*processEvent)(int fd, int events, void* data);
|
||||||
|
|
||||||
std::map<int, Vector2i> touchEvents;
|
std::map<int, Vector2i> touchEvents;
|
||||||
|
@ -44,6 +44,8 @@ namespace sf
|
|||||||
{
|
{
|
||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
|
WindowImplAndroid* WindowImplAndroid::singleInstance = NULL;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
WindowImplAndroid::WindowImplAndroid(WindowHandle handle)
|
WindowImplAndroid::WindowImplAndroid(WindowHandle handle)
|
||||||
: m_size(0, 0)
|
: m_size(0, 0)
|
||||||
@ -58,6 +60,9 @@ WindowImplAndroid::WindowImplAndroid(VideoMode mode, const String& title, unsign
|
|||||||
ActivityStates* states = getActivity(NULL);
|
ActivityStates* states = getActivity(NULL);
|
||||||
Lock lock(states->mutex);
|
Lock lock(states->mutex);
|
||||||
|
|
||||||
|
if (style& Style::Fullscreen)
|
||||||
|
states->fullscreen = true;
|
||||||
|
|
||||||
// Register process event callback
|
// Register process event callback
|
||||||
states->processEvent = processEvent;
|
states->processEvent = processEvent;
|
||||||
|
|
||||||
@ -84,34 +89,8 @@ WindowHandle WindowImplAndroid::getSystemHandle() const
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void WindowImplAndroid::processEvents()
|
void WindowImplAndroid::processEvents()
|
||||||
{
|
{
|
||||||
ActivityStates* states = getActivity(NULL);
|
|
||||||
Lock lock(states->mutex);
|
|
||||||
|
|
||||||
// Process incoming OS events
|
// Process incoming OS events
|
||||||
ALooper_pollAll(0, NULL, NULL, NULL);
|
ALooper_pollAll(0, NULL, NULL, NULL);
|
||||||
|
|
||||||
while (!states->pendingEvents.empty())
|
|
||||||
{
|
|
||||||
Event tempEvent = states->pendingEvents.back();
|
|
||||||
states->pendingEvents.pop_back();
|
|
||||||
|
|
||||||
if (tempEvent.type == Event::GainedFocus)
|
|
||||||
{
|
|
||||||
states->context->createSurface(states->window);
|
|
||||||
|
|
||||||
m_size.x = ANativeWindow_getWidth(states->window);
|
|
||||||
m_size.y = ANativeWindow_getHeight(states->window);
|
|
||||||
|
|
||||||
states->updated = true;
|
|
||||||
}
|
|
||||||
else if (tempEvent.type == Event::LostFocus)
|
|
||||||
{
|
|
||||||
states->context->destroySurface();
|
|
||||||
states->updated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
pushEvent(tempEvent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -178,6 +157,31 @@ void WindowImplAndroid::setKeyRepeatEnabled(bool enabled)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void WindowImplAndroid::forwardEvent(const Event& event)
|
||||||
|
{
|
||||||
|
ActivityStates* states = getActivity(NULL);
|
||||||
|
Lock lock(states->mutex);
|
||||||
|
|
||||||
|
if (event.type == Event::GainedFocus)
|
||||||
|
{
|
||||||
|
states->context->createSurface(states->window);
|
||||||
|
|
||||||
|
WindowImplAndroid::singleInstance->m_size.x = ANativeWindow_getWidth(states->window);
|
||||||
|
WindowImplAndroid::singleInstance->m_size.y = ANativeWindow_getHeight(states->window);
|
||||||
|
|
||||||
|
states->updated = true;
|
||||||
|
}
|
||||||
|
else if (event.type == Event::LostFocus)
|
||||||
|
{
|
||||||
|
states->context->destroySurface();
|
||||||
|
states->updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowImplAndroid::singleInstance->pushEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int WindowImplAndroid::processEvent(int fd, int events, void* data)
|
int WindowImplAndroid::processEvent(int fd, int events, void* data)
|
||||||
{
|
{
|
||||||
@ -300,7 +304,7 @@ void WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates*
|
|||||||
event.mouseWheel.x = AMotionEvent_getX(_event, 0);
|
event.mouseWheel.x = AMotionEvent_getX(_event, 0);
|
||||||
event.mouseWheel.y = AMotionEvent_getY(_event, 0);
|
event.mouseWheel.y = AMotionEvent_getY(_event, 0);
|
||||||
|
|
||||||
states->pendingEvents.push_back(event);
|
forwardEvent(event);
|
||||||
|
|
||||||
// Dettach this thread from the JVM
|
// Dettach this thread from the JVM
|
||||||
lJavaVM->DetachCurrentThread();
|
lJavaVM->DetachCurrentThread();
|
||||||
@ -323,14 +327,14 @@ void WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates* sta
|
|||||||
event.key.control = false;
|
event.key.control = false;
|
||||||
event.key.shift = metakey & AMETA_SHIFT_ON;
|
event.key.shift = metakey & AMETA_SHIFT_ON;
|
||||||
|
|
||||||
states->pendingEvents.push_back(event);
|
forwardEvent(event);
|
||||||
|
|
||||||
if (int unicode = getUnicode(_event))
|
if (int unicode = getUnicode(_event))
|
||||||
{
|
{
|
||||||
Event event;
|
Event event;
|
||||||
event.type = Event::TextEntered;
|
event.type = Event::TextEntered;
|
||||||
event.text.unicode = unicode;
|
event.text.unicode = unicode;
|
||||||
states->pendingEvents.push_back(event);
|
forwardEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +380,7 @@ void WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates*
|
|||||||
states->touchEvents[id] = Vector2i(event.touch.x, event.touch.y);
|
states->touchEvents[id] = Vector2i(event.touch.x, event.touch.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
states->pendingEvents.push_back(event);
|
forwardEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +444,7 @@ void WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Ac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
states->pendingEvents.push_back(event);
|
forwardEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,6 +154,9 @@ public :
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void setKeyRepeatEnabled(bool enabled);
|
virtual void setKeyRepeatEnabled(bool enabled);
|
||||||
|
|
||||||
|
static void forwardEvent(const Event& event);
|
||||||
|
static WindowImplAndroid* singleInstance;
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user