示例#1
0
        public bool?ShowDialog <TViewModel>(TViewModel viewModel) where TViewModel : IGameWindowRequestClose
        {
            Type        viewType   = Mappings[typeof(TViewModel)];
            IGameWindow gameWindow = (IGameWindow)Activator.CreateInstance(viewType);

            EventHandler <GameWindowCloseRequestedEventArgs> handler = null;

            handler = (sender, e) =>
            {
                viewModel.CloseRequested -= handler;

                if (e.DialogResult.HasValue)
                {
                    gameWindow.DialogResult = e.DialogResult;
                }
                else
                {
                    gameWindow.Close();
                }
            };

            viewModel.CloseRequested += handler;

            gameWindow.DataContext = viewModel;
            gameWindow.Owner       = _owner;

            return(gameWindow.ShowDialog());
        }
示例#2
0
        public void Run(IGameWindow gameWindow, Action tickCallback)
        {
            while (gameWindow.IsOpen)
            {
                SDL.SDL_PollEvent(out var ev);
                if (ev.type == SDL.SDL_EventType.SDL_QUIT)
                {
                    gameWindow.Close();
                }

                tickCallback();
            }
        }