예제 #1
0
 /// <summary>
 /// draws border and background box in either the default background colors or in provided colors
 /// </summary>
 /// <param name="spriteBatch"></param>
 /// <param name="context"></param>
 /// <param name="specialBorderColor"></param>
 protected void drawBorderAndBackgroundBox(SpriteBatch spriteBatch, UIRenderingContext context, float layer, Color?borderColor = null, Color?backgroundColor = null)
 {
     borderColor = borderColor ?? UIStyleUnification.borderColor;
     spriteBatch.Draw(Main.notverymagicpixel, lastRenderedSize, null, borderColor.Value, 0f, Vector2.Zero, SpriteEffects.None, layer + .0002f);
     backgroundColor = backgroundColor ?? UIStyleUnification.elementBackground;
     spriteBatch.Draw(Main.notverymagicpixel, new Rectangle((int)context.nextControlRenderingLocation.X + UIStyleUnification.border, (int)context.nextControlRenderingLocation.Y + UIStyleUnification.border, lastRenderedSize.Width - 2 * UIStyleUnification.border, lastRenderedSize.Height - 2 * UIStyleUnification.border), null, backgroundColor.Value, 0, Vector2.Zero, SpriteEffects.None, layer + .0001f);
 }
예제 #2
0
        public override void draw(SpriteBatch spriteBatch, ref UIRenderingContext context, float layer)
        {
            //Render the text in the location provided by the UIRenderingContext
            spriteBatch.DrawString(font, text, context.nextControlRenderingLocation, color, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer);
            Vector2 size = font.MeasureString(text);

            lastRenderedSize = new Rectangle((int)context.nextControlRenderingLocation.X, (int)context.nextControlRenderingLocation.Y, (int)size.X, (int)size.Y);
        }
예제 #3
0
        public override void draw(SpriteBatch spriteBatch, ref UIRenderingContext context, float layer)
        {
            Color   colour = waitingForInput ? UIStyleUnification.elementSelect : UIStyleUnification.defaultText;
            Vector2 size   = Main.UIFont.MeasureString(keyName);

            lastRenderedSize = new Rectangle((int)context.nextControlRenderingLocation.X, (int)context.nextControlRenderingLocation.Y, (int)size.X + UIStyleUnification.borderSize * 3, (int)size.Y + UIStyleUnification.borderSize * 2);
            drawBorderAndBackgroundBox(spriteBatch, context, layer);
            spriteBatch.DrawString(Main.UIFont, keyName, context.nextControlRenderingLocation + new Vector2(UIStyleUnification.borderSize), colour, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer);
        }
예제 #4
0
        public override void draw(SpriteBatch spriteBatch, ref UIRenderingContext context, float layer)
        {
            Vector2 size = Main.UIFont.MeasureString(text);

            lastRenderedSize = new Rectangle((int)context.nextControlRenderingLocation.X, (int)context.nextControlRenderingLocation.Y, (int)size.X + UIStyleUnification.borderSize * 3, (int)size.Y + UIStyleUnification.borderSize * 2);
            Color backgroundColor = hovered ? UIStyleUnification.interactHoverBackground : UIStyleUnification.interactBackground;

            drawBorderAndBackgroundBox(spriteBatch, context, layer, UIStyleUnification.interactBorder, backgroundColor);
            spriteBatch.DrawString(Main.UIFont, text, context.nextControlRenderingLocation + new Vector2(UIStyleUnification.borderSize), UIStyleUnification.defaultText, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer);
        }
예제 #5
0
 public virtual void draw(SpriteBatch spriteBatch, ref UIRenderingContext context, float layer)
 {
     if (context.isHorizontal)
     {
         //Draw line for error.
         spriteBatch.Draw(Main.notverymagicpixel, context.nextControlRenderingLocation, null, UIStyleUnification.errorLineColor, 0f, Vector2.Zero, new Vector2(1, UIStyleUnification.errorLineHeight), SpriteEffects.None, layer);
         //set the last render location as the line
         lastRenderedSize = new Rectangle((int)context.nextControlRenderingLocation.X, (int)context.nextControlRenderingLocation.Y, 1, UIStyleUnification.errorLineHeight);
     }
     else
     {
         int errorLineWidth = context.width;
         spriteBatch.Draw(Main.notverymagicpixel, context.nextControlRenderingLocation, null, UIStyleUnification.errorLineColor, 0f, Vector2.Zero, new Vector2(errorLineWidth, 1), SpriteEffects.None, layer);
         //set the element's render location as the line
         lastRenderedSize = new Rectangle((int)context.nextControlRenderingLocation.X, (int)context.nextControlRenderingLocation.Y, errorLineWidth, 1);
     }
 }
