Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property viewer to DrawVisualiser #780

Merged
merged 33 commits into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9811970
Better visualizer
Jun 3, 2017
a2d6ce0
Override ToStrings
Jun 3, 2017
92a0322
Bottom-right display
Jun 3, 2017
7c10866
Little fixes
Jun 3, 2017
d691fa8
Attach PropertyDisplay to highlight
Jun 3, 2017
2d6495f
Parent highlighting
Jun 3, 2017
e96128c
Truncate double
Jun 3, 2017
442cd0e
Appear right next to the tree
Jun 3, 2017
e02fba2
Suggestions
Jun 4, 2017
7165cf6
Unnecessary
Jun 4, 2017
57ca2fb
AlmostRounded for near integer rounding
Jun 5, 2017
e82ed0c
Fixes
Jun 5, 2017
e5cc325
Trim whitespace
Jun 5, 2017
2551db6
Better use of Math.Round
Jun 5, 2017
4d40b47
Just round
Jun 5, 2017
5c78b42
Semicolon
Jun 5, 2017
051fd0e
Add xml documentation
Jun 5, 2017
95f609c
Merge branch 'master' into better-viz
Jun 6, 2017
c6ef468
Merge branch 'master' into better-viz
Jun 7, 2017
372dc8d
Cleanups.
Jun 7, 2017
c5dd98a
CI cleanups.
Jun 7, 2017
8655843
Cleanups and fixes
Jun 13, 2017
c940bc2
Merge branch 'master' into better-viz
Jun 13, 2017
dab603a
Fix EdgeEffect ToString when None
Jun 13, 2017
634b888
Code styling improvements
Jun 14, 2017
5ba107b
Move PropertyItem into PropertyDisplay
Jun 14, 2017
26a1bc1
Use ? expression
Jun 14, 2017
e7768ab
Merge branch 'master' into better-viz
peppy Jun 16, 2017
afb61e5
Combine PropertyDisplay and DrawVisualiser
peppy Jun 16, 2017
29417a4
Standardise padding and text sizes
peppy Jun 16, 2017
e2afd04
Improve right click behaviour
peppy Jun 16, 2017
2e8e7e3
Styling improvements
peppy Jun 16, 2017
8f632b9
Don't hide property viewer when double-clicking a new target
peppy Jun 16, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions osu.Framework/Audio/AudioManager.cs
Expand Up @@ -371,5 +371,7 @@ private void checkAudioDeviceChanged()
{
}
}

public override string ToString() => $@"AudioManager ({currentAudioDevice})";

This comment was marked as off-topic.

}
}
8 changes: 8 additions & 0 deletions osu.Framework/Graphics/Colour/ColourInfo.cs
Expand Up @@ -197,6 +197,14 @@ public float MaxAlpha
}
}

public override string ToString()
{
if (HasSingleColour)
return $@"{TopLeft} (Single)";

else return $@"{TopLeft}, {TopRight}, {BottomLeft}, {BottomRight}";
}

public static implicit operator ColourInfo(SRGBColour colour) => SingleColour(colour);
public static implicit operator ColourInfo(Color4 colour) => (SRGBColour)colour;
}
Expand Down
1 change: 1 addition & 0 deletions osu.Framework/Graphics/Colour/SRGBColour.cs
Expand Up @@ -45,5 +45,6 @@ public struct SRGBColour : IEquatable<SRGBColour>
public void MultiplyAlpha(float alpha) => Linear.A *= alpha;

public bool Equals(SRGBColour other) => Linear.Equals(other.Linear);
public override string ToString() => Linear.ToString();
}
}
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/Containers/ContainerDrawNode.cs
Expand Up @@ -67,6 +67,8 @@ public struct EdgeEffect : IEquatable<EdgeEffect>
Type == other.Type &&
Roundness == other.Roundness &&
Radius == other.Radius;

public override string ToString() => $@"{Radius} {Type}EdgeEffect";
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/DrawInfo.cs
Expand Up @@ -77,5 +77,7 @@ public bool Equals(DrawInfo other)
{
return Matrix.Equals(other.Matrix) && Colour.Equals(other.Colour) && Blending.Equals(other.Blending);
}

