public DinosaurDetailsViewModel(
            int id,
            IBitmapLoader bitmapLoader,
            IApi api,
            IScheduler scheduler)
        {
            this.id        = id;
            this.api       = api;
            this.activator = new ViewModelActivator();

            using (GetSharedIsActivated(this, out var isActivated))
            {
                this.confirmDeleteInteraction = new Interaction <Unit, bool>();
                this.getCommand      = CreateGetCommand(this, scheduler);
                this.saveCommand     = CreateSaveCommand(this, scheduler);
                this.deleteCommand   = CreateDeleteCommand(this, api, scheduler, isActivated);
                this.isBusy          = TrueWhilstAnyCommandIsExecuting(this, this.getCommand, this.saveCommand, this.deleteCommand);
                this.validatedWeight = IntegralWeightsFrom(this);
                this.image           = BitmapsFromImageDataIn(this, bitmapLoader);
                this.error           = MergeErrorsIn(this, this.getCommand, this.saveCommand, this.deleteCommand);

                PopulateFromGetCommandResults(this);
                GetDataUponActivation(this.getCommand, isActivated);
                SaveDataTwoSecondsAfterItChanges(this, scheduler, isActivated, this.saveCommand);
            }
        }
Exemplo n.º 2
0
 public DinosaurDetailsViewModelBuilder()
 {
     this.activate       = true;
     this.id             = 42;
     this.bitmapLoader   = new BitmapLoaderMockBuilder().Build();
     this.api            = new ApiMockBuilder().Build();
     this.mainScheduler  = CurrentThreadScheduler.Instance;
     this.timerScheduler = new SchedulerMock();
 }
Exemplo n.º 3
0
        public GLGraphicsFactory (Dictionary<string, ITexture> textures, IContainer resolver, IGLUtils glUtils, IGraphicsBackend graphics)
		{
			this._textures = textures;
			this._resolver = resolver;
			this._resources = resolver.Resolve<IResourceLoader>();
			this._bitmapLoader = Hooks.BitmapLoader;
            this._spriteSheetLoader = new SpriteSheetLoader (_resources, _bitmapLoader, addAnimationFrame, loadImage, graphics);
            
            AGSGameSettings.CurrentSkin = new AGSBlueSkin(this, glUtils).CreateSkin();
		}
Exemplo n.º 4
0
		public SpriteSheetLoader (IResourceLoader resources, IBitmapLoader bitmapLoader, 
                                  Action<IImage, AGSAnimation> addAnimationFrame,
                                  Func<ITexture, IBitmap, string, ILoadImageConfig, ISpriteSheet, IImage> loadImage,
                                  IGraphicsBackend graphics)
		{
            _graphics = graphics;
			_resources = resources;
			_bitmapLoader = bitmapLoader;
			_addAnimationFrame = addAnimationFrame;
			_loadImage = loadImage;
		}
Exemplo n.º 5
0
 public SpriteSheetLoader(IResourceLoader resources, IBitmapLoader bitmapLoader,
                          Action <IImage, AGSAnimation> addAnimationFrame,
                          Func <ITexture, IBitmap, string, ILoadImageConfig, ISpriteSheet, IImage> loadImage,
                          IGraphicsBackend graphics)
 {
     _graphics          = graphics;
     _resources         = resources;
     _bitmapLoader      = bitmapLoader;
     _addAnimationFrame = addAnimationFrame;
     _loadImage         = loadImage;
 }
Exemplo n.º 6
0
        public GLGraphicsFactory(Dictionary <string, ITexture> textures, IContainer resolver, IGLUtils glUtils,
                                 IGraphicsBackend graphics, IBitmapLoader bitmapLoader, IUIThread uiThread)
        {
            this._uiThread          = uiThread;
            this._textures          = textures;
            this._resolver          = resolver;
            this._resources         = resolver.Resolve <IResourceLoader>();
            this._bitmapLoader      = bitmapLoader;
            this._spriteSheetLoader = new SpriteSheetLoader(_resources, _bitmapLoader, addAnimationFrame, loadImage, graphics);

            AGSGameSettings.CurrentSkin = new AGSBlueSkin(this, glUtils).CreateSkin();
        }
Exemplo n.º 7
0
        public IBitmapImage Capture(IBitmapLoader BitmapLoader)
        {
            if (_syncContext == null)
            {
                return(_captureWebcam.GetFrame(BitmapLoader));
            }

            IBitmapImage image = null;

            _syncContext.Run(() => image = _captureWebcam.GetFrame(BitmapLoader));

            return(image);
        }
