Example #1
0
 public TextureCoordinateRect(TextureCoordinatePoint point, IntDimension size)
 {
     this.X      = point.X;
     this.Y      = point.Y;
     this.Width  = size.Width;
     this.Height = size.Height;
 }
Example #2
0
 public CityBarRenderingFactory(GameRenderingConfig renderingConfig,
                                StrategyGameData gameData,
                                IntDimension tileSize,
                                Group widgetParent) : base(renderingConfig, gameData, tileSize)
 {
     this.widgetParent = widgetParent;
 }
Example #3
0
        public TextureCoordinateRect TileAreaForCardinalDirection(IntDimension ts, CardinalIndex dir)
        {
            var w     = ts.Width;
            var h     = ts.Height;
            var wHalf = ts.Width / 2;
            var hHalf = ts.Height / 2;

            switch (dir)
            {
            case CardinalIndex.West:
                return(new TextureCoordinateRect(0, 0, wHalf, hHalf));

            case CardinalIndex.North:
                return(new TextureCoordinateRect(wHalf, 0, w - wHalf, hHalf));

            case CardinalIndex.East:
                return(new TextureCoordinateRect(wHalf, hHalf, w - wHalf, h - hHalf));

            case CardinalIndex.South:
                return(new TextureCoordinateRect(0, hHalf, wHalf, h - hHalf));

            default:
                throw new ArgumentException();
            }
        }
Example #4
0
        void ApplyInsert(IntDimension size, T c)
        {
            if (c == null)
            {
                throw new ArgumentNullException();
            }

            if (Content != null)
            {
                throw new InvalidOperationException();
            }

            if (!Fits(size))
            {
                throw new InvalidOperationException();
            }

            Content = c;
            width   = size.Width;
            height  = size.Height;

            var s = this.Split(size);

            left   = s.Item1;
            bottom = s.Item2;
        }
Example #5
0
 public void StartDrawing()
 {
     tileSize  = new IntDimension(2, 2);
     drawn     = 0;
     discarded = 0;
     Console.Clear();
 }
Example #6
0
        protected CityBarRenderingFactoryBase(GameRenderingConfig renderingConfig,
                                              StrategyGameData gameData,
                                              IntDimension tileSize)
        {
            RenderingConfig = renderingConfig ?? throw new ArgumentNullException(nameof(RenderingConfig));
            GameData        = gameData ?? throw new ArgumentNullException(nameof(GameData));

            RenderControl = new RendererControl(tileSize, renderingConfig.RenderType);
        }
Example #7
0
        public TTile Produce(IntDimension tileSize, IntRect gridBounds, IntPoint anchor, string tag, TRawTexture texture)
        {
            var subTextureName   = tag + "@" + texture.Name;
            var subTextureBounds = texture.Bounds.Clip(gridBounds);
            var nativeBounds     = textureOperations.ToNative(texture.Bounds.Size, subTextureBounds);
            var nativeTexture    = texture.CreateSubTexture(subTextureName, nativeBounds);
            var atlasTexture     = textureAtlas.Add(nativeTexture);

            return(CreateTile(tag, atlasTexture, tileSize, anchor));
        }
Example #8
0
        public IEnumerable <TTile> ProduceAll(IntDimension tileSize, IntPoint anchor, IEnumerable <string> tags, TTexture texture)
        {
            var tagsAsList   = tags.ToArray();
            var atlasTexture = textureAtlas.Add(texture);

            foreach (var tileTag in tagsAsList)
            {
                yield return(CreateTile(tileTag, atlasTexture, tileSize, anchor));
            }
        }
Example #9
0
        public XnaTexture CreateTexture(string name, IntDimension textureSize, bool clearToTransparentBlack = true)
        {
            var texture = new Texture2D(device, textureSize.Width, textureSize.Height, false, SurfaceFormat.Color);

            if (clearToTransparentBlack)
            {
                texture.SetData(FillClearTextureCache(textureSize));
            }

            return(new XnaTexture(name, new TextureCoordinateRect(0, 0, textureSize.Width, textureSize.Height), texture));
        }
