Example #1
0
        /// <summary>
        ///   Renders the specified control using the provided graphics interface
        /// </summary>
        /// <param name="control">Control that will be rendered</param>
        /// <param name="graphics">
        ///   Graphics interface that will be used to draw the control
        /// </param>
        public void Render(
            Controls.Desktop.ChoiceControl control, IFlatGuiGraphics graphics
            )
        {
            // Determine the index of the state we're going to display
            int stateIndex = (control.Selected ? 4 : 0);

            if (control.Enabled)
            {
                if (control.Depressed)
                {
                    stateIndex += 3;
                }
                else if (control.MouseHovering)
                {
                    stateIndex += 2;
                }
                else
                {
                    stateIndex += 1;
                }
            }

            // Get the pixel coordinates of the region covered by the control on
            // the screen
            RectangleF controlBounds = control.GetAbsoluteBounds();
            float      width         = controlBounds.Width;

            // Now adjust the bounds to a square of height x height pixels so we can
            // render the graphical portion of the choice control
            controlBounds.Width = controlBounds.Height;
            graphics.DrawElement(states[stateIndex], controlBounds);

            // If the choice has text assigned to it, render it too
            if (!string.IsNullOrEmpty(control.Text))
            {
                // Restore the original width, then subtract the region that was covered by
                // the graphical portion of the control.
                controlBounds.Width = width - controlBounds.Height;
                controlBounds.X    += controlBounds.Height;

                // Draw the text that was assigned to the choice control
                graphics.DrawString(states[stateIndex], controlBounds, control.Text);
            }
        }
Example #2
0
        public void Render(PaletteButtonControl control, IFlatGuiGraphics graphics)
        {
            RectangleF controlBounds = control.GetAbsoluteBounds();

            // Determine the style to use for the button
            int stateIndex = 0;

            if (control.Enabled)
            {
                if (control.Depressed)
                {
                    stateIndex = 3;
                }
                else if (control.MouseHovering || control.HasFocus)
                {
                    stateIndex = 2;
                }
                else
                {
                    stateIndex = 1;
                }
            }

            // Draw the button's frame
            ByteColor color = control.Color;

            graphics.DrawElement(states[stateIndex], ref controlBounds, ref color);

            RectangleF innerBounds = controlBounds;

            innerBounds.Inflate(-1f, -1f);

            if (control.Texture != null)
            {
                graphics.DrawCustomTexture(control.Texture, ref innerBounds);
            }

            // If there's text assigned to the button, draw it into the button
            if (!string.IsNullOrEmpty(control.Text))
            {
                graphics.DrawString(states[stateIndex], 0, ref controlBounds, control.Text, true);
            }
        }
        /// <summary>
        ///   Renders the specified control using the provided graphics interface
        /// </summary>
        /// <param name="control">Control that will be rendered</param>
        /// <param name="graphics">
        ///   Graphics interface that will be used to draw the control
        /// </param>
        public void Render(
            Controls.Desktop.WindowControl control, IFlatGuiGraphics graphics
            )
        {
            RectangleF controlBounds = control.GetAbsoluteBounds();

            if (control.CustomWindowImage == null)
            {
                graphics.DrawElement("window", ref controlBounds);
            }
            else
            {
                graphics.DrawCustomTexture(control.CustomWindowImage, ref controlBounds, 0, control.DrawGroupId);
            }

            if (control.Title != null)
            {
                graphics.DrawString("window", 0, ref controlBounds, control.Title, false);
            }
        }
