Marker* -> Handle

This commit is contained in:
smoogipoo 2017-12-18 19:21:26 +09:00
parent 3999940538
commit 09c51df2bd
5 changed files with 130 additions and 130 deletions

View File

@ -1,105 +1,105 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Graphics; using osu.Game.Graphics;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
namespace osu.Game.Rulesets.Edit.Layers.Selection namespace osu.Game.Rulesets.Edit.Layers.Selection
{ {
/// <summary> /// <summary>
/// Represents a marker visible on the border of a <see cref="MarkerContainer"/> which exposes /// Represents a marker visible on the border of a <see cref="HandleContainer"/> which exposes
/// properties that are used to resize a <see cref="HitObjectSelectionBox"/>. /// properties that are used to resize a <see cref="HitObjectSelectionBox"/>.
/// </summary> /// </summary>
public class Marker : CompositeDrawable public class Handle : CompositeDrawable
{ {
private const float marker_size = 10; private const float marker_size = 10;
/// <summary> /// <summary>
/// Invoked when this <see cref="Marker"/> requires the current drag rectangle. /// Invoked when this <see cref="Handle"/> requires the current drag rectangle.
/// </summary> /// </summary>
public Func<RectangleF> GetDragRectangle; public Func<RectangleF> GetDragRectangle;
/// <summary> /// <summary>
/// Invoked when this <see cref="Marker"/> wants to update the drag rectangle. /// Invoked when this <see cref="Handle"/> wants to update the drag rectangle.
/// </summary> /// </summary>
public Action<RectangleF> UpdateDragRectangle; public Action<RectangleF> UpdateDragRectangle;
/// <summary> /// <summary>
/// Invoked when this <see cref="Marker"/> has finished updates to the drag rectangle. /// Invoked when this <see cref="Handle"/> has finished updates to the drag rectangle.
/// </summary> /// </summary>
public Action FinishCapture; public Action FinishCapture;
private Color4 normalColour; private Color4 normalColour;
private Color4 hoverColour; private Color4 hoverColour;
public Marker() public Handle()
{ {
Size = new Vector2(marker_size); Size = new Vector2(marker_size);
InternalChild = new CircularContainer InternalChild = new CircularContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
Child = new Box { RelativeSizeAxes = Axes.Both } Child = new Box { RelativeSizeAxes = Axes.Both }
}; };
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
Colour = normalColour = colours.Yellow; Colour = normalColour = colours.Yellow;
hoverColour = colours.YellowDarker; hoverColour = colours.YellowDarker;
} }
protected override bool OnDragStart(InputState state) => true; protected override bool OnDragStart(InputState state) => true;
protected override bool OnDrag(InputState state) protected override bool OnDrag(InputState state)
{ {
var currentRectangle = GetDragRectangle(); var currentRectangle = GetDragRectangle();
float left = currentRectangle.Left; float left = currentRectangle.Left;
float right = currentRectangle.Right; float right = currentRectangle.Right;
float top = currentRectangle.Top; float top = currentRectangle.Top;
float bottom = currentRectangle.Bottom; float bottom = currentRectangle.Bottom;
// Apply modifications to the capture rectangle // Apply modifications to the capture rectangle
if ((Anchor & Anchor.y0) > 0) if ((Anchor & Anchor.y0) > 0)
top += state.Mouse.Delta.Y; top += state.Mouse.Delta.Y;
else if ((Anchor & Anchor.y2) > 0) else if ((Anchor & Anchor.y2) > 0)
bottom += state.Mouse.Delta.Y; bottom += state.Mouse.Delta.Y;
if ((Anchor & Anchor.x0) > 0) if ((Anchor & Anchor.x0) > 0)
left += state.Mouse.Delta.X; left += state.Mouse.Delta.X;
else if ((Anchor & Anchor.x2) > 0) else if ((Anchor & Anchor.x2) > 0)
right += state.Mouse.Delta.X; right += state.Mouse.Delta.X;
UpdateDragRectangle(RectangleF.FromLTRB(left, top, right, bottom)); UpdateDragRectangle(RectangleF.FromLTRB(left, top, right, bottom));
return true; return true;
} }
protected override bool OnDragEnd(InputState state) protected override bool OnDragEnd(InputState state)
{ {
FinishCapture(); FinishCapture();
return true; return true;
} }
protected override bool OnHover(InputState state) protected override bool OnHover(InputState state)
{ {
this.FadeColour(hoverColour, 100); this.FadeColour(hoverColour, 100);
return true; return true;
} }
protected override void OnHoverLost(InputState state) protected override void OnHoverLost(InputState state)
{ {
this.FadeColour(normalColour, 100); this.FadeColour(normalColour, 100);
} }
} }
} }

View File

