-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from andy840119/should-not-masking-shader
Should not masking shader parts.
- Loading branch information
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
osu.Framework.Font.Tests/Extensions/RectangleFExtensionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using NUnit.Framework; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Extensions; | ||
using osu.Framework.Graphics.Primitives; | ||
|
||
namespace osu.Framework.Font.Tests.Extensions | ||
{ | ||
public class RectangleFExtensionsTest | ||
{ | ||
[TestCase(2, Anchor.Centre, 0, 5, 40, 20)] | ||
[TestCase(2, Anchor.TopLeft, 10, 10, 40, 20)] | ||
[TestCase(2, Anchor.TopRight, -10, 10, 40, 20)] | ||
[TestCase(2, Anchor.BottomLeft, 10, 0, 40, 20)] | ||
[TestCase(2, Anchor.BottomRight, -10, 0, 40, 20)] | ||
public void TestScale(float scale, Anchor origin, float x, float y, float width, float height) | ||
{ | ||
var rectangle = new RectangleF(10, 10, 20, 10); | ||
var target = rectangle.Scale(scale, origin); | ||
|
||
Assert.AreEqual(target.X, x); | ||
Assert.AreEqual(target.Y, y); | ||
Assert.AreEqual(target.Width, width); | ||
Assert.AreEqual(target.Height, height); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
osu.Framework.Font/Graphics/Extensions/RectangleFExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Extensions.EnumExtensions; | ||
using osu.Framework.Graphics.Primitives; | ||
using osuTK; | ||
|
||
namespace osu.Framework.Graphics.Extensions | ||
{ | ||
public static class RectangleFExtensions | ||
{ | ||
public static RectangleF Scale(this RectangleF source, float scale, Anchor origin = Anchor.Centre) | ||
=> source.Scale(new Vector2(scale), origin); | ||
|
||
public static RectangleF Scale(this RectangleF source, Vector2 scale, Anchor origin = Anchor.Centre) | ||
{ | ||
var newWidth = source.Width * scale.X; | ||
var newHeight = source.Height * scale.Y; | ||
|
||
var x = source.X - getXScale(origin) * (newWidth - source.Width); | ||
var y = source.Y - getYScale(origin) * (newHeight - source.Height); | ||
|
||
return new RectangleF(x, y, newWidth, newHeight); | ||
|
||
static float getXScale(Anchor origin) | ||
{ | ||
if (origin.HasFlagFast(Anchor.x0)) | ||
return 0; | ||
|
||
if (origin.HasFlagFast(Anchor.x1)) | ||
return 0.5f; | ||
|
||
if (origin.HasFlagFast(Anchor.x2)) | ||
return 1f; | ||
|
||
return 100; | ||
} | ||
|
||
static float getYScale(Anchor origin) | ||
{ | ||
if (origin.HasFlagFast(Anchor.y0)) | ||
return 0; | ||
|
||
if (origin.HasFlagFast(Anchor.y1)) | ||
return 0.5f; | ||
|
||
if (origin.HasFlagFast(Anchor.y2)) | ||
return 1f; | ||
|
||
return 100; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters