예제 #1
0
        public override void Draw(GameTime time, SpriteBatch spriteBatch)
        {
            GraphicsDevice graphicsDevice = spriteBatch.GraphicsDevice;

            if (time.IsRunningSlowly)
            {
                graphicsDevice.Clear(Color.MistyRose);
            }
            else
            {
                graphicsDevice.Clear(Color.CornflowerBlue);
            }


            foreach (IRigidBody b in PE.ActiveBodies)
            {
                GraphicsUtils.DrawBall(b.Position, b.BoundingBox.Width / 2, Color.Black, 255);
            }

            foreach (IRigidBody b in PE.MapBodies)
            {
                if (b is IVertWallBody || b is IHorizWallBody)
                {
                    var bb = b.BoundingBox;
                    GraphicsUtils.DrawRectangle(bb.XMin, bb.XMax, bb.YMin, bb.YMax, Color.Black);
                }
            }

            drawTree <IRigidBody>(PE.QTbodies);
            // GraphicsUtils.End();
        }
예제 #2
0
파일: Sandbox2.cs 프로젝트: preetum/archive
        public override void Draw(GameTime time, SpriteBatch spriteBatch)
        {
            GraphicsDevice graphicsDevice = spriteBatch.GraphicsDevice;

            if (time.IsRunningSlowly)
            {
                graphicsDevice.Clear(Color.MistyRose);
            }
            else
            {
                graphicsDevice.Clear(Color.CornflowerBlue);
            }


            foreach (IRigidBody b in PE.ActiveBodies)
            {
                GraphicsUtils.DrawBall(b.Position, b.BoundingBox.Width / 2, Color.Black, 255);
            }

            foreach (IRigidBody b in PE.MapBodies)
            {
                if (b is IVertWallBody || b is IHorizWallBody)
                {
                    var bb = b.BoundingBox;
                    GraphicsUtils.DrawRectangle(bb.XMin, bb.XMax, bb.YMin, bb.YMax, Color.Black);
                }
            }

            foreach (var bff in PE.bffields)
            {
                var bb = bff.AreaInfluenced;
                GraphicsUtils.DrawRectangle(bb.XMin, bb.XMax, bb.YMin, bb.YMax, Color.FromNonPremultiplied(200, 100, 100, 50));
            }


            if (mactive)
            {
                GraphicsUtils.DrawRectangle(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), rad * 2, rad * 2, 0f, Color.FromNonPremultiplied(200, 100, 100, 150));
            }

            drawTree <IRigidBody>(PE.QTbodies);

            // GraphicsUtils.End();
        }
예제 #3
0
        public override void Draw(GameTime time, SpriteBatch spriteBatch)
        {
            GraphicsDevice graphicsDevice = spriteBatch.GraphicsDevice;

            graphicsDevice.Clear(Color.CornflowerBlue);

            foreach (var o in Objs)
            {
                Color c = o.Flagged ? Color.Red : Color.Black;
                GraphicsUtils.DrawRectangle(o.Span.XMin, o.Span.XMax, o.Span.YMin, o.Span.YMax, c);
            }

            drawTree(QT);


            if (qactive)
            {
                var qfix = query;
                qfix.FixBoundOrder(); //don't mess with query itself, since the interaction code will mess up.
                GraphicsUtils.DrawRectangleTop(qfix.XMin, qfix.XMax, qfix.YMin, qfix.YMax, Color.FromNonPremultiplied(255, 0, 0, 127));
            }
        }
예제 #4
0
        /// <summary>
        /// 创建消息窗图像,同时输出内容区,用于外部定位
        /// </summary>
        private static Bitmap CreateTipImage(string text, TipStyle style, out Rectangle contentBounds)
        {
            var size       = Size.Empty;
            var iconBounds = Rectangle.Empty;
            var textBounds = Rectangle.Empty;

            if (style.Icon != null)
            {
                size            = style.Icon.Size;
                iconBounds.Size = size;
                textBounds.X    = size.Width;
            }

            if (text.Length != 0)
            {
                if (style.Icon != null)
                {
                    size.Width   += style.IconSpacing;
                    textBounds.X += style.IconSpacing;
                }

                textBounds.Size = Size.Truncate(GraphicsUtils.MeasureString(text, style.TextFont ?? DefaultFont, 0, DefStringFormat));
                size.Width     += textBounds.Width;

                if (size.Height < textBounds.Height)
                {
                    size.Height = textBounds.Height;
                }
                else if (size.Height > textBounds.Height)//若文字没有图标高,令文字与图标垂直居中,否则与图标平齐
                {
                    textBounds.Y += (size.Height - textBounds.Height) / 2;
                }
                textBounds.Offset(style.TextOffset);
            }
            size += style.Padding.Size;
            iconBounds.Offset(style.Padding.Left, style.Padding.Top);
            textBounds.Offset(style.Padding.Left, style.Padding.Top);

            contentBounds = new Rectangle(Point.Empty, size);
            var fullBounds = GraphicsUtils.GetBounds(contentBounds, style.Border, style.ShadowRadius, style.ShadowOffset.X, style.ShadowOffset.Y);

            contentBounds.Offset(-fullBounds.X, -fullBounds.Y);
            iconBounds.Offset(-fullBounds.X, -fullBounds.Y);
            textBounds.Offset(-fullBounds.X, -fullBounds.Y);

            var bmp = new Bitmap(fullBounds.Width, fullBounds.Height);

            Graphics g         = null;
            Brush    backBrush = null;
            Brush    textBrush = null;

            try
            {
                g = Graphics.FromImage(bmp);
                g.SmoothingMode   = SmoothingMode.HighQuality;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;

                backBrush = (style.BackBrush ?? (r => new SolidBrush(style.BackColor)))(contentBounds);
                GraphicsUtils.DrawRectangle(g, contentBounds,
                                            backBrush,
                                            style.Border,
                                            style.CornerRadius,
                                            style.ShadowColor,
                                            style.ShadowRadius,
                                            style.ShadowOffset.X,
                                            style.ShadowOffset.Y);

                if (style.Icon != null)
                {
                    //DEBUG: g.DrawRectangle(new Border(Color.Red) { Width = 1, Direction = Direction.Inner }.Pen, iconBounds);
                    g.DrawImageUnscaled(style.Icon, iconBounds.Location);
                }
                if (text.Length != 0)
                {
                    textBrush = new SolidBrush(style.TextColor);
                    //DEBUG: g.DrawRectangle(new Border(Color.Red){ Width=1, Direction= Direction.Inner}.Pen, textBounds);
                    g.DrawString(text, style.TextFont ?? DefaultFont, textBrush, textBounds.Location, DefStringFormat);
                }

                g.Flush(FlushIntention.Sync);
                return(bmp);
            }
            finally
            {
                if (g != null)
                {
                    g.Dispose();
                }
                if (backBrush != null)
                {
                    backBrush.Dispose();
                }
                if (textBrush != null)
                {
                    textBrush.Dispose();
                }
            }
        }