public override string ToString() => $@"{GetType().Name.Replace(@"DrawInfo", string.Empty)} DrawInfo";
}
}
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/MarginPadding.cs
Expand Up @@ -43,6 +43,8 @@ public bool Equals(MarginPadding other)
return Top == other.Top && Left == other.Left && Bottom == other.Bottom && Right == other.Right;
}

public override string ToString() => $@"({Top}, {Left}, {Bottom}, {Right})";

public static MarginPadding operator -(MarginPadding mp)
{
return new MarginPadding
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/Shaders/Shader.cs
Expand Up @@ -168,6 +168,8 @@ public void Unbind()
IsBound = false;
}

public override string ToString() => $@"{name} Shader (Compiled: {programID != -1})";

/// <summary>
/// Returns a uniform from the shader.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/Textures/Texture.cs
Expand Up @@ -202,6 +202,8 @@ public void DrawQuad(Quad vertexQuad, ColourInfo colour, RectangleF? textureRect

TextureGL.DrawQuad(vertexQuad, TextureBounds(textureRect), colour, vertexAction, inflationPercentage);
}

public override string ToString() => $@"{AssetName} ({Width}, {Height})";
}

public class TextureWhitePixel : Texture
Expand Down
72 changes: 66 additions & 6 deletions osu.Framework/Graphics/Visualisation/DrawVisualiser.cs
Expand Up @@ -8,12 +8,20 @@
using osu.Framework.Input;
using osu.Framework.Threading;
using osu.Framework.Lists;
using System;
using System.Reflection;
using System.Collections.Generic;
using OpenTK.Graphics;

namespace osu.Framework.Graphics.Visualisation
{
public class DrawVisualiser : OverlayContainer
{
private readonly TreeContainer treeContainer;
internal readonly TreeContainer treeContainer;
internal readonly PropertyDisplay propertyDisplay;

internal VisualisedDrawable highlighted;
private Box highlightMarker;

private readonly InfoOverlay overlay;
private ScheduledDelegate task;
Expand All @@ -26,17 +34,26 @@ public DrawVisualiser()
RelativeSizeAxes = Axes.Both;
Children = new Drawable[]
{
overlay = new InfoOverlay(),
overlay = new InfoOverlay()
{
Depth = float.MaxValue
},
propertyDisplay = new PropertyDisplay
{
Depth = float.MinValue

This comment was marked as off-topic.

},
treeContainer = new TreeContainer
{
Depth = float.MinValue,
Depth = 0f, // Below property display
ChooseTarget = chooseTarget,
GoUpOneParent = delegate
{
var parent = Target?.Parent;
if (parent?.Parent != null)
Target = Target?.Parent;
}
},
ToggleProperties = propertyDisplay.ToggleVisibility,

},
new CursorContainer()
};
Expand Down Expand Up @@ -72,12 +89,15 @@ private void chooseTarget()
{
Target = null;
targetSearching = true;

propertyDisplay.State = Visibility.Hidden;
}

private Drawable findTargetIn(Drawable d, InputState state)
{
if (d is DrawVisualiser) return null;
if (d is CursorContainer) return null;
if (d is PropertyDisplay) return null;

if (!d.IsPresent) return null;

Expand Down Expand Up @@ -131,7 +151,12 @@ private void createRootVisualisedDrawable()
treeContainer.Add(targetDrawable);

runUpdate(); // run an initial update to immediately show the selected hierarchy.

// Update property viewer
setHighlight(targetDrawable);
}

propertyDisplay.State = Visibility.Visible;
}

private IDrawable target;
Expand All @@ -152,6 +177,21 @@ private void runUpdate()

visualise(Target, targetDrawable);
}

This comment was marked as off-topic.

private void updatePropertyDisplay(IDrawable d)
{
propertyDisplay.Clear(true);

if (d == null)
return;

Type type = d.GetType();

propertyDisplay.Add(
((IEnumerable<MemberInfo>)type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) // Get all properties
.Concat(type.GetFields(BindingFlags.Instance | BindingFlags.Public)) // And all fields

This comment was marked as off-topic.

.OrderBy(member => member.Name)
.Select(member => new PropertyItem(member, d)));
}

