Skip to content

Commit

Permalink
Merge pull request #46 from gusmanb/test_graphics_avalonia
Browse files Browse the repository at this point in the history
Merge with new graphics branch
  • Loading branch information
gusmanb authored Jan 14, 2024
2 parents 036fb8f + febe619 commit b886d80
Show file tree
Hide file tree
Showing 24 changed files with 714 additions and 282 deletions.
6 changes: 3 additions & 3 deletions MsBox.Avalonia/MsBox.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<AvaloniaResource Include="Assets\*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0" />
<PackageReference Include="DialogHost.Avalonia" Version="0.7.5" />
<PackageReference Include="Markdown.Avalonia.Tight" Version="11.0.0-d1" />
<PackageReference Include="Avalonia" Version="11.0.6" />
<PackageReference Include="DialogHost.Avalonia" Version="0.7.7" />
<PackageReference Include="Markdown.Avalonia.Tight" Version="11.0.2" />
</ItemGroup>
<ItemGroup>
<None Update="icon.jpg">
Expand Down
28 changes: 16 additions & 12 deletions ZXBStudio/BuildSystem/ZXBasicMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,23 +562,27 @@ private static ZXVariableStorage StorageFromString(string? Value, string Variabl

private static int GetDimensionSize(string DimensionString)
{
int size = 0;

if (!int.TryParse(DimensionString, out size))
try
{
if (DimensionString.ToLower().Contains("to"))
int size = 0;

if (!int.TryParse(DimensionString, out size))
{
string[] parts = DimensionString.ToLower().Split("to");
if (parts.Length == 1)
return int.Parse(parts[0]);
if (DimensionString.ToLower().Contains("to"))
{
string[] parts = DimensionString.ToLower().Split("to");
if (parts.Length == 1)
return int.Parse(parts[0]);
else
return int.Parse(parts[1]) - int.Parse(parts[0]) + 1;
}
else
return int.Parse(parts[1]) - int.Parse(parts[0]) + 1;
return 0;
}
else
return 0;
}

return size;
return size;
}
catch { return 0; }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public bool Inicialize(GraphicsModes graphicMode, PaletteColor[] palette, int se
DrawZXSpectrum();
grdZXSpectrum.IsVisible = true;
break;
case GraphicsModes.Next:
grdNext.IsVisible = true;
break;

}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ private void DrawPalette(Canvas cnv)
rows = 2;
cols = 8;
break;
case GraphicsModes.Next:
rows = 16;
cols = 16;
break;
}

int cellW = (int)(((this.Width - 200) / 2) / cols);
Expand Down
9 changes: 5 additions & 4 deletions ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Focusable="True"
Background="#ff202020"
x:Class="ZXBasicStudio.DocumentEditors.ZXGraphics.SpriteEditor">

x:Class="ZXBasicStudio.DocumentEditors.ZXGraphics.SpriteEditor">
<Grid Name="grdMain" RowDefinitions="*,Auto">
<Grid Name="grdEditor" Grid.RowSpan="2" ColumnDefinitions="180,4,*,4,200" Margin="0,8,0,0">

Expand Down Expand Up @@ -105,8 +104,10 @@
<WrapPanel Orientation="Horizontal" Background="#ff202020" Grid.Row="2" Margin="10,5,10,5" Height="NaN">
<TextBlock Name="txtZoom" Classes="dialog" Width="54">Zoom 24x</TextBlock>
<Slider Name="sldZoom" Width="100" Minimum="1" Maximum="9" Value="6" VerticalAlignment="Center"/>
<TextBlock Name="txtFrame" Classes="dialog" Width="55" Margin="8,4,0,0">Frame</TextBlock>
<Slider Name="sldFrame" Width="100" Minimum="0" Maximum="0" Value="0" VerticalAlignment="Center"/>
<TextBlock Name="lblFrame" Classes="dialog" Width="55" Margin="16,8,0,0">Frame</TextBlock>
<Border Classes="numericborder" Margin="-10,0,0,0">
<NumericUpDown Classes="dialog" Name="txtFrame" Minimum="0" Increment="1" Maximum="255" Value="0" VerticalAlignment="Center"/>
</Border>

<Grid Name="btnPaper" Margin="8,0,0,0" ColumnDefinitions="*,16,Auto">
<TextBlock Margin="10,5,5,5">Paper</TextBlock>
Expand Down
70 changes: 50 additions & 20 deletions ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private void _Initialize(string fileName)
}

