Exemplo n.º 1
0
        public Point GetAlignedOrigin(Vector2 textSize, string text, Rectangle destinationRectangle, WindowAlignment alignment = WindowAlignment.TopLeft)
        {
            text.ThrowIfNull("text");

            switch (alignment)
            {
                case WindowAlignment.TopLeft:
                    return new Point(destinationRectangle.X, destinationRectangle.Y);
                case WindowAlignment.TopCenter:
                    return new Point((destinationRectangle.Center.X - (textSize.X / 2)).Round(), destinationRectangle.Y);
                case WindowAlignment.TopRight:
                    return new Point((destinationRectangle.Right - textSize.X).Round(), destinationRectangle.Y);
                case WindowAlignment.RightCenter:
                    return new Point((destinationRectangle.Right - textSize.X).Round(), (destinationRectangle.Center.Y - (textSize.Y / 2)).Round());
                case WindowAlignment.BottomRight:
                    return new Point((destinationRectangle.Right - textSize.X).Round(), (destinationRectangle.Bottom - textSize.Y).Round());
                case WindowAlignment.BottomCenter:
                    return new Point((destinationRectangle.Center.X - (textSize.X / 2)).Round(), (destinationRectangle.Bottom - textSize.Y).Round());
                case WindowAlignment.BottomLeft:
                    return new Point(destinationRectangle.X, (destinationRectangle.Bottom - textSize.Y).Round());
                case WindowAlignment.LeftCenter:
                    return new Point(destinationRectangle.X, (destinationRectangle.Center.Y - (textSize.Y / 2)).Round());
                case WindowAlignment.Center:
                    return new Point((destinationRectangle.Center.X - (textSize.X / 2)).Round(), (destinationRectangle.Center.Y - (textSize.Y / 2)).Round());
                default:
                    throw new ArgumentOutOfRangeException("alignment");
            }
        }
Exemplo n.º 2
0
        public static int GetMenuItemId(this WindowAlignment alignment)
        {
            switch (alignment)
            {
            case WindowAlignment.TopLeft: return(MenuItemId.SC_ALIGN_TOP_LEFT);

            case WindowAlignment.TopCenter: return(MenuItemId.SC_ALIGN_TOP_CENTER);

            case WindowAlignment.TopRight: return(MenuItemId.SC_ALIGN_TOP_RIGHT);

            case WindowAlignment.MiddleLeft: return(MenuItemId.SC_ALIGN_MIDDLE_LEFT);

            case WindowAlignment.MiddleCenter: return(MenuItemId.SC_ALIGN_MIDDLE_CENTER);

            case WindowAlignment.MiddleRight: return(MenuItemId.SC_ALIGN_MIDDLE_RIGHT);

            case WindowAlignment.BottomLeft: return(MenuItemId.SC_ALIGN_BOTTOM_LEFT);

            case WindowAlignment.BottomCenter: return(MenuItemId.SC_ALIGN_BOTTOM_CENTER);

            case WindowAlignment.BottomRight: return(MenuItemId.SC_ALIGN_BOTTOM_RIGHT);

            case WindowAlignment.CenterHorizontally: return(MenuItemId.SC_ALIGN_CENTER_HORIZONTALLY);

            case WindowAlignment.CenterVertically: return(MenuItemId.SC_ALIGN_CENTER_VERTICALLY);

            default: throw new ArgumentException(nameof(alignment));
            }
        }
Exemplo n.º 3
0
 private void SetAlignmentMenuItem(Window window, int itemId, WindowAlignment alignment)
 {
     window.Menu.UncheckAlignmentMenu();
     window.Menu.CheckMenuItem(itemId, true);
     window.ShowNormal();
     window.SetAlignment(alignment);
 }