Example #4
0
        /// <summary>
        ///     Renders the specified control using the provided graphics interface
        /// </summary>
        /// <param name="control">Control that will be rendered</param>
        /// <param name="graphics">
        ///     Graphics interface that will be used to draw the control
        /// </param>
        public void Render(GuiButtonControl control, IFlatGuiGraphics graphics)
        {
            var controlBounds = control.GetAbsoluteBounds();

            // Determine the style to use for the button
            var stateIndex = 0;

            if (control.Enabled)
            {
                if (control.Depressed)
                {
                    stateIndex = 3;
                }
                else
                {
                    if (control.MouseHovering || control.HasFocus)
                    {
                        stateIndex = 2;
                    }
                    else
                    {
                        stateIndex = 1;
                    }
                }
            }

            // Draw the button's frame
            graphics.DrawElement(_states[stateIndex], controlBounds);

            // If there's image assigned to the button, draw it into the button
            if (control.Texture != null)
            {
                graphics.DrawImage(controlBounds, control.Texture, control.SourceRectangle);
            }

            // If there's text assigned to the button, draw it into the button
            if (!string.IsNullOrEmpty(control.Text))
            {
                graphics.DrawString(_states[stateIndex], controlBounds, control.Text);
            }
        }
Example #5
0
        public void Render(StickyButtonControl control, IFlatGuiGraphics graphics)
        {
            var controlBounds = control.GetAbsoluteBounds();

            // Determine the style to use for the button
            var stateIndex = 0;

            if (control.Enabled)
            {
                if (control.Depressed)
                {
                    stateIndex = 3;
                }
                else if (control.MouseHovering || control.HasFocus)
                {
                    stateIndex = 2;
                }
                else
                {
                    stateIndex = 1;
                }
            }

            if (control.Sticked)
            {
                stateIndex = 3;
            }

            // Draw the button's frame
            graphics.DrawElement(States[stateIndex], ref controlBounds);

            // If there's text assigned to the button, draw it into the button
            if (!string.IsNullOrEmpty(control.Text))
            {
                graphics.DrawString(States[stateIndex], 0, ref controlBounds, control.Text, false);
            }
        }
        /// <summary>
        ///   Renders the specified control using the provided graphics interface
        /// </summary>
        /// <param name="control">Control that will be rendered</param>
        /// <param name="graphics">
        ///   Graphics interface that will be used to draw the control
        /// </param>
        public void Render(Controls.Desktop.InputControl control, IFlatGuiGraphics graphics)
        {
            RectangleF controlBounds = control.GetAbsoluteBounds();

            // Draw the control's frame and background
            if (control.CustomBackground == null)
            {
                graphics.DrawElement(Style, ref controlBounds);
            }
            else
            {
                graphics.DrawCustomTexture(control.CustomBackground, ref controlBounds);
            }

            if (control.CustomHintImage != null && string.IsNullOrEmpty(control.Text) && !control.HasFocus)
            {
                var bounds = controlBounds;

                bounds.Width  = control.CustomHintImage.Width;
                bounds.Height = control.CustomHintImage.Height;

                if (!control.CustomHintImageOffset.HasValue)
                {
                    var dx = (controlBounds.Height - bounds.Height) / 2;

                    bounds.X += dx;
                    bounds.Y += dx;
                }
                else
                {
                    bounds.X += control.CustomHintImageOffset.Value.X;
                    bounds.Y += control.CustomHintImageOffset.Value.Y;
                }

                graphics.DrawCustomTexture(control.CustomHintImage, ref bounds);
            }

            //Clip the region
            using (graphics.SetClipRegion(ref controlBounds))
            {
                string text = control.Text ?? string.Empty;

                // Amount by which the text will be moved within the input box in
                // order to keep the caret in view even when the text is wider than
                // the input box.
                float left = 0;

                // Only scroll the text within the input box when it has the input
                // focus and the caret is being shown.
                if (control.HasFocus)
                {
                    float offSetSize = 0;
                    // Find out where the cursor is from the left end of the text
                    RectangleF stringSize;
                    if (control.CustomFont == null)
                    {
                        stringSize = graphics.MeasureString(Style, ref controlBounds, text.Substring(0, control.CaretPosition));
                    }
                    else
                    {
                        stringSize = graphics.MeasureString(control.CustomFont, ref controlBounds, text.Substring(0, control.CaretPosition));
                        offSetSize = control.CustomFont.Size;
                    }

                    // exTODO: Renderer should query the size of the control's frame
                    //   Otherwise text will be visible over the frame, which might look bad
                    //   if a skin uses a frame wider than 2 pixels or in a different color
                    //   than the text.
                    while ((stringSize.Width + offSetSize) + left > controlBounds.Width)
                    {
                        left -= controlBounds.Width / 10.0f;
                    }
                }

                // Draw the text into the input box
                controlBounds.X += left;

                string textToDraw = control.Text;
                if (control.IsPassword)
                {
                    textToDraw = new string('*', textToDraw.Length);
                }

                int withCarret = -1;
                // If the input box is in focus, also draw the caret so the user knows
                // where characters will be inserted into the text.
                if (control.HasFocus)
                {
                    if (control.MillisecondsSinceLastCaretMovement % 500 < 250)
                    {
                        withCarret = control.CaretPosition;
                    }
                }

                if (control.ColorSet)
                {
                    ByteColor color = control.Color;

                    if (control.CustomFont != null)
                    {
                        if (!control.TextOffset.HasValue)
                        {
                            var dx = (controlBounds.Height - control.CustomFont.HeightInPoints) / 2;
                            var dy = (controlBounds.Height - control.CustomFont.CharHeight) / 2;

                            controlBounds.X += dx;
                            controlBounds.Y += dy;
                        }
                        else
                        {
                            controlBounds.X += control.TextOffset.Value.X;
                            controlBounds.Y += control.TextOffset.Value.Y;
                        }

                        graphics.DrawString(control.CustomFont, ref controlBounds, textToDraw, ref color, false, withCarret);
                    }
                    else
                    {
                        graphics.DrawString(Style, 0, ref controlBounds, textToDraw, ref color, false, withCarret);
                    }
                }
                else
                {
                    if (control.CustomFont != null)
                    {
                        ByteColor color = control.Color;
                        if (!control.TextOffset.HasValue)
                        {
                            var dx = (controlBounds.Height - control.CustomFont.HeightInPoints) / 2;
                            var dy = (controlBounds.Height - control.CustomFont.CharHeight) / 2;

                            controlBounds.X += dx;
                            controlBounds.Y += dy;
                        }
                        else
                        {
                            controlBounds.X += control.TextOffset.Value.X;
                            controlBounds.Y += control.TextOffset.Value.Y;
                        }

                        graphics.DrawString(control.CustomFont, ref controlBounds, textToDraw, ref color, false, withCarret);
                    }
                    else
                    {
                        graphics.DrawString(Style, 0, ref controlBounds, textToDraw, false, withCarret);
                    }
                }
            }

            // Let the control know that we can provide it with additional informations
            // about how its text is being rendered
            control.OpeningLocator = this;
            this.graphics          = graphics;
        }
