X Tutup
Skip to content
This repository was archived by the owner on Jan 4, 2023. It is now read-only.

Commit 754151d

Browse files
committed
Cleaning up background render modes in Paint Tool.
1 parent f36f38d commit 754151d

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

Disks/PixelVisionOS/System/Tools/PaintTool/Src/canvas-panel.lua

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ function PaintTool:CreateCanvasPanel()
2222
self.snapToGrid = true
2323
self.mousePos = NewPoint()
2424

25+
self.maskId = -1
26+
2527
-- self.scale = 1
2628
self.scaledViewport = NewRect()
2729
self.scaleValues = {.5, 1, 2, 4, 8}--, 8}
@@ -602,7 +604,7 @@ function PaintTool:DrawCanvasPanel()
602604
end
603605

604606
-- Redraw the background of the canvas
605-
if(self.backgroundMode ~= 1) then
607+
if(self.maskId > -1) then
606608
self.backgroundLayerCanvas:DrawPixels(self.viewportRect.X, self.viewportRect.Y, DrawMode.TilemapCache, self.scale, 0, 0, self.scaledViewport)
607609
end
608610

@@ -615,20 +617,17 @@ function PaintTool:DrawCanvasPanel()
615617

616618
end
617619

618-
-- TODO need to tie this into the mask color selection (which is not implemented yet so default to 0)
619-
local tmpMaskId = 0
620-
621620
-- Draw the pixel data in the upper left hand corner of the tool's window
622-
self.imageLayerCanvas:DrawPixels(self.viewportRect.X, self.viewportRect.Y, DrawMode.TilemapCache, self.scale, self.colorOffset, tmpMaskId, self.scaledViewport)
621+
self.imageLayerCanvas:DrawPixels(self.viewportRect.X, self.viewportRect.Y, DrawMode.TilemapCache, self.scale, self.colorOffset, self.maskId, self.scaledViewport)
623622

624623
-- Only draw the flag layer when we need to
625624
if(self.pickerMode == FlagMode) then
626-
self.flagLayerCanvas:DrawPixels(self.viewportRect.X, self.viewportRect.Y, DrawMode.TilemapCache, self.scale, self.colorOffset, tmpMaskId, self.scaledViewport)
625+
self.flagLayerCanvas:DrawPixels(self.viewportRect.X, self.viewportRect.Y, DrawMode.TilemapCache, self.scale, self.colorOffset, self.maskId, self.scaledViewport)
627626
end
628627

629628
-- Only draw the temp layer when we need to
630629
if(self.drawTmpLayer == true) then
631-
self.tmpLayerCanvas:DrawPixels(self.viewportRect.X, self.viewportRect.Y, DrawMode.TilemapCache, self.scale, self.colorOffset, tmpMaskId, self.scaledViewport)
630+
self.tmpLayerCanvas:DrawPixels(self.viewportRect.X, self.viewportRect.Y, DrawMode.TilemapCache, self.scale, self.colorOffset, self.maskId, self.scaledViewport)
632631
end
633632

634633
-- if(self.showGrid == true) then
@@ -1296,30 +1295,30 @@ end
12961295

12971296
function PaintTool:InvalidateBackground()
12981297

1299-
-- Mode 1 will render the transparent canvas texture for the background
1300-
-- if(self.backgroundMode == 1) then
1298+
-- Mode 1 shows all the colors, no masking
1299+
if(self.backgroundMode == 1) then
13011300

13021301
-- print("Sprite", dump(Sprite(MetaSprite("emptymaskcolor").Sprites[1].Id)))
1303-
1304-
13051302

1303+
self.maskId = -1
13061304

1307-
-- Mode 2 will render the background color
1308-
-- else
1309-
if(self.backgroundMode == 2) then
1305+
-- Mode 2 uses the mask and transparent background
1306+
elseif(self.backgroundMode == 2) then
13101307

1311-
self.backgroundLayerCanvas:fill(self.backgroundColorId + self.colorOffset)
1308+
self.maskId = 0 -- TODO this needs to be provided by the selected mask color
13121309

1310+
self.backgroundLayerCanvas:DrawRectangle(0, 0, self.backgroundLayerCanvas.Width, self.backgroundLayerCanvas.Height, true)
1311+
1312+
-- Mode 3 shows the background color
13131313
else
13141314

1315-
-- Use the mask color as the default background
1316-
-- self.backgroundLayerCanvas:fill(self.colorOffset)
1315+
self.maskId = 0 -- TODO this needs to be provided by the selected mask color
13171316

1318-
self.backgroundLayerCanvas:DrawRectangle(0, 0, self.backgroundLayerCanvas.Width, self.backgroundLayerCanvas.Height, true)
1317+
self.backgroundLayerCanvas:fill(self.backgroundColorId + self.colorOffset)
13191318

13201319
end
13211320

1322-
-- Invalidate the canvas to force it to redraw
1321+
13231322
self:InvalidateCanvas()
13241323

13251324
end

SDK/Player/Chips/Game/GameChip.Draw.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void DrawRect(int x, int y, int width, int height, int colorOffset = 0,
206206
// }
207207

208208
// TODO is there a faster way to do this?
209-
DrawPixels(pixels, x, y, width, height, false, false, drawMode, Constants.FirstColorId + colorOffset); // This is always set to ignore transparency?
209+
DrawPixels(pixels, x, y, width, height, false, false, drawMode, Constants.FirstColorId + colorOffset, -1); // This is always set to ignore transparency?
210210
}
211211

212212

SDK/Player/Chips/Game/GameChip.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ public int BackgroundColor(int? colorOffset = null)
137137
return _bgColorOffset;
138138
}
139139

140-
private string _maskColor = Constants.MaskColor;
141-
142140
public string MaskColor(string value = "")
143141
{
144142
if(value != "")

SDK/Player/Constants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace PixelVision8.Player
22
{
33
public static class Constants
44
{
5+
56
// The default size of sprites 8x8
67
public const int SpriteSize = 8;
78

@@ -12,7 +13,7 @@ public static class Constants
1213
public const int FirstColorId = EmptyPixel + 1;
1314

1415
// The default mask color
15-
public const string MaskColor = "#FF00FF"; // TODO need to remove the dependency on this so it can go back to #FF00FF
16+
public const string MaskColor = "#FF00FF";
1617

1718
// List of default Pixel Vision 8 colors
1819
public const string DefaultColors =

SDK/Player/Utils/Utilities.PixelData.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,17 @@ public static void MergePixels<T>(
175175

176176
tmpPixel = src.Pixels[tmpX + srcPWidth * tmpY];
177177

178-
if (tmpPixel != maskId)
178+
if (maskId == -1 || tmpPixel != maskId)
179179
{
180180
tmpX = (flipH ? srcWidth - 1 - col : col) + destX;
181181

182182
tmpY = (flipV ? srcWidth - 1 - row : row) + destY;
183183

184184
if (tmpX >= 0 && tmpX < destPWidth && tmpY >= 0 && tmpY < destPHeight)
185185
{
186+
var tmp = tmpPixel + colorOffset;
186187
// TODO need to figure out how to fix this
187-
dest.Pixels[tmpX + destPWidth * tmpY] = tmpPixel + colorOffset;
188+
dest.Pixels[tmpX + destPWidth * tmpY] = tmp;
188189
}
189190
}
190191

0 commit comments

Comments
 (0)
X Tutup