@@ -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
621636end
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
624645function 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
816839end
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.
819859function 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
11801220end
11811221
0 commit comments