protected virtual void Dispose(bool disposing) { if (disposing) { } Texture = null; }
public static void Draw(DrawContext drawContext, Camera camera, Box2 bounds, float opacity, Project project, FrameStats frameStats, OsbSprite sprite) { var time = project.DisplayTime * 1000; if (sprite.TexturePath == null || !sprite.IsActive(time)) { return; } if (frameStats != null) { frameStats.SpriteCount++; frameStats.CommandCount += sprite.CommandCost; frameStats.IncompatibleCommands |= sprite.HasIncompatibleCommands; frameStats.OverlappedCommands |= sprite.HasOverlappedCommands; } var fade = sprite.OpacityAt(time); if (fade < 0.00001f) { return; } var scale = (Vector2)sprite.ScaleAt(time); if (scale.X == 0 || scale.Y == 0) { return; } if (sprite.FlipHAt(time)) { scale.X = -scale.X; } if (sprite.FlipVAt(time)) { scale.Y = -scale.Y; } Texture2dRegion texture = null; var fullPath = Path.Combine(project.MapsetPath, sprite.GetTexturePathAt(time)); try { texture = project.TextureContainer.Get(fullPath); if (texture == null) { fullPath = Path.Combine(project.ProjectAssetFolderPath, sprite.GetTexturePathAt(time)); texture = project.TextureContainer.Get(fullPath); } } catch (IOException) { // Happens when another process is writing to the file, will try again later. return; } if (texture == null) { return; } var position = sprite.PositionAt(time); var rotation = sprite.RotationAt(time); var color = sprite.ColorAt(time); var finalColor = ((Color4)color) .LerpColor(Color4.Black, project.DimFactor) .WithOpacity(opacity * fade); var additive = sprite.AdditiveAt(time); var origin = GetOriginVector(sprite.Origin, texture.Width, texture.Height); if (frameStats != null) { var size = texture.Size * scale; var spriteObb = new OrientedBoundingBox(position, origin * scale, size.X, size.Y, rotation); if (spriteObb.Intersects(OsuHitObject.WidescreenStoryboardBounds)) { frameStats.EffectiveCommandCount += sprite.CommandCost; // Approximate how much of the sprite is on screen var spriteAabb = spriteObb.GetAABB(); var intersection = spriteAabb.IntersectWith(OsuHitObject.WidescreenStoryboardBounds); var aabbIntersectionFactor = (intersection.Width * intersection.Height) / (spriteAabb.Width * spriteAabb.Height); var intersectionArea = size.X * size.Y * aabbIntersectionFactor; frameStats.ScreenFill += Math.Min(OsuHitObject.WidescreenStoryboardArea, intersectionArea) / OsuHitObject.WidescreenStoryboardArea; } } var boundsScaling = bounds.Height / 480; DrawState.Prepare(drawContext.Get <QuadRenderer>(), camera, additive ? AdditiveStates : AlphaBlendStates) .Draw(texture, bounds.Left + bounds.Width * 0.5f + (position.X - 320) * boundsScaling, bounds.Top + position.Y * boundsScaling, origin.X, origin.Y, scale.X * boundsScaling, scale.Y * boundsScaling, rotation, finalColor); }
public void Draw(Texture2dRegion texture, float x, float y, float originX, float originY, float scaleX, float scaleY, float rotation, Color4 color, float textureX0, float textureY0, float textureX1, float textureY1) { if (!rendering) { throw new InvalidOperationException("Not rendering"); } if (texture == null) { throw new ArgumentNullException(nameof(texture)); } if (currentTexture != texture.BindableTexture) { DrawState.FlushRenderer(); currentTexture = texture.BindableTexture; } else if (spritesInBatch == maxSpritesPerBatch) { DrawState.FlushRenderer(true); } var width = textureX1 - textureX0; var height = textureY1 - textureY0; float fx = -originX; float fy = -originY; float fx2 = width - originX; float fy2 = height - originY; var flipX = false; var flipY = false; if (scaleX != 1 || scaleY != 1) { flipX = scaleX < 0; flipY = scaleY < 0; var absScaleX = flipX ? -scaleX : scaleX; var absScaleY = flipY ? -scaleY : scaleY; fx *= absScaleX; fy *= absScaleY; fx2 *= absScaleX; fy2 *= absScaleY; } float p1x = fx; float p1y = fy; float p2x = fx; float p2y = fy2; float p3x = fx2; float p3y = fy2; float p4x = fx2; float p4y = fy; float x1; float y1; float x2; float y2; float x3; float y3; float x4; float y4; if (rotation != 0) { var cos = (float)Math.Cos(rotation); var sin = (float)Math.Sin(rotation); x1 = cos * p1x - sin * p1y; y1 = sin * p1x + cos * p1y; x2 = cos * p2x - sin * p2y; y2 = sin * p2x + cos * p2y; x3 = cos * p3x - sin * p3y; y3 = sin * p3x + cos * p3y; x4 = x1 + (x3 - x2); y4 = y3 - (y2 - y1); } else { x1 = p1x; y1 = p1y; x2 = p2x; y2 = p2y; x3 = p3x; y3 = p3y; x4 = p4x; y4 = p4y; } var spritePrimitive = default(SpritePrimitive); spritePrimitive.x1 = x1 + x; spritePrimitive.y1 = y1 + y; spritePrimitive.x2 = x2 + x; spritePrimitive.y2 = y2 + y; spritePrimitive.x3 = x3 + x; spritePrimitive.y3 = y3 + y; spritePrimitive.x4 = x4 + x; spritePrimitive.y4 = y4 + y; var textureUvBounds = texture.UvBounds; var textureUvRatio = texture.UvRatio; var textureU0 = textureUvBounds.Left + textureX0 * textureUvRatio.X; var textureV0 = textureUvBounds.Top + textureY0 * textureUvRatio.Y; var textureU1 = textureUvBounds.Left + textureX1 * textureUvRatio.X; var textureV1 = textureUvBounds.Top + textureY1 * textureUvRatio.Y; float u0, v0, u1, v1; if (flipX) { u0 = textureU1; u1 = textureU0; } else { u0 = textureU0; u1 = textureU1; } if (flipY) { v0 = textureV1; v1 = textureV0; } else { v0 = textureV0; v1 = textureV1; } spritePrimitive.u1 = u0; spritePrimitive.v1 = v0; spritePrimitive.u2 = u0; spritePrimitive.v2 = v1; spritePrimitive.u3 = u1; spritePrimitive.v3 = v1; spritePrimitive.u4 = u1; spritePrimitive.v4 = v0; spritePrimitive.color1 = spritePrimitive.color2 = spritePrimitive.color3 = spritePrimitive.color4 = color.ToRgba(); spriteArray[spritesInBatch] = spritePrimitive; RenderedSpriteCount++; spritesInBatch++; }
public void Draw(Texture2dRegion texture, float x, float y, float originX, float originY, float scaleX, float scaleY, float rotation, Color4 color) => Draw(texture, x, y, originX, originY, scaleX, scaleY, rotation, color, 0, 0, texture.Width, texture.Height);
public static void Draw(DrawContext drawContext, Camera camera, Box2 bounds, float opacity, Project project, OsbSprite sprite) { var time = project.DisplayTime * 1000; if (sprite.TexturePath == null || !sprite.IsActive(time)) { return; } var fade = sprite.OpacityAt(time); if (fade < 0.00001f) { return; } var scale = (Vector2)sprite.ScaleAt(time); if (scale.X == 0 || scale.Y == 0) { return; } if (sprite.FlipHAt(time)) { scale.X = -scale.X; } if (sprite.FlipVAt(time)) { scale.Y = -scale.Y; } var fullPath = Path.Combine(project.MapsetPath, sprite.GetTexturePathAt(time)); Texture2dRegion texture = null; try { texture = project.TextureContainer.Get(fullPath); } catch (IOException) { // Happens when another process is writing to the file, will try again later. return; } if (texture == null) { return; } var position = sprite.PositionAt(time); var rotation = sprite.RotationAt(time); var color = sprite.ColorAt(time); var finalColor = ((Color4)color).WithOpacity(opacity * fade); var additive = sprite.AdditiveAt(time); Vector2 origin; switch (sprite.Origin) { default: case OsbOrigin.TopLeft: origin = new Vector2(0, 0); break; case OsbOrigin.TopCentre: origin = new Vector2(texture.Width * 0.5f, 0); break; case OsbOrigin.TopRight: origin = new Vector2(texture.Width, 0); break; case OsbOrigin.CentreLeft: origin = new Vector2(0, texture.Height * 0.5f); break; case OsbOrigin.Centre: origin = new Vector2(texture.Width * 0.5f, texture.Height * 0.5f); break; case OsbOrigin.CentreRight: origin = new Vector2(texture.Width, texture.Height * 0.5f); break; case OsbOrigin.BottomLeft: origin = new Vector2(0, texture.Height); break; case OsbOrigin.BottomCentre: origin = new Vector2(texture.Width * 0.5f, texture.Height); break; case OsbOrigin.BottomRight: origin = new Vector2(texture.Width, texture.Height); break; } var boundsScaling = bounds.Height / 480; DrawState.Prepare(drawContext.Get <SpriteRenderer>(), camera, additive ? AdditiveStates : AlphaBlendStates) .Draw(texture, bounds.Left + bounds.Width * 0.5f + (position.X - 320) * boundsScaling, bounds.Top + position.Y * boundsScaling, origin.X, origin.Y, scale.X * boundsScaling, scale.Y * boundsScaling, rotation, finalColor); }
public FontGlyph(Texture2dRegion texture, int width, int height) { this.texture = texture; this.width = width; this.height = height; }