sldZoom.PropertyChanged += SldZoom_PropertyChanged;
sldFrame.PropertyChanged += SldFrame_PropertyChanged;
txtFrame.PropertyChanged += TxtFrame_PropertyChanged;

btnClear.Tapped += BtnClear_Tapped;
btnCut.Tapped += BtnCut_Tapped;
Expand Down Expand Up @@ -351,7 +351,6 @@ private void _Initialize(string fileName)
this.Focus();
}


#region Color

private void BtnPaper_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
Expand Down Expand Up @@ -465,6 +464,8 @@ private void SpriteList_Command(SpritePatternControl sender, string command)
ctrlPreview.Refresh();
ctrlProperties.SpriteData = sender.SpriteData;
ctrlProperties.Refresh();
SpriteProperties_FrameUpdate(ctrlProperties, command);
txtFrame.Text = "0";
break;
}
}
Expand Down Expand Up @@ -498,24 +499,25 @@ private void SpriteProperties_Command(SpritePropertiesControl sender, string com
SpriteList_Clone(sender.SpriteData);
SpriteList_Modified(sender.SpriteData);
break;
case "FRAMEUPDATE":
SpriteProperties_FrameUpdate(sender, command);
break;
case "REFRESH":
ctrlEditor.SpriteData = sender.SpriteData;
SpriteList_Modified(sender.SpriteData);
if (ctrlEditor.SpriteData.CurrentFrame != actualFrame)
{
actualFrame = ctrlEditor.SpriteData.CurrentFrame;
if (sldFrame.Maximum < actualFrame)
txtFrame.Value = actualFrame;
if (txtFrame.Maximum < actualFrame)
{
sldFrame.Maximum = actualFrame;
txtFrame.Maximum = actualFrame;
}
sldFrame.Value = actualFrame;
txtFrame.Value = actualFrame;
Refresh();
}
UpdateColorPanel();
break;
case "CHANGEMODE":
ctrlEditor.SpriteData = sender.SpriteData;
SpriteList_Modified(sender.SpriteData);
switch (sender.SpriteData.GraphicMode)
{
case GraphicsModes.Monochrome:
Expand All @@ -526,17 +528,38 @@ private void SpriteProperties_Command(SpritePropertiesControl sender, string com
ctrlEditor.PrimaryColorIndex = 0;
ctrlEditor.SecondaryColorIndex = 7;
break;
case GraphicsModes.Next:
ctrlEditor.PrimaryColorIndex = 255;
ctrlEditor.SecondaryColorIndex = 0;
break;
}
ctrlEditor.SpriteData = sender.SpriteData;
SpriteList_Modified(sender.SpriteData);
UpdateColorPanel();
break;
}
}


private void SpriteProperties_FrameUpdate(SpritePropertiesControl sender, string command)
{
if (sender.SpriteData == null)
{
return;
}

int f = sender.SpriteData.Frames - 1;
if (f < 0)
{
f = 0;
}
else if (f > 255)
{
f = 255;
}
txtFrame.Maximum = f;
txtFrame.Text = f.ToString();
txtFrame.UpdateLayout();
SpriteProperties_Command(sender, "REFRESH");
}


private void SpriteList_AddSprite()
{
SpritePatternControl selectedSprite = null;
Expand Down Expand Up @@ -611,7 +634,7 @@ private void SpriteList_Insert(Sprite spriteData)
spriteData.Frames++;
ctrlProperties.Refresh();
ctrlEditor.Refresh();
sldFrame.Maximum = spriteData.Frames;
txtFrame.MaxHeight = spriteData.Frames - 1;
}


Expand Down Expand Up @@ -692,16 +715,16 @@ private void Editor_Command(SpritePatternEditor sender, string command)

private void Refresh()
{
txtFrame.Text = "Frame " + actualFrame.ToString();
txtFrame.Text = actualFrame.ToString();
if (ctrlProperties.SpriteData != null)
{
sldFrame.Maximum = ctrlProperties.SpriteData.Frames;
txtFrame.Maximum = ctrlProperties.SpriteData.Frames - 1;
}
else
{
sldFrame.Maximum = 0;
txtFrame.Maximum = 0;
}
sldFrame.UpdateLayout();
txtFrame.UpdateLayout();
}


