public TextureCoordinateRect(TextureCoordinatePoint point, IntDimension size) { this.X = point.X; this.Y = point.Y; this.Width = size.Width; this.Height = size.Height; }
public CityBarRenderingFactory(GameRenderingConfig renderingConfig, StrategyGameData gameData, IntDimension tileSize, Group widgetParent) : base(renderingConfig, gameData, tileSize) { this.widgetParent = widgetParent; }
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(); } }
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; }
public void StartDrawing() { tileSize = new IntDimension(2, 2); drawn = 0; discarded = 0; Console.Clear(); }
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); }
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)); }
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)); } }
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)); }
IntDimension ComputeTextSize(IntDimension contentSize) { var title = grid.FormattingMetaData.Title; if (string.IsNullOrEmpty(title)) { return(new IntDimension()); } return(prefs.DefaultFont.MeasureText(title, contentSize.Width)); }
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()); }
bool Fits(IntDimension c) { if (c.Height > SpaceAvailableY) { return(false); } if (c.Width > SpaceAvailableX) { return(false); } return(true); }
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; }
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); }
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); }
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); }
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)); } }
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); }
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); }
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(); }
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); } }
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)); }
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); }
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); }
public TTile Produce(IntDimension tileSize, IntPoint anchor, string tag, TTexture texture) { var atlasTexture = textureAtlas.Add(texture); return(CreateTile(tag, atlasTexture, tileSize, anchor)); }
public BoundedTextureData <Color> CreateClearTexture(IntDimension size) { var data = FillClearTextureCache(size); return(new BoundedTextureData <Color>(new TextureCoordinateRect(0, 0, size.Width, size.Height), data)); }
protected abstract TTile CreateTile(string tag, TTexture texture, IntDimension tileSize, IntPoint anchor);
protected override MonoGameTile CreateTile(string tag, XnaTexture texture, IntDimension tileSize, IntPoint anchor) { return(new MonoGameTile(tag, texture, anchor)); }
public TextureCoordinateRect ToNative(IntDimension context, IntRect src) { return(new TextureCoordinateRect(src.X, src.Y, src.Width, src.Height)); }
double ComputeWeight(IntDimension s) { return(Math.Pow(X + s.Width, 2) + Math.Pow(Y + s.Height, 2)); }