Exemple #1
1
        public static void Draw(ISpriteBatch sb, Vector2 source, Vector2 dest, Color color)
        {
            var dist = Vector2.Distance(source, dest);
            var angle = GetAngle(source, dest);

            // Get the length of the segments
            var segLen = dist / 6;
            if (segLen < 5.0f)
                segLen = 5.0f;
            if (segLen > 25.0f)
                segLen = 25.0f;

            // Primary line
            var tailLen = dist - (segLen / 2);
            var pDest = source + (new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * tailLen);
            RenderLine.Draw(sb, source, pDest, color);

            // Arrow segment 1
            var ang1 = angle - MathHelper.PiOver4;
            var seg1 = dest - (new Vector2((float)Math.Cos(ang1), (float)Math.Sin(ang1)) * segLen);
            RenderLine.Draw(sb, dest, seg1, color);

            // Arrow segment 2
            var ang2 = angle + MathHelper.PiOver4;
            var seg2 = dest - (new Vector2((float)Math.Cos(ang2), (float)Math.Sin(ang2)) * segLen);
            RenderLine.Draw(sb, dest, seg2, color);

            // Arrow segment 3
            RenderLine.Draw(sb, seg1, seg2, color);
        }
Exemple #2
0
 public ComponentRenderer(ISpriteBatch spriteBatch)
 {
     _renderers = new Dictionary <Type, ISpriteRenderer>
     {
         [typeof(ImageSprite)] = new SpriteRenderer(spriteBatch), [typeof(TextSprite)] = new TextRenderer(spriteBatch)
     };
 }
Exemple #3
0
 public LevelView(ILevel level, ISpriteBatch spriteBatch, ITexture texture, ICamera camera)
 {
     _level = level;
     _spriteBatch = spriteBatch;
     _texture = texture;
     _camera = camera;
 }
Exemple #4
0
 /// <summary>
 /// Draws the item that this <see cref="IDragDropProvider"/> contains for when this item
 /// is being dragged.
 /// </summary>
 /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to use to draw.</param>
 /// <param name="position">The position to draw the sprite at.</param>
 /// <param name="color">The color to use when drawing the item.</param>
 void IDragDropProvider.DrawDraggedItem(ISpriteBatch spriteBatch, Vector2 position, Color color)
 {
     if (Sprite != null)
     {
         Sprite.Draw(spriteBatch, position, color);
     }
 }
 public void SetUp()
 {
     stubSpriteBatch = MockRepository.GenerateStub<ISpriteBatch>();
     stubFont = MockRepository.GenerateStub<IFont>();
     stubConsole = MockRepository.GenerateStub<IConsole<string>>();
     stubConsole.Log = log;
 }
Exemple #6
0
        /// <summary>
        /// Makes the object draw itself.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> the object can use to draw itself with.</param>
        public void Draw(ISpriteBatch sb)
        {
            if (BeforeDraw != null)
            {
                BeforeDraw.Raise(this, EventArgsHelper.Create(sb));
            }

            var drawPos = DrawPosition;

            _lastScreenPosition = drawPos - Parent.Camera.Min;

            if (IsVisible && !Invisible)
            {
                // Draw the character body
                _characterSprite.Draw(sb, drawPos, Heading, Color);

                // Draw the HP/MP
                DrawSPBar(sb, HPPercent, 0, new Color(255, 0, 0, 175));
                DrawSPBar(sb, MPPercent, 1, new Color(0, 0, 255, 175));

                // Draw the name
                DrawName(sb, NameFont);
            }

            if (AfterDraw != null)
            {
                AfterDraw.Raise(this, EventArgsHelper.Create(sb));
            }
        }
        /// <summary>
        /// Draws the <see cref="SkeletonBodyItem"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Position to draw at.</param>
        /// <param name="scale">Amount to scale the Grh in percent (1.0f for no scaling).</param>
        /// <param name="color">The color.</param>
        /// <param name="effect">SpriteEffects to use when drawing.</param>
        internal void Draw(ISpriteBatch sb, Vector2 position, float scale, Color color, SpriteEffects effect)
        {
            // Validate
            if (Source == null)
                return;

            // Find the effect
            Vector2 m;
            switch (effect)
            {
                case SpriteEffects.FlipHorizontally:
                    m = new Vector2(-1, 1);
                    break;

                case SpriteEffects.FlipVertically:
                    m = new Vector2(1, -1);
                    break;

                default:
                    m = new Vector2(1, 1);
                    break;
            }

            // Calculate the angle
            float angle;
            if (Dest == null)
                angle = 0.0f;
            else
                angle = SkeletonNode.GetAngle(Source.Position * m, Dest.Position * m) - MathHelper.PiOver2;

            // Draw
            var v = Source.Position + ItemInfo.Offset;
            Grh.Draw(sb, (v * m) + position, color, effect, angle, ItemInfo.Origin, scale);
        }
