Пример #1
0
        } // DisposeManagedResources

        #endregion

        #region Draw

        /// <summary>
        /// Prerender the control into the control's render target.
        /// </summary>
        protected override void DrawControl(Rectangle rect)
        {
            if (texture != null)
            {
                switch (sizeMode)
                {
                case SizeMode.Normal:
                case SizeMode.Auto:
                    Renderer.Draw(texture.Resource, rect.X, rect.Y, sourceRectangle, Color);
                    break;

                case SizeMode.Stretched:
                    Renderer.Draw(texture.Resource, rect, sourceRectangle, Color);
                    break;

                case SizeMode.Centered:
                    int x = (rect.Width / 2) - (texture.Width / 2);
                    int y = (rect.Height / 2) - (texture.Height / 2);
                    Renderer.Draw(texture.Resource, x, y, sourceRectangle, Color);
                    break;

                case SizeMode.Fit:
                    Rectangle aspectRatiorectangle = rect;
                    if (texture.Width / texture.Height > rect.Width / rect.Height)
                    {
                        aspectRatiorectangle.Height = (int)(rect.Height * ((float)rect.Width / rect.Height) / ((float)texture.Width / texture.Height));
                        aspectRatiorectangle.Y      = rect.Y + (rect.Height - aspectRatiorectangle.Height) / 2;
                    }
                    else
                    {
                        aspectRatiorectangle.Width = (int)(rect.Width * ((float)texture.Width / texture.Height) / ((float)rect.Width / rect.Height));
                        aspectRatiorectangle.X     = rect.X + (rect.Width - aspectRatiorectangle.Width) / 2;
                    }

                    Renderer.Draw(texture.Resource, aspectRatiorectangle, sourceRectangle, Color);
                    break;
                }
            }
        } // DrawControl
