Skip to content

Commit 1e2a406

Browse files
author
Juan Segura
committed
- Added View/Hide attributes button
- Added Invert pixels on selected cell button - Added Invert colors on selected cell button
1 parent ea77558 commit 1e2a406

9 files changed

Lines changed: 200 additions & 19 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Have fun!
2828
- <a href="https://github.com/phosphor-icons/phosphor-icons?ref=svgrepo.com" target="_blank">Phosphor</a> in MIT License
2929
- <a href="https://www.zondicons.com/?ref=svgrepo.com" target="_blank">Steve Schoger</a> in PD License
3030
- <a href="https://www.figma.com/@thewolfkit?ref=svgrepo.com" target="_blank">Thewolfkit</a> in CC Attribution License
31+
- <a href="https://github.com/UXAspects/UXAspects?ref=svgrepo.com" target="_blank">Uxaspects</a> in Apache License
32+
- <a href="https://github.com/uxwb/icons?ref=svgrepo.com" target="_blank">Uxwb</a> in GPL License
3133
- <a href="https://www.wishforge.games/?ref=svgrepo.com" target="_blank">Wishforge.games</a> in CC Attribution License
3234
- <a href="https://github.com/yamatsum/nonicons?ref=svgrepo.com" target="_blank">Yamatsum</a> in MIT License
3335
- <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

ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,21 @@
103103
</Button>
104104
<Line StartPoint="0,0" EndPoint="0,32" Stroke="White" Margin="5,0,5,0"></Line>
105105

106-
<Button Classes="toolbar" Name="btnInvertPixelsCell" ToolTip.Tip="Invert pixels on cell" IsEnabled="False">
106+
<ToggleButton Classes="toolbar" Name="btnViewAttributes" ToolTip.Tip="Hide or view attributes" IsChecked="True">
107+
<svg:Svg Path="/Svg/hide.svg"></svg:Svg>
108+
</ToggleButton>
109+
<ToggleButton Classes="toolbar" Name="btnSelectPixelsCell" ToolTip.Tip="Select cell" IsChecked="True" IsVisible="False">
110+
<svg:Svg Path="/Svg/select.svg"></svg:Svg>
111+
</ToggleButton>
112+
<ToggleButton Classes="toolbar" Name="btnInvertPixelsCell" ToolTip.Tip="Invert pixels on selected cell" IsChecked="True">
107113
<svg:Svg Path="/Svg/invert-mode-svgrepo-com.svg"></svg:Svg>
108-
</Button>
109-
<Button Classes="toolbar" Name="btnInvertColorsCell" ToolTip.Tip="Invert colors on cell" IsEnabled="False">
114+
</ToggleButton>
115+
<ToggleButton Classes="toolbar" Name="btnInvertColorsCell" ToolTip.Tip="Invert attributes on selected cell" IsChecked="True">
110116
<svg:Svg Path="/Svg/invert-color-svgrepo-com.svg"></svg:Svg>
111-
</Button>
117+
</ToggleButton>
112118
<Line StartPoint="0,0" EndPoint="0,32" Stroke="White" Margin="5,0,5,0"></Line>
113119

120+
114121
<Button Classes="toolbar" Name="btnImport" ToolTip.Tip="Import from image or data">
115122
<svg:Svg Path="/Svg/ImageImport.svg"></svg:Svg>
116123
</Button>

ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,11 @@ private void _Initialize(string fileName)
325325

326326
btnUndo.Tapped += BtnUndo_Tapped;
327327
btnRedo.Tapped += BtnRedo_Tapped;
328+
329+
btnViewAttributes.Tapped += BtnViewAttributes_Tapped;
328330
btnInvertColorsCell.Tapped += BtnInvertColorsCell_Tapped;
329-
btnInvertPixelsCell.Tapped += BtnInvertPixelsCell_Tapped;
330-
331+
btnInvertPixelsCell.Tapped += BtnInvertPixelsCell_Tapped;
332+
331333
Refresh();
332334