Exemple #8
0
        /// <summary>
        /// When overridden in the derived class, handles performing drawing before the GUI for a <see cref="IDrawableMap"/> has been draw.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to use to draw.</param>
        /// <param name="imap">The <see cref="IDrawableMap"/> being drawn.</param>
        protected override void HandleBeforeDrawMapGUI(ISpriteBatch spriteBatch, IDrawableMap imap)
        {
            base.HandleBeforeDrawMapGUI(spriteBatch, imap);

            if (!IsEnabled)
            {
                return;
            }

            if (IsSelecting)
            {
                return;
            }

            if ((Control.ModifierKeys & _placeLightKey) != 0)
            {
                if (imap == _mouseOverMap)
                {
                    var lightSprite = SystemSprites.Lightblub;
                    var pos         = _mousePos - (lightSprite.Size / 2f);
                    pos = GridAligner.Instance.Align(pos);
                    lightSprite.Draw(spriteBatch, pos);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Draws the <see cref="IRefractionEffect"/>.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw with.</param>
        public void Draw(ISpriteBatch spriteBatch)
        {
            if (IsExpired || !IsEnabled)
            {
                return;
            }

            SetShaderParameters(TickCount.Now);

            // Draw
            var dest = ToRectangle();

            var oldBlendMode = spriteBatch.BlendMode;

            try
            {
                spriteBatch.BlendMode = BlendMode.None;
                try
                {
                    Shader.Bind();

                    WaveNoise.Draw(spriteBatch, dest);
                }
                finally
                {
                    Shader.Unbind();
                }
            }
            finally
            {
                spriteBatch.BlendMode = oldBlendMode;
            }
        }
 public void Draw(ISpriteBatch spriteBatch)
 {
     for (int i = 0; i < _particleSystems.Count; i++)
     {
         _particleSystems[i].Draw(spriteBatch);
     }
 }
Exemple #11
0
        /// <summary>
        /// Checks if this <see cref="Sprite"/> can be drawn with the given <see cref="ISpriteBatch"/>.
        /// </summary>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param>
        /// <returns>True if this <see cref="Sprite"/> can be drawn; otherwise false.</returns>
        bool CanDraw(ISpriteBatch sb)
        {
            // Invalid SpriteBatch
            if (sb == null)
            {
                const string errmsg = "Failed to render Sprite `{0}` - SpriteBatch is null!";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg, this);
                }
                return(false);
            }

            if (sb.IsDisposed)
            {
                const string errmsg = "Failed to render Sprite `{0}` - SpriteBatch is disposed!";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg, this);
                }
                return(false);
            }

            return(true);
        }
Exemple #12
0
        /// <summary>
        /// Draw the Button.
        /// </summary>
        /// <param name="spriteBatch"><see cref="ISpriteBatch"/> to draw to.</param>
        protected override void DrawControl(ISpriteBatch spriteBatch)
        {
            base.DrawControl(spriteBatch);

            // Draw the text
            DrawText(spriteBatch, _textPos);
        }
        /// <summary>
        /// Draws the <see cref="Control"/>.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param>
        protected override void DrawControl(ISpriteBatch spriteBatch)
        {
            base.DrawControl(spriteBatch);

            // Check for a valid sprite
            if (Sprite == null || Sprite.Texture == null)
            {
                return;
            }

            // Update the sprite before drawing it
            Sprite.Update(TickCount.Now);

            var sp  = ScreenPosition;
            var min = sp + new Vector2(Border.LeftWidth, Border.TopHeight);

            // Draw the picture
            if (StretchSprite)
            {
                // Stretched draw
                var drawSize = ClientSize;
                var dest     = new Rectangle((int)min.X, (int)min.Y, (int)drawSize.X, (int)drawSize.Y);
                _sprite.Draw(spriteBatch, dest, Color.White);
            }
            else
            {
                // Non-stretched draw
                _sprite.Draw(spriteBatch, min, Color.White);
            }
        }
Exemple #14
0
        /// <summary>
        /// Draws the InfoBox.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw with.</param>
        public void Draw(ISpriteBatch sb)
        {
            ThreadAsserts.IsMainThread();

            // Remove dead items
            while (_items.Count > 0 && _items[0].CreatedTime + _messageLife < TickCount.Now)
            {
                _items.RemoveAt(0);
            }

            // Loop through all items
            var i = 0;

            foreach (var item in _items)
            {
                // Set the position
                var pos = _position;
                pos.Y -= _font.GetLineSpacing() * (i++ + 1);
                pos.X -= item.Width;

                // Set the color
                var lifeLeft = (item.CreatedTime + _messageLife) - TickCount.Now;
                var alpha    = (byte)Math.Min(255, lifeLeft);
                var color    = new Color(item.Color.R, item.Color.G, item.Color.B, alpha);

                // Draw
                sb.DrawString(_font, item.Message, pos, color);
            }
        }
        public static void Initialize()
        {
            // Set up the graphics system
            _graphics = new GraphicsContext ();

            _texture = new Texture2D("/Application/32.png", false);

            _spriteBatch = new MonoGameSpriteBatch(_graphics, 256);
            //_spriteBatch = new MonoGameSpriteBatchNoIndex(_graphics, 256);
            //_spriteBatch = new MonoGameSpriteBatchVector3(_graphics, 256);
            //_spriteBatch = new MonoGameSpriteBatchUnpacked(_graphics, 256);

            //_spriteBatch = new DoubleBufferedSpriteBatch(new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256));
            //_spriteBatch = new TripleBufferedSpriteBatch(new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256));

            //_spriteBatch = new DoubleBufferedSpriteBatch(
            //	new DoubleBufferedSpriteBatch(new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256)),
            //	new DoubleBufferedSpriteBatch(new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256)));

            //_spriteBatch = new TripleBufferedSpriteBatch(
            //	new TripleBufferedSpriteBatch(new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256)),
            //	new TripleBufferedSpriteBatch(new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256)),
            //	new TripleBufferedSpriteBatch(new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256), new MonoGameSpriteBatch(_graphics, 256)));

            //_spriteBatch2 = new MonoGameSpriteBatch(_graphics, 256);
        }
 /// <summary>
 /// Handles drawing the GUI for the map.
 /// </summary>
 /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param>
 protected virtual void DrawGUI(ISpriteBatch sb)
 {
     if (DesignMode)
     {
         return;
     }
 }
