Skip to content

Commit

Permalink
Merge branch 'master' into fix-ugly-ime-sdl3
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach authored Nov 8, 2024
2 parents 1a09aaf + d4d9cca commit 04acf05
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
# Attempt to upload results even if test fails.
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#always
- name: Upload Test Results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: osu-framework-test-results-${{matrix.os.prettyname}}-${{matrix.threadingMode}}-${{matrix.os.configuration}}
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework.Android/osu.Framework.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ProjectReference Include="..\osu.Framework\osu.Framework.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.SDL3-CS.Android" Version="2024.1015.0" />
<PackageReference Include="ppy.SDL3-CS.Android" Version="2024.1022.0" />
<PackageReference Include="Xamarin.AndroidX.Window" Version="1.2.0.1" PrivateAssets="compile" />
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions osu.Framework.Tests/Graphics/RendererTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,28 @@ public void TestWhitePixelReuseUpdatesTextureWrapping()
Assert.That(renderer.CurrentWrapModeS, Is.EqualTo(WrapMode.None));
Assert.That(renderer.CurrentWrapModeS, Is.EqualTo(WrapMode.None));
}

[Test]
public void TestTextureAtlasReuseUpdatesTextureWrapping()
{
DummyRenderer renderer = new DummyRenderer();

TextureAtlas atlas = new TextureAtlas(renderer, 1024, 1024);

Texture textureWrapNone = atlas.Add(100, 100, WrapMode.None, WrapMode.None)!;
Texture textureWrapClamp = atlas.Add(100, 100, WrapMode.ClampToEdge, WrapMode.ClampToEdge)!;

renderer.BindTexture(textureWrapNone, 0, null, null);
Assert.That(renderer.CurrentWrapModeS, Is.EqualTo(WrapMode.None));
Assert.That(renderer.CurrentWrapModeT, Is.EqualTo(WrapMode.None));

renderer.BindTexture(textureWrapClamp, 0, null, null);
Assert.That(renderer.CurrentWrapModeS, Is.EqualTo(WrapMode.ClampToEdge));
Assert.That(renderer.CurrentWrapModeT, Is.EqualTo(WrapMode.ClampToEdge));

renderer.BindTexture(textureWrapNone, 0, null, null);
Assert.That(renderer.CurrentWrapModeS, Is.EqualTo(WrapMode.None));
Assert.That(renderer.CurrentWrapModeT, Is.EqualTo(WrapMode.None));
}
}
}
27 changes: 27 additions & 0 deletions osu.Framework.Tests/Visual/UserInterface/TestSceneSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public TestSceneSliderBar()
Size = new Vector2(200, 50),
BackgroundColour = Color4.White,
SelectionColour = Color4.Pink,
FocusColour = Color4.OrangeRed,
KeyboardStep = 1,
Current = sliderBarValue
},
Expand All @@ -72,6 +73,7 @@ public TestSceneSliderBar()
RangePadding = 20,
BackgroundColour = Color4.White,
SelectionColour = Color4.Pink,
FocusColour = Color4.OrangeRed,
KeyboardStep = 1,
Current = sliderBarValue
},
Expand All @@ -85,6 +87,7 @@ public TestSceneSliderBar()
Size = new Vector2(200, 10),
BackgroundColour = Color4.White,
SelectionColour = Color4.Pink,
FocusColour = Color4.OrangeRed,
KeyboardStep = 1,
Current = sliderBarValue
},
Expand All @@ -97,6 +100,7 @@ public TestSceneSliderBar()
Size = new Vector2(200, 10),
BackgroundColour = Color4.White,
SelectionColour = Color4.Pink,
FocusColour = Color4.OrangeRed,
KeyboardStep = 1,
Current = sliderBarValue
},
Expand All @@ -109,6 +113,8 @@ public TestSceneSliderBar()
{
sliderBar.Current.Disabled = false;
sliderBar.Current.Value = 0;
sliderBar.GetContainingFocusManager()!.ChangeFocus(null);
sliderBarWithNub.GetContainingFocusManager()!.ChangeFocus(null);
});