Пример #2
0
        } // InitSkin

        #endregion

        #region Draw

        /// <summary>
        /// Prerender the control into the control's render target.
        /// </summary>
        protected override void DrawControl(Rectangle rect)
        {
            base.DrawControl(rect);

            SkinLayer layerControl   = SkinInformation.Layers["Control"];
            SkinLayer layerSelection = SkinInformation.Layers["Selection"];
            int verticalSize = LineHeight();
            Color color;

            // Find maximum width (not including right side text)
            // This information will be used to render the right side text, if any.
            int maximumWidth = 0;
            foreach (MenuItem menuItem in Items)
            {
                int textWidth = (int)layerControl.Text.Font.Font.MeasureString(menuItem.Text).X + 16;
                if (textWidth > maximumWidth)
                    maximumWidth = textWidth;
            }

            // Render all menu items.
            for (int i = 0; i < Items.Count; i++)
            {
                int mod = i > 0 ? 2 : 0;
                int left = rect.Left + layerControl.ContentMargins.Left + verticalSize;
                int hight = verticalSize - mod - (i < (Items.Count - 1) ? 1 : 0);
                int top = rect.Top + layerControl.ContentMargins.Top + (i * verticalSize) + mod;


                if (Items[i].SeparationLine && i > 0)
                {
                    Rectangle rectangle = new Rectangle(left, rect.Top + layerControl.ContentMargins.Top + (i * verticalSize), LineWidth() - verticalSize + 4, 1);
                    Renderer.Draw(Skin.Controls["Control"].Layers[0].Image.Texture.Resource, rectangle, layerControl.Text.Colors.Enabled);
                }

                #region No Selected
                if (ItemIndex != i)
                {
                    if (Items[i].Enabled)
                    {
                        Rectangle rectangle = new Rectangle(left, top, LineWidth() - verticalSize, hight);
                        // Render Text.
                        Renderer.DrawString(this, layerControl, Items[i].Text, rectangle, false);
                        // Render Right Side Text.
                        if (!string.IsNullOrEmpty(Items[i].RightSideText))
                        {
                            rectangle = new Rectangle(rectangle.Left + maximumWidth, rectangle.Top,
                                                     (int)layerControl.Text.Font.Font.MeasureString(Items[i].RightSideText).X + 16, rectangle.Height);
                            Renderer.DrawString(this, layerControl, Items[i].RightSideText, rectangle, false);
                        }
                        color = layerControl.Text.Colors.Enabled;
                    }
                    else
                    {
                        Rectangle rectangle = new Rectangle(left + layerControl.Text.OffsetX, top + layerControl.Text.OffsetY, LineWidth() - verticalSize, hight);
                        // Render Text.
                        Renderer.DrawString(layerControl.Text.Font.Font.Resource, Items[i].Text, rectangle, layerControl.Text.Colors.Disabled, layerControl.Text.Alignment);
                        // Render Right Side Text.
                        if (!string.IsNullOrEmpty(Items[i].RightSideText))
                        {
                            rectangle = new Rectangle(rectangle.Left + maximumWidth, rectangle.Top,
                                                     (int)layerControl.Text.Font.Font.MeasureString(Items[i].RightSideText).X + 16, rectangle.Height);
                            Renderer.DrawString(layerControl.Text.Font.Font.Resource, Items[i].RightSideText, rectangle, layerControl.Text.Colors.Disabled, layerControl.Text.Alignment);
                        }
                        color = layerControl.Text.Colors.Disabled;
                    }
                }
                #endregion

                #region Selected
                else
                {
                    if (Items[i].Enabled)
                    {
                        Rectangle rs = new Rectangle(rect.Left + layerControl.ContentMargins.Left, 
                                                     top,
                                                     Width - (layerControl.ContentMargins.Horizontal - SkinInformation.OriginMargins.Horizontal),
                                                     hight);
                        Renderer.DrawLayer(this, layerSelection, rs);

                        Rectangle rectangle = new Rectangle(left, top, LineWidth() - verticalSize, hight);
                        // Render String.
                        Renderer.DrawString(this, layerSelection, Items[i].Text, rectangle, false);
                        // Render Right Side Text.
                        if (!string.IsNullOrEmpty(Items[i].RightSideText))
                        {
                            rectangle = new Rectangle(rectangle.Left + maximumWidth, rectangle.Top,
                                                     (int)layerControl.Text.Font.Font.MeasureString(Items[i].RightSideText).X + 16, rectangle.Height);
                            Renderer.DrawString(this, layerSelection, Items[i].RightSideText, rectangle, false);
                        }
                        color = layerSelection.Text.Colors.Enabled;
                    }
                    else
                    {
                        Rectangle rs = new Rectangle(rect.Left + layerControl.ContentMargins.Left,
                                                     top,
                                                     Width - (layerControl.ContentMargins.Horizontal - SkinInformation.OriginMargins.Horizontal),
                                                     verticalSize);
                        Renderer.DrawLayer(layerSelection, rs, layerSelection.States.Disabled.Color, layerSelection.States.Disabled.Index);

                        Rectangle rectangle = new Rectangle(left + layerControl.Text.OffsetX,
                                                    top + layerControl.Text.OffsetY,
                                                    LineWidth() - verticalSize, hight);
                        // Render Text.
                        Renderer.DrawString(layerSelection.Text.Font.Font.Resource, Items[i].Text, rectangle,
                                            layerSelection.Text.Colors.Disabled, layerSelection.Text.Alignment);
                        // Render Right Side Text.
                        if (!string.IsNullOrEmpty(Items[i].RightSideText))
                        {
                            rectangle = new Rectangle(rectangle.Left + maximumWidth, rectangle.Top,
                                                     (int)layerControl.Text.Font.Font.MeasureString(Items[i].RightSideText).X + 16, rectangle.Height);
                            Renderer.DrawString(layerSelection.Text.Font.Font.Resource, Items[i].RightSideText, rectangle,
                                                layerSelection.Text.Colors.Disabled, layerSelection.Text.Alignment);
                        }
                        color = layerSelection.Text.Colors.Disabled;
                    }
                }
                #endregion

                if (Items[i].Icon != null)
                {
                    Rectangle r = new Rectangle(rect.Left + layerControl.ContentMargins.Left + 3, rect.Top + top + 3, LineHeight() - 6, LineHeight() - 6);
                    Renderer.Draw(Items[i].Icon, r, Color.White);
                }

                if (Items[i].Items != null && Items[i].Items.Count > 0)
                {
                    Renderer.Draw(Skin.Images["Shared.ArrowRight"].Texture.Resource, rect.Left + LineWidth() - 4, rect.Top + layerControl.ContentMargins.Top + (i * verticalSize) + 8, color);
                }
            }
        } // DrawControl