Exemple #17
0
        /// <summary>
        /// Draws the <see cref="IRefractionEffect"/>.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw with.</param>
        public virtual void Draw(ISpriteBatch spriteBatch)
        {
            if (IsExpired || !IsEnabled)
            {
                return;
            }

            // Update the effect's parameters
            SetShaderParameters(_lastUpdateTime);

            // Draw
            var dest = ToRectangle();

            var oldBlendMode = spriteBatch.BlendMode;

            try
            {
                spriteBatch.BlendMode = BlendMode.Add;
                Shader.Bind();
                ExplosionNoise.Draw(spriteBatch, dest);
            }
            finally
            {
                spriteBatch.BlendMode = oldBlendMode;
            }
        }
Exemple #18
0
        /// <summary>
        /// Recursively draws the joints and bones of a skeleton.
        /// </summary>
        /// <param name="camera">Camera to use.</param>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="selectedNode">SpriteBatch to draw to.</param>
        /// <param name="node">Current node being drawn.</param>
        /// <param name="colorIndex">Index of the color to use from the ColorList.</param>
        static void RecursiveDraw(ICamera2D camera, ISpriteBatch sb, SkeletonNode selectedNode, SkeletonNode node, int colorIndex)
        {
            // Find the color of the joint
            var color = _colorList[colorIndex];
            if (node == selectedNode)
                color = _nodeColorSelected;
            else if (node.Parent == null)
                color = _nodeColorRoot;

            // Draw the joint
            var scale = 1f / camera.Scale;
            var origin = SkeletonNode.HalfJointVector;
            _joint.Draw(sb, node.Position, color, SpriteEffects.None, 0f, origin, scale);

            // Iterate through the children
            foreach (var child in node.Nodes)
            {
                colorIndex++;
                if (colorIndex == _colorList.Length)
                    colorIndex = 0;

                // Draw the bone to the child
                RenderLine.Draw(sb, node.Position, child.Position, _colorList[colorIndex], (1f / camera.Scale) * 2f);

                // Draw the child
                RecursiveDraw(camera, sb, selectedNode, child, colorIndex);
            }
        }
Exemple #19
0
        public static void DrawSpawn(MapSpawnValues spawn, ISpriteBatch spriteBatch, IDrawableMap map, Font font)
        {
            var spawnArea = spawn.SpawnArea;

            // Only draw if it does not cover the whole map
            if (!spawnArea.X.HasValue && !spawnArea.Y.HasValue && !spawnArea.Width.HasValue && !spawnArea.Height.HasValue)
                return;

            // Draw spawn area
            Vector2 cameraOffset = map.Camera.Min;
            Rectangle rect = spawnArea.ToRectangle(map);
            rect.X -= (int)cameraOffset.X;
            rect.Y -= (int)cameraOffset.Y;
            RenderRectangle.Draw(spriteBatch, rect, new Color(0, 255, 0, 75), new Color(0, 0, 0, 125), 2);

            // Draw name
            CharacterTemplate charTemp = CharacterTemplateManager.Instance[spawn.CharacterTemplateID];
            if (charTemp != null)
            {
                string text = string.Format("{0}x {1} [{2}]", spawn.SpawnAmount, charTemp.TemplateTable.Name, spawn.CharacterTemplateID);

                Vector2 textPos = new Vector2(rect.X, rect.Y);
                textPos -= new Vector2(0, font.MeasureString(text).Y);
                textPos = textPos.Round();

                spriteBatch.DrawStringShaded(font, text, textPos, Color.White, Color.Black);
            }
        }
Exemple #20
0
        void QuestDescriptionDrawer(ISpriteBatch sb, Vector2 pos, IQuestDescription item, int index)
        {
            if (item == null)
            {
                return;
            }

            // Write the list index
            var indexStr      = "  " + (index + 1) + ". ";
            var indexStrWidth = Font.MeasureString(indexStr).X;

            sb.DrawString(Font, indexStr, pos, ForeColor);

            // Get the color to use for the title
            var titleColor = ForeColor;

            // Draw the quest's title, prefixing a DONE tag if its ready to turn in
            var title = item.Name;

            if (HasFinishQuestReqs(item.QuestID))
            {
                titleColor = CanTurnInQuestForeColor;
                title      = "[DONE] " + title;
            }
            sb.DrawString(Font, title, pos + new Vector2(indexStrWidth + 10, 0), titleColor);
        }
