Example #1
0
        /// <summary>
        ///     Sets the specified window's show state.
        /// </summary>
        /// <param name="windowHandle">A handle to the window.</param>
        /// <param name="state">Controls how the window is to be shown.</param>
        /// <returns>
        ///     If the window was previously visible, the return value is <c>true</c>, otherwise the return value is
        ///     <c>false</c>.
        /// </returns>
        public static bool ShowWindow(IntPtr windowHandle, WindowStates state)
        {
            // Check if the handle is valid
            HandleManipulator.ValidateAsArgument(windowHandle, "windowHandle");

            // Change the state of the window
            return(User32.ShowWindow(windowHandle, state));
        }
Example #2
0
        private void SetWindowPlacement(WindowStates windowState)
        {
            WindowPlacement placement = _appSettings.SidebarMode ? _appSettings.SidebarWindowPlacement : _appSettings.WindowPlacement;

            if (placement != null)
            {
                this.SetWindowPlacement(placement, windowState);
            }
        }
Example #3
0
        /// <summary>
        /// Sets the window state.
        /// </summary>
        /// <param name="newState">New state.</param>
        private void SetState(WindowStates newState)
        {
            gameWindow.IsBorderless = !(newState == WindowStates.WINDOWED);
            currentWindowState      = newState;

            SetSize(currentWindowSize);

            OnWindowStateChange?.Invoke(newState);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EngillEngine.Core.Util.Window"/> class.
        /// </summary>
        /// <param name="gameWindow">Game window.</param>
        public Window(GameWindow gameWindow)
        {
            this.gameWindow = gameWindow;
            gameWindow.AllowUserResizing = true;
            currentWindowState           = WindowStates.WINDOWED;
            currentWindowSize            = gameWindow.ClientBounds.Size;
            DisplayMode displayMode    = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode;
            Point       fullscreenSize = new Point(displayMode.Width, displayMode.Height);

            currentWindowFullscreenSize = fullscreenSize;
        }
Example #5
0
 public virtual void Draw(Graphics graphics, Func <Vector3, Point> to2D, Action redraw, Perspective perspective)
 {
     foreach (var activeArea in WindowStates.
              Aggregate(new List <IDiagramDrawable>(), (l, w) => {
         l.AddRange(w.Features.Where(f => f is IDiagramDrawable).Select(f => f as IDiagramDrawable));
         return(l);
     }))
     {
         activeArea.Draw(graphics, to2D, redraw, perspective);
     }
 }
 /// <summary>
 /// Registers the window for the specified Task
 /// </summary>
 public void RegisterWindow <T_>(T window) where T_ : IWindow, new()
 {
     if (Windows.ContainsKey(window) && Windows[window] != null)
     {
         Windows[window].Add(new T_());
     }
     else
     {
         Windows[window] = new HashSet <IWindow> {
             new T_()
         }
     };
     WindowStates.Add(window, false);
 }
    public void SetToState(WindowStates windowState)
    {
        switch (windowState)
        {
        case WindowStates.MISSION_SELECT:
            missionDetailsWindow.SetActive(false);
            this.missionDetailsWindow.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
            this.missionDetailsWindow.GetComponent <MissionDetailWindow>().IsOpen = false;
            this.mainMenueController.ActivateDeployUI(false);
            mainMenueController.Unexpand();
            // Reset MissionSelect
            // Reset GeneralMenue
            // Reset SquadMenue
            break;

        case WindowStates.GENERAL_SELECT:
            this.missionDetailsWindow.SetActive(true);
            this.mainMenueController.ActivateDeployUI(false);
            if (!mainMenueController.IsExpanded || mainMenueController.EnabledMenue + 1 != 1)
            {
                this.mainMenueController.ToggleMenue(1);
            }
            // Reset GeneralMenue
            // Reset SquadMenue
            break;

        case WindowStates.SQUAD_SELECT:
            this.missionDetailsWindow.SetActive(false);
            this.missionDetailsWindow.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
            this.missionDetailsWindow.GetComponent <MissionDetailWindow>().IsOpen = false;
            this.mainMenueController.ActivateDeployUI(true);
            if (!mainMenueController.IsExpanded || mainMenueController.EnabledMenue + 1 != 2)
            {
                this.mainMenueController.ToggleMenue(2);
            }
            // Reset SquadMenue
            break;

        default:
            throw new ArgumentOutOfRangeException("windowState", windowState, null);
        }

        aktState = windowState;
    }
Example #8
0
        public void TakeScreenshot(string filenameWithoutExt, bool playSound = true, bool waitUntilActive = true)
        {
            string path = Path.Combine(Environment.CurrentDirectory, "ScreenCaptures");

            (new Thread(() =>
            {
                if (!IsOpened || !IsConnected)
                {
                    return;
                }

                do
                {
                    WindowStates state = WindowState;
                    if (state == WindowStates.Minimized)
                    {
                        Restore();
                    }
                    else if (state == WindowStates.Hidden)
                    {
                        Show();
                    }
                    else if (state == WindowStates.Inactive)
                    {
                        BringToFront();
                    }
                    Thread.Sleep(100);
                } while (waitUntilActive && WindowState != WindowStates.Active);

                var image = ScreenCapture.CaptureActiveWindow();
                string[] files = Directory.GetFiles(path, filenameWithoutExt + "*");
                string newFilename = filenameWithoutExt + (files.Length > 0 ? " (" + files.Length.ToString() + ")" : "") + ".jpg";
                image.Save(Path.Combine(path, newFilename), System.Drawing.Imaging.ImageFormat.Jpeg);
                SetStatusText("Screenshot saved.");
                string soundFile = Path.Combine(new string[] { Environment.CurrentDirectory, "Alarms", "Camera Shutter.wav" });
                if (playSound && File.Exists(soundFile))
                {
                    new SoundPlayer(soundFile).Play();
                }
            })).Start();
        }
Example #9
0
        public void StartWindows()
        {
            do
            {
                switch (currentState)
                {
                case WindowStates.Exit:
                    needToRender = false;
                    break;

                case WindowStates.MainMenu:
                    State = menuWindow.ShowMenu(State);
                    break;

                case WindowStates.PlayerSelect:
                    State         = playerSelectionWindow.ShowPlayerSelection(State);
                    playersInGame = playerSelectionWindow.GetPlayersNumber();
                    break;

                case WindowStates.DiseSelect:
                    State     = diceSelectionWindow.ShowDiceWindow(State);
                    diceValue = diceSelectionWindow.GetDiceNumber();
                    break;

                case WindowStates.Game:
                    gameController.StartGame(playersInGame, diceValue);
                    State = gameController.DetermineState();
                    break;

                case WindowStates.ExtraRound:

                    break;

                case WindowStates.Winnner:
                    State = winWindow.ShowWinner(gameController.GetWinnerID(), gameController.GetWinnerValue(), State);
                    break;
                }

                currentState = (WindowStates)State;
            } while (needToRender);
        }
Example #10
0
        public void RegisterHandlers(WindowInfo window = null)
        {
            if (window == null)
            {
                window = WindowInfo.Find(this.Handle);
            }

            if (!Runtime.Instance.WindowManager.Exists(window) ||
                this.handlersRegistered)
            {
                return;
            }

            window.OriginalState    = this.LastState;
            window.IsPinned         = this.IsPinned;
            window.Hidden          += (s, e) => { this.State |= WindowStates.Hidden; };
            window.Shown           += (s, e) => { this.State &= ~WindowStates.Hidden; };
            window.Pinned          += (s, e) => { this.State |= WindowStates.Pinned; };
            window.Unpinned        += (s, e) => { this.State &= ~WindowStates.Pinned; };
            window.Locked          += (s, e) => { this.State |= WindowStates.Protected; };
            window.Unlocked        += (s, e) => { this.State &= ~WindowStates.Protected; };
            this.StateChanged      += (s, e) => { HiddenWindowStore.Save(Runtime.Instance.Store); };
            this.handlersRegistered = true;
        }
        private bool MoveToEdge(MoveToDirections direction, WindowStates windowState,
            double distanceToTopBoundaryIfFloating, double distanceToBottomBoundaryIfFloating,
            double distanceToLeftBoundaryIfFloating, double distanceToRightBoundaryIfFloating)
        {
            Log.InfoFormat("MoveToEdge called with direction:{0}, windowState:{1}, distanceToTopBoundaryIfFloating:{2}, distanceToBottomBoundaryIfFloating:{3}, distanceToLeftBoundaryIfFloating:{4}, distanceToRightBoundaryIfFloating: {5}",
                direction, windowState, distanceToTopBoundaryIfFloating, distanceToBottomBoundaryIfFloating, distanceToLeftBoundaryIfFloating, distanceToRightBoundaryIfFloating);

            bool adjustment = false;
            switch (windowState)
            {
                case WindowStates.Docked:
                    //Jump to (and dock on) a different edge
                    var dockPosition = getDockPosition();
                    if (direction == MoveToDirections.Top && dockPosition != DockEdges.Top)
                    {
                        saveDockPosition(DockEdges.Top);
                        adjustment = true;
                    }
                    else if (direction == MoveToDirections.Bottom && dockPosition != DockEdges.Bottom)
                    {
                        saveDockPosition(DockEdges.Bottom);
                        adjustment = true;
                    }
                    else if (direction == MoveToDirections.Left && dockPosition != DockEdges.Left)
                    {
                        saveDockPosition(DockEdges.Left);
                        adjustment = true;
                    }
                    else if (direction == MoveToDirections.Right && dockPosition != DockEdges.Right)
                    {
                        saveDockPosition(DockEdges.Right);
                        adjustment = true;
                    }
                    break;

                case WindowStates.Floating:
                    //Jump to edge(s)
                    switch (direction) //Handle horizontal adjustment
                    {
                        case MoveToDirections.Left:
                        case MoveToDirections.BottomLeft:
                        case MoveToDirections.TopLeft:
                            window.Left -= distanceToLeftBoundaryIfFloating;
                            break;

                        case MoveToDirections.Right:
                        case MoveToDirections.BottomRight:
                        case MoveToDirections.TopRight:
                            window.Left += distanceToRightBoundaryIfFloating;
                            break;
                    }
                    switch (direction) //Handle vertical adjustment
                    {
                        case MoveToDirections.Bottom:
                        case MoveToDirections.BottomLeft:
                        case MoveToDirections.BottomRight:
                            window.Top += distanceToBottomBoundaryIfFloating;
                            break;

                        case MoveToDirections.Top:
                        case MoveToDirections.TopLeft:
                        case MoveToDirections.TopRight:
                            window.Top -= distanceToTopBoundaryIfFloating;
                            break;
                    }
                    adjustment = true;
                    break;
            }
            return adjustment;
        }
        private bool Move(MoveToDirections direction, double amountInPx, double distanceToTopBoundaryIfFloating,
            double distanceToBottomBoundaryIfFloating, double distanceToLeftBoundaryIfFloating,
            double distanceToRightBoundaryIfFloating, WindowStates windowState, Rect floatingSizeAndPosition)
        {
            Log.InfoFormat("Move called with direction:{0}, amountInPx:{1}, distanceToTopBoundaryIfFloating:{2}, distanceToBottomBoundaryIfFloating:{3}, distanceToLeftBoundaryIfFloating:{4}, distanceToRightBoundaryIfFloating: {5}, windowState:{6}, floatingSizeAndPosition.Top:{7}, floatingSizeAndPosition.Bottom:{8}, floatingSizeAndPosition.Left:{9}, floatingSizeAndPosition.Right:{10}",
                direction, amountInPx, distanceToTopBoundaryIfFloating, distanceToBottomBoundaryIfFloating, distanceToLeftBoundaryIfFloating, distanceToRightBoundaryIfFloating, windowState, floatingSizeAndPosition.Top, floatingSizeAndPosition.Bottom, floatingSizeAndPosition.Left, floatingSizeAndPosition.Right);

            bool adjustment = false;
            var yAdjustmentAmount = amountInPx / Graphics.DipScalingFactorY;
            var xAdjustmentAmount = amountInPx / Graphics.DipScalingFactorX;
            var yAdjustmentToBottom = distanceToBottomBoundaryIfFloating < 0 ? distanceToBottomBoundaryIfFloating : yAdjustmentAmount.CoerceToUpperLimit(distanceToBottomBoundaryIfFloating);
            var yAdjustmentToTop = distanceToTopBoundaryIfFloating < 0 ? distanceToTopBoundaryIfFloating : yAdjustmentAmount.CoerceToUpperLimit(distanceToTopBoundaryIfFloating);
            var xAdjustmentToLeft = distanceToLeftBoundaryIfFloating < 0 ? distanceToLeftBoundaryIfFloating : xAdjustmentAmount.CoerceToUpperLimit(distanceToLeftBoundaryIfFloating);
            var xAdjustmentToRight = distanceToRightBoundaryIfFloating < 0 ? distanceToRightBoundaryIfFloating : xAdjustmentAmount.CoerceToUpperLimit(distanceToRightBoundaryIfFloating);

            switch (windowState)
            {
                case WindowStates.Docked:
                    switch (getDockPosition())
                    {
                        case DockEdges.Top:
                            switch (direction)
                            {
                                case MoveToDirections.Bottom:
                                case MoveToDirections.BottomLeft:
                                case MoveToDirections.BottomRight:
                                    UnRegisterAppBar();
                                    saveWindowState(WindowStates.Floating);
                                    savePreviousWindowState(WindowStates.Floating);
                                    window.Top = screenBoundsInDp.Top;
                                    switch (direction)
                                    {
                                        case MoveToDirections.Bottom:
                                            window.Left = floatingSizeAndPosition.Left;
                                            break;

                                        case MoveToDirections.BottomLeft:
                                            window.Left = floatingSizeAndPosition.Left - xAdjustmentToLeft;
                                            break;

                                        case MoveToDirections.BottomRight:
                                            window.Left = floatingSizeAndPosition.Left + xAdjustmentToRight;
                                            break;
                                    }
                                    window.Height = floatingSizeAndPosition.Height;
                                    window.Width = floatingSizeAndPosition.Width;
                                    adjustment = true;
                                    break;
                            }
                            break;

                        case DockEdges.Bottom:
                            switch (direction)
                            {
                                case MoveToDirections.Top:
                                case MoveToDirections.TopLeft:
                                case MoveToDirections.TopRight:
                                    UnRegisterAppBar();
                                    saveWindowState(WindowStates.Floating);
                                    savePreviousWindowState(WindowStates.Floating);
                                    window.Top = screenBoundsInDp.Bottom - floatingSizeAndPosition.Height;
                                    switch (direction)
                                    {
                                        case MoveToDirections.Top:
                                            window.Left = floatingSizeAndPosition.Left;
                                            break;

                                        case MoveToDirections.TopLeft:
                                            window.Left = floatingSizeAndPosition.Left - xAdjustmentToLeft;
                                            break;

                                        case MoveToDirections.TopRight:
                                            window.Left = floatingSizeAndPosition.Left + xAdjustmentToRight;
                                            break;
                                    }
                                    window.Height = floatingSizeAndPosition.Height;
                                    window.Width = floatingSizeAndPosition.Width;
                                    adjustment = true;
                                    break;
                            }
                            break;

                        case DockEdges.Left:
                            switch (direction)
                            {
                                case MoveToDirections.Right:
                                case MoveToDirections.TopRight:
                                case MoveToDirections.BottomRight:
                                    UnRegisterAppBar();
                                    saveWindowState(WindowStates.Floating);
                                    savePreviousWindowState(WindowStates.Floating);
                                    window.Left = screenBoundsInDp.Left;
                                    switch (direction)
                                    {
                                        case MoveToDirections.Right:
                                            window.Top = floatingSizeAndPosition.Top;
                                            break;

                                        case MoveToDirections.TopRight:
                                            window.Top = floatingSizeAndPosition.Top - yAdjustmentToTop;
                                            break;

                                        case MoveToDirections.BottomRight:
                                            window.Top = floatingSizeAndPosition.Top + yAdjustmentToBottom;
                                            break;
                                    }
                                    window.Height = floatingSizeAndPosition.Height;
                                    window.Width = floatingSizeAndPosition.Width;
                                    adjustment = true;
                                    break;
                            }
                            break;

                        case DockEdges.Right:
                            switch (direction)
                            {
                                case MoveToDirections.Left:
                                case MoveToDirections.TopLeft:
                                case MoveToDirections.BottomLeft:
                                    UnRegisterAppBar();
                                    saveWindowState(WindowStates.Floating);
                                    savePreviousWindowState(WindowStates.Floating);
                                    window.Left = screenBoundsInDp.Right - floatingSizeAndPosition.Width;
                                    switch (direction)
                                    {
                                        case MoveToDirections.Left:
                                            window.Top = floatingSizeAndPosition.Top;
                                            break;

                                        case MoveToDirections.TopLeft:
                                            window.Top = floatingSizeAndPosition.Top - yAdjustmentToTop;
                                            break;

                                        case MoveToDirections.BottomLeft:
                                            window.Top = floatingSizeAndPosition.Top + yAdjustmentToBottom;
                                            break;
                                    }
                                    window.Height = floatingSizeAndPosition.Height;
                                    window.Width = floatingSizeAndPosition.Width;
                                    adjustment = true;
                                    break;
                            }
                            break;
                    }
                    break;

                case WindowStates.Floating:
                    switch (direction) //Handle horizontal adjustment
                    {
                        case MoveToDirections.Left:
                        case MoveToDirections.BottomLeft:
                        case MoveToDirections.TopLeft:
                            if (xAdjustmentAmount > xAdjustmentToLeft)
                            {
                                saveWindowState(WindowStates.Docked);
                                savePreviousWindowState(WindowStates.Docked);
                                saveDockPosition(DockEdges.Left);
                                RegisterAppBar();
                            }
                            else
                            {
                                window.Left -= xAdjustmentToLeft;
                            }
                            break;

                        case MoveToDirections.Right:
                        case MoveToDirections.BottomRight:
                        case MoveToDirections.TopRight:
                            if (xAdjustmentAmount > xAdjustmentToRight)
                            {
                                saveWindowState(WindowStates.Docked);
                                savePreviousWindowState(WindowStates.Docked);
                                saveDockPosition(DockEdges.Right);
                                RegisterAppBar();
                            }
                            else
                            {
                                window.Left += xAdjustmentToRight;
                            }
                            break;
                    }
                    switch (direction) //Handle vertical adjustment
                    {
                        case MoveToDirections.Bottom:
                        case MoveToDirections.BottomLeft:
                        case MoveToDirections.BottomRight:
                            if (yAdjustmentAmount > yAdjustmentToBottom)
                            {
                                saveWindowState(WindowStates.Docked);
                                savePreviousWindowState(WindowStates.Docked);
                                saveDockPosition(DockEdges.Bottom);
                                RegisterAppBar();
                            }
                            else
                            {
                                window.Top += yAdjustmentToBottom;
                            }
                            break;

                        case MoveToDirections.Top:
                        case MoveToDirections.TopLeft:
                        case MoveToDirections.TopRight:
                            if (yAdjustmentAmount > yAdjustmentToTop)
                            {
                                saveWindowState(WindowStates.Docked);
                                savePreviousWindowState(WindowStates.Docked);
                                saveDockPosition(DockEdges.Top);
                                RegisterAppBar();
                            }
                            else
                            {
                                window.Top -= yAdjustmentToTop;
                            }
                            break;
                    }
                    adjustment = true;
                    break;
            }
            return adjustment;
        }
Example #13
0
 /// <summary>
 /// Virtual method which the game may override if it needs to respond to the game window resizing
 /// </summary>
 /// <param name="windowState">The new window state</param>
 /// <param name="newSize">A Vector2 structure containing the new window size</param>
 /// <param name="oldSize">A Vector2 structure containing the previous window size</param>
 protected virtual void Resize(WindowStates windowState, Vector2 newSize, Vector2 oldSize)
 {
     // Nothing to do by default
 }
Example #14
0
        /// <summary>
        /// Check to see whether the game window has resized since the last update, and inform the
        /// rest of the game if it has.
        /// </summary>
        private void CheckForResize()
        {
            bool notifyGame = false;
            // The window bounds
            Vector2 windowSize;
            // The window bounds without scaling
            Vector2 windowSizeUnscaled;


#if WINDOWS_PHONE
            // Read the raw unscaled window dimensions
            windowSizeUnscaled = new Vector2(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
            // The window on Windows Phone is not scaled so the window size will always match
            windowSize = windowSizeUnscaled;
#else
            // Read the raw unscaled window dimensions
            windowSizeUnscaled = new Vector2((float)_window.Bounds.Width, (float)_window.Bounds.Height);
            // Scale the dimensions by the device dpi to get the actual pixel dimension of the window
            windowSize = windowSizeUnscaled * Windows.Graphics.Display.DisplayProperties.LogicalDpi / 96;
#endif

            // Have the dimensions changed since we last looked at them?
            if (!_knownWindowSize.Equals(windowSize))
            {
                // Do we need to tell the game about the resize?
                // (If this is the first call, knownWidth will be -1, and so we won't worry in that case,
                // we'll only notify on subsequent changes to the window size).
                if (!_knownWindowSize.Equals(Vector2.Zero))
                {
                    notifyGame = true;
                }

                // Determine the new window state
#if WINDOWS_PHONE
                // Windows Phone doesn't support window states, we will always be FullScreen
                CurrentWindowState = WindowStates.FullScreen;
#else
                // Read the current application view state and use that to derive the
                // appropriate WindowStates enumeration item.
                switch (Windows.UI.ViewManagement.ApplicationView.Value)
                {
                case ApplicationViewState.Filled:
                    CurrentWindowState = WindowStates.Filled;
                    break;

                case ApplicationViewState.Snapped:
                    CurrentWindowState = WindowStates.Snapped;
                    break;

                default:
                    CurrentWindowState = WindowStates.FullScreen;
                    break;
                }
#endif

                // Tell the game that it has resized
                if (notifyGame)
                {
                    // Call the Resize method of GameHost so that the game class can respond
                    // if it is overriding it.
                    Resize(CurrentWindowState, windowSize, _knownWindowSize);

                    // Notify all game mode handlers about the resize too
                    foreach (GameModeBase gameMode in _gameModeHandlers.Values)
                    {
                        gameMode.Resize(CurrentWindowState, windowSize, _knownWindowSize);
                    }
                }

                // Remember the new width and height
                _knownWindowSize = windowSize;
            }
        }
Example #15
0
        /// <summary>
        /// Provides derived classes an opportunity to handle changes
        /// to the WindowState property.
        /// </summary>
        /// <param name="oldWindowState">The old WindowState value</param>
        /// <param name="newWindowState">The new WindowState value</param>
        protected virtual void OnWindowStateChanged(
            WindowStates oldWindowState, WindowStates newWindowState)
        {
            if (oldWindowState == newWindowState)
            {
                return;
            }

            if (_restorePositionOnStateChange)
            {
                if (oldWindowState == WindowStates.Snapped)
                {
                    this.StopCurrentSnapStoryboard();

                    if (!_isDraggingFromSnapped)
                    {
#pragma warning disable 4014
                        this.AnimateStraightSnapAsync(_lastWindowPosition.X, _lastWindowPosition.Y);
#pragma warning restore 4014
                    }
                }
                else if (oldWindowState == WindowStates.Maximized)
                {
                    if (!_isDraggingFromSnapped)
                    {
                        this.X = _lastWindowPosition.X;
                        this.Y = _lastWindowPosition.Y;
                    }

                    if (_lastWindowWidth != 0)
                    {
                        this.Width = _lastWindowWidth;
                        this.Height = _lastWindowHeight;
                    }
                }
            }

            this.UpdateVisualStates(true);
        }
Example #16
0
        /// <summary>
        /// Snaps to nearest edge.
        /// </summary>
        public async Task SnapToEdgeAsync()
        {
            if (WindowEdgeSnapBehavior == WindowEdgeSnapBehavior.None)
            {
                return;
            }

            if (this.Parent == null)
            {
                await this.WaitForLoadedAsync();
            }

            if (WindowState == WindowStates.Normal)
            {
                _lastWindowPosition.X = this.X;
                _lastWindowPosition.Y = this.Y;
            }

            double angle;
            var movableAreaBoundaries = this.GetMovableArea();

            double distanceToLeft = this.X.Distance(movableAreaBoundaries.Left);
            double distanceToTop = this.Y.Distance(movableAreaBoundaries.Top);
            double distanceToRight = this.X.Distance(movableAreaBoundaries.Right);
            double distanceToBottom = this.Y.Distance(movableAreaBoundaries.Bottom);
            double minDistance = distanceToLeft;
            var x = movableAreaBoundaries.Left - 1;
            var y = this.Y;

            if (distanceToTop < minDistance)
            {
                minDistance = distanceToTop;
                x = this.X;
                y = movableAreaBoundaries.Top - 1;
            }

            if (distanceToRight < minDistance)
            {
                minDistance = distanceToRight;
                x = movableAreaBoundaries.Right + 1;
                y = this.Y;
            }

            if (distanceToBottom < minDistance)
            {
                x = this.X;
                y = movableAreaBoundaries.Bottom + 1;
            }

            var desiredPosition = this.GetDesiredPosition(x, y, out angle, out _lastSnapEdge);
            x = desiredPosition.X;
            y = desiredPosition.Y;

            _restorePositionOnStateChange = false;
            this.WindowState = WindowStates.Snapped;
            _restorePositionOnStateChange = true;

            if (WindowEdgeSnapBehavior != WindowEdgeSnapBehavior.ToTitleBarWithRotation)
            {
                await AnimateStraightSnapAsync(x, y);
            }
            else
            {
                await AnimateRotatedSnapAsync(x, y, angle);
            }
        }
Example #17
0
 public static extern bool ShowWindow(IntPtr hWnd, WindowStates nCmdShow);
Example #18
0
 public static extern bool ShowWindow(IntPtr hWnd, WindowStates nCmdShow);
        private void RunReader(object obj)
        {
            var token = new CancellationTokenSource();
            CancellationToken ct = token.Token;
            //Start new thread to read form file.
            Task.Factory.StartNew(() =>
            {

                WindowState = WindowStates.Running;
                var fs = new FileStream(@"C:\Users\Madalina\Desktop\Radu\SampleData.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                var tr = new StreamReader(fs);
                string line;

                while (true)
                {
                    line = tr.ReadLine();
                    if (!String.IsNullOrEmpty(line))
                    {
                        //Update on the UI thread.
                        _dispatcherContext.Invoke(() =>
                        {
                            var stock = new Stock(line.Split(':')[0], new Price(Convert.ToDouble(line.Split(':')[1]), DateTime.Now));
                            ct.ThrowIfCancellationRequested();
                            if (_stockList.Contains(stock))
                            {
                                foreach(Stock item in _stockList)
                                {
                                    if (item.InstrumentName == stock.InstrumentName)
                                    {
                                        item.PreviousPrice = item.CurrentPrice;
                                        item.CurrentPrice = stock.CurrentPrice;
                                    }
                                }
                            }
                            else
                            {
                                _stockList.Add(stock);
                            }
                        });
                        Thread.Sleep(500);
                    }
                }
                WindowState = WindowStates.Complete;
            }).ContinueWith(t =>
            {
                WindowState = WindowStates.Failed;
            }, TaskContinuationOptions.OnlyOnFaulted
                );
        }
Example #20
0
 /// <summary>
 /// Restores the window
 /// </summary>
 public async Task RestoreAsync()
 {
     this.Visibility = Visibility.Visible;
     this.WindowState = WindowStates.Normal;
     await this.ActivateAsync();
 }
Example #21
0
        /// <summary>
        /// Maximizes the window
        /// </summary>
        public void Maximize()
        {
            if (WindowState == WindowStates.Normal)
            {
                _lastWindowPosition.X = this.X;
                _lastWindowPosition.Y = this.Y;
                _lastWindowWidth = this.ActualWidth;
                _lastWindowHeight = this.ActualHeight;
            }

            this.X = - this.BorderThickness.Left;
            this.Y = - this.BorderThickness.Top;

            if (_parent != null)
            {
                this.Width = _parent.ActualWidth + this.BorderThickness.Left + this.BorderThickness.Right;
                this.Height = _parent.ActualHeight + this.BorderThickness.Top + this.BorderThickness.Bottom;
            }

            this.UpdateVisualStates(true);
            this.WindowState = WindowStates.Maximized;
        }
Example #22
0
        private void SnapToEdgeIfNecessary()
        {
            if (WindowEdgeSnapBehavior == WindowEdgeSnapBehavior.None)
            {
                return;
            }

            double angle;
            var desiredPosition = GetDesiredPosition(this.X, this.Y, out angle, out _lastSnapEdge);
            var x = desiredPosition.X;
            var y = desiredPosition.Y;

            if (_layoutGridTransform == null || (
                x == this.X &&
                y == this.Y &&
                angle == _layoutGridTransform.Rotation))
            {
                return;
            }

            _restorePositionOnStateChange = false;
            this.WindowState = WindowStates.Snapped;
            _restorePositionOnStateChange = true;

            if (WindowEdgeSnapBehavior == WindowEdgeSnapBehavior.Straight ||
                WindowEdgeSnapBehavior == WindowEdgeSnapBehavior.StraightToTitleBar)
            {
#pragma warning disable 4014
                AnimateStraightSnapAsync(x, y);
#pragma warning restore 4014
            }
            else
            {
#pragma warning disable 4014
                AnimateRotatedSnapAsync(x, y, angle);
#pragma warning restore 4014
            }
        }
Example #23
0
        private void OnBorderManipulationInertiaStarting(object sender, ManipulationInertiaStartingRoutedEventArgs e)
        {
            _flickStartX = this.X;
            _flickStartY = this.Y;
            _flickStartCumulativeX = e.Cumulative.Translation.X;
            _flickStartCumulativeY = e.Cumulative.Translation.Y;

            if (_isDraggingFromSnapped)
            {
                // TODO: Prevent snapping if flicking towards center of screen
            }

            if (_layoutGridTransform != null)
            {
                _flickStartAngle = _layoutGridTransform.Rotation;
            }

            var naturalFlickDisplacement = e.GetExpectedDisplacement();
            e.TranslationBehavior.DesiredDisplacement = naturalFlickDisplacement;
            _naturalFlickDisplacementX = e.GetExpectedDisplacementX();
            _naturalFlickDisplacementY = e.GetExpectedDisplacementY();

            Edges desiredSnapEdge;
            var desiredPosition = this.GetDesiredPosition(_flickStartX + _naturalFlickDisplacementX, _flickStartY + _naturalFlickDisplacementY, out _flickAdjustedEndAngle, out desiredSnapEdge);
            _flickAdjustedEndX = desiredPosition.X;
            _flickAdjustedEndY = desiredPosition.Y;

            if (desiredSnapEdge == Edges.None)
            {
                return;
            }

            _lastSnapEdge = desiredSnapEdge;
            _isAdjustedFlick = true;

            if (_flickAdjustedEndX != _naturalFlickDisplacementX && (_flickAdjustedEndY == _naturalFlickDisplacementY ||
                _flickAdjustedEndX.Distance(_naturalFlickDisplacementX) > _flickAdjustedEndY.Distance(_naturalFlickDisplacementY)))
            {
                // snap to left or right side
                e.SetDesiredDisplacementX(_flickAdjustedEndX - _flickStartX);
                _naturalFlickDisplacementX = e.GetExpectedDisplacementX();
                _naturalFlickDisplacementY = e.GetExpectedDisplacementY();
            }
            else if (_flickAdjustedEndY != _naturalFlickDisplacementY && (_flickAdjustedEndX == _naturalFlickDisplacementX ||
                _flickAdjustedEndX.Distance(_naturalFlickDisplacementY) > _flickAdjustedEndY.Distance(_naturalFlickDisplacementX)))
            {
                // snap to left or right side
                e.SetDesiredDisplacementY(_flickAdjustedEndY - _flickStartY);
                _naturalFlickDisplacementX = e.GetExpectedDisplacementX();
                _naturalFlickDisplacementY = e.GetExpectedDisplacementY();
            }

            if (e.GetExpectedDisplacementDuration() > 0.5)
            {
                _isFlickTooLong = true;
                _restorePositionOnStateChange = false;
                this.WindowState = WindowStates.Snapped;
                _restorePositionOnStateChange = true;

                if (WindowEdgeSnapBehavior != WindowEdgeSnapBehavior.ToTitleBarWithRotation)
                {
#pragma warning disable 4014
                    AnimateStraightSnapAsync(_flickAdjustedEndX, _flickAdjustedEndY);
#pragma warning restore 4014
                }
                else
                {
#pragma warning disable 4014
                    AnimateRotatedSnapAsync(_flickAdjustedEndX, _flickAdjustedEndY, _flickAdjustedEndAngle);
#pragma warning restore 4014
                }
            }
        }
Example #24
0
        private async void OnBorderManipulationStarting(object sender, ManipulationStartedRoutedEventArgs e)
        {
            if (this.WindowState == WindowStates.Normal)
            {
                _lastWindowPosition.X = this.X;
                _lastWindowPosition.Y = this.Y;
            }
            else if (this.WindowState == WindowStates.Snapped)
            {
                _isDraggingFromSnapped = true;
            }

            //if (_lastWindowWidth != 0)
            //{
            //    this.Width = _lastWindowWidth;
            //    this.Height = _lastWindowHeight;
            //}

            _restorePositionOnStateChange = false;
            this.WindowState = WindowStates.Normal;
            _restorePositionOnStateChange = true;
            await this.ActivateAsync(); 
            
            _isAdjustedFlick = false;
        }
Example #25
0
 public static bool ShowWindow(IntPtr windowHandle, WindowStates state)
 {
     HandleManipulator.ValidateAsArgument(windowHandle, "windowHandle");
     return(User32.ShowWindow(windowHandle, state));
 }
Example #26
0
        private void SnapToEdgeIfNecessary()
        {
            if (WindowEdgeSnapBehavior == WindowEdgeSnapBehavior.None)
            {
                return;
            }

            double angle;
            var desiredPosition = GetDesiredPosition(this.X, this.Y, out angle, out _lastSnapEdge);
            var x = desiredPosition.X;
            var y = desiredPosition.Y;

            if (_layoutGridTransform == null || (
                x == this.X &&
                y == this.Y &&
                angle == _layoutGridTransform.Rotation))
            {
                return;
            }

            this.WindowState = WindowStates.Snapped;

            if (WindowEdgeSnapBehavior == WindowEdgeSnapBehavior.Straight ||
                WindowEdgeSnapBehavior == WindowEdgeSnapBehavior.StraightToTitleBar)
            {
                AnimateStraightSnapAsync(x, y);
            }
            else
            {
                AnimateRotatedSnapAsync(x, y, angle);
            }
        }
Example #27
0
        /// <summary>
        ///     Sets the specified window's show state.
        /// </summary>
        /// <param name="windowHandle">A handle to the window.</param>
        /// <param name="state">Controls how the window is to be shown.</param>
        /// <returns>
        ///     If the window was previously visible, the return value is <c>true</c>, otherwise the return value is
        ///     <c>false</c>.
        /// </returns>
        public static bool ShowWindow(IntPtr windowHandle, WindowStates state)
        {
            // Check if the handle is valid
            HandleManipulator.ValidateAsArgument(windowHandle, "windowHandle");

            // Change the state of the window
            return NativeMethods.ShowWindow(windowHandle, state);
        }
Example #28
0
        public static bool SetWindowPlacement(this System.Windows.Window window, WindowPlacement placement, WindowStates windowState)
        {
            placement.Length = Marshal.SizeOf(typeof(WindowPlacement));
            placement.Flags  = 0;

            switch (windowState)
            {
            case WindowStates.Minimized:
                placement.ShowCommand = (int)WindowStates.Minimized;
                break;

            case WindowStates.Normal when placement.ShowCommand == (int)WindowStates.Minimized:
                placement.ShowCommand = (int)WindowStates.Normal;
                break;

            case WindowStates.Hidden:
                placement.ShowCommand = (int)WindowStates.Hidden;
                break;
            }

            return(SetWindowPlacement(new WindowInteropHelper(window).Handle, placement));
        }