Skip to content

Commit 9fac79c

Browse files
authored
Merge pull request #28 from SirRickster/memory-viewer-button-bar
Añadida barra de botones en "Memory Viewer"
2 parents dee5017 + 45383f3 commit 9fac79c

6 files changed

Lines changed: 237 additions & 66 deletions

File tree

ZXBStudio/App.axaml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,50 +109,55 @@
109109
<Setter Property="Margin" Value="0"></Setter>
110110
<Setter Property="CornerRadius" Value="5"></Setter>
111111
<Setter Property="Height" Value="24"></Setter>
112-
<Setter Property="Padding" Value="5"></Setter>
112+
<Setter Property="Padding" Value="2"></Setter>
113113
</Style>
114114
<Style Selector="TextBlock.dialog">
115115
<Setter Property="Foreground" Value="#ffffffff"></Setter>
116-
<Setter Property="Margin" Value="5"></Setter>
116+
<Setter Property="Margin" Value="2"></Setter>
117117
</Style>
118118
<Style Selector="TextBox.dialog">
119-
<Setter Property="Margin" Value="5"></Setter>
119+
<Setter Property="Margin" Value="2"></Setter>
120120
<Setter Property="CornerRadius" Value="5"></Setter>
121-
<Setter Property="Height" Value="32"></Setter>
121+
<Setter Property="Height" Value="24"></Setter>
122122
<Setter Property="MaxWidth" Value="140"></Setter>
123123
</Style>
124124
<Style Selector="Button.dialog">
125-
<Setter Property="Margin" Value="5"></Setter>
125+
<Setter Property="Margin" Value="2"></Setter>
126126
<Setter Property="CornerRadius" Value="5"></Setter>
127127
</Style>
128+
<Style Selector="ToggleButton.dialog">
129+
<Setter Property="Margin" Value="2"></Setter>
130+
<Setter Property="CornerRadius" Value="5"></Setter>
131+
<Setter Property="Height" Value="32"></Setter>
132+
</Style>
128133
<Style Selector="ComboBox.dialog">
129134
<Setter Property="Margin" Value="0"></Setter>
130135
<Setter Property="CornerRadius" Value="5"></Setter>
131-
<Setter Property="Height" Value="32"></Setter>
132-
<Setter Property="Padding" Value="5"></Setter>
136+
<Setter Property="Height" Value="24"></Setter>
137+
<Setter Property="Padding" Value="2"></Setter>
133138
</Style>
134139

135140
<Style Selector="NumericUpDown.dialog">
136141
<Setter Property="Margin" Value="0"></Setter>
137142
<Setter Property="CornerRadius" Value="5"></Setter>
138-
<Setter Property="Padding" Value="5,7,0,0"></Setter>
143+
<Setter Property="Padding" Value="5,2,0,0"></Setter>
139144
<Setter Property="VerticalAlignment" Value="Center"></Setter>
140145
<Setter Property="BorderThickness" Value="0"></Setter>
141146
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
142147
</Style>
143148
<Style Selector="NumericUpDown.dialog TextBox">
144-
<Setter Property="Margin" Value="5"></Setter>
149+
<Setter Property="Margin" Value="0"></Setter>
145150
<Setter Property="CornerRadius" Value="5"></Setter>
146-
<Setter Property="Height" Value="32"></Setter>
151+
<Setter Property="Height" Value="24"></Setter>
147152
<Setter Property="MaxWidth" Value="140"></Setter>
148-
<Setter Property="HorizontalAlignment" Value="Left"></Setter>
153+
<Setter Property="HorizontalAlignment" Value="Right"></Setter>
149154
</Style>
150-
<Style Selector="Border.numericborder">
155+
<Style Selector="Border.numericBorder">
151156
<Setter Property="BorderBrush" Value="#ff909090" ></Setter>
152-
<Setter Property="BorderThickness" Value="2" ></Setter>
157+
<Setter Property="BorderThickness" Value="1" ></Setter>
153158
<Setter Property="CornerRadius" Value="5" ></Setter>
154159
<Setter Property="Padding" Value="-1" ></Setter>
155-
<Setter Property="Margin" Value="5,0,5,0"></Setter>
160+
<Setter Property="Margin" Value="2,0,2,0"></Setter>
156161
<Setter Property="Height" Value="32"></Setter>
157162
</Style>
158163
</Application.Styles>

