Skip to content

Commit

Permalink
Debugger: Add separators in some tooltips to group related values
Browse files Browse the repository at this point in the history
  • Loading branch information
SourMesen committed Jun 15, 2024
1 parent 60a75b6 commit 508d234
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
10 changes: 6 additions & 4 deletions UI/Debugger/Controls/DynamicTooltip.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
x:Class="Mesen.Debugger.Controls.DynamicTooltip"
>
<UserControl.Styles>
<Style Selector="TextBlock">
<Setter Property="VerticalAlignment" Value="Top" />
</Style>
<Style Selector="TextBox">
<Setter Property="Background" Value="Transparent" />
<Setter Property="VerticalAlignment" Value="Top" />
Expand All @@ -29,6 +26,10 @@
</UserControl.Styles>

<UserControl.DataTemplates>
<DataTemplate DataType="dc:TooltipSeparator">
<Rectangle Height="1" Fill="{StaticResource MesenGrayBorderColor}" Margin="5 3" />
</DataTemplate>

<DataTemplate DataType="dc:CustomTooltipEntry">
<ContentControl Content="{Binding Value}" />
</DataTemplate>
Expand All @@ -42,6 +43,7 @@
<TextBlock
Name="Header"
Text="{Binding Name}"
VerticalAlignment="{Binding VerticalAlignment}"
MinWidth="{Binding FirstColumnWidth, ElementName=root}"
IsVisible="{Binding Name.Length}"
Margin="0 0 10 2"
Expand All @@ -64,7 +66,7 @@
/>
</DataTemplate>
<DataTemplate DataType="x:Boolean">
<CheckBox IsChecked="{Binding}" IsEnabled="False" />
<CheckBox IsChecked="{Binding}" IsEnabled="False" Margin="-3 -3 0 0" />
</DataTemplate>
<DataTemplate DataType="dc:TooltipPictureEntry">
<Border BorderBrush="Gray" Background="#666" BorderThickness="1">
Expand Down
34 changes: 34 additions & 0 deletions UI/Debugger/Controls/DynamicTooltip.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Mesen.Config;
Expand Down Expand Up @@ -57,6 +58,10 @@ private void ComputeColumnWidth()
int maxWidth = 0;
Typeface typeface = new Typeface(mesenFont, FontStyle.Normal, FontWeight.Bold);
foreach(var item in Items) {
if(item is TooltipSeparator || item is CustomTooltipEntry) {
continue;
}

var text = new FormattedText(item.Name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, fontSize, null);
maxWidth = Math.Max(maxWidth, (int)text.Width + 5);
}
Expand Down Expand Up @@ -92,6 +97,8 @@ public class TooltipEntry : ReactiveObject
[Reactive] public object Value { get; set; } = "";
[Reactive] public bool UseMonoFont { get; set; } = false;

public virtual VerticalAlignment VerticalAlignment => Value is bool ? VerticalAlignment.Center : VerticalAlignment.Top;

public TooltipEntry(string name, object value, bool useMonoFont = false)
{
Name = name;
Expand All @@ -107,6 +114,13 @@ public CustomTooltipEntry(string name, object value, bool useMonoFont = false) :
}
}

public class TooltipSeparator : TooltipEntry
{
public TooltipSeparator(string name) : base(name, false, false)
{
}
}

public class TooltipEntries : List<TooltipEntry>, INotifyCollectionChanged
{
private Dictionary<string, TooltipEntry> _entries = new();
Expand Down Expand Up @@ -160,6 +174,22 @@ public void AddCustomEntry(string name, Control value)
}
}

public void AddSeparator(string name)
{
if(this.Count > _updatedKeys.Count - 1 && this[_updatedKeys.Count - 1] is TooltipSeparator) {
return;
}

_updatedKeys.Add(name);

if(!_entries.TryGetValue(name, out _)) {
TooltipEntry? entry = new TooltipSeparator(name);
_entries[name] = entry;
base.Insert(_updatedKeys.Count - 1, new TooltipSeparator(name));
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}

public void AddEntry(string name, NullableBoolean value)
{
if(value != NullableBoolean.Undefined) {
Expand Down Expand Up @@ -201,6 +231,10 @@ public void EndUpdate()
}
}

while(this.Count > 0 && this[^1] is TooltipSeparator) {
RemoveAt(this.Count - 1);
}

if(updated) {
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
Expand Down
8 changes: 8 additions & 0 deletions UI/Debugger/ViewModels/SpriteViewerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ private void Config_PropertyChanged(object? sender, PropertyChangedEventArgs e)
);
entries.AddEntry("Size", sprite.Width + "x" + sprite.Height);

entries.AddSeparator("TileSeparator");

entries.AddEntry("Tile index", "$" + sprite.TileIndex.ToString("X2"));

MemoryType memType = CpuType.GetVramMemoryType(sprite.UseExtendedVram);
Expand All @@ -323,10 +325,16 @@ private void Config_PropertyChanged(object? sender, PropertyChangedEventArgs e)
} else {
entries.AddEntry("Tile address", FormatAddress(sprite.TileAddress, memType));
}

