mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 14:25:05 +08:00
Add new icons and tooltips
This commit is contained in:
parent
78c5d57074
commit
4e6a505a99
@ -5,6 +5,7 @@ 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.Cursor;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
@ -68,6 +69,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FillFlowContainer buttons;
|
||||||
|
|
||||||
public const float BORDER_RADIUS = 3;
|
public const float BORDER_RADIUS = 3;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
@ -105,72 +108,114 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
buttons = new FillFlowContainer
|
||||||
|
{
|
||||||
|
Y = 20,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Anchor = Anchor.BottomCentre,
|
||||||
|
Origin = Anchor.Centre
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (CanRotate)
|
if (CanScaleX) addXScaleComponents();
|
||||||
|
if (CanScaleX && CanScaleY) addFullScaleComponents();
|
||||||
|
if (CanScaleY) addYScaleComponents();
|
||||||
|
if (CanRotate) addRotationComponents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addRotationComponents()
|
||||||
|
{
|
||||||
|
const float separation = 40;
|
||||||
|
|
||||||
|
buttons.Insert(-1, new DragHandleButton(FontAwesome.Solid.Undo, "Rotate 90 degrees counter-clockwise")
|
||||||
{
|
{
|
||||||
const float separation = 40;
|
OperationStarted = operationStarted,
|
||||||
|
OperationEnded = operationEnded,
|
||||||
|
Action = () => OnRotation?.Invoke(-90)
|
||||||
|
});
|
||||||
|
|
||||||
AddRangeInternal(new Drawable[]
|
buttons.Add(new DragHandleButton(FontAwesome.Solid.Redo, "Rotate 90 degrees clockwise")
|
||||||
{
|
|
||||||
new Box
|
|
||||||
{
|
|
||||||
Colour = colours.YellowLight,
|
|
||||||
Blending = BlendingParameters.Additive,
|
|
||||||
Alpha = 0.3f,
|
|
||||||
Size = new Vector2(BORDER_RADIUS, separation),
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.BottomCentre,
|
|
||||||
},
|
|
||||||
new RotationDragHandle
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Y = -separation,
|
|
||||||
HandleDrag = e => OnRotation?.Invoke(e),
|
|
||||||
OperationStarted = operationStarted,
|
|
||||||
OperationEnded = operationEnded
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CanScaleY)
|
|
||||||
{
|
{
|
||||||
AddRangeInternal(new[]
|
OperationStarted = operationStarted,
|
||||||
{
|
OperationEnded = operationEnded,
|
||||||
createDragHandle(Anchor.TopCentre),
|
Action = () => OnRotation?.Invoke(90)
|
||||||
createDragHandle(Anchor.BottomCentre),
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CanScaleX)
|
AddRangeInternal(new Drawable[]
|
||||||
{
|
{
|
||||||
AddRangeInternal(new[]
|
new Box
|
||||||
{
|
{
|
||||||
createDragHandle(Anchor.CentreLeft),
|
Depth = float.MaxValue,
|
||||||
createDragHandle(Anchor.CentreRight),
|
Colour = colours.YellowLight,
|
||||||
});
|
Blending = BlendingParameters.Additive,
|
||||||
}
|
Alpha = 0.3f,
|
||||||
|
Size = new Vector2(BORDER_RADIUS, separation),
|
||||||
if (CanScaleX && CanScaleY)
|
Anchor = Anchor.TopCentre,
|
||||||
{
|
Origin = Anchor.BottomCentre,
|
||||||
AddRangeInternal(new[]
|
},
|
||||||
|
new DragHandleButton(FontAwesome.Solid.Redo, "Free rotate")
|
||||||
{
|
{
|
||||||
createDragHandle(Anchor.TopLeft),
|
Anchor = Anchor.TopCentre,
|
||||||
createDragHandle(Anchor.TopRight),
|
Y = -separation,
|
||||||
createDragHandle(Anchor.BottomLeft),
|
HandleDrag = e => OnRotation?.Invoke(e.Delta.X),
|
||||||
createDragHandle(Anchor.BottomRight),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ScaleDragHandle createDragHandle(Anchor anchor) =>
|
|
||||||
new ScaleDragHandle(anchor)
|
|
||||||
{
|
|
||||||
HandleDrag = e => OnScale?.Invoke(e, anchor),
|
|
||||||
OperationStarted = operationStarted,
|
OperationStarted = operationStarted,
|
||||||
OperationEnded = operationEnded
|
OperationEnded = operationEnded
|
||||||
};
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addYScaleComponents()
|
||||||
|
{
|
||||||
|
buttons.Add(new DragHandleButton(FontAwesome.Solid.ArrowsAltV, "Flip vertically")
|
||||||
|
{
|
||||||
|
OperationStarted = operationStarted,
|
||||||
|
OperationEnded = operationEnded,
|
||||||
|
Action = () => OnFlip?.Invoke(Direction.Vertical)
|
||||||
|
});
|
||||||
|
|
||||||
|
AddRangeInternal(new[]
|
||||||
|
{
|
||||||
|
createDragHandle(Anchor.TopCentre),
|
||||||
|
createDragHandle(Anchor.BottomCentre),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addFullScaleComponents()
|
||||||
|
{
|
||||||
|
AddRangeInternal(new[]
|
||||||
|
{
|
||||||
|
createDragHandle(Anchor.TopLeft),
|
||||||
|
createDragHandle(Anchor.TopRight),
|
||||||
|
createDragHandle(Anchor.BottomLeft),
|
||||||
|
createDragHandle(Anchor.BottomRight),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addXScaleComponents()
|
||||||
|
{
|
||||||
|
buttons.Add(new DragHandleButton(FontAwesome.Solid.ArrowsAltH, "Flip horizontally")
|
||||||
|
{
|
||||||
|
OperationStarted = operationStarted,
|
||||||
|
OperationEnded = operationEnded,
|
||||||
|
Action = () => OnFlip?.Invoke(Direction.Horizontal)
|
||||||
|
});
|
||||||
|
|
||||||
|
AddRangeInternal(new[]
|
||||||
|
{
|
||||||
|
createDragHandle(Anchor.CentreLeft),
|
||||||
|
createDragHandle(Anchor.CentreRight),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScaleDragHandle createDragHandle(Anchor anchor) =>
|
||||||
|
new ScaleDragHandle(anchor)
|
||||||
|
{
|
||||||
|
HandleDrag = e => OnScale?.Invoke(e.Delta, anchor),
|
||||||
|
OperationStarted = operationStarted,
|
||||||
|
OperationEnded = operationEnded
|
||||||
|
};
|
||||||
|
|
||||||
private int activeOperations;
|
private int activeOperations;
|
||||||
|
|
||||||
private void operationEnded()
|
private void operationEnded()
|
||||||
@ -193,30 +238,53 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RotationDragHandle : DragHandle
|
private sealed class DragHandleButton : DragHandle, IHasTooltip
|
||||||
{
|
{
|
||||||
private SpriteIcon icon;
|
private SpriteIcon icon;
|
||||||
|
|
||||||
|
private readonly IconUsage iconUsage;
|
||||||
|
|
||||||
|
public Action Action;
|
||||||
|
|
||||||
|
public DragHandleButton(IconUsage iconUsage, string tooltip)
|
||||||
|
{
|
||||||
|
this.iconUsage = iconUsage;
|
||||||
|
|
||||||
|
TooltipText = tooltip;
|
||||||
|
|
||||||
|
Anchor = Anchor.Centre;
|
||||||
|
Origin = Anchor.Centre;
|
||||||
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
Size *= 2;
|
Size *= 2;
|
||||||
|
|
||||||
AddInternal(icon = new SpriteIcon
|
AddInternal(icon = new SpriteIcon
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Size = new Vector2(0.5f),
|
Size = new Vector2(0.5f),
|
||||||
Icon = FontAwesome.Solid.Redo,
|
Icon = iconUsage,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnClick(ClickEvent e)
|
||||||
|
{
|
||||||
|
OperationStarted?.Invoke();
|
||||||
|
Action?.Invoke();
|
||||||
|
OperationEnded?.Invoke();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void UpdateHoverState()
|
protected override void UpdateHoverState()
|
||||||
{
|
{
|
||||||
base.UpdateHoverState();
|
base.UpdateHoverState();
|
||||||
icon.Colour = !HandlingMouse && IsHovered ? Color4.White : Color4.Black;
|
icon.Colour = !HandlingMouse && IsHovered ? Color4.White : Color4.Black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string TooltipText { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DragHandle : Container
|
private class DragHandle : Container
|
||||||
|
Loading…
Reference in New Issue
Block a user