ZXBStudio/DebuggingTools/Memory/Controls/ZXMemoryView.axaml

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,77 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:wnd="using:ZXBasicStudio.Classes"
6+
xmlns:svg="using:Avalonia.Svg.Skia"
57
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
68
x:Class="ZXBasicStudio.DebuggingTools.Memory.Controls.ZXMemoryView">
7-
<UserControl.Styles>
8-
<Style Selector="TextBlock">
9-
<Setter Property="Foreground" Value="#ffffff"></Setter>
10-
<Setter Property="VerticalAlignment" Value="Center"></Setter>
11-
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
12-
<Setter Property="TextAlignment" Value="Center"></Setter>
13-
<Setter Property="FontFamily" Value="Cascadia Code,Consolas,Menlo,Monospace"></Setter>
14-
</Style>
15-
</UserControl.Styles>
16-
<UserControl.ContextMenu>
17-
<ContextMenu Placement="Pointer">
18-
<MenuItem Header="ASCII view" Name="mnuAscii"/>
19-
<MenuItem Header="HEX view" Name="mnuHex"/>
20-
<Separator></Separator>
21-
<MenuItem Header="Search..." Name="mnuSearch"/>
22-
</ContextMenu>
23-
</UserControl.ContextMenu>
24-
<Grid ColumnDefinitions="*,32">
25-
<Grid Name="grdBlocks" ColumnDefinitions="2*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*" RowDefinitions="*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="#303030" Margin="0,0,0,02">
26-
<TextBlock Grid.Column="1">00</TextBlock>
27-
<TextBlock Grid.Column="2">01</TextBlock>
28-
<TextBlock Grid.Column="3">02</TextBlock>
29-
<TextBlock Grid.Column="4">03</TextBlock>
30-
<TextBlock Grid.Column="5">04</TextBlock>
31-
<TextBlock Grid.Column="6">05</TextBlock>
32-
<TextBlock Grid.Column="7">06</TextBlock>
33-
<TextBlock Grid.Column="8">07</TextBlock>
34-
<TextBlock Grid.Column="9">08</TextBlock>
35-
<TextBlock Grid.Column="10">09</TextBlock>
36-
<TextBlock Grid.Column="11">0A</TextBlock>
37-
<TextBlock Grid.Column="12">0B</TextBlock>
38-
<TextBlock Grid.Column="13">0C</TextBlock>
39-
<TextBlock Grid.Column="14">0D</TextBlock>
40-
<TextBlock Grid.Column="15">0E</TextBlock>
41-
<TextBlock Grid.Column="16">0F</TextBlock>
42-
<Separator Margin="0" VerticalAlignment="Bottom" Grid.ColumnSpan="17"></Separator>
43-
<Rectangle Grid.RowSpan="17" HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="1" Stroke="#444444" StrokeThickness="2" />
9+
<UserControl.Styles>
10+
<Style Selector="TextBlock">
11+
<Setter Property="Foreground" Value="#ffffff"></Setter>
12+
<Setter Property="VerticalAlignment" Value="Center"></Setter>
13+
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
14+
<Setter Property="TextAlignment" Value="Center"></Setter>
15+
<Setter Property="FontFamily" Value="Cascadia Code,Consolas,Menlo,Monospace"></Setter>
16+
</Style>
17+
</UserControl.Styles>
18+
<UserControl.ContextMenu>
19+
<ContextMenu Placement="Pointer">
20+
<MenuItem Header="ASCII view" Name="mnuAscii" />
21+
<MenuItem Header="HEX view" Name="mnuHex" />
22+
<Separator></Separator>
23+
<MenuItem Header="Search..." Name="mnuSearch" />
24+
<MenuItem Header="Goto" Name="mnuGoto" />
25+
</ContextMenu>
26+
</UserControl.ContextMenu>
27+
<Grid RowDefinitions="auto,*">
28+
<StackPanel Grid.Row="0" Spacing="2" Orientation="Horizontal" Margin="2">
29+
<ToggleButton Classes="dialog" Name="btnMemoryAddressHexFormat" IsChecked="{Binding Path=!#MemoryDecimalMode}" ToolTip.Tip="Display memory address as Hexadecimal">
30+
Hex
31+
</ToggleButton>
32+
<ToggleButton Classes="dialog" Name="btnMemoryAddressDecFormat" IsChecked="{Binding Path=#MemoryDecimalMode}" ToolTip.Tip="Display memory address as Decimal">
33+
Dec
34+
</ToggleButton>
35+
<Line StartPoint="0,2" EndPoint="0,34" Stroke="White" Margin="2,0,2,0"></Line>
36+
<ToggleButton Classes="dialog" Name="btnSwitchHexFormat" IsChecked="{Binding Path=!#ASCIIMode}" ToolTip.Tip="Display memory content as HEX">
37+
Hex
38+
</ToggleButton>
39+
<ToggleButton Classes="dialog" Name="btnSwitchASCIIFormat" IsChecked="{Binding Path=#ASCIIMode}" ToolTip.Tip="Display memory content as ASCII">
40+
ASCII
41+
</ToggleButton>
42+
<Line StartPoint="0,2" EndPoint="0,34" Stroke="White" Margin="2,0,2,0"></Line>
43+
<Border Classes="numericBorder">
44+
<NumericUpDown Margin="3,0" MinWidth="100" Classes="dialog" VerticalAlignment="Center"
45+
HorizontalAlignment="Left" ParsingNumberStyle="Integer" Increment="1" Minimum="0"
46+
Maximum="65535" Value="0" Name="nudAddress">
47+
</NumericUpDown>
48+
</Border>
49+
<Button Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right" Padding="7" Name="btnGoto">Goto</Button>
50+
</StackPanel>
51+
<Grid Grid.Row="1" ColumnDefinitions="*,32">
52+
<Grid Grid.Column="0" Grid.Row="1" Name="grdBlocks" ColumnDefinitions="2*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*"
53+
RowDefinitions="*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*" VerticalAlignment="Stretch"
54+
HorizontalAlignment="Stretch" Background="#303030" Margin="0,0,0,02">
55+
<TextBlock Grid.Column="1">00</TextBlock>
56+
<TextBlock Grid.Column="2">01</TextBlock>
57+
<TextBlock Grid.Column="3">02</TextBlock>
58+
<TextBlock Grid.Column="4">03</TextBlock>
59+
<TextBlock Grid.Column="5">04</TextBlock>
60+
<TextBlock Grid.Column="6">05</TextBlock>
61+
<TextBlock Grid.Column="7">06</TextBlock>
62+
<TextBlock Grid.Column="8">07</TextBlock>
63+
<TextBlock Grid.Column="9">08</TextBlock>
64+
<TextBlock Grid.Column="10">09</TextBlock>
65+
<TextBlock Grid.Column="11">0A</TextBlock>
66+
<TextBlock Grid.Column="12">0B</TextBlock>
67+
<TextBlock Grid.Column="13">0C</TextBlock>
68+
<TextBlock Grid.Column="14">0D</TextBlock>
69+
<TextBlock Grid.Column="15">0E</TextBlock>
70+
<TextBlock Grid.Column="16">0F</TextBlock>
71+
<Separator Margin="0" VerticalAlignment="Bottom" Grid.ColumnSpan="17"></Separator>
72+
<Rectangle Grid.RowSpan="17" HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="1"
73+
Stroke="#444444" StrokeThickness="2" />
74+
</Grid>
75+
<ScrollBar Name="scrFirstRow" Orientation="Vertical" Minimum="0" Maximum="4080" Grid.Column="1"></ScrollBar>
76+
</Grid>
4477
</Grid>
45-
<ScrollBar Name="scrFirstRow" Orientation="Vertical" Minimum="0" Maximum="4080" Grid.Column="1"></ScrollBar>
46-
</Grid>
47-
</UserControl>
78+
</UserControl>

