Skip to content

Commit 63d9936

Browse files
authored
Implement animated canvas preview (#550)
1 parent e2b91f2 commit 63d9936

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1883
-362
lines changed

src/SerialLoops.Lib/Items/BackgroundItem.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public SKBitmap GetBackground()
5454
else if (BackgroundType == BgType.TEX_CG_DUAL_SCREEN)
5555
{
5656
SKBitmap bitmap = new(Graphic1.Width, Graphic1.Height + Graphic2.Height);
57-
SKCanvas canvas = new(bitmap);
57+
using SKCanvas canvas = new(bitmap);
5858

5959
SKBitmap tileBitmap = new(Graphic2.Width, Graphic2.Height);
6060
SKBitmap tiles = Graphic2.GetImage(width: 64);
61-
SKCanvas tileCanvas = new(tileBitmap);
61+
using SKCanvas tileCanvas = new(tileBitmap);
6262
int currentTile = 0;
6363
for (int y = 0; y < tileBitmap.Height; y += 64)
6464
{
@@ -85,7 +85,7 @@ public SKBitmap GetBackground()
8585
else
8686
{
8787
SKBitmap bitmap = new(Graphic1.Width, Graphic1.Height + Graphic2.Height);
88-
SKCanvas canvas = new(bitmap);
88+
using SKCanvas canvas = new(bitmap);
8989

9090
canvas.DrawBitmap(Graphic1.GetImage(), new SKPoint(0, 0));
9191
canvas.DrawBitmap(Graphic2.GetImage(), new SKPoint(0, Graphic1.Height));
@@ -124,22 +124,23 @@ public bool SetBackground(SKBitmap image, IProgressTracker tracker, ILogger log,
124124
break;
125125

126126
case BgType.TEX_CG_DUAL_SCREEN:
127+
{
127128
SKBitmap newTextureBitmap = new(Graphic1.Width, Graphic1.Height);
128129
SKBitmap newTileBitmap = new(64, Graphic2.Height * Graphic2.Width / 64);
129130
SKBitmap tileSource = new(image.Width, image.Height - Graphic1.Height);
130131

131132
tracker.Focus(localize("Drawing bottom screen texture..."), 1);
132-
SKCanvas textureCanvas = new(newTextureBitmap);
133+
using SKCanvas textureCanvas = new(newTextureBitmap);
133134
textureCanvas.DrawBitmap(image, new(0, image.Height - newTextureBitmap.Height, newTextureBitmap.Width, image.Height), new SKRect(0, 0, newTextureBitmap.Width, newTextureBitmap.Height));
134135
textureCanvas.Flush();
135136
tracker.Finished++;
136137

137-
SKCanvas tileSourceCanvas = new(tileSource);
138+
using SKCanvas tileSourceCanvas = new(tileSource);
138139
tileSourceCanvas.DrawBitmap(image, 0, 0);
139140
tileSourceCanvas.Flush();
140141

141142
tracker.Focus(localize("Drawing top screen tiles..."), newTileBitmap.Height / 64 * newTileBitmap.Width / 64);
142-
SKCanvas tileCanvas = new(newTileBitmap);
143+
using SKCanvas tileCanvas = new(newTileBitmap);
143144
int currentTile = 0;
144145
for (int y = 0; y < tileSource.Height; y += 64)
145146
{
@@ -170,19 +171,24 @@ public bool SetBackground(SKBitmap image, IProgressTracker tracker, ILogger log,
170171
Graphic2.SetImage(newTileBitmap);
171172
tracker.Finished++;
172173
break;
174+
}
173175

174176
default:
177+
{
175178
SKBitmap newGraphic1 = new(Graphic1.Width, Graphic1.Height);
176179
SKBitmap newGraphic2 = new(Graphic2.Width, Graphic2.Height);
177180

178181
tracker.Focus(localize("Drawing textures..."), 2);
179-
SKCanvas canvas1 = new(newGraphic1);
180-
canvas1.DrawBitmap(image, new(0, 0, newGraphic1.Width, newGraphic1.Height), new SKRect(0, 0, newGraphic1.Width, newGraphic1.Height));
182+
using SKCanvas canvas1 = new(newGraphic1);
183+
canvas1.DrawBitmap(image, new(0, 0, newGraphic1.Width, newGraphic1.Height),
184+
new SKRect(0, 0, newGraphic1.Width, newGraphic1.Height));
181185
canvas1.Flush();
182186
tracker.Finished++;
183187

184-
SKCanvas canvas2 = new(newGraphic2);
185-
canvas2.DrawBitmap(image, new(0, newGraphic1.Height, newGraphic2.Width, newGraphic1.Height + newGraphic2.Height), new SKRect(0, 0, newGraphic2.Width, newGraphic2.Height));
188+
using SKCanvas canvas2 = new(newGraphic2);
189+
canvas2.DrawBitmap(image,
190+
new(0, newGraphic1.Height, newGraphic2.Width, newGraphic1.Height + newGraphic2.Height),
191+
new SKRect(0, 0, newGraphic2.Width, newGraphic2.Height));
186192
canvas2.Flush();
187193
tracker.Finished++;
188194

@@ -192,6 +198,7 @@ public bool SetBackground(SKBitmap image, IProgressTracker tracker, ILogger log,
192198
{
193199
texPalette.Insert(0, new(0, 248, 0));
194200
}
201+
195202
tracker.Finished++;
196203
Graphic1.SetPalette(texPalette);
197204
tracker.Finished++;
@@ -202,6 +209,7 @@ public bool SetBackground(SKBitmap image, IProgressTracker tracker, ILogger log,
202209
Graphic2.SetImage(newGraphic2);
203210
tracker.Finished++;
204211
break;
212+
}
205213
}
206214
return true;
207215
}
@@ -230,4 +238,4 @@ public SKBitmap GetPreview(Project project)
230238
{
231239
return GetBackground();
232240
}
233-
}
241+
}

src/SerialLoops.Lib/Items/CharacterItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public SKBitmap GetNewNameplate(SKBitmap blankNameplate, SKBitmap blankNameplate
5252
}
5353

5454
SKBitmap newNameplate = new(64, 16);
55-
SKCanvas newCanvas = new(newNameplate);
55+
using SKCanvas newCanvas = new(newNameplate);
5656
newCanvas.DrawBitmap(blankNameplate, new SKPoint(0, 0));
5757

5858
double widthFactor = 1.0;

src/SerialLoops.Lib/Items/CharacterSpriteItem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void SetSprite(SKBitmap layoutBitmap, List<(SKBitmap Frame, short Time)>
5757
Graphics.MouthAnimation.AnimationX = mouthX;
5858
Graphics.MouthAnimation.AnimationY = mouthY;
5959
}
60-
60+
6161
public SKBitmap GetPreview(Project project)
6262
{
6363
return GetClosedMouthAnimation(project).First().Frame;
@@ -90,7 +90,7 @@ private List<SKColor> SetBaseLayoutAndReturnPalette(SKBitmap layoutBitmap, ILogg
9090
continue;
9191
}
9292

93-
SKCanvas textureCanvas = new(texture);
93+
using SKCanvas textureCanvas = new(texture);
9494

9595
for (short y = 0; y < texture.Height; y += 32)
9696
{
@@ -208,4 +208,4 @@ public void Write(Project project, ILogger log)
208208
IO.WriteBinaryFile(Path.Combine("assets", "graphics", $"{MouthTexture.Index:X3}.png"), mouthTextureStream.ToArray(), project, log);
209209
IO.WriteStringFile(Path.Combine("assets", "graphics", $"{MouthTexture.Index:X3}.gi"), MouthTexture.GetGraphicInfoFile(), project, log);
210210
}
211-
}
211+
}

src/SerialLoops.Lib/Items/ChessPuzzleItem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public ChessPuzzleItem Clone()
2929
public static SKBitmap GetEmptyChessboard(ArchiveFile<GraphicsFile> grp)
3030
{
3131
SKBitmap board = new(256, 192);
32-
SKCanvas canvas = new(board);
32+
using SKCanvas canvas = new(board);
3333
SKBitmap chs1 = grp.GetFileByName("CHS_SYS_01DNX").GetImage(transparentIndex: 0);
3434

3535
canvas.DrawBitmap(chs1, new(0,0,80,80), new SKRect(0,16,80,96));
@@ -44,7 +44,7 @@ public static SKBitmap GetEmptyChessboard(ArchiveFile<GraphicsFile> grp)
4444
public SKBitmap GetChessboard(Project project)
4545
{
4646
SKBitmap board = new(256, 192);
47-
SKCanvas canvas = new(board);
47+
using SKCanvas canvas = new(board);
4848

4949
SKBitmap emptyBoard = GetEmptyChessboard(project.Grp);
5050
canvas.DrawBitmap(emptyBoard, 0, 0);
@@ -61,7 +61,7 @@ public SKBitmap GetChessboard(Project project)
6161
public static SKBitmap GetChessPiece(ChessFile.ChessPiece piece, ArchiveFile<GraphicsFile> grp)
6262
{
6363
SKBitmap pieceBitmap = new(16, 32);
64-
SKCanvas canvas = new(pieceBitmap);
64+
using SKCanvas canvas = new(pieceBitmap);
6565
SKBitmap chs0 = (byte)piece < 0x80
6666
? grp.GetFileByName("CHS_SYS_00DNX").GetImage(transparentIndex: 0)
6767
: grp.GetFileByName("CHS_SYS_00DNX").GetImage(transparentIndex: 16, paletteOffset: 16);

src/SerialLoops.Lib/Items/MapItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public SKBitmap GetMapImage(ArchiveFile<GraphicsFile> grp, bool displayPathingMa
4545
map = Map.GetMapImages(grp, 0, grp.GetFileByIndex(Map.Settings.LayoutFileIndex).LayoutEntries.Count);
4646
}
4747
SKBitmap mapWithGrid = new(map.Width, map.Height);
48-
SKCanvas canvas = new(mapWithGrid);
48+
using SKCanvas canvas = new(mapWithGrid);
4949
canvas.DrawBitmap(map, new SKPoint(0, 0));
5050

5151
SKPoint gridZero = GetOrigin(grp);

src/SerialLoops.Lib/Items/PlaceItem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override void Refresh(Project project, ILogger log)
2626
public static SKBitmap Unscramble(SKBitmap placeGraphic)
2727
{
2828
SKBitmap adjustedPlace = new(placeGraphic.Width, placeGraphic.Height);
29-
SKCanvas canvas = new(adjustedPlace);
29+
using SKCanvas canvas = new(adjustedPlace);
3030

3131
int col = 0, row = 0;
3232
for (int y = 0; y < 4; y++)
@@ -58,7 +58,7 @@ public SKBitmap GetNewPlaceGraphic(SKTypeface msGothicHaruhi)
5858
{
5959
string spaceAdjustedText = PlaceName.Replace(" ", " ");
6060
SKBitmap newPlaceBitmap = new(PlaceGraphic.Width, PlaceGraphic.Height);
61-
SKCanvas canvas = new(newPlaceBitmap);
61+
using SKCanvas canvas = new(newPlaceBitmap);
6262
SKColor bgColor = new(0, 249, 0);
6363
canvas.DrawRegion(new(new SKRectI(0, 0, newPlaceBitmap.Width, newPlaceBitmap.Height)), new() { Color = bgColor });
6464
TextBlock placeText = new()
@@ -134,4 +134,4 @@ public override SKTypeface TypefaceFromStyle(IStyle style, bool ignoreFontVarian
134134
return _fonts[style.FontFamily];
135135
}
136136
}
137-
}
137+
}

0 commit comments

Comments
 (0)