mirror of
https://github.com/ppy/osu
synced 2025-01-21 13:23:13 +00:00
put Bar into its own file and let it only add a background if BackgroundColour is changed
This commit is contained in:
parent
e59c0a770f
commit
eb4b3772e9
134
osu.Game/Graphics/UserInterface/Bar.cs
Normal file
134
osu.Game/Graphics/UserInterface/Bar.cs
Normal file
@ -0,0 +1,134 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class Bar : Container
|
||||
{
|
||||
private Box background;
|
||||
private readonly Box bar;
|
||||
|
||||
private const int resize_duration = 250;
|
||||
|
||||
private const EasingTypes easing = EasingTypes.InOutCubic;
|
||||
|
||||
private float length;
|
||||
public float Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return length;
|
||||
}
|
||||
set
|
||||
{
|
||||
length = MathHelper.Clamp(value, 0, 1);
|
||||
updateBarLength();
|
||||
}
|
||||
}
|
||||
|
||||
public SRGBColour BackgroundColour
|
||||
{
|
||||
get
|
||||
{
|
||||
return background?.Colour ?? default(SRGBColour);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (background == null)
|
||||
Add(background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Depth = 1,
|
||||
});
|
||||
background.Colour = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SRGBColour BarColour
|
||||
{
|
||||
get
|
||||
{
|
||||
return bar.Colour;
|
||||
}
|
||||
set
|
||||
{
|
||||
bar.Colour = value;
|
||||
}
|
||||
}
|
||||
|
||||
private BarDirection direction = BarDirection.LeftToRight;
|
||||
public BarDirection Direction
|
||||
{
|
||||
get
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
set
|
||||
{
|
||||
direction = value;
|
||||
updateBarLength();
|
||||
}
|
||||
}
|
||||
|
||||
public Bar()
|
||||
{
|
||||
Children = new[]
|
||||
{
|
||||
bar = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void updateBarLength()
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case BarDirection.LeftToRight:
|
||||
case BarDirection.RightToLeft:
|
||||
bar.ResizeTo(new Vector2(length, 1), resize_duration, easing);
|
||||
break;
|
||||
|
||||
case BarDirection.TopToBottom:
|
||||
case BarDirection.BottomToTop:
|
||||
bar.ResizeTo(new Vector2(1, length), resize_duration, easing);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case BarDirection.LeftToRight:
|
||||
case BarDirection.TopToBottom:
|
||||
bar.Anchor = Anchor.TopLeft;
|
||||
bar.Origin = Anchor.TopLeft;
|
||||
break;
|
||||
|
||||
case BarDirection.RightToLeft:
|
||||
case BarDirection.BottomToTop:
|
||||
bar.Anchor = Anchor.BottomRight;
|
||||
bar.Origin = Anchor.BottomRight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum BarDirection
|
||||
{
|
||||
LeftToRight = 1 << 0,
|
||||
RightToLeft = 1 << 1,
|
||||
TopToBottom = 1 << 2,
|
||||
BottomToTop = 1 << 3,
|
||||
|
||||
Vertical = TopToBottom | BottomToTop,
|
||||
Horizontal = LeftToRight | RightToLeft,
|
||||
}
|
||||
}
|
@ -4,10 +4,7 @@
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@ -53,129 +50,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / values.Count) : new Vector2(1.0f / values.Count, 1),
|
||||
Length = values[i] / values.Max(),
|
||||
Direction = Direction,
|
||||
BackgroundColour = new Color4(0, 0, 0, 0),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Bar : Container
|
||||
{
|
||||
private readonly Box background;
|
||||
private readonly Box bar;
|
||||
|
||||
private const int resize_duration = 250;
|
||||
|
||||
private const EasingTypes easing = EasingTypes.InOutCubic;
|
||||
|
||||
private float length;
|
||||
public float Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return length;
|
||||
}
|
||||
set
|
||||
{
|
||||
length = MathHelper.Clamp(value, 0, 1);
|
||||
updateBarLength();
|
||||
}
|
||||
}
|
||||
|
||||
public SRGBColour BackgroundColour
|
||||
{
|
||||
get
|
||||
{
|
||||
return background.Colour;
|
||||
}
|
||||
set
|
||||
{
|
||||
background.Colour = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SRGBColour BarColour
|
||||
{
|
||||
get
|
||||
{
|
||||
return bar.Colour;
|
||||
}
|
||||
set
|
||||
{
|
||||
bar.Colour = value;
|
||||
}
|
||||
}
|
||||
|
||||
private BarDirection direction = BarDirection.LeftToRight;
|
||||
public BarDirection Direction
|
||||
{
|
||||
get
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
set
|
||||
{
|
||||
direction = value;
|
||||
updateBarLength();
|
||||
}
|
||||
}
|
||||
|
||||
public Bar()
|
||||
{
|
||||
Children = new[]
|
||||
{
|
||||
background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
bar = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void updateBarLength()
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case BarDirection.LeftToRight:
|
||||
case BarDirection.RightToLeft:
|
||||
bar.ResizeTo(new Vector2(length, 1), resize_duration, easing);
|
||||
break;
|
||||
|
||||
case BarDirection.TopToBottom:
|
||||
case BarDirection.BottomToTop:
|
||||
bar.ResizeTo(new Vector2(1, length), resize_duration, easing);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case BarDirection.LeftToRight:
|
||||
case BarDirection.TopToBottom:
|
||||
bar.Anchor = Anchor.TopLeft;
|
||||
bar.Origin = Anchor.TopLeft;
|
||||
break;
|
||||
|
||||
case BarDirection.RightToLeft:
|
||||
case BarDirection.BottomToTop:
|
||||
bar.Anchor = Anchor.BottomRight;
|
||||
bar.Origin = Anchor.BottomRight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum BarDirection
|
||||
{
|
||||
LeftToRight = 1 << 0,
|
||||
RightToLeft = 1 << 1,
|
||||
TopToBottom = 1 << 2,
|
||||
BottomToTop = 1 << 3,
|
||||
|
||||
Vertical = TopToBottom | BottomToTop,
|
||||
Horizontal = LeftToRight | RightToLeft,
|
||||
}
|
||||
}
|
@ -56,7 +56,6 @@ namespace osu.Game.Screens.Select
|
||||
case BeatmapDetailTab.Details:
|
||||
Details.Show();
|
||||
Leaderboard.Hide();
|
||||
updateDetails();
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -66,6 +65,7 @@ namespace osu.Game.Screens.Select
|
||||
break;
|
||||
}
|
||||
currentTab = tab;
|
||||
updateDetails();
|
||||
},
|
||||
},
|
||||
content = new Container
|
||||
|
@ -87,6 +87,7 @@
|
||||
<Compile Include="Graphics\Sprites\OsuSpriteText.cs" />
|
||||
<Compile Include="Graphics\Transforms\TransformAccent.cs" />
|
||||
<Compile Include="Graphics\UserInterface\BackButton.cs" />
|
||||
<Compile Include="Graphics\UserInterface\Bar.cs" />
|
||||
<Compile Include="Graphics\UserInterface\FocusedTextBox.cs" />
|
||||
<Compile Include="Graphics\UserInterface\Nub.cs" />
|
||||
<Compile Include="Graphics\UserInterface\OsuMenu.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user