Example #10
0
        IntDimension ComputeTextSize(IntDimension contentSize)
        {
            var title = grid.FormattingMetaData.Title;

            if (string.IsNullOrEmpty(title))
            {
                return(new IntDimension());
            }

            return(prefs.DefaultFont.MeasureText(title, contentSize.Width));
        }
Example #11
0
        public DungeonTileSet(IContentLoader <TRawTexture> loader,
                              ITileProducer <TTile, TTexture, TRawTexture> producer)
        {
            this.loader   = loader;
            this.producer = producer;

            TileSize = new IntDimension(50, 24);
            tp       = new TexturePack <TTile>("default",
                                               TileSize,
                                               TextureType.Isometric,
                                               LoadDecorations().ToArray());
        }
Example #12
0
        bool Fits(IntDimension c)
        {
            if (c.Height > SpaceAvailableY)
            {
                return(false);
            }

            if (c.Width > SpaceAvailableX)
            {
                return(false);
            }

            return(true);
        }
Example #13
0
        public MonoGameRenderer(IGraphicsDeviceService graphicsDeviceService,
                                IRendererControl viewport)
        {
            Viewport    = viewport ?? throw new ArgumentNullException(nameof(viewport));
            SpriteBatch = new SpriteBatch(graphicsDeviceService.GraphicsDevice);

            this.GraphicsDeviceService = graphicsDeviceService;
            offsetsBySpritePosition    = SpritePositionExtensions.OffsetsFor(viewport.ActiveRenderType);

            tileSize = viewport.TileSize;

            enableScissorTest = RasterizerState.CullCounterClockwise.Copy();
            enableScissorTest.ScissorTestEnable = true;
        }
Example #14
0
        public TexturePack(string name,
                           IntDimension tileSize,
                           TextureType textureType,
                           params ITextureFile <TTile>[] textureFiles)
        {
            TileSize    = tileSize;
            TextureType = textureType;
            if (textureFiles == null)
            {
                throw new ArgumentNullException(nameof(textureFiles));
            }

            Name         = name ?? throw new ArgumentNullException(nameof(name));
            TextureFiles = new List <ITextureFile <TTile> >(textureFiles);
        }
Example #15
0
        public GridTextureFile(string name,
                               IntDimension tileSize,
                               [NotNull] ITileProducer <TTile, TTexture, TRawTexture> producer,
                               [NotNull] IContentLoader <TRawTexture> loader,
                               params TileGrid[] grids)
        {
            if (grids == null)
            {
                throw new ArgumentNullException(nameof(grids));
            }

            this.tileSize = tileSize;
            this.producer = producer ?? throw new ArgumentNullException(nameof(producer));
            this.loader   = loader ?? throw new ArgumentNullException(nameof(loader));
            Name          = name ?? throw new ArgumentNullException(nameof(name));
            Grids         = new List <TileGrid>(grids);
        }
Example #16
0
        Color[] FillClearTextureCache(IntDimension tileSize)
        {
            var l = tileSize.Width * tileSize.Height;

            if (clearTexturesCache.TryGetValue(l, out var t))
            {
                if (t.TryGetTarget(out var cacheColorArray))
                {
                    return(cacheColorArray);
                }
            }

            var clearColorArray = new Color[tileSize.Width * tileSize.Height];

            clearTexturesCache[l] = new WeakReference <Color[]>(clearColorArray);
            return(clearColorArray);
        }
Example #17
0
        public IEnumerable <TTile> ProduceAll(IntDimension tileSize,
                                              IntRect gridBounds,
                                              IntPoint anchor,
                                              IEnumerable <string> tags,
                                              TRawTexture texture)
        {
            var tagsAsList       = tags.ToArray();
            var subTextureName   = string.Join(",", tagsAsList);
            var subTextureBounds = texture.Bounds.Clip(gridBounds);
            var nativeBounds     = textureOperations.ToNative(texture.Bounds.Size, subTextureBounds);
            var nativeTexture    = texture.CreateSubTexture(subTextureName, nativeBounds);
            var atlasTexture     = textureAtlas.Add(nativeTexture);

            foreach (var tileTag in tagsAsList)
            {
                yield return(CreateTile(tileTag, atlasTexture, tileSize, anchor));
            }
        }
