public FlippingView(Context context, int width, int height)
            : base(context)
        {
            flipOutView = new ImageView(context);
            flipInView  = new ImageView(context);

            AddView(flipOutView, width, height);
            AddView(flipInView, width, height);

            flipInView.RotationY = -90;

            var flipOutAnimator = ObjectAnimator.OfFloat(flipOutView, "rotationY", 0, 90);

            flipOutAnimator.SetInterpolator(new AccelerateInterpolator());

            var flipInAnimator = ObjectAnimator.OfFloat(flipInView, "rotationY", -90, 0);

            flipInAnimator.SetInterpolator(new DecelerateInterpolator());

            animations = new AnimatorSet();
            animations.PlaySequentially(flipOutAnimator, flipInAnimator);

            animations.AnimationEnd += (sender, e) =>
            {
                flipOutView.RotationY = 0;
                flipInView.RotationY  = -90;

                Flipped?.Invoke(this, EventArgs.Empty);
            };
        }
Ejemplo n.º 2
0
 public abstract void DrawText(Font font, string text, Vec2 pos, Vec2?scale       = null, double rotation = 0, Vec2?origin = null, Color?color = null, Flipped flipped = Flipped.None, Rectangle?source = null, IAnchor2d anchor = null);
Ejemplo n.º 3
0
 public abstract void DrawImage(Texture texture, Vec2 pos, Vec2?scale       = null, double rotation = 0, Vec2?origin = null, Color?color = null, Flipped flipped = Flipped.None, Rectangle?source = null, IAnchor2d anchor = null);
Ejemplo n.º 4
0
            private void InternalDrawImage(Texture texture, Vec2 pos, Vec2 scale, double rotation, Vec2 origin, Color color, Flipped flipped, Rectangle?source, IAnchor2d anchor)
            {
                const double degreeToRadianConst = 57.2957795131;

                if (!(texture is SDLTexture sdltexture))
                {
                    Logger.Log(LogLevel.Warning, "Texture is not of type SDLTexture");
                    return;
                }

                pos += anchor?.ScreenBounds.Pos ?? Vec2.Zero;
                if (anchor is Entity2d entityAnchor)
                {
                    scale    *= entityAnchor?.Scale ?? Vec2.One;
                    rotation += entityAnchor?.Rotation ?? 0;
                    origin   += entityAnchor?.Origin ?? Vec2.Zero;
                    //TODO: Blend color and flip entity
                }

                var drect = new SDL2.SDL.SDL_Rect
                {
                    x = (int)(pos.X - origin.X),
                    y = (int)(pos.Y - origin.Y),
                    w = (int)(texture.Size.X * scale.X),
                    h = (int)(texture.Size.Y * scale.Y)
                };

                var sdlPoint = new SDL2.SDL.SDL_Point
                {
                    x = (int)origin.X,
                    y = (int)origin.Y
                };

                SDL2.SDL.SDL_SetTextureColorMod(sdltexture.SDL_Image, (byte)color.R, (byte)color.G, (byte)color.B);
                SDL2.SDL.SDL_SetTextureAlphaMod(sdltexture.SDL_Image, (byte)color.A);

                var sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_NONE;

                if (flipped == Flipped.Horizontal)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL;
                }
                else if (flipped == Flipped.Vertical)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL;
                }
                else if (flipped == Flipped.Both)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL | SDL2.SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL;
                }

                if (!source.HasValue)
                {
                    SDL2.SDL.SDL_RenderCopyEx(this.SDLRenderer, sdltexture.SDL_Image, (IntPtr)null, ref drect, rotation * degreeToRadianConst, ref sdlPoint, sdlRenderFlip);
                }
                else
                {
                    SDL2.SDL.SDL_Rect srect = new SDL2.SDL.SDL_Rect
                    {
                        x = (int)source?.Pos.X,
                        y = (int)source?.Pos.Y,
                        w = (int)source?.Size.X,
                        h = (int)source?.Size.Y
                    };

                    SDL2.SDL.SDL_RenderCopyEx(this.SDLRenderer, sdltexture.SDL_Image, ref srect, ref drect, rotation * degreeToRadianConst, ref sdlPoint, sdlRenderFlip);
                }
            }
Ejemplo n.º 5
0
 public override void DrawImage(Texture texture, Vec2 pos, Vec2?scale = null, double rotation = 0, Vec2?origin = null, Color?color = null, Flipped flipped = Flipped.None, Rectangle?source = null, IAnchor2d anchor = null)
 {
     InternalDrawImage(texture, pos, scale ?? new Vec2(1), rotation, origin ?? new Vec2(0), color ?? Color.White, flipped, source, anchor);
 }