333335
if (SpritePatternsList.Count > 1)
@@ -1018,15 +1020,32 @@ private void BtnImport_Tapped(object? sender, TappedEventArgs e)
10181020
}
10191021

10201022

1023+
1024+
private void BtnViewAttributes_Tapped(object? sender, TappedEventArgs e)
1025+
{
1026+
ctrlEditor.ViewAttributes = btnViewAttributes.IsChecked==true;
1027+
}
1028+
1029+
10211030
private void BtnInvertPixelsCell_Tapped(object? sender, TappedEventArgs e)
10221031
{
1023-
1032+
ctrlEditor.InvertPixelsCell = btnInvertPixelsCell.IsChecked == false;
1033+
if (ctrlEditor.InvertPixelsCell)
1034+
{
1035+
btnInvertColorsCell.IsChecked = true;
1036+
ctrlEditor.InvertColorsCell = false;
1037+
}
10241038
}
10251039

10261040

10271041
private void BtnInvertColorsCell_Tapped(object? sender, TappedEventArgs e)
10281042
{
1029-
1043+
ctrlEditor.InvertColorsCell = btnInvertColorsCell.IsChecked == false;
1044+
if (ctrlEditor.InvertColorsCell)
1045+
{
1046+
btnInvertPixelsCell.IsChecked = true;
1047+
ctrlEditor.InvertPixelsCell = false;
1048+
}
10301049
}
10311050

10321051

ZXBStudio/DocumentEditors/ZXGraphics/SpritePatternEditor.axaml.cs

Lines changed: 112 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ public int Zoom
8383
public bool Bright { get; set; }
8484
public bool Flash { get; set; }
8585

86+
public bool ViewAttributes
87+
{
88+
get
89+
{
90+
return _ViewAttributes;
91+
}
92+
set
93+
{
94+
_ViewAttributes = value;
95+
aspect.ViewAttributes = value;
96+
Refresh(false);
97+
}
98+
}
99+
100+
private bool _ViewAttributes = true;
101+
102+
public bool InvertPixelsCell { get; set; } = false;
103+
104+
public bool InvertColorsCell { get; set; } = false;
105+
86106
#endregion
87107

88108

@@ -126,6 +146,8 @@ public SpritePatternEditor()
126146
grdEditor.PointerPressed += GrdEditor_PointerPressed;
127147
grdEditor.PointerReleased += GrdEditor_PointerReleased;
128148
grdEditor.PointerExited += GrdEditor_PointerExited;
149+
150+
aspect.ViewAttributes = true;
129151
}
130152

131153

@@ -277,19 +299,31 @@ private bool Pattern_Equals(Pattern p1, Pattern p2)
277299
private void GrdEditor_PointerPressed(object? sender, Avalonia.Input.PointerPressedEventArgs e)
278300
{
279301
var p = e.GetCurrentPoint(grdEditor);
280-
if (p.Properties.IsLeftButtonPressed)
302+
303+
if (InvertPixelsCell)
281304
{
282-
SetPoint(p.Position.X, p.Position.Y, PrimaryColorIndex);
283-
MouseLeftPressed = true;
284-
MouseRightPressed = false;
305+
GrdEditor_InvertPixelsCell(p.Position.X, p.Position.Y);
285306
}
286-
else if (p.Properties.IsRightButtonPressed)
307+
else if (InvertColorsCell)
287308
{
288-
SetPoint(p.Position.X, p.Position.Y, SecondaryColorIndex);
289-
MouseLeftPressed = false;
290-
MouseRightPressed = true;
309+
GrdEditor_InvertColorsCell(p.Position.X, p.Position.Y);
291310
}
292-
}
311+
else
312+
{
313+
if (p.Properties.IsLeftButtonPressed)
314+
{
315+
SetPoint(p.Position.X, p.Position.Y, PrimaryColorIndex);
316+
MouseLeftPressed = true;
317+
MouseRightPressed = false;
318+
}
319+
else if (p.Properties.IsRightButtonPressed)
320+
{
321+
SetPoint(p.Position.X, p.Position.Y, SecondaryColorIndex);
322+
MouseLeftPressed = false;
323+
MouseRightPressed = true;
324+
}
325+
}
326+
}
293327

