/// <summary>
        /// 实现图形接口的绘图逻辑
        /// </summary>
        /// <param name="bitmap"></param>
        public void Draw(WriteableBitmap bitmap)
        {
            bitmap.Clear();
            for (int i = 0; i < _width; i++)
            {
                for (int j = 0; j < _height; j++)
                {
                    int x = _net[i, j].Position.X.ToDisplayUnits();
                    int y = _net[i, j].Position.Y.ToDisplayUnits();

                    // 绘制弹性连线
                    double dLeft;
                    double dDown;
                    if (i > 0 && (dLeft = (_net[i, j].Position - _net[i - 1, j].Position).Length()) / _gridSize < _factor)
                    {
                        byte colorRow = dLeft > _gridSize ? (byte)((int)(255 - (dLeft - _gridSize) / ((_factor - 1) * _gridSize) * 200)) : (byte)255;
                        bitmap.DrawLineAa(
                            x, y,
                            _net[i - 1, j].Position.X.ToDisplayUnits(), _net[i - 1, j].Position.Y.ToDisplayUnits(),
                            Color.FromArgb(colorRow, 0, 0, 0));
                    }
                    if (j > 0 && (dDown = (_net[i, j].Position - _net[i, j - 1].Position).Length()) / _gridSize < _factor)
                    {
                        byte colorCol = dDown > _gridSize ? (byte)((int)(255 - (dDown - _gridSize) / ((_factor - 1) * _gridSize) * 200)) : (byte)255;
                        bitmap.DrawLineAa(
                            x, y,
                            _net[i, j - 1].Position.X.ToDisplayUnits(), _net[i, j - 1].Position.Y.ToDisplayUnits(),
                            Color.FromArgb(colorCol, 0, 0, 0));
                    }
                    // 绘制点
                    bitmap.FillEllipseCentered(x, y, 2, 2, Colors.Black);
                }
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (Bitmap bmp1 = new Bitmap(400, 500))
                using (var bmplock = bmp1.Lock())
                {
                    WriteableBitmap wb = bmplock.GetWritableBitmap();
                    //lines

                    int y = 0;

                    wb.DrawLine(0, y, 100, y + 100, System.Windows.Media.Imaging.Color.FromArgb(255, 255, 0, 0));     //red
                    wb.DrawLine(0, y + 100, 100, y + 0, System.Windows.Media.Imaging.Color.FromArgb(255, 0, 0, 255)); //blue

                    wb.DrawLineAa(100, y, 200, y + 100, System.Windows.Media.Imaging.Color.FromArgb(255, 255, 0, 0));
                    wb.DrawLineAa(100, y + 100, 200, y + 0, System.Windows.Media.Imaging.Color.FromArgb(255, 0, 0, 255)); //blue


                    //----------
                    y += 150;
                    wb.DrawLineDDA(0, y, 100, y + 100, System.Windows.Media.Imaging.Color.FromArgb(255, 255, 0, 0));     //red
                    wb.DrawLineDDA(0, y + 100, 100, y + 0, System.Windows.Media.Imaging.Color.FromArgb(255, 0, 0, 255)); //blue


                    wb.DrawEllipse(200, 0, 300, 100, System.Windows.Media.Imaging.Color.FromArgb(255, 255, 0, 0));

                    //
                    bmplock.WriteAndUnlock();

                    bmp1.Save("d:\\WImageTest\\a0002.png");
                }
        }
示例#3
0
        public void DrawPathStartHorizontal(Room roomStart, Room roomFinish, bool start = true)
        {
            WriteableBitmap floorMap = start ? writeableBmpFloorStart : writeableBmpFloorFinish;

            int newY = 0;

            if (Math.Abs(roomFinish.Y - roomStart.Y) < 200 &&
                Math.Abs(roomFinish.X - roomStart.X) == 0)
            {
                return;
            }
            else if (roomStart.Y <= 208 && roomFinish.Y <= 208)
            {
                newY = 116;
            }
            else if (roomStart.Y > 208 && roomFinish.Y > 208)
            {
                newY = 306;
            }
            else if (roomStart.Y <= 208 && roomFinish.Y > 208)
            {
                newY = 306;
            }
            else if (roomStart.Y > 208 && roomFinish.Y <= 208)
            {
                newY = 116;
            }
            floorMap.DrawLineAa((int)roomStart.X, (int)roomStart.Y, (int)roomStart.X, newY, Color.FromArgb(255, 0, 0, 0), 5);
            floorMap.DrawLineAa((int)roomFinish.X, (int)roomFinish.Y, (int)roomFinish.X, newY, Color.FromArgb(255, 0, 0, 0), 5);
            roomStart.Y  = newY;
            roomFinish.Y = newY;
        }
示例#4
0
        private void DrawRect(WriteableBitmap bitmap, int top, int right, int bottom, int left, int stroke = 10)
        {
            left   = Math.Max(stroke, left);
            top    = Math.Max(stroke, top);
            right  = Math.Min(bitmap.PixelWidth - stroke, right);
            bottom = Math.Min(bitmap.PixelHeight - stroke, bottom);

            bitmap.DrawLineAa(left, top, right, top, Colors.Blue, stroke);
            bitmap.DrawLineAa(right, top, right, bottom, Colors.Blue, stroke);
            bitmap.DrawLineAa(left, bottom, right, bottom, Colors.Blue, stroke);
            bitmap.DrawLineAa(left, top, left, bottom, Colors.Blue, stroke);
        }
 public static void DrawRectanglesOnBitmap(WriteableBitmap bitmap, Rectangle[] rectangles)
 {
     foreach (var rect in rectangles)
     {
         var x1 = (int)((rect.X * (int)SCALE_FACTOR) * PIXEL_POINT_CONVERSION);
         var x2 = (int)(x1 + (((int)SCALE_FACTOR * rect.Width) * PIXEL_POINT_CONVERSION));
         var y1 = rect.Y * (int)SCALE_FACTOR;
         var y2 = y1 + ((int)SCALE_FACTOR * rect.Height);
         bitmap.DrawLineAa(x1, y1, x2, y1, strokeThickness: 5, color: Colors.Blue);
         bitmap.DrawLineAa(x1, y1, x1, y2, strokeThickness: 5, color: Colors.Blue);
         bitmap.DrawLineAa(x1, y2, x2, y2, strokeThickness: 5, color: Colors.Blue);
         bitmap.DrawLineAa(x2, y1, x2, y2, strokeThickness: 5, color: Colors.Blue);
     }
 }
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            if (Points.Count == 0 || writeableBitmap.PixelHeight < 2 || writeableBitmap.PixelWidth < 2)
            {
                return;
            }
            var prevX      = _points[0].X; //writeableBitmap.CheckX(GetClientX(_points[0].X));
            var prevY      = 0.0;          // writeableBitmap.CheckY(GetClientY(_points[0].Y));
            var prevModelY = 0.0;

            for (int i = 0; i < Points.Count; i++)
            {
                var x = Points[i].X;              //writeableBitmap.CheckX(GetClientX(Points[i].X));
                var y = Points[i].Y + prevModelY; //writeableBitmap.CheckY(GetClientY(Points[i].Y + prevModelY)) ;
                prevModelY = Points[i].Y + prevModelY;
                //y = writeableBitmap.CheckY(y);
                if (double.IsInfinity(y))
                {
                    y = dirtyModelRect.Bottom;
                }
                var line1 = dirtyModelRect.CohenSutherlandLineClip(new Point(x, y), new Point(x, prevY));
                var line2 = dirtyModelRect.CohenSutherlandLineClip(new Point(x, prevY), new Point(prevX, prevY));
                if (line1 != null)
                {
                    var x1 = writeableBitmap.CheckX(GetClientX(line1[0].X));
                    var y1 = writeableBitmap.CheckY(GetClientY(line1[0].Y));
                    var x2 = writeableBitmap.CheckX(GetClientX(line1[1].X));
                    var y2 = writeableBitmap.CheckY(GetClientY(line1[1].Y));
                    writeableBitmap.DrawLineAa(x1, y1, x2, y2, IntColor);
                }
                if (line2 != null)
                {
                    var x1 = writeableBitmap.CheckX(GetClientX(line2[0].X));
                    var y1 = writeableBitmap.CheckY(GetClientY(line2[0].Y));
                    var x2 = writeableBitmap.CheckX(GetClientX(line2[1].X));
                    var y2 = writeableBitmap.CheckY(GetClientY(line2[1].Y));
                    writeableBitmap.DrawLineAa(x1, y1, x2, y2, IntColor);
                }
                //writeableBitmap.DrawLineAa(x, prevY, x, y, IntColor);
                //writeableBitmap.DrawLineAa(x, prevY, prevX, prevY, IntColor);
                if (_markedPoint == i && _markedArea != StepLineArea.None)
                {
                    DrawMark(writeableBitmap, x, y, prevX, prevY, _markedArea);
                }
                prevX = x;
                prevY = y;
            }
        }