Ejemplo n.º 6
0
            private void InternalDrawText(Font font, string text, Vec2 pos, Vec2 scale, double rotation, Vec2 origin, Color color, Flipped flipped, Rectangle?source, IAnchor2d anchor)
            {
                const double degreeToRadianConst = 57.2957795131;

                if (!(font is SDLFont sdlFont))
                {
                    Logger.Log(LogLevel.Warning, "Font is not of type SDLFont");
                    return;
                }

                pos += anchor?.ScreenBounds.Pos ?? Vec2.Zero;

                var sdlColor = new SDL2.SDL.SDL_Color
                {
                    r = (byte)color.R,
                    g = (byte)color.G,
                    b = (byte)color.B,
                    a = (byte)color.A
                };
                var fontSur = SDL_ttf.TTF_RenderText_Solid(sdlFont.SDL_Font, text, sdlColor);
                var fontTex = SDL2.SDL.SDL_CreateTextureFromSurface(this.SDLRenderer, fontSur);

                SDL2.SDL.SDL_QueryTexture(fontTex, out _, out _, out int w, out int h);
                var fontSize = new Vec2(w, h);
                var drect    = new SDL2.SDL.SDL_Rect
                {
                    x = (int)(pos.X - origin.X),
                    y = (int)(pos.Y - origin.Y),
                    w = (int)(fontSize.X * scale.X),
                    h = (int)(fontSize.Y * scale.Y)
                };

                var sdlPoint = new SDL2.SDL.SDL_Point
                {
                    x = (int)origin.X,
                    y = (int)origin.Y
                };

                var sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_NONE;

                if (flipped == Flipped.Horizontal)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL;
                }
                else if (flipped == Flipped.Vertical)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL;
                }
                else if (flipped == Flipped.Both)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL | SDL2.SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL;
                }

                if (!source.HasValue)
                {
                    SDL2.SDL.SDL_RenderCopyEx(this.SDLRenderer, fontTex, (IntPtr)null, ref drect, rotation * degreeToRadianConst, ref sdlPoint, sdlRenderFlip);
                }
                else
                {
                    SDL2.SDL.SDL_Rect srect = new SDL2.SDL.SDL_Rect
                    {
                        x = (int)source?.Pos.X,
                        y = (int)source?.Pos.Y,
                        w = (int)source?.Size.X,
                        h = (int)source?.Size.Y
                    };

                    SDL2.SDL.SDL_RenderCopyEx(this.SDLRenderer, fontTex, ref srect, ref drect, rotation * degreeToRadianConst, ref sdlPoint, sdlRenderFlip);
                }

                SDL2.SDL.SDL_FreeSurface(fontSur);
                SDL2.SDL.SDL_DestroyTexture(fontTex);
            }
Ejemplo n.º 7
0
 public override void DrawText(Font font, string text, Vec2 pos, Vec2?scale = null, double rotation = 0, Vec2?origin = null, Color?color = null, Flipped flipped = Flipped.None, Rectangle?source = null, IAnchor2d anchor = null)
 {
     InternalDrawText(font, text, pos, scale ?? new Vec2(1), rotation, origin ?? new Vec2(), color ?? Color.White, flipped, source, anchor);
 }
Ejemplo n.º 8
0
        /// <inheritdoc />
        protected override void ConfigureComponent()
        {
            string color   = "";
            string options = "";

            ElementTag = "i";

            if (Disabled)
            {
                options = $"{options}disabled ";
            }

            if (Loading)
            {
                options = $"{options}loading ";
            }

            if (Fitted)
            {
                options = $"{options}fitted ";
            }

            if (Link)
            {
                options = $"{options}link ";
            }

            if (Flipped != FlipDirection.None)
            {
                options = $"{options}{Flipped.GetDescription()} flipped ";
            }

            if (Rotated != Rotation.None)
            {
                options = $"{options}{Rotated.GetDescription()} rotated ";
            }

            if (Corner != Corner.None)
            {
                options = Corner == Corner.Default ? $"{options} corner " : $"{options}{Corner.GetDescription()} corner ";
            }

            if (Circular)
            {
                options = $"{options}circular ";
            }

            if (Bordered)
            {
                options = $"{options}bordered ";
            }

            if (Inverted)
            {
                options = $"{options}inverted ";
            }

            if (Color != Color.None)
            {
                color = $"{Color.GetDescription()} ";
            }


            if (Size != Size.None && Size != Size.Medium)
            {
                options = $"{options}{Size.GetDescription()} ";
            }

            ElementClass = $"{color}{Name.GetDescription()} {options}icon";
        }