Пример #3
0
        } // DrawControl

        private void DrawPart(Rectangle rect, BevelBorder pos, BevelStyle style, bool all)
        {
            SkinLayer layer = SkinInformation.Layers["Control"];
            Color c1 = Utilities.ParseColor(layer.Attributes["LightColor"].Value);
            Color c2 = Utilities.ParseColor(layer.Attributes["DarkColor"].Value);
            Color c3 = Utilities.ParseColor(layer.Attributes["FlatColor"].Value);

            if (Color != UndefinedColor) c3 = Color;

            Texture texture = SkinInformation.Layers["Control"].Image.Texture;

            int x1 = 0; int y1 = 0; int w1 = 0; int h1 = 0;
            int x2 = 0; int y2 = 0; int w2 = 0; int h2 = 0;

            if (style == BevelStyle.Bumped || style == BevelStyle.Etched)
            {
                if (all && (pos == BevelBorder.Top || pos == BevelBorder.Bottom))
                {
                    rect = new Rectangle(rect.Left + 1, rect.Top, rect.Width - 2, rect.Height);
                }
                else if (all && (pos == BevelBorder.Left))
                {
                    rect = new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height - 1);
                }
                switch (pos)
                {
                    case BevelBorder.Left:
                        {
                            x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height;
                            x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1;
                            break;
                        }
                    case BevelBorder.Top:
                        {
                            x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1;
                            x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1;
                            break;
                        }
                    case BevelBorder.Right:
                        {
                            x1 = rect.Left + rect.Width - 2; y1 = rect.Top; w1 = 1; h1 = rect.Height;
                            x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1;
                            break;
                        }
                    case BevelBorder.Bottom:
                        {
                            x1 = rect.Left; y1 = rect.Top + rect.Height - 2; w1 = rect.Width; h1 = 1;
                            x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1;
                            break;
                        }
                }
            }
            else
            {
                switch (pos)
                {
                    case BevelBorder.Left:
                        {
                            x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height;
                            break;
                        }
                    case BevelBorder.Top:
                        {
                            x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1;
                            break;
                        }
                    case BevelBorder.Right:
                        {
                            x1 = rect.Left + rect.Width - 1; y1 = rect.Top; w1 = 1; h1 = rect.Height;
                            break;
                        }
                    case BevelBorder.Bottom:
                        {
                            x1 = rect.Left; y1 = rect.Top + rect.Height - 1; w1 = rect.Width; h1 = 1;
                            break;
                        }
                }
            }

            switch (Style)
            {
                case BevelStyle.Bumped:
                    {
                        Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c1);
                        Renderer.Draw(texture.Resource, new Rectangle(x2, y2, w2, h2), c2);
                        break;
                    }
                case BevelStyle.Etched:
                    {
                        Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c2);
                        Renderer.Draw(texture.Resource, new Rectangle(x2, y2, w2, h2), c1);
                        break;
                    }
                case BevelStyle.Raised:
                    {
                        Color c = c1;
                        if (pos == BevelBorder.Left || pos == BevelBorder.Top) c = c1;
                        else c = c2;

                        Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c);
                        break;
                    }
                case BevelStyle.Lowered:
                    {
                        Color c = c1;
                        if (pos == BevelBorder.Left || pos == BevelBorder.Top) c = c2;
                        else c = c1;

                        Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c);
                        break;
                    }
                default:
                    {
                        Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c3);
                        break;
                    }
            }
        } // DrawPart
