private void PaintProcessNew(Vector2 pTextureCoord, PaintPixelDelegate pPaintPixelFunc, System.Action pPrePaintFunc, System.Action pPostPaintFunc) { if (!CanPaint) { PaintEnd(); return; } Vector2 pos = pTextureCoord; pos.x *= mTargetTexture.width; pos.y *= mTargetTexture.height; if (!mIsPainting) { mIsPainting = true; mLastPaintPos = pos; } if (pPrePaintFunc != null) { pPrePaintFunc(); } // Debug.LogWarning ("xxx " + pTextureCoord); if (pPostPaintFunc != null) { pPostPaintFunc(); } mLastPaintPos = pos; }
private void PaintProcess(Vector2 pTextureCoord, PaintPixelDelegate pPaintPixelFunc, System.Action pPrePaintFunc, System.Action pPostPaintFunc) { if (!CanPaint) { PaintEnd(); return; } Vector2 pos = pTextureCoord; pos.x *= mTargetTexture.width; pos.y *= mTargetTexture.height; if (!mIsPainting) { mIsPainting = true; mLastPaintPos = pos; } if (pPrePaintFunc != null) { pPrePaintFunc(); } Vector2 delta = pos - mLastPaintPos; float distanceX = Mathf.Abs(delta.x); float distanceY = Mathf.Abs(delta.y); Vector2 paintPos = mLastPaintPos - CurrentBrush.Extents; if (distanceX < mTargetTexture.width * 0.25f && distanceY < mTargetTexture.height * 0.25f) { int tapCount = Mathf.CeilToInt(Mathf.Max(distanceX / CurrentBrush.PointMaxSpacing.x, distanceY / CurrentBrush.PointMaxSpacing.y)); Vector2 step = delta / tapCount; for (int i = 1; i < tapCount; i++) { paintPos += step; PaintTap(paintPos, pPaintPixelFunc); } } paintPos = pos - CurrentBrush.Extents; PaintTap(paintPos, pPaintPixelFunc); if (pPostPaintFunc != null) { pPostPaintFunc(); } mLastPaintPos = pos; }
private void PaintTap(Vector2 pPaintPos, PaintPixelDelegate pPaintPixelFunc) { int startX = (int)pPaintPos.x, startY = (int)pPaintPos.y; int paintWidth = (int)CurrentBrush.Size.x, paintHeight = (int)CurrentBrush.Size.y; float brushMaskStepX = CurrentBrush.MaskWidth / (float)paintWidth, brushMaskStepY = CurrentBrush.MaskHeight / (float)paintHeight; float brushMaskStartX = brushMaskStepX * 0.5f, brushMaskStartY = brushMaskStepY * 0.5f; // adjust bound inside texture if (startX < 0) { paintWidth += startX; brushMaskStartX -= startX * brushMaskStepX; startX = 0; } if (startX + paintWidth >= mTargetTexture.width) { paintWidth = mTargetTexture.width - startX; } if (startY < 0) { paintHeight += startY; brushMaskStartY -= startY * brushMaskStepY; startY = 0; } if (startY + paintHeight >= mTargetTexture.height) { paintHeight = mTargetTexture.height - startY; } // paint mask float paintMaskStepX = CurrentPaintMask.MaskWidth / (float)mTargetTexture.width, paintMaskStepY = CurrentPaintMask.MaskHeight / (float)mTargetTexture.height; float paintMaskStartX = (startX + 0.5f) * paintMaskStepX, paintMaskStartY = (startY + 0.5f) * paintMaskStepY; // pattern float brushPatternStepX, brushPatternStepY; float brushPatternStartX, brushPatternStartY; switch (CurrentPattern.PatternFillMode) { case CocoMakeupPattern.FillMode.BrushArea: float scaleX = (float)CurrentPattern.MaskWidth / CurrentBrush.MaskWidth; float scaleY = (float)CurrentPattern.MaskHeight / CurrentBrush.MaskHeight; brushPatternStepX = brushMaskStepX * scaleX; brushPatternStepY = brushMaskStepY * scaleY; brushPatternStartX = brushMaskStartX * scaleX; brushPatternStartY = brushMaskStartY * scaleY; break; default: brushPatternStepX = CurrentPattern.MaskWidth / (float)mTargetTexture.width; brushPatternStepY = CurrentPattern.MaskHeight / (float)mTargetTexture.height; brushPatternStartX = (startX + 0.5f) * brushPatternStepX; brushPatternStartY = (startY + 0.5f) * brushPatternStepY; break; } // paint pixels int index = startY * mTargetTexture.width + startX; float paintMaskIndex = (int)paintMaskStartY * CurrentPaintMask.MaskWidth + paintMaskStartX; float brushMaskIndex = (int)brushMaskStartY * CurrentBrush.MaskWidth + brushMaskStartX; float brushPatternIndex = (int)brushPatternStartY * CurrentPattern.MaskWidth + brushPatternStartX; for (int y = 0; y < paintHeight; ++y) { for (int x = 0; x < paintWidth; ++x, ++index, paintMaskIndex += paintMaskStepX, brushMaskIndex += brushMaskStepX, brushPatternIndex += brushPatternStepX) { //Debug.LogWarning ("index : (" + x + ", " + y + "), (" + paintWidth + ", " + paintHeight + ")"); //Debug.LogWarning ("paint mask : " + paintMaskIndex + " (" + (int)(paintMaskStartX + x * paintMaskStepX) + ", " + (int)(paintMaskStartY + y * paintMaskStepY) + "), (" + paintMaskStartX + ", " + paintMaskStartY + "), (" + paintMaskStepX + ", " + paintMaskStepY + ")"); //Debug.LogWarning ("brush mask : " + brushMaskIndex + " (" + (int)(brushMaskStartX + x * brushMaskStepX) + ", " + (int)(brushMaskStartY + y * brushMaskStepY) + ")"); //Debug.LogWarning ("brush pattern : " + brushPatternIndex + " (" + (int)(brushPatternStartX + x * brushPatternStepX) + ", " + (int)(brushPatternStartY + y * brushPatternStepY) + "), (" + brushPatternStartX + ", " + brushPatternStartY + "), (" + brushPatternStepX + ", " + brushPatternStepY + ")"); //Debug.LogWarning ("target: (" + (startX + x) + ", " + (startY + y); CurrentCanvasLayer.LayerPixels [index] = pPaintPixelFunc( CurrentCanvasLayer.LayerPixels [index], CurrentPaintMask.MaskAlphas [(int)paintMaskIndex], CurrentBrush.MaskAlphas [(int)brushMaskIndex], CurrentBrush.MixColor, CurrentPattern.PatternPixels [(int)brushPatternIndex] ); UpdateTargetPixel(index); } index += mTargetTexture.width - paintWidth; paintMaskIndex = (int)(paintMaskStartY + y * paintMaskStepY) * CurrentPaintMask.MaskWidth + paintMaskStartX; brushMaskIndex = (int)(brushMaskStartY + y * brushMaskStepY) * CurrentBrush.MaskWidth + brushMaskStartX; brushPatternIndex = (int)(brushPatternStartY + y * brushPatternStepY) * CurrentPattern.MaskWidth + brushPatternStartX; } }