Beispiel #1
0
        public Window(WindowOptions options)
        {
            if (Application.MainWindow != null)
            {
                throw new Lime.Exception("Attempt to set Application.MainWindow twice");
            }
            Application.MainWindow = this;
            Active     = true;
            fpsCounter = new FPSCounter();
            input      = new Input();

            UnityApplicationDelegate.Instance.Updating += delta => {
                Input.Refresh();
                RaiseUpdating(delta);
                AudioSystem.Update();
                Input.TextInput = null;
                Input.CopyKeysState();
                if (LastSize != ClientSize)
                {
                    RaiseResized(false);
                    LastSize = ClientSize;
                }
            };
            UnityApplicationDelegate.Instance.Rendering += () => {
                RaiseRendering();
                fpsCounter.Refresh();
            };
            UnityApplicationDelegate.Instance.Destroying += () => {
                RaiseClosed();
            };
        }
Beispiel #2
0
        private void Update()
        {
            isInvalidated = false;
            if (!form.Visible || !form.CanFocus)
            {
                return;
            }
            float delta = Mathf.Clamp((float)stopwatch.Elapsed.TotalSeconds, 0, Application.MaxDelta);

            stopwatch.Restart();
            if (this == Application.MainWindow && Application.MainMenu != null)
            {
                Application.MainMenu.Refresh();
            }
            // Refresh mouse position of every frame to make HitTest work properly if mouse is outside of the screen.
            RefreshMousePosition();
            RaiseUpdating(delta);
            AudioSystem.Update();
            Input.CopyKeysState();
            Input.ProcessPendingKeyEvents(delta);
            Input.TextInput = null;
            if (renderingState == RenderingState.RenderDeferred)
            {
                Invalidate();
            }
            renderingState = RenderingState.Updated;
        }
Beispiel #3
0
 private void Update(float delta)
 {
     UnclampedDelta = delta;
     delta          = Math.Min(UnclampedDelta, Application.MaxDelta);
     base.RaiseUpdating(delta);
     AudioSystem.Update();
     Input.CopyKeysState();
     Input.ProcessPendingKeyEvents(delta);
 }
Beispiel #4
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            var delta = Mathf.Clamp((float)stopwatch.Elapsed.TotalSeconds, 0, Application.MaxDelta);

            stopwatch.Restart();
            base.OnUpdateFrame(new FrameEventArgs(delta));
            AudioSystem.Update();
            input.CopyKeysState();
            input.ProcessPendingKeyEvents(delta);
            keyboardHandler.ProcessTextInput();
        }
Beispiel #5
0
        private static ITexture TryLoadImage(string path)
        {
            if (!AssetBundle.Current.FileExists(path))
            {
                return(null);
            }
            var texture = new Texture2D();

            texture.LoadTextureParams(path);
            texture.LoadImage(path);
            AudioSystem.Update();
            return(texture);
        }
Beispiel #6
0
        private void OnUpdateFrame(object s, Xamarin.FrameEventArgs e)
        {
            if (!Active || UIViewController.SoftKeyboardBeingShownOrHid)
            {
                return;
            }
            var delta = (float)Math.Min(e.Time, Application.MaxDelta);

            RaiseUpdating(delta);
            Input.CopyKeysState();
            Input.ProcessPendingKeyEvents(delta);
            AudioSystem.Update();
        }
Beispiel #7
0
        private void Update()
        {
            var delta = (float)stopwatch.Elapsed.TotalSeconds;

            stopwatch.Restart();
            delta = Mathf.Clamp(delta, 0, Application.MaxDelta);
            // Refresh mouse position on every frame to make HitTest work properly if mouse is outside of the window.
            RefreshMousePosition();
            Input.ProcessPendingKeyEvents(delta);
            RaiseUpdating(delta);
            AudioSystem.Update();
            Input.TextInput = null;
            Input.CopyKeysState();
        }
Beispiel #8
0
        public void LoadImage(string path, TextureMissingDelegate onTextureMissing = null)
        {
            IsStubTexture = false;

            try {
                foreach (string textureFileExtension in AffordableTextureFileExtensions)
                {
                    string tryPath = path + textureFileExtension;
                    if (!AssetBundle.Current.FileExists(tryPath))
                    {
                        continue;
                    }

                    Stream stream;
                    try {
                        stream = AssetBundle.Current.OpenFileLocalized(tryPath);
                    } catch (System.Exception e) {
                        Console.WriteLine("Can not open file '{0}':\n{1}", path, e);
                        continue;
                    }

                    using (stream) {
                        LoadImageHelper(stream, createReloader: false);
                    }

                    LoadTextureParams(path);

                    var maskPath = path + ".mask";
                    if (AssetBundle.Current.FileExists(maskPath))
                    {
                        OpacityMask = new OpacityMask(maskPath);
                    }

                    // Update audio buffers if the audio system performs in the main thread.
                    AudioSystem.Update();

                    return;
                }

                Console.WriteLine("Missing texture '{0}'", path);
                onTextureMissing?.Invoke(path);
                LoadStubImage();
            } finally {
                reloader = new TextureBundleReloader(path);
            }
        }