示例#7
0
        public void Draw(WriteableBitmap bitmap)
        {
            // 绘制物体
            var points = new List <int>();

            foreach (var vertex in this.combinedParticle.Vertexs)
            {
                points.Add(vertex.Position.X.ToDisplayUnits());
                points.Add(vertex.Position.Y.ToDisplayUnits());
            }

            bitmap.FillPolygon(points.ToArray(), Colors.LightCoral);

            // 绘制边缘
            points.Clear();
            foreach (var point in this.edgePoints)
            {
                points.Add(point.X.ToDisplayUnits());
                points.Add(point.Y.ToDisplayUnits());
            }

            points.Add(this.edgePoints[0].X.ToDisplayUnits());
            points.Add(this.edgePoints[0].Y.ToDisplayUnits());
            bitmap.DrawPolyline(points.ToArray(), Colors.Black);

            // 绘制PinRod
            foreach (var e in this.combinedParticle.PinRods)
            {
                bitmap.DrawLineAa(
                    e.ParticleA.Position.X.ToDisplayUnits(), e.ParticleA.Position.Y.ToDisplayUnits(),
                    e.ParticleB.Position.X.ToDisplayUnits(), e.ParticleB.Position.Y.ToDisplayUnits(), Colors.Red);
            }
        }
示例#8
0
        private void img_move(object sender, MouseEventArgs e)
        {
            if (isDrawable)
            {
                Point P = e.GetPosition(img);
                Paint      = Buf.Clone();
                img.Source = Paint;
                switch (tool)
                {
                case 1:
                    Paint.DrawLine((int)point.X, (int)point.Y, (int)P.X, (int)P.Y, color);
                    point = e.GetPosition(img);
                    Buf   = Paint.Clone();
                    break;

                case 2:
                    Paint.DrawLineAa((int)point.X, (int)point.Y, (int)P.X, (int)P.Y, color, thickness);
                    break;

                case 3:
                    Paint.DrawEllipse((int)point.X, (int)point.Y, (int)P.X, (int)P.Y, color);
                    break;
                }
            }
        }
示例#9
0
        public void drawPoints(Object myObject, EventArgs myEventArgs)
        {
            double pos       = MainHandler.Time.CurrentPlayPositionPrecise;
            int    actualdim = 3;
            int    index     = (int)((int)(pos * sr) * signal.dim);

            if (pos >= MainHandler.Time.TotalDuration)
            {
                index = (int)MainHandler.Time.TotalDuration;
            }

            Color  col    = this.SignalColor;
            double width  = renderWidth;
            double height = renderHeight;


            writeableBmp.Lock();
            writeableBmp.Clear(this.BackColor);

            //add some logic here
            //  if(signal.meta_type == "kinect2")
            {
                if (index < signal.data.Length)
                {
                    for (int i = 0; i < signal.dim; i = i + 3)
                    {
                        double X = (signal.data[index + i * actualdim]) * zoomFactor * height + (width / 2) + offsetX;
                        double Y = height - (signal.data[index + i * actualdim + 1]) * zoomFactor * width - height / 2 + offsetY;
                        double Z = signal.data[index + i * actualdim + 2] * 100;
                        writeableBmp.DrawLineAa((int)X, (int)Y, (int)X + 1, (int)Y, this.SignalColor);
                    }
                }
            }
            writeableBmp.Unlock();
        }