Exemplo n.º 4
0
        public static void Align(WindowAlignment alignment, IntPtr hWnd)
        {
            if(hWnd == IntPtr.Zero)
            {
                hWnd = GetForegroundWindow();
            }

            var style = GetWindowLong(hWnd, GWL_STYLE);

            if((style & WS_SIZEBOX) == WS_SIZEBOX)
            {
                int areaWidth = Screen.PrimaryScreen.WorkingArea.Width;
                int areaHeight = Screen.PrimaryScreen.WorkingArea.Height;
                int windowWidth = areaWidth / 3;
                int marginLeft = alignment > 0 ? ((areaWidth % windowWidth) >> 1) * (int)alignment : 0;
                int xPos = windowWidth * (int)alignment + marginLeft;

                //Console.WriteLine("WorkingArea: {0}x{1}", areaWidth, areaHeight);
                //Console.WriteLine("Window: {0}x{1}", windowWidth, areaHeight);
                //Console.WriteLine("Margin left: {0}", marginLeft);
                //Console.WriteLine("Style: {0}", style);
                //Console.WriteLine("Position X: {0}", xPos);

                MoveWindow(hWnd, xPos, 0, windowWidth, areaHeight, true);
            }
        }
Exemplo n.º 5
0
        public Point GetAlignedOrigin(SpriteFont spriteFont, string text, Rectangle destinationRectangle, WindowAlignment alignment = WindowAlignment.TopLeft)
        {
            spriteFont.ThrowIfNull("spriteFont");
            text.ThrowIfNull("text");

            Vector2 textSize = spriteFont.MeasureString(text);

            return GetAlignedOrigin(textSize, text, destinationRectangle, alignment);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Show a window relative to another window.
 /// </summary>
 /// <param name="window">The window to show.</param>
 /// <param name="previous">The window to show window relative to.</param>
 /// <param name="alignment">The alignemnt of window to previous.</param>
 public void showWindow(MDIWindow window, MDIWindow previous, WindowAlignment alignment)
 {
     if (previous == null)
     {
         throw new MDIException("Previous window cannot be null.");
     }
     setWindowProperties(window);
     previous._ParentContainer.addChild(window, previous, alignment);
     invalidate();
 }
Exemplo n.º 7
0
 protected internal override void restoreToMDILayout(MDIWindow mdiWindow, WindowAlignment windowAlignment)
 {
     if (!window.Visible)
     {
         ensureVisible();
         doChangeVisibility(true);
         onShown(EventArgs.Empty);
         if (MDIManager != null)
         {
             MDIManager.showWindow(this, mdiWindow, windowAlignment);
         }
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Show this window relative to another window, will only do something if this window
 /// is not visible.
 /// </summary>
 /// <param name="previous">The previous window.</param>
 /// <param name="alignment">The alignment relative to the previous window.</param>
 public void showRelativeTo(MDIWindow previous, WindowAlignment alignment)
 {
     if (!window.Visible)
     {
         ensureVisible();
         doChangeVisibility(true);
         onShown(EventArgs.Empty);
         if (MDIManager != null)
         {
             MDIManager.showWindow(this, previous, alignment);
         }
     }
 }
Exemplo n.º 9
0
        protected void SetWindowRectangle(WindowAlignment alignment, int width, int height)
        {
            Rectangle windowDestinationRectangle = Constants.GameWindow.DestinationRectangle;
            Point     windowCenterPoint          = windowDestinationRectangle.Center;
            Rectangle windowRectangle;

            switch (alignment)
            {
            case WindowAlignment.TopLeft:
                windowRectangle = new Rectangle(0, 0, width, height);
                break;

            case WindowAlignment.TopCenter:
                windowRectangle = new Rectangle(windowCenterPoint.X - (width / 2), 0, width, height);
                break;

            case WindowAlignment.TopRight:
                windowRectangle = new Rectangle(windowDestinationRectangle.Right - width, 0, width, height);
                break;

            case WindowAlignment.RightCenter:
                windowRectangle = new Rectangle(windowDestinationRectangle.Right - width, windowCenterPoint.Y - (height / 2), width, height);
                break;

            case WindowAlignment.BottomRight:
                windowRectangle = new Rectangle(windowDestinationRectangle.Right - width, windowDestinationRectangle.Bottom - height, width, height);
                break;

            case WindowAlignment.BottomCenter:
                windowRectangle = new Rectangle(windowCenterPoint.X - (width / 2), windowDestinationRectangle.Bottom - height, width, height);
                break;

            case WindowAlignment.BottomLeft:
                windowRectangle = new Rectangle(0, windowDestinationRectangle.Bottom - height, width, height);
                break;

            case WindowAlignment.LeftCenter:
                windowRectangle = new Rectangle(0, windowCenterPoint.Y - (height / 2), width, height);
                break;

            case WindowAlignment.Center:
                windowRectangle = new Rectangle(windowCenterPoint.X - (width / 2), windowCenterPoint.Y - (height / 2), width, height);
                break;

            default:
                throw new ArgumentOutOfRangeException("alignment");
            }

            Window = new Window(windowRectangle);
        }
Exemplo n.º 10
0
        private void Form_TaskDesigner_Load(object sender, EventArgs e)
        {
            comboBxObjectToAdd.Text          = "<Select>";
            comboBxObjectToAdd.SelectedIndex = 1;
            pictureBxTextureImage.Visible    = checkBoxUseTexture.Checked;
            numericUpDownImageNumber.Enabled = checkBoxUseTexture.Checked;
            labelImage.Enabled = checkBoxUseTexture.Checked;

            string        textureFilesPath;
            DirectoryInfo dInfoTextures = new DirectoryInfo(Environment.CurrentDirectory);

            dInfoTextures    = dInfoTextures.Parent;
            textureFilesPath = dInfoTextures.FullName + @"\Textures";

            string[] textureFiles = new string[20];
            if (Directory.Exists(textureFilesPath))
            {
                textureFiles = Directory.GetFiles(textureFilesPath, "*.bmp");
            }

            foreach (string currentFile in textureFiles)
            {
                try
                {
                    Bitmap currentImage = new Bitmap(currentFile);
                    currentImage.RotateFlip(RotateFlipType.RotateNoneFlipY);
                    imageList.Images.Add(currentImage);
                }
                catch (ArgumentNullException ex)
                {
                    System.Windows.Forms.MessageBox.Show("Cannot find texture files. Please ensure that the \"Textures\" folder is in the executable parent directory. Exception message: " + ex.Message, "Cannot Find Texture Files");
                    Environment.Exit(-1);
                }
            }

            this.numericUpDownImageNumber.Maximum = (imageList.Images.Count - 1);

            pictureBxTextureImage.Image = imageList.Images[(int)this.numericUpDownImageNumber.Value];


            Externals.LoadVisualiser(m_objectsToDraw);

            //if (Externals.VisualiserLoaded())
            {
                WindowAlignment.BringVisualiserToFrontAndAlignWindows();
            }

            Externals.SendNotification("TDSOK");
        }
Exemplo n.º 11
0
        private void findWindowLanding(MDIWindow source, MDIWindow target, float mouseX, float mouseY)
        {
            if (target != null)
            {
                if (source != target)
                {
                    float top    = target.Location.y;
                    float bottom = top + target.WorkingSize.Height;
                    float left   = target.Location.x;
                    float right  = left + target.WorkingSize.Width;

                    float topDelta    = mouseY - top;
                    float bottomDelta = bottom - mouseY;
                    float leftDelta   = mouseX - left;
                    float rightDelta  = right - mouseX;
                    if (topDelta < bottomDelta && topDelta < leftDelta && topDelta < rightDelta)
                    {
                        finalWindowAlignment = WindowAlignment.Top;
                        windowTargetWidget.setCoord((int)left, (int)top, (int)target.WorkingSize.Width, (int)(target.WorkingSize.Height * 0.5f));
                    }
                    else if (bottomDelta < topDelta && bottomDelta < leftDelta && bottomDelta < rightDelta)
                    {
                        finalWindowAlignment = WindowAlignment.Bottom;
                        windowTargetWidget.setCoord((int)left, (int)(top + target.WorkingSize.Height * 0.5f), (int)target.WorkingSize.Width, (int)(target.WorkingSize.Height * 0.5f));
                    }
                    else if (leftDelta < topDelta && leftDelta < bottomDelta && leftDelta < rightDelta)
                    {
                        finalWindowAlignment = WindowAlignment.Left;
                        windowTargetWidget.setCoord((int)left, (int)top, (int)(target.WorkingSize.Width * 0.5f), (int)target.WorkingSize.Height);
                    }
                    else if (rightDelta < leftDelta && rightDelta < bottomDelta && rightDelta < topDelta)
                    {
                        finalWindowAlignment = WindowAlignment.Right;
                        windowTargetWidget.setCoord((int)(left + target.WorkingSize.Width * 0.5f), (int)top, (int)(target.WorkingSize.Width * 0.5f), (int)target.WorkingSize.Height);
                    }

                    windowTargetWidget.Visible = true;
                }
                else
                {
                    windowTargetWidget.Visible = false;
                }
            }
        }
        protected void SetWindowRectangle(WindowAlignment alignment, int width, int height)
        {
            Rectangle windowDestinationRectangle = Constants.GameWindow.DestinationRectangle;
            Point windowCenterPoint = windowDestinationRectangle.Center;
            Rectangle windowRectangle;

            switch (alignment)
            {
                case WindowAlignment.TopLeft:
                    windowRectangle = new Rectangle(0, 0, width, height);
                    break;
                case WindowAlignment.TopCenter:
                    windowRectangle = new Rectangle(windowCenterPoint.X - (width / 2), 0, width, height);
                    break;
                case WindowAlignment.TopRight:
                    windowRectangle = new Rectangle(windowDestinationRectangle.Right - width, 0, width, height);
                    break;
                case WindowAlignment.RightCenter:
                    windowRectangle = new Rectangle(windowDestinationRectangle.Right - width, windowCenterPoint.Y - (height / 2), width, height);
                    break;
                case WindowAlignment.BottomRight:
                    windowRectangle = new Rectangle(windowDestinationRectangle.Right - width, windowDestinationRectangle.Bottom - height, width, height);
                    break;
                case WindowAlignment.BottomCenter:
                    windowRectangle = new Rectangle(windowCenterPoint.X - (width / 2), windowDestinationRectangle.Bottom - height, width, height);
                    break;
                case WindowAlignment.BottomLeft:
                    windowRectangle = new Rectangle(0, windowDestinationRectangle.Bottom - height, width, height);
                    break;
                case WindowAlignment.LeftCenter:
                    windowRectangle = new Rectangle(0, windowCenterPoint.Y - (height / 2), width, height);
                    break;
                case WindowAlignment.Center:
                    windowRectangle = new Rectangle(windowCenterPoint.X - (width / 2), windowCenterPoint.Y - (height / 2), width, height);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("alignment");
            }

            Window = new Window(windowRectangle);
        }
Exemplo n.º 13
0
 protected internal abstract void restoreToMDILayout(MDIWindow mDIWindow, WindowAlignment windowAlignment);
Exemplo n.º 14
0
        public void SetAlignment(WindowAlignment alignment)
        {
            int       x, y;
            Rectangle screen = ScreenId < Screen.AllScreens.Length ? Screen.AllScreens[ScreenId].WorkingArea : Screen.PrimaryScreen.WorkingArea;
            Rect      window = Size;

            switch (alignment)
            {
            case WindowAlignment.TopLeft:
            {
                x = screen.X;
                y = screen.Y;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.TopCenter:
            {
                x = ((screen.Width - window.Width) / 2) + screen.X;
                y = screen.Y;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.TopRight:
            {
                x = screen.Width - window.Width + screen.X;
                y = screen.Y;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.MiddleLeft:
            {
                x = screen.X;
                y = ((screen.Height - window.Height) / 2) + screen.Y;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.MiddleCenter:
            {
                x = ((screen.Width - window.Width) / 2) + screen.X;
                y = ((screen.Height - window.Height) / 2) + screen.Y;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.MiddleRight:
            {
                x = screen.Width - window.Width + screen.X;
                y = ((screen.Height - window.Height) / 2) + screen.Y;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.BottomLeft:
            {
                x = screen.X;
                y = screen.Height - window.Height + screen.Y;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.BottomCenter:
            {
                x = ((screen.Width - window.Width) / 2) + screen.X;
                y = screen.Height - window.Height + screen.Y;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.BottomRight:
            {
                x = screen.Width - window.Width + screen.X;
                y = screen.Height - window.Height + screen.Y;
                SetPosition(x, y);
            }
            break;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Add a child to a specific place with a specific alignment to the
        /// container. This method will create subcontainers as needed to get
        /// the layout desired.
        /// </summary>
        /// <param name="child">The child to add.</param>
        /// <param name="previous">The window to add the child relative to.</param>
        /// <param name="alignment">The alignment of child to previous.</param>
        public override void addChild(MDIWindow child, MDIWindow previous, WindowAlignment alignment)
        {
            switch (alignment)
            {
            case WindowAlignment.Left:
                if (previous._ParentContainer.Layout == MDILayoutContainer.LayoutType.Horizontal)
                {
                    //The child can simply be appended.
                    previous._ParentContainer.insertChild(child, previous, false);
                }
                else
                {
                    //The child needs a new subcontainer created.
                    MDILayoutContainer    newContainer    = new MDILayoutContainerScale(MDILayoutContainer.LayoutType.Horizontal, Padding, CurrentDockLocation);
                    MDIChildContainerBase parentContainer = previous._ParentContainer;
                    parentContainer.swapAndRemove(newContainer, previous);
                    newContainer.addChild(child);
                    newContainer.addChild(previous);
                }
                break;

            case WindowAlignment.Right:
                if (previous._ParentContainer.Layout == MDILayoutContainer.LayoutType.Horizontal)
                {
                    //The child can simply be appended.
                    previous._ParentContainer.insertChild(child, previous, true);
                }
                else
                {
                    //The child needs a new subcontainer created.
                    MDILayoutContainer    newContainer    = new MDILayoutContainerScale(MDILayoutContainer.LayoutType.Horizontal, Padding, CurrentDockLocation);
                    MDIChildContainerBase parentContainer = previous._ParentContainer;
                    parentContainer.swapAndRemove(newContainer, previous);
                    newContainer.addChild(previous);
                    newContainer.addChild(child);
                }
                break;

            case WindowAlignment.Top:
                if (previous._ParentContainer.Layout == MDILayoutContainer.LayoutType.Vertical)
                {
                    //The child can simply be appended.
                    previous._ParentContainer.insertChild(child, previous, false);
                }
                else
                {
                    //The child needs a new subcontainer created.
                    MDILayoutContainer    newContainer    = new MDILayoutContainerScale(MDILayoutContainer.LayoutType.Vertical, Padding, CurrentDockLocation);
                    MDIChildContainerBase parentContainer = previous._ParentContainer;
                    parentContainer.swapAndRemove(newContainer, previous);
                    newContainer.addChild(child);
                    newContainer.addChild(previous);
                }
                break;

            case WindowAlignment.Bottom:
                if (previous._ParentContainer.Layout == MDILayoutContainer.LayoutType.Vertical)
                {
                    //The child can simply be appended.
                    previous._ParentContainer.insertChild(child, previous, true);
                }
                else
                {
                    //The child needs a new subcontainer created.
                    MDILayoutContainer    newContainer    = new MDILayoutContainerScale(MDILayoutContainer.LayoutType.Vertical, Padding, CurrentDockLocation);
                    MDIChildContainerBase parentContainer = previous._ParentContainer;
                    parentContainer.swapAndRemove(newContainer, previous);
                    newContainer.addChild(previous);
                    newContainer.addChild(child);
                }
                break;
            }
        }
Exemplo n.º 16
0
 public override void addChild(MDIWindow window, MDIWindow previous, WindowAlignment alignment)
 {
     addChild(window);
 }
Exemplo n.º 17
0
 public override void addChild(MDIWindow window, MDIWindow previous, WindowAlignment alignment)
 {
     layoutContainer.addChild(window, previous, alignment);
 }
Exemplo n.º 18
0
        public void SetAlignment(WindowAlignment alignment)
        {
            var x      = 0;
            var y      = 0;
            var screen = Screen.FromHandle(Handle).WorkingArea;
            var window = Size;
            var margin = GetSystemMargins();


            switch (alignment)
            {
            case WindowAlignment.TopLeft:
            {
                x = screen.X - margin.Left;
                y = screen.Y - margin.Top;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.TopCenter:
            {
                x = ((screen.Width - window.Width) / 2) + screen.X;
                y = screen.Y - margin.Top;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.TopRight:
            {
                x = (screen.Width - window.Width + screen.X) + margin.Right;
                y = screen.Y - margin.Top;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.MiddleLeft:
            {
                x = screen.X - margin.Left;
                y = (((screen.Height - window.Height) / 2) + screen.Y);
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.MiddleCenter:
            {
                x = ((screen.Width - window.Width) / 2) + screen.X;
                y = ((screen.Height - window.Height) / 2) + screen.Y;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.MiddleRight:
            {
                x = screen.Width - window.Width + screen.X + margin.Right;
                y = (((screen.Height - window.Height) / 2) + screen.Y);
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.BottomLeft:
            {
                x = screen.X - margin.Left;
                y = screen.Height - window.Height + screen.Y + margin.Bottom;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.BottomCenter:
            {
                x = ((screen.Width - window.Width) / 2) + screen.X;
                y = screen.Height - window.Height + screen.Y + margin.Bottom;
                SetPosition(x, y);
            }
            break;

            case WindowAlignment.BottomRight:
            {
                x = screen.Width - window.Width + screen.X + margin.Right;
                y = screen.Height - window.Height + screen.Y + margin.Bottom;
                SetPosition(x, y);
            }
            break;
            }
        }
        public Point GetAlignedOrigin(SpriteFont spriteFont, string text, Rectangle destinationRectangle, WindowAlignment alignment = WindowAlignment.TopLeft)
        {
            spriteFont.ThrowIfNull("spriteFont");
            text.ThrowIfNull("text");

            Vector2 textSize = spriteFont.MeasureString(text);

            return(GetAlignedOrigin(textSize, text, destinationRectangle, alignment));
        }
Exemplo n.º 20
0
        public MDISceneViewWindow createWindow(String name, Vector3 translation, Vector3 lookAt, Vector3 boundMin, Vector3 boundMax, float minOrbitDistance, float maxOrbitDistance, int zIndexStart, MDISceneViewWindow previous = null, WindowAlignment alignment = WindowAlignment.Left)
        {
            OrbitCameraController orbitCamera = new OrbitCameraController(translation, lookAt, boundMin, boundMax, minOrbitDistance, maxOrbitDistance);

            orbitCamera.AllowRotation = AllowRotation;
            orbitCamera.AllowZoom     = AllowZoom;
            orbitCamera.setUpdateTimer(mainTimer);
            MDISceneViewWindow window = new MDISceneViewWindow(rendererWindow, this, orbitCamera, name, background, zIndexStart);

            window.AutoAspectRatio = autoAspectRatio;
            window.AspectRatio     = aspectRatio;
            window.BackColor       = DefaultBackgroundColor;
            if (WindowCreated != null)
            {
                WindowCreated.Invoke(window);
            }
            if (camerasCreated)
            {
                window.createSceneView(currentScene);
            }
            //Count is 0, disable close button on first window
            if (mdiWindows.Count == 0)
            {
                window.AllowClose = false;
            }
            //Count is 1, enable the close button on the first window
            if (mdiWindows.Count == 1)
            {
                mdiWindows[0].AllowClose = true;
            }
            mdiWindows.Add(window);

            if (previous != null)
            {
                mdiLayout.showWindow(window._getMDIWindow(), previous._getMDIWindow(), alignment);
            }
            else
            {
                mdiLayout.showWindow(window._getMDIWindow());
            }
            return(window);
        }
Exemplo n.º 21
0
 protected internal override void restoreToMDILayout(MDIWindow mDIWindow, WindowAlignment windowAlignment)
 {
 }
 public abstract void addChild(MDIWindow window, MDIWindow previous, WindowAlignment alignment);
Exemplo n.º 23
0
        public void SetAlignment(WindowAlignment alignment)
        {
            var x      = 0;
            var y      = 0;
            var screen = Screen.FromHandle(Handle).WorkingArea;
            var window = Size;

            State.Alignment = alignment;
            if (alignment == WindowAlignment.CenterHorizontally)
            {
                SetLeft(((screen.Width - window.Width) / 2) + screen.X);
                return;
            }

            if (alignment == WindowAlignment.CenterVertically)
            {
                SetTop(((screen.Height - window.Height) / 2) + screen.Y);
                return;
            }

            switch (alignment)
            {
            case WindowAlignment.TopLeft:
            {
                x = screen.X;
                y = screen.Y;
            }
            break;

            case WindowAlignment.TopCenter:
            {
                x = ((screen.Width - window.Width) / 2) + screen.X;
                y = screen.Y;
            }
            break;

            case WindowAlignment.TopRight:
            {
                x = screen.Width - window.Width + screen.X;
                y = screen.Y;
            }
            break;

            case WindowAlignment.MiddleLeft:
            {
                x = screen.X;
                y = (((screen.Height - window.Height) / 2) + screen.Y);
            }
            break;

            case WindowAlignment.MiddleCenter:
            {
                x = ((screen.Width - window.Width) / 2) + screen.X;
                y = ((screen.Height - window.Height) / 2) + screen.Y;
            }
            break;

            case WindowAlignment.MiddleRight:
            {
                x = screen.Width - window.Width + screen.X;
                y = (((screen.Height - window.Height) / 2) + screen.Y);
            }
            break;

            case WindowAlignment.BottomLeft:
            {
                x = screen.X;
                y = screen.Height - window.Height + screen.Y;
            }
            break;

            case WindowAlignment.BottomCenter:
            {
                x = ((screen.Width - window.Width) / 2) + screen.X;
                y = screen.Height - window.Height + screen.Y;
            }
            break;

            case WindowAlignment.BottomRight:
            {
                x = screen.Width - window.Width + screen.X;
                y = screen.Height - window.Height + screen.Y;
            }
            break;
            }
            SetPosition(x, y);
        }
Exemplo n.º 24
0
 public AlignCombo(WindowAlignment alignment, System.Windows.Forms.Keys keys, KeyModifier modifier = KeyModifier.None)
     : base(keys, modifier)
 {
     this.Alignment = alignment;
 }
Exemplo n.º 25
0
        //All dialogs on a given level have the same alignment and can have the dialog found before it as the parent with "right" or "bottom" alignment
        //A dialog on a child level will have the opposite alignment of its parent (that is why it is a child)

        //so you need a function store level details, which takes the alignment to the parent and the parent dialog
        //assign the first dialog to have the parent and parent alignment, any other dialogs on that level parent to the previous found dialog and have right or bottom alignment
        private void storeLayoutInfo(StoredMDILayoutContainer storedLayout, MDIWindow parent, WindowAlignment alignmentToParent)
        {
            bool foundWindow = false;
            int  i           = 0;

            for (i = 0; i < children.Count; ++i)
            {
                //Search level for the first dialog, store all elements up till the dialog
                //if a dialog is found
                MDIWindow currentWindow = children[i] as MDIWindow;
                if (currentWindow != null)
                {
                    foundWindow = true;
                    //parent the dialog to the parent passed to the function with the alignment passed in
                    //add child level elements to the "left" or "top" from the list of stored dialogs (calling the recursive func)
                    storedLayout.addWindowEntry(new WindowEntry(currentWindow, alignmentToParent, parent));
                    foundWindow = true;
                    for (int j = 0; j < i; ++j)
                    {
                        MDILayoutContainer childLayout = (MDILayoutContainer)children[j];
                        childLayout.storeLayoutInfo(storedLayout, currentWindow, layoutType == LayoutType.Horizontal ? WindowAlignment.Left : WindowAlignment.Top);
                    }
                    //add remaining child elements to the "right" or "bottom" of the current window
                    //if another window is found, change currentwindow
                    //parent the newly found window to the currentwindow with "left" or "bottom" alignment
                    MDIWindow previousWindow = currentWindow;
                    for (++i; i < children.Count; ++i)
                    {
                        currentWindow = children[i] as MDIWindow;
                        if (currentWindow != null)
                        {
                            storedLayout.addWindowEntry(new WindowEntry(currentWindow, layoutType == LayoutType.Horizontal ? WindowAlignment.Right : WindowAlignment.Bottom, previousWindow));
                            previousWindow = currentWindow;
                        }
                        else
                        {
                            MDILayoutContainer childLayout = (MDILayoutContainer)children[i];
                            childLayout.storeLayoutInfo(storedLayout, previousWindow, layoutType == LayoutType.Horizontal ? WindowAlignment.Right : WindowAlignment.Bottom);
                        }
                    }
                }
            }
            if (!foundWindow)
            {
                //if no dialog is found it means we are at the top level and the default order was changed, no other levels should be able to be completely empty, in this case flip
                //the alignment and call again with no parent dialog (this will cause the first found dialog to be the parent and its sibling will get the correct flipped alignment
                foreach (MDILayoutContainer child in children)
                {
                    child.storeLayoutInfo(storedLayout, parent, child.layoutType == LayoutType.Horizontal ? WindowAlignment.Left : WindowAlignment.Top);
                }
            }
        }
 protected void SetWindowRectangleUsingClientSize(WindowAlignment alignment, int clientWidth, int clientHeight, Padding padding)
 {
     SetWindowRectangle(alignment, clientWidth + padding.X, clientHeight + padding.Y, padding);
 }
 public LevelInfo(WindowAlignment alignment, MDIWindow previousWindow = null)
 {
     this.Alignment      = alignment;
     this.PreviousWindow = previousWindow;
 }
        public Point GetAlignedOrigin(Vector2 textSize, string text, Rectangle destinationRectangle, WindowAlignment alignment = WindowAlignment.TopLeft)
        {
            text.ThrowIfNull("text");

            switch (alignment)
            {
            case WindowAlignment.TopLeft:
                return(new Point(destinationRectangle.X, destinationRectangle.Y));

            case WindowAlignment.TopCenter:
                return(new Point((destinationRectangle.Center.X - (textSize.X / 2)).Round(), destinationRectangle.Y));

            case WindowAlignment.TopRight:
                return(new Point((destinationRectangle.Right - textSize.X).Round(), destinationRectangle.Y));

            case WindowAlignment.RightCenter:
                return(new Point((destinationRectangle.Right - textSize.X).Round(), (destinationRectangle.Center.Y - (textSize.Y / 2)).Round()));

            case WindowAlignment.BottomRight:
                return(new Point((destinationRectangle.Right - textSize.X).Round(), (destinationRectangle.Bottom - textSize.Y).Round()));

            case WindowAlignment.BottomCenter:
                return(new Point((destinationRectangle.Center.X - (textSize.X / 2)).Round(), (destinationRectangle.Bottom - textSize.Y).Round()));

            case WindowAlignment.BottomLeft:
                return(new Point(destinationRectangle.X, (destinationRectangle.Bottom - textSize.Y).Round()));

            case WindowAlignment.LeftCenter:
                return(new Point(destinationRectangle.X, (destinationRectangle.Center.Y - (textSize.Y / 2)).Round()));

            case WindowAlignment.Center:
                return(new Point((destinationRectangle.Center.X - (textSize.X / 2)).Round(), (destinationRectangle.Center.Y - (textSize.Y / 2)).Round()));

            default:
                throw new ArgumentOutOfRangeException("alignment");
            }
        }
 protected void SetWindowRectangleUsingClientSize(WindowAlignment alignment, int clientWidth, int clientHeight, Padding padding)
 {
     SetWindowRectangle(alignment, clientWidth + padding.X, clientHeight + padding.Y, padding);
 }
 public WindowEntry(MDIWindow window, WindowAlignment alignment, MDIWindow previous = null)
 {
     this.Window         = window;
     this.Alignment      = alignment;
     this.PreviousWindow = previous;
 }