ZXBStudio/DebuggingTools/Memory/Controls/ZXMemoryView.axaml.cs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public partial class ZXMemoryView : UserControl
1919
DispatcherTimer timer;
2020

2121
public bool ASCIIMode { get; set; }
22+
public bool MemoryDecimalMode { get; set; }
23+
2224
public ZXMemoryRange? HighlightedRange { get; set; }
2325
public ZXMemoryView()
2426
{
@@ -60,6 +62,34 @@ public ZXMemoryView()
6062
mnuAscii.Click += (o, e) => { ASCIIMode = true; Update(); };
6163
mnuHex.Click += (o, e) => { ASCIIMode = false; Update(); };
6264
mnuSearch.Click += MnuSearch_Click;
65+
mnuGoto.Click += MnuGoto_Click;
66+
btnGoto.Click += (o, e) => { GoToAddress((ushort)(nudAddress.Value ?? 0)); Update(); };
67+
btnSwitchASCIIFormat.Click += (o, e) =>
68+
{
69+
ASCIIMode = true;
70+
btnSwitchASCIIFormat.IsChecked = true;
71+
btnSwitchHexFormat.IsChecked = false;
72+
Update();
73+
};
74+
btnSwitchHexFormat.Click += (o, e) =>
75+
{
76+
ASCIIMode = false;
77+
btnSwitchASCIIFormat.IsChecked = false;
78+
btnSwitchHexFormat.IsChecked = true;
79+
Update();
80+
};
81+
btnMemoryAddressHexFormat.Click += (o, e) => {
82+
MemoryDecimalMode = false;
83+
btnMemoryAddressHexFormat.IsChecked = true;
84+
btnMemoryAddressDecFormat.IsChecked = false;
85+
Update();
86+
};
87+
btnMemoryAddressDecFormat.Click += (o, e) => {
88+
MemoryDecimalMode = true;
89+
btnMemoryAddressHexFormat.IsChecked = false;
90+
btnMemoryAddressDecFormat.IsChecked = true;
91+
Update();
92+
};
6393
}
6494

