Exemplo n.º 1
0
        internal GUIStyleState getState(GUIDrawArguments drawArgs)
        {
            if (drawArgs.on)
            {
                if (drawArgs.hasKeyboardFocus)
                {
                    return(onFocused);
                }
                else if (drawArgs.isActive)
                {
                    return(onActive);
                }
                else if (drawArgs.isHover)
                {
                    return(onHover);
                }
                else
                {
                    return(onNormal);
                }
            }
            else
            {
                if (drawArgs.hasKeyboardFocus)
                {
                    return(focused);
                }
                else if (drawArgs.isActive)
                {
                    return(active);
                }
                else if (drawArgs.isHover)
                {
                    return(hover);
                }
            }

            return(normal);
        }
Exemplo n.º 2
0
        internal void Draw(RenderManager graphics, GUIContent content, GUIDrawArguments drawArgs)
        {
            var size = drawArgs.position.Size;

            if (fixedWidth > 0f)
            {
                size.X = fixedWidth;
            }
            if (fixedHeight > 0f)
            {
                size.Y = fixedHeight;
            }

            drawArgs.content = AxisAlignedBox.FromRect(drawArgs.position.minVector + padding.min, size - padding.max - padding.min);
            var textSize = Vector2.Zero;

            if (!string.IsNullOrEmpty(content.text))
            {
                if (wordWrap)
                {
                    textSize = font.MeasureString(content.text, drawArgs.content.Size);
                }
                else
                {
                    textSize = font.MeasureString(content.text);
                }
            }

            var remainingWidth  = drawArgs.content.Width - textSize.X;
            var remainingHeight = drawArgs.content.Height - textSize.Y;

            var drawIcon = content.icon != null;
            var drawText = !string.IsNullOrEmpty(content.text);

            var state = getState(drawArgs);

            if (remainingWidth <= 0 && imagePosition == ImagePosition.ImageLeft)
            {
                textSize.X = drawArgs.content.Width;
                drawIcon   = false;
            }
            else if (remainingHeight <= 0 && imagePosition == ImagePosition.ImageAbove)
            {
                textSize.Y = drawArgs.content.Height;
                drawIcon   = false;
            }

            var material = state.material;// Root.instance.resources.createMaterialFromTexture("content/textures/gui/box.png")

            if (material != null)
            {
                if (border.min == Vector2.Zero && border.max == Vector2.Zero)
                {
                    graphics.Draw(material, drawArgs.position, state.backgroundColor);
                }
                else
                {
                    var src      = AxisAlignedBox.FromRect(Vector2.Zero, material.textureSize);
                    var dstRects = drawArgs.position.fromRectOffset(border);
                    var srcRects = src.fromRectOffset(border);
                    for (var i = 0; i < dstRects.Length; i++)
                    {
                        if (dstRects[i].Width > 0 && dstRects[i].Height > 0)
                        {
                            graphics.Draw(material, dstRects[i], srcRects[i], state.backgroundColor);
                        }
                    }
                }
            }

            if (drawIcon && imagePosition == ImagePosition.ImageLeft)
            {
                AxisAlignedBox icon, text;
                computeTextAndIconLeft(content, drawArgs.content, textSize, remainingWidth, out icon, out text);

                graphics.Draw(content.icon, icon, Color.White);
                font.DrawText(graphics.currentRenderQueue, text.minVector, this.fontSize, content.text, state.textColor, 0f, text.Width);
            }
            else if (drawIcon && imagePosition == ImagePosition.ImageAbove)
            {
                AxisAlignedBox icon, text;
                computeTextAndIconAbove(content, drawArgs.content, textSize, remainingHeight, out icon, out text);

                graphics.Draw(content.icon, icon, Color.White);
                if (wordWrap)
                {
                    font.DrawWrappedOnWordText(graphics.currentRenderQueue, text.minVector, this.fontSize, content.text, state.textColor, 0f, text.Size);
                }
                else
                {
                    font.DrawText(graphics.currentRenderQueue, text.minVector, this.fontSize, content.text, state.textColor, 0f, text.Width);
                }
            }
            else if (drawText && imagePosition != ImagePosition.ImageOnly)
            {
                var position = computePosition(drawArgs.content, textSize);
                if (wordWrap)
                {
                    font.DrawWrappedOnWordText(graphics.currentRenderQueue, position.minVector, this.fontSize, content.text, state.textColor, 0f, position.Size);
                }
                else
                {
                    font.DrawText(graphics.currentRenderQueue, position.minVector, this.fontSize, content.text, state.textColor, 0f, position.Width);
                }
            }
            else if (drawIcon && imagePosition != ImagePosition.TextOnly)
            {
                var position = computePosition(drawArgs.content, content.icon.textureSize);
                graphics.Draw(content.icon, position, Color.White);
                graphics.DrawRect(position, Color.Blue);
            }
        }