예제 #1
0
        public AGSScale(IHasImage image, float width, float height)
        {
            _image = image;

            ScaleX = 1;
            ScaleY = 1;
            ResetBaseSize(width, height);
        }
예제 #2
0
        public AGSScale(IHasImage image)
        {
            _image = image;

            ScaleX = 1;
            ScaleY = 1;
            image.OnImageChanged.Subscribe((sender, args) =>
            {
                if (_initialWidth == 0f) ResetBaseSize(_image.Image.Width, _image.Image.Height);
            });
        }
예제 #3
0
        public void ImageNameToImageUrl(IHasImage hasImage)
        {
            if (hasImage == null)
            {
                throw new ArgumentNullException(nameof(hasImage));
            }
            if (hasImage.Image == null)
            {
                return;
            }

            hasImage.Image = GetImageUrl(hasImage.Image);
        }
예제 #4
0
 public static void BindSizeToImage(IHasImage image, IScale scale)
 {
     image.PropertyChanged += ((_, args) =>
     {
         if (args.PropertyName != nameof(IHasImage.Image))
         {
             return;
         }
         if (MathUtils.FloatEquals(scale.BaseSize.Width, 0f) && image.Image != null)
         {
             scale.BaseSize = new SizeF(image.Image.Width, image.Image.Height);
         }
     });
 }
예제 #5
0
		public AGSSprite (Resolver resolver, IMaskLoader maskLoader)
		{
            _maskLoader = maskLoader;
            _resolver = resolver;

            //todo: abstract it to the constructor
            _translate = new AGSTranslate();
            _hasImage = new AGSHasImage();
            _hasImage.Anchor = new PointF();                        
            _rotate = new AGSRotate();

            ScaleX = 1;
            ScaleY = 1;
            _hasImage.OnImageChanged.Subscribe((sender, args) => ScaleBy(ScaleX, ScaleY));
        }
예제 #6
0
        public AGSSprite(Resolver resolver, IMaskLoader maskLoader)
        {
            _maskLoader    = maskLoader;
            _resolver      = resolver;
            OnScaleChanged = new AGSEvent <AGSEventArgs>();

            //todo: abstract it to the constructor
            _translate       = new AGSTranslate();
            _hasImage        = new AGSHasImage();
            _hasImage.Anchor = new PointF();
            _rotate          = new AGSRotate();

            ScaleX = 1;
            ScaleY = 1;
            _hasImage.OnImageChanged.Subscribe((sender, args) => ScaleBy(ScaleX, ScaleY));
        }
예제 #7
0
 public AGSImageComponent(IHasImage image, IGraphicsFactory factory, IRenderPipeline pipeline,
                          IGLTextureRenderer renderer, ITextureCache textures,
                          ITextureFactory textureFactory, IGLColorBuilder colorBuilder)
 {
     IsImageVisible          = true;
     _getTextureFunc         = textureFactory.CreateTexture; //Creating a delegate in advance to avoid memory allocations on critical path
     _textures               = textures;
     _colorBuilder           = colorBuilder;
     _image                  = image;
     _factory                = factory;
     _colorAdjusters         = new IHasImage[2];
     _image.PropertyChanged += onPropertyChanged;
     _pipeline               = pipeline;
     _boxesPool              = new ObjectPool <AGSBoundingBoxes>(_ => new AGSBoundingBoxes(), 2);
     _instructionPool        = new ObjectPool <Instruction>(instructionPool => new Instruction(instructionPool, _boxesPool, renderer), 2);
 }
예제 #8
0
        public AGSSprite(Resolver resolver, IMaskLoader maskLoader)
        {
            _id         = Interlocked.Increment(ref _lastId);
            _maskLoader = maskLoader;
            _resolver   = resolver;

            //todo: abstract it to the constructor
            _translate      = new AGSTranslate();
            _hasImage       = new AGSHasImage();
            _hasImage.Pivot = new PointF();
            _scale          = new AGSScale(_hasImage);
            _rotate         = new AGSRotate();

            _scale.PropertyChanged     += onPropertyChanged;
            _hasImage.PropertyChanged  += onPropertyChanged;
            _translate.PropertyChanged += onPropertyChanged;
        }
예제 #9
0
        public static Action BindSizeToImage(IHasImage image, IScale scale)
        {
            PropertyChangedEventHandler onPropertyChanged = ((_, args) =>
            {
                if (args.PropertyName != nameof(IHasImage.Image))
                {
                    return;
                }
                if (MathUtils.FloatEquals(scale.BaseSize.Width, 0f) && image.Image != null)
                {
                    scale.BaseSize = new SizeF(image.Image.Width, image.Image.Height);
                }
            });

            image.PropertyChanged += onPropertyChanged;
            return(() => image.PropertyChanged -= onPropertyChanged);
        }