示例#10
0
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            if (writeableBitmap.PixelHeight < 2 || writeableBitmap.PixelWidth < 2)
            {
                return;
            }

            for (int i = 1; i < Points.Count; i++)
            {
                if (double.IsNaN(Points[i].X) || double.IsNaN(Points[i].Y) || double.IsNaN(Points[i - 1].X) || double.IsNaN(Points[i - 1].Y))
                {
                    continue;
                }
                var points = dirtyModelRect.CohenSutherlandLineClip(Points[i - 1], Points[i]);
                if (points == null)
                {
                    continue;
                }

                var x1 = writeableBitmap.CheckX(GetClientX(points[0].X));
                var y1 = writeableBitmap.CheckY(GetClientY(points[0].Y));
                var x2 = writeableBitmap.CheckX(GetClientX(points[1].X));
                var y2 = writeableBitmap.CheckY(GetClientY(points[1].Y));
                writeableBitmap.DrawLineAa(x1, y1, x2, y2, _intColor);
            }

            foreach (var point in Points.Where(dirtyModelRect.Contains))
            {
                DrawMark(writeableBitmap, point);
            }
        }
示例#11
0
        public static Image GenerateWaypointGraphImage(ITierInfo tier, Transformation2D transformer, double strokeThickness)
        {
            // Init image
            Image image = new Image();

            image.Stretch             = Stretch.Fill;
            image.SnapsToDevicePixels = true;
            RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.NearestNeighbor);
            WriteableBitmap writeableBitmap = BitmapFactory.New((int)transformer.ProjectionXLength, (int)transformer.ProjectionYLength);
            // Create complete waypoint graph
            SymmetricKeyDictionary <IWaypointInfo, bool> connections = new SymmetricKeyDictionary <IWaypointInfo, bool>();

            foreach (var waypoint in tier.GetInfoWaypoints())
            {
                // Create and remember connections (while doing so bidirectional connections are implicitly combined to one)
                foreach (var otherWP in waypoint.GetInfoConnectedWaypoints())
                {
                    connections[waypoint, otherWP] = true;
                }
            }
            // Create connections
            foreach (var connection in connections.KeysCombined)
            {
                writeableBitmap.DrawLineAa(
                    (int)transformer.ProjectX(connection.Item1.GetInfoCenterX()),
                    (int)transformer.ProjectY(connection.Item1.GetInfoCenterY()),
                    (int)transformer.ProjectX(connection.Item2.GetInfoCenterX()),
                    (int)transformer.ProjectY(connection.Item2.GetInfoCenterY()),
                    Colors.Black,
                    (int)Math.Ceiling(strokeThickness * 3));
            }
            // Return it
            image.Source = writeableBitmap;
            return(image);
        }
示例#12
0
        private void DrawCap(WriteableBitmap writeableBitmap, int x, int y)
        {
            if (y < 0 || y >= writeableBitmap.PixelHeight)
            {
                return;
            }
            var x1 = writeableBitmap.CheckX(x - _capSize);
            var x2 = writeableBitmap.CheckX(x + _capSize + 1);

            writeableBitmap.DrawLineAa(x1, y, x2, y, _intColor);
        }
示例#13
0
        public NAudioDisplayViewModel(NAudioPlayer player)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            _player            = player;
            _player.MaxVolume += OnMaxVolume;

            _bmp.Clear(Colors.Beige);
            _bmp.DrawLineAa(10, 20, 50, 70, Colors.Blue, 5);
        }
示例#14
0
 public void Draw(WriteableBitmap bitmap)
 {
     bitmap.DrawLineAa(
         this.FixedParticle.Position.X.ToDisplayUnits(),
         this.FixedParticle.Position.Y.ToDisplayUnits(),
         this.Particle.Position.X.ToDisplayUnits(),
         this.Particle.Position.Y.ToDisplayUnits(),
         Colors.DarkGray);
     bitmap.FillEllipseCentered(
         this.Particle.Position.X.ToDisplayUnits(),
         this.Particle.Position.Y.ToDisplayUnits(), this.R, this.R, Colors.DarkRed);
 }
示例#15
0
            public override void Draw(WriteableBitmap wb, float scale, float posX, float posY)
            {
                var pos1 = Body.GetWorldPoint(new Vec2());
                var pos2 = Body2.GetWorldPoint(new Vec2());

                wb.DrawLineAa(
                    (int)((pos1.X + posX) * scale),
                    (int)((pos1.Y + posY) * scale),
                    (int)((pos2.X + posX) * scale),
                    (int)((pos2.Y + posY) * scale),
                    Color, ((int)(scale * 2)).Inbetween(1, 5));
            }
示例#16
0
 public void DrawLine(double startX, double startY, double endX, double endY, Color color, double thickness)
 {
     startX = Offset.X + startX * Scale;
     startY = Offset.Y + startY * Scale;
     endX = Offset.X + endX * Scale;
     endY = Offset.Y + endY * Scale;
     int thick = (int)(thickness * Scale);
     if (thick < 1)
     {
         thick = 1;
     }
     bmp.DrawLineAa((int)startX, (int)startY, (int)endX, (int)endY, color, thick);
 }