Exemple #21
0
 /// <summary>
 /// Draws the <see cref="TransBoxManager"/> and all transformation boxes in it.
 /// </summary>
 /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to use to draw.</param>
 /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param>
 public void Draw(ISpriteBatch spriteBatch, ICamera2D camera)
 {
     foreach (var tb in _transBoxes)
     {
         tb.Draw(spriteBatch, camera);
     }
 }
Exemple #22
0
        internal InfoBar(ISpriteBatch spriteBatch, ISpriteFont spriteFont)
        {
            _spriteBatch = spriteBatch;
            _spriteFont = spriteFont;

            FontColor = Color.LightBlue;
        }
Exemple #23
0
        /// <summary>
        /// Draw sprites in this frame.
        /// </summary>
        /// <param name="batch">SpriteBatch to draw with</param>
        /// <param name="frame">Frame to draw</param>
        /// <param name="position">World position of frame</param>
        public static void Draw(ISpriteBatch batch, Frame frame, Vector2 position, params Frame[] extraFrames)
        {
            var spriteRefs = new List <SpriteRef>(frame.SpriteRefs);

            foreach (var extraFrame in extraFrames)
            {
                foreach (var sprRef in extraFrame.SpriteRefs)
                {
                    if (sprRef.Z < 0)
                    {
                        spriteRefs.Add(sprRef);
                    }
                    else if (sprRef.Z >= spriteRefs.Count)
                    {
                        spriteRefs.Insert(0, sprRef);
                    }
                    else
                    {
                        spriteRefs.Insert(spriteRefs.Count - sprRef.Z, sprRef);
                    }
                }
            }

            foreach (var spriteRef in spriteRefs)
            {
                Vector2 spritePos = position;
                spritePos.X += spriteRef.X;
                spritePos.Y += spriteRef.Y;

                batch.Draw(spriteRef.Sprite.Texture, spritePos, spriteRef.Sprite.Source, Color.White, spriteRef.Rotation, spriteRef.Sprite.Origin, 1, spriteRef.SpriteEffects, 0);
            }
        }
Exemple #24
0
        /// <summary>
        /// Draws the text insertion cursor.
        /// </summary>
        /// <param name="sb">The <see cref="SpriteBatch"/> to draw to.</param>
        /// <param name="textPos">The screen position to start drawing the text at.</param>
        void DrawCursor(ISpriteBatch sb, Vector2 textPos)
        {
            if (!HasFocus || !IsEnabled)
            {
                return;
            }

            if (_cursorBlinkTimer + EditableTextHandler.CursorBlinkRate < _currentTime)
            {
                return;
            }

            var offset = 0;

            if (CursorLinePosition > 0)
            {
                var len = Math.Min(CursorLinePosition, _lines.CurrentLine.LineText.Length);
                offset =
                    GetTextCursorOffset(_lines.CurrentLine.LineText.Substring(LineCharBufferOffset, len - LineCharBufferOffset));
            }

            var visibleLineOffset = (_lines.CurrentLineIndex - LineBufferOffset) * Font.GetLineSpacing();

            var p1 = textPos + new Vector2(offset, visibleLineOffset);
            var p2 = p1 + new Vector2(0, Font.GetLineSpacing());

            RenderLine.Draw(sb, p1, p2, Color.Black);
        }
Exemple #25
0
        /// <summary>
        /// Draws the <see cref="ControlBorder"/> to a given <see cref="Control"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw with.</param>
        /// <param name="c">Control to draw to.</param>
        public void Draw(ISpriteBatch sb, Control c)
        {
            if (!_canDraw)
            {
                return;
            }

            var color = c.BorderColor;

            // Apply the color transformations (if they exist)
            if (_globalColorTransformations.Count > 0)
            {
                lock (_globalColorTransformationsSync)
                {
                    foreach (var t in _globalColorTransformations)
                    {
                        color = t(c, color);
                    }
                }
            }

            Vector2   sp     = c.ScreenPosition;
            Rectangle region = new Rectangle(sp.X, sp.Y, c.Size.X, c.Size.Y);

            Draw(sb, region, color);
        }
Exemple #26
0
        /// <summary>
        /// Draws the <see cref="ParticleEmitter"/>.
        /// </summary>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param>
        internal void Draw(ISpriteBatch sb)
        {
            // Check if we can even draw anything
            if (Sprite == null || ActiveParticles <= 0)
            {
                return;
            }

            // Keep track of what the blend mode was originally so we can restore it when done
            var originalBlendMode = sb.BlendMode;

            // Set the blend mode
            sb.BlendMode = BlendMode;

            // Get the origin to use for the particles
            var origin = Sprite.Size / 2f;

            // Draw the live particles
            for (var i = 0; i < ActiveParticles; i++)
            {
                var p = _particles[i];
                Sprite.Draw(sb, Owner.Position + p.Position, p.Color, SpriteEffects.None, p.Rotation, origin, p.Scale);
            }

            // Restore the blend mode
            sb.BlendMode = originalBlendMode;
        }
 public Camera(ISpriteBatch spriteBatch)
 {
     if (spriteBatch == null)
         throw new ArgumentNullException("spriteBatch");
     _spriteBatch = spriteBatch;
     _boundingRectangle = new Rectangle(0, 0, 1024, 640);
 }
