Ejemplo n.º 1
0
        public void Display(Graphics gfx)
        {
            Tool.Point offset = controls[0] * map.SizeCorrected + map.Position;

            Tool.Size size = (controls[1] - controls[0]) * map.SizeCorrected;

            foreach (PathDef def in paths)
            {
                def.path.Reset();

                Tool.Point last = offset + def.points[0] * size;
                foreach (Tool.Point point in def.points)
                {
                    Tool.Point newpt = offset + point * size;
                    def.path.AddLine(last, newpt);
                    last = newpt;
                }

                gfx.DrawPath(def.pen, def.path);
            }

            int j = 0;

            foreach (Tool.Point point in controls)
            {
                Tool.Point pt = (point * map.SizeCorrected + map.Position).Truncate;

                Brush brush = (isDraggingCtrlPoint == j) ? brushSelected : brushUnselected;
                gfx.FillEllipse(brush, new Rectangle((int)pt.X - 5, (int)pt.Y - 5, 11, 11));
                j++;
            }
        }
Ejemplo n.º 2
0
        public Tool.Point UnitToPanel(iconDB from)
        {
            Tool.Size  ratio   = this.nfo.dbMapSize / this.nfo.dbRefMapSize;
            Tool.Point unitPos = from.pos * ratio + this.nfo.dbMapOffsetUnit;

            return(this.Position + (unitPos * this.SizeCorrected) - (from.icon.Size * 0.5f));
        }
Ejemplo n.º 3
0
        public Tool.Point UnitToPanel(Tool.Point from)
        {
            //                return Position + from * SizeCorrected;
            Tool.Size  ratio   = this.nfo.dbMapSize / this.nfo.dbRefMapSize;
            Tool.Point unitPos = from * ratio + this.nfo.dbMapOffsetUnit;

            return(this.Position + unitPos * this.SizeCorrected);
        }
Ejemplo n.º 4
0
        public Tool.Point PanelToUnit(Tool.Point from)
        {
            Tool.Point unitInMap = (Tool.Point)((from - this.Position) / this.SizeCorrected);
            unitInMap = (Tool.Point)(unitInMap - this.nfo.dbMapOffsetUnit);
            Tool.Size ratio = this.nfo.dbRefMapSize / this.nfo.dbMapSize;

            Tool.Point pt = unitInMap * ratio;
            pt.Y = 1.0f - pt.Y;

            return(pt);
        }
Ejemplo n.º 5
0
        public float ResizeFromZoom(float zoom)
        {
            Tool.Size minSize = nfo.defTileSize * (float)Math.Pow(2, nfo.min_depth);

            Tool.Size maxSize = new Tool.Size((int)nfo.defTileSize.Width << (nfo.mag_depth - 1),
                                              (int)nfo.defTileSize.Height << (nfo.mag_depth - 1));

            Tool.Size temp = nfo.defTileSize * zoom;

            Size = Tool.Size.Max(minSize, Tool.Size.Min(maxSize, temp));

            return(Size.Width / nfo.defTileSize.Width);
        }
Ejemplo n.º 6
0
        public void ControlPointUpdated(int idx)
        {
            if (idx < 2)
            {
                // Update 2 & 3
                controls[2] = new Tool.Point(controls[1].X, controls[0].Y);
                controls[3] = new Tool.Point(controls[0].X, controls[1].Y);
            }
            else
            {
                // Update 1 & 2
                controls[0] = new Tool.Point(controls[3].X, controls[2].Y);
                controls[1] = new Tool.Point(controls[2].X, controls[3].Y);
            }

            Tool.Size size = (controls[1] - controls[0]);

            boundaries[0] = controls[0] + defBoundaries[0] * size;
            boundaries[1] = controls[0] + defBoundaries[1] * size;
        }
Ejemplo n.º 7
0
        private void UpdateData()
        {
            Tool.Size reqTileCount = (_size / nfo.defTileSize).UpperPowerOf2;

            _depth = (int)Math.Log(Math.Max(reqTileCount.Width, reqTileCount.Height), 2);

            // Clamp to min depth
            _depth = Math.Max(_depth, nfo.min_depth);

            // Clamp to max depth
            _depth = Math.Min(_depth, nfo.mag_depth - 1);

            // Clamp tile count
            Tool.Size maxSize = new Tool.Size(1 << _depth, 1 << _depth);

            _tileCount = Tool.Size.Min(reqTileCount, maxSize);

            _tileSize = (_size / _tileCount).Ceiling;

            // and re-adjust size from new tile size
            _size          = _tileSize * _tileCount;
            _sizeCorrected = (_size * _ratio).Ceiling;
        }