Beispiel #9
0
        private void Update()
        {
            var wasInvalidated = isInvalidated;

            isInvalidated = false;
            if (!form.Visible || !form.CanFocus)
            {
                return;
            }
            UnclampedDelta = (float)stopwatch.Elapsed.TotalSeconds;
            float delta = Mathf.Clamp(UnclampedDelta, 0, Application.MaxDelta);

            stopwatch.Restart();
            if (this == Application.MainWindow && Application.MainMenu != null)
            {
                Application.MainMenu.Refresh();
            }
            fpsCounter.Refresh();
            // Refresh mouse position of every frame to make HitTest work properly if mouse is outside of the screen.
            RefreshMousePosition();
            RaiseUpdating(delta);
            AudioSystem.Update();
            if (active || Input.IsSimulationRunning)
            {
                Input.CopyKeysState();
                Input.ProcessPendingKeyEvents(delta);
                Input.TextInput = null;
            }
            if (wasInvalidated || renderingState == RenderingState.RenderDeferred)
            {
                glControl.Invalidate();
            }
            renderingState = RenderingState.Updated;
            if (AsyncRendering)
            {
                renderCompleted.WaitOne();
                renderCompleted.Reset();
            }
            RaiseSync();
            if (AsyncRendering)
            {
                renderReady.Set();
            }
        }
Beispiel #10
0
        public void LoadImage(string path, TextureMissingDelegate onTextureMissing = null)
        {
            IsStubTexture = false;

            foreach (string textureFileExtension in AffordableTextureFileExtensions)
            {
                string tryPath = path + textureFileExtension;
                if (!AssetBundle.Current.FileExists(tryPath))
                {
                    continue;
                }

                Stream stream;
                try {
                    stream = AssetBundle.Current.OpenFileLocalized(tryPath);
                } catch (System.Exception e) {
                    Console.WriteLine("Can not open file '{0}':\n{1}", path, e);
                    continue;
                }

                using (stream) {
                    LoadImageHelper(stream);
                }

                LoadTextureParams(path);

                var maskPath = path + ".mask";
                if (AssetBundle.Current.FileExists(maskPath))
                {
                    OpacityMask = new OpacityMask(maskPath);
                }

                if (Application.IsMain(Application.CurrentThread))
                {
                    AudioSystem.Update();
                }

                return;
            }

            Console.WriteLine("Missing texture '{0}'", path);
            onTextureMissing?.Invoke(path);
            LoadStubImage(IsStubTextureTransparent && !path.IsNullOrWhiteSpace());
        }
Beispiel #11
0
        private void Update()
        {
            UnclampedDelta = (float)stopwatch.Elapsed.TotalSeconds;
            stopwatch.Restart();
            var delta = Mathf.Clamp(UnclampedDelta, 0, Application.MaxDelta);

            // Refresh mouse position on every frame to make HitTest work properly if mouse is outside of the window.
            RefreshMousePosition();
            RaiseUpdating(delta);
            AudioSystem.Update();
            if (Active || Input.IsSimulationRunning)
            {
                Input.CopyKeysState();
                Input.ProcessPendingKeyEvents(delta);
                Input.TextInput = null;
            }
            if (Application.AreAllWindowsInactive())
            {
                Input.ClearKeyState();
            }
            RaiseSync();
        }
Beispiel #12
0
        private void Update()
        {
            UnclampedDelta = (float)stopwatch.Elapsed.TotalSeconds;
            stopwatch.Restart();
            var delta = Mathf.Clamp(UnclampedDelta, 0, Application.MaxDelta);

            // Refresh mouse position on every frame to make HitTest work properly if mouse is outside of the window.
            RefreshMousePosition();
            if (Active || Input.IsSimulationRunning)
            {
                Input.ProcessPendingInputEvents(delta);
            }
            RaiseUpdating(delta);
            AudioSystem.Update();
            if (Active || Input.IsSimulationRunning)
            {
                Input.CopyKeysState();
                Input.TextInput = null;
            }
            // We give one update cycle to handle files drop
            // (files dropped event may be fired inside update)
            if (Input.DroppedFiles.Count > 0 || shouldCleanDroppedFiles)
            {
                if (shouldCleanDroppedFiles)
                {
                    Input.DroppedFiles.Clear();
                }
                shouldCleanDroppedFiles = !shouldCleanDroppedFiles;
            }

            if (Application.AreAllWindowsInactive())
            {
                Input.ClearKeyState();
            }
            RaiseSync();
        }
Beispiel #13
0
        private void Update()
        {
            var wasInvalidated = isInvalidated;

            isInvalidated = false;
            if (!form.Visible || !form.CanFocus || !renderControl.IsHandleCreated)
            {
                return;
            }
            UnclampedDelta = (float)stopwatch.Elapsed.TotalSeconds;
            float delta = Mathf.Clamp(UnclampedDelta, 0, Application.MaxDelta);

            stopwatch.Restart();
            if (this == Application.MainWindow && Application.MainMenu != null)
            {
                Application.MainMenu.Refresh();
            }
            fpsCounter.Refresh();
            // Refresh mouse position of every frame to make HitTest work properly if mouse is outside of the screen.
            RefreshMousePosition();
            if (active || Input.IsSimulationRunning)
            {
                Input.ProcessPendingInputEvents(delta);
            }
            if (Input.IsSimulationRunning)
            {
                Application.Input.Simulator.OnProcessingPendingInputEvents();
            }
            RaiseUpdating(delta);
            AudioSystem.Update();
            if (active || Input.IsSimulationRunning)
            {
                Input.CopyKeysState();
                Input.TextInput = null;
            }
            if (wasInvalidated || renderingState == RenderingState.RenderDeferred)
            {
                renderControl.Invalidate();
            }
            // We give one update cycle to handle files drop
            // (files dropped event may be fired inside update)
            if (Input.DroppedFiles.Count > 0 || shouldCleanDroppedFiles)
            {
                if (shouldCleanDroppedFiles)
                {
                    Input.DroppedFiles.Clear();
                }
                shouldCleanDroppedFiles = !shouldCleanDroppedFiles;
            }
            renderingState = renderControl.CanRender ? RenderingState.Updated : RenderingState.Rendered;
            WaitForRendering();
            if (renderControl.CanRender)
            {
                RaiseSync();
                if (AsyncRendering)
                {
                    renderCompleted.Reset();
                    renderReady.Set();
                }
            }
        }