Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Have fun!
- <a href="https://github.com/phosphor-icons/phosphor-icons?ref=svgrepo.com" target="_blank">Phosphor</a> in MIT License
- <a href="https://www.zondicons.com/?ref=svgrepo.com" target="_blank">Steve Schoger</a> in PD License
- <a href="https://www.figma.com/@thewolfkit?ref=svgrepo.com" target="_blank">Thewolfkit</a> in CC Attribution License
- <a href="https://github.com/UXAspects/UXAspects?ref=svgrepo.com" target="_blank">Uxaspects</a> in Apache License
- <a href="https://github.com/uxwb/icons?ref=svgrepo.com" target="_blank">Uxwb</a> in GPL License
- <a href="https://www.wishforge.games/?ref=svgrepo.com" target="_blank">Wishforge.games</a> in CC Attribution License
- <a href="https://github.com/yamatsum/nonicons?ref=svgrepo.com" target="_blank">Yamatsum</a> in MIT License
- <a href="https://github.com/32pixelsCo/zest-icons/blob/master/packages/zest-free/LICENSE.md?ref=svgrepo.com" target="_blank">Zest</a> in MIT License
2 changes: 1 addition & 1 deletion ZXBStudio/Dialogs/SplashScreen.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Border BorderBrush="Black" BorderThickness="2">
<Grid RowDefinitions="*,Auto">
<Image Grid.RowSpan="2" Source="/Assets/LogoBig.png"></Image>
<Label x:Name="lblVersion" VerticalAlignment="Bottom"></Label>
<Label x:Name="lblVersion" VerticalAlignment="Bottom"/>
</Grid>
</Border>
</Window>
2 changes: 1 addition & 1 deletion ZXBStudio/Dialogs/SplashScreen.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public partial class SplashScreen : Window
public SplashScreen()
{
InitializeComponent();
lblVersion.Content = $"v{Program.Version} | {Program.VersionDate}";
lblVersion.Content=$"{Program.Version} | {Program.VersionDate}";
}
}
}
17 changes: 14 additions & 3 deletions ZXBStudio/DocumentEditors/ZXGraphics/PaletteBuilderDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<Grid Grid.Row="3" Grid.ColumnDefinitions="Auto,*" Grid.RowDefinitions="Auto,Auto,Auto,Auto,Auto">
<CheckBox Grid.Row="0" Name="chkUseCurrent" IsChecked="True" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="0" Grid.Column="1" Classes="dialog" VerticalAlignment="Center">Convert to current palette</TextBlock>

<CheckBox Grid.Row="1" Name="chkAppend" IsChecked="False" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="1" Grid.Column="1" Classes="dialog" VerticalAlignment="Center">Append new colors to current palette</TextBlock>

Expand Down Expand Up @@ -78,7 +78,7 @@
<NumericUpDown Classes="dialog" Name="txtBlue" Minimum="0" Increment="36" Maximum="255" Width="60" VerticalAlignment="Center" Value="0"/>
</Border>

<Border Grid.Row="1" Grid.Column="3" Grid.RowSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="1" BorderBrush="Red">
<Border Grid.Row="1" Grid.Column="3" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="1" BorderBrush="Red">
<Grid Name="grdSelectedColor" Width="50" Height="50"></Grid>
</Border>

Expand All @@ -95,10 +95,21 @@
<Button Name="btnRefresh" Classes="dialog" HorizontalAlignment="Right">Refresh</Button>
<Button Grid.Row="2" Name="btnSaveImage" Classes="dialog" HorizontalAlignment="Right">Save image</Button>
</Grid>

<StackPanel Grid.Row="4" Grid.ColumnSpan="5" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Name="btnClose" Classes="dialog">Close</Button>
</StackPanel>

<Grid Name="grdColorPicker" Grid.ColumnSpan="5" Grid.RowSpan="5" IsVisible="False"
Margin="10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Canvas x:Name="ColorWheelCanvas" Width="500" Height="500" Background="Black"
HorizontalAlignment="Center" VerticalAlignment="Center"
PointerPressed="ColorWheelCanvas_PointerPressed"/>
<Border Width="100" Height="30" Background="White"
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10">
<Rectangle x:Name="SelectedColorPreview" Fill="Transparent"/>
</Border>
</Grid>