예제 #10
0
        public AGSSprite(Resolver resolver, IMaskLoader maskLoader)
        {
            _id = Interlocked.Increment(ref _lastId);
            _pixelPerfectArea = new Lazy <IArea>(generatePixelPerfectArea);
            _maskLoader       = maskLoader;
            _resolver         = resolver;

            //todo: abstract it to the constructor
            _translate      = new AGSTranslate();
            _hasImage       = new AGSHasImage();
            _hasImage.Pivot = new PointF();
            _scale          = new AGSScale();
            AGSScale.BindSizeToImage(_hasImage, _scale);
            _rotate = new AGSRotate();

            _scale.PropertyChanged     += onPropertyChanged;
            _hasImage.PropertyChanged  += onPropertyChanged;
            _translate.PropertyChanged += onPropertyChanged;
        }
예제 #11
0
        public AGSScale(IHasImage image)
        {
            _image = image;

            _scaleX = 1;
            _scaleY = 1;

            image.PropertyChanged += ((_, args) =>
            {
                if (args.PropertyName != nameof(IHasImage.Image))
                {
                    return;
                }
                if (MathUtils.FloatEquals(BaseSize.Width, 0f) && _image.Image != null)
                {
                    BaseSize = new SizeF(_image.Image.Width, _image.Image.Height);
                }
            });
        }
예제 #12
0
        private AGSScale(IHasImage image, bool shouldSubscribeToImageChange)
        {
            _image         = image;
            OnScaleChanged = new AGSEvent <AGSEventArgs>();

            ScaleX = 1;
            ScaleY = 1;

            if (!shouldSubscribeToImageChange)
            {
                return;
            }
            image.OnImageChanged.Subscribe((sender, args) =>
            {
                if (_initialWidth == 0f)
                {
                    ResetBaseSize(_image.Image.Width, _image.Image.Height);
                }
            });
        }
예제 #13
0
 /// <summary>
 /// Tweens the brightness of the image (where 1 is default, 2 is twice as bright).
 /// <example>
 /// <code language="lang-csharp">
 /// var tween = obj.TweenBrightness(2f, 2f, Ease.QuadOut);
 /// await tween.Task;
 /// </code>
 /// </example>
 /// <seealso cref="Tween"/>
 /// <seealso cref="IHasImage.Brightness"/>
 /// </summary>
 /// <returns>The tween.</returns>
 /// <param name="sprite">Sprite.</param>
 /// <param name="toBrightness">To brightness.</param>
 /// <param name="timeInSeconds">Time in seconds.</param>
 /// <param name="easing">Easing function.</param>
 public static Tween TweenBrightness(this IHasImage sprite, float toBrightness, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(sprite.Brightness.X, toBrightness, b => sprite.Brightness = new Vector4(b), timeInSeconds, easing));
 }
예제 #14
0
 /// <summary>
 /// Tweens the lightness of the image's tint (based on HSLA color scheme).
 /// <example>
 /// <code language="lang-csharp">
 /// var tween = obj.TweenLightness(0f, 2f, Ease.QuadOut);
 /// await tween.Task;
 /// </code>
 /// </example>
 /// <seealso cref="Color.FromHsla"/>
 /// <seealso cref="Tween"/>
 /// <seealso cref="IHasImage.Tint"/>
 /// </summary>
 /// <returns>The tween.</returns>
 /// <param name="sprite">Sprite.</param>
 /// <param name="toLightness">To lightness.</param>
 /// <param name="timeInSeconds">Time in seconds.</param>
 /// <param name="easing">Easing function.</param>
 public static Tween TweenTintLightness(this IHasImage sprite, float toLightness, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(sprite.Tint.GetLightness(), toLightness, l => sprite.Tint = Color.FromHsla(sprite.Tint.GetHue(),
                                                                                                 sprite.Tint.GetSaturation(), l, sprite.Tint.A), timeInSeconds, easing));
 }
예제 #15
0
 /// <summary>
 /// Tweens the blue tint of the image.
 /// <example>
 /// <code language="lang-csharp">
 /// var tween = obj.TweenBlue(255, 2f, Ease.QuadIn);
 /// await tween.Task;
 /// </code>
 /// </example>
 /// <seealso cref="Tween"/>
 /// <seealso cref="IHasImage.Tint"/>
 /// </summary>
 /// <returns>The tween.</returns>
 /// <param name="sprite">Sprite.</param>
 /// <param name="toBlue">To blue.</param>
 /// <param name="timeInSeconds">Time in seconds.</param>
 /// <param name="easing">Easing function.</param>
 public static Tween TweenBlue(this IHasImage sprite, byte toBlue, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(sprite.Tint.B, toBlue, b => sprite.Tint = Color.FromArgb(sprite.Tint.A, sprite.Tint.R,
                                                                               sprite.Tint.G, (byte)b), timeInSeconds, easing));
 }
