Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TileBrushImpl"/> class.
        /// </summary>
        /// <param name="brush"></param>
        /// <param name="target"></param>
        /// <param name="targetSize"></param>
        public TileBrushImpl(
            TileBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size targetSize)
        {
            var helper = new TileBrushImplHelper(brush, targetSize);

            if (!helper.IsValid)
            {
                return;
            }

            using (var intermediate = new BitmapRenderTarget(target, CompatibleRenderTargetOptions.None, helper.IntermediateSize.ToSharpDX()))
            {
                using (var ctx = new RenderTarget(intermediate).CreateDrawingContext())
                {
                    intermediate.Clear(null);
                    helper.DrawIntermediate(ctx);
                }

                PlatformBrush = new BitmapBrush(
                    target,
                    intermediate.Bitmap,
                    GetBitmapBrushProperties(brush),
                    GetBrushProperties(brush, helper.DestinationRect));
            }
        }
    private void CreateBrush()
    {
        // Make sure there isn't already an existing tile brush
        if (brush == null)
        {
            // Grab reference to map's tile brush and make sure its not null
            var sprite = map.tileBrush;
            if (sprite != null)
            {
                // Create a new object
                GameObject obj = new GameObject("TileBrush");
                // Nest the brush inside the tile map object
                obj.transform.SetParent(map.transform);

                // Attach the game object and finish setting up the brush
                brush      = obj.AddComponent <TileBrush>();
                brush.tile = obj.AddComponent <SpriteRenderer>();
                // Make sure the brush stays above placed tiles
                brush.tile.sortingOrder = 1000;

                // Calculate brush size using the tileset pixels per unit.
                brush.brushSize = new Vector2(sprite.textureRect.width / map.pixelsPerUnit,
                                              sprite.textureRect.height / map.pixelsPerUnit);
                brush.UpdateBrush(sprite);
                // Set the brush to origin position
                MoveBrush(map.transform.position.x, map.transform.position.y);
            }
        }
    }