示例#17
0
        private void RasterizeRenderedPrimitives(
            WriteableBitmap targetBitmap,
            RenderedPrimitives pixelSpacePrimitives
            )
        {
            using (targetBitmap.GetBitmapContext())
            {
                foreach (var line in pixelSpacePrimitives.Lines)
                {
                    targetBitmap.DrawLineAa(
                        (int)line.From.X, (int)line.From.Y,
                        (int)line.To.X, (int)line.To.Y,
                        line.Color);
                }

                foreach (var point in pixelSpacePrimitives.Points)
                {
                    if (point.Position.X < 0 || point.Position.Y < 0 ||
                        (int)point.Position.X >= targetBitmap.PixelWidth ||
                        (int)point.Position.Y >= targetBitmap.PixelHeight)
                    {
                        continue;
                    }

                    targetBitmap.FillEllipseCentered(
                        (int)point.Position.X,
                        (int)point.Position.Y,
                        2, 2,
                        point.Color
                        );
                }

                foreach (var point in pixelSpacePrimitives.RawPixels)
                {
                    if (point.Position.X < 0 || point.Position.Y < 0 ||
                        (int)point.Position.X >= targetBitmap.PixelWidth ||
                        (int)point.Position.Y >= targetBitmap.PixelHeight)
                    {
                        continue;
                    }

                    targetBitmap.SetPixel(
                        (int)point.Position.X,
                        (int)point.Position.Y,
                        point.Color
                        );
                }
            }
        }
示例#18
0
        public async Task <object[]> DrawPath(Room start, Room finish)
        {
            roomStart  = start;
            roomFinish = finish;
            if (roomStart.Floor != roomFinish.Floor)
            {
                var task = Render($"{start.Floor}.png");
                writeableBmpFloorStart = await task;
                task.Wait();

                task = Render($"{finish.Floor}.png");
                writeableBmpFloorFinish = await task;
                task.Wait();

                DrawPathBetweenFloors();
                return(new object[] { writeableBmpFloorStart, writeableBmpFloorFinish });
            }
            else
            {
                var task = Render($"{start.Floor}.png");
                writeableBmpFloorStart = await task;
                task.Wait();

                DrawPathFromRoomToCorridor(roomStart);
                DrawPathFromRoomToCorridor(roomFinish, true);

                if ((roomStart.X == 51 && roomFinish.X == 51) ||
                    (roomStart.X == 230 && roomFinish.X == 230) ||
                    (roomStart.X == 410 && roomFinish.X == 410) ||
                    (roomStart.X == 589 && roomFinish.X == 589) ||
                    (roomStart.Y == 116 && roomFinish.Y == 116) ||
                    (roomStart.Y == 306 && roomFinish.Y == 306))
                {
                    //Nic nie trzeba robić :D
                }
                else if (roomStart.Y > 116 && roomStart.Y < 306)
                {
                    DrawPathStartHorizontal(roomStart, roomFinish);
                }
                else
                {
                    DrawPathStartVertical(roomStart, roomFinish);
                }

                writeableBmpFloorStart.DrawLineAa((int)roomStart.X, (int)roomStart.Y, (int)roomFinish.X, (int)roomFinish.Y, Color.FromArgb(255, 0, 0, 0), 5);

                return(new object[] { writeableBmpFloorStart });
            }
        }
示例#19
0
        public void DrawLine(float sx, float sy, float ex, float ey, float w)
        {
            var s = states.Peek();

            if (_inPolyline)
            {
                _startedPolyline = true;
            }
            else
            {
            }

            float x1, y1, x2, y2;

            s.Transform.Apply(sx, sy, out x1, out y1);
            s.Transform.Apply(ex, ey, out x2, out y2);

            bmp.DrawLineAa((int)x1, (int)y1, (int)x2, (int)y2, lastColor);
        }
示例#20
0
        public void DrawPathBetweenFloors()
        {
            DrawPathFromRoomToStairsAndReverse();

            if ((roomStart.X == 51 && stairsStart.X == 51) ||
                (roomStart.X == 230 && stairsStart.X == 230) ||
                (roomStart.X == 410 && stairsStart.X == 410) ||
                (roomStart.X == 589 && stairsStart.X == 589) ||
                (roomStart.Y == 116 && stairsStart.Y == 116) ||
                (roomStart.Y == 306 && stairsStart.Y == 306))
            {
                //Nic nie trzeba robić :D
            }
            else if (roomStart.Y > 116 && roomStart.Y < 306)
            {
                DrawPathStartHorizontal(roomStart, stairsStart);
            }
            else
            {
                DrawPathStartVertical(roomStart, stairsStart);
            }
            writeableBmpFloorStart.DrawLineAa((int)roomStart.X, (int)roomStart.Y, (int)stairsStart.X, (int)stairsStart.Y, Color.FromArgb(255, 0, 0, 0), 5);

            if ((stairsFinish.X == 51 && roomFinish.X == 51) ||
                (stairsFinish.X == 230 && roomFinish.X == 230) ||
                (stairsFinish.X == 410 && roomFinish.X == 410) ||
                (stairsFinish.X == 589 && roomFinish.X == 589) ||
                (stairsFinish.Y == 116 && roomFinish.Y == 116) ||
                (stairsFinish.Y == 306 && roomFinish.Y == 306))
            {
                //Nic nie trzeba robić :D
            }
            else if (stairsFinish.Y > 116 && stairsFinish.Y < 306)
            {
                DrawPathStartHorizontal(stairsFinish, roomFinish, false);
            }
            else
            {
                DrawPathStartVertical(stairsFinish, roomFinish, false);
            }
            writeableBmpFloorFinish.DrawLineAa((int)stairsFinish.X, (int)stairsFinish.Y, (int)roomFinish.X, (int)roomFinish.Y, Color.FromArgb(255, 0, 0, 0), 5);
        }