예제 #6
0
        public override void draw(SpriteBatch spriteBatch, ref UIRenderingContext context, float layer)
        {
            lastRenderedSize = new Rectangle((int)context.nextControlRenderingLocation.X, (int)context.nextControlRenderingLocation.Y, totalBoxSide, totalBoxSide);
            if (grabbable)
            {
                drawBorderAndBackgroundBox(spriteBatch, context, layer, UIStyleUnification.selectOutline);
            }
            else
            {
                drawBorderAndBackgroundBox(spriteBatch, context, layer);
            }

            if (itemHolder.held != null)
            {
                spriteBatch.Draw(Item.itemTextures[itemHolder.held.id], new Rectangle((int)context.nextControlRenderingLocation.X + UIStyleUnification.borderSize, (int)context.nextControlRenderingLocation.Y + UIStyleUnification.borderSize, boxSide, boxSide), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, layer + .00001f);
            }
        }
        public override void draw(SpriteBatch spriteBatch, ref UIRenderingContext outerContext, float layer)
        {
            UIRenderingContext context = new UIRenderingContext(outerContext.nextControlRenderingLocation + new Vector2(xPadding, yPadding), false);

            foreach (UIElement element in elements)
            {
                //draw each element

                element.draw(spriteBatch, ref context, layer);
                //padding
                context.nextControlRenderingLocation.X += xPadding;
                context.nextControlRenderingLocation.X += element.lastRenderedSize.Width;
                context.speculateHeight(element.lastRenderedSize.Height);
            }
            //Only need to add one X padding due to it being added at the last element.
            int paddedWidth = context.width + xPadding;
            int height      = context.height + 2 * yPadding;

            lastRenderedSize = new Rectangle((int)outerContext.nextControlRenderingLocation.X, (int)outerContext.nextControlRenderingLocation.Y, paddedWidth, height);
        }
예제 #8
0
        public override void draw(SpriteBatch spriteBatch, ref UIRenderingContext context, float layer)
        {
            Vector2 size = Main.UIFont.MeasureString(text);

            lastRenderedSize = new Rectangle((int)context.nextControlRenderingLocation.X, (int)context.nextControlRenderingLocation.Y, width + UIStyleUnification.borderSize * 3, vertHeight + UIStyleUnification.borderSize * 2);
            if (selected)
            {
                drawBorderAndBackgroundBox(spriteBatch, context, layer, UIStyleUnification.selectOutline);
            }
            else
            {
                drawBorderAndBackgroundBox(spriteBatch, context, layer);
            }

            if (text != "")
            {
                spriteBatch.DrawString(Main.UIFont, text, context.nextControlRenderingLocation + new Vector2(UIStyleUnification.borderSize), UIStyleUnification.defaultText, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer);
            }
            else if (promptText != null)
            {
                spriteBatch.DrawString(Main.SlantUIFont, promptText, context.nextControlRenderingLocation + new Vector2(UIStyleUnification.borderSize), UIStyleUnification.fadedText, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer);
            }
        }