Exemple #28
0
        /// <summary>
        /// Draws a <see cref="Skeleton"/>.
        /// </summary>
        /// <param name="skeleton">The <see cref="Skeleton"/> to draw.</param>
        /// <param name="camera">Camera to use.</param>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to draw with.</param>
        /// <param name="selectedNode">The <see cref="SkeletonNode"/> to draw as selected.</param>
        public static void Draw(Skeleton skeleton, ICamera2D camera, ISpriteBatch sb, SkeletonNode selectedNode = null)
        {
            if (skeleton == null)
            {
                Debug.Fail("skeleton is null.");
                return;
            }
            if (skeleton.RootNode == null)
            {
                Debug.Fail("skeleton contains no root node.");
                return;
            }
            if (sb == null)
            {
                Debug.Fail("sb is null.");
                return;
            }
            if (sb.IsDisposed)
            {
                Debug.Fail("sb is disposed.");
                return;
            }
            if (camera == null)
            {
                Debug.Fail("camera is null.");
                return;
            }

            RecursiveDraw(camera, sb, selectedNode, skeleton.RootNode, 0);
        }
Exemple #29
0
                /// <summary>
                /// Draws the item in this slot. This method is always called, even when the slot is empty.
                /// </summary>
                /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param>
                /// <param name="itemSprite">The <see cref="Grh"/> to draw. Will never be null, but can contain
                /// an invalid or empty sprite.</param>
                protected virtual void DrawItem(ISpriteBatch spriteBatch, Grh itemSprite)
                {
                    if (itemSprite.GrhData == null)
                    {
                        return;
                    }

                    // Grab the screen position and client size
                    var sp = ScreenPosition;
                    var cs = ClientSize;

                    // Get the size to use for drawing (never exceeding the size of the control)
                    var drawSize = Vector2.Min(cs, itemSprite.Size);

                    // Get the draw position (centering on the control)
                    var drawPos = sp + ((cs - drawSize) / 2f);

                    // Draw
                    var spriteDestRect = new Rectangle(drawPos.X, drawPos.Y, drawSize.X, drawSize.Y);

                    _sprite.Draw(spriteBatch, spriteDestRect);

                    // Draw the amount
                    var itemInfo = GetSlotItemInfo();

                    if (itemInfo == null)
                    {
                        return;
                    }

                    var amount = ItemsCollection.PeerTradeForm.GetItemAmount(itemInfo);

                    DrawItemAmount(spriteBatch, amount);
                }
Exemple #30
0
        public void Begin(ISpriteBatch batch)
        {
            device.SetRenderTarget(target);
            device.Clear(screenConstants.BackgroundColor);

            batch.Begin();
        }
Exemple #31
0
        void DrawItems(ISpriteBatch spriteBatch)
        {
            if (Items == null)
            {
                return;
            }

            var pos    = ScreenPosition + new Vector2(Border.LeftWidth, Border.TopHeight);
            var ipp    = ItemsPerPage;
            var offset = (CurrentPage - 1) * ipp;
            var ih     = ItemHeight;
            var count  = Items.Count();

            var selIndex = SelectedIndex;

            for (var i = offset; i < offset + ipp && i < count; i++)
            {
                if (selIndex == i)
                {
                    DrawSelectionRegion(spriteBatch, new Rectangle((int)pos.X, (int)pos.Y, (int)ClientSize.X, ItemHeight));
                }

                ItemDrawer(spriteBatch, pos, i);

                pos += new Vector2(0, ih);
            }
        }
Exemple #32
0
 /// <summary>
 /// Draws the <see cref="StyledText"/>s in this <see cref="StyledTextsDrawer"/>.
 /// </summary>
 /// <param name="sb">The <see cref="ISpriteBatch"/>.</param>
 /// <param name="defaultColor">The default color.</param>
 /// <param name="offset">The offset to start drawing the text at.</param>
 public void Draw(ISpriteBatch sb, Color defaultColor, Vector2 offset)
 {
     foreach (var item in _textsWithPos)
     {
         item.StyledText.Draw(sb, Font, offset + item.Position, defaultColor);
     }
 }
        /// <summary>Render this AParentSceneNode by rendering all its children.</summary>
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform, 
            int depth)
        {
            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            if (view == HolofunkView.Secondary && SecondaryViewOption == SecondaryViewOption.PositionMirrored) {
                combinedTransform = new Transform(
                    new Vector2(
                        spriteBatch.Viewport.X - combinedTransform.Translation.X,
                        combinedTransform.Translation.Y),
                    combinedTransform.Scale);
            }

            Spam.Graphics.WriteLine(new string(' ', depth * 4) + Label + ": parentTransform " + parentTransform + ", localTransform " + LocalTransform + ", combinedTransform " + combinedTransform);

            // m_children must only be enumerated / mutated under lock (this)
            lock (this) {
                m_childSnapshot.AddRange(m_children);
            }

            for (int i = 0; i < m_childSnapshot.Count; i++) {
                m_childSnapshot[i].Render(now, graphicsDevice, spriteBatch, content, view, combinedTransform, depth + 1);
            }

            // note that clearing preserves the capacity in the list, so no reallocation on next render
            m_childSnapshot.Clear();
        }
