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

Commit

Permalink
Fixing fill and adding select all.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Apr 20, 2021
1 parent 4c99572 commit 7c9a4cc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 20 deletions.
80 changes: 60 additions & 20 deletions Disks/PixelVisionOS/System/Tools/PaintTool/code-canvas-panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,13 @@ function PaintTool:UpdateCanvasPanel(timeDelta)
self:InvalidateBrushPreview()

end


elseif(Key(Keys.Escape, InputState.Released)) then

if(self.selectRect ~= nil) then
self:CancelCanvasSelection()
end

elseif(Key(Keys.Delete) or Key(Keys.Back)) then

if(self.selectRect ~= nil) then
Expand Down Expand Up @@ -474,15 +480,18 @@ function PaintTool:DrawCanvasPanel()
-- Check if we need to fill the area below the selection
if(self.fillRect == true) then

for i = 1, #self.selectedPixelData do
self.selectedPixelData[i] = self.fillRectColor
end
-- We fill the are first because there is no need to clear
self.imageLayerCanvas:Clear(self.fillRectColor, self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height)
-- self.imageLayerCanvas:Clear(self.fillRectColor, self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height)

self.fillRect = false

-- Clear the selected pixels since we just filled the area
self.selectedPixelData = nil
-- self.selectedPixelData = nil

self:CancelCanvasSelection()
-- self:CancelCanvasSelection()

end

Expand All @@ -491,19 +500,25 @@ function PaintTool:DrawCanvasPanel()
-- Check to see if the state has been set to canceled
if(self.selectionState == "canceled") then

-- Check to see if the selection is ignoring transparency
if(self.selectionUsesMaskColor == true) then

self.imageLayerCanvas:Clear(-1, self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height)

end

print("COpy Pixels!!!")
-- Draw pixel data to the image
self.imageLayerCanvas:MergePixels(self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height, self.selectedPixelData)

-- Clear the pixel data
self.selectedPixelData = nil
if(self.selectedPixelData ~= nil) then

-- Check to see if the selection is ignoring transparency
if(self.selectionUsesMaskColor == true) then

self.imageLayerCanvas:Clear(-1, self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height)

end

-- Draw pixel data to the image
self.imageLayerCanvas:MergePixels(self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height, self.selectedPixelData)

-- Clear the pixel data
self.selectedPixelData = nil

end


-- Clear the selection state
self.selectionState = "none"
Expand All @@ -516,7 +531,7 @@ function PaintTool:DrawCanvasPanel()

-- Force the display to clear the tmp layer canvas
self.tmpLayerCanvas:Clear()
print("Clear Tmp Layer - Cancel selection")
-- print("Clear Tmp Layer - Cancel selection")


-- Invalidate the canvas and the selection
Expand Down Expand Up @@ -549,14 +564,14 @@ function PaintTool:DrawCanvasPanel()

-- Clear the tmp layer
self.tmpLayerCanvas:Clear()
print("Clear Tmp Layer - Redraw selection")
-- print("Clear Tmp Layer - Redraw selection")
if(self.selectedPixelData ~= nil) then

-- Check to see if the selection is ignoring transparency
if(self.selectionUsesMaskColor == true) then

self.tmpLayerCanvas:Clear(self.maskColor, self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height)
print("Clear Tmp Layer - Redraw Selection mask")
-- print("Clear Tmp Layer - Redraw Selection mask")
end

self.tmpLayerCanvas:MergePixels(self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height, self.selectedPixelData)
Expand Down Expand Up @@ -620,6 +635,12 @@ function PaintTool:DrawCanvasPanel()

end

function PaintTool:ClearTmpLayer()

-- TODO need to rout all draw calls through APIs to make sure they are correctly invalidating and not being called multiple times in a single frame

end


function PaintTool:OnNextZoom(reverse)

Expand Down Expand Up @@ -805,6 +826,8 @@ function PaintTool:CancelCanvasSelection()
-- Clear the selection state
self.selectionState = "canceled"

self:InvalidateUndo()

-- Invalidate the display so it redraws on the next frame
self:InvalidateCanvas()

Expand All @@ -815,6 +838,23 @@ function PaintTool:CancelCanvasSelection()

end

function PaintTool:SelectAll()
print("Select All")

self:OnSelectTool("select")

self:InvalidateUndo()

self.selectionState = "resize"

self.selectRect = NewRect( 0, 0, self.imageLayerCanvas.Width, self.imageLayerCanvas.Height )

self.selectedPixelData = nil

self.onClick()

end

-- Use this to perform a click action on a button. It's used internally when a mouse click is detected.
function PaintTool:CanvasRelease(callAction)

Expand Down Expand Up @@ -1078,7 +1118,7 @@ function PaintTool:DrawOnCanvas(mousePos)

if(self.selectionState == "new" or self.selectionState == "resize") then

self.selectionState = "resize"
self.selectionState = "resize"

-- print("resize", data.selectRect, mousePos, , )

Expand Down Expand Up @@ -1175,7 +1215,7 @@ function PaintTool:FillCanvasSelection(colorID)
self.fillRect = true
self.fillRectColor = colorID or self.brushColor

self:InvalidateCanvas()
-- self:InvalidateCanvas()

end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function PaintTool:CreateDropDownMenu()
{name = "Fill", action = function() self:FillCanvasSelection() end, key = Keys.F, enabled = false, toolTip = "Learn about PV8."},
{name = "Flip H", action = function() self:FlipH() end, key = Keys.H, enabled = false, toolTip = "Learn about PV8."},
{name = "Flip V", action = function() self:FlipV() end, key = Keys.J, enabled = false, toolTip = "Learn about PV8."},
{name = "Select All", action = function() self:SelectAll() end, key = Keys.A, enabled = true, toolTip = "Learn about PV8."},

-- {divider = true},
-- {name = "Line Thicker", action = function() end, toolTip = "Learn about PV8."},
Expand Down Expand Up @@ -356,6 +357,7 @@ end

function PaintTool:InvalidateUndo(canvas, selection)

-- TODO need to optimize this by using the canvas and selection flags
self.canvasInvalid = canvas or true
self.selectionInvalid = selection or true

Expand Down

0 comments on commit 7c9a4cc

Please sign in to comment.