294328

295329
/// <summary>
@@ -1053,5 +1087,74 @@ private void SetPointValue(int x, int y, int colorIndex, ref Pattern pattern)
10531087
}
10541088

10551089
#endregion
1090+
1091+
1092+
#region Invert pixels and colors
1093+
1094+
private void GrdEditor_InvertPixelsCell(double mx, double my)
1095+
{
1096+
if (SpriteData == null)
1097+
{
1098+
return;
1099+
}
1100+
1101+
int x = (int)mx;
1102+
int y = (int)my;
1103+
1104+
x = x / (_Zoom + 1);
1105+
y = y / (_Zoom + 1);
1106+
1107+
x = x / 8;
1108+
y = y / 8;
1109+
1110+
if (x < 0 || y < 0 || x >= SpriteData.Width || y >= SpriteData.Height)
1111+
{
1112+
return;
1113+
}
1114+
1115+
for(int py = 0; py < 8; py++)
1116+
{
1117+
for (int px = 0; px < 8; px++)
1118+
{
1119+
int dir = ((y * 8 + py) * SpriteData.Width) + (x * 8 + px);
1120+
if (dir < SpriteData.Patterns[SpriteData.CurrentFrame].RawData.Length)
1121+
{
1122+
var value = SpriteData.Patterns[SpriteData.CurrentFrame].RawData[dir];
1123+
if (value == PrimaryColorIndex)
1124+
{
1125+
SpriteData.Patterns[SpriteData.CurrentFrame].RawData[dir] = SecondaryColorIndex;
1126+
}
1127+
else if (value == SecondaryColorIndex)
1128+
{
1129+
SpriteData.Patterns[SpriteData.CurrentFrame].RawData[dir] = PrimaryColorIndex;
1130+
}
1131+
}
1132+
}
1133+
}
1134+
Refresh();
1135+
}
1136+
1137+
private void GrdEditor_InvertColorsCell(double mx, double my)
1138+
{
1139+
if (SpriteData == null)
1140+
{
1141+
return;
1142+
}
1143+
int x = (int)mx;
1144+
int y = (int)my;
1145+
x = x / (_Zoom + 1);
1146+
y = y / (_Zoom + 1);
1147+
1148+
var inkBak = PrimaryColorIndex;
1149+
var paperBak = SecondaryColorIndex;
1150+
var attr=GetAttribute(SpriteData.Patterns[SpriteData.CurrentFrame], x, y);
1151+
PrimaryColorIndex = attr.Paper;
1152+
SecondaryColorIndex = attr.Ink;
1153+
SetAttribute(SpriteData.Patterns[SpriteData.CurrentFrame], x, y);
1154+
PrimaryColorIndex = inkBak;
1155+
SecondaryColorIndex=paperBak;
1156+
Refresh();
1157+
}
1158+
#endregion
10561159
}
10571160
}

