public IAnimation LoadAnimationFromSpriteSheet(ISpriteSheet spriteSheet, IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null) { animationConfig = animationConfig ?? new AGSAnimationConfiguration(); string filePath = spriteSheet.Path; IResource resource = _resources.LoadResource(filePath); if (resource == null) { throw new InvalidOperationException("Failed to load sprite sheet from " + filePath); } IBitmap bitmap = _bitmapLoader.Load(resource.Stream); int cellsGrabbed = 0; getSpriteSheetData(bitmap, spriteSheet, animationConfig, out int cellsInRow, out int cellsInCol, out int _, out int cellX, out int cellY, out int cellsToGrab, out Point mainStep, out Point secondStep, out AGSAnimation animation); for (int currentCell = 0; cellsGrabbed < cellsToGrab; currentCell++) { if (currentCell >= spriteSheet.StartFromCell) { getImageInfo(bitmap, cellX, cellY, spriteSheet, loadConfig, filePath, out Rectangle _, out IBitmap clone, out string path, out ITexture tex); IImage image = _loadImage(tex, clone, path, loadConfig, spriteSheet); _addAnimationFrame(image, animation); cellsGrabbed++; } nextCell(mainStep, secondStep, cellsInRow, cellsInCol, ref cellX, ref cellY); } animation.Setup(); return(animation); }
public IMask Load(string path, bool transparentMeansMasked = false, Color? debugDrawColor = null, string saveMaskToFile = null, string id = null) { Debug.WriteLine("MaskLoader: Load " + path ?? "null"); var resource = _resourceLoader.LoadResource(path); IBitmap image = _bitmapLoader.Load(resource.Stream); return load(path, image, transparentMeansMasked, debugDrawColor, saveMaskToFile, id); }
private ITexture initEmptyTexture() { var bitmap = _bitmapLoader.Load(1, 1); bitmap.SetPixel(Colors.White, 0, 0); return(_graphicsFactory.LoadImage(bitmap, new AGSLoadImageConfig(config: new AGSTextureConfig(scaleUp: ScaleUpFilters.Nearest))).Texture); }
private ObjectPool <IBitmap> getPool(int width, int height) { Size size = new Size(width, height); return(_bitmaps.GetOrAdd(size, _ => new ObjectPool <IBitmap> (__ => _bitmapLoader.Load(width, height), 3, bitmap => bitmap.Clear()))); }
private IImage loadImage(IResource resource, ILoadImageConfig config = null) { IImage image = null; _renderThread.RunBlocking(() => { ITexture tex = createTexture(config); try { IBitmap bitmap = _bitmapLoader.Load(resource.Stream); image = loadImage(tex, bitmap, resource.ID, config, null); } catch (ArgumentException e) { Debug.WriteLine("Failed to load image from {0}, is it really an image?\r\n{1}", resource.ID, e.ToString()); } }); return(image); }
public IBitmap GetBitmap(int width, int height) { return(_bitmapLoader.Load(width, height)); }
public DinosaurDetailsViewModel( int id, IBitmapLoader bitmapLoader = null, IApi api = null) { bitmapLoader = bitmapLoader ?? Locator.Current.GetService <IBitmapLoader>(); api = api ?? Locator.Current.GetService <IApi>(); this.id = id; this.api = api; this.activator = new ViewModelActivator(); var publishedIsActivated = this .GetIsActivated() .Publish(); this.getCommand = ReactiveCommand.CreateFromObservable( this.GetDinosaur); this.saveCommand = ReactiveCommand.CreateFromObservable( this.SaveDinosaur); this.confirmDeleteInteraction = new Interaction <Unit, bool>(); var canDelete = publishedIsActivated .Select( isActivated => { if (!isActivated) { return(Observable.Empty <bool>()); } // For the purposes of this sample, we assume IsAuditingAvailable ticks on the main thread. Otherwise, we'd need an ObserveOn. return(this.api.IsAuditingAvailable); }) .Switch(); this.deleteCommand = ReactiveCommand.CreateFromObservable( this.DeleteDinosaur, canDelete); this.isBusy = Observable .CombineLatest( this.getCommand.IsExecuting, this.saveCommand.IsExecuting, this.deleteCommand.IsExecuting, (isGetting, isSaving, isDeleting) => isGetting || isSaving || isDeleting) .ToProperty(this, x => x.IsBusy); this.validatedWeight = this .WhenAnyValue(x => x.Weight) .Select( weight => { if (int.TryParse(weight, out var validatedWeight)) { return(Validated <int> .WithValue(validatedWeight)); } return(Validated <int> .WithError($"'{weight}' is not a valid weight. Please enter whole numbers only.")); }) .ToProperty(this, x => x.ValidatedWeight); this.image = this .WhenAnyValue(x => x.ImageData) .SelectMany( imageData => Observable .Using( () => new MemoryStream(imageData ?? Array.Empty <byte>()), stream => bitmapLoader.Load(stream, null, null).ToObservable())) .ToProperty(this, x => x.Image); this .getCommand .Subscribe(this.PopulateFrom); publishedIsActivated .Where(isActivated => isActivated) .Select(_ => Unit.Default) .InvokeCommand(this.getCommand); var shouldSave = Observable .Merge( this .WhenAnyValue(x => x.Name, x => x.ValidatedWeight, x => x.Image, IsValid) .Skip(1) .Where(isValid => isValid) .Throttle(TimeSpan.FromSeconds(2), RxApp.MainThreadScheduler) .Select(_ => Unit.Default), publishedIsActivated .Where(isActivated => !isActivated) .Select(_ => Unit.Default)); shouldSave .InvokeCommand(this.saveCommand); publishedIsActivated .Connect(); this.error = Observable .Merge( this .getCommand .ThrownExceptions .Select(ex => new Error(ex, this.getCommand)), this .getCommand .Select(_ => (Error)null), this .saveCommand .ThrownExceptions .Select(ex => new Error(ex, this.saveCommand)), this .saveCommand .Select(_ => (Error)null), this .deleteCommand .ThrownExceptions .Select(ex => new Error(ex, this.deleteCommand)), this .deleteCommand .Select(_ => (Error)null)) .ToProperty(this, x => x.Error); }