예제 #16
0
 /// <summary>
 /// Tweens the green tint of the image.
 /// <example>
 /// <code language="lang-csharp">
 /// var tween = obj.TweenGreen(255, 2f, Ease.QuadIn);
 /// await tween.Task;
 /// </code>
 /// </example>
 /// <seealso cref="Tween"/>
 /// <seealso cref="IHasImage.Tint"/>
 /// </summary>
 /// <returns>The tween.</returns>
 /// <param name="sprite">Sprite.</param>
 /// <param name="toGreen">To green.</param>
 /// <param name="timeInSeconds">Time in seconds.</param>
 /// <param name="easing">Easing function.</param>
 public static Tween TweenGreen(this IHasImage sprite, byte toGreen, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(sprite.Tint.G, toGreen, g => sprite.Tint = Color.FromArgb(sprite.Tint.A, sprite.Tint.R,
                                                                                (byte)g, sprite.Tint.B), timeInSeconds, easing));
 }
예제 #17
0
 /// <summary>
 /// Tweens the red tint of the image.
 /// <example>
 /// <code language="lang-csharp">
 /// var tween = obj.TweenRed(255, 2f, Ease.QuadIn);
 /// await tween.Task;
 /// </code>
 /// </example>
 /// <seealso cref="Tween"/>
 /// <seealso cref="IHasImage.Tint"/>
 /// </summary>
 /// <returns>The tween.</returns>
 /// <param name="sprite">Sprite.</param>
 /// <param name="toRed">To red.</param>
 /// <param name="timeInSeconds">Time in seconds.</param>
 /// <param name="easing">Easing function.</param>
 public static Tween TweenRed(this IHasImage sprite, byte toRed, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(sprite.Tint.R, toRed, r => sprite.Tint = Color.FromArgb(sprite.Tint.A, (byte)r,
                                                                              sprite.Tint.G, sprite.Tint.B), timeInSeconds, easing));
 }
예제 #18
0
        private Matrix4 getModelMatrix(IScale scale, IRotate rotate, ITranslate translate, IHasImage image,
                                       IJumpOffsetComponent jump, PointF areaScaling, PointF resolutionTransform, bool useCustomImageSize)
        {
            if (scale == null)
            {
                return(Matrix4.Identity);
            }
            float?customWidth = _customImageSize == null || !useCustomImageSize ?
                                _nullFloat : (_customImageSize.Value.Width * scale.ScaleX);
            float?customHeight = _customImageSize == null || !useCustomImageSize ?
                                 _nullFloat : (_customImageSize.Value.Height * scale.ScaleY);
            float  width        = (customWidth ?? scale.Width) * areaScaling.X * resolutionTransform.X;
            float  height       = (customHeight ?? scale.Height) * areaScaling.Y * resolutionTransform.Y;
            PointF pivotOffsets = GetPivotOffsets(image == null ? PointF.Empty : image.Pivot,
                                                  width, height);
            Matrix4 pivotMat = Matrix4.CreateTranslation(new Vector3(-pivotOffsets.X, -pivotOffsets.Y, 0f));
            Matrix4 scaleMat = Matrix4.CreateScale(new Vector3(scale.ScaleX * areaScaling.X,
                                                               scale.ScaleY * areaScaling.Y, 1f));
            float   radians     = rotate == null ? 0f : MathUtils.DegreesToRadians(rotate.Angle);
            Matrix4 rotationMat = Matrix4.CreateRotationZ(radians);
            float   x           = translate == null ? 0f : translate.X * resolutionTransform.X;
            float   y           = translate == null ? 0f : translate.Y * resolutionTransform.Y;

            if (jump != null)
            {
                x += jump.JumpOffset.X * resolutionTransform.X;
                y += jump.JumpOffset.Y * resolutionTransform.Y;
            }
            Matrix4 translateMat = Matrix4.CreateTranslation(new Vector3(x, y, 0f));

            return(scaleMat * pivotMat * rotationMat * translateMat);
        }
예제 #19
0
 /// <summary>
 /// Tweens the hue of the image's tint (based on HSLA color scheme).
 /// <example>
 /// <code language="lang-csharp">
 /// var tween = obj.TweenHue(0, 2f, Ease.QuadOut);
 /// await tween.Task;
 /// </code>
 /// </example>
 /// <seealso cref="Color.FromHsla"/>
 /// <seealso cref="Tween"/>
 /// <seealso cref="IHasImage.Tint"/>
 /// </summary>
 /// <returns>The tween.</returns>
 /// <param name="sprite">Sprite.</param>
 /// <param name="toHue">To hue.</param>
 /// <param name="timeInSeconds">Time in seconds.</param>
 /// <param name="easing">Easing function.</param>
 public static Tween TweenTintHue(this IHasImage sprite, int toHue, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run((float)sprite.Tint.GetHue(), (float)toHue, h => sprite.Tint = Color.FromHsla((int)h, sprite.Tint.GetSaturation(),
                                                                                                   sprite.Tint.GetLightness(), sprite.Tint.A), timeInSeconds, easing));
 }