Пример #4
0
        } // GetIconRectangle

        /// <summary>
        /// Prerender the control into the control's render target.
        /// </summary>
        protected override void DrawControl(Rectangle rect)
        {
            SkinLayer skinLayerFrameTop    = captionVisible ? SkinInformation.Layers[layerCaption] : SkinInformation.Layers[layerFrameTop];
            SkinLayer skinLayerFrameLeft   = SkinInformation.Layers[layerFrameLeft];
            SkinLayer skinLayerFrameRight  = SkinInformation.Layers[layerFrameRight];
            SkinLayer skinLayerFrameBottom = SkinInformation.Layers[layerFrameBottom];
            SkinLayer skinLayerIcon        = SkinInformation.Layers[layerIcon];
            LayerStates layerStateFrameTop, layerStateFrameLeft, layerStateFrameRight, layerStateFrameButtom;
            SpriteFont font = skinLayerFrameTop.Text.Font.Font.Resource;
            Color color;

            if ((Focused || (UserInterfaceManager.FocusedControl != null && UserInterfaceManager.FocusedControl.Root == Root)) && ControlState != ControlState.Disabled)
            {
                layerStateFrameTop = skinLayerFrameTop.States.Focused;
                layerStateFrameLeft = skinLayerFrameLeft.States.Focused;
                layerStateFrameRight = skinLayerFrameRight.States.Focused;
                layerStateFrameButtom = skinLayerFrameBottom.States.Focused;
                color = skinLayerFrameTop.Text.Colors.Focused;
            }
            else if (ControlState == ControlState.Disabled)
            {
                layerStateFrameTop = skinLayerFrameTop.States.Disabled;
                layerStateFrameLeft = skinLayerFrameLeft.States.Disabled;
                layerStateFrameRight = skinLayerFrameRight.States.Disabled;
                layerStateFrameButtom = skinLayerFrameBottom.States.Disabled;
                color = skinLayerFrameTop.Text.Colors.Disabled;
            }
            else
            {
                layerStateFrameTop = skinLayerFrameTop.States.Enabled;
                layerStateFrameLeft = skinLayerFrameLeft.States.Enabled;
                layerStateFrameRight = skinLayerFrameRight.States.Enabled;
                layerStateFrameButtom = skinLayerFrameBottom.States.Enabled;
                color = skinLayerFrameTop.Text.Colors.Enabled;
            }
            // Render Background plane
            Renderer.DrawLayer(SkinInformation.Layers[layerWindow], rect, SkinInformation.Layers[layerWindow].States.Enabled.Color, SkinInformation.Layers[layerWindow].States.Enabled.Index);
            // Render border
            if (borderVisible)
            {
                Renderer.DrawLayer(skinLayerFrameTop, new Rectangle(rect.Left, rect.Top, rect.Width, skinLayerFrameTop.Height), layerStateFrameTop.Color, layerStateFrameTop.Index);
                Renderer.DrawLayer(skinLayerFrameLeft, new Rectangle(rect.Left, rect.Top + skinLayerFrameTop.Height, skinLayerFrameLeft.Width, rect.Height - skinLayerFrameTop.Height - skinLayerFrameBottom.Height), layerStateFrameLeft.Color, layerStateFrameLeft.Index);
                Renderer.DrawLayer(skinLayerFrameRight, new Rectangle(rect.Right - skinLayerFrameRight.Width, rect.Top + skinLayerFrameTop.Height, skinLayerFrameRight.Width, rect.Height - skinLayerFrameTop.Height - skinLayerFrameBottom.Height), layerStateFrameRight.Color, layerStateFrameRight.Index);
                Renderer.DrawLayer(skinLayerFrameBottom, new Rectangle(rect.Left, rect.Bottom - skinLayerFrameBottom.Height, rect.Width, skinLayerFrameBottom.Height), layerStateFrameButtom.Color, layerStateFrameButtom.Index);

                if (iconVisible && (Icon != null || skinLayerIcon != null) && captionVisible)
                {
                    Texture2D i = Icon ?? skinLayerIcon.Image.Texture.Resource;
                    Renderer.Draw(i, GetIconRectangle(), Color.White);
                }

                int icosize = 0;
                if (skinLayerIcon != null && iconVisible && captionVisible)
                {
                    icosize = skinLayerFrameTop.Height - skinLayerFrameTop.ContentMargins.Vertical + 4 + skinLayerIcon.OffsetX;
                }
                int closesize = 0;
                if (buttonClose.Visible)
                {
                    closesize = buttonClose.Width - (buttonClose.SkinInformation.Layers[layerButton].OffsetX);
                }

                Rectangle r = new Rectangle(rect.Left + skinLayerFrameTop.ContentMargins.Left + icosize,
                                            rect.Top + skinLayerFrameTop.ContentMargins.Top,
                                            rect.Width - skinLayerFrameTop.ContentMargins.Horizontal - closesize - icosize,
                                            skinLayerFrameTop.Height - skinLayerFrameTop.ContentMargins.Top - skinLayerFrameTop.ContentMargins.Bottom);
                int ox = skinLayerFrameTop.Text.OffsetX;
                int oy = skinLayerFrameTop.Text.OffsetY;
                Renderer.DrawString(font, Text, r, color, skinLayerFrameTop.Text.Alignment, ox, oy, true);
            }
        } // DrawControl