Exemple #34
0
        /// <summary>
        /// Draw the Button.
        /// </summary>
        /// <param name="spriteBatch"><see cref="ISpriteBatch"/> to draw to.</param>
        protected override void DrawControl(ISpriteBatch spriteBatch)
        {
            base.DrawControl(spriteBatch);

            // Draw the text
            DrawText(spriteBatch, _textPos);
        }
        public void Draw(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary)
        {
            if (!this._gameObject.IsExtant)
            {
                return;
            }

            this._time %= this._lengthOfAnimation;
            var positionInAnimation = this._time / this._lengthOfAnimation;

            DrawParameters drawParameters = default;

            drawParameters.Texture = spriteLibrary.GetSprite(this._textureName);
            var frameCount = (drawParameters.Texture.Width / Constants.TileLength);
            int frameIndex = (int)Math.Floor(frameCount * positionInAnimation);

            // Calculate the source rectangle of the current frame.
            drawParameters.AreaWithinTexture = new Rectangle(frameIndex * Constants.TileLength, 0, Constants.TileLength, Constants.TileLength);
            drawParameters.Position          = this._gameObject.Position;
            drawParameters.Rotation          = this.Rotation;
            drawParameters.Effects           = this.SpriteEffect;
            drawParameters.Opacity           = this.Opacity;

            // Draw the current frame.
            spriteBatch.DrawTexture(drawParameters);
        }
Exemple #36
0
        private void DrawName(ISpriteBatch spriteBatch)
        {
            Vector2 measure = Font.MeasureString(Score.Name);
            Vector2 origin = new Vector2(0, measure.Y * 0.5f);

            spriteBatch.DrawString(Font, Score.Name, NamePosition.WorldPosition, Color.White, WorldRotation, origin, WorldScale, SpriteEffects.None, 0);
        }
Exemple #37
0
        public static void DrawSpawn(MapSpawnValues spawn, ISpriteBatch spriteBatch, IDrawableMap map, Font font)
        {
            var spawnArea = spawn.SpawnArea;

            // Only draw if it does not cover the whole map
            if (!spawnArea.X.HasValue && !spawnArea.Y.HasValue && !spawnArea.Width.HasValue && !spawnArea.Height.HasValue)
            {
                return;
            }

            // Draw spawn area
            Vector2   cameraOffset = map.Camera.Min;
            Rectangle rect         = spawnArea.ToRectangle(map);

            rect.X -= (int)cameraOffset.X;
            rect.Y -= (int)cameraOffset.Y;
            RenderRectangle.Draw(spriteBatch, rect, new Color(0, 255, 0, 75), new Color(0, 0, 0, 125), 2);

            // Draw name
            CharacterTemplate charTemp;

            if (CharacterTemplateManager.Instance.TryGetValue(spawn.CharacterTemplateID, out charTemp))
            {
                string text = string.Format("{0}x {1} [{2}]", spawn.SpawnAmount, charTemp.TemplateTable.Name, spawn.CharacterTemplateID);

                Vector2 textPos = new Vector2(rect.X, rect.Y);
                textPos -= new Vector2(0, font.MeasureString(text).Y);
                textPos  = textPos.Round();

                spriteBatch.DrawStringShaded(font, text, textPos, Color.White, Color.Black);
            }
        }
        /// <summary>
        /// Makes the object draw itself.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> the object can use to draw itself with.</param>
        public void Draw(ISpriteBatch sb)
        {
            if (!IsAlive)
                return;

            _particleEffect.Draw(sb);
        }
Exemple #39
0
        /// <summary>
        /// When overridden in the derived class, handles performing drawing after the GUI for a <see cref="IDrawableMap"/> has been draw.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to use to draw.</param>
        /// <param name="map">The <see cref="IDrawableMap"/> being drawn.</param>
        protected override void HandleAfterDrawMapGUI(ISpriteBatch spriteBatch, IDrawableMap map)
        {
            base.HandleAfterDrawMapGUI(spriteBatch, map);

            if (!IsEnabled)
            {
                return;
            }

            if (map != _mouseOverMap)
            {
                return;
            }

            var grh      = GlobalState.Instance.Map.GrhToPlace;
            var worldPos = map.Camera.ToWorld(_mousePos);
            var drawPos  = worldPos - map.Camera.Min;

            if (!Input.IsCtrlDown)
            {
                drawPos = GridAligner.Instance.Align(drawPos, true).Round();
            }

            if (Input.IsShiftDown)
            {
                // Display tooltip of what would be selected
                var grhToSelect = MapGrhPencilTool.GetGrhToSelect(map, worldPos);
                MapGrhPencilTool.DrawMapGrhTooltip(spriteBatch, map, grhToSelect, worldPos);
            }
            else
            {
                grh.Update(map.GetTime());
                grh.Draw(spriteBatch, drawPos, new Color(255, 255, 255, 180));
            }
        }