6595
private async void MnuSearch_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
@@ -83,6 +113,27 @@ private async void MnuSearch_Click(object? sender, Avalonia.Interactivity.Routed
83113
await dlg.ShowDialog(win);
84114
}
85115

116+
private async void MnuGoto_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
117+
{
118+
if (mem == null)
119+
return;
120+
121+
var top = TopLevel.GetTopLevel(this);
122+
123+
if(top == null)
124+
return;
125+
126+
var win = top as Window;
127+
128+
if (win == null)
129+
return;
130+
131+
ZXMemoryGotoDialog dlg = new ZXMemoryGotoDialog();
132+
dlg.Initialize(mem, this);
133+
134+
await dlg.ShowDialog(win);
135+
}
136+
86137
public void Initialize(IMemory Memory)
87138
{
88139
mem = Memory;
@@ -124,15 +175,16 @@ public void Update()
124175
for (int y = 0; y < 16; y++)
125176
{
126177
ushort rowAddress = (ushort)(y * 16);
127-
addressBlocks[y].Text = (startAddress + rowAddress).ToString("X4");
128-
178+
addressBlocks[y].Text = MemoryDecimalMode
179+
? (startAddress + rowAddress).ToString("D")
180+
: (startAddress + rowAddress).ToString("X4");
129181
for (int x = 0; x < 16; x++)
130182
{
131183
int byteAddress = rowAddress + x + startAddress;
132184

133185
var tb = dataBlocks[x + rowAddress];
134186
tb.Text = ASCIIMode ? Encoding.ASCII.GetString(block, x + rowAddress, 1) : block[x + rowAddress].ToString("X2");
135-
187+
136188
if (HighlightedRange != null && HighlightedRange.Contains(byteAddress))
137189
{
138190
if (tb.Background != Brushes.Red)
@@ -153,7 +205,11 @@ public void GoToAddress(ushort Address)
153205

154206
if (rowAddress > 4080)
155207
rowAddress = 4080;
208+
209+
ZXMemoryRange rng = new ZXMemoryRange { StartAddress = Address , EndAddress = Address };
156210

211+
HighlightedRange = rng;
212+
nudAddress.Value = Address;
157213
scrFirstRow.Value = rowAddress;
158214

159215
timer.Stop();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Window xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
mc:Ignorable="d" d:DesignWidth="350" d:DesignHeight="120"
6+
MinWidth="350" MaxWidth="300"
7+
MinHeight="120" MaxHeight="120"
8+
CanResize="false"
9+
x:Class="ZXBasicStudio.DebuggingTools.Memory.Dialogs.ZXMemoryGotoDialog"
10+
Icon="/Assets/zxbs.ico" WindowStartupLocation="CenterOwner"
11+
Title="Goto memory position">
12+
<Grid RowDefinitions="Auto,10,Auto,Auto,Auto" Margin="10">
13+
<NumericUpDown Margin="0,5,0,0" MinWidth="100" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Center" ParsingNumberStyle="Integer" Increment="1" Minimum="0" Maximum="65535" Name="nudAddress"></NumericUpDown>
14+
<StackPanel Margin="0,0,0,10" Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right">
15+
<Button Classes="dialog" VerticalAlignment="Bottom" Padding="7" Name="btnGoto">Goto</Button>
16+
<Button Classes="dialog" VerticalAlignment="Bottom" Padding="7" Name="btnClose">Close</Button>
17+
</StackPanel>
18+
</Grid>
19+
</Window>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Avalonia.Controls;
2+
using Konamiman.Z80dotNet;
3+
using Markdown.Avalonia.Utils;
4+
using System;
5+
using System.Text;
6+
using Tmds.DBus.Protocol;
7+
using ZXBasicStudio.DebuggingTools.Memory.Classes;
8+
using ZXBasicStudio.DebuggingTools.Memory.Controls;
9+
using ZXBasicStudio.Extensions;
10+
11+
namespace ZXBasicStudio.DebuggingTools.Memory.Dialogs
12+
{
13+
public partial class ZXMemoryGotoDialog : Window
14+
{
15+
IMemory? mem;
16+
ZXMemoryView? view;
17+
ushort currentAddr = 0;
18+
public ZXMemoryGotoDialog()
19+
{
20+
InitializeComponent();
21+
nudAddress.Value = currentAddr;
22+
btnGoto.Click += BtnGoto_Click;
23+
btnClose.Click += BtnClose_Click;
24+
}
25+
26+
private void BtnClose_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
27+
{
28+
this.Close();
29+
}
30+
31+
private void BtnGoto_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
32+
{
33+
Goto((ushort)(nudAddress.Value ?? 0));
34+
}
35+
36+
async void Goto(ushort address)
37+
{
38+
if (mem == null || view == null)
39+
return;
40+
41+
try
42+
{
43+
ZXMemoryRange rng = new ZXMemoryRange { StartAddress = address , EndAddress = address };
44+
45+
view.HighlightedRange = rng;
46+
nudAddress.Value = address;
47+
view.GoToAddress(address);
48+
view.Update();
49+
currentAddr = (ushort)(address < 65535 ? address + 1 : address);
50+
}
51+
catch { await this.ShowError("Error", "Error, possible invalid input."); }
52+
}
53+
54+
public void Initialize(IMemory Memory, ZXMemoryView View)
55+
{
56+
mem = Memory;
57+
view = View;
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)