예제 #20
0
 public AGSImageComponent(IHasImage image, IGraphicsFactory factory)
 {
     _image   = image;
     _factory = factory;
     _image.PropertyChanged += onPropertyChanged;
 }
예제 #21
0
        private Matrix4 getModelMatrix(IScale scale, IRotate rotate, ITranslate translate, IHasImage image,
                                       PointF areaScaling, PointF resolutionTransform, bool useCustomImageSize)
        {
            if (scale == null)
            {
                return(Matrix4.Identity);
            }
            float?customWidth = _customImageSize == null || !useCustomImageSize ?
                                _nullFloat : _customImageSize.Value.Width;
            float?customHeight = _customImageSize == null || !useCustomImageSize ?
                                 _nullFloat : _customImageSize.Value.Height;
            float   width         = (customWidth ?? scale.Width) * resolutionTransform.X;
            float   height        = (customHeight ?? scale.Height) * resolutionTransform.Y;
            PointF  anchorOffsets = getAnchorOffsets(image.Anchor, width, height);
            Matrix4 anchor        = Matrix4.CreateTranslation(new Vector3(-anchorOffsets.X, -anchorOffsets.Y, 0f));
            Matrix4 scaleMat      = Matrix4.CreateScale(new Vector3(scale.ScaleX * areaScaling.X,
                                                                    scale.ScaleY * areaScaling.Y, 1f));
            Matrix4 rotation  = Matrix4.CreateRotationZ(rotate.Angle);
            float   x         = translate.X * resolutionTransform.X;
            float   y         = translate.Y * resolutionTransform.Y;
            Matrix4 transform = Matrix4.CreateTranslation(new Vector3(x, y, 0f));

            return(anchor * scaleMat * rotation * transform);
        }
예제 #22
0
 public AGSScale(IHasImage image) : this(image, true)
 {
 }
예제 #23
0
 /// <summary>
 /// Tweens the pivot point (its y position) of an image.
 /// <example>
 /// <code language="lang-csharp">
 /// var tween = obj.TweenPivotY(0.5f, 2f, Ease.SineIn);
 /// await tween.Task;
 /// </code>
 /// </example>
 /// <seealso cref="Tween"/>
 /// <seealso cref="IHasImage.Pivot"/>
 /// </summary>
 /// <returns>The tween.</returns>
 /// <param name="sprite">Sprite.</param>
 /// <param name="toPivotY">To pivot y.</param>
 /// <param name="timeInSeconds">Time in seconds.</param>
 /// <param name="easing">Easing function.</param>
 public static Tween TweenPivotY(this IHasImage sprite, float toPivotY, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(sprite.Pivot.Y, toPivotY, y => sprite.Pivot = new PointF(sprite.Pivot.X, y), timeInSeconds, easing));
 }
예제 #24
0
 /// <summary>
 /// Tweens the opacity of the image.
 /// <example>
 /// <code language="lang-csharp">
 /// var tween = obj.TweenOpacity(0, 2f, Ease.Linear); //Fade out
 /// await tween.Task;
 /// </code>
 /// </example>
 /// <seealso cref="Tween"/>
 /// <seealso cref="IHasImage.Opacity"/>
 /// </summary>
 /// <returns>The tween.</returns>
 /// <param name="sprite">Sprite.</param>
 /// <param name="toOpacity">To opacity.</param>
 /// <param name="timeInSeconds">Time in seconds.</param>
 /// <param name="easing">Easing function.</param>
 public static Tween TweenOpacity(this IHasImage sprite, byte toOpacity, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(sprite.Opacity, toOpacity, o => sprite.Opacity = (byte)o, timeInSeconds, easing));
 }
예제 #25
0
 public AGSImageComponent(IHasImage image, IGraphicsFactory factory)
 {
     _image   = image;
     _factory = factory;
 }
예제 #26
0
 /// <summary>
 /// Fades out the object.
 /// </summary>
 /// <returns>The out.</returns>
 /// <param name="sprite">Sprite.</param>
 /// <param name="timeInSeconds">Time in seconds.</param>
 /// <param name="easing">Easing.</param>
 public static Tween FadeOut(this IHasImage sprite, float timeInSeconds, Func <float, float> easing = null)
 {
     return(sprite.TweenOpacity(0, timeInSeconds, easing));
 }
예제 #27
0
 public AGSImageComponent(IHasImage image, IGraphicsFactory factory)
 {
     _image = image;
     _factory = factory;
 }
예제 #28
0
 public AGSScale(IHasImage image, float width, float height) : this(image, false)
 {
     ResetBaseSize(width, height);
 }