Exemple #40
0
        /// <summary>
        /// Makes the object draw itself.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> the object can use to draw itself with.</param>
        public void Draw(ISpriteBatch sb)
        {
            // Ensure the sprite is set
            if (!IsSpriteSet())
            {
                return;
            }

            // Pre-drawing
            if (BeforeDraw != null)
            {
                BeforeDraw.Raise(this, EventArgsHelper.Create(sb));
            }

            // Draw
            if (IsVisible)
            {
                HandleDraw(sb);
            }

            // Post-drawing
            if (AfterDraw != null)
            {
                AfterDraw.Raise(this, EventArgsHelper.Create(sb));
            }
        }
Exemple #41
0
 /// <summary>
 /// Draws the <see cref="SkeletonBody"/>.
 /// </summary>
 /// <param name="sb"><see cref="ISpriteBatch"/> to draw with.</param>
 /// <param name="position">Position to draw at.</param>
 /// <param name="color">The color.</param>
 /// <param name="scale">Scale in percent (1.0f for normal scale).</param>
 /// <param name="effect"><see cref="SpriteEffects"/> to use when drawing.</param>
 public void Draw(ISpriteBatch sb, Vector2 position, Color color, float scale, SpriteEffects effect)
 {
     foreach (var bodyItem in BodyItems)
     {
         bodyItem.Draw(sb, position, scale, color, effect);
     }
 }
Exemple #42
0
        private void DrawPausedMessage(ISpriteBatch spriteBatch)
        {
            this._green = (this._green + 1) % 512;
            var          greenComponent = Math.Abs(255 - this._green);
            const string paused         = "-> P A U S E D <-";

            spriteBatch.DrawCentredString(this._statusFont, paused, 100, new Color(0, greenComponent, 0));
        }
 public ConsoleOverlaySetView(IOverlayView inputView, IOverlayView commandConsoleView, IOverlayView messageConsoleView, IOverlayView possibleCommandsView, ISpriteBatch spriteBatch, ITexture texture, IFont font)
     : base(spriteBatch, texture, font)
 {
     _overlays.Add(inputView);
     _overlays.Add(commandConsoleView);
     _overlays.Add(messageConsoleView);
     _overlays.Add(possibleCommandsView);
 }
        /// <summary>
        /// Draws the Control.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param>
        protected override void DrawControl(ISpriteBatch spriteBatch)
        {
            // Check if we need to update the size of the items list
            if (_lstQuests.Items.Count() != _lastItemsListSize)
                RepositionChildren();

            base.DrawControl(spriteBatch);
        }
            /// <summary>
            /// Draws the <see cref="ITransBox"/>.
            /// </summary>
            /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param>
            /// <param name="camera">The <see cref="ICamera2D"/>.</param>
            public void Draw(ISpriteBatch spriteBatch, ICamera2D camera)
            {
                var p = camera.ToScreen(Position).Round();
                var s = Size.Round();
                var r = new Rectangle((int)p.X, (int)p.Y, (int)s.X, (int)s.Y);

                SystemSprites.Move.Draw(spriteBatch, r, Color.White);
            }
Exemple #46
0
        public void Render(Moment now, GraphicsDevice graphicsDevice, ISpriteBatch spriteBatch, TextureContent content, HolofunkView view)
        {
            if (RootNode != null) {
                RootNode.Render(now, graphicsDevice, spriteBatch, content, view, Transform.Identity, 0);
            }

            Spam.Graphics.WriteLine("End Render");
        }
Exemple #47
0
 public void Render(Primitive primitive, SpriteBatch spriteBatch)
 {
     if (this.spriteBatch == null)
     {
         this.spriteBatch = new SpriteBatchWrapper(spriteBatch);
     }
     Render(primitive);
 }
        /// <summary>
        /// Handles drawing the GUI for the map.
        /// </summary>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param>
        protected virtual void DrawMapGUI(ISpriteBatch sb)
        {
            ToolManager.Instance.InvokeBeforeDrawMapGUI(sb, Map);

            TransBoxManager.Draw(sb, Camera);

            ToolManager.Instance.InvokeAfterDrawMapGUI(sb, Map);
        }
Exemple #49
0
 public void Render(Primitive primitive, SpriteBatch spriteBatch)
 {
     if (this.spriteBatch == null)
     {
         this.spriteBatch = new SpriteBatchWrapper(spriteBatch);
     }
     Render(primitive);
 }
            /// <summary>
            /// Draws the <see cref="ITransBox"/>.
            /// </summary>
            /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param>
            /// <param name="camera">The <see cref="ICamera2D"/>.</param>
            public void Draw(ISpriteBatch spriteBatch, ICamera2D camera)
            {
                Vector2   p = camera.ToScreen(Position).Round();
                Vector2   s = Size.Round();
                Rectangle r = new Rectangle(p.X, p.Y, s.X, s.Y);

                SystemSprites.Move.Draw(spriteBatch, r, Color.White);
            }