Example #7
0
 /// <summary>
 ///   Renders the specified control using the provided graphics interface
 /// </summary>
 /// <param name="control">Control that will be rendered</param>
 /// <param name="graphics">
 ///   Graphics interface that will be used to draw the control
 /// </param>
 public void Render(Controls.Arcade.PanelControl control, IFlatGuiGraphics graphics)
 {
     // This is simple! A panel consists of a single element we need to draw.
     graphics.DrawElement("window", control.GetAbsoluteBounds());
 }
        /// <summary>
        ///   Renders the specified control using the provided graphics interface
        /// </summary>
        /// <param name="control">Control that will be rendered</param>
        /// <param name="graphics">
        ///   Graphics interface that will be used to draw the control
        /// </param>
        public void Render(Controls.Desktop.InputKeyCatchControl control, IFlatGuiGraphics graphics)
        {
            RectangleF controlBounds = control.GetAbsoluteBounds();

            // Draw the control's frame and background
            if (control.CustomBackground == null)
            {
                if (control.HasFocus)
                {
                    graphics.DrawElement(Style, ref controlBounds, ref control.HasFocusBackColor);
                }
                else
                {
                    graphics.DrawElement(Style, ref controlBounds);
                }
            }
            else
            {
                graphics.DrawCustomTexture(control.CustomBackground, ref controlBounds);
            }

            if (control.CustomHintImage != null && string.IsNullOrEmpty(control.Text) && !control.HasFocus)
            {
                var bounds = controlBounds;

                bounds.Width  = control.CustomHintImage.Width;
                bounds.Height = control.CustomHintImage.Height;

                var dx = (controlBounds.Height - bounds.Height) / 2;

                bounds.X += dx;
                bounds.Y += dx;

                graphics.DrawCustomTexture(control.CustomHintImage, ref bounds);
            }

            using (graphics.SetClipRegion(ref controlBounds))
            {
                string text = control.Text ?? string.Empty;

                // Amount by which the text will be moved within the input box in
                // order to keep the caret in view even when the text is wider than
                // the input box.
                float left = 0;

                // Only scroll the text within the input box when it has the input
                // focus and the caret is being shown.
                if (control.HasFocus)
                {
                    // Find out where the cursor is from the left end of the text
                    RectangleF stringSize = graphics.MeasureString(Style, ref controlBounds, text);

                    // exTODO: Renderer should query the size of the control's frame
                    //   Otherwise text will be visible over the frame, which might look bad
                    //   if a skin uses a frame wider than 2 pixels or in a different color
                    //   than the text.
                    while (stringSize.Width + left > controlBounds.Width)
                    {
                        left -= controlBounds.Width / 10.0f;
                    }
                }

                // Draw the text into the input box
                controlBounds.X += left;

                string textToDraw = control.Text;

                // If the input box is in focus, also draw the caret so the user knows
                // where characters will be inserted into the text.
                if (control.ColorSet)
                {
                    ByteColor color = control.Color;

                    if (control.CustomFont != null)
                    {
                        var move = (controlBounds.Height - control.CustomFont.CharHeight) / 2;
                        controlBounds.X += move;
                        controlBounds.Y += move;
#if DEBUG
                        if (move <= 2)
                        {
                            logger.Warn("Input component height ({0}) too small for the font size ({1})!", controlBounds.Height, control.CustomFont.CharHeight);
                        }
#endif
                        graphics.DrawString(control.CustomFont, ref controlBounds, textToDraw, ref color, false);
                    }
                    else
                    {
                        graphics.DrawString(Style, 0, ref controlBounds, textToDraw, ref color, false);
                    }
                }
                else
                {
                    if (control.CustomFont != null)
                    {
                        ByteColor color = control.Color;
                        var       move  = (controlBounds.Height - control.CustomFont.CharHeight) / 2;
                        controlBounds.X += move;
                        controlBounds.Y += move;

                        graphics.DrawString(control.CustomFont, ref controlBounds, textToDraw, ref color, false);
                    }
                    else
                    {
                        graphics.DrawString(Style, 0, ref controlBounds, textToDraw, false);
                    }
                }
            }

            // Let the control know that we can provide it with additional informations
            // about how its text is being rendered
            this.graphics = graphics;
        }
