Skip to content

Commit 6e0bf0d

Browse files
committed
Sprite editor:
- Added 8x8 red grid lines in sprite editor. - Removed NextMode from sprite editor, must be with an independent editor. - Solved bug while changing sprite's graphic mode
1 parent b517c65 commit 6e0bf0d

7 files changed

Lines changed: 82 additions & 181 deletions

File tree

ZXBStudio/DocumentEditors/ZXGraphics/ColorPickerControl.axaml.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ public bool Inicialize(GraphicsModes graphicMode, PaletteColor[] palette, int se
5353
DrawZXSpectrum();
5454
grdZXSpectrum.IsVisible = true;
5555
break;
56-
case GraphicsModes.Next:
57-
grdNext.IsVisible = true;
58-
break;
59-
6056
}
6157

6258
return true;

ZXBStudio/DocumentEditors/ZXGraphics/ColorPickerDialog.axaml.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ private void DrawPalette(Canvas cnv)
6969
rows = 2;
7070
cols = 8;
7171
break;
72-
case GraphicsModes.Next:
73-
rows = 16;
74-
cols = 16;
75-
break;
7672
}
7773

7874
int cellW = (int)(((this.Width - 200) / 2) / cols);

ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,6 @@ private void SpriteProperties_Command(SpritePropertiesControl sender, string com
514514
UpdateColorPanel();
515515
break;
516516
case "CHANGEMODE":
517-
ctrlEditor.SpriteData = sender.SpriteData;
518-
SpriteList_Modified(sender.SpriteData);
519517
switch (sender.SpriteData.GraphicMode)
520518
{
521519
case GraphicsModes.Monochrome:
@@ -526,11 +524,9 @@ private void SpriteProperties_Command(SpritePropertiesControl sender, string com
526524
ctrlEditor.PrimaryColorIndex = 0;
527525
ctrlEditor.SecondaryColorIndex = 7;
528526
break;
529-
case GraphicsModes.Next:
530-
ctrlEditor.PrimaryColorIndex = 255;
531-
ctrlEditor.SecondaryColorIndex = 0;
532-
break;
533527
}
528+
ctrlEditor.SpriteData = sender.SpriteData;
529+
SpriteList_Modified(sender.SpriteData);
534530
UpdateColorPanel();
535531
break;
536532
}

ZXBStudio/DocumentEditors/ZXGraphics/SpritePatternEditor.axaml.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,6 @@ private void SetPoint(double mx, double my, int value)
323323
SetAttribute(sprite, x, y);
324324
}
325325
break;
326-
case GraphicsModes.Next:
327-
sprite.RawData[dir] = value;
328-
break;
329326
}
330327

331328
Refresh(false);

ZXBStudio/DocumentEditors/ZXGraphics/SpritePropertiesControl.axaml.cs

Lines changed: 47 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ public bool IsSelected
7070
private bool newSprite = true;
7171
private Sprite _SpriteData = null;
7272

73-
private byte[] ZX2NextColors = new byte[] { 0, 2, 160, 162, 20, 22, 180, 227, 0, 3, 224, 226, 28, 31, 252, 255 };
74-
7573
#endregion
7674

7775