Ejemplo n.º 8
0
        public static void CreateBitmapFromTiles(string dstFilePath, string srcDirPath, int tileCountX, int tileCountY, Tool.Size tileSize)
        {
            Bitmap result = new Bitmap((int)tileSize.Width * tileCountX,
                                       (int)tileSize.Height * tileCountY);
            Graphics g = Graphics.FromImage((Image)result);

            g.InterpolationMode = InterpolationMode.NearestNeighbor;
            g.Clear(Color.White);

            for (int y = 0; y < tileCountY; y++)
            {
                for (int x = 0; x < tileCountX; x++)
                {
                    Bitmap input = new Bitmap(srcDirPath + x + "_" + y + ".png");
                    g.DrawImage(input, new Rectangle((int)(x * tileSize.Width), (int)(y * tileSize.Height), (int)tileSize.Width, (int)tileSize.Height));
                    input.Dispose();
                }
            }

            SaveJpeg(dstFilePath, result, 90);
            result.Dispose();
        }
Ejemplo n.º 9
0
 public Rectangle TileRectangleEx(Tool.Point p, Tool.Size sz)
 {
     return(new Rectangle(Position + p * _tileSize, sz));
 }
Ejemplo n.º 10
0
 public VirtualMap()
 {
     Position = Tool.Point.Empty;
     Size     = new Tool.Size(400, 400);
 }
Ejemplo n.º 11
0
 public void SetRatio(Tool.Size ratio)
 {
     _ratio = ratio;
 }
Ejemplo n.º 12
0
        public MapHelper(VirtualMap map, string worldId)
        {
            this.map = map;

            foreach (Tool.Point[] arr in Tool.mapHelperDefs[worldId])
            {
                AddPathDef(arr);
            }

            Tool.Point min = new Tool.Point(9999999, 9999999);
            Tool.Point max = new Tool.Point(-9999999, -9999999);
            foreach (PathDef _def in paths)
            {
                foreach (Tool.Point pt in _def.points)
                {
                    min = Tool.Point.Min(min, pt);
                    max = Tool.Point.Max(max, pt);
                }
            }
            Tool.Size size = (max - min);

            //  DB Map boundaries
            {
                Tool.Point[] points = new Tool.Point[]
                {
                    new Tool.Point(0, map.nfo.dbRefMapSize.Height),
                    new Tool.Point(map.nfo.dbRefMapSize.Width, map.nfo.dbRefMapSize.Height),
                    new Tool.Point(map.nfo.dbRefMapSize.Width, 0),
                    new Tool.Point(0, 0),
                    new Tool.Point(0, map.nfo.dbRefMapSize.Height)
                };
                AddPathDef(points, new Pen(Color.Red, 2));
            }

            foreach (PathDef _def in paths)
            {
                for (int i = 0; i < _def.points.Count; i++)
                {
                    Tool.Point pt = _def.points[i];
                    pt             = (Tool.Point)((pt - min) / size);
                    _def.points[i] = pt;
                }
            }

            defBoundaries[0] = (Tool.Point)((new Tool.Point(0, map.nfo.dbRefMapSize.Height) - min) / size);
            defBoundaries[1] = (Tool.Point)((new Tool.Point(map.nfo.dbRefMapSize.Width, 0) - min) / size);

            //  DB bounding box
            {
                Tool.Point[] points = new Tool.Point[]
                {
                    new Tool.Point(0, 0),
                    new Tool.Point(0, 1),
                    new Tool.Point(1, 1),
                    new Tool.Point(1, 0),
                    new Tool.Point(0, 0)
                };
                AddPathDef(points, new Pen(Color.Green, 1));
            }

            // DB map boundaries
            boundaries[0] = map.nfo.dbMapOffsetUnit;
            boundaries[1] = boundaries[0] + map.nfo.dbMapSize / map.nfo.dbRefMapSize;

            // Control points
            Tool.Size Csize = (boundaries[1] - boundaries[0]) / (defBoundaries[1] - defBoundaries[0]);

            controls[0] = (Tool.Point)(boundaries[0] - defBoundaries[0] * Csize);
            controls[1] = controls[0] + Csize;

            controls[2] = new Tool.Point(controls[1].X, controls[0].Y);
            controls[3] = new Tool.Point(controls[0].X, controls[1].Y);
        }