[Test]
Expand All @@ -122,6 +128,7 @@ public void TestVerticalDragHasNoEffect()
() => { InputManager.MoveMouseTo(sliderBar.ToScreenSpace(sliderBar.DrawSize * new Vector2(0.75f, 1f))); });
AddStep("Release Click", () => { InputManager.ReleaseButton(MouseButton.Left); });
checkValue(0);
AddAssert("Slider has no focus", () => !sliderBar.HasFocus);
}

[Test]
Expand All @@ -136,6 +143,7 @@ public void TestDragOutReleaseInHasNoEffect()
AddStep("Drag Up", () => { InputManager.MoveMouseTo(sliderBar.ToScreenSpace(sliderBar.DrawSize * new Vector2(0.25f, 0.5f))); });
AddStep("Release Click", () => { InputManager.ReleaseButton(MouseButton.Left); });
checkValue(0);
AddAssert("Slider has focus", () => sliderBar.HasFocus);
}

[Test]
Expand All @@ -160,6 +168,23 @@ public void TestKeyboardInput()
InputManager.ReleaseKey(Key.Right);
});
checkValue(1);

AddStep("Click slider", () => InputManager.Click(MouseButton.Left));
checkValue(-5);

AddAssert("Slider has focus", () => sliderBar.HasFocus);

AddStep("move mouse outside", () =>
{
InputManager.MoveMouseTo(sliderBar.ToScreenSpace(sliderBar.DrawSize * new Vector2(2f, 0.5f)));
});

AddStep("Press right arrow key", () =>
{
InputManager.PressKey(Key.Right);
InputManager.ReleaseKey(Key.Right);
});
checkValue(-4);
}

[TestCase(false)]
Expand Down Expand Up @@ -246,6 +271,7 @@ public void TestAbsoluteDrag()
() => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.4f, 1f))); });
AddStep("Release Click", () => { InputManager.ReleaseButton(MouseButton.Left); });
checkValue(-2);
AddAssert("Slider has focus", () => sliderBarWithNub.HasFocus);
}

[Test]
Expand All @@ -259,6 +285,7 @@ public void TestRelativeDrag()
() => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.75f, 1f))); });
AddStep("Release Click", () => { InputManager.ReleaseButton(MouseButton.Left); });
checkValue(3);
AddAssert("Slider has focus", () => sliderBarWithNub.HasFocus);
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/FrameworkEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static FrameworkEnvironment()
if (DebugUtils.IsDebugBuild)
AllowInsecureRequests = parseBool(Environment.GetEnvironmentVariable("OSU_INSECURE_REQUESTS")) ?? false;

UseSDL3 = RuntimeInfo.IsMobile || (parseBool(Environment.GetEnvironmentVariable("OSU_SDL3")) ?? false);
UseSDL3 = RuntimeInfo.IsMobile || (parseBool(Environment.GetEnvironmentVariable("OSU_SDL3")) ?? true);
}

private static bool? parseBool(string? value)
Expand Down
3 changes: 3 additions & 0 deletions osu.Framework/Graphics/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,10 @@ public bool BindTexture(Texture texture, int unit, WrapMode? wrapModeS, WrapMode
public bool BindTexture(INativeTexture texture, int unit = 0, WrapMode wrapModeS = WrapMode.None, WrapMode wrapModeT = WrapMode.None)
{
if (lastActiveTextureUnit == unit && lastBoundTexture[unit] == texture)
{
setWrapMode(wrapModeS, wrapModeT);
return true;
}

FlushCurrentBatch(FlushBatchSource.BindTexture);

Expand Down
42 changes: 41 additions & 1 deletion osu.Framework/Graphics/UserInterface/BasicSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Numerics;
using osuTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using Vector2 = osuTK.Vector2;

namespace osu.Framework.Graphics.UserInterface
Expand All @@ -23,6 +24,18 @@ public Color4 SelectionColour
set => SelectionBox.Colour = value;
}

private Color4 focusColour = FrameworkColour.YellowGreen;

public Color4 FocusColour
{
get => focusColour;
set
{
focusColour = value;
updateFocus();
}
}

protected readonly Box SelectionBox;
protected readonly Box Box;

Expand All @@ -37,10 +50,37 @@ public BasicSliderBar()
},
SelectionBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = FrameworkColour.Yellow,
RelativeSizeAxes = Axes.Both,
}
};

