Exemplo n.º 1
0
 private void DxContainer_DragDrop(object sender, DragEventArgs e)
 {
     lock (this)
     {
         if (!e.Data.GetDataPresent(DataFormats.FileDrop))
         {
             return;
         }
         if (!AssertLayerSelected())
         {
             return;
         }
         string[]             data = (string[])e.Data.GetData(DataFormats.FileDrop);
         System.Drawing.Point p    = PointToClient(new System.Drawing.Point(e.X, e.Y));
         foreach (string file in data)
         {
             System.Drawing.Bitmap bmp;
             try
             {
                 bmp = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(file);
             }
             catch
             {
                 continue;
             }
             if (ImageDropped != null)
             {
                 ImageDropped.Invoke(selectedBoard, bmp, Path.GetFileNameWithoutExtension(file), new Point(PhysicalToVirtual(p.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0), PhysicalToVirtual(p.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0)));
             }
         }
     }
 }
Exemplo n.º 2
0
 private void DxContainer_MouseMove(object sender, MouseEventArgs e)
 {
     lock (this)
     {
         System.Drawing.Point mouse = PointToClient(Cursor.Position);
         if (VirtualToPhysical(selectedBoard.Mouse.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0) != mouse.X || VirtualToPhysical(selectedBoard.Mouse.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0) != mouse.Y)
         {
             Point oldPos = new Point(selectedBoard.Mouse.X, selectedBoard.Mouse.Y);
             Point newPos = new Point(PhysicalToVirtual(mouse.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0), PhysicalToVirtual(mouse.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0));
             selectedBoard.Mouse.Move(newPos.X, newPos.Y);
             if (MouseMoved != null)
             {
                 MouseMoved.Invoke(selectedBoard, oldPos, newPos, new Point(mouse.X, mouse.Y));
             }
         }
     }
 }
Exemplo n.º 3
0
        public void FillWithTiles(TerrainGenerator generator, TimelineLayer board)
        {
            var surroundingChunksWithRivers = new List <TileForInlandWaterConnectivity>();


            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    var tile = board.InlandWaterConnectivity[this.ChunkWorldMapLocationPoint.X + i][this.ChunkWorldMapLocationPoint.Y + j];
                    if (tile.WaterBorderLines.Any())
                    {
                        surroundingChunksWithRivers.Add(tile);
                    }
                }
            }

            for (int x = 0; x < Constants.ChunkSize; x++)
            {
                for (int y = 0; y < Constants.ChunkSize; y++)
                {
                    chunkTiles[x][y] = generator.GetTileWithoutRiverWater(x + worldPositionBottomLeftCorner.X,
                                                                          y + worldPositionBottomLeftCorner.Y, Constants.ChunkSize);

                    //if (x == 0 || y == 0 || x == Constants.ChunkSize - 1 || y == Constants.ChunkSize - 1)
                    //{
                    //	chunkTiles[x][y].Terrain = TerrainLibrary.Terrains[TerrainTypes.Nothingness];
                    //}
                }
            }



            if (surroundingChunksWithRivers.Any())
            {
                //TODO this part is really useful for plotting rivers/roads on map, should be moved to its own class
                // the point is: i must generate a chunk sized bitmap to detect which tiles are river tiles and which are not
                // in this bitmap, black pixels are ignored, white ones are river tiles

                Pen whitePen = new Pen(System.Drawing.Color.White, Constants.ChunkSize);

                var waterBitmap = new Bitmap(Constants.ChunkSize, Constants.ChunkSize);

                var graphics = Graphics.FromImage(waterBitmap);

                foreach (var chunkWithRivers in surroundingChunksWithRivers)
                {
                    var riverLines = chunkWithRivers.WaterBorderLines;

                    foreach (var waterBorderLine in riverLines)
                    {
                        var chunkRiverPoints = waterBorderLine.Points;

                        var chunkPointIndex = chunkRiverPoints.FindIndex(p =>
                                                                         p.X == chunkWithRivers.x && p.Y == chunkWithRivers.y);

                        var chHalf = Constants.ChunkSize / 2;
                        var halfV  = new Microsoft.Xna.Framework.Vector2(chHalf);
                        Point ScalePoint(Point p)
                        {
                            return(((p.ToVector2() * Constants.ChunkSize) + halfV).ToPoint());
                        }

                        int curveLenght     = 5;
                        int curveHalfLenght = curveLenght / 2;

                        System.Drawing.Point[]      curvePoints = null;
                        List <System.Drawing.Point> endPoints   = null;
                        if (chunkRiverPoints.Count >= curveLenght)
                        {
                            curvePoints = new System.Drawing.Point[curveLenght];
                            endPoints   = new List <System.Drawing.Point>();
                            int rangeStart = 0, rangeEnd = 0;
                            int rangeIndex = chunkPointIndex;
                            if (chunkPointIndex >= curveHalfLenght && chunkPointIndex < chunkRiverPoints.Count - curveHalfLenght)
                            {
                                rangeStart = -curveHalfLenght;
                                rangeEnd   = curveHalfLenght;
                            }

                            //this chunk is a first point in this water line
                            else if (chunkPointIndex <= curveHalfLenght)
                            {
                                rangeStart = 0;
                                rangeEnd   = curveLenght - 1;

                                rangeIndex = 0;
                                endPoints.Add(ScalePoint(chunkRiverPoints[rangeStart] - ChunkWorldMapLocationPoint).ToPoint());
                            }

                            //this chunk is last
                            else if (chunkPointIndex > chunkRiverPoints.Count - curveHalfLenght - 1)
                            {
                                rangeStart = -curveLenght + 1;
                                rangeEnd   = 0;

                                rangeIndex = chunkRiverPoints.Count - 1;

                                endPoints.Add(ScalePoint(chunkRiverPoints[rangeIndex] - ChunkWorldMapLocationPoint).ToPoint());
                            }


                            for (int i = rangeStart, pointsIndex = 0; i <= rangeEnd; i++, pointsIndex++)
                            {
                                curvePoints[pointsIndex] = ScalePoint(chunkRiverPoints[rangeIndex + i] - ChunkWorldMapLocationPoint).ToPoint();
                            }
                        }
                        else
                        {
                            var allpointsCount = chunkRiverPoints.Count;
                            curvePoints = new System.Drawing.Point[allpointsCount];

                            for (int i = 0; i < chunkRiverPoints.Count; i++)
                            {
                                curvePoints[i] = ScalePoint(chunkRiverPoints[i] - ChunkWorldMapLocationPoint).ToPoint();
                            }
                        }


                        graphics.DrawCurve(whitePen, curvePoints);
                        if (endPoints != null)
                        {
                            foreach (var point in endPoints)
                            {
                                graphics.FillEllipse(Brushes.White, point.X - chHalf, point.Y - chHalf, Constants.ChunkSize, Constants.ChunkSize);
                            }
                        }
                    }

                    //then we use the bitmap and fill the chunk
                    for (int x = 0; x < Constants.ChunkSize; x++)
                    {
                        for (int y = 0; y < Constants.ChunkSize; y++)
                        {
                            if (waterBitmap.GetPixel(x, y).R > 0)
                            {
                                chunkTiles[x][y].Biome   = Biomes.River;
                                chunkTiles[x][y].Terrain = TerrainTypes.Water;
                            }
                        }
                    }
                }
            }
        }
 public static System.Drawing.Point Nearest(this System.Drawing.Point point, Size near, bool ceil = false)
 {
     return(new System.Drawing.Point(point.X.Nearest(near.Width, ceil), point.Y.Nearest(near.Height, ceil)));
 }