示例#21
0
        public void DrawArrow(int x, int y, EnumPosition position, bool start = true)
        {
            WriteableBitmap floorMap = start ? writeableBmpFloorStart : writeableBmpFloorFinish;

            switch (position)
            {
            case EnumPosition.Up:
            {
                floorMap.DrawLineAa(x, y, x - 10, y + 10, Color.FromArgb(255, 0, 0, 0), 5);
                floorMap.DrawLineAa(x, y, x + 10, y + 10, Color.FromArgb(255, 0, 0, 0), 5);
                break;
            }

            case EnumPosition.Right:
            {
                floorMap.DrawLineAa(x, y, x - 10, y - 10, Color.FromArgb(255, 0, 0, 0), 5);
                floorMap.DrawLineAa(x, y, x - 10, y + 10, Color.FromArgb(255, 0, 0, 0), 5);
                break;
            }

            case EnumPosition.Down:
            {
                floorMap.DrawLineAa(x, y, x - 10, y - 10, Color.FromArgb(255, 0, 0, 0), 5);
                floorMap.DrawLineAa(x, y, x + 10, y - 10, Color.FromArgb(255, 0, 0, 0), 5);
                break;
            }

            case EnumPosition.Left:
            {
                floorMap.DrawLineAa(x, y, x + 10, y - 10, Color.FromArgb(255, 0, 0, 0), 5);
                floorMap.DrawLineAa(x, y, x + 10, y + 10, Color.FromArgb(255, 0, 0, 0), 5);
                break;
            }

            default:
                break;
            }
        }
示例#22
0
        public void Draw(WriteableBitmap bitmap)
        {
            if (_type == PhysicsType.Water)
            {
                bitmap.FillRectangle(0, WorldHeight * 2 / 3, WorldWidth, WorldHeight, Colors.SkyBlue);
            }
            else if (_type == PhysicsType.Wind)
            {
                bitmap.FillRectangle(0, WorldHeight * 1 / 3, WorldWidth, WorldHeight * 2 / 3, Colors.LightGray);
            }

            bitmap.DrawLineAa(
                _edge.PointA.X.ToDisplayUnits(),
                _edge.PointA.Y.ToDisplayUnits(),
                _edge.PointB.X.ToDisplayUnits(),
                _edge.PointB.Y.ToDisplayUnits(), Colors.Black);

            for (int i = _objList.Count - 1; i >= 0; i--)
            {
                int x = _objList[i].Position.X.ToDisplayUnits();
                int y = _objList[i].Position.Y.ToDisplayUnits();

                if (y > WorldHeight || x > WorldWidth || x < 0 || y < 0)
                {
                    PhysicsWorld.RemoveObject(_objList[i]);
                    _objList.Remove(_objList[i]);
                }
                else
                {
                    if (_type == PhysicsType.Water)
                    {
                        bitmap.FillEllipseCentered(x, y, BallSize, BallSize, y > WorldHeight * 2 / 3 ? Colors.DarkBlue : Colors.Black);
                    }
                    else
                    {
                        bitmap.FillEllipseCentered(x, y, BallSize, BallSize, Colors.Black);
                    }
                }
            }
        }
示例#23
0
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            if (writeableBitmap.PixelHeight < 2 || writeableBitmap.PixelWidth < 2)
            {
                return;
            }

            for (int i = 0; i < Points.Count; i++)
            {
                if (double.IsNaN(Points[i].X) || double.IsNaN(Points[i].Y))
                {
                    continue;
                }
                if (Points[i].X <dirtyModelRect.Left || Points[i].X> dirtyModelRect.Right)
                {
                    continue;
                }

                var x1 = writeableBitmap.CheckX(GetClientX(Points[i].X));

                var y   = GetClientY(Points[i].Y);
                var y1  = GetClientY(Points[i].YMax);
                var y2  = GetClientY(Points[i].YMin);
                var y11 = writeableBitmap.CheckY(y1);
                var y21 = writeableBitmap.CheckY(y2);
                if (y1 >= 0 && y1 < writeableBitmap.PixelHeight && y1 != y)
                {
                    DrawCap(writeableBitmap, x1, y11);
                }
                if (y2 >= 0 && y2 < writeableBitmap.PixelHeight && y2 != y)
                {
                    DrawCap(writeableBitmap, x1, y21);
                }

                writeableBitmap.DrawLineAa(x1, y11, x1, y21, _intColor);
            }
        }
示例#24
0
 public void DrawLine(double x1, double y1, double x2, double y2, Color color)
 {
     _context.DrawLineAa((int)Math.Round(x1), (int)Math.Round(y1), (int)Math.Round(x2), (int)Math.Round(y2), color.ToArgb());
 }
示例#25
0
 public void DrawLineEx(WriteableBitmap bmp, int x, int y, int width, int height, Color color, int tick)
 {
     bmp.DrawLineAa(x, y, x + width, y + height, color, tick);
 }