Exemple #51
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="dest">Destination rectangle.</param>
        /// <param name="color">Color of the rectangle.</param>
        public static void Draw(ISpriteBatch sb, Rectangle dest, Color color)
        {
            var fDest = new FloatRect(dest.Left, dest.Top, dest.Width, dest.Height);

            using (var s = Shape.Rectangle(fDest, color))
            {
                sb.Draw(s);
            }
        }
Exemple #52
0
        public virtual void Draw(ISpriteBatch spriteBatch)
        {
            string scoreString = DisplayScore.ToString();

            Vector2 measure = Font.MeasureString(scoreString);
            Vector2 origin = new Vector2(measure.X, measure.Y * 0.5f);

            spriteBatch.DrawString(Font, scoreString, ScorePosition.WorldPosition, Color.White, WorldRotation, origin, WorldScale, SpriteEffects.None, 0);
        }
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Top-left corner position.</param>
        /// <param name="size">The size of the rectangle.</param>
        /// <param name="color">Color of the rectangle.</param>
        public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color)
        {
            var drawRect = _drawRectBorder;

            drawRect.Size = size;
            drawRect.Position = position;
            drawRect.FillColor = color;

            sb.Draw(drawRect);
        }
        /// <summary>
        /// Draws the <see cref="ICharacterSprite"/>.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw with.</param>
        /// <param name="position">The position to draw the sprite.</param>
        /// <param name="heading">The character's heading.</param>
        /// <param name="color">The color of the sprite.</param>
        public void Draw(ISpriteBatch spriteBatch, Vector2 position, Direction heading, Color color)
        {
            if (_skelAnim == null)
                return;

            var se = (heading == Direction.East ? SpriteEffects.None : SpriteEffects.FlipHorizontally);
            var p = position + new Vector2(_bodySize.X / 2f, _bodySize.Y);

            _skelAnim.Draw(spriteBatch, p, color, se);
        }
 public void SetUp()
 {
     stubInputView = MockRepository.GenerateStub<IOverlayView>();
     stubCommandConsoleView = MockRepository.GenerateStub<IOverlayView>();
     stubMessageConsoleView = MockRepository.GenerateStub<IOverlayView>();
     stubPossibleCommandsView = MockRepository.GenerateStub<IOverlayView>();
     stubSpriteBatch = MockRepository.GenerateStub<ISpriteBatch>();
     stubTexture = MockRepository.GenerateStub<ITexture>();
     stubFont = MockRepository.GenerateStub<IFont>();
     hudView = new ConsoleOverlaySetView(stubInputView, stubCommandConsoleView, stubMessageConsoleView, stubPossibleCommandsView, stubSpriteBatch, stubTexture, stubFont);
 }
Exemple #56
0
 public void Render(Starbound.UI.Controls.Control control, SpriteBatch spriteBatch)
 {
     if (this.spriteBatch == null)
     {
         this.spriteBatch = new SpriteBatchWrapper(spriteBatch);
     }
     foreach (Primitive primitive in control.Template.Primitives)
     {
         Render(primitive);
     }
 }
        /// <summary>
        /// Handles drawing the map.
        /// </summary>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param>
        protected virtual void DrawWorld(ISpriteBatch sb)
        {
            if (DesignMode)
                return;

            var pe = ParticleEffect;
            if (pe == null)
                return;

            pe.Draw(sb);
        }
Exemple #58
0
        /// <summary>
        /// Draws the Control.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param>
        protected override void DrawControl(ISpriteBatch spriteBatch)
        {
            var iig = IsInGuild;
            if (iig != _lastIsInGuild)
            {
                UpdateGuildStatus();
                _lastIsInGuild = iig;
            }

            base.DrawControl(spriteBatch);
        }
        protected override void DrawControl(ISpriteBatch spriteBatch)
        {
            var currentTime = GetTime();

            var offset = new Vector2(-_iconSize.X, 0);

            foreach (var dase in _statusEffects.ActiveStatusEffects)
            {
                dase.Draw(spriteBatch, Position + offset, currentTime);
                offset += new Vector2(0, _iconSize.Y);
            }
        }
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Top-left corner position.</param>
        /// <param name="size">The size of the rectangle.</param>
        /// <param name="color">Color of the box.</param>
        /// <param name="borderColor">Color of the border to draw around the rectangle.</param>
        /// <param name="borderThickness">The thickness of the border in pixels. Default is 1.</param>
        public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color, Color borderColor, float borderThickness = 1f)
        {
            var drawRect = _drawRectNoBorder;

            drawRect.Size = size;
            drawRect.Position = position;
            drawRect.FillColor = color;
            drawRect.OutlineColor = borderColor;
            drawRect.OutlineThickness = borderThickness;

            sb.Draw(drawRect);
        }