ZXBStudio/DocumentEditors/ZXGraphics/ZXGridImageView.axaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ namespace ZXBasicStudio.DocumentEditors.ZXGraphics
1414
{
1515
public partial class ZXGridImageView : UserControl
1616
{
17+
public bool ViewAttributes {
18+
get
19+
{
20+
return _ViewAttributes;
21+
}
22+
set
23+
{
24+
_ViewAttributes = value;
25+
InvalidateVisual();
26+
}
27+
}
28+
private bool _ViewAttributes = false;
29+
1730
private WriteableBitmap? gridImage;
1831
private IZXBitmap? backgroundImage;
1932
private SKColor gridColor = new SKColor(0x00, 0x00, 0x00, 0xFF);
@@ -75,15 +88,19 @@ public ZXGridImageView()
7588
private void EnsureGrid()
7689
{
7790
if (backgroundImage == null)
91+
{
7892
return;
93+
}
7994

8095
int w = (int)(backgroundImage.PixelSize.Width * Zoom + backgroundImage.PixelSize.Width + 1);
8196
int h = (int)(backgroundImage.PixelSize.Height * Zoom + backgroundImage.PixelSize.Height + 1);
8297

8398
if (gridImage != null)
8499
{
85100
if (gridImage.PixelSize.Width == w && gridImage.PixelSize.Height == h)
101+
{
86102
return;
103+
}
87104

88105
gridImage.Dispose();
89106

ZXBStudio/DocumentEditors/ZXGraphics/ZXSpriteImage.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public class ZXSpriteImage : IZXBitmap, IDisposable
1717
#endregion
1818

1919
#region Public properties
20+
2021
public bool IsEmpty { get; private set; }
22+
public bool ViewAttributes { get; set; } = true;
23+
2124
#endregion
2225

2326
#region Constructors
@@ -90,9 +93,27 @@ public unsafe void RenderSprite(Sprite Sprite, int FrameNumber)
9093
{
9194
var attr = GetAttribute(Sprite, frame, x, y);
9295
if (colorIndex == 0)
93-
color = Sprite.Palette[attr.Paper];
96+
{
97+
if (ViewAttributes)
98+
{
99+
color = Sprite.Palette[attr.Paper];
100+
}
101+
else
102+
{
103+
color = Sprite.Palette[7];
104+
}
105+
}
94106
else
95-
color = Sprite.Palette[attr.Ink];
107+
{
108+
if(ViewAttributes)
109+
{
110+
color = Sprite.Palette[attr.Ink];
111+
}
112+
else
113+
{
114+
color = Sprite.Palette[0];
115+
}
116+
}
96117
}
97118
break;
98119
case GraphicsModes.Monochrome:

ZXBStudio/Svg/hide.svg

Lines changed: 7 additions & 0 deletions
Loading

ZXBStudio/Svg/select.svg

Lines changed: 1 addition & 0 deletions
Loading

ZXBStudio/ZXBasicStudio.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<None Remove="Svg\gears-solid.svg" />
171171
<None Remove="Svg\github.svg" />
172172
<None Remove="Svg\hashtag-solid.svg" />
173+
<None Remove="Svg\hide.svg" />
173174
<None Remove="Svg\ImageImport.svg" />
174175
<None Remove="Svg\invert-color-svgrepo-com.svg" />
175176
<None Remove="Svg\invert-mode-svgrepo-com.svg" />
@@ -195,6 +196,7 @@
195196
<None Remove="Svg\redo.svg" />
196197
<None Remove="Svg\scissors-solid.svg" />
197198
<None Remove="Svg\Seal.svg" />
199+
<None Remove="Svg\select.svg" />
198200
<None Remove="Svg\square-minus-solid.svg" />
199201
<None Remove="Svg\square-plus-solid.svg" />
200202
<None Remove="Svg\stop-solid.svg" />
@@ -359,6 +361,8 @@
359361
<AvaloniaResource Include="Svg\circle-question-solid.svg" />
360362
<AvaloniaResource Include="Svg\Documents\file-zxramdisk.svg" />
361363
<AvaloniaResource Include="Svg\github.svg" />
364+
<AvaloniaResource Include="Svg\hide.svg" />
365+
<AvaloniaResource Include="Svg\select.svg" />
362366
<AvaloniaResource Include="Svg\White\book.svg" />
363367
<AvaloniaResource Include="Svg\White\chat.svg" />
364368
<AvaloniaResource Include="Svg\White\discord.svg" />

0 commit comments

Comments
 (0)