예제 #9
0
        public void draw(SpriteBatch spriteBatch, float layer)
        {
            if (!Visible)
            {
                return;
            }
            Vector2 renderloc = location;

            //don't move down with titlebar, also draw a border
            //if there is a titlebar, move down where the main window is drawn.
            if ((windowButtons & (uint)windowTopButtons.titlebar) == (uint)windowTopButtons.titlebar)
            {
                //renderloc.Y += titleBarHeight;
                //Also draw titlebar.
            }
            Color borderColor = isFocused ? UIStyleUnification.windowBorderColorFocused : UIStyleUnification.windowBorderColor;

            if (!tickedUp)
            {
                UIRenderingContext context = new UIRenderingContext(new Vector2(renderloc.X + xPadding, renderloc.Y + yPadding), true, minimumWidth);
                foreach (UIElement element in this)
                {
                    //draw each element
                    element.draw(spriteBatch, ref context, layer);

                    //Do this regardless of element type.
                    context.nextControlRenderingLocation.Y += element.lastRenderedSize.Height;
                    context.nextControlRenderingLocation.Y += yPadding;
                    context.speculateWidth(element.lastRenderedSize.Width);
                }
                //draw the background of the window based on total elements drawn.
                //which is in the UIRenderingContext
                int width = context.width;
                //save this width for later
                lastWidth = (uint)width;
                int paddedWidth = width + 2 * xPadding;
                //Only need to add one Y padding due to it being added at the last element.
                int height = context.height + yPadding;

                lastRenderedLocation = new Rectangle((int)renderloc.X, (int)renderloc.Y, paddedWidth, height);
                //draw the background of the window
                spriteBatch.Draw(Main.notverymagicpixel, lastRenderedLocation, null, UIStyleUnification.windowBackgroundColor, 0f, Vector2.Zero, SpriteEffects.None, layer + .001f);
                //draw border
                spriteBatch.Draw(Main.notverymagicpixel, new Rectangle(lastRenderedLocation.X - UIStyleUnification.windowBorder, lastRenderedLocation.Y - UIStyleUnification.windowBorder, lastRenderedLocation.Width + 2 * UIStyleUnification.windowBorder, lastRenderedLocation.Height + 2 * UIStyleUnification.windowBorder), null, borderColor, 0, Vector2.Zero, SpriteEffects.None, layer + 0.002f);
            }

            //Draw the titlebar.
            if ((windowButtons & (uint)windowTopButtons.titlebar) == (uint)windowTopButtons.titlebar)
            {
                //magic pixel is temporary, want to have a textured, 3d-looking, including on the ends, so it can just be drawn to the rectangle without any worries.
                int titleBarY = (int)location.Y - titleBarHeight;
                titleBarRectangle = new Rectangle((int)location.X, titleBarY, (int)lastPaddedWidth, titleBarHeight);
                spriteBatch.Draw(Main.notverymagicpixel, titleBarRectangle, null, UIStyleUnification.titlebarColor, 0f, Vector2.Zero, SpriteEffects.None, layer + 0.001f);
                //draw an outline for it
                spriteBatch.Draw(Main.notverymagicpixel, new Rectangle(titleBarRectangle.X - UIStyleUnification.windowBorder, titleBarRectangle.Y - UIStyleUnification.windowBorder, titleBarRectangle.Width + 2 * UIStyleUnification.windowBorder, titleBarRectangle.Height + 2 * UIStyleUnification.windowBorder), null, borderColor, 0, Vector2.Zero, SpriteEffects.None, layer + 0.002f);

                //titlebar is required to have buttons.

                //down tick
                if ((windowButtons & (uint)windowTopButtons.tickDown) == (uint)windowTopButtons.tickDown)
                {
                    spriteBatch.Draw(tickDownBack, tickDownLocation, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer + .0003f);
                    spriteBatch.Draw(tickDownSymbol, tickDownLocation, null, Color.White, 0f, Vector2.Zero, 1f, tickedUp ? SpriteEffects.None : SpriteEffects.FlipVertically, layer + .0002f);
                    if (tickDownHovered)
                    {
                        spriteBatch.Draw(tickDownBorder, tickDownLocation, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer + .0001f);
                    }
                }

                //close to parent (minimise?)
                if ((windowButtons & (uint)windowTopButtons.removeToParent) == (uint)windowTopButtons.removeToParent)
                {
                    spriteBatch.Draw(removeToParent, removeToParentLocation, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer + 0.0001f);
                    if (removeToParentHovered)
                    {
                        spriteBatch.Draw(removeToParentBorder, removeToParentLocation, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer);
                    }
                }

                //close
                if ((windowButtons & (uint)windowTopButtons.close) == (uint)windowTopButtons.close)
                {
                    spriteBatch.Draw(close, closeLocation, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer + 0.0001f);
                    if (closeHovered)
                    {
                        spriteBatch.Draw(closeBorder, closeLocation, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, layer);
                    }
                }
            }
        }