public static extern System.Int32 SDL_RenderCopyEx( IntPtr /* SDL_Renderer* */ renderer, IntPtr /* SDL_Texture* */ texture, IntPtr /* SDL_Rect* */ srcrect, IntPtr /* SDL_Rect* */ dstrect, [MarshalAs(UnmanagedType.R8)] System.Double angle, IntPtr /* SDL_Point* */ center, SDL_RendererFlip flip);
void init() { SetImage(_Path); int a; uint b; SDL_QueryTexture(_Texture, out b, out a, out _sourceRectangle.w, out _sourceRectangle.h); _Flip = SDL_RendererFlip.SDL_FLIP_NONE; _Angle = 0; _Center.x = (_sourceRectangle.w) / 2; _Center.y = (_sourceRectangle.h) / 2; _S.Add(this); //_win.SceneManager.Add(); }
public void Flip(int angle, int x, int y, int a) { _Angle = angle; _Center.x = x; _Center.y = y; if (a == 0) { _Flip = SDL_RendererFlip.SDL_FLIP_NONE; } else if (a == 1) { _Flip = SDL_RendererFlip.SDL_FLIP_HORIZONTAL; } else if (a == 2) { _Flip = SDL_RendererFlip.SDL_FLIP_VERTICAL; } }
public static extern System.Int32 SDL_RenderCopyEx( IntPtr/* SDL_Renderer* */ renderer, IntPtr/* SDL_Texture* */ texture, IntPtr/* SDL_Rect* */ srcrect, IntPtr/* SDL_Rect* */ dstrect, [MarshalAs(UnmanagedType.R8)] System.Double angle, IntPtr/* SDL_Point* */ center, SDL_RendererFlip flip);
public unsafe static int SDL_RenderCopyEx(IntPtr renderer, IntPtr texture, SDL_Rect *srcrect, SDL_Rect *dstrect, double angle, SDL_Point *center, SDL_RendererFlip flip) => s_SDL_RenderCopyEx_IntPtr_IntPtr_SDL_Rect_SDL_Rect_double_SDL_Point_SDL_RendererFlip_t(renderer, texture, srcrect, dstrect, angle, center, flip);
public static extern int RenderCopyEx(IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, ref SDL_Rect dstrect, double angle, ref SDL_Point center, SDL_RendererFlip flip);
public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, ref SDL_Rect dstrect, double angle, ref SDL_Point center, SDL_RendererFlip flip );
/// <summary> /// Renders an individual sprite. /// </summary> /// <param name="s">The sprite to render.</param> public void RenderSprite(Sprite s, Bitmap bmp, int XOffset, int YOffset) { Graphics.Log($"Rendering sprite {(!string.IsNullOrEmpty(s.Name) ? "'" + s.Name + "' " : "")}-- color: {s.Color} x: {s.X} y: {s.Y} bmp({bmp.Width},{bmp.Height}{(s.Bitmap is SolidBitmap ? ", " + ((SolidBitmap) s.Bitmap).Color.ToString() : "")}) ox: {s.OX} oy: {s.OY}"); IntPtr Texture = IntPtr.Zero; if (s.Tone.Red == 0 && s.Tone.Green == 0 && s.Tone.Blue == 0 && s.Tone.Gray == 0 && s.Color.Alpha == 0) { Texture = bmp.Texture; } else { Texture = bmp.ColorToneTexture(s.Color, s.Tone); } if (Texture == IntPtr.Zero) { throw new Exception("Attempted to render a zero-pointer texture."); } // Sprite Opacity + Renderer opacity byte Alpha = Convert.ToByte(255d * (s.Opacity / 255d) * (this.Opacity / 255d)); SDL_SetTextureAlphaMod(Texture, Alpha); List <Point> Points; if (s.MultiplePositions.Count == 0) // Normal X,Y positions { Points = new List <Point>() { new Point(s.X, s.Y) }; } else // Multiple positions; used to prevent the need for hundreds of identical sprites that only differ in position (e.g. in a background grid) { Graphics.Log("Multiple positions!"); Points = s.MultiplePositions; } SDL_Rect Src = new SDL_Rect(); SDL_Rect Dest = new SDL_Rect(); if (bmp is SolidBitmap) { Src.x = 0; Src.y = 0; Src.w = 1; Src.h = 1; Dest.w = (bmp as SolidBitmap).BitmapWidth; Dest.h = (bmp as SolidBitmap).BitmapHeight; } else { Src = s.SrcRect.SDL_Rect; // Additional checks, since ZoomX/ZoomY are 1 99% of the time, this way it skips the extra calculation. if (s.ZoomX == 1) { Dest.w = Src.w; } else { Dest.w = (int)Math.Round(Src.w * s.ZoomX); } if (s.ZoomY == 1) { Dest.h = Src.h; } else { Dest.h = (int)Math.Round(Src.h * s.ZoomY); } } if (!bmp.Locked && !(bmp is SolidBitmap)) { Graphics.Log("ERR: Bitmap is locked"); throw new BitmapLockedException(); } foreach (Point p in Points) { int oxoffset = s.FactorZoomIntoOrigin ? (int)Math.Round((double)s.OX * s.ZoomX) : s.OX; int oyoffset = s.FactorZoomIntoOrigin ? (int)Math.Round((double)s.OY * s.ZoomY) : s.OY; Dest.x = p.X - oxoffset + XOffset; Dest.y = p.Y - oyoffset + YOffset; if (s.Angle % 360 == 0 && s.OX == 0 && s.OY == 0 && !s.MirrorX && !s.MirrorY) { SDL_RenderCopy(this.SDL_Renderer, Texture, ref Src, ref Dest); } else { SDL_Point Center = new SDL_Point(); Center.x = s.OX; Center.y = s.OY; SDL_RendererFlip MirrorState = SDL_RendererFlip.SDL_FLIP_NONE; if (s.MirrorX) { MirrorState |= SDL_RendererFlip.SDL_FLIP_HORIZONTAL; } if (s.MirrorY) { MirrorState |= SDL_RendererFlip.SDL_FLIP_VERTICAL; } SDL_RenderCopyEx(this.SDL_Renderer, Texture, ref Src, ref Dest, s.Angle % 360, ref Center, MirrorState); } // Don't destroy the texture as it can be reused next render } }