@@ -292,185 +290,75 @@ private void CmbMode_SelectionChanged(object? sender, SelectionChangedEventArgs
292290

293291
private void ChangeMode(GraphicsModes oldMode, GraphicsModes newMode)
294292
{
295-
// TODO: Improve conversion...
296293
if (oldMode == newMode)
297294
{
298295
return;
299296
}
300297
if (oldMode == GraphicsModes.Monochrome)
301298
{
302-
switch (newMode)
299+
foreach (var frame in SpriteData.Patterns)
303300
{
304-
case GraphicsModes.ZXSpectrum:
301+
if (frame.Attributes == null)
302+
{
303+
int cW = SpriteData.Width / 8;
304+
int cH = SpriteData.Height / 8;
305+
frame.Attributes = new AttributeColor[cW * cH];
306+
}
307+
308+
for (int n = 0; n < frame.Attributes.Length; n++)
309+
{
310+
frame.Attributes[n] = new AttributeColor()
305311
{
306-
foreach (var frame in SpriteData.Patterns)
307-
{
308-
if (frame.Attributes == null)
309-
{
310-
int cW = SpriteData.Width / 8;
311-
int cH = SpriteData.Height / 8;
312-
frame.Attributes = new AttributeColor[cW * cH];
313-
for (int n = 0; n < frame.Attributes.Length; n++)
314-
{
315-
frame.Attributes[n] = new AttributeColor()
316-
{
317-
Ink = 0,
318-
Paper = 7
319-
};
320-
}
321-
}
322-
/*
323-
for (int n = 0; n < frame.RawData.Length; n++)
324-
{
325-
var o = frame.RawData[n];
326-
if (o == 0)
327-
{
328-
frame.RawData[n] = 1;
329-
}
330-
else
331-
{
332-
frame.RawData[n] = 0;
333-
}
334-
}
335-
*/
336-
}
312+
Ink = 0,
313+
Paper = 7
314+
};
315+
}
316+
317+
for (int n = 0; n < frame.RawData.Length; n++)
318+
{
319+
var o = frame.RawData[n];
320+
if (o == 0)
321+
{
322+
frame.RawData[n] = 0;
337323
}
338-
break;
339-
case GraphicsModes.Next:
324+
else
340325
{
341-
foreach (var frame in SpriteData.Patterns)
342-
{
343-
for (int n = 0; n < frame.RawData.Length; n++)
344-
{
345-
var o = frame.RawData[n];
346-
if (o == 0)
347-
{
348-
frame.RawData[n] = 227;
349-
}
350-
else
351-
{
352-
frame.RawData[n] = 0;
353-
}
354-
}
355-
}
326+
frame.RawData[n] = 7;
356327
}
357-
break;
328+
}
329+
358330
}
359331
}
360-
else if (oldMode == GraphicsModes.ZXSpectrum)
332+
else
361333
{
362-
switch (newMode)
334+
foreach (var frame in SpriteData.Patterns)
363335
{
364-
case GraphicsModes.Monochrome:
365-
{
366-
foreach (var frame in SpriteData.Patterns)
367-
{
368-
if (frame.Attributes == null)
369-
{
370-
int cW = SpriteData.Width / 8;
371-
int cH = SpriteData.Height / 8;
372-
frame.Attributes = new AttributeColor[cW * cH];
373-
for (int n = 0; n < frame.Attributes.Length; n++)
374-
{
375-
frame.Attributes[n] = new AttributeColor()
376-
{
377-
Ink = 0,
378-
Paper = 7
379-
};
380-
}
381-
}
382-
for (int n = 0; n < frame.RawData.Length; n++)
383-
{
384-
var o = frame.RawData[n];
385-
if (o == 0)
386-
{
387-
frame.RawData[n] = 1;
388-
}
389-
else
390-
{
391-
frame.RawData[n] = 0;
392-
}
393-
}
394-
}
395-
}
396-
break;
397-
case GraphicsModes.Next:
336+
if (frame.Attributes == null)
337+
{
338+
int cW = SpriteData.Width / 8;
339+
int cH = SpriteData.Height / 8;
340+
frame.Attributes = new AttributeColor[cW * cH];
341+
}
342+
for (int n = 0; n < frame.Attributes.Length; n++)
398343
{
399-
foreach (var frame in SpriteData.Patterns)
344+
frame.Attributes[n] = new AttributeColor()
400345
{
401-
for (int n = 0; n < frame.RawData.Length; n++)
402-
{
403-
var o = frame.RawData[n];
404-
if (o == 0)
405-
{
406-
frame.RawData[n] = 227;
407-
}
408-
else
409-
{
410-
frame.RawData[n] = 0;
411-
}
412-
}
413-
}
346+
Ink = 0,
347+
Paper = 7
348+
};
414349
}
415-
break;
416-
}
417-
}
418-
else if (oldMode == GraphicsModes.Next)
419-
{
420-
switch (newMode)
421-
{
422-
case GraphicsModes.Monochrome:
350+
for (int n = 0; n < frame.RawData.Length; n++)
351+
{
352+
var o = frame.RawData[n];
353+
if (o == 0)
423354
{
424-
foreach (var frame in SpriteData.Patterns)
425-
{
426-
for (int n = 0; n < frame.RawData.Length; n++)
427-
{
428-
var o = frame.RawData[n];
429-
if (o == 0)
430-
{
431-
frame.RawData[n] = 1;
432-
}
433-
else
434-
{
435-
frame.RawData[n] = 0;
436-
}
437-
}
438-
}
355+
frame.RawData[n] = 0;
439356
}
440-
break;
441-
case GraphicsModes.ZXSpectrum:
357+
else
442358
{
443-
foreach (var frame in SpriteData.Patterns)
444-
{
445-
if (frame.Attributes == null)
446-
{
447-
int cW = SpriteData.Width / 8;
448-
int cH = SpriteData.Height / 8;
449-
frame.Attributes = new AttributeColor[cW * cH];
450-
for (int n = 0; n < frame.Attributes.Length; n++)
451-
{
452-
frame.Attributes[n] = new AttributeColor()
453-
{
454-
Ink = 0,
455-
Paper = 7
456-
};
457-
}
458-
}
459-
for (int n = 0; n < frame.RawData.Length; n++)
460-
{
461-
var o = frame.RawData[n];
462-
if (o == 0)
463-
{
464-
frame.RawData[n] = 0;
465-
}
466-
else
467-
{
468-
frame.RawData[n] = 1;
469-
}
470-
}
471-
}
359+
frame.RawData[n] = 1;
472360
}
473-
break;
361+
}
474362
}
475363
}
476364
}