entries.AddSeparator("PaletteSeparator");

entries.AddEntry("Palette index", sprite.Palette.ToString());
if(sprite.PaletteAddress >= 0) {
entries.AddEntry("Palette address", "$" + sprite.PaletteAddress.ToString("X2"));
}

entries.AddSeparator("MiscSeparator");

entries.AddEntry("Visibility", ResourceHelper.GetEnumText(sprite.Visibility));
entries.AddEntry("Horizontal mirror", sprite.HorizontalMirror);
entries.AddEntry("Vertical mirror", sprite.VerticalMirror);
Expand Down
12 changes: 12 additions & 0 deletions UI/Debugger/ViewModels/TilemapViewerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ private void UpdateTilemapInfo()
if(tileInfo.TileMapAddress >= 0) {
entries.AddEntry("Tilemap address", FormatAddress(tileInfo.TileMapAddress));
}

entries.AddSeparator("TileSeparator");

if(tileInfo.TileIndex >= 0) {
entries.AddEntry("Tile index", "$" + tileInfo.TileIndex.ToString("X2"));
}
Expand All @@ -605,6 +608,9 @@ private void UpdateTilemapInfo()
entries.AddEntry("Tile address", FormatAddress(tileInfo.TileAddress));
}
}

entries.AddSeparator("PaletteSeparator");

if(tileInfo.PaletteIndex >= 0) {
if(tileInfo.BasePaletteIndex >= 0) {
entries.AddEntry("Palette index", $"{tileInfo.BasePaletteIndex} ({tileInfo.PaletteIndex})");
Expand All @@ -615,12 +621,18 @@ private void UpdateTilemapInfo()
if(tileInfo.PaletteAddress >= 0) {
entries.AddEntry("Palette address", "$" + tileInfo.PaletteAddress.ToString("X2"));
}

entries.AddSeparator("AttributeSeparator");

if(tileInfo.AttributeAddress >= 0) {
entries.AddEntry("Attribute address", "$" + tileInfo.AttributeAddress.ToString("X4"));
}
if(tileInfo.AttributeData >= 0) {
entries.AddEntry("Attribute data", "$" + tileInfo.AttributeData.ToString("X2"));
}

entries.AddSeparator("MiscSeparator");

if(tileInfo.PixelData >= 0) {
entries.AddEntry("Pixel data", "$" + tileInfo.PixelData.ToString("X2"));
}
Expand Down
8 changes: 8 additions & 0 deletions UI/Debugger/Windows/EventViewerWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,15 @@ private TooltipEntries GetTooltipData(DebugEventInfo evt)
{
TooltipEntries entries = new();
entries.AddEntry("Type", ResourceHelper.GetEnumText(evt.Type));

entries.AddSeparator("LocationSeparator");

entries.AddEntry("Scanline", evt.Scanline.ToString());
entries.AddEntry(_model.CpuType == CpuType.Snes ? "H-Clock" : "Cycle", evt.Cycle.ToString());
entries.AddEntry("PC", "$" + evt.ProgramCounter.ToString("X" + _model.CpuType.GetAddressSize()));

entries.AddSeparator("AddressValueSeparator");

switch(evt.Type) {
case DebugEventType.Register:
bool isWrite = evt.Operation.Type == MemoryOperationType.Write || evt.Operation.Type == MemoryOperationType.DmaWrite;
Expand All @@ -149,9 +154,12 @@ private TooltipEntries GetTooltipData(DebugEventInfo evt)

string details = EventViewerViewModel.GetEventDetails(_model.CpuType, evt, false);
if(details.Length > 0) {
entries.AddSeparator("DetailsSeparator");
entries.AddEntry("Details", details);
}

entries.EndUpdate();

return entries;
}

Expand Down

0 comments on commit 508d234

Please sign in to comment.