Пример #1
0
 public SkinLayer(SkinLayer source) : base(source)
 {
     if (source != null)
     {
         Image          = new SkinImage(source.Image);
         Width          = source.Width;
         Height         = source.Height;
         OffsetX        = source.OffsetX;
         OffsetY        = source.OffsetY;
         Alignment      = source.Alignment;
         SizingMargins  = source.SizingMargins;
         ContentMargins = source.ContentMargins;
         States         = source.States;
         Overlays       = source.Overlays;
         Text           = new SkinText(source.Text);
         Attributes     = new SkinList <SkinAttribute>(source.Attributes);
     }
     else
     {
         throw new Exception("Parameter for SkinLayer copy constructor cannot be null.");
     }
 }
Пример #2
0
        /// <summary>
        /// Helper to position controls based on the visibility of the input text box control.
        /// </summary>
        private void PositionControls()
        {
            // Is the user input text box initialized?
            if (txtMain != null)
            {
                // Position the input text box based on the visibility of the channel selection box.
                txtMain.Left  = channelsVisible ? cmbMain.Width + 1 : 0;
                txtMain.Width = channelsVisible ? Width - cmbMain.Width - 1 : Width;

                if (textBoxVisible)
                {
                    ClientMargins = new Margins(Skin.ClientMargins.Left, Skin.ClientMargins.Top + 4, sbVert.Width + 6, txtMain.Height + 4);
                    sbVert.Height = Height - txtMain.Height - 5;
                }

                else
                {
                    ClientMargins = new Margins(Skin.ClientMargins.Left, Skin.ClientMargins.Top + 4, sbVert.Width + 6, 2);
                    sbVert.Height = Height - 4;
                }

                Invalidate();
            }
        }
Пример #3
0
 /// <summary>
 /// Adjusts the margins of the client area of the combo box control.
 /// </summary>
 protected override void AdjustMargins()
 {
     base.AdjustMargins();
     ClientMargins = new Margins(ClientMargins.Left, ClientMargins.Top, ClientMargins.Right + 16,
                                 ClientMargins.Bottom);
 }
Пример #4
0
        /// <returns>Returns a rectangle that specifies the location and size of the asset that was requested.</returns>
        /// <param name="index">Index specifying where on the source image, the asset we want is located.</param>
        /// <param name="alignment">???</param>
        /// <param name="margins">???</param>
        /// <param name="partSize">Size of the asset piece to retrieve the source region for.</param>
        /// <param name="imageSize">Size of the entire image.</param>
        /// <summary>
        /// when multiple assets are packed into a single image file.
        /// Used to grab a piece of the source region of a skin resource
        /// </summary>
        private static Rectangle GetSourceArea(Size imageSize, Size partSize, Margins margins, Alignment alignment,
                                               int index)
        {
            var rect = new Rectangle();
// Break the image down into rows and columns.
            var xc = (int)((float)imageSize.Width / partSize.Width);
            var yc = (int)((float)imageSize.Height / partSize.Height);

// Figure out which row and column the asset is located at.
            var xm = (index) % xc;
            var ym = (index) / xc;

            var adj = 1;

            margins.Left   += margins.Left > 0 ? adj : 0;
            margins.Top    += margins.Top > 0 ? adj : 0;
            margins.Right  += margins.Right > 0 ? adj : 0;
            margins.Bottom += margins.Bottom > 0 ? adj : 0;

            margins = new Margins(margins.Left, margins.Top, margins.Right, margins.Bottom);
// Adjust the text position to account for the specified alignment.
            switch (alignment)
            {
            case Alignment.TopLeft:
            {
                rect = new Rectangle((0 + (xm * partSize.Width)),
                                     (0 + (ym * partSize.Height)),
                                     margins.Left,
                                     margins.Top);
                break;
            }

            case Alignment.TopCenter:
            {
                rect = new Rectangle((0 + (xm * partSize.Width)) + margins.Left,
                                     (0 + (ym * partSize.Height)),
                                     partSize.Width - margins.Left - margins.Right,
                                     margins.Top);
                break;
            }

            case Alignment.TopRight:
            {
                rect = new Rectangle((partSize.Width + (xm * partSize.Width)) - margins.Right,
                                     (0 + (ym * partSize.Height)),
                                     margins.Right,
                                     margins.Top);
                break;
            }

            case Alignment.MiddleLeft:
            {
                rect = new Rectangle((0 + (xm * partSize.Width)),
                                     (0 + (ym * partSize.Height)) + margins.Top,
                                     margins.Left,
                                     partSize.Height - margins.Top - margins.Bottom);
                break;
            }

            case Alignment.MiddleCenter:
            {
                rect = new Rectangle((0 + (xm * partSize.Width)) + margins.Left,
                                     (0 + (ym * partSize.Height)) + margins.Top,
                                     partSize.Width - margins.Left - margins.Right,
                                     partSize.Height - margins.Top - margins.Bottom);
                break;
            }

            case Alignment.MiddleRight:
            {
                rect = new Rectangle((partSize.Width + (xm * partSize.Width)) - margins.Right,
                                     (0 + (ym * partSize.Height)) + margins.Top,
                                     margins.Right,
                                     partSize.Height - margins.Top - margins.Bottom);
                break;
            }

            case Alignment.BottomLeft:
            {
                rect = new Rectangle((0 + (xm * partSize.Width)),
                                     (partSize.Height + (ym * partSize.Height)) - margins.Bottom,
                                     margins.Left,
                                     margins.Bottom);
                break;
            }

            case Alignment.BottomCenter:
            {
                rect = new Rectangle((0 + (xm * partSize.Width)) + margins.Left,
                                     (partSize.Height + (ym * partSize.Height)) - margins.Bottom,
                                     partSize.Width - margins.Left - margins.Right,
                                     margins.Bottom);
                break;
            }

            case Alignment.BottomRight:
            {
                rect = new Rectangle((partSize.Width + (xm * partSize.Width)) - margins.Right,
                                     (partSize.Height + (ym * partSize.Height)) - margins.Bottom,
                                     margins.Right,
                                     margins.Bottom);
                break;
            }
            }

            return(rect);
        }
