Example #1
0
        public void Render(ContextMenuControl control, IFlatGuiGraphics graphics)
        {
            _graphics = graphics;

            RectangleF bounds = control.GetAbsoluteBounds();

            graphics.DrawElement("context", bounds);

            string text = control.Name;

            graphics.DrawString("context", bounds, text);

            var itemBounds = new RectangleF(bounds.X + 3, bounds.Y + 30, bounds.Width - 12, ContextMenuControl.ItemHeight);

            foreach (var item in control.Items)
            {
                if (control.SelectedItems.Contains(control.Items.IndexOf(item)))
                {
                    graphics.DrawElement("context.item.highlighted", itemBounds);
                }
                graphics.DrawString("context.item", itemBounds, item);
                itemBounds.Y += itemBounds.Height;
            }

            control.ListRowLocator = this;
        }
Example #2
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.LabelControl control, IFlatGuiGraphics graphics)
        {
            var absoluteBounds = control.GetAbsoluteBounds();

            if (control.CustomFont != null)
            {
                ByteColor color = control.Color;
                graphics.DrawString(control.CustomFont, ref absoluteBounds, control.Suffix == null ? control.Text : control.Text + control.Suffix, ref color, control.Autosizing, -1, control.CustomHorizontalPlacement, control.CustomVerticalPlacement);
            }
            else
            {
                string styleFrame;

                if (control.IsHeaderFont)
                {
                    styleFrame = "labelHeader";
                }
                else
                {
                    switch (control.FontStyle)
                    {
                    case System.Drawing.FontStyle.Bold:
                        styleFrame = "labelBold";
                        break;

                    case System.Drawing.FontStyle.Italic:
                        styleFrame = "labelItalic";
                        break;

                    case System.Drawing.FontStyle.Regular:
                        styleFrame = "label";
                        break;

                    case System.Drawing.FontStyle.Underline:
                        styleFrame = "labelUnderline";
                        break;

                    default:
                        styleFrame = "label";
                        break;
                    }
                }

                if (control.ColorSet)
                {
                    ByteColor color = control.Color;
                    graphics.DrawString(styleFrame, 0, ref absoluteBounds, control.Suffix == null ? control.Text : control.Text + control.Suffix, ref color, control.Autosizing);
                }
                else
                {
                    graphics.DrawString(styleFrame, 0, ref absoluteBounds, control.Suffix == null ? control.Text : control.Text + control.Suffix, control.Autosizing);
                }
            }
        }
        /// <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.CloseWindowButtonControl 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
            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);
            }
        }
        public void Render(StyledTextControl control, IFlatGuiGraphics graphics)
        {
            RectangleF controlBounds = control.GetAbsoluteBounds();

            // Draw the button's frame
            graphics.DrawString(control.Font, controlBounds, control.Text);
        }
        /// <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
            graphics.DrawElement(Style, controlBounds);

            using (graphics.SetClipRegion(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, controlBounds, text.Substring(0, control.CaretPosition)
                        );

                    // TODO: 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;
                graphics.DrawString(Style, controlBounds, 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.HasFocus)
                {
                    if (control.MillisecondsSinceLastCaretMovement % 500 < 250)
                    {
                        graphics.DrawCaret(
                            "input.normal", controlBounds, control.Text, control.CaretPosition
                            );
                    }
                }
            }

            // 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;
        }
        /// <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.ListControl control, IFlatGuiGraphics graphics)
        {
            this.graphics = graphics;

            RectangleF controlBounds = control.GetAbsoluteBounds();

            graphics.DrawElement(Style, ref controlBounds);

            // Cache the number of items in the list (as a float, this comes in handy later)
            // and the height of a single item when rendered
            float totalItems = control.Items.Count;
            float rowHeight  = GetRowHeight(controlBounds);

            // Number of items (+fraction) fitting into the list's height
            float itemsInView = controlBounds.Height / rowHeight;

            // Number of items by which the slider can move up and down
            float scrollableArea = Math.Max(totalItems - itemsInView, 0.0f);

            // Index (+fraction) of the item at the top of the list given
            // the slider's current position
            float scrollPosition = control.Slider.ThumbPosition * scrollableArea;

            // Determine the first and the last item we need to draw
            // (no need to draw the whole of the list when only a small subset
            // will end up in the clipping area)
            int firstItem = (int)scrollPosition;
            int lastItem  = (int)Math.Ceiling(scrollPosition + itemsInView);

            lastItem = Math.Min(lastItem, control.Items.Count);

            // Set up a rectangle we can use to track the bounds of the item
            // currently being rendered
            RectangleF itemBounds = controlBounds;

            itemBounds.Y     -= (scrollPosition - firstItem) * rowHeight;
            itemBounds.Height = rowHeight;

            //Force a scissor zone for drawing ! => Will flush the previously accumulated information
            using (graphics.SetClipRegion(ref controlBounds))
            {
                for (int item = firstItem; item < lastItem; ++item)
                {
                    if (control.SelectedItems.Contains(item))
                    {
                        graphics.DrawElement("list.selection", ref itemBounds);
                    }

                    graphics.DrawString(Style, 0, ref itemBounds, control.Items[item].ToString(), false);
                    //graphics.DrawElement("button.normal", itemBounds);
                    itemBounds.Y += rowHeight;
                }
            }

            control.ListRowLocator = this;
        }
        /// <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(GuiWindowControl control, IFlatGuiGraphics graphics)
        {
            var controlBounds = control.GetAbsoluteBounds();

            graphics.DrawElement("window", controlBounds);

            if (control.Title != null)
            {
                graphics.DrawString("window", controlBounds, control.Title);
            }
        }
