public static unsafe void DrawPixel(int x, int y, int c) { if (Eight.IsQuitting) { return; } if (x < 0 && y < 0 && x >= Eight.RealWidth && y >= Eight.RealHeight) { return; } Color color = Color.FromArgb(c); var pixel = new SDL_Rect { x = x, y = y, w = 1, h = 1 }; SDL_FillRect(Display.Surface, ref pixel, SDL_MapRGB(((SDL_Surface *)Display.Surface)->format, color.R, color.G, color.B)); Display.Dirty = true; }
/// <inheritdoc/> void IMessageSubscriber <UltravioletMessageID> .ReceiveMessage(UltravioletMessageID type, MessageData data) { if (type == UltravioletMessages.TextInputRegionChanged) { unsafe { var service = SoftwareKeyboardService.Create(); var region = service.TextInputRegion; if (region.HasValue) { var rect = new SDL_Rect() { x = region.Value.X, y = region.Value.Y, w = region.Value.Width, h = region.Value.Height, }; SDL.SetTextInputRect(&rect); } else { SDL.SetTextInputRect(null); } } } }
void IGraphicsDriver.Display(int displayScaleX, int displayScaleY, int renderScaleX, int renderScaleY) { if (displayScaleX < 1) { throw new ArgumentOutOfRangeException("displayScaleX"); } if (displayScaleY < 1) { throw new ArgumentOutOfRangeException("displayScaleY"); } this.nativeWidth = 320 * renderScaleX; this.nativeHeight = 200 * renderScaleY; this.nativeScaleX = renderScaleX; this.nativeScaleY = renderScaleY; this.displayScaleX = displayScaleX; this.displayScaleY = displayScaleY; this.displayWidth = this.nativeWidth * displayScaleX; this.displayHeight = this.nativeHeight * displayScaleY; this.bpp = 8; int flags = 0; this.surfacePtr = SDL_SetVideoMode(this.displayWidth, this.displayHeight, this.bpp, flags); SDL_Rect rect2 = new SDL_Rect(0, 0, (short)this.displayWidth, (short)this.displayHeight); SDL_SetClipRect(this.surfacePtr, ref rect2); }
private void RenderTileFOV(TileFOVInfo tileFOVInfo) { if (!tileFOVInfo.Visible) { return; } byte alpha; if (tileFOVInfo.RevealedByMap) { alpha = BLACK_OPACITY_FOR_REVEALED_BY_MAP; } else if (tileFOVInfo.CoveredByFOV) { alpha = BLACK_OPACITY_FOR_COVERED_BY_FOV; } else { alpha = (byte)(MAX_BLACK_OPACITY_FOR_VISIBLE * tileFOVInfo.DistanceFactor); } var screenPosition = GetScreenPosition(tileFOVInfo.Position); var tRect = new SDL_Rect() { x = screenPosition.X, y = screenPosition.Y, w = BoardComp.TILE_SIZE / 2, h = BoardComp.TILE_SIZE / 2 }; SDL_SetRenderDrawColor(UxContext.WRenderer, 0, 0, 0, alpha); SDL_RenderFillRect(UxContext.WRenderer, ref tRect); }
/// <inheritdoc/> public override Surface2D CreateSurface(Rectangle region) { Contract.EnsureNotDisposed(this, Disposed); if (region.Left < 0 || region.Top < 0 || region.Right > Width || region.Bottom > Height || region.Width <= 0 || region.Height <= 0) { throw new ArgumentOutOfRangeException("region"); } var copysurf = new SDL2PlatformNativeSurface(region.Width, region.Height); var srcrect = new SDL_Rect() { x = region.X, y = region.Y, w = region.Width, h = region.Height }; var dstrect = new SDL_Rect() { x = 0, y = 0, w = region.Width, h = region.Height }; if (SDL_BlitSurface(nativesurf.NativePtr, &srcrect, copysurf.NativePtr, &dstrect) < 0) { throw new SDL2Exception(); } var options = SrgbEncoded ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor; var result = new SDL2Surface2D(Ultraviolet, copysurf, options); return(result); }
/// <summary> /// Blits the surface onto the specified destination surface. /// </summary> /// <param name="src">The source surface.</param> /// <param name="srcRect">The area of this surface that will be copied to the destination surface.</param> /// <param name="dst">The destination surface.</param> /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param> private static void BlitInternal(OpenGLSurface2D src, Rectangle srcRect, OpenGLSurface2D dst, Rectangle dstRect) { var sdlSrcRect = new SDL_Rect() { x = srcRect.X, y = srcRect.Y, w = srcRect.Width, h = srcRect.Height }; var sdlDstRect = new SDL_Rect() { x = dstRect.X, y = dstRect.Y, w = dstRect.Width, h = dstRect.Height }; if (SDL.SetSurfaceBlendMode(src.nativesurf.Native, SDL_BlendMode.NONE) < 0) { throw new SDL2Exception(); } if (srcRect.Width != dstRect.Width || srcRect.Height != dstRect.Height) { if (SDL.BlitScaled(src.nativesurf.Native, &sdlSrcRect, dst.nativesurf.Native, &sdlDstRect) < 0) { throw new SDL2Exception(); } } else { if (SDL.BlitSurface(src.nativesurf.Native, &sdlSrcRect, dst.nativesurf.Native, &sdlDstRect) < 0) { throw new SDL2Exception(); } } }
public void DrawTexture(Texture texture, Transform transform) { Vector2 pos = transform.DoTransform(); Vector2 translated = Translate(pos); translated.x *= Width; translated.y *= Height; SDL_Rect dest = new SDL_Rect { x = (int)(translated.x - transform.center.x * transform.scale), y = (int)(translated.y - transform.center.y * transform.scale), w = (int)(texture.Width * transform.scale), h = (int)(texture.Height * transform.scale), //w = texture.Width, //h = texture.Height, //x = (int)translated.x, //y = (int)translated.y, }; SDL_Point center = new SDL_Point { x = (int)transform.center.x, y = (int)transform.center.y, //x = 0, y = 0, }; SDL_RenderCopyEx(SDLRenderer, texture.SDLTexture, IntPtr.Zero, ref dest, transform.rotation, IntPtr.Zero, SDL_RendererFlip.SDL_FLIP_NONE); }
internal Texture(IntPtr renderer, Palette palette, Bytemap bytemap) { if (palette == null || bytemap == null) { // Do not load empty bitmap _handle = IntPtr.Zero; return; } Width = bytemap.Width; Height = bytemap.Height; _rect = new SDL_Rect { X = 0, Y = 0, W = Width, H = Height }; _renderer = renderer; _handle = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, SDL_TextureAccess.SDL_TEXTUREACCESS_STREAMING, Width, Height); SDL_Rect rect = new SDL_Rect() { X = 0, Y = 0, W = Width, H = Height }; int[] paletteData = PaletteArray(palette); //bool hasAlpha = palette.Entries.Any(x => x.A != 255); if (HasAlpha(palette)) { SDL_SetTextureBlendMode(_handle, SDL_BlendMode.SDL_BLENDMODE_BLEND); } if (SDL_LockTexture(_handle, ref rect, out IntPtr pixels, out int pitch) == 0) { int[] src = bytemap.ToColourMap(paletteData); Marshal.Copy(src, 0, pixels, Width * Height); SDL_UnlockTexture(_handle); } }
public void Render() { var topLeftPoint = UxContext.Center.Substract(UxContext.ScreenSize.Divide(2).ToPoint()); var initialScreenPos = new Point( x: topLeftPoint.X % TextureSize.Width, y: topLeftPoint.Y % TextureSize.Height ); var screenPos = new Point(initialScreenPos.X, initialScreenPos.Y); do { var textureRect = new SDL_Rect() { x = 0, y = 0, w = TextureSize.Width, h = TextureSize.Height, }; var outputRect = new SDL_Rect() { x = screenPos.X, y = screenPos.Y, w = TextureSize.Width, h = TextureSize.Height, }; SDL_RenderCopy(UxContext.WRenderer, Texture, ref textureRect, ref outputRect); screenPos = screenPos.Add(x: TextureSize.Width); if (screenPos.X > UxContext.ScreenSize.Width) { screenPos = new Point(initialScreenPos.X, screenPos.Y + TextureSize.Height); } } while (screenPos.Y < UxContext.ScreenSize.Height); }
public void DrawRgb(IntPtr buff, int width, int storewidth, int height) { //var bitmap = new Bitmap(width, height, storewidth, PixelFormat.Format24bppRgb, buff); //this.Invoke(new MethodInvoker(()=> // { // DrawBitmap(bitmap); // })); SDL_Rect dst = new SDL_Rect(); dst.x = 0; dst.y = 0; dst.w = panel1.Width; dst.h = panel1.Height; IntPtr pic = SDL.SDL_CreateRGBSurfaceFrom(buff, width, height, 24, storewidth, 0x00ff0000, 0x0000ff00, 0x000000ff, 0); IntPtr tex = SDL.SDL_CreateTextureFromSurface(renderer, pic); SDL.SDL_RenderClear(renderer); SDL.SDL_RenderCopy(renderer, tex, IntPtr.Zero, ref dst); SDL.SDL_RenderPresent(renderer); SDL_FreeSurface(pic); SDL_DestroyTexture(tex); }
/// <summary> /// Contains logic which renders data to screen. /// </summary> protected virtual void Render(RenderContext ctx) { foreach (var layerEntry in ctx.OrderBy(x => x.Key)) { foreach (var spriteCtx in layerEntry.Value) { unsafe { var pixels = spriteCtx.Image.ToArray(); fixed(void *p = &pixels[0]) { var texturePtr = SDL_CreateTexture(this.RendererPtr, SDL_PIXELFORMAT_ABGR8888, (int)SDL_TextureAccess.SDL_TEXTUREACCESS_STATIC, spriteCtx.Width, spriteCtx.Height); var rect = new SDL_Rect { w = spriteCtx.Width, h = spriteCtx.Height, x = spriteCtx.PosX, y = spriteCtx.PosY }; SDL_SetRenderTarget(this.RendererPtr, texturePtr); SDL_UpdateTexture(texturePtr, IntPtr.Zero, new IntPtr(p), spriteCtx.Width * 4); SDL_RenderCopy(this.RendererPtr, texturePtr, IntPtr.Zero, ref rect); } } } } }
/// <summary> /// Creates a copy of a region of this surface. /// </summary> /// <param name="region">The region of this surface to copy.</param> /// <returns>A new surface which is a copy of the specified region of this surface.</returns> public override Surface2D CreateSurface(Rectangle region) { Contract.EnsureNotDisposed(this, Disposed); if (region.Left < 0 || region.Top < 0 || region.Right > Width || region.Bottom > Height || region.Width <= 0 || region.Height <= 0) { throw new ArgumentOutOfRangeException("region"); } var copysurf = new SDL_Surface(region.Width, region.Height); var srcrect = new SDL_Rect() { x = region.X, y = region.Y, w = region.Width, h = region.Height }; var dstrect = new SDL_Rect() { x = 0, y = 0, w = region.Width, h = region.Height }; if (SDL.BlitSurface(nativesurf.Native, &srcrect, copysurf.Native, &dstrect) < 0) { throw new SDL2Exception(); } return(new OpenGLSurface2D(Ultraviolet, copysurf)); }
public unsafe void ReadBuffer(byte[] dest) { SDL_Rect rect = new SDL_Rect { x = 0, y = 0, w = Renderer.Window.Width, h = Renderer.Window.Height }; fixed(byte *data = dest) SDL_RenderReadPixels(Context, ref rect, SDL_PIXELFORMAT_RGB24, (IntPtr)data, Renderer.Window.Width * 3); }
public static Rectangle ToRectangle(this SDL_Rect rect) => new Rectangle() { X = rect.x, Y = rect.y, Width = rect.w, Height = rect.h };
public int DrawRect(SDL_Rect rect, Color color) { SDL_SetRenderDrawColor(_rendererPointer, color); int rValue = SDL_RenderDrawRect(_rendererPointer, ref rect); SDL_SetRenderDrawColor(_rendererPointer, DrawColor); return(rValue); }
public unsafe void OnVideoRefresh(Span <byte> srcPixels, int width, int height, int srcPitch) { if (!RefreshVideo) { return; } if (SDL_LockTexture(_emulationTexture, IntPtr.Zero, out var dstPixelsP, out var dstPitch) == 0) { var dstPixels = new Span <byte>((byte *)dstPixelsP, dstPitch * height); if (dstPitch == srcPitch) { srcPixels .Slice(0, height * srcPitch) .CopyTo(dstPixels); } else { var src = srcPixels; var dst = dstPixels; for (int y = 0; y < height; y++) { src.Slice(0, width * 2).CopyTo(dst); src = src.Slice(srcPitch); dst = dst.Slice(dstPitch); } } SDL_UnlockTexture(_emulationTexture); var srcRect = new SDL_Rect { w = width, h = height }; SDL_RenderGetViewport(_renderer, out var maxRect); var dstRect = maxRect; var scaleX = (float)maxRect.w / width; var scaleY = (float)maxRect.h / height; if (scaleX == scaleY) { } else if (scaleX > scaleY) { dstRect.w = (int)(width * scaleY); dstRect.x = (maxRect.w - dstRect.w) / 2; } else { dstRect.h = (int)(height * scaleX); dstRect.y = (maxRect.h - dstRect.h) / 2; } SDL_RenderCopy(_renderer, _emulationTexture, ref srcRect, ref dstRect); SDL_RenderPresent(_renderer); } }
public void ScaleTo(SDLSurface target, int width, int height) { SDL_Rect rect = new SDL_Rect() { x = 0, y = 0, w = width, h = height }; SDL_BlitScaled(surface, IntPtr.Zero, target, ref rect); }
public void DrawText(int x, int y, string text) { var rect = new SDL_Rect(); var texture = IntPtr.Zero; GetTextureAndRect(x, y, text, _font, ref texture, ref rect); Sdl(SDL_RenderCopy(_renderer, texture, IntPtr.Zero, ref rect)); SDL_DestroyTexture(texture); }
void IGraphicsDriver.Fill(RenderRectangle rect, byte color) { SDL_Rect sdlRect = new SDL_Rect() { x = (short)(rect.X * this.displayScaleX), y = (short)(rect.Y * this.displayScaleY), w = (short)(rect.Width * this.displayScaleX), h = (short)(rect.Height * this.displayScaleY) }; SDL_FillRect(this.surfacePtr, ref sdlRect, color); }
public static void DrawRect(int _x, int _y, int _w, int _h) { SDL_Rect r = new SDL_Rect(); r.x = _x; r.y = _y; r.w = _w; r.h = _h; SDL_RenderFillRect(SDLRenderer, ref r); }
public Rect(int X, int Y, int Width, int Height) { SDL_Rect r = new SDL_Rect(); r.x = X; r.y = Y; r.w = Width; r.h = Height; this._SDL_Rect = r; }
public HealthRenderer(UxContext uxContext) : base(uxContext) { Texture = uxContext.GetTexture("player-health-bar.png"); TextureSize = new Size(TEXTURE_WIDTH, TEXTURE_HEIGHT); TextureRect = new SDL_Rect() { x = 0, y = 0, w = TextureSize.Width, h = TextureSize.Height }; }
public PickableRenderer( IGameRenderer gameRenderer, UxContext uxContext, IRenderizable game, IntPtr texture, SDL_Rect textureRect ) : base( uxContext, game, new PickableSpriteProvider <T>(texture, textureRect) ) =>
public virtual Bitmap Screenshot() { Bitmap bmp = new Bitmap(SDL_CreateRGBSurfaceWithFormat(0, this.Width, this.Height, 32, SDL_PIXELFORMAT_RGBA8888)); SDL_Rect rect = new SDL_Rect(); rect.x = 0; rect.y = 0; rect.w = bmp.Width; rect.h = bmp.Height; SDL_RenderReadPixels(this.Renderer.SDL_Renderer, rect, SDL_PIXELFORMAT_RGBA8888, bmp.SurfaceObject.pixels, bmp.SurfaceObject.pitch); return(bmp); }
public static void SetTextInputRectangle(Rect rectangle) { SDL_Rect rect = new SDL_Rect { x = rectangle.X1, y = rectangle.Y1, w = rectangle.Width, h = rectangle.Height }; SDL_SetTextInputRect(ref rect); }
public PlayerAnimationProvider(UxContext uxContext, int playerRadius) { Texture = uxContext.GetTexture("player-texture.png"); var playerDiameter = playerRadius * 2; MaskTexture = Masks.GetCircleMask(playerRadius); TextureRect = new SDL_Rect { x = 0, y = 0, w = playerDiameter, h = playerDiameter }; OutputSize = new Size(TextureRect.w, TextureRect.h); NonRepeatingTextureSize = 64 - TextureRect.w; }
void IGraphicsDriver.Shake(byte count) { const int Offset = 3; const int Delay = 100; int scaledOffsetX = Offset * this.displayScaleX; int scaledOffsetY = Offset * this.displayScaleY; SDL_Surface surface = (SDL_Surface)Marshal.PtrToStructure(this.surfacePtr, typeof(SDL_Surface)); // Save screen byte[] backup = new byte[surface.pitch * this.displayHeight]; Marshal.Copy(surface.pixels, backup, 0, surface.pitch * this.displayHeight); for (byte c = 0; c < count; c++) { SDL_Delay(Delay); // Draw black on left SDL_Rect leftRect = new SDL_Rect() { x = (short)0, y = (short)0, w = (short)scaledOffsetX, h = (short)this.displayHeight }; SDL_FillRect(this.surfacePtr, ref leftRect, 0); // Draw black on top SDL_Rect topRect = new SDL_Rect() { x = (short)0, y = (short)0, w = (short)this.displayWidth, h = (short)scaledOffsetY }; SDL_FillRect(this.surfacePtr, ref topRect, 0); // Draw screen at offset for (int j = 0; j < this.displayHeight - scaledOffsetY; j++) { int x = surface.pixels.ToInt32() + ((j + scaledOffsetY) * surface.pitch) + scaledOffsetY; int length = this.displayWidth - scaledOffsetX; IntPtr ptr = new IntPtr(x); Marshal.Copy(backup, j * surface.pitch, ptr, length); } SDL_UpdateWindowSurface(this.windowPtr); SDL_Delay(Delay); // Restore screen Marshal.Copy(backup, 0, surface.pixels, surface.pitch * this.displayHeight); SDL_UpdateWindowSurface(this.windowPtr); } }
public void DrawTexture(Texture texture, int x, int y, int w, int h) { Vector2 translated = Translate(new Vector2(x, y)); SDL_Rect dest = new SDL_Rect { x = (int)translated.x, y = (int)translated.y, w = w, h = h, }; SDL_RenderCopy(SDLRenderer, texture.SDLTexture, IntPtr.Zero, ref dest); }
public void FillRectUntranslated(float x, float y, float w, float h, byte r, byte g, byte b, byte a) { SDL_SetRenderDrawColor(SDLRenderer, r, g, b, a); SDL_Rect rect = new SDL_Rect { x = (int)x, y = (int)y, w = (int)w, h = (int)h }; SDL_RenderFillRect(SDLRenderer, ref rect); }
public void FillRect(int x, int y, int w, int h, byte r, byte g, byte b, byte a) { SDL_SetRenderDrawColor(SDLRenderer, r, g, b, a); Vector2 translated = Translate(new Vector2(x, y)); SDL_Rect rect = new SDL_Rect { x = (int)translated.x, y = (int)translated.y, w = w, h = h }; SDL_RenderFillRect(SDLRenderer, ref rect); }
public static extern int SDL_SoftStretch( ref SDL_Surface src, ref SDL_Rect srcrect, ref SDL_Surface dst, ref SDL_Rect dstrect );
public static extern int SDL_DisplayYUVOverlay(IntPtr overlay, ref SDL_Rect dstrect);
public static extern int SDL_FillRect( ref SDL_Surface dst, ref SDL_Rect rect, uint color );
public static extern int SDL_UpdateWindowSurfaceRects( IntPtr window, SDL_Rect[] rects, int numrects );
public static extern SDL_bool SDL_HasIntersection( ref SDL_Rect A, ref SDL_Rect B );
public static int SDL_BlitSurface(/* SDL_Surface * */IntPtr src, /* SDL_Rect * */ref SDL_Rect srcrect, /* SDL_Surface * */IntPtr dst, /* SDL_Rect * */ref SDL_Rect dstrect) { return SDL_BlitSurface_(src, ref srcrect, dst, ref dstrect); }
static extern IntPtr SDL_FillRect(IntPtr surface, ref SDL_Rect rect, int color);
public static extern SDL_bool SDL_RectEmpty(ref SDL_Rect rect);
public static extern SDL_bool SDL_RectEquals( ref SDL_Rect A, ref SDL_Rect B );
public static extern void SDL_SetClipRect(IntPtr surface, ref SDL_Rect rect);
public static extern void SDL_UnionRect( ref SDL_Rect A, ref SDL_Rect B, ref SDL_Rect result );
public static int SDL_FillRect(/* SDL_Surface * */IntPtr dst, /* SDL_Rect * */ref SDL_Rect dstrect, Uint32 color) { return SDL_FillRect_(dst, ref dstrect, color); }
public static extern SDL_bool SDL_IntersectRect( ref SDL_Rect A, ref SDL_Rect B, ref SDL_Rect result );
public static extern void SDL_GL_UpdateRects(int numrects, /* SDL_Rect* */ref SDL_Rect rects);
public static extern int SDL_BlitSurface(IntPtr src, ref SDL_Rect srcrect, IntPtr dst, ref SDL_Rect dstrect);
public static extern int SDL_GetDisplayBounds( int displayIndex, ref SDL_Rect rect );
public static extern int SDL_UpperBlitScaled( ref SDL_Surface src, ref SDL_Rect srcrect, ref SDL_Surface dst, ref SDL_Rect dstrect );
public static extern int SDL_FillRects( ref SDL_Surface dst, SDL_Rect[] rects, int count, uint color );
public static extern int SDL_DisplayYUVOverlay(/* SDL_Overlay * */IntPtr overlay, /* SDL_Rect * */ref SDL_Rect dstrect);
public static extern int SDL_SoftStretch(/* SDL_Surface * */IntPtr src, /* SDL_Rect * */ref SDL_Rect srcrect, /* SDL_Surface * */IntPtr dst, /* SDL_Rect * */ref SDL_Rect dstrect);
public static extern void SDL_GetClipRect(/* SDL_Surface * */IntPtr surface, /* SDL_Rect * */ref SDL_Rect rect);
private static unsafe int SDL_BlitSurface_(/* SDL_Surface * */IntPtr src, /* SDL_Rect * */ref SDL_Rect srcrect, /* SDL_Surface * */IntPtr dst, /* SDL_Rect * */ref SDL_Rect dstrect) { fixed (SDL_Rect* s = &srcrect) { fixed (SDL_Rect* d = &dstrect) { return SDL_UpperBlit(src, (IntPtr)s, dst, (IntPtr)d); } } }
public static extern SDL_bool SDL_SetClipRect(/* SDL_Surface * */IntPtr surface, /* SDL_Rect * */ref SDL_Rect rect);
public static extern void SDL_SetTextInputRect(ref SDL_Rect rect);
public static extern void SDL_UpdateRects(/* SDL_Surface * */IntPtr screen, int numrects, /* SDL_Rect * */ref SDL_Rect rects);
public static extern int SDL_LowerBlit( ref SDL_Surface src, ref SDL_Rect srcrect, ref SDL_Surface dst, ref SDL_Rect dstrect );
private static unsafe int SDL_FillRect_(/* SDL_Surface * */IntPtr dst, /* SDL_Rect * */ref SDL_Rect dstrect, Uint32 color) { fixed (SDL_Rect* d = &dstrect) { return SDL_FillRect(dst, (IntPtr)d, color); } }
public static extern SDL_bool SDL_IntersectRectAndLine( ref SDL_Rect rect, ref int X1, ref int Y1, ref int X2, ref int Y2 );
public static extern void SDL_GetClipRect( ref SDL_Surface surface, ref SDL_Rect rect );
public static extern SDL_bool SDL_SetClipRect( ref SDL_Surface surface, ref SDL_Rect rect );