private void updateHoveredDrawable()
{
Expand All @@ -160,9 +200,10 @@ private void updateHoveredDrawable()

private VisualisedDrawable createVisualisedDrawable(VisualisedDrawable parent, Drawable target)
{
var vis = new VisualisedDrawable(parent, target, treeContainer)
var vis = new VisualisedDrawable(parent, target, this)
{
RequestTarget = delegate { Target = target; }
RequestTarget = delegate { Target = target; },
HighlightTarget = setHighlight
};

vis.HoverGained = delegate
Expand All @@ -179,6 +220,25 @@ private VisualisedDrawable createVisualisedDrawable(VisualisedDrawable parent, D

return vis;
}

This comment was marked as off-topic.

private void setHighlight(VisualisedDrawable newHighlight)
{
// Remove marker from previous highlight
if (highlightMarker != null && highlightMarker.Parent != null)
((IContainerCollection<Drawable>)highlightMarker.Parent).Remove(highlightMarker);

highlightMarker = new Box()
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.1f,
Colour = Color4.Khaki
};
newHighlight.Add(highlightMarker);

newHighlight.Expand();

highlighted = newHighlight;
updatePropertyDisplay(newHighlight.Target);
}

private void visualise(IDrawable d, VisualisedDrawable vis)
{
Expand Down
163 changes: 163 additions & 0 deletions osu.Framework/Graphics/Visualisation/PropertyDisplay.cs
@@ -0,0 +1,163 @@
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace osu.Framework.Graphics.Visualisation
{
internal class PropertyDisplay : OverlayContainer
{
private readonly FillFlowContainer flow;

private const float width = 600;
private const float height = 400;

private readonly Box titleBar;

protected override Container<Drawable> Content => flow;

public PropertyDisplay()
{
Masking = true;
CornerRadius = 5;
Anchor = Origin = Anchor.BottomRight;
Position = new Vector2(-20);
Size = new Vector2(width, height);
AddInternal(new Drawable[]
{
new Box
{
Colour = new Color4(30, 30, 30, 240),
RelativeSizeAxes = Axes.Both,
Depth = 0
},
titleBar = new Box //title decoration
{
Colour = Color4.DarkBlue,
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, 20),
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 20 },
Children = new[]
{
new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarOverlapsContent = false,
Children = new[]
{
flow = new FillFlowContainer()
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical
}
},
}
}
},
});
}

protected override bool OnDragStart(InputState state) => titleBar.Contains(state.Mouse.NativeState.Position);

protected override bool OnDrag(InputState state)
{
Position += state.Mouse.Delta;
return base.OnDrag(state);
}

protected override void PopIn()
{
FadeTo(0.7f, 100);
}
protected override void PopOut()
{
FadeOut(100);
}
}

internal class PropertyItem : ClickableContainer
{
private readonly SpriteText nameText;
private readonly SpriteText valueText;

private readonly Box box;

private readonly Func<string> getValue; // Use delegate for performance

public PropertyItem(MemberInfo info, IDrawable d)
{
try
{
switch (info.MemberType)
{
case MemberTypes.Property:
getValue = ((PropertyInfo)info).GetValue(d).ToString;
break;

case MemberTypes.Field:
getValue = ((FieldInfo)info).GetValue(d).ToString;
break;
}
}
catch
{
getValue = () => @"<Cannot evaluate>";
}

RelativeSizeAxes = Axes.X;
Height = 20f;
AddInternal(new Drawable[]
{
box = new Box()
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
Alpha = 0f
},
nameText = new SpriteText()
{
Text = info.Name,
TextSize = Height
},
valueText = new SpriteText()
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
TextSize = Height
}
});
}

protected override void Update()
{
base.Update();

// Update value
valueText.Text = getValue();
}

protected override bool OnHover(InputState state)
{
box.FadeTo(0.2f, 100);

return true;
}
protected override void OnHoverLost(InputState state)
{
box.FadeOut(100);
}
}
}