示例#26
0
        private void StartAlgorithm_OnClick(object sender, RoutedEventArgs e)
        {
            e.Handled   = true;
            _pathfinder = new Pathfinder(QuaxPosIndex);
            //_mapImgOverlay = new WriteableBitmap(Convert.ToInt32(_mapImg.PixelWidth * OverlayZoomLevel), Convert.ToInt32(_mapImg.PixelHeight * OverlayZoomLevel), _mapImg.DpiX,
            //    _mapImg.DpiY, PixelFormats.Bgra32, null);
            //MapImageOverlay.Source = _mapImgOverlay; //TODO: WTF Clear die Quadtree Sachen wenn er fertig is und tab wechselt

            try
            {
                var timer = new Stopwatch();
                timer.Start();
                var pathInfo = _pathfinder.FindPath();
                timer.Stop();
                Result_Header.Content        = $"Ergebnis für {Manager.Instance.CurPositionTab.Header}";
                Result_AlgorithmTime.Content = $"{timer.ElapsedMilliseconds}ms";
                Result_DroneFlights.Content  = $"{Manager.Instance.CurPositionTab.AnzahlFluege}";

                if (pathInfo.StadtGefunden)
                {
                    Result_FoundPath.Content = "JA";
                    for (int i = 0; i < pathInfo.Weg.Count; i++)
                    {
                        if (i == 0)
                        {
                            _mapImgOverlay.DrawLineAa(Convert.ToInt32(MapDaten.Instance.QuaxPositionen[QuaxPosIndex].X * OverlayZoomLevel),
                                                      Convert.ToInt32(MapDaten.Instance.QuaxPositionen[QuaxPosIndex].Y * OverlayZoomLevel),
                                                      Convert.ToInt32(pathInfo.Weg[i].MapQuadrat.Mittelpunkt.X * OverlayZoomLevel),
                                                      Convert.ToInt32(pathInfo.Weg[i].MapQuadrat.Mittelpunkt.Y * OverlayZoomLevel), Colors.Cyan, StrokeThickness);
                        }

                        if (i < pathInfo.Weg.Count - 1)
                        {
                            _mapImgOverlay.DrawLineAa(Convert.ToInt32(pathInfo.Weg[i].MapQuadrat.Mittelpunkt.X * OverlayZoomLevel),
                                                      Convert.ToInt32(pathInfo.Weg[i].MapQuadrat.Mittelpunkt.Y * OverlayZoomLevel),
                                                      Convert.ToInt32(pathInfo.Weg[i + 1].MapQuadrat.Mittelpunkt.X * OverlayZoomLevel),
                                                      Convert.ToInt32(pathInfo.Weg[i + 1].MapQuadrat.Mittelpunkt.Y * OverlayZoomLevel), Colors.Cyan, StrokeThickness);
                        }
                        else if (i == pathInfo.Weg.Count - 1)
                        {
                            _mapImgOverlay.DrawLineAa(Convert.ToInt32(pathInfo.Weg[i].MapQuadrat.Mittelpunkt.X * OverlayZoomLevel),
                                                      Convert.ToInt32(pathInfo.Weg[i].MapQuadrat.Mittelpunkt.Y * OverlayZoomLevel),
                                                      Convert.ToInt32(pathInfo.StadtPos.X * OverlayZoomLevel),
                                                      Convert.ToInt32(pathInfo.StadtPos.Y * OverlayZoomLevel), Colors.Cyan, StrokeThickness);
                        }
                    }

                    MessageBox.Show($"Weg Laenge: {pathInfo.Weg.Count}\nIn {timer.ElapsedMilliseconds}ms");
                }
                else
                {
                    Result_FoundPath.Content = "NEIN";
                    MessageBox.Show("Es konnte kein Weg gefunden werden!");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.StackTrace, exception.Message);
            }

            _pathfinder = null;
        }
示例#27
0
        public void DrawPathFromRoomToCorridor(Room which, bool finish = false, bool start = true)
        {
            WriteableBitmap floorMap = start ? writeableBmpFloorStart : writeableBmpFloorFinish;

            switch ((int)which.X)
            {
            case 35:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Left, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 51, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 51;
                break;
            }

            case 67:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Right, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 51, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 51;
                break;
            }

            case 212:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Left, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 230, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 230;
                break;
            }

            case 250:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Right, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 230, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 230;
                break;
            }

            case 291:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Right, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 265, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 265;
                break;
            }

            case 347:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Left, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 375, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 375;
                break;
            }

            case 390:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Left, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 410, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 410;
                break;
            }

            case 428:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Right, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 410, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 410;
                break;
            }

            case 573:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Left, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 589, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 589;
                break;
            }

            case 605:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Right, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, 589, (int)which.Y, Color.FromArgb(255, 0, 0, 0), 5);
                which.X = 589;
                break;
            }

            default:
                break;
            }

            switch ((int)which.Y)
            {
            case 35:
            {
                floorMap.DrawLineAa((int)which.X, (int)which.Y, (int)which.X, 116, Color.FromArgb(255, 0, 0, 0), 5);
                which.Y = 116;
                break;
            }

            case 93:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Up, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, (int)which.X, 116, Color.FromArgb(255, 0, 0, 0), 5);
                which.Y = 116;
                break;
            }

            case 140:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Down, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, (int)which.X, 116, Color.FromArgb(255, 0, 0, 0), 5);
                which.Y = 116;
                break;
            }

            case 283:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Up, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, (int)which.X, 306, Color.FromArgb(255, 0, 0, 0), 5);
                which.Y = 306;
                break;
            }

            case 330:
            {
                if (finish)
                {
                    DrawArrow((int)which.X, (int)which.Y, EnumPosition.Down, start);
                }
                floorMap.DrawLineAa((int)which.X, (int)which.Y, (int)which.X, 306, Color.FromArgb(255, 0, 0, 0), 5);
                which.Y = 306;
                break;
            }

            case 390:
            {
                floorMap.DrawLineAa((int)which.X, (int)which.Y, (int)which.X, 306, Color.FromArgb(255, 0, 0, 0), 5);
                which.Y = 306;
                break;
            }

            default:
                break;
            }
        }
