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(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);
            }
        }