Exemplo n.º 8
0
#pragma warning restore CS0067

        public GLLabelRenderer(Dictionary <string, ITexture> textures,
                               IBoundingBoxBuilder boundingBoxBuilder, IGLColorBuilder colorBuilder,
                               IGLTextureRenderer textureRenderer, BitmapPool bitmapPool, IGLViewportMatrixFactory viewportMatrix,
                               AGSBoundingBoxes labelBoundingBoxes, AGSBoundingBoxes textBoundingBoxes, IGraphicsFactory graphicsFactory,
                               IGLUtils glUtils, IGraphicsBackend graphics, IBitmapLoader bitmapLoader, IFontLoader fonts,
                               IRuntimeSettings settings, IRenderMessagePump messagePump, IGameState state, IGameEvents events)
        {
            _bindings = new List <IComponentBinding>();
            _afterCropTextBoundingBoxes = new AGSBoundingBoxes();
            _state                       = state;
            _events                      = events;
            Width                        = 1f;
            Height                       = 1f;
            _matricesPool                = new GLMatrices[3];
            _messagePump                 = messagePump;
            OnLabelSizeChanged           = new AGSEvent();
            _glUtils                     = glUtils;
            _graphics                    = graphics;
            _fonts                       = fonts;
            _bitmapPool                  = bitmapPool;
            _viewport                    = viewportMatrix;
            _textureRenderer             = textureRenderer;
            _labelBoundingBoxes          = labelBoundingBoxes;
            _textBoundingBoxes           = textBoundingBoxes;
            _boundingBoxBuilder          = boundingBoxBuilder;
            _virtualResolution           = settings.VirtualResolution;
            _settings                    = settings;
            _labelBoundingBoxFakeBuilder = new BoundingBoxesEmptyBuilder();
            _bgRenderer                  = new GLImageRenderer(textures,
                                                               colorBuilder, _textureRenderer, graphicsFactory, glUtils, bitmapLoader);

            _colorBuilder = colorBuilder;

            TextVisible           = true;
            TextBackgroundVisible = true;

            subscribeTextConfigChanges();
            PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(TextBackgroundVisible))
                {
                    return;
                }
                onBoundingBoxShouldChange();
                if (e.PropertyName == nameof(Config))
                {
                    subscribeTextConfigChanges();
                }
            };
            _shouldUpdateBoundingBoxes = true;
        }
Exemplo n.º 9
0
        public GLGraphicsFactory(Dictionary <string, ITexture> textures, Resolver resolver, IGLUtils glUtils,
                                 IGraphicsBackend graphics, IBitmapLoader bitmapLoader, IRenderThread renderThread,
                                 IResourceLoader resources, IIconFactory icons, IBrushLoader brushes, IRenderMessagePump messagePump)
        {
            Icons              = icons;
            Brushes            = brushes;
            _renderThread      = renderThread;
            _textures          = textures;
            _resolver          = resolver;
            _resources         = resources;
            _bitmapLoader      = bitmapLoader;
            _spriteSheetLoader = new SpriteSheetLoader(_resources, _bitmapLoader, addAnimationFrame, loadImage, graphics, messagePump);

            AGSGameSettings.CurrentSkin = new AGSBlueSkin(this, glUtils).CreateSkin();
        }
Exemplo n.º 10
0
 public GLImageRenderer(Dictionary <string, ITexture> textures,
                        IGLColorBuilder colorBuilder, IGLTextureRenderer renderer,
                        IGraphicsFactory graphicsFactory, IGLUtils glUtils,
                        IBitmapLoader bitmapLoader)
 {
     _graphicsFactory   = graphicsFactory;
     _createTextureFunc = createNewTexture; //Creating a delegate in advance to avoid memory allocations on critical path
     _textures          = textures;
     _colorBuilder      = colorBuilder;
     _renderer          = renderer;
     _glUtils           = glUtils;
     _bitmapLoader      = bitmapLoader;
     _emptyTexture      = new Lazy <ITexture>(() => initEmptyTexture());
     _colorAdjusters    = new IHasImage[2];
 }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the current frame from the buffer.
        /// </summary>
        /// <returns>The Bitmap of the frame.</returns>
        public IDisposable GetFrame(IBitmapLoader BitmapLoader)
        {
            if (_actualGraphState != GraphState.Rendered)
            {
                return(null);
            }

            //Asks for the buffer size.
            var bufferSize = 0;

            _sampGrabber.GetCurrentBuffer(ref bufferSize, IntPtr.Zero);

            if (bufferSize <= 0)
            {
                return(null);
            }

            if (_savedArray == null || _savedArray.Length < bufferSize)
            {
                _savedArray = new byte[bufferSize + 64000];
            }

            //Allocs the byte array.
            var handleObj = GCHandle.Alloc(_savedArray, GCHandleType.Pinned);

            //Gets the addres of the pinned object.
            var address = handleObj.AddrOfPinnedObject();

            try
            {
                //Puts the buffer inside the byte array.
                _sampGrabber.GetCurrentBuffer(ref bufferSize, address);

                //Image size.
                var width  = _videoInfoHeader.BmiHeader.Width;
                var height = _videoInfoHeader.BmiHeader.Height;

                var stride = width * 4;
                address += height * stride;

                return(BitmapLoader.CreateBitmapBgr32(new Size(width, height), address, -stride));
            }
            finally
            {
                handleObj.Free();
            }
        }
