@@ -54,7 +54,7 @@ function PaintTool:CreateCanvasPanel()
5454 self .imageCanvas .SetPixels (0 , 0 , self .image .Width , self .image .Height , pixelData )
5555
5656
57- self .tmpPaintCanvas = NewCanvas (self .viewportRect . width , self .viewportRect . height )
57+ self .tmpPaintCanvas = NewCanvas (self .imageCanvas . Width , self .imageCanvas . Width )
5858 self .tmpPaintCanvas .Clear (- 1 );
5959
6060 self .vSliderData = editorUI :CreateSlider ({x = 235 - 3 , y = 44 + 3 + 8 , w = 10 , h = 193 - 24 - 7 - 8 }, " vsliderhandle" , " Scroll text vertically." )
123123
124124function PaintTool :UpdateCanvasPanel (timeDelta )
125125
126+ -- Ignore the update if the option menu is open
127+ -- if(self.optionMenuOpen == true) then
128+ -- return
129+ -- end
130+
126131 -- If the button has data but it's not enabled exit out of the update
127132 if (self .canvasPanel .enabled == false ) then
128133
@@ -178,12 +183,14 @@ function PaintTool:UpdateCanvasPanel(timeDelta)
178183
179184 -- TODO need to adjust for scroll and scale
180185 local tmpPos = NewPoint (
181- math.floor ((editorUI .collisionManager .mousePos .x - self .viewportRect .x ) / self .scale ) + self .scaledViewport .X ,
182- math.floor ((editorUI .collisionManager .mousePos .y - self .viewportRect .y )/ self .scale ) + self .scaledViewport .Y
186+ math.floor ((editorUI .collisionManager .mousePos .x - self .viewportRect .X ) / self .scale ) + self .scaledViewport .X ,
187+ math.floor ((editorUI .collisionManager .mousePos .y - self .viewportRect .Y )/ self .scale ) + self .scaledViewport .Y
183188 )
184189
185190 -- print("Mouse Pos", dump(editorUI.collisionManager.mousePos), "adjusted", tmpPos, self.scaledViewport.X)
186191
192+ -- print("Mouse", dump(editorUI.collisionManager.mousePos), (math.floor((editorUI.collisionManager.mousePos.x - self.viewportRect.X)/ self.scale) + self.scaledViewport.X))
193+
187194 -- Check to see if the button is pressed and has an onAction callback
188195 if (editorUI .collisionManager .mouseReleased == true ) then
189196
@@ -289,37 +296,13 @@ function PaintTool:DrawCanvasPanel()
289296 -- Draw the pixel data in the upper left hand cornver of the tool's window
290297 self .imageCanvas :DrawPixels (self .viewportRect .X , self .viewportRect .Y , DrawMode .TilemapCache , self .scale , - 1 , self .maskColor , self .colorOffset , self .scaledViewport )
291298
292- self .tmpPaintCanvas :DrawPixels (self .viewportRect .X , self .viewportRect .Y , DrawMode .TilemapCache , self .scale , - 1 , self .emptyColorID , self .colorOffset , NewRect ( 0 , 0 , self .scaledViewport . Width , self . scaledViewport . Height ) )
299+ self .tmpPaintCanvas :DrawPixels (self .viewportRect .X , self .viewportRect .Y , DrawMode .TilemapCache , self .scale , - 1 , self .emptyColorID , self .colorOffset , self .scaledViewport )
293300
294301
295302 self .displayInvalid = false
296303
297304 end
298305
299- -- if(self.canvasPanel.inFocus == true) then
300-
301- -- -- print(editorUI.mouseCursor.pos)
302-
303- -- local tmpX = self.mCol * self.gridSize
304- -- local tmpY = self.mRow * self.gridSize
305-
306- -- if(tmpX < (self.tmpPaintCanvas.width * self.scale) and tmpY < (self.tmpPaintCanvas.height * self.scale)) then
307-
308- -- -- TODO If dragging, snap this to the mouse position
309-
310- -- tmpX = tmpX + self.viewportRect.X - self.scaledViewport.X
311- -- tmpY = tmpY + self.viewportRect.Y- self.scaledViewport.Y
312-
313- -- self.overCanvas:DrawPixels( tmpX - 3 , tmpY - 3, DrawMode.UI )
314-
315- -- self.tmpPaintCanvas:DrawPixels(tmpX, tmpY, DrawMode.SpriteAbove, self.scale, -1, self.maskColor, 0, NewRect( self.mCol * 8 + self.scaledViewport.X, self.mRow * 8 + self.scaledViewport.Y, 8, 8 ))
316-
317- -- else
318- -- editorUI:ClearFocus(self.canvasPanel)
319- -- end
320- -- end
321-
322-
323306end
324307
325308
@@ -363,6 +346,8 @@ function PaintTool:OnNextZoom(reverse)
363346 self .scaledViewport .Width = Clamp (viewWidth , 1 , math.max (imageWidth , self .imageCanvas .width )) -- math.min(self.viewportRect.Width, math.min(self.tmpPaintCanvas.width * self.scale, math.ceil(self.viewportRect.Width / self.scale)))
364347 self .scaledViewport .Height = Clamp (viewHeight , 1 , math.max (imageHeight , self .imageCanvas .height ))-- , self.viewportRect.Height) --math.min(self.viewportRect.Height, math.min(self.tmpPaintCanvas.height * self.scale, math.ceil(self.viewportRect.Height / self.scale)))
365348
349+
350+ print (" self.scaledViewport" , dump (self .scaledViewport ))
366351 -- Calculate the boundary for scrolling
367352 self .boundaryRect .Width = self .imageCanvas .width - self .scaledViewport .Width
368353 self .boundaryRect .Height = self .imageCanvas .height - self .scaledViewport .Height
@@ -530,6 +515,9 @@ function PaintTool:CanvasRelease(callAction)
530515
531516 -- -- Clear the canvas
532517 self .tmpPaintCanvas :Clear ()
518+
519+
520+ self :InvalidateSprites ()
533521
534522 -- if(data.selectRect ~= nil and (data.selectRect.Width == 0 or data.selectRect.Height == 0)) then
535523 -- data.selectRect = nil
@@ -663,67 +651,69 @@ function PaintTool:DrawOnCanvas(mousePos)
663651
664652 self :InvalidateCanvas ()
665653
666- -- elseif(data .tool == "select") then
654+ elseif (self .tool == " select" ) then
667655
668- -- if(data .mouseState == "pressed") then
656+ if (self .mouseState == " pressed" ) then
669657
670- -- if(data .selectRect == nil) then
658+ if (self .selectRect == nil ) then
671659
672- -- data .selectionState = "new"
660+ self .selectionState = " new"
673661
674- -- data .selectRect = NewRect(data .startPos.x, data .startPos.y, 0, 0)
662+ self .selectRect = NewRect (self .startPos .x , self .startPos .y , 0 , 0 )
675663
676- -- else
664+ else
677665
678- -- if(data .selectRect:Contains(mousePos) == true) then
666+ if (self .selectRect :Contains (mousePos ) == true ) then
679667
680- -- data .selectionState = "newmove"
668+ self .selectionState = " newmove"
681669
682- -- data .moveOffset = NewPoint(data .selectRect.X - mousePos.X, data .selectRect.Y - mousePos.Y)
670+ self .moveOffset = NewPoint (self .selectRect .X - mousePos .X , self .selectRect .Y - mousePos .Y )
683671
684- -- if(data .selectedPixelData == nil) then
672+ if (self .selectedPixelData == nil ) then
685673
686- -- data .selectedPixelData = self:CutPixels(data )
687- -- end
674+ self .selectedPixelData = self :CutPixels (self )
675+ end
688676
689- -- else
677+ else
690678
691- -- self:CancelCanvasSelection(data )
679+ self :CancelCanvasSelection (self )
692680
693- -- end
681+ end
694682
695- -- end
683+ end
696684
697685 elseif (self .mouseState == " dragging" ) then
698686
699- -- if(data .selectRect ~= nil) then
700- -- if(data .selectionState == "new" or data .selectionState == "resize") then
687+ if (self .selectRect ~= nil ) then
688+ if (self .selectionState == " new" or self .selectionState == " resize" ) then
701689
702- -- data .selectionState = "resize"
690+ self .selectionState = " resize"
703691
704- -- -- print("resize", data.selectRect, mousePos, , )
692+ -- print("resize", data.selectRect, mousePos, , )
705693
706- -- data .selectRect.X = math.min(data .startPos.X, mousePos.X)
707- -- data .selectRect.Y = math.min(data .startPos.Y, mousePos.Y)
708- -- data .selectRect.Width = Clamp(math.abs(mousePos.X - data .startPos.X), 0, data .tmpPaintCanvas.width)
709- -- data .selectRect.Height = Clamp(math.abs(mousePos.Y - data .startPos.Y), 0, data .tmpPaintCanvas.height)
694+ self .selectRect .X = math.min (self .startPos .X , mousePos .X )
695+ self .selectRect .Y = math.min (self .startPos .Y , mousePos .Y )
696+ self .selectRect .Width = Clamp (math.abs (mousePos .X - self .startPos .X ), 0 , self .tmpPaintCanvas .width )
697+ self .selectRect .Height = Clamp (math.abs (mousePos .Y - self .startPos .Y ), 0 , self .tmpPaintCanvas .height )
710698
711- -- else
699+ else
712700
713701
714- -- editorUI.cursorID = 2
702+ editorUI .cursorID = 2
715703
716- -- data .selectRect.X = mousePos.X + data .moveOffset.X -- data.selectionSize.X
717- -- data .selectRect.Y = mousePos.Y + data .moveOffset.Y -- data.selectionSize.Y
704+ self .selectRect .X = mousePos .X + self .moveOffset .X -- data.selectionSize.X
705+ self .selectRect .Y = mousePos .Y + self .moveOffset .Y -- data.selectionSize.Y
718706
719707
720- -- data .selectionState = "move"
708+ self .selectionState = " move"
721709
722- -- end
723- -- end
710+ end
711+ end
712+
724713
725- -- end
714+ end
726715
716+ print (" Selection" , dump (self .selectRect ))
727717
728718
729719 elseif (self .tool == " eyedropper" ) then
@@ -743,3 +733,59 @@ function PaintTool:DrawOnCanvas(mousePos)
743733
744734end
745735
736+ function PixelVisionOS :CutPixels ()
737+
738+ if (self .selectRect == nil ) then
739+ return
740+ end
741+
742+ local selection =
743+ {
744+ size = NewRect (self .selectRect .X , self .selectRect .Y , self .selectRect .Width , self .selectRect .Height )
745+ }
746+
747+ selection .pixelData = self .paintCanvas :GetPixels (selection .size .X , selection .size .Y , selection .size .Width , selection .size .Height )
748+
749+ -- Convert the mask colors to the tool's mask color
750+ for i = 1 , # selection .pixelData do
751+ if (selection .pixelData [i ] == 255 ) then
752+ selection .pixelData [i ] = - 1
753+ end
754+ end
755+
756+ selection .pixelData [i ] = 5
757+
758+ local bgColor = self .showBGColor and gameEditor :BackgroundColor () + 256 or self .emptyColorID
759+
760+
761+ -- Change the stroke to a single pixel of white
762+ self .tmpPaintCanvas :SetStroke (bgColor , self .defaultStrokeWidth )
763+
764+ -- Change the stroke to a single pixel of white
765+ self .tmpPaintCanvas :SetPattern ({ bgColor }, self .defaultStrokeWidth , self .defaultStrokeWidth )
766+
767+ -- Adjust right and bottom to account for 1 px border
768+ self .tmpPaintCanvas :DrawRectangle (selection .size .Left , selection .size .Top , selection .size .Right - 1 , selection .size .Bottom - 1 , true )
769+
770+ return selection
771+
772+ end
773+
774+ function PixelVisionOS :FillCanvasSelection (self , colorID )
775+
776+ if (self .selectRect == nil ) then
777+ return
778+ end
779+
780+ if (self .selectedPixelData == nil ) then
781+ self .selectedPixelData = self :CutPixels (self )
782+ end
783+
784+ for i = 1 , # self .selectedPixelData .pixelData do
785+ self .selectedPixelData .pixelData [i ] = colorID or (self .brushColor + self .colorOffset )
786+ end
787+
788+ -- Fire a release event
789+ self :CanvasRelease (self , true )
790+
791+ end
0 commit comments