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 20 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
3 changes: 3 additions & 0 deletions osu.Framework/Audio/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Framework.Threading;
using System.Linq;
using System.Diagnostics;
using osu.Framework.Extensions.TypeExtensions;

namespace osu.Framework.Audio
{
Expand Down Expand Up @@ -371,5 +372,7 @@ private void checkAudioDeviceChanged()
{
}
}

public override string ToString() => $@"{GetType().ReadableName()} ({currentAudioDevice})";
}
}
8 changes: 8 additions & 0 deletions osu.Framework/Graphics/Colour/ColourInfo.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
3 changes: 3 additions & 0 deletions osu.Framework/Graphics/DrawInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Extensions.TypeExtensions;

namespace osu.Framework.Graphics
{
Expand Down Expand Up @@ -77,5 +78,7 @@ public bool Equals(DrawInfo other)
{
return Matrix.Equals(other.Matrix) && Colour.Equals(other.Colour) && Blending.Equals(other.Blending);
}

public override string ToString() => $@"{GetType().ReadableName().Replace(@"DrawInfo", string.Empty)} DrawInfo";
}
}
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/MarginPadding.cs
Original file line number Diff line number Diff line change
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
8 changes: 5 additions & 3 deletions osu.Framework/Graphics/Primitives/RectangleF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Globalization;
using System.Runtime.InteropServices;
using OpenTK;
using osu.Framework.MathUtils;

namespace osu.Framework.Graphics.Primitives
{
Expand Down Expand Up @@ -354,9 +355,10 @@ internal float DistanceSquared(Vector2 localSpacePos)
/// <returns>A string that contains the position, width, and height of this <see cref="T:System.Drawing.RectangleF"></see> structure¾for example, "{X=20, Y=20, Width=100, Height=50}".</returns>
/// <filterpriority>1</filterpriority>
/// <PermissionSet><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /></PermissionSet>
public override string ToString() => "{X=" + X.ToString(CultureInfo.CurrentCulture) + ",Y=" + Y.ToString(CultureInfo.CurrentCulture) +
",Width=" + Width.ToString(CultureInfo.CurrentCulture) + ",Height=" +
Height.ToString(CultureInfo.CurrentCulture) + "}";
public override string ToString() => $"X={Math.Round(X, 3).ToString(CultureInfo.CurrentCulture)}, "
+ $"Y={Math.Round(Y, 3).ToString(CultureInfo.CurrentCulture)}, "
+ $"Width={Math.Round(Width, 3).ToString(CultureInfo.CurrentCulture)}, "
+ $"Height={Math.Round(Height, 3).ToString(CultureInfo.CurrentCulture)}";

static RectangleF()
{
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/Shaders/Shader.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public void DrawQuad(Quad vertexQuad, ColourInfo colour, RectangleF? textureRect

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

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

public class TextureWhitePixel : Texture
Expand Down
125 changes: 115 additions & 10 deletions osu.Framework/Graphics/Visualisation/DrawVisualiser.cs
Original file line number Diff line number Diff line change
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;
using OpenTK;

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 readonly InfoOverlay overlay;
private ScheduledDelegate task;
Expand All @@ -26,20 +34,72 @@ 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
{
Drawable lastHighlight = highlighted?.Target;

var parent = Target?.Parent;
if (parent?.Parent != null)
Target = Target?.Parent;
}
Target = (Drawable)Target?.Parent;

// Rehighlight the last highlight
if (lastHighlight != null)
{
VisualisedDrawable visualised = findVisualised(lastHighlight, targetDrawable);
if (visualised != null)
setHighlight(visualised);
}
},
ToggleProperties = delegate
{
if (targetDrawable == null)
return;

propertyDisplay.ToggleVisibility();

if (propertyDisplay.State == Visibility.Visible)
setHighlight(targetDrawable);
},
},
new CursorContainer()
};

propertyDisplay.StateChanged += (display, visibility) =>
{
switch (visibility)
{
case Visibility.Hidden:
setHighlight(null);
break;
}
};
}

private VisualisedDrawable findVisualised(Drawable d, VisualisedDrawable root)
{
foreach (VisualisedDrawable child in root.Flow.InternalChildren)
{
if (child.Target == d)
return child;

VisualisedDrawable found = findVisualised(d, child);
if (found != null)
return found;
}

return null;
}

protected override bool BlockPassThroughMouse => false;
Expand Down Expand Up @@ -70,6 +130,9 @@ protected override void PopOut()

private void chooseTarget()
{
setHighlight(null);
propertyDisplay.State = Visibility.Hidden;

Target = null;
targetSearching = true;
}
Expand All @@ -78,6 +141,7 @@ 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 @@ -132,18 +196,23 @@ private void removeRootVisualisedDrawable()
private void createRootVisualisedDrawable()
{
removeRootVisualisedDrawable();
setHighlight(null);

if (target != null)
{
targetDrawable = createVisualisedDrawable(null, target as Drawable);
treeContainer.Add(targetDrawable);

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

// Set highlight and update
setHighlight(targetDrawable);
}
}

private IDrawable target;
private Drawable target;

public IDrawable Target
public Drawable Target
{
get { return target; }
set
Expand All @@ -159,6 +228,21 @@ private void runUpdate()

visualise(Target, targetDrawable);
}

This comment was marked as off-topic.

private void updatePropertyDisplay(Drawable 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 @@ -167,9 +251,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 @@ -186,6 +271,26 @@ private VisualisedDrawable createVisualisedDrawable(VisualisedDrawable parent, D

return vis;
}

This comment was marked as off-topic.

private void setHighlight(VisualisedDrawable newHighlight)
{
highlighted?.highlightBackground.FadeOut();

if (newHighlight == null)
{
updatePropertyDisplay(null);
highlighted = null;
return;
}

updatePropertyDisplay(newHighlight.Target);
highlighted = newHighlight;

if (propertyDisplay.State == Visibility.Visible)
{
newHighlight.highlightBackground.FadeIn();
newHighlight.Expand();
}
}

private void visualise(IDrawable d, VisualisedDrawable vis)
{
Expand Down Expand Up @@ -232,7 +337,7 @@ protected override bool OnClick(InputState state)
{
if (targetSearching)
{
Target = findTarget(state)?.Parent;
Target = (Drawable)findTarget(state)?.Parent;

if (Target != null)
{
Expand Down