Example #18
0
        public SKBitmap CreateBitmap(TileTextureCollection c, int scale = 1, SKBitmap?bmp = null)
        {
            scale = Math.Max(scale, 1);

            var expectedSize = ComputeRenderedSize(c);

            expectedSize = new IntDimension(expectedSize.Width * scale, expectedSize.Height * scale);
            if (bmp == null || bmp.Width != expectedSize.Width || bmp.Height != expectedSize.Height)
            {
                bmp?.Dispose();
                bmp = new SKBitmap(expectedSize.Width, expectedSize.Height);
            }

            using var ctx = new SKCanvas(bmp);
            ctx.Scale(scale, scale);
            ctx.Clear(SKColor.Empty);
            Produce(ctx, c);
            return(bmp);
        }
Example #19
0
        public ArrangeNode <T>?FindInsertPosition(IntDimension size)
        {
            if (Content == null)
            {
                if (Fits(size))
                {
                    Logger.Verbose("Choosing <empty node>");
                    return(this);
                }

                Logger.Verbose("Rejecting <empty node>");
                return(null);
            }

            Logger.Verbose("Choosing .. {Content}", Content);

            var leftPos   = left?.FindInsertPosition(size);
            var bottomPos = bottom?.FindInsertPosition(size);

            if (leftPos == null)
            {
                Logger.Verbose("Choosing bottom by default for {Content}", Content);
                return(bottomPos);
            }

            if (bottomPos == null)
            {
                Logger.Verbose("Choosing left by default for {Content}", Content);
                return(leftPos);
            }

            var weightLeft   = leftPos.ComputeWeight(size);
            var weightBottom = bottomPos.ComputeWeight(size);

            if (weightLeft <= weightBottom)
            {
                Logger.Verbose("Choosing left for {Content}", Content);
                return(leftPos);
            }

            Logger.Verbose("Choosing bottom for {Content}", Content);
            return(bottomPos);
        }
Example #20
0
        public BlendingTileGenerator(ITileRegistry <TTile> tileRegistry,
                                     ITextureOperations <TTexture, TColor> textureOperations,
                                     IDerivedTileProducer <TTile, TTexture> tileProducer,
                                     RenderType renderType,
                                     IntDimension tileSize,
                                     TTile ditherMask,
                                     string prefix = "t.blend.gen.")
        {
            this.tileRegistry      = tileRegistry ?? throw new ArgumentNullException(nameof(tileRegistry));
            this.tileProducer      = tileProducer;
            this.renderType        = renderType;
            this.tileSize          = tileSize;
            this.ditherMask        = ditherMask;
            this.prefix            = prefix ?? "t.blend.gen";
            this.textureOperations = textureOperations ?? throw new ArgumentNullException(nameof(textureOperations));

            cardinalMaskRegistry = CardinalIndexTileRegistry <TTile> .CreateLong(tileRegistry);

            this.maskCache = PopulateCache();
        }
Example #21
0
        public bool Insert(IntDimension size, T c)
        {
            Logger.Verbose("Start Insert {Content}", c);

            try
            {
                var insertPos = FindInsertPosition(size);
                if (insertPos != null)
                {
                    insertPos.ApplyInsert(size, c);
                    return(true);
                }

                return(false);
            }
            finally
            {
                Logger.Verbose("Done Insert {Content}", c);
            }
        }