Пример #5
0
        /// <returns>The region where the partial source piece should be drawn.</returns>
        /// <param name="alignment">Which piece of the asset is this?</param>
        /// <param name="margins">Margin values applied to the region.</param>
        /// <param name="area">Entire destination region where the image should be drawn.</param>
        /// <summary>
        /// Calculates the correct piece of the destination region where the partial source area should be drawn.
        /// </summary>
        public static Rectangle GetDestinationArea(Rectangle area, Margins margins, Alignment alignment)
        {
            var rect = new Rectangle();

            var adj = 1;

            margins.Left   += margins.Left > 0 ? adj : 0;
            margins.Top    += margins.Top > 0 ? adj : 0;
            margins.Right  += margins.Right > 0 ? adj : 0;
            margins.Bottom += margins.Bottom > 0 ? adj : 0;

            margins = new Margins(margins.Left, margins.Top, margins.Right, margins.Bottom);

// Adjust the text position to account for the specified alignment.
            switch (alignment)
            {
            case Alignment.TopLeft:
            {
                rect = new Rectangle(area.Left + 0,
                                     area.Top + 0,
                                     margins.Left,
                                     margins.Top);
                break;
            }

            case Alignment.TopCenter:
            {
                rect = new Rectangle(area.Left + margins.Left,
                                     area.Top + 0,
                                     area.Width - margins.Left - margins.Right,
                                     margins.Top);
                break;
            }

            case Alignment.TopRight:
            {
                rect = new Rectangle(area.Left + area.Width - margins.Right,
                                     area.Top + 0,
                                     margins.Right,
                                     margins.Top);
                break;
            }

            case Alignment.MiddleLeft:
            {
                rect = new Rectangle(area.Left + 0,
                                     area.Top + margins.Top,
                                     margins.Left,
                                     area.Height - margins.Top - margins.Bottom);
                break;
            }

            case Alignment.MiddleCenter:
            {
                rect = new Rectangle(area.Left + margins.Left,
                                     area.Top + margins.Top,
                                     area.Width - margins.Left - margins.Right,
                                     area.Height - margins.Top - margins.Bottom);
                break;
            }

            case Alignment.MiddleRight:
            {
                rect = new Rectangle(area.Left + area.Width - margins.Right,
                                     area.Top + margins.Top,
                                     margins.Right,
                                     area.Height - margins.Top - margins.Bottom);
                break;
            }

            case Alignment.BottomLeft:
            {
                rect = new Rectangle(area.Left + 0,
                                     area.Top + area.Height - margins.Bottom,
                                     margins.Left,
                                     margins.Bottom);
                break;
            }

            case Alignment.BottomCenter:
            {
                rect = new Rectangle(area.Left + margins.Left,
                                     area.Top + area.Height - margins.Bottom,
                                     area.Width - margins.Left - margins.Right,
                                     margins.Bottom);
                break;
            }

            case Alignment.BottomRight:
            {
                rect = new Rectangle(area.Left + area.Width - margins.Right,
                                     area.Top + area.Height - margins.Bottom,
                                     margins.Right,
                                     margins.Bottom);
                break;
            }
            }

            return(rect);
        }