Masking = true;
}

protected override void OnFocus(FocusEvent e)
{
updateFocus();
base.OnFocus(e);
}

protected override void OnFocusLost(FocusLostEvent e)
{
updateFocus();
base.OnFocusLost(e);
}

private void updateFocus()
{
if (HasFocus)
{
BorderThickness = 3;
BorderColour = FocusColour;
}
else
{
BorderThickness = 0;
}
}

protected override void UpdateValue(float value)
Expand Down
5 changes: 4 additions & 1 deletion osu.Framework/Graphics/UserInterface/SliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,21 @@ protected override bool OnDragStart(DragStartEvent e)
return false;
}

GetContainingFocusManager()?.ChangeFocus(this);
handleMouseInput(e);
return true;
}

protected override void OnDragEnd(DragEndEvent e) => Commit();

public override bool AcceptsFocus => true;

protected override bool OnKeyDown(KeyDownEvent e)
{
if (currentNumberInstantaneous.Disabled)
return false;

if (!IsHovered)
if (!IsHovered && !HasFocus)
return false;

float step = KeyboardStep != 0 ? KeyboardStep : (Convert.ToSingle(currentNumberInstantaneous.MaxValue) - Convert.ToSingle(currentNumberInstantaneous.MinValue)) / 20;
Expand Down
32 changes: 18 additions & 14 deletions osu.Framework/Graphics/Visualisation/DrawVisualiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ protected override void Update()
overlay.Target = Searching ? cursorTarget : inputManager.HoveredDrawables.OfType<VisualisedDrawable>().FirstOrDefault()?.Target;
}

private static readonly Dictionary<Type, bool> is_type_valid_target_cache = new Dictionary<Type, bool>();

private void updateCursorTarget()
{
Drawable drawableTarget = null;
Expand Down Expand Up @@ -268,30 +270,32 @@ void findTarget(Drawable drawable)
if (!validForTarget(drawable))
return;

// Special case for full-screen overlays that act as input receptors, but don't display anything
if (!hasCustomDrawNode(drawable))
return;

drawableTarget = drawable;
}
}

// Valid if the drawable contains the mouse position and the position wouldn't be masked by the parent
bool validForTarget(Drawable drawable)
=> drawable.ScreenSpaceDrawQuad.Contains(inputManager.CurrentState.Mouse.Position)
&& maskingQuad?.Contains(inputManager.CurrentState.Mouse.Position) != false;
}
{
if (!drawable.ScreenSpaceDrawQuad.Contains(inputManager.CurrentState.Mouse.Position)
|| maskingQuad?.Contains(inputManager.CurrentState.Mouse.Position) == false)
{
return false;
}

private static readonly Dictionary<Type, bool> has_custom_drawnode_cache = new Dictionary<Type, bool>();
Type type = drawable.GetType();

private bool hasCustomDrawNode(Drawable drawable)
{
var type = drawable.GetType();
if (is_type_valid_target_cache.TryGetValue(type, out bool valid))
return valid;

if (has_custom_drawnode_cache.TryGetValue(type, out bool existing))
return existing;
// Exclude "overlay" objects (Component/etc) that don't draw anything and don't override CreateDrawNode().
valid = type.GetMethod(nameof(CreateDrawNode), BindingFlags.Instance | BindingFlags.NonPublic)?.DeclaringType != typeof(Drawable);

return has_custom_drawnode_cache[type] = type.GetMethod(nameof(CreateDrawNode), BindingFlags.Instance | BindingFlags.NonPublic)?.DeclaringType != typeof(Drawable);
// Exclude objects that specify they should be hidden anyway.
valid &= !type.GetCustomAttributes<DrawVisualiserHiddenAttribute>(true).Any();

return is_type_valid_target_cache[type] = valid;
}
}