Exemplo n.º 12
0
 public GLImageRenderer(Dictionary <string, ITexture> textures,
                        IGLBoundingBoxBuilder boundingBoxBuilder,
                        IGLColorBuilder colorBuilder, IGLTextureRenderer renderer, IGLBoundingBoxes bgBoxes,
                        IGLViewportMatrixFactory layerViewports, IGraphicsFactory graphicsFactory, IGLUtils glUtils,
                        IBitmapLoader bitmapLoader)
 {
     _graphicsFactory    = graphicsFactory;
     _textures           = textures;
     _boundingBoxBuilder = boundingBoxBuilder;
     _colorBuilder       = colorBuilder;
     _renderer           = renderer;
     _layerViewports     = layerViewports;
     BoundingBoxes       = bgBoxes;
     _glUtils            = glUtils;
     _bitmapLoader       = bitmapLoader;
     _emptyTexture       = new Lazy <ITexture>(() => initEmptyTexture());
 }
Exemplo n.º 13
0
        public GLGraphicsFactory(ITextureCache textures, Resolver resolver,
                                 IGraphicsBackend graphics, IBitmapLoader bitmapLoader, IRenderThread renderThread,
                                 IResourceLoader resources, IIconFactory icons, IBrushLoader brushes,
                                 IRenderMessagePump messagePump, IGameSettings settings, IBorderFactory borders)
        {
            Icons              = icons;
            Brushes            = brushes;
            Borders            = borders;
            _renderThread      = renderThread;
            _textures          = textures;
            _resolver          = resolver;
            _resources         = resources;
            _bitmapLoader      = bitmapLoader;
            _spriteSheetLoader = new SpriteSheetLoader(_resources, _bitmapLoader, addAnimationFrame, loadImage, graphics, messagePump);

            settings.Defaults.Skin = new AGSBlueSkin(this).CreateSkin();
        }
Exemplo n.º 14
0
        public GLLabelRenderer(Dictionary <string, ITexture> textures,
                               IGLBoundingBoxBuilder boundingBoxBuilder, IGLColorBuilder colorBuilder,
                               IGLTextureRenderer textureRenderer, BitmapPool bitmapPool, IGLViewportMatrixFactory viewportMatrix,
                               IGLBoundingBoxes labelBoundingBoxes, IGLBoundingBoxes textBoundingBoxes, IGraphicsFactory graphicsFactory,
                               IGLUtils glUtils, IGraphicsBackend graphics, IBitmapLoader bitmapLoader, IFontLoader fonts)
        {
            _glUtils            = glUtils;
            _graphics           = graphics;
            _fonts              = fonts;
            _bitmapPool         = bitmapPool;
            _viewport           = viewportMatrix;
            _textureRenderer    = textureRenderer;
            _labelBoundingBoxes = labelBoundingBoxes;
            _textBoundingBoxes  = textBoundingBoxes;
            _boundingBoxBuilder = boundingBoxBuilder;
            _bgRenderer         = new GLImageRenderer(textures,
                                                      new BoundingBoxesEmptyBuilder(), colorBuilder, _textureRenderer, _labelBoundingBoxes,
                                                      viewportMatrix, graphicsFactory, glUtils, bitmapLoader);

            _colorBuilder = colorBuilder;

            TextVisible = true;
        }
Exemplo n.º 15
0
 public DinosaurDetailsViewModelBuilder WithBitmapLoader(IBitmapLoader bitmapLoader) =>
 this.With(ref this.bitmapLoader, bitmapLoader);
Exemplo n.º 16
0
 public BitmapPool(IBitmapLoader bitmapLoader)
 {
     _bitmaps      = new ConcurrentDictionary <Size, ObjectPool <IBitmap> > (2, 40);
     _bitmapLoader = bitmapLoader;
     initPool();
 }
Exemplo n.º 17
0
 public AGSMaskLoader(IGameFactory factory, IResourceLoader resourceLoader, IBitmapLoader bitmapLoader)
 {
     _factory        = factory;
     _resourceLoader = resourceLoader;
     _bitmapLoader   = bitmapLoader;
 }
Exemplo n.º 18
0
 public GLTextureFactory(IGraphicsFactory graphicsFactory, IBitmapLoader bitmapLoader)
 {
     _graphicsFactory = graphicsFactory;
     _bitmapLoader    = bitmapLoader;
     _emptyTexture    = initEmptyTexture();
 }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
 public IBitmapImage Capture(IBitmapLoader BitmapLoader)
 {
     return(_syncContext.Run(() => _captureWebcam.GetFrame(BitmapLoader)));
 }
Exemplo n.º 21
0
 public GLTextureFactory(IGraphicsFactory graphicsFactory, IBitmapLoader bitmapLoader)
 {
     _graphicsFactory = graphicsFactory;
     _bitmapLoader    = bitmapLoader;
     _emptyTexture    = new Lazy <ITexture>(() => initEmptyTexture());
 }