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

View File

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

View File

@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
private readonly Container borderMask;
private readonly Drawable background;
private readonly MarkerContainer markers;
private readonly HandleContainer handles;
private Color4 captureFinishedColour;
@ -65,7 +65,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
},
}
},
markers = new MarkerContainer
handles = new HandleContainer
{
RelativeSizeAxes = Axes.Both,
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.
background.Delay(50).FadeOut(200);
markers.FadeIn(200);
handles.FadeIn(200);
Selection.Value = new SelectionInfo
{

View File

@ -11,14 +11,14 @@ using OpenTK;
namespace osu.Game.Rulesets.Edit.Layers.Selection
{
/// <summary>
/// Represents the centre of a <see cref="MarkerContainer"/>.
/// Represents the origin of a <see cref="HandleContainer"/>.
/// </summary>
public class CentreMarker : CompositeDrawable
public class OriginHandle : CompositeDrawable
{
private const float marker_size = 10;
private const float line_width = 2;
public CentreMarker()
public OriginHandle()
{
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\ScoreModsContainer.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\Marker.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\MarkerContainer.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\Handle.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\HandleContainer.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\SelectionInfo.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\SelectionLayer.cs" />
<Compile Include="Screens\Edit\Components\BottomBarContainer.cs" />