Example #22
0
        IntDimension ComputeGridSize(IntDimension labelSize, IntDimension contentSize)
        {
            var textSizeWithSpacing = labelSize.Height;

            if (textSizeWithSpacing > 0)
            {
                textSizeWithSpacing += prefs.TextSpacing;
            }

            var(w, h) = (Math.Max(contentSize.Width, labelSize.Width),
                         contentSize.Height + textSizeWithSpacing);

            var border  = grid.FormattingMetaData.Border ?? 0;
            var padding = grid.FormattingMetaData.Padding ?? 0;

            w += 2 * border;
            w += 2 * padding;
            h += 2 * border;
            h += 2 * padding;
            return(new IntDimension(w, h));
        }
Example #23
0
        public bool TryGenerate(string tag, CardinalIndex direction, out TTile tile)
        {
            var etag = $"{prefix}{tag}_{direction}";

            if (tileRegistry.TryFind(etag, out var predefined))
            {
                tile = predefined;
                return(true);
            }

            var sourceArea = textureOperations.TileAreaForCardinalDirection(tileSize, direction);

            if (!TryFindSourceMask(direction, out var effectiveMask, out var anchor))
            {
                tile = default;
                return(false);
            }

            if (!tileRegistry.TryFind(tag, out var terrain) ||
                !terrain.HasTexture)
            {
                tile = default;
                return(false);
            }

            var data   = textureOperations.ExtractData(terrain.Texture, sourceArea);
            var result = textureOperations.CombineMask(data, effectiveMask);

            var wrappedTextureSize = new IntDimension(tileSize.Width, tileSize.Height);
            var wrappedTexture     = textureOperations.CreateTexture(etag, wrappedTextureSize);

            textureOperations.ApplyTextureData(wrappedTexture, result, sourceArea.Origin);

            tile = tileProducer.Produce(tileSize, anchor, etag, wrappedTexture);
            return(true);
        }
Example #24
0
        public static bool TryCreate <TTile, TTexture, TColor>(
            out BlendingTileGeneratorRegistry <TTile, TTexture, TColor> result,
            ITileRegistry <TTile> tileRegistry,
            RenderType renderType,
            ITextureOperations <TTexture, TColor> textureOperations,
            IDerivedTileProducer <TTile, TTexture> tileProducer,
            IntDimension tileSize,
            string prefix         = null,
            string ditherMaskName = null)
            where TTile : ITexturedTile <TTexture>
            where TTexture : ITexture
        {
            if (!TryFindDitherMask(out var ditherMask, tileRegistry, ditherMaskName))
            {
                result = default;
                return(false);
            }

            var generator = new BlendingTileGenerator <TTile, TTexture, TColor>(tileRegistry,
                                                                                textureOperations, tileProducer, renderType, tileSize, ditherMask, prefix);

            result = new BlendingTileGeneratorRegistry <TTile, TTexture, TColor>(generator);
            return(true);
        }
Example #25
0
        public TTile Produce(IntDimension tileSize, IntPoint anchor, string tag, TTexture texture)
        {
            var atlasTexture = textureAtlas.Add(texture);

            return(CreateTile(tag, atlasTexture, tileSize, anchor));
        }
Example #26
0
        public BoundedTextureData <Color> CreateClearTexture(IntDimension size)
        {
            var data = FillClearTextureCache(size);

            return(new BoundedTextureData <Color>(new TextureCoordinateRect(0, 0, size.Width, size.Height), data));
        }
Example #27
0
 protected abstract TTile CreateTile(string tag, TTexture texture, IntDimension tileSize, IntPoint anchor);
Example #28
0
 protected override MonoGameTile CreateTile(string tag, XnaTexture texture, IntDimension tileSize, IntPoint anchor)
 {
     return(new MonoGameTile(tag, texture, anchor));
 }
Example #29
0
 public TextureCoordinateRect ToNative(IntDimension context, IntRect src)
 {
     return(new TextureCoordinateRect(src.X, src.Y, src.Width, src.Height));
 }
Example #30
0
 double ComputeWeight(IntDimension s)
 {
     return(Math.Pow(X + s.Width, 2) + Math.Pow(Y + s.Height, 2));
 }