</Grid>
</Window>
173 changes: 172 additions & 1 deletion ZXBStudio/DocumentEditors/ZXGraphics/PaletteBuilderDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using Avalonia.Controls.Shapes;
using static CommunityToolkit.Mvvm.ComponentModel.__Internals.__TaskExtensions.TaskAwaitableWithoutEndValidation;
using FFmpeg.AutoGen;
using System.Diagnostics;

namespace ZXBasicStudio.DocumentEditors.ZXGraphics
{
Expand All @@ -44,6 +45,7 @@ public partial class PaletteBuilderDialog : Window, IDisposable

private Rectangle[] rectangulos = new Rectangle[256];
private PaletteColor[] palette = null;
private PaletteColor[] palette512 = null;
private string sourceFile = null;
private string convertedFile = null;
private bool imgSourceLoaded = false;
Expand All @@ -68,8 +70,9 @@ public PaletteBuilderDialog()

// Set the palette
palette = ServiceLayer.GetPalette(GraphicsModes.Next);
selectedColorIndex = 0;
selectedColorIndex = 0;
DrawPalette();
DrawColorPicker();

btnFileSource.Tapped += BtnFileSource_Tapped;
btnResetPalette.Click += BtnResetPalette_Click;
Expand All @@ -85,7 +88,10 @@ public PaletteBuilderDialog()
btnRefresh.Click += BtnRefresh_Click;
btnSaveImage.Click += BtnSaveImage_Click;

btnColorPicker.Click += BtnColorPicker_Click;

btnClose.Click += BtnClose_Click;

}


Expand Down Expand Up @@ -893,5 +899,170 @@ private void CrearPaletaGPL9bits()
}

#endregion


#region Color Picker

private int Circles = 8; //16;
private int Sectors = 32;
private double Radius = 200;

private void BtnColorPicker_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
grdColorPicker.IsVisible = true;
}


private void DrawColorPicker()
{
Create512Palette();

ColorWheelCanvas.Children.Clear();
double ringWidth = Radius / Circles;
double angleStep = 360.0 / Sectors;
double cx = Radius;
double cy = Radius;

for (int circle = 0; circle < Circles; circle++)
{
double r1 = ringWidth * circle;
double r2 = ringWidth * (circle + 1);
double value = (circle + 1) / (double)Circles;

for (int sector = 0; sector < Sectors; sector++)
{
double hue = sector * angleStep;
Color color = FromHSV(hue, 1.0, value);
int idx=ServiceLayer.GetColor(color.R, color.G, color.B, palette512, 5);
var p = palette512[idx];
var color512=Color.FromRgb(p.Red, p.Green, p.Blue);
DrawSegment(cx, cy, r1, r2, hue, angleStep, color512);
}
}
}

private void DrawSegment(double cx, double cy, double r1, double r2, double startAngle, double angleSize, Color color)
{
var startRad = Math.PI * startAngle / 180.0;
var endRad = Math.PI * (startAngle + angleSize) / 180.0;

var p1 = new Point(cx + r1 * Math.Cos(startRad), cy + r1 * Math.Sin(startRad));
var p2 = new Point(cx + r2 * Math.Cos(startRad), cy + r2 * Math.Sin(startRad));
var p3 = new Point(cx + r2 * Math.Cos(endRad), cy + r2 * Math.Sin(endRad));
var p4 = new Point(cx + r1 * Math.Cos(endRad), cy + r1 * Math.Sin(endRad));

var path = new Avalonia.Controls.Shapes.Path
{
Fill = new SolidColorBrush(color),
StrokeThickness = 0,
Data = new PathGeometry
{
Figures = new PathFigures
{
new PathFigure
{
StartPoint = p1,
Segments = new PathSegments
{
new LineSegment { Point = p2 },
new ArcSegment
{
Point = p3,
Size = new Size(r2, r2),
SweepDirection = SweepDirection.Clockwise,
IsLargeArc = angleSize > 180
},
new LineSegment { Point = p4 },
new ArcSegment
{
Point = p1,
Size = new Size(r1, r1),
SweepDirection = SweepDirection.CounterClockwise,
IsLargeArc = angleSize > 180
}
}
}
}
}
};

ColorWheelCanvas.Children.Add(path);
}

private void ColorWheelCanvas_PointerPressed(object? sender, PointerPressedEventArgs e)
{
var pos = e.GetPosition(ColorWheelCanvas);
double dx = pos.X - Radius;
double dy = pos.Y - Radius;
double distance = Math.Sqrt(dx * dx + dy * dy);
if (distance > Radius) return;

double angle = Math.Atan2(dy, dx) * 180 / Math.PI;
if (angle < 0) angle += 360;

int sector = (int)(angle / (360.0 / Sectors));
int circle = (int)(distance / (Radius / Circles));

double hue = sector * (360.0 / Sectors);
double value = (circle + 1) / (double)Circles;
Color color = FromHSV(hue, 1.0, value);

SelectedColorPreview.Fill = new SolidColorBrush(color);
}

