Ejemplo n.º 1
0
            public override void DrawLine(Vec2 from, Vec2 size, Color color, IAnchor2d anchor = null)
            {
                from += anchor?.ScreenBounds.Pos ?? Vec2.Zero;

                SDL2.SDL.SDL_SetRenderDrawColor(SDLRenderer, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
                SDL2.SDL.SDL_RenderDrawLine(SDLRenderer, (int)from.X, (int)from.Y, (int)size.X, (int)size.Y);
            }
Ejemplo n.º 2
0
            public override void DrawPixels(List <Vec2> points, Color color, IAnchor2d anchor = null)
            {
                SDL2.SDL.SDL_SetRenderDrawColor(SDLRenderer, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
                var sdlpoints = new SDL2.SDL.SDL_Point[points.Count];
                int i         = 0;

                foreach (var point in points)
                {
                    var tpoint = point + (anchor?.ScreenBounds.Pos ?? Vec2.Zero);
                    sdlpoints[i] = new SDL2.SDL.SDL_Point
                    {
                        x = (int)tpoint.X,
                        y = (int)tpoint.Y
                    };
                    i++;
                }
                SDL2.SDL.SDL_RenderDrawPoints(SDLRenderer, sdlpoints, points.Count);
            }
Ejemplo n.º 3
0
 public override void DrawRectangle(Rectangle rectangle, bool filled, Color color, IAnchor2d anchor = null)
 {
 }
Ejemplo n.º 4
0
 public override void DrawPixel(Vec2 point, Color color, IAnchor2d anchor = null)
 {
 }
Ejemplo n.º 5
0
 public override void DrawPixels(List <Vec2> points, Color color, IAnchor2d anchor = null)
 {
 }
Ejemplo n.º 6
0
 public abstract void DrawText(Font font, string text, Vec2 pos, IAnchor2d anchor = null);
Ejemplo n.º 7
0
 public override void DrawRectangle(Rectangle rectangle, bool filled, Color color, IAnchor2d anchor = null)
 {
     DrawRectangle(rectangle.Pos, rectangle.Size, filled, color, anchor);
 }
Ejemplo n.º 8
0
 public abstract void DrawRectangle(Rectangle rectangle, bool filled, Color color, IAnchor2d anchor  = null);
Ejemplo n.º 9
0
 public abstract void DrawImage(Texture texture, Vec2 pos, IAnchor2d anchor = null);
Ejemplo n.º 10
0
 public override void DrawRectangleE(Vec2 from, Vec2 to, bool filled, Color color, IAnchor2d anchor = null)
 {
 }
Ejemplo n.º 11
0
 public abstract void DrawPixel(Vec2 point, Color color, IAnchor2d anchor          = null);
Ejemplo n.º 12
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.º 13
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.º 14
0
 public override void DrawImage(Texture texture, Vec2 pos, IAnchor2d anchor = null)
 {
     DrawImage(texture, pos, null, anchor: anchor);
 }
Ejemplo n.º 15
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.º 16
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.º 17
0
 public override void DrawText(Font font, string text, Vec2 pos, IAnchor2d anchor = null)
 {
     DrawText(font, text, pos, null, anchor: anchor);
 }
Ejemplo n.º 18
0
            public override void DrawRectangle(Vec2 from, Vec2 size, bool filled, Color color, IAnchor2d anchor = null)
            {
                from += anchor?.ScreenBounds.Pos ?? Vec2.Zero;

                SDL2.SDL.SDL_SetRenderDrawColor(SDLRenderer, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
                var rect = new SDL2.SDL.SDL_Rect
                {
                    x = (int)from.X,
                    y = (int)from.Y,
                    w = (int)size.X,
                    h = (int)size.Y
                };

                if (filled)
                {
                    SDL2.SDL.SDL_RenderFillRect(SDLRenderer, ref rect);
                }
                else
                {
                    SDL2.SDL.SDL_RenderDrawRect(SDLRenderer, ref rect);
                }
            }
Ejemplo n.º 19
0
 public abstract void DrawLineE(Vec2 from, Vec2 to, Color color, IAnchor2d anchor  = null);
Ejemplo n.º 20
0
 public override void DrawLineE(Vec2 from, Vec2 to, Color color, IAnchor2d anchor)
 {
     DrawLine(from, to - from, color, anchor);
 }
Ejemplo n.º 21
0
 public abstract void DrawPixels(List <Vec2> points, Color color, IAnchor2d anchor = null);
Ejemplo n.º 22
0
 public override void DrawPixel(Vec2 point, Color color, IAnchor2d anchor = null)
 {
     point += anchor?.ScreenBounds.Pos ?? Vec2.Zero;
     SDL2.SDL.SDL_SetRenderDrawColor(SDLRenderer, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
     SDL2.SDL.SDL_RenderDrawPoint(SDLRenderer, (int)point.X, (int)point.Y);
 }
Ejemplo n.º 23
0
 public abstract void DrawRectangleE(Vec2 from, Vec2 to, bool filled, Color color, IAnchor2d anchor  = null);
Ejemplo n.º 24
0
 public override void DrawText(Font font, string text, Vec2 pos, IAnchor2d anchor = null)
 {
 }
Ejemplo n.º 25
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.º 26
0
 public override void DrawImage(Texture texture, Vec2 pos, IAnchor2d anchor = null)
 {
 }
Ejemplo n.º 27
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.º 28
0
 public override void DrawLineE(Vec2 from, Vec2 to, Color color, IAnchor2d anchor = null)
 {
 }