public bool Searching { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;

namespace osu.Framework.Graphics.Visualisation
{
/// <summary>
/// Indicates that instances of this type or any subtype should not be valid targets for the draw visualiser.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class DrawVisualiserHiddenAttribute : Attribute;
}
22 changes: 14 additions & 8 deletions osu.Framework/IO/Network/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public class WebRequest : IDisposable
/// <summary>
/// FILE parameters.
/// </summary>
private readonly IDictionary<string, byte[]> files = new Dictionary<string, byte[]>();
private readonly List<FormFile> files = new List<FormFile>();

/// <summary>
/// The request headers.
Expand Down Expand Up @@ -349,9 +349,9 @@ private async Task internalPerform(CancellationToken cancellationToken = default

foreach (var p in files)
{
var byteContent = new ByteArrayContent(p.Value);
var byteContent = new ByteArrayContent(p.Content);
byteContent.Headers.Add("Content-Type", "application/octet-stream");
formData.Add(byteContent, p.Key, p.Key);
formData.Add(byteContent, p.ParamName, p.Filename);
}

postContent = await formData.ReadAsStreamAsync(linkedToken.Token).ConfigureAwait(false);
Expand Down Expand Up @@ -662,17 +662,21 @@ public void AddRaw(Stream stream)
}

/// <summary>
/// Add a new FILE parameter to this request. Replaces any existing file with the same name.
/// Add a new FILE parameter to this request.
/// This may not be used in conjunction with <see cref="AddRaw(Stream)"/>. GET requests may not contain files.
/// </summary>
/// <param name="name">The name of the file. This becomes the name of the file in a multi-part form POST content.</param>
/// <param name="paramName">The name of the form parameter of the request that the file relates to.</param>
/// <param name="data">The file data.</param>
public void AddFile(string name, byte[] data)
/// <param name="filename">
/// The filename of the file to be sent to be reported to the server in the <c>Content-Disposition</c> header.
/// <c>blob</c> is used by default if omitted, to <see href="https://developer.mozilla.org/en-US/docs/Web/API/FormData/append#filename">mirror browser behaviour</see>.
/// </param>
public void AddFile(string paramName, byte[] data, string filename = "blob")
{
ArgumentNullException.ThrowIfNull(name);
ArgumentNullException.ThrowIfNull(paramName);
ArgumentNullException.ThrowIfNull(data);

files[name] = data;
files.Add(new FormFile(paramName, data, filename));
}

/// <summary>
Expand Down Expand Up @@ -931,5 +935,7 @@ protected override void Dispose(bool disposing)
baseStream.Dispose();
}
}

private record struct FormFile(string ParamName, byte[] Content, string Filename);
}
}
2 changes: 1 addition & 1 deletion osu.Framework/osu.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="ppy.osuTK.NS20" Version="1.0.211" />
<PackageReference Include="StbiSharp" Version="1.1.0" />
<PackageReference Include="ppy.SDL2-CS" Version="1.0.741-alpha" />
<PackageReference Include="ppy.SDL3-CS" Version="2024.1015.0" />
<PackageReference Include="ppy.SDL3-CS" Version="2024.1022.0" />
<PackageReference Include="ppy.osu.Framework.SourceGeneration" Version="2023.720.0" />

<!-- DO NOT use ProjectReference for native packaging project.
Expand Down

0 comments on commit 04acf05

Please sign in to comment.