Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 62 additions & 11 deletions src/Myra/Graphics2D/RenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,29 @@ namespace Myra.Graphics2D
public enum TextureFiltering
{
Nearest,
Linear
}
Linear,
Anisotropic
}

public partial class RenderContext : IDisposable
{
#if MONOGAME || FNA
private static RasterizerState _uiRasterizerState;

private static RasterizerState UIRasterizerState
private static SamplerState _textureFilteringAnisotropic = new SamplerState
{
Filter = TextureFilter.Anisotropic,
AddressU = TextureAddressMode.Clamp,
AddressV = TextureAddressMode.Clamp,
AddressW = TextureAddressMode.Clamp,
BorderColor = Color.Transparent,
MaxAnisotropy = 16,
MaxMipLevel = 16,
MipMapLevelOfDetailBias = 0f,
ComparisonFunction = CompareFunction.Never,
FilterMode = TextureFilterMode.Default
};

private static RasterizerState UIRasterizerState
{
get
{
Expand Down Expand Up @@ -105,6 +119,7 @@ internal Rectangle DeviceScissor
}
}

private bool _isAnisotropicFilteringOn;

public Rectangle Scissor
{
Expand Down Expand Up @@ -255,7 +270,7 @@ public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? s
/// <param name="depth"></param>
public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 scale, float depth = 0.0f)
{
SetTextureFiltering(TextureFiltering.Nearest);
SetTextureFiltering(_isAnisotropicFilteringOn ? TextureFiltering.Anisotropic : TextureFiltering.Nearest);
color = CrossEngineStuff.MultiplyColor(color, Opacity);
scale *= Transform.Scale;
rotation += Transform.Rotation;
Expand Down Expand Up @@ -430,7 +445,7 @@ public void DrawRichText(RichTextLayout richText, Vector2 position, Color color,
public void Begin()
{
#if MONOGAME || FNA
var samplerState = _textureFiltering == TextureFiltering.Nearest ? SamplerState.PointClamp : SamplerState.LinearClamp;
var samplerState = SelectedSamplerState();

_renderer.Begin(SpriteSortMode.Deferred,
BlendState.AlphaBlend,
Expand All @@ -439,9 +454,8 @@ public void Begin()
UIRasterizerState,
null);
#elif STRIDE
var samplerState = _textureFiltering == TextureFiltering.Nearest ?
MyraEnvironment.Game.GraphicsDevice.SamplerStates.PointClamp :
MyraEnvironment.Game.GraphicsDevice.SamplerStates.LinearClamp;
var samplerState = SelectedSamplerState();

_renderer.Begin(MyraEnvironment.Game.GraphicsContext,
SpriteSortMode.Deferred,
BlendStates.AlphaBlend,
Expand All @@ -455,7 +469,39 @@ public void Begin()
_beginCalled = true;
}

public void End()
#if MONOGAME || FNA
private SamplerState SelectedSamplerState()
{
switch (_textureFiltering)
{
case TextureFiltering.Nearest:
return SamplerState.PointClamp;
case TextureFiltering.Linear:
return SamplerState.LinearClamp;
case TextureFiltering.Anisotropic:
return _textureFilteringAnisotropic;
default:
throw new ArgumentOutOfRangeException();
}
}
#elif STRIDE
private SamplerState SelectedSamplerState()
{
switch (_textureFiltering)
{
case TextureFiltering.Nearest:
return MyraEnvironment.Game.GraphicsDevice.SamplerStates.PointClamp;
case TextureFiltering.Linear:
return MyraEnvironment.Game.GraphicsDevice.SamplerStates.LinearClamp;
case TextureFiltering.Anisotropic:
return MyraEnvironment.Game.GraphicsDevice.SamplerStates.AnisotropicClamp;
default:
throw new ArgumentOutOfRangeException();
}
}
#endif

public void End()
{
_renderer.End();
_beginCalled = false;
Expand Down Expand Up @@ -489,5 +535,10 @@ public void Dispose()
{
ReleaseUnmanagedResources();
}
}

public void SetAnisotropicFilteringMode(bool isAnisotropicFiltering)
{
_isAnisotropicFilteringOn = isAnisotropicFiltering;
}
}
}
10 changes: 8 additions & 2 deletions src/Myra/Graphics2D/UI/Containers/ScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ public IImage VerticalScrollKnob
get; set;
}

[Browsable(false)]
[Category("Appearance")]
public int ScrollMultiplier
{
get; set;
} = 10;

[Browsable(false)]
[Content]
public override Widget Content
{
Expand Down Expand Up @@ -395,7 +401,7 @@ public override void OnMouseWheel(float delta)
return;
}

var step = 10 * ScrollMaximum.Y / _thumbMaximumY;
var step = ScrollMultiplier * ScrollMaximum.Y / _thumbMaximumY;
if (delta < 0)
{
_scrollbarOrientation = Orientation.Vertical;
Expand Down
23 changes: 20 additions & 3 deletions src/Myra/Graphics2D/UI/Simple/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,22 @@ public class Image : Widget, IPressable
{
private IImage _image, _overImage, _pressedImage;

[Category("Appearance")]
private bool _isAnisotropicFiltering = false;

public bool IsAnisotropicFiltering
{
get
{
return _isAnisotropicFiltering;
}
set
{
_isAnisotropicFiltering = value;
InvalidateMeasure();
}
}

[Category("Appearance")]
public IImage Renderable
{
get
Expand Down Expand Up @@ -164,8 +179,10 @@ public override void InternalRender(RenderContext context)
bounds.Height = (int)(bounds.Width * aspect);
}

image.Draw(context, bounds, Color);
}
context.SetAnisotropicFilteringMode(_isAnisotropicFiltering);
image.Draw(context, bounds, Color);
context.SetAnisotropicFilteringMode(false);
}
}

public void ApplyPressableImageStyle(PressableImageStyle imageStyle)
Expand Down
Loading