@ -11,77 +11,77 @@ using osu.Framework.Graphics.Primitives;
namespace osu.Game.Rulesets.Edit.Layers.Selection namespace osu.Game.Rulesets.Edit.Layers.Selection
{ {
/// <summary> /// <summary>
/// A <see cref="CompositeDrawable"/> that has <see cref="Marker"/>s around its border. /// A <see cref="CompositeDrawable"/> that has <see cref="Handle"/>s around its border.
/// </summary> /// </summary>
public class MarkerContainer : CompositeDrawable public class HandleContainer : CompositeDrawable
{ {
/// <summary> /// <summary>
/// Invoked when a <see cref="Marker"/> requires the current drag rectangle. /// Invoked when a <see cref="Handle"/> requires the current drag rectangle.
/// </summary> /// </summary>
public Func<RectangleF> GetDragRectangle; public Func<RectangleF> GetDragRectangle;
/// <summary> /// <summary>
/// Invoked when a <see cref="Marker"/> wants to update the drag rectangle. /// Invoked when a <see cref="Handle"/> wants to update the drag rectangle.
/// </summary> /// </summary>
public Action<RectangleF> UpdateDragRectangle; public Action<RectangleF> UpdateDragRectangle;
/// <summary> /// <summary>
/// Invoked when a <see cref="Marker"/> has finished updates to the drag rectangle. /// Invoked when a <see cref="Handle"/> has finished updates to the drag rectangle.
/// </summary> /// </summary>
public Action FinishCapture; public Action FinishCapture;
public MarkerContainer() public HandleContainer()
{ {
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
new Marker new Handle
{ {
Anchor = Anchor.TopLeft, Anchor = Anchor.TopLeft,
Origin = Anchor.Centre Origin = Anchor.Centre
}, },
new Marker new Handle
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.Centre Origin = Anchor.Centre
}, },
new Marker new Handle
{ {
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.Centre Origin = Anchor.Centre
}, },
new Marker new Handle
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre Origin = Anchor.Centre
}, },
new Marker new Handle
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.Centre Origin = Anchor.Centre
}, },
new Marker new Handle
{ {
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.Centre Origin = Anchor.Centre
}, },
new Marker new Handle
{ {
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Origin = Anchor.Centre Origin = Anchor.Centre
}, },
new Marker new Handle
{ {
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Origin = Anchor.Centre Origin = Anchor.Centre
}, },
new CentreMarker new OriginHandle
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre Origin = Anchor.Centre
} }
}; };
InternalChildren.OfType<Marker>().ForEach(m => InternalChildren.OfType<Handle>().ForEach(m =>
{ {
m.GetDragRectangle = () => GetDragRectangle(); m.GetDragRectangle = () => GetDragRectangle();
m.UpdateDragRectangle = r => UpdateDragRectangle(r); m.UpdateDragRectangle = r => UpdateDragRectangle(r);

View File

@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
private readonly Container borderMask; private readonly Container borderMask;
private readonly Drawable background; private readonly Drawable background;
private readonly MarkerContainer markers; private readonly HandleContainer handles;
private Color4 captureFinishedColour; private Color4 captureFinishedColour;
@ -65,7 +65,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
}, },
} }
}, },
markers = new MarkerContainer handles = new HandleContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Alpha = 0, Alpha = 0,
@ -159,7 +159,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
// Transform into markers to let the user modify the drag selection further. // Transform into markers to let the user modify the drag selection further.
background.Delay(50).FadeOut(200); background.Delay(50).FadeOut(200);
markers.FadeIn(200); handles.FadeIn(200);
Selection.Value = new SelectionInfo Selection.Value = new SelectionInfo
{ {

View File

@ -11,14 +11,14 @@ using OpenTK;
namespace osu.Game.Rulesets.Edit.Layers.Selection namespace osu.Game.Rulesets.Edit.Layers.Selection
{ {
/// <summary> /// <summary>
/// Represents the centre of a <see cref="MarkerContainer"/>. /// Represents the origin of a <see cref="HandleContainer"/>.
/// </summary> /// </summary>
public class CentreMarker : CompositeDrawable public class OriginHandle : CompositeDrawable
{ {
private const float marker_size = 10; private const float marker_size = 10;
private const float line_width = 2; private const float line_width = 2;
public CentreMarker() public OriginHandle()
{ {
Size = new Vector2(marker_size); Size = new Vector2(marker_size);

View File

@ -307,10 +307,10 @@
<Compile Include="Overlays\Profile\Sections\Ranks\DrawableTotalScore.cs" /> <Compile Include="Overlays\Profile\Sections\Ranks\DrawableTotalScore.cs" />
<Compile Include="Overlays\Profile\Sections\Ranks\ScoreModsContainer.cs" /> <Compile Include="Overlays\Profile\Sections\Ranks\ScoreModsContainer.cs" />
<Compile Include="Overlays\Settings\SettingsButton.cs" /> <Compile Include="Overlays\Settings\SettingsButton.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\CentreMarker.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\OriginHandle.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\HitObjectSelectionBox.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\HitObjectSelectionBox.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\Marker.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\Handle.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\MarkerContainer.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\HandleContainer.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\SelectionInfo.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\SelectionInfo.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\SelectionLayer.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\SelectionLayer.cs" />
<Compile Include="Screens\Edit\Components\BottomBarContainer.cs" /> <Compile Include="Screens\Edit\Components\BottomBarContainer.cs" />