public bool DisplayRegionMask(CanvasDrawingSession drawingSession, float zoomFactor, bool editInProgress)
{
if (!IsEnabled || !IsEditingRegion || !ShowRegion || regionMask == null)
return false;
if (editInProgress && RegionSelectionOperation == SelectionOperation.Replace)
return false;
drawingSession.Blend = CanvasBlend.SourceOver;
if (!editInProgress)
{
// Gray out everything outside the region.
var mask = new ColorMatrixEffect
{
Source = GetRegionMask(),
ColorMatrix = new Matrix5x4
{
// Set RGB = gray.
M51 = 0.5f,
M52 = 0.5f,
M53 = 0.5f,
// Invert and scale the mask alpha.
M44 = -0.75f,
M54 = 0.75f,
}
};
drawingSession.DrawImage(mask);
}
// Magenta region border.
var border = GetSelectionBorder(regionMask, zoomFactor);
drawingSession.DrawImage(border);
return true;
}