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 1 commit
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
78 changes: 60 additions & 18 deletions osu.Framework/Graphics/Visualisation/DrawVisualiser.cs
Expand Up @@ -22,7 +22,6 @@ public class DrawVisualiser : OverlayContainer
internal readonly PropertyDisplay propertyDisplay;

internal VisualisedDrawable highlighted;
private Box highlightMarker;

private readonly InfoOverlay overlay;
private ScheduledDelegate task;
Expand All @@ -49,14 +48,55 @@ public DrawVisualiser()
ChooseTarget = chooseTarget,
GoUpOneParent = delegate
{
Drawable lastHighlight = highlighted?.Target;

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

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

if (propertyDisplay.State == Visibility.Visible)
setHighlight(targetDrawable);
},
ToggleProperties = propertyDisplay.ToggleVisibility,
},
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 @@ -87,10 +127,10 @@ protected override void PopOut()

private void chooseTarget()
{
setHighlight(null);

Target = null;
targetSearching = true;

propertyDisplay.State = Visibility.Hidden;
}

private Drawable findTargetIn(Drawable d, InputState state)
Expand Down Expand Up @@ -145,6 +185,8 @@ private void removeRootVisualisedDrawable()
private void createRootVisualisedDrawable()
{
removeRootVisualisedDrawable();
setHighlight(null);

if (target != null)
{
targetDrawable = createVisualisedDrawable(null, target as Drawable);
Expand All @@ -155,8 +197,6 @@ private void createRootVisualisedDrawable()
// Update property viewer
setHighlight(targetDrawable);
}

propertyDisplay.State = Visibility.Visible;
}

private Drawable target;
Expand All @@ -182,8 +222,12 @@ private void updatePropertyDisplay(Drawable d)
propertyDisplay.Clear(true);

if (d == null)
{
propertyDisplay.State = Visibility.Hidden;
return;
}

propertyDisplay.State = Visibility.Visible;
Type type = d.GetType();

propertyDisplay.Add(
Expand Down Expand Up @@ -223,22 +267,20 @@ private VisualisedDrawable createVisualisedDrawable(VisualisedDrawable parent, D
}

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);
highlighted?.highlightBackground.FadeOut();

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

newHighlight.Expand();
updatePropertyDisplay(null);
highlighted = null;
return;
}

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

newHighlight.highlightBackground.FadeIn();
newHighlight.Expand();
}

private void visualise(IDrawable d, VisualisedDrawable vis)
Expand Down
75 changes: 53 additions & 22 deletions osu.Framework/Graphics/Visualisation/PropertyDisplay.cs
Expand Up @@ -94,60 +94,91 @@ internal class PropertyItem : ClickableContainer
{
private readonly SpriteText nameText;
private readonly SpriteText valueText;
private readonly Box changeMarker;

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;
getValue = () => ((PropertyInfo)info).GetValue(d)?.ToString();
break;

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

RelativeSizeAxes = Axes.X;
Height = 20f;
AddInternal(new Drawable[]
{
box = new Box()
new Container()
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
Alpha = 0f
},
nameText = new SpriteText()
{
Text = info.Name,
TextSize = Height
Padding = new MarginPadding()
{
Right = 6
},
Children = 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
},
}
},
valueText = new SpriteText()
changeMarker = new Box()
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
TextSize = Height
Size = new Vector2(4, 18),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Colour = Color4.Red
}
});
}

private string lastValue;

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

// Update value
valueText.Text = getValue();
string value;
try
{
value = getValue();
}
catch
{
value = @"<Cannot evaluate>";
}

if (value != lastValue)
{
changeMarker.ClearTransforms();
changeMarker.Alpha = 0.8f;
changeMarker.FadeOut(200);
}

valueText.Text = lastValue = value;
}

protected override bool OnHover(InputState state)
Expand Down
15 changes: 14 additions & 1 deletion osu.Framework/Graphics/Visualisation/VisualisedDrawable.cs
Expand Up @@ -32,6 +32,7 @@ public int Compare(VisualisedDrawable x, VisualisedDrawable y)
public Drawable Target { get; }

private readonly Box background;
internal readonly Box highlightBackground;

This comment was marked as off-topic.

private readonly SpriteText text;
private readonly Drawable previewBox;
private readonly Drawable activityInvalidate;
Expand Down Expand Up @@ -111,6 +112,15 @@ public VisualisedDrawable(VisualisedDrawable parent, Drawable d, DrawVisualiser
Origin = Anchor.CentreLeft,
Colour = Color4.Transparent,
},
highlightBackground = new Box
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(1, 0.8f),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Colour = Color4.Khaki.Opacity(0.4f),
Alpha = 0
},
text = new SpriteText
{
Scale = new Vector2(0.9f),
Expand Down Expand Up @@ -180,7 +190,10 @@ protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
if (state.Mouse.IsPressed(MouseButton.Right))
{
HighlightTarget?.Invoke(this);
if (viz.highlighted == this)
HighlightTarget?.Invoke(null);

else HighlightTarget?.Invoke(this);

This comment was marked as off-topic.

return true;
}

Expand Down