Esempio n. 3
0
        public void Slide(TileBrush brush, double newIndex, double stripCount)
        {
            m_timer.Stop();
            if (brush != null)
            {
                m_timer.Interval = TimeSpan.FromMilliseconds(Interval);
                var size     = 1.0 / stripCount;
                var rectSize = GetSize(size);
                if (newIndex > 0)
                {
                    m_counter = 0;
                    var start = (newIndex - 1) * size;
                    var end   = newIndex * size;
                    var step  = (end - start) / Steps;

                    m_slider = () =>
                    {
                        var move  = (start + m_counter * step) * Sign;
                        var point = GetPoint(move);
                        brush.Viewbox = new Rect(point, rectSize);
                        m_counter++;
                        return(m_counter > Steps);
                    };
                    m_timer.Start();
                }
                else
                {
                    var point = GetPoint(0);
                    brush.Viewbox = new Rect(point, rectSize);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Construct new SelectionRectVisual object for the given rectangle
        /// </summary>
        public SelectionRectVisual(Point firstPointP, Point secondPointP, double zoomP)
        {
            DrawingGroup   drawing = new DrawingGroup();
            DrawingContext context = drawing.Open();

            context.DrawRectangle(Brushes.White, null, new Rect(-1, -1, 3, 3));
            context.DrawRectangle(Brushes.Black, null, new Rect(0.25, -1, 0.5, 3));
            context.Close();
            drawing.Freeze();

            // Create a drawing brush that tiles the unit square from the drawing created above.
            // The size of the viewport and the rotation angle will be updated as we use the
            // dashed pen.
            DrawingBrush drawingBrush = new DrawingBrush(drawing);

            drawingBrush.ViewportUnits = BrushMappingMode.Absolute;
            drawingBrush.Viewport      = new Rect(0, 0, _dashRepeatLength, _dashRepeatLength);
            drawingBrush.ViewboxUnits  = BrushMappingMode.Absolute;
            drawingBrush.Viewbox       = new Rect(0, 0, 1, 1);
            drawingBrush.Stretch       = Stretch.Uniform;
            drawingBrush.TileMode      = TileMode.Tile;

            // Store the drawing brush and a copy that's rotated by 90 degrees.
            _horizontalDashBrush         = drawingBrush;
            _verticalDashBrush           = drawingBrush.Clone();
            _verticalDashBrush.Transform = new RotateTransform(90);

            this._firstPoint  = firstPointP;
            this._secondPoint = secondPointP;
            this._zoom        = zoomP;
            _visualForRect    = new DrawingVisual();
            this.AddVisualChild(_visualForRect);
            this.AddLogicalChild(_visualForRect);
        }
Esempio n. 5
0
 void CreateBrush()
 {
     if (brush == null)
     {
         brush = TileBrush.CreateBrush(map);
     }
 }
Esempio n. 6
0
    void CreateBrush()
    {
        Sprite sprite;

        if (needTilePrefab && TilePrebab != null)
        {
            sprite = ((GameObject)TilePrebab).GetComponent <SpriteRenderer>().sprite;
        }
        else
        {
            sprite = map.currentTileBrush;
        }

        if (sprite != null)
        {
            GameObject go = new GameObject("Brush");
            go.transform.SetParent(map.transform);

            brush            = go.AddComponent <TileBrush> ();
            brush.renderer2D = go.AddComponent <SpriteRenderer> ();
            brush.renderer2D.sortingOrder = 1000;

            var pixelsToUnits = map.pixelsToUnits;
            brush.brushSize = new Vector2(sprite.textureRect.width / pixelsToUnits,
                                          sprite.textureRect.height / pixelsToUnits);
            brush.UpdateBrush(sprite);
        }
    }
Esempio n. 7
0
 public MapBuilderCore()
 {
     Tiles      = new List <TileBrush>(20);
     EmptyGroud = new TileBrush('、', 999);
     EndDesign  = false;
     Brush      = new TileBrush('S', 1000);
 }
        private void OnDialogApply(object sender, EventArgs eventArgs)
        {
            Command command = null;

            if (m_newTileBrush != null)
            {
                command = new EditTileBrushesCommand(m_map, m_tileBrushCollection, m_newTileBrush);
            }
            else
            {
                TileBrushCollection newTileBrushCollection = new TileBrushCollection();

                foreach (ListViewItem listViewItem in m_listView.Items)
                {
                    // extract corresponding brushes and apply new ids
                    TileBrush newTileBrush = (TileBrush)listViewItem.Tag;

                    // add to collection
                    newTileBrushCollection.TileBrushes.Add(newTileBrush);
                }

                command = new EditTileBrushesCommand(m_map, m_tileBrushCollection, newTileBrushCollection);
            }

            CommandHistory.Instance.Do(command);

            MarkAsApplied();
        }
Esempio n. 9
0
        /// <summary>
        /// Calculates a _translate based on a <see cref="TileBrush"/>, a source and destination
        /// rectangle and a _scale.
        /// </summary>
        /// <param name="brush">The brush.</param>
        /// <param name="sourceRect">The source rectangle.</param>
        /// <param name="destinationRect">The destination rectangle.</param>
        /// <param name="scale">The _scale factor.</param>
        /// <returns>A vector with the X and Y _translate.</returns>

        public static Vector CalculateTranslate(
            TileBrush brush,
            Rect sourceRect,
            Rect destinationRect,
            Vector scale)
        {
            var x    = 0.0;
            var y    = 0.0;
            var size = sourceRect.Size * scale;

            switch (brush.AlignmentX)
            {
            case AlignmentX.Center:
                x += (destinationRect.Width - size.Width) / 2;
                break;

            case AlignmentX.Right:
                x += destinationRect.Width - size.Width;
                break;
            }

            switch (brush.AlignmentY)
            {
            case AlignmentY.Center:
                y += (destinationRect.Height - size.Height) / 2;
                break;

            case AlignmentY.Bottom:
                y += destinationRect.Height - size.Height;
                break;
            }

            return(new Vector(x, y));
        }
Esempio n. 10
0
        public EditCutCommand(Layer layer, TileSelection tileSelection)
        {
            m_layer             = layer;
            m_selectionLocation = tileSelection.Bounds.Location;
            m_tileSelection     = tileSelection;
            m_oldTiles          = null;

            m_description = "Cut selection from layer \"" + m_layer.Id + "\"";
        }
Esempio n. 11
0
        public EditDeleteCommand(Layer layer, TileSelection tileSelection)
        {
            m_layer             = layer;
            m_selectionLocation = tileSelection.Bounds.Location;
            m_tileSelection     = tileSelection;
            m_tileBrush         = null;

            m_description = "Erase selection from layer \"" + m_layer.Id + "\"";
        }
Esempio n. 12
0
 public void DestroyBrush()
 {
     if (brush != null)
     {
         var go = brush.gameObject;
         brush = null;
         DestroyImmediate(go);
     }
 }
Esempio n. 13
0
        public override void Do()
        {
            ClipBoardManager clipBoardManager = ClipBoardManager.Instance;

            m_previousClipboardContent = clipBoardManager.RetrieveTileBrush();
            m_oldTiles = new TileBrush(m_layer, m_tileSelection);
            clipBoardManager.StoreTileBrush(m_oldTiles);
            m_tileSelection.EraseTiles(m_layer);
        }
        public TileBrushDialog(Map map, TileBrushCollection tileBrushCollection)
        {
            InitializeComponent();

            m_map = map;
            m_tileBrushCollection = tileBrushCollection;
            m_newTileBrush        = null;
            m_selectedTileBrush   = null;
        }
        private void OnSelectedIndexChanged(object sender, EventArgs eventArgs)
        {
            bool selected = m_listView.SelectedIndices.Count > 0;

            m_renameButton.Enabled = m_deleteButton.Enabled = selected;

            m_selectedTileBrush = selected
                ? (TileBrush)m_listView.SelectedItems[0].Tag
                : null;
        }
Esempio n. 16
0
    private void selectTileBrush()
    {
        this.reset();
        mapRenderer.highlightLayer(tileSelector.SelectedTileLayer);
        selectedTileSprite.sprite = tileSelector.SelectedTileSprite;
        selectedTileSprite.transform.localScale = tileSelector.SelectedTileScale;
        TileBrush brush = new TileBrush(tileSelector.SelectedTilePrefabPath, tileSelector.SelectedTileScale, tileSelector.SelectedTileLayer, mapCreator);

        this.selecedTool = brush;
    }
Esempio n. 17
0
        private static BitmapBrushProperties GetBitmapBrushProperties(TileBrush brush)
        {
            var tileMode = brush.TileMode;

            return(new BitmapBrushProperties
            {
                ExtendModeX = GetExtendModeX(tileMode),
                ExtendModeY = GetExtendModeY(tileMode),
            });
        }
Esempio n. 18
0
        public TileBrushImplHelper(TileBrush brush, Size targetSize)
        {
            _imageBrush  = brush as ImageBrush;
            _visualBrush = brush as VisualBrush;
            if (_imageBrush != null)
            {
                if (_imageBrush.Source == null)
                {
                    return;
                }
                _imageSize = new Size(_imageBrush.Source.PixelWidth, _imageBrush.Source.PixelHeight);
                IsValid    = true;
            }
            else if (_visualBrush != null)
            {
                var visual = _visualBrush.Visual;
                if (visual == null)
                {
                    return;
                }
                var layoutable = visual as ILayoutable;

                if (layoutable != null)
                {
                    if (layoutable.IsArrangeValid == false)
                    {
                        layoutable.Measure(Size.Infinity);
                        layoutable.Arrange(new Rect(layoutable.DesiredSize));
                    }

                    _imageSize = layoutable.Bounds.Size;
                    IsValid    = true;
                }
            }
            else
            {
                return;
            }

            _tileMode        = brush.TileMode;
            _sourceRect      = brush.SourceRect.ToPixels(_imageSize);
            DestinationRect  = brush.DestinationRect.ToPixels(targetSize);
            _scale           = brush.Stretch.CalculateScaling(DestinationRect.Size, _sourceRect.Size);
            _translate       = CalculateTranslate(brush, _sourceRect, DestinationRect, _scale);
            IntermediateSize = CalculateIntermediateSize(_tileMode, targetSize, DestinationRect.Size);
            _transform       = CalculateIntermediateTransform(
                _tileMode,
                _sourceRect,
                DestinationRect,
                _scale,
                _translate,
                out _drawRect);
        }
Esempio n. 19
0
 private static BrushProperties GetBrushProperties(TileBrush brush, Rect destinationRect)
 {
     return(new BrushProperties
     {
         Opacity = (float)brush.Opacity,
         Transform = brush.TileMode != TileMode.None ?
                     SharpDX.Matrix3x2.Translation(
             (float)destinationRect.X,
             (float)destinationRect.Y) :
                     SharpDX.Matrix3x2.Identity,
     });
 }
Esempio n. 20
0
        /// <summary/>
        /// <param name="brush"/>
        /// <param name="random"/>
        protected void ApplyTileBrushProperties(TileBrush brush, DeterministicRandom random)
        {
            ApplyBrushProperties(brush, random);

            brush.AlignmentX    = random.NextEnum <AlignmentX>();
            brush.AlignmentY    = random.NextEnum <AlignmentY>();
            brush.Stretch       = random.NextEnum <Stretch>();
            brush.TileMode      = random.NextEnum <TileMode>();
            brush.Viewbox       = Viewbox;
            brush.ViewboxUnits  = random.NextEnum <BrushMappingMode>();
            brush.Viewport      = Viewport;
            brush.ViewportUnits = random.NextEnum <BrushMappingMode>();
        }
Esempio n. 21
0
        public override void Do()
        {
            TileSelection tileSelection = new TileSelection();

            m_tileBrush.GenerateSelection(m_brushLocation, tileSelection);
            m_oldTiles = new TileBrush(m_layer, tileSelection);

            m_tileBrush.ApplyTo(m_layer, m_brushLocation, m_tileSelection);
            if (!m_fromClipboard)
            {
                m_tileSelection.Clear();
            }
        }
Esempio n. 22
0
        private static BrushProperties GetBrushProperties(TileBrush brush, Rect destinationRect)
        {
            var tileTransform =
                brush.TileMode != TileMode.None ?
                Matrix.CreateTranslation(destinationRect.X, destinationRect.Y) :
                Matrix.Identity;

            return(new BrushProperties
            {
                Opacity = (float)brush.Opacity,
                Transform = tileTransform.ToDirect2D(),
            });
        }
        public EditTileBrushesCommand(
            Map map,
            TileBrushCollection currentTileBrushCollection,
            TileBrush newTileBrush)
        {
            m_map = map;
            m_currentTileBrushCollection = currentTileBrushCollection;
            m_oldTileBrushCollection     = new TileBrushCollection(currentTileBrushCollection);
            m_newTileBrushCollection     = new TileBrushCollection(currentTileBrushCollection);
            m_newTileBrushCollection.TileBrushes.Add(newTileBrush);

            m_description = "Make new tile brush";
        }
        private void SelectBrush(Guid brushId)
        {
            if (_selectedBrush == brushId)
            {
                return;
            }

            TileBrush prevBrush = _selectedBrushRef;
            TileBrush newBrush  = TileBrushManager.GetBrush(brushId);

            _selectedBrushRef = newBrush;

            OnSyncCurrentBrush(new SyncTileBrushEventArgs(prevBrush));
        }
Esempio n. 25
0
        protected override void SourceChangedCore(TileSourceType type)
        {
            ClearPreviewMarker();
            _activeBrush = null;

            if (type == TileSourceType.Brush)
                _activeBrush = ActiveBrush;

            if (Info != null) {
                if (type == TileSourceType.Tile && ActiveTile != null)
                    Info.InfoString = "Source: Tile " + ActiveTile.Uid;
                else if (type == TileSourceType.Brush && ActiveBrush != null)
                    Info.InfoString = "Source: Brush " + ActiveBrush.Name;
            }
        }
Esempio n. 26
0
        public EditPasteCommand(Layer layer,
                                TileBrush tileBrush, Location brushLocation,
                                TileSelection tileSelection, bool fromClipboard)
        {
            m_layer         = layer;
            m_tileBrush     = tileBrush;
            m_brushLocation = brushLocation;
            m_tileSelection = tileSelection;
            m_fromClipboard = fromClipboard;
            m_oldTiles      = null;

            m_description = fromClipboard
                ? "Paste copied tiles" : "Paste tile brush \"" + tileBrush.Id + "\"";
            m_description += " at " + m_brushLocation + " in layer \"" + m_layer.Id + "\"";
        }
Esempio n. 27
0
    private void CreateBrush()
    {
        var sprite = map.CurrentTileBrush;

        if (sprite != null)
        {
            var newGO = new GameObject("Brush");
            newGO.transform.SetParent(map.transform);
            brush            = newGO.AddComponent <TileBrush>();
            brush.rendered2D = newGO.AddComponent <SpriteRenderer>();
            var pixelsToUnits = map.pixelsToUnits;
            brush.brushSize = new Vector2(sprite.textureRect.width / pixelsToUnits, sprite.textureRect.height / pixelsToUnits);
            brush.UpdateBrush(sprite);
        }
    }
Esempio n. 28
0
    void CreateBrush()
    {
        Sprite sprite = board.currentTileBrush;

        if (sprite != null)
        {
            GameObject br = new GameObject("Brush");
            br.transform.SetParent(board.transform);
            brush            = br.AddComponent <TileBrush> ();
            brush.renderer2D = br.AddComponent <SpriteRenderer> ();
            brush.renderer2D.sortingOrder = 1000;
            int pixelsToUnit = board.pixelsToUnits;
            brush.brushSize = new Vector2(sprite.textureRect.width / pixelsToUnit, sprite.textureRect.height / pixelsToUnit);
            brush.UpdateBrush(sprite);
        }
    }
Esempio n. 29
0
    public static TileBrush CreateBrush(TileMap map)
    {
        var       sprite = map.currentTileBrush;
        TileBrush brush  = null;

        if (sprite)
        {
            GameObject go = new GameObject("Brush");
            go.transform.parent = map.transform;
            brush            = go.AddComponent <TileBrush>();
            brush.renderer2D = go.AddComponent <SpriteRenderer>();
            brush.brushSize  = new Vector2(sprite.textureRect.width / 100, sprite.textureRect.height / 100);
            brush.UpdateBrush(sprite);
        }

        return(brush);
    }
Esempio n. 30
0
        private static void CreateBrush()
        {
            DrawingGroup drawingGroup = new DrawingGroup();

            drawingGroup.Children.Add(new GeometryDrawing(Brushes.LightGray, null, new RectangleGeometry(new Rect(0, 0, 2, 2))));
            drawingGroup.Children.Add(new GeometryDrawing(Brushes.DarkGray, null,
                                                          Geometry.Combine(
                                                              new RectangleGeometry(new Rect(0, 0, 1, 1)),
                                                              new RectangleGeometry(new Rect(1, 1, 1, 1)),
                                                              GeometryCombineMode.Union,
                                                              null)
                                                          ));
            _checkerBrush = new DrawingBrush(drawingGroup);
            _checkerBrush.ViewportUnits = BrushMappingMode.Absolute;
            _checkerBrush.TileMode      = TileMode.Tile;
            CheckerBrush.Viewport       = new Rect(new Point(0, 0), new Size(32, 32));
        }
    void CreateBrush()
    {
        var sprite = map.currentTileBrush;

        if (sprite != null)
        {
            GameObject go = new GameObject("Brush");
            go.transform.SetParent(map.transform);
            brush            = go.AddComponent <TileBrush>();
            brush.renderer2D = go.AddComponent <SpriteRenderer>();
            brush.renderer2D.sortingOrder = 1000;


            var pixelsToUnits = map.pixlesToUnits;
            brush.brushSize = new Vector2(sprite.textureRect.width / pixelsToUnits, sprite.textureRect.height / pixelsToUnits);
            brush.UpdateBrush(sprite);
        }
    }
Esempio n. 32
0
	void OnEnable() {
		map = target as TileMap;
		brush = map.brush;
		Tools.current = Tool.View;

		//create new map
		if (map.tileManager == null) {
			var go = new GameObject("Tiles");
			go.transform.SetParent(map.transform);
			go.transform.position = Vector3.zero;
			go.layer = LayerMask.NameToLayer("Wall");
			map.tileManager = go.AddComponent<TileManager>();
		}

		//create new brush
		if (brush == null) {
			var sprite = map.currentTileBrush;
			if (sprite != null) {
				GameObject go = new GameObject("Brush");
				go.transform.SetParent(map.transform);

				brush = go.AddComponent<TileBrush>();
				brush.renderer2D = go.AddComponent<SpriteRenderer>();
				brush.renderer2D.sortingOrder = 1000;

				RefreshBrush();
			}
			//re-enable brush
		} else if (!brush.isActiveAndEnabled) {
			brush.gameObject.SetActive(true);

			if (map.texture2D != null) {
				UpdateCalculations();
				RefreshBrush();
			}
		}
	}
 public SyncTileBrushEventArgs(TileBrush brush)
 {
     PreviousBrush = brush;
 }
Esempio n. 34
0
    void CreateBrush()
    {
        if (brush == null)
        {

            brush = TileBrush.CreateBrush(map);
        }
    }
Esempio n. 35
0
 public TileBrushTool(Application application, Tileset Tileset, string brushFile)
     : base(application, Tileset, new TileSelection())
 {
     brush = TileBrush.loadFromFile(brushFile, Tileset);
     ActionName = "Tile Brush";
 }
Esempio n. 36
0
        private void StartDrag(PointerEventInfo info, ILevelGeometry viewport)
        {
            ClearPreviewMarker();
            _activeBrush = null;

            TileCoord location = TileLocation(info);

            int x = (int)(location.X * Layer.TileWidth);
            int y = (int)(location.Y * Layer.TileHeight);

            _band = new RubberBand(new Point(location.X, location.Y));
            _selectionAnnot = new SelectionAnnot(new Point((int)info.X, (int)info.Y)) {
                Fill = new SolidColorBrush(new Color(76, 178, 255, 128)),
            };

            _annots.Add(_selectionAnnot);

            //StartAutoScroll(info, viewport);
        }
Esempio n. 37
0
        private void EndDrag(PointerEventInfo info, ILevelGeometry viewport)
        {
            Rectangle selection = ClampSelection(_band.Selection);

            StaticTileBrush anonBrush = new StaticTileBrush("User Selected", Layer.TileWidth, Layer.TileHeight);
            foreach (LocatedTile tile in Layer.TilesAt(_band.Selection))
                anonBrush.AddTile(new TileCoord(tile.X - _band.Selection.Left, tile.Y - _band.Selection.Top), tile.Tile);

            anonBrush.Normalize();

            _activeBrush = anonBrush;

            _annots.Remove(_selectionAnnot);
            _selectionAnnot = null;

            //EndAutoScroll(info, viewport);
        }
        private void SelectBrush(Guid brushId)
        {
            if (_selectedBrush == brushId)
                return;

            TileBrush prevBrush = _selectedBrushRef;
            TileBrush newBrush = TileBrushManager.GetBrush(brushId);

            _selectedBrushRef = newBrush;

            OnSyncCurrentBrush(new SyncTileBrushEventArgs(prevBrush));
        }
Esempio n. 39
0
    /// <summary>
    /// Creates a new Brush by loading a list of valid patterns from the given file
    /// </summary>
    // TODO: change file syntax from CSV to Lisp
    public static TileBrush loadFromFile(string fname, Tileset tileset)
    {
        FileStream fs = new FileStream(fname, FileMode.Open);
        TextReader trd = new StreamReader(fs);

        TileBrush brush = new TileBrush(3, 3, tileset);

        try {
            string s;
            while ((s = trd.ReadLine()) != null) {
                string[] v = s.Split(',');
                if (v.Length < 9) continue;
                TileBlock tb = (TileBlock)new TileBlock(3,3,0);
                tb[0, 0] = int.Parse(v[0]);
                tb[1, 0] = int.Parse(v[1]);
                tb[2, 0] = int.Parse(v[2]);
                tb[0, 1] = int.Parse(v[3]);
                tb[1, 1] = int.Parse(v[4]);
                tb[2, 1] = int.Parse(v[5]);
                tb[0, 2] = int.Parse(v[6]);
                tb[1, 2] = int.Parse(v[7]);
                tb[2, 2] = int.Parse(v[8]);
                if (brush.FindPattern(tb) == null) brush.patterns.Add(tb);
            }
        } finally {
            trd.Close();
            fs.Close();
        }

        return brush;
    }