private static Color FromHSV(double hue, double saturation, double value)
{
double c = value * saturation;
double x = c * (1 - Math.Abs((hue / 60.0 % 2) - 1));
double m = value - c;

double r = 0, g = 0, b = 0;

if (hue < 60) { r = c; g = x; }
else if (hue < 120) { r = x; g = c; }
else if (hue < 180) { g = c; b = x; }
else if (hue < 240) { g = x; b = c; }
else if (hue < 300) { r = x; b = c; }
else { r = c; b = x; }

byte R = (byte)((r + m) * 255);
byte G = (byte)((g + m) * 255);
byte B = (byte)((b + m) * 255);

return Color.FromRgb(R, G, B);
}

private void Create512Palette()
{
palette512 = new PaletteColor[512];
for (int i = 0; i < 512; i++)
{
int r = ((i & 0b111000000) >> 6)*36;
int g = ((i & 0b000111000) >> 3)*36;
int b = (i & 0b000000111)*36;
if (r > 250)
{
r = 255;
}
if (g > 250)
{
g = 255;
}
if (b > 250)
{
b = 255;
}

palette512[i] = new PaletteColor()
{
Red = (byte)r,
Green = (byte)g,
Blue = (byte)b,
HasPriority = false
};
}
}

#endregion
}
}
19 changes: 13 additions & 6 deletions ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
<Grid Grid.Column="2" Grid.Row="1" RowDefinitions="Auto,*,Auto">
<WrapPanel Orientation="Horizontal" Grid.ColumnSpan="5" Margin="10" Background="#ff202020" Height="NaN">

<Button Classes="toolbar" Name="btnUndo" ToolTip.Tip="Undo last action" IsEnabled="False">
<Button Classes="toolbar" Name="btnUndo" ToolTip.Tip="Undo last action">
<svg:Svg Path="/Svg/undo.svg"></svg:Svg>
</Button>
<Button Classes="toolbar" Name="btnRedo" ToolTip.Tip="Redo last action" IsEnabled="False">
<Button Classes="toolbar" Name="btnRedo" ToolTip.Tip="Redo last action" >
<svg:Svg Path="/Svg/redo.svg"></svg:Svg>
</Button>

Expand Down Expand Up @@ -103,14 +103,21 @@
</Button>
<Line StartPoint="0,0" EndPoint="0,32" Stroke="White" Margin="5,0,5,0"></Line>

<Button Classes="toolbar" Name="btnInvertPixelsCell" ToolTip.Tip="Invert pixels on cell" IsEnabled="False">
<ToggleButton Classes="toolbar" Name="btnViewAttributes" ToolTip.Tip="Hide or view attributes" IsChecked="True">
<svg:Svg Path="/Svg/hide.svg"></svg:Svg>
</ToggleButton>
<ToggleButton Classes="toolbar" Name="btnColorPicker" ToolTip.Tip="Select cell" IsChecked="True">
<svg:Svg Path="/Svg/picker.svg"></svg:Svg>
</ToggleButton>
<ToggleButton Classes="toolbar" Name="btnInvertPixelsCell" ToolTip.Tip="Invert pixels on selected cell" IsChecked="True">
<svg:Svg Path="/Svg/invert-mode-svgrepo-com.svg"></svg:Svg>
</Button>
<Button Classes="toolbar" Name="btnInvertColorsCell" ToolTip.Tip="Invert colors on cell" IsEnabled="False">
</ToggleButton>
<ToggleButton Classes="toolbar" Name="btnInvertColorsCell" ToolTip.Tip="Invert attributes on selected cell" IsChecked="True">
<svg:Svg Path="/Svg/invert-color-svgrepo-com.svg"></svg:Svg>
</Button>
</ToggleButton>
<Line StartPoint="0,0" EndPoint="0,32" Stroke="White" Margin="5,0,5,0"></Line>


<Button Classes="toolbar" Name="btnImport" ToolTip.Tip="Import from image or data">
<svg:Svg Path="/Svg/ImageImport.svg"></svg:Svg>
</Button>
Expand Down
Loading