Example #8
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(GuiLabelControl control, IFlatGuiGraphics graphics)
        {
            var frameName = "label";

            if (control.Style != null)
            {
                frameName = control.Style;
            }

            graphics.DrawString(frameName, control.GetAbsoluteBounds(), control.Text);
        }
Example #9
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(GuiListControl control, IFlatGuiGraphics graphics)
        {
            _graphics = graphics;

            var controlBounds = control.GetAbsoluteBounds();

            graphics.DrawElement(_style, controlBounds);

            // Cache the number of items in the list (as a float, this comes in handy later)
            // and the height of a single item when rendered
            float totalItems = control.Items.Count;
            var   rowHeight  = GetRowHeight(controlBounds);

            // Number of items (+fraction) fitting into the list's height
            var itemsInView = controlBounds.Height / rowHeight;

            // Number of items by which the slider can move up and down
            var scrollableArea = Math.Max(totalItems - itemsInView, 0.0f);

            // Index (+fraction) of the item at the top of the list given
            // the slider's current position
            var scrollPosition = control.Slider.ThumbPosition * scrollableArea;

            // Determine the first and the last item we need to draw
            // (no need to draw the whole of the list when only a small subset
            // will end up in the clipping area)
            var firstItem = (int)scrollPosition;
            var lastItem  = (int)Math.Ceiling(scrollPosition + itemsInView);

            lastItem = Math.Min(lastItem, control.Items.Count);

            // Set up a rectangle we can use to track the bounds of the item
            // currently being rendered
            var itemBounds = controlBounds;

            itemBounds.Y     -= (scrollPosition - firstItem) * rowHeight;
            itemBounds.Height = rowHeight;

            using (graphics.SetClipRegion(controlBounds))
            {
                for (var item = firstItem; item < lastItem; ++item)
                {
                    if (control.SelectedItems.Contains(item))
                    {
                        graphics.DrawElement("list.selection", itemBounds);
                    }

                    graphics.DrawString(_style, itemBounds, control.Items[item]);
                    itemBounds.Y += rowHeight;
                }
            }

            control.ListRowLocator = this;
        }
Example #10
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(GuiOptionControl control, IFlatGuiGraphics graphics)
        {
            // Determine the index of the state we're going to display
            var 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
            var controlBounds = control.GetAbsoluteBounds();
            var width         = controlBounds.Width;

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

            // If the option has text assigned to it, render it too
            if (control.Text != null)
            {
                // 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 option control
                graphics.DrawString(_states[stateIndex], controlBounds, control.Text);
            }
        }
Example #11
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 #12
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 #14
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 #15
0
        public void Render(QueuedCommandControl control, IFlatGuiGraphics graphics)
        {
            var controlBounds = control.GetAbsoluteBounds();

            // Draw the ability name
            graphics.DrawString("button.normal", controlBounds, control.Command.Ability.Name);

            var avatarBounds = new RectangleF(controlBounds.X, controlBounds.Y, controlBounds.Width, controlBounds.Height);

            avatarBounds.Height -= 10;
            avatarBounds.Width   = avatarBounds.Height;
            avatarBounds.X      += 5;
            avatarBounds.Y      += 5;
            graphics.DrawElement("avatar.icon." + control.Command.Character.Avatar.Icon, avatarBounds);
            var abilityBounds = new RectangleF(controlBounds.X, controlBounds.Y, controlBounds.Width, controlBounds.Height);

            abilityBounds.Height -= 10;
            abilityBounds.Width   = abilityBounds.Height;
            abilityBounds.X      += controlBounds.Width - 5 - abilityBounds.Width;
            abilityBounds.Y      += 5;
            graphics.DrawElement("radialcontrol.images." + control.Command.Ability.ImageName + ".normal", abilityBounds);
        }
        /// <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 #17
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(GuiLabelControl control, IFlatGuiGraphics graphics)
 {
     graphics.DrawString("label", control.GetAbsoluteBounds(), control.Text);
 }
        /// <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;
        }
        /// <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 #20
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.LabelControl control, IFlatGuiGraphics graphics)
 {
     graphics.DrawString(control.Frame, control.GetAbsoluteBounds(), control.Text);
 }
Example #21
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
        }