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

Commit 7c9a4cc

Browse files
committed
Fixing fill and adding select all.
1 parent 4c99572 commit 7c9a4cc

File tree

2 files changed

+62
-20
lines changed

2 files changed

+62
-20
lines changed

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

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,13 @@ function PaintTool:UpdateCanvasPanel(timeDelta)
245245
self:InvalidateBrushPreview()
246246

247247
end
248-
248+
249+
elseif(Key(Keys.Escape, InputState.Released)) then
250+
251+
if(self.selectRect ~= nil) then
252+
self:CancelCanvasSelection()
253+
end
254+
249255
elseif(Key(Keys.Delete) or Key(Keys.Back)) then
250256

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

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

480489
self.fillRect = false
481490

482491
-- Clear the selected pixels since we just filled the area
483-
self.selectedPixelData = nil
492+
-- self.selectedPixelData = nil
484493

485-
self:CancelCanvasSelection()
494+
-- self:CancelCanvasSelection()
486495

487496
end
488497

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

494-
-- Check to see if the selection is ignoring transparency
495-
if(self.selectionUsesMaskColor == true) then
496-
497-
self.imageLayerCanvas:Clear(-1, self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height)
498-
499-
end
500503

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

505-
-- Clear the pixel data
506-
self.selectedPixelData = nil
505+
if(self.selectedPixelData ~= nil) then
506+
507+
-- Check to see if the selection is ignoring transparency
508+
if(self.selectionUsesMaskColor == true) then
509+
510+
self.imageLayerCanvas:Clear(-1, self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height)
511+
512+
end
513+
514+
-- Draw pixel data to the image
515+
self.imageLayerCanvas:MergePixels(self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height, self.selectedPixelData)
516+
517+
-- Clear the pixel data
518+
self.selectedPixelData = nil
519+
520+
end
521+
507522

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

517532
-- Force the display to clear the tmp layer canvas
518533
self.tmpLayerCanvas:Clear()
519-
print("Clear Tmp Layer - Cancel selection")
534+
-- print("Clear Tmp Layer - Cancel selection")
520535

521536

522537
-- Invalidate the canvas and the selection
@@ -549,14 +564,14 @@ function PaintTool:DrawCanvasPanel()
549564

550565
-- Clear the tmp layer
551566
self.tmpLayerCanvas:Clear()
552-
print("Clear Tmp Layer - Redraw selection")
567+
-- print("Clear Tmp Layer - Redraw selection")
553568
if(self.selectedPixelData ~= nil) then
554569

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

558573
self.tmpLayerCanvas:Clear(self.maskColor, self.selectRect.X, self.selectRect.Y, self.selectRect.Width, self.selectRect.Height)
559-
print("Clear Tmp Layer - Redraw Selection mask")
574+
-- print("Clear Tmp Layer - Redraw Selection mask")
560575
end
561576

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

621636
end
622637

638+
function PaintTool:ClearTmpLayer()
639+
640+
-- 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
641+
642+
end
643+
623644

624645
function PaintTool:OnNextZoom(reverse)
625646

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

829+
self:InvalidateUndo()
830+
808831
-- Invalidate the display so it redraws on the next frame
809832
self:InvalidateCanvas()
810833

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

816839
end
817840

841+
function PaintTool:SelectAll()
842+
print("Select All")
843+
844+
self:OnSelectTool("select")
845+
846+
self:InvalidateUndo()
847+
848+
self.selectionState = "resize"
849+
850+
self.selectRect = NewRect( 0, 0, self.imageLayerCanvas.Width, self.imageLayerCanvas.Height )
851+
852+
self.selectedPixelData = nil
853+
854+
self.onClick()
855+
856+
end
857+
818858
-- Use this to perform a click action on a button. It's used internally when a mouse click is detected.
819859
function PaintTool:CanvasRelease(callAction)
820860

@@ -1078,7 +1118,7 @@ function PaintTool:DrawOnCanvas(mousePos)
10781118

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

1081-
self.selectionState = "resize"
1121+
self.selectionState = "resize"
10821122

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

@@ -1175,7 +1215,7 @@ function PaintTool:FillCanvasSelection(colorID)
11751215
self.fillRect = true
11761216
self.fillRectColor = colorID or self.brushColor
11771217

1178-
self:InvalidateCanvas()
1218+
-- self:InvalidateCanvas()
11791219

11801220
end
11811221

Disks/PixelVisionOS/System/Tools/PaintTool/code-drop-down-menu.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function PaintTool:CreateDropDownMenu()
2727
{name = "Fill", action = function() self:FillCanvasSelection() end, key = Keys.F, enabled = false, toolTip = "Learn about PV8."},
2828
{name = "Flip H", action = function() self:FlipH() end, key = Keys.H, enabled = false, toolTip = "Learn about PV8."},
2929
{name = "Flip V", action = function() self:FlipV() end, key = Keys.J, enabled = false, toolTip = "Learn about PV8."},
30+
{name = "Select All", action = function() self:SelectAll() end, key = Keys.A, enabled = true, toolTip = "Learn about PV8."},
3031

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

357358
function PaintTool:InvalidateUndo(canvas, selection)
358359

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

0 commit comments

Comments
 (0)
X Tutup