Skip to content

Commit

Permalink
[SDL2] Add an overload to PumpEvents which takes a custom handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
mellinoe committed Feb 5, 2018
1 parent d3f2cd5 commit c1263c9
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/Veldrid.SDL2/Sdl2Window.cs
Expand Up @@ -36,7 +36,6 @@ public unsafe class Sdl2Window
// Cached Sdl2Window state (for threaded processing)
private BufferedValue<Point> _cachedPosition = new BufferedValue<Point>();
private BufferedValue<Point> _cachedSize = new BufferedValue<Point>();
private bool _continuousResizeReceived;
private string _cachedWindowTitle;
private bool _newWindowTitleReceived;

Expand Down Expand Up @@ -312,19 +311,14 @@ public InputSnapshot PumpEvents()
return _publicSnapshot;
}

private void ProcessEvents()
public void PumpEvents(SDLEventHandler eventHandler)
{
if (_continuousResizeReceived)
{
_continuousResizeReceived = false;
RefreshCachedSize();
}
ProcessEvents(eventHandler);
}

if (_newWindowTitleReceived)
{
_newWindowTitleReceived = false;
SDL_SetWindowTitle(_window, _cachedWindowTitle);
}
private void ProcessEvents()
{
CheckNewWindowTitle();

SDL_Event ev;
while (SDL_PollEvent(&ev) != 0)
Expand Down Expand Up @@ -434,6 +428,26 @@ private void ProcessEvents()
}
}

private void ProcessEvents(SDLEventHandler eventHandler)
{
CheckNewWindowTitle();

SDL_Event ev;
while (SDL_PollEvent(&ev) != 0)
{
eventHandler(ref ev);
}
}

private void CheckNewWindowTitle()
{
if (_newWindowTitleReceived)
{
_newWindowTitleReceived = false;
SDL_SetWindowTitle(_window, _cachedWindowTitle);
}
}

private void HandleTextInputEvent(SDL_TextInputEvent textInputEvent)
{
uint byteCount = 0;
Expand Down Expand Up @@ -1100,4 +1114,6 @@ private class ValueHolder
public T Value;
}
}

public delegate void SDLEventHandler(ref SDL_Event ev);
}

0 comments on commit c1263c9

Please sign in to comment.