ZXBStudio/DocumentEditors/ZXGraphics/ZXGridImageView.axaml.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public partial class ZXGridImageView : UserControl
1717
private WriteableBitmap? gridImage;
1818
private IZXBitmap? backgroundImage;
1919
private SKColor gridColor = new SKColor(0x00, 0x00, 0x00, 0xFF);
20+
private SKColor grid8x8Color = new SKColor(0xFF, 0x00, 0x00, 0xFF);
21+
2022
private int zoom = 4;
23+
2124
public int Zoom
2225
{
2326
get => zoom;
@@ -34,6 +37,7 @@ public int Zoom
3437
InvalidateVisual();
3538
}
3639
}
40+
3741
public SKColor GridColor
3842
{
3943
get => gridColor;
@@ -61,6 +65,8 @@ public IZXBitmap? BackgroundImage
6165
}
6266
}
6367

68+
public bool Show8x8Grid { get; set; } = true;
69+
6470
public ZXGridImageView()
6571
{
6672
InitializeComponent();
@@ -98,14 +104,33 @@ private void EnsureGrid()
98104
canvas.Clear(new SKColor(0xFF, 0xFF, 0xFF, 0x00));
99105

100106
using var paint = new SKPaint { Color = gridColor, StrokeWidth = 1, IsAntialias = false };
107+
using var paintGrid = new SKPaint { Color = grid8x8Color, StrokeWidth = 1, IsAntialias = false };
101108

102109
//Draw vertical lines
103110
for (int x = 0; x < gridImage.PixelSize.Width + 1; x += Zoom + 1)
104-
canvas.DrawLine(new SKPoint(x, 0), new SKPoint(x, gridImage.PixelSize.Height), paint);
111+
{
112+
if ((x % 8) == 0)
113+
{
114+
canvas.DrawLine(new SKPoint(x, 0), new SKPoint(x, gridImage.PixelSize.Height), paintGrid);
115+
}
116+
else
117+
{
118+
canvas.DrawLine(new SKPoint(x, 0), new SKPoint(x, gridImage.PixelSize.Height), paint);
119+
}
120+
}
105121

106122
//Draw horizontal lines
107123
for (int y = 0; y < gridImage.PixelSize.Height + 1; y += Zoom + 1)
108-
canvas.DrawLine(new SKPoint(0, y), new SKPoint(gridImage.PixelSize.Width, y), paint);
124+
{
125+
if ((y % 8) == 0)
126+
{
127+
canvas.DrawLine(new SKPoint(0, y), new SKPoint(gridImage.PixelSize.Width, y), paintGrid);
128+
}
129+
else
130+
{
131+
canvas.DrawLine(new SKPoint(0, y), new SKPoint(gridImage.PixelSize.Width, y), paint);
132+
}
133+
}
109134

110135
}
111136

@@ -121,7 +146,7 @@ public override void Render(DrawingContext context)
121146

122147
context.DrawImage(backgroundImage, new Rect(0, 0, gridImage.Size.Width, gridImage.Size.Height));
123148

124-
if(zoom > 4)
149+
if (zoom > 4)
125150
context.DrawImage(gridImage, new Rect(0, 0, gridImage.Size.Width, gridImage.Size.Height));
126151
}
127152

@@ -133,7 +158,7 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
133158

134159
protected override void OnPointerMoved(PointerEventArgs e)
135160
{
136-
base.OnPointerMoved(e);
161+
base.OnPointerMoved(e);
137162
Debug.WriteLine($"OnPointerMoved: {this.Width}/{this.Height} : {e.GetPosition(this)}");
138163
}
139164
}

ZXBStudio/DocumentEditors/ZXGraphics/ZXSpriteImage.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ public unsafe void RenderSprite(Sprite Sprite, int FrameNumber)
9595
}
9696
break;
9797
case GraphicsModes.Monochrome:
98-
case GraphicsModes.Next:
98+
if (colorIndex > Sprite.Palette.Length - 1)
99+
{
100+
colorIndex = Sprite.Palette.Length - 1;
101+
}
99102
color = Sprite.Palette[colorIndex];
100103
break;
101104
default:

0 commit comments

Comments
 (0)