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

Commit

Permalink
Fixes for #327, #313, #312, #311, #304, #275, #292, and #285
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Jun 26, 2020
1 parent 512ef5d commit 61993a3
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 8 deletions.
63 changes: 56 additions & 7 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-canvas-v3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function PixelVisionOS:CreateCanvas(rect, size, scale, colorOffset, toolTip, emp

-- Create a selection canvas
data.selectionCanvas = NewCanvas(data.rect.w, data.rect.h)
data.selectionCanvas.wrap = false

print("Wrap", data.selectionCanvas.wrap)

data.selectionCanvas:SetStroke({0}, 1, 1)

local spriteData = _G["pixelselection1x"]
Expand All @@ -48,7 +52,6 @@ function PixelVisionOS:CreateCanvas(rect, size, scale, colorOffset, toolTip, emp

data.onClick = function(tmpData)


self:CanvasRelease(tmpData, true)

end
Expand Down Expand Up @@ -149,6 +152,8 @@ function PixelVisionOS:UpdateCanvas(data, hitRect)
return
end



-- If the button has data but it's not enabled exit out of the update
if(data.enabled == false) then

Expand Down Expand Up @@ -277,7 +282,11 @@ function PixelVisionOS:UpdateCanvas(data, hitRect)
data.brushDrawArgs[2] = (position.y * data.gridSize) + data.rect.y - data.borderOffset
-- Draw over rect
-- editorUI:NewDraw("DrawSprites", data.overDrawArgs)
editorUI:NewDraw("DrawRect", data.brushDrawArgs)

if(data.tool ~= "eyedropper") then
editorUI:NewDraw("DrawRect", data.brushDrawArgs)
end

end

-- end
Expand Down Expand Up @@ -324,8 +333,6 @@ function PixelVisionOS:UpdateCanvas(data, hitRect)
-- If we are not in the button's rect, clear the focus
editorUI:ClearFocus(data)



end

end
Expand Down Expand Up @@ -362,6 +369,14 @@ function PixelVisionOS:UpdateCanvas(data, hitRect)

end

-- Trigger click if released out of bounds to save drawing
if(editorUI.collisionManager.mouseReleased == true and data.mouseState == "dragging") then
-- Click the button
data.onClick(data)
data.firstPress = true

end

-- Make sure we don't need to redraw the button.
self:RedrawCanvas(data)

Expand Down Expand Up @@ -541,9 +556,9 @@ function PixelVisionOS:DrawOnCanvas(data, mousePos, toolID)
-- TODO this doesn't appear to do anything
data.overColor = data.paintCanvas:ReadPixelAt(mousePos.x, mousePos.y) - data.colorOffset

elseif(data.tool == "select") then
-- elseif(data.tool == "select") then

-- print("select", data.startPos.x, data.startPos.y)
-- -- print("select", data.startPos.x, data.startPos.y)

end

Expand All @@ -567,6 +582,13 @@ function PixelVisionOS:CutPixels(data)

selection.pixelData = data.paintCanvas:GetPixels(selection.size.X, selection.size.Y, selection.size.Width, selection.size.Height)

-- Convert the mask colors to the tool's mask color
for i = 1, #selection.pixelData do
if(selection.pixelData[i] == 255) then
selection.pixelData[i] = -1
end
end

-- Change the stroke to a single pixel of white
data.tmpPaintCanvas:SetStroke({data.emptyColorID}, 1, 1)

Expand Down Expand Up @@ -606,7 +628,7 @@ function PixelVisionOS:CancelCanvasSelection(data, mergeSelection, action)
data.paintCanvas:SetPixels(data.selectRect.Left, data.selectRect.Top, data.selectedPixelData.size.Width, data.selectedPixelData.size.Height, data.selectedPixelData.pixelData)
data.paintCanvas:Invalidate()
end

data.selectedPixelData = nil
data.selectionState = "none"
data.selectRect = nil
Expand Down Expand Up @@ -728,6 +750,8 @@ function PixelVisionOS:CanvasRelease(data, callAction)

data.mouseState = data.mouseState == "released" and "up" or "released"


print("Released")
-- Return if the selection rect is nil
-- if(data.selectRect ~= nil) then
-- return
Expand All @@ -744,6 +768,8 @@ function PixelVisionOS:CanvasRelease(data, callAction)
-- Normally clearing the canvas invalidates it but se want to reset it until its drawn in again
data.tmpPaintCanvas:ResetValidation()

print("Merged tmp canvas")

end

-- if(data.selectedPixelData ~= nil) then
Expand Down Expand Up @@ -771,6 +797,24 @@ function PixelVisionOS:CanvasRelease(data, callAction)

end

local oldPixelData = nil

if(data.selectedPixelData ~= nil) then

oldPixelData = data.paintCanvas:GetPixels()

-- data.paintCanvas:MergeCanvas(data.selectionCanvas, 0, true)

print("Pixels", dump(data.selectedPixelData.pixelData))

--TODO need to test for a special key down and toggle ignoring transparency
data.ignoreMaskColor = true

data.paintCanvas:SetPixels(data.selectRect.Left, data.selectRect.Top, data.selectedPixelData.size.Width, data.selectedPixelData.size.Height, data.selectedPixelData.pixelData)


end

-- trigger the canvas action callback
if(data.onAction ~= nil and callAction ~= false) then

Expand All @@ -779,6 +823,11 @@ function PixelVisionOS:CanvasRelease(data, callAction)

end

if(oldPixelData ~= nil) then
data.paintCanvas:SetPixels(oldPixelData)
data.paintCanvas:Invalidate()
end

end

function PixelVisionOS:CanvasPress(data, callAction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function DrawTool:OnSystemColorDropTarget(src, dest)
local realDestID = destPos.index + dest.altColorOffset

-- Make sure the colors are not the same
if(realSrcID ~= realDestID) then
if(realSrcID ~= realDestID and destPos.index < pixelVisionOS.totalSystemColors) then



Expand Down
68 changes: 68 additions & 0 deletions SDK/Engine/Data/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using PixelVision8.Engine.Chips;
using PixelVision8.Engine.Utils;
Expand Down Expand Up @@ -681,5 +682,72 @@ public int[] SamplePixels(int x, int y, int width, int height)

return pixelData;
}

public override void SetPixels(int x, int y, int blockWidth, int blockHeight, int[] pixels)
{

if (wrap == false)
{

BlockSave(pixels, blockWidth, blockHeight, this.pixels, x, y, width, height);
return;
}

base.SetPixels(x, y, blockWidth, blockHeight, pixels);
}

void BlockSave(int[] src, int srcW, int srcH, int[] dest, int destX, int destY, int destW, int destH)
{

var srcX = 0;
var srcY = 0;
var srcLength = srcW;

// Adjust X
if (destX < 0)
{
srcX = -destX;

srcW -= srcX;

// destW += destX;
destX = 0;
}

if (destX + srcW > destW)
srcW -= ((destX + srcW) - destW);

if (srcW <= 0) return;

// Adjust Y
if (destY < 0)
{
srcY = -destY;

srcH -= srcY;

// destW += destX;
destY = 0;
}

if (destY + srcH > destH)
srcH -= ((destY + srcH) - destH);

if (srcH <= 0) return;

var row = 0;
var startCol = 0;
var endCol = 0;
var destCol = 0;

for (row = 0; row < srcH; row++)
{
startCol = srcX + (row + srcY) * srcLength;
destCol = destX + (row + destY) * destW;

Array.Copy(src, startCol, dest, destCol, srcW);
}

}
}
}

0 comments on commit 61993a3

Please sign in to comment.