Expand Down Expand Up @@ -746,13 +769,20 @@ private void ZoomOut()
}


private void SldFrame_PropertyChanged(object? sender, Avalonia.AvaloniaPropertyChangedEventArgs e)
private void TxtFrame_PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
byte v = (byte)sldFrame.Value;
if (actualFrame == v || ctrlProperties.SpriteData == null || v < 0 || v >= (ctrlProperties.SpriteData.Frames))
byte v = txtFrame.Text.ToByte();
if (actualFrame == v ||
ctrlProperties.SpriteData == null ||
v < 0 ||
v >= (ctrlProperties.SpriteData.Frames))
{
return;
}
if (v > 255)
{
v = 255;
}
actualFrame = v;
if (ctrlEditor.SpriteData != null)
{
Expand Down
28 changes: 18 additions & 10 deletions ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,31 @@
<Grid ColumnDefinitions="180,*,Auto" RowDefinitions="Auto, Auto,Auto,Auto,Auto,Auto,Auto,Auto">
<TextBlock Name="lblBuild" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Enable build:</TextBlock>
<CheckBox Classes="dialog" Name="chkAuto" Grid.Column="1"></CheckBox>

<TextBlock Name="lblOutputFile" Grid.Row="1" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">File path:</TextBlock>
<TextBox Name="txtOutputFile" Grid.Row="1" Classes="dialog" Grid.Column="1" MaxWidth="Infinity"></TextBox>
<Button Name="btnOutputFile" Grid.Row="1" Classes="dialog" Grid.Column="2" VerticalAlignment="Center">...</Button>

<TextBlock Name="lblLabelName" Classes="dialog" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Right">Var prefix:</TextBlock>
<TextBox Name="txtLabelName" Classes="dialog" Grid.Row="2" Grid.Column="1" MaxLength="64" Width="100" HorizontalAlignment="Left"></TextBox>
<TextBlock Name="lblDataType" Classes="dialog" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right">Data type:</TextBlock>
<ComboBox Name="cmbDataType" Classes="dialog" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left">
<ComboBoxItem>DIM (data as array)</ComboBoxItem>
<ComboBoxItem>ASM (DEFB inside ASM Block)</ComboBoxItem>
<ComboBoxItem>.BIN file (INCBIN "file.bin")</ComboBoxItem>
<ComboBoxItem>.TAP file (LOAD "" CODE)</ComboBoxItem>
</ComboBox>

<TextBlock Name="lblOutputFile" Grid.Row="2" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">File path:</TextBlock>
<TextBox Name="txtOutputFile" Grid.Row="2" Classes="dialog" Grid.Column="1" MaxWidth="Infinity"></TextBox>
<Button Name="btnOutputFile" Grid.Row="2" Classes="dialog" Grid.Column="2" VerticalAlignment="Center">...</Button>

<TextBlock Name="lblLabelName" Classes="dialog" Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Right">Var prefix:</TextBlock>
<TextBox Name="txtLabelName" Classes="dialog" Grid.Row="3" Grid.Column="1" MaxLength="64" Width="100" HorizontalAlignment="Left"></TextBox>

<TextBlock Name="lblArrayBase" Classes="dialog" Grid.Row="5" VerticalAlignment="Center" HorizontalAlignment="Right">Array base:</TextBlock>
<ComboBox Name="cmbArrayBase" Classes="dialog" Grid.Row="5" Grid.Column="1" HorizontalAlignment="Left">
<TextBlock Name="lblArrayBase" Classes="dialog" Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Right">Array base:</TextBlock>
<ComboBox Name="cmbArrayBase" Classes="dialog" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Left">
<ComboBoxItem>0 (default)</ComboBoxItem>
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>From project settings</ComboBoxItem>
</ComboBox>

<TextBlock Name="lblAttr" Grid.Row="6" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Export attributes</TextBlock>
<CheckBox Name="chkAttr" Grid.Row="6" Grid.Column="1" Classes="dialog"></CheckBox>
<TextBlock Name="lblAttr" Grid.Row="5" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Export attributes</TextBlock>
<CheckBox Name="chkAttr" Grid.Row="5" Grid.Column="1" Classes="dialog"></CheckBox>
</Grid>

<TextBlock Name="txtError" FontSize="14" Foreground="Red" Margin="0,16,0,16" IsVisible="False">
Expand Down
Loading

0 comments on commit b886d80

Please sign in to comment.