示例#28
0
        public void DrawPathStartVertical(Room roomStart, Room roomFinish, bool start = true)
        {
            WriteableBitmap floorMap = start ? writeableBmpFloorStart : writeableBmpFloorFinish;

            int newX = 0;

            //51, 230, 410, 589
            //  135, 315, 506
            //  600,  570,  575
            //A       X <= 135
            //B 135 < X <= 315
            //C 315< X <= 506
            //D 506< X

            if (Math.Abs(roomFinish.X - roomStart.X) < 575 &&
                Math.Abs(roomFinish.Y - roomStart.Y) == 0)
            {
                return;
            }
            //↓roomStart jest w przedziale A
            else if (roomStart.X <= 135 &&//AA
                     roomFinish.X <= 135)
            {
                newX = 51;
            }
            else if (roomStart.X <= 135 &&//AB
                     roomFinish.X > 135 && roomFinish.X <= 315)
            {
                newX = 230;
            }
            else if (roomStart.X <= 135 &&//AC
                     roomFinish.X > 315 && roomFinish.X <= 506)
            {
                newX = 410;
            }
            else if (roomStart.X <= 135 &&//AD
                     roomFinish.X > 506)
            {
                newX = 589;
            }
            //↓roomStart jest w przedziale B
            else if (roomStart.X > 135 && roomStart.X <= 315 &&//BA
                     roomFinish.X <= 135)
            {
                newX = 51;
            }
            else if (roomStart.X > 135 && roomStart.X <= 315 &&//BB
                     roomFinish.X > 135 && roomFinish.X <= 315)
            {
                newX = 230;
            }
            else if (roomStart.X > 135 && roomStart.X <= 315 &&//BC
                     roomFinish.X > 315 && roomFinish.X <= 506)
            {
                newX = 410;
            }
            else if (roomStart.X > 135 && roomStart.X <= 315 &&//BD
                     roomFinish.X > 506)
            {
                newX = 589;
            }
            //↓roomStart jest w przedziale C
            else if (roomStart.X > 315 && roomStart.X <= 506 &&//CA
                     roomFinish.X <= 135)
            {
                newX = 51;
            }
            else if (roomStart.X > 315 && roomStart.X <= 506 &&//CB
                     roomFinish.X > 135 && roomFinish.X <= 320)
            {
                newX = 230;
            }
            else if (roomStart.X > 315 && roomStart.X <= 506 &&//CC
                     roomFinish.X > 320 && roomFinish.X <= 506)
            {
                newX = 410;
            }
            else if (roomStart.X > 315 && roomStart.X <= 506 &&//CD
                     roomFinish.X > 506)
            {
                newX = 589;
            }
            //↓roomStart jest w przedziale D
            else if (roomStart.X > 506 &&//DA
                     roomFinish.X <= 135)
            {
                newX = 51;
            }
            else if (roomStart.X > 506 &&//DB
                     roomFinish.X > 135 && roomFinish.X <= 320)
            {
                newX = 230;
            }
            else if (roomStart.X > 506 &&//DC
                     roomFinish.X > 320 && roomFinish.X <= 506)
            {
                newX = 410;
            }
            else if (roomStart.X > 506 &&//DD
                     roomFinish.X > 506)
            {
                newX = 589;
            }
            floorMap.DrawLineAa((int)roomStart.X, (int)roomStart.Y, newX, (int)roomStart.Y, Color.FromArgb(255, 0, 0, 0), 5);
            floorMap.DrawLineAa((int)roomFinish.X, (int)roomFinish.Y, newX, (int)roomFinish.Y, Color.FromArgb(255, 0, 0, 0), 5);
            roomStart.X  = newX;
            roomFinish.X = newX;
        }