Example #9
0
        public void Render(InventoryCell control, IFlatGuiGraphics graphics)
        {
            var controlBounds = control.GetAbsoluteBounds();

            #region Backgroung
            if (control.DrawCellBackground)
            {
                if (control.MouseHovering || control.IsCellSelected)
                {
                    if (control.CustomBackgroundHover != null)
                    {
                        if (control.CustomBackgroundAutosize)
                        {
                            graphics.DrawCustomTexture(control.CustomBackgroundHover, ref controlBounds, 0, control.DrawGroupId);
                        }
                        else
                        {
                            var dx = (controlBounds.Width - control.CustomBackgroundHover.Width) / 2;
                            var dy = (controlBounds.Height - control.CustomBackgroundHover.Height) / 2;

                            var bgBounds = controlBounds;

                            bgBounds.X     += dx;
                            bgBounds.Y     += dy;
                            bgBounds.Width  = control.CustomBackgroundHover.Width;
                            bgBounds.Height = control.CustomBackgroundHover.Height;

                            graphics.DrawCustomTexture(control.CustomBackgroundHover, ref bgBounds, 0, control.DrawGroupId);
                        }
                    }
                    else
                    {
                        graphics.DrawElement("button.highlighted", ref controlBounds);
                    }
                }
                else
                {
                    if (control.CustomBackground != null)
                    {
                        if (control.CustomBackgroundAutosize)
                        {
                            graphics.DrawCustomTexture(control.CustomBackground, ref controlBounds, 0, control.DrawGroupId);
                        }
                        else
                        {
                            var dx = (controlBounds.Width - control.CustomBackground.Width) / 2;
                            var dy = (controlBounds.Height - control.CustomBackground.Height) / 2;

                            var bgBounds = controlBounds;

                            bgBounds.X     += dx;
                            bgBounds.Y     += dy;
                            bgBounds.Width  = control.CustomBackground.Width;
                            bgBounds.Height = control.CustomBackground.Height;

                            graphics.DrawCustomTexture(control.CustomBackground, ref bgBounds, 0, control.DrawGroupId);
                        }
                    }
                    else
                    {
                        graphics.DrawElement("button.normal", ref controlBounds, control.DrawGroupId);
                    }
                }
            }
            #endregion

            #region Item icon
            if (control.Slot != null && !control.Slot.IsEmpty)
            {
                SpriteTexture tex;
                int           textureArrayIndex;
                control.IconFactory.Lookup(control.Slot.Item, out tex, out textureArrayIndex);
                if (tex != null)
                {
                    const int innerBorder = 3;
                    var       texBounds   = new RectangleF(
                        controlBounds.X + innerBorder,
                        controlBounds.Y + innerBorder,
                        controlBounds.Width - innerBorder * 2,
                        controlBounds.Height - innerBorder * 2
                        );

                    ByteColor?color = control.Color;

                    if (control.IsDisabledCell)
                    {
                        color = new ByteColor(255, 255, 255, 30);
                    }

                    graphics.DrawCustomTexture(tex, ref texBounds, textureArrayIndex, control.DrawIconsGroupId, color);
                }
                else
                {
                    var displayName = control.Slot.Item.Name;

                    graphics.DrawString("button.normal", 0, ref controlBounds, displayName, false, -1, control.DrawGroupId);
                }
            }
            #endregion

            #region Items count

            if ((control.Slot != null && control.Slot.ItemsCount > 1) || !string.IsNullOrEmpty(control.CountString))
            {
                var itemsCount = control.CountString ?? control.Slot.ItemsCount.ToString();

                var textSize = graphics.MeasureString("slot.items", ref controlBounds, itemsCount);

                var h = textSize.Height;
                var w = textSize.Width;

                var textPosition = new RectangleF(controlBounds.X + controlBounds.Width - textSize.Width - 6,
                                                  controlBounds.Y + controlBounds.Height - textSize.Height,
                                                  w,
                                                  h);
                graphics.DrawString("slot.items.shadow", 0, ref textPosition, itemsCount, false, -1, control.DrawGroupId);
                graphics.DrawString("slot.items", 0, ref textPosition, itemsCount, false, -1, control.DrawGroupId);
            }

            #endregion
        }
 public void Render(GridCellControl control, IFlatGuiGraphics graphics)
 {
     graphics.DrawElement(_highlights[control.Highlight], control.GetAbsoluteBounds());
 }
        /// <summary>
        ///   Renders the specified control using the provided graphics interface
        /// </summary>
        /// <param name="control">Control that will be rendered</param>
        /// <param name="graphics">
        ///   Graphics interface that will be used to draw the control
        /// </param>
        public void Render(
            Controls.Desktop.ButtonControl control, IFlatGuiGraphics graphics
            )
        {
            RectangleF controlBounds = control.GetAbsoluteBounds();

            // Determine the style to use for the button
            int stateIndex = 0;

            if (control.Enabled)
            {
                if (control.Depressed)
                {
                    stateIndex = 3;
                }
                else if (control.MouseHovering || control.HasFocus)
                {
                    stateIndex = 2;
                }
                else
                {
                    stateIndex = 1;
                }
            }

            if (stateIndex == 0)
            {
                if (control.CustomImageDisabled != null)
                {
                    graphics.DrawCustomTexture(control.CustomImageDisabled, ref controlBounds);
                }
                else if (control.CustomImage != null)
                {
                    graphics.DrawCustomTexture(control.CustomImage, ref controlBounds, 0, control.DrawGroupId, new ByteColor(255, 255, 255, 100));
                }
            }
            else if (stateIndex == 1 && control.CustomImage != null)
            {
                graphics.DrawCustomTexture(control.CustomImage, ref controlBounds);
            }
            else if (stateIndex == 2 && control.CustomImageHover != null)
            {
                graphics.DrawCustomTexture(control.CustomImageHover, ref controlBounds);
            }
            else if (stateIndex == 3 && control.CustomImageDown != null)
            {
                graphics.DrawCustomTexture(control.CustomImageDown, ref controlBounds);
            }
            else
            {
                // Draw the button's frame
                graphics.DrawElement(states[stateIndex], ref controlBounds);
            }

            if (control.CusomImageLabel != null)
            {
                var imgRect = controlBounds;

                imgRect.X     += (imgRect.Width - control.CusomImageLabel.Width) / 2;
                imgRect.Y     += (imgRect.Height - control.CusomImageLabel.Height) / 2;
                imgRect.Width  = control.CusomImageLabel.Width;
                imgRect.Height = control.CusomImageLabel.Height;

                if (stateIndex == 3)
                {
                    imgRect.Y += 1;
                }

                if (stateIndex == 0)
                {
                    graphics.DrawCustomTexture(control.CusomImageLabel, ref imgRect, 0, control.DrawGroupId, new ByteColor(255, 255, 255, 100));
                }
                else
                {
                    graphics.DrawCustomTexture(control.CusomImageLabel, ref imgRect);
                }
            }
            else if (!string.IsNullOrEmpty(control.Text))
            {
                if (control.CustomFont != null)
                {
                    ByteColor color = control.Color;
                    graphics.DrawString(control.CustomFont, ref controlBounds, control.Text, ref color, false, -1, FlatGuiGraphics.Frame.HorizontalTextAlignment.Center, FlatGuiGraphics.Frame.VerticalTextAlignment.Center);
                }
                else
                {
                    if (control.ColorSet)
                    {
                        ByteColor color = control.Color;
                        graphics.DrawString(states[stateIndex], control.TextFontId, ref controlBounds, control.Text, ref color, false);
                    }
                    else
                    {
                        graphics.DrawString(states[stateIndex], control.TextFontId, ref controlBounds, control.Text, false);
                    }
                }
            }
        }
Example #12
0
 /// <summary>
 /// Renders the specified control.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="graphics">The graphics.</param>
 public void Render(SimpleSprite control, IFlatGuiGraphics graphics)
 {
     graphics.DrawElement(control.FrameName, control.GetAbsoluteBounds());
 }
Example #13
0
        public void Render(ImageControl control, IFlatGuiGraphics graphics)
        {
            RectangleF controlBounds = control.GetAbsoluteBounds();

            graphics.DrawElement("image", controlBounds, control.Texture, Color.White);
        }