示例#29
0
        private void MakeBitmap()
        {
            if ((ActualWidth < 1) || (ActualHeight < 1))
            {
                return;
            }

            if (ImageData == null)
            {
                return;
            }


            if (ImageData.imageSize.X < 0.0)
            {
                _writeableBmp = BitmapFactory.New((int)ActualWidth, (int)ActualHeight);
            }
            else
            {
                _writeableBmp = BitmapFactory.New((int)ImageData.imageSize.X, (int)ImageData.imageSize.Y);
            }

            RootImage.Source = _writeableBmp;

            using (_writeableBmp.GetBitmapContext())
            {
                XFactor = ActualWidth / ImageData.boundingRect.Width();
                YFactor = ActualHeight / ImageData.boundingRect.Height();
                var minX = ImageData.boundingRect.MinX;
                var minY = ImageData.boundingRect.MinY;

                foreach (var plotRectangle in ImageData.filledRects)
                {
                    _writeableBmp.FillRectangle(
                        XWindow(plotRectangle.MinX, minX),
                        YWindow(plotRectangle.MinY, ActualHeight, minY),
                        XWindow(plotRectangle.MinX + plotRectangle.Width(), minX),
                        YWindow(plotRectangle.MinY + plotRectangle.Height(), ActualHeight, minY),
                        plotRectangle.V
                        );
                }

                foreach (var plotRectangle in ImageData.openRects)
                {
                    _writeableBmp.DrawRectangle(
                        XWindow(plotRectangle.MinX, minX),
                        YWindow(plotRectangle.MinY, ActualHeight, minY),
                        XWindow(plotRectangle.MinX + plotRectangle.Width(), minX),
                        YWindow(plotRectangle.MinY + plotRectangle.Height(), ActualHeight, minY),
                        plotRectangle.V
                        );
                }

                foreach (var plotLine in ImageData.plotLines)
                {
                    _writeableBmp.DrawLineAa(
                        XWindow(plotLine.X1, minX),
                        YWindow(plotLine.Y1, ActualHeight, minY),
                        XWindow(plotLine.X2, minX),
                        YWindow(plotLine.Y2, ActualHeight, minY),
                        plotLine.V
                        );
                }


                foreach (var plotPoint in ImageData.plotPoints)
                {
                    _writeableBmp.FillRectangle(
                        XWindow(plotPoint.X, minX),
                        YWindow(plotPoint.Y, ActualHeight, minY),
                        XWindow(plotPoint.X + 1, minX),
                        YWindow(plotPoint.Y + 1, ActualHeight, minY),
                        plotPoint.V
                        );
                }
            } // Invalidates on exit of using block
        }
        private void UpdateVisualVertical(double xStart, double yStart, int width, int height, Color color, bool isMultiColor, int leftThickness, int rightThickness)
        {
            double xEnd, yEnd;

            if (((FastStepLineBitmapSeries)fastSeries).EnableAntiAliasing)
            {
                for (int i = 1; i < xValues.Count; i++)
                {
                    if (isSeriesSelected)
                    {
                        color = seriesSelectionColor;
                    }
                    else if (Series.SegmentColorPath != null && fastSeries.Interior == null)
                    {
                        if (Series.ColorValues.Count > 0 && Series.ColorValues[startIndex] != null)
                        {
                            color = GetColor(Series.ColorValues[startIndex]);
                        }
                        else if (Series.Palette == ChartColorPalette.None)
                        {
                            int serIndex = Series.ActualArea.GetSeriesIndex(this.Series);
                            color = GetColor(Series.ActualArea.ColorModel.GetBrush(serIndex));
                        }
                        else
                        {
                            Brush brush = Series.ColorModel.GetBrush(startIndex);
                            color = GetColor(brush);
                        }
                    }
                    else if (isMultiColor)
                    {
                        Brush brush = Series.ColorModel.GetBrush(startIndex);
                        color = GetColor(brush);
                    }
                    xEnd = xValues[i];
                    yEnd = yValues[i];
                    startIndex++;
                    if (!double.IsNaN(yStart) && !double.IsNaN(yEnd))
                    {
                        var leftOffset  = xStart - leftThickness;
                        var rightOffset = xStart + rightThickness;
                        if (yEnd < yStart)
                        {
                            bitmap.FillRectangle(fastBuffer, width, height, (int)yEnd, (int)leftOffset, (int)yStart, (int)rightOffset, color, fastSeries.bitmapPixels);
                        }
                        else
                        {
                            bitmap.FillRectangle(fastBuffer, width, height, (int)yStart, (int)leftOffset, (int)yEnd, (int)rightOffset, color, fastSeries.bitmapPixels);
                        }
                        bitmap.DrawLineAa(fastBuffer, width, height, (int)yStart, (int)leftOffset, (int)yEnd, (int)leftOffset, color, fastSeries.bitmapPixels);
                        bitmap.DrawLineAa(fastBuffer, width, height, (int)yStart, (int)leftOffset, (int)yStart, (int)rightOffset, color, fastSeries.bitmapPixels);
                        bitmap.DrawLineAa(fastBuffer, width, height, (int)yStart, (int)rightOffset, (int)yEnd, (int)rightOffset, color, fastSeries.bitmapPixels);
                        bitmap.DrawLineAa(fastBuffer, width, height, (int)yEnd, (int)leftOffset, (int)yEnd, (int)rightOffset, color, fastSeries.bitmapPixels);
                        leftOffset  = yEnd - leftThickness;
                        rightOffset = yEnd + rightThickness;
                        bitmap.FillRectangle(fastBuffer, width, height, (int)leftOffset, (int)xEnd, (int)rightOffset, (int)xStart, color, fastSeries.bitmapPixels);
                        bitmap.DrawLineAa(fastBuffer, width, height, (int)leftOffset, (int)xEnd, (int)rightOffset, (int)xEnd, color, fastSeries.bitmapPixels);
                        bitmap.DrawLineAa(fastBuffer, width, height, (int)leftOffset, (int)xEnd, (int)leftOffset, (int)xStart, color, fastSeries.bitmapPixels);
                        bitmap.DrawLineAa(fastBuffer, width, height, (int)leftOffset, (int)xStart, (int)rightOffset, (int)xStart, color, fastSeries.bitmapPixels);
                        bitmap.DrawLineAa(fastBuffer, width, height, (int)rightOffset, (int)xEnd, (int)rightOffset, (int)xStart, color, fastSeries.bitmapPixels);
                    }
                    xStart = xEnd;
                    yStart = yEnd;
                }
            }
            else
            {
                for (int i = 1; i < xValues.Count; i++)
                {
                    if (isSeriesSelected)
                    {
                        color = seriesSelectionColor;
                    }
                    else if (Series.SegmentColorPath != null && fastSeries.Interior == null)
                    {
                        if (Series.ColorValues.Count > 0 && Series.ColorValues[startIndex] != null)
                        {
                            color = GetColor(Series.ColorValues[startIndex]);
                        }
                        else if (Series.Palette == ChartColorPalette.None)
                        {
                            int serIndex = Series.ActualArea.GetSeriesIndex(this.Series);
                            color = GetColor(Series.ActualArea.ColorModel.GetBrush(serIndex));
                        }
                        else
                        {
                            Brush brush = Series.ColorModel.GetBrush(startIndex);
                            color = GetColor(brush);
                        }
                    }
                    else if (isMultiColor)
                    {
                        Brush brush = Series.ColorModel.GetBrush(startIndex);
                        color = GetColor(brush);
                    }
                    xEnd = xValues[i];
                    yEnd = yValues[i];
                    startIndex++;
                    if (!double.IsNaN(yStart) && !double.IsNaN(yEnd))
                    {
                        var leftOffset  = xStart - leftThickness;
                        var rightOffset = xStart + rightThickness;
                        if (yEnd < yStart)
                        {
                            bitmap.FillRectangle(fastBuffer, width, height, (int)yEnd, (int)leftOffset, (int)yStart, (int)rightOffset, color, fastSeries.bitmapPixels);
                        }
                        else
                        {
                            bitmap.FillRectangle(fastBuffer, width, height, (int)yStart, (int)leftOffset, (int)yEnd, (int)rightOffset, color, fastSeries.bitmapPixels);
                        }
                        leftOffset  = yEnd - leftThickness;
                        rightOffset = yEnd + rightThickness;
                        if (xEnd < xStart)
                        {
                            bitmap.FillRectangle(fastBuffer, width, height, (int)leftOffset, (int)xEnd, (int)rightOffset, (int)xStart, color, fastSeries.bitmapPixels);
                        }
                        else
                        {
                            bitmap.FillRectangle(fastBuffer, width, height, (int)leftOffset, (int)xStart, (int)rightOffset, (int)xEnd, color, fastSeries.bitmapPixels);
                        }
                    }
                    xStart = xEnd;
                    yStart = yEnd;
                }
            }
        }