示例#1
0
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            using (PdnGraphicsPath path = new PdnGraphicsPath())
            {
                path.AddPolygons(polygonSet);

                using (PdnRegion fillRegion = new PdnRegion(path))
                {
                    Rectangle boundingBox = fillRegion.GetBoundsInt();

                    Surface        surface = ((BitmapLayer)ActiveLayer).Surface;
                    RenderArgs     ra      = new RenderArgs(surface);
                    HistoryMemento ha;

                    using (PdnRegion affected = Utility.SimplifyAndInflateRegion(fillRegion))
                    {
                        ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, DocumentWorkspace.ActiveLayerIndex, affected);
                    }

                    ra.Graphics.CompositingMode = AppEnvironment.GetCompositingMode();
                    ra.Graphics.FillRegion(brush, fillRegion.GetRegionReadOnly());

                    HistoryStack.PushNewMemento(ha);
                    ActiveLayer.Invalidate(boundingBox);
                    Update();
                }
            }
        }
示例#2
0
        public Renderer(Settings settings, PdnRegion selectionRegion)
        {
            //convert to AA space
            selectionBounds = selectionRegion.GetBoundsInt();
            var scaledBounds = selectionBounds.Multiply(settings.AntiAliasLevel);

            font     = settings.GetAntiAliasSizeFont();
            image    = new Bitmap(scaledBounds.Width, scaledBounds.Height);
            graphics = Graphics.FromImage(image);
            graphics.Clear(Color.Black);
            graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            this.settings = settings;

            //map color black to transparent
            ColorMap[] colorMap =
            {
                new ColorMap
                {
                    OldColor = Color.Black,
                    NewColor = Color.Transparent
                }
            };
            imageAttributes = new ImageAttributes();
            imageAttributes.SetRemapTable(colorMap);
        }
示例#3
0
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            using (PdnGraphicsPath path = new PdnGraphicsPath())
            {
                path.AddPolygons(polygonSet);

                using (PdnRegion fillRegion = new PdnRegion(path))
                {
                    Rectangle boundingBox = fillRegion.GetBoundsInt();

                    Surface surface = ((BitmapLayer)ActiveLayer).Surface;
                    RenderArgs ra = new RenderArgs(surface);
                    HistoryMemento ha;

                    using (PdnRegion affected = Utility.SimplifyAndInflateRegion(fillRegion))
                    {
                        ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, DocumentWorkspace.ActiveLayerIndex, affected);
                    }

                    ra.Graphics.CompositingMode = AppEnvironment.GetCompositingMode();
                    ra.Graphics.FillRegion(brush, fillRegion.GetRegionReadOnly());

                    HistoryStack.PushNewMemento(ha);
                    ActiveLayer.Invalidate(boundingBox);
                    Update();
                }
            }
        }
示例#4
0
        protected override void OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            base.OnSetRenderInfo(parameters, dstArgs, srcArgs);

            PdnRegion rgn = EnvironmentParameters.GetSelection(EnvironmentParameters.SourceSurface.Bounds);

            bounds = rgn.GetBoundsInt();
        }
示例#5
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            mouseUp = true;

            if (!mouseDownSettingCloneSource)
            {
                Cursor = cursorMouseUp;
            }

            if (IsMouseLeftDown(e))
            {
                this.rendererDst.Visible = true;

                if (savedRegion != null)
                {
                    //RestoreRegion(this.savedRegion);
                    ActiveLayer.Invalidate(this.savedRegion.GetBoundsInt());
                    savedRegion.Dispose();
                    savedRegion = null;
                    Update();
                }

                if (GetStaticData().takeFrom == Point.Empty || GetStaticData().lastMoved == Point.Empty)
                {
                    return;
                }

                if (historyRects.Count > 0)
                {
                    PdnRegion saveMeRegion;

                    Rectangle[] rectsRO;
                    int         rectsROLength;
                    this.historyRects.GetArrayReadOnly(out rectsRO, out rectsROLength);
                    saveMeRegion = Utility.RectanglesToRegion(rectsRO, 0, rectsROLength);

                    PdnRegion simplifiedRegion = Utility.SimplifyAndInflateRegion(saveMeRegion);
                    SaveRegion(simplifiedRegion, simplifiedRegion.GetBoundsInt());

                    historyRects = new Vector <Rectangle>();

                    HistoryMemento ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, ActiveLayerIndex,
                                                                 simplifiedRegion, this.ScratchSurface);

                    HistoryStack.PushNewMemento(ha);
                    this.ClearSavedMemory();
                }
            }
        }
示例#6
0
        public TypeSetter(Settings settings, PdnRegion selectionRegion)
        {
            //parameters in
            this.settings        = settings;
            this.selectionRegion = selectionRegion;
            bounds = selectionRegion.GetBoundsInt();

            //convert to AA space
            scaledBounds = bounds.Multiply(settings.AntiAliasLevel);
            font         = settings.GetAntiAliasSizeFont();
            image        = new Bitmap(scaledBounds.Width, scaledBounds.Height);
            graphics     = Graphics.FromImage(image);

            //constants
            lineIncrement    = (int)Math.Round(font.Height + font.Height * settings.LineSpacing);
            horizontalMargin = (int)Math.Round(font.Size / 10f);

            Lines = new List <LineData>();
        }
示例#7
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            Modes OldMode = Mode;

            Mode           = (Modes)newToken.GetProperty <StaticListChoiceProperty>(PropertyNames.Mode).Value;
            ModeChanged    = Mode != OldMode;
            LowerThreshold = newToken.GetProperty <Int32Property>(PropertyNames.LowerThreshold).Value;

            UpperThreshold = newToken.GetProperty <Int32Property>(PropertyNames.UpperThreshold).Value;

            float OldTolerance = Tolerance;

            Tolerance        = newToken.GetProperty <Int32Property>(PropertyNames.Tolerance).Value;
            Tolerance       *= Tolerance / toleranceMax / toleranceMax;
            ToleranceChanged = Tolerance != OldTolerance;

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);

            PdnRegion           selection = EnvironmentParameters.GetSelection(SrcArgs.Surface.Bounds);
            List <RectangleRef> selRects  = RectangleRef.RectanglesToRectangleRefs(selection.GetRegionScansInt());

            CustomOnRender(RectangleRef.SplitSmall(selRects, selection.GetBoundsInt().Bottom / 4));
        }
示例#8
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            this.rendererDst.BrushLocation = new Point(e.X, e.Y);
            this.rendererDst.BrushSize     = AppEnvironment.PenInfo.Width / 2.0f;

            if (!(ActiveLayer is BitmapLayer) || (takeFromLayer == null))
            {
                return;
            }

            if (GetStaticData().updateSrcPreview)
            {
                Point currentMouse = new Point(e.X, e.Y);
                Point difference   = new Point(currentMouse.X - GetStaticData().lastMoved.X, currentMouse.Y - GetStaticData().lastMoved.Y);
                this.rendererSrc.BrushLocation = new Point(GetStaticData().takeFrom.X + difference.X, GetStaticData().takeFrom.Y + difference.Y);;
                this.rendererSrc.BrushSize     = AppEnvironment.PenInfo.Width / 2.0f;
            }

            if (IsMouseLeftDown(e) &&
                (GetStaticData().takeFrom != Point.Empty) &&
                !IsCtrlDown())
            {
                Point currentMouse = new Point(e.X, e.Y);
                Point lastTakeFrom = Point.Empty;

                lastTakeFrom = GetStaticData().takeFrom;
                if (GetStaticData().lastMoved != Point.Empty)
                {
                    Point difference = new Point(currentMouse.X - GetStaticData().lastMoved.X, currentMouse.Y - GetStaticData().lastMoved.Y);
                    GetStaticData().takeFrom = new Point(GetStaticData().takeFrom.X + difference.X, GetStaticData().takeFrom.Y + difference.Y);
                }
                else
                {
                    GetStaticData().lastMoved = currentMouse;
                }

                int       penWidth = (int)AppEnvironment.PenInfo.Width;
                Rectangle rect;

                if (penWidth != 1)
                {
                    rect = new Rectangle(new Point(GetStaticData().takeFrom.X - penWidth / 2, GetStaticData().takeFrom.Y - penWidth / 2), new Size(penWidth + 1, penWidth + 1));
                }
                else
                {
                    rect = new Rectangle(new Point(GetStaticData().takeFrom.X - penWidth, GetStaticData().takeFrom.Y - penWidth), new Size(1 + (2 * penWidth), 1 + (2 * penWidth)));
                }

                Rectangle boundRect = new Rectangle(GetStaticData().takeFrom, new Size(1, 1));

                // If the takeFrom area escapes the boundary
                if (!ActiveLayer.Bounds.Contains(boundRect))
                {
                    GetStaticData().lastMoved = currentMouse;
                    lastTakeFrom = GetStaticData().takeFrom;
                }

                if (this.savedRegion != null)
                {
                    ActiveLayer.Invalidate(savedRegion.GetBoundsInt());
                    this.savedRegion.Dispose();
                    this.savedRegion = null;
                }

                rect.Intersect(takeFromLayer.Surface.Bounds);

                if (rect.Width == 0 || rect.Height == 0)
                {
                    return;
                }

                this.savedRegion = new PdnRegion(rect);
                SaveRegion(this.savedRegion, rect);

                // Draw that clone line
                Surface takeFromSurface;
                if (object.ReferenceEquals(takeFromLayer, ActiveLayer))
                {
                    takeFromSurface = this.ScratchSurface;
                }
                else
                {
                    takeFromSurface = takeFromLayer.Surface;
                }

                if (this.clipRegion == null)
                {
                    this.clipRegion = Selection.CreateRegion();
                }

                DrawCloneLine(currentMouse, GetStaticData().lastMoved, lastTakeFrom,
                              takeFromSurface, ((BitmapLayer)ActiveLayer).Surface);

                this.rendererSrc.BrushLocation = GetStaticData().takeFrom;

                ActiveLayer.Invalidate(rect);
                Update();

                GetStaticData().lastMoved = currentMouse;
            }
        }
示例#9
0
        private void RenderGradient()
        {
            ColorBgra startColor = AppEnvironment.PrimaryColor;
            ColorBgra endColor   = AppEnvironment.SecondaryColor;

            if (this.shouldSwapColors)
            {
                if (AppEnvironment.GradientInfo.AlphaOnly)
                {
                    // In transparency mode, the color values don't matter. We just need to reverse
                    // and invert the alpha values.
                    byte startAlpha = startColor.A;
                    startColor.A = (byte)(255 - endColor.A);
                    endColor.A   = (byte)(255 - startAlpha);
                }
                else
                {
                    Utility.Swap(ref startColor, ref endColor);
                }
            }

            PointF startPointF = this.startPoint;
            PointF endPointF   = this.endPoint;

            if (this.shouldConstrain)
            {
                if (this.mouseNub == this.startNub)
                {
                    ConstrainPoints(endPointF, ref startPointF);
                }
                else
                {
                    ConstrainPoints(startPointF, ref endPointF);
                }
            }

            RestoreSavedRegion();

            Surface   surface    = ((BitmapLayer)DocumentWorkspace.ActiveLayer).Surface;
            PdnRegion clipRegion = DocumentWorkspace.Selection.CreateRegion();

            SaveRegion(clipRegion, clipRegion.GetBoundsInt());

            RenderGradient(surface, clipRegion, AppEnvironment.GetCompositingMode(), startPointF, startColor, endPointF, endColor);

            using (PdnRegion simplified = Utility.SimplifyAndInflateRegion(clipRegion, Utility.DefaultSimplificationFactor, 0))
            {
                DocumentWorkspace.ActiveLayer.Invalidate(simplified);
            }

            clipRegion.Dispose();

            // Set up status bar text
            double          angle                = -180.0 * Math.Atan2(endPointF.Y - startPointF.Y, endPointF.X - startPointF.X) / Math.PI;
            MeasurementUnit units                = AppWorkspace.Units;
            double          offsetXPhysical      = Document.PixelToPhysicalX(endPointF.X - startPointF.X, units);
            double          offsetYPhysical      = Document.PixelToPhysicalY(endPointF.Y - startPointF.Y, units);
            double          offsetLengthPhysical = Math.Sqrt(offsetXPhysical * offsetXPhysical + offsetYPhysical * offsetYPhysical);

            string numberFormat;
            string unitsAbbreviation;

            if (units != MeasurementUnit.Pixel)
            {
                string unitsAbbreviationName = "MeasurementUnit." + units.ToString() + ".Abbreviation";
                unitsAbbreviation = PdnResources.GetString(unitsAbbreviationName);
                numberFormat      = "F2";
            }
            else
            {
                unitsAbbreviation = string.Empty;
                numberFormat      = "F0";
            }

            string unitsString = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");

            string statusText = string.Format(
                this.helpTextWhileAdjustingFormat,
                offsetXPhysical.ToString(numberFormat),
                unitsAbbreviation,
                offsetYPhysical.ToString(numberFormat),
                unitsAbbreviation,
                offsetLengthPhysical.ToString("F2"),
                unitsString,
                angle.ToString("F2"));

            SetStatus(this.toolIcon, statusText);

            // Make sure everything is on screen.
            Update();
        }
示例#10
0
        protected void RenderShape()
        {
            // create the Pen we will use to draw with
            Pen       outlinePen    = null;
            Brush     interiorBrush = null;
            PenInfo   pi            = AppEnvironment.PenInfo;
            BrushInfo bi            = AppEnvironment.BrushInfo;

            ColorBgra primary   = AppEnvironment.PrimaryColor;
            ColorBgra secondary = AppEnvironment.SecondaryColor;

            if (!ForceShapeDrawType && AppEnvironment.ShapeDrawType == ShapeDrawType.Interior)
            {
                Utility.Swap(ref primary, ref secondary);
            }

            // Initialize pens and brushes to the correct colors
            if ((mouseButton & MouseButtons.Left) == MouseButtons.Left)
            {
                outlinePen    = pi.CreatePen(AppEnvironment.BrushInfo, primary.ToColor(), secondary.ToColor());
                interiorBrush = bi.CreateBrush(secondary.ToColor(), primary.ToColor());
            }
            else if ((mouseButton & MouseButtons.Right) == MouseButtons.Right)
            {
                outlinePen    = pi.CreatePen(AppEnvironment.BrushInfo, secondary.ToColor(), primary.ToColor());
                interiorBrush = bi.CreateBrush(primary.ToColor(), secondary.ToColor());
            }

            if (!this.UseDashStyle)
            {
                outlinePen.DashStyle = DashStyle.Solid;
            }

            outlinePen.LineJoin   = LineJoin.MiterClipped;
            outlinePen.MiterLimit = 2;

            // redraw the old saveSurface
            if (interiorSaveRegion != null)
            {
                RestoreRegion(interiorSaveRegion);
                interiorSaveRegion.Dispose();
                interiorSaveRegion = null;
            }

            if (outlineSaveRegion != null)
            {
                RestoreRegion(outlineSaveRegion);
                outlineSaveRegion.Dispose();
                outlineSaveRegion = null;
            }

            // anti-aliasing? Don't mind if I do
            if (AppEnvironment.AntiAliasing)
            {
                renderArgs.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            }
            else
            {
                renderArgs.Graphics.SmoothingMode = SmoothingMode.None;
            }

            // also set the pixel offset mode
            renderArgs.Graphics.PixelOffsetMode = GetPixelOffsetMode();

            // figure out how we're going to draw
            ShapeDrawType drawType;

            if (ForceShapeDrawType)
            {
                drawType = ForcedShapeDrawType;
            }
            else
            {
                drawType = AppEnvironment.ShapeDrawType;
            }

            // get the region we want to save
            points = this.TrimShapePath(points);
            PointF[]        pointsArray = points.ToArray();
            PdnGraphicsPath shapePath   = CreateShapePath(pointsArray);

            if (shapePath != null)
            {
                // create non-optimized interior region
                PdnRegion interiorRegion = new PdnRegion(shapePath);

                // create non-optimized outline region
                PdnRegion outlineRegion;

                using (PdnGraphicsPath outlinePath = (PdnGraphicsPath)shapePath.Clone())
                {
                    try
                    {
                        outlinePath.Widen(outlinePen);
                        outlineRegion = new PdnRegion(outlinePath);
                    }

                    // Sometimes GDI+ gets cranky if we have a very small shape (e.g. all points
                    // are coincident).
                    catch (OutOfMemoryException)
                    {
                        outlineRegion = new PdnRegion(shapePath);
                    }
                }

                // create optimized outlineRegion for purposes of rendering, if it is possible to do so
                // shapes will often provide an "optimized" region that circumvents the fact that
                // we'd otherwise get a region that encompasses the outline *and* the interior, thus
                // slowing rendering significantly in many cases.
                RectangleF[] optimizedOutlineRegion = GetOptimizedShapeOutlineRegion(pointsArray, shapePath);
                PdnRegion    invalidOutlineRegion;

                if (optimizedOutlineRegion != null)
                {
                    Utility.InflateRectanglesInPlace(optimizedOutlineRegion, (int)(outlinePen.Width + 2));
                    invalidOutlineRegion = Utility.RectanglesToRegion(optimizedOutlineRegion);
                }
                else
                {
                    invalidOutlineRegion = Utility.SimplifyAndInflateRegion(outlineRegion, Utility.DefaultSimplificationFactor, (int)(outlinePen.Width + 2));
                }

                // create optimized interior region
                PdnRegion invalidInteriorRegion = Utility.SimplifyAndInflateRegion(interiorRegion, Utility.DefaultSimplificationFactor, 3);

                PdnRegion invalidRegion = new PdnRegion();
                invalidRegion.MakeEmpty();

                // set up alpha blending
                renderArgs.Graphics.CompositingMode = AppEnvironment.GetCompositingMode();

                SaveRegion(invalidOutlineRegion, invalidOutlineRegion.GetBoundsInt());
                this.outlineSaveRegion = invalidOutlineRegion;
                if ((drawType & ShapeDrawType.Outline) != 0)
                {
                    shapePath.Draw(renderArgs.Graphics, outlinePen);
                }

                invalidRegion.Union(invalidOutlineRegion);

                // draw shape
                if ((drawType & ShapeDrawType.Interior) != 0)
                {
                    SaveRegion(invalidInteriorRegion, invalidInteriorRegion.GetBoundsInt());
                    this.interiorSaveRegion = invalidInteriorRegion;
                    renderArgs.Graphics.FillPath(interiorBrush, shapePath);
                    invalidRegion.Union(invalidInteriorRegion);
                }
                else
                {
                    invalidInteriorRegion.Dispose();
                    invalidInteriorRegion = null;
                }

                bitmapLayer.Invalidate(invalidRegion);

                invalidRegion.Dispose();
                invalidRegion = null;

                outlineRegion.Dispose();
                outlineRegion = null;

                interiorRegion.Dispose();
                interiorRegion = null;
            }

            Update();

            if (shapePath != null)
            {
                shapePath.Dispose();
                shapePath = null;
            }

            outlinePen.Dispose();
            interiorBrush.Dispose();
        }
示例#11
0
        private static unsafe void LoadOrSaveSurfaceRegion(FileStream fileHandle, Surface surface, PdnRegion region, bool trueForSave)
        {
            Rectangle[] scans         = region.GetRegionScansReadOnlyInt();
            Rectangle   regionBounds  = region.GetBoundsInt();
            Rectangle   surfaceBounds = surface.Bounds;
            int         scanCount     = 0;

            void *[] ppvBuffers;
            uint[]   lengths;

            regionBounds.Intersect(surfaceBounds);
            long length = (long)regionBounds.Width * (long)regionBounds.Height * (long)ColorBgra.SizeOf;

            if (scans.Length == 1 &&
                length <= uint.MaxValue &&
                surface.IsContiguousMemoryRegion(regionBounds))
            {
                ppvBuffers = new void *[1];
                lengths    = new uint[1];

                ppvBuffers[0] = surface.GetPointAddressUnchecked(regionBounds.Location);
                lengths[0]    = (uint)length;
            }
            else
            {
                for (int i = 0; i < scans.Length; ++i)
                {
                    Rectangle rect = scans[i];
                    rect.Intersect(surfaceBounds);

                    if (rect.Width != 0 && rect.Height != 0)
                    {
                        scanCount += rect.Height;
                    }
                }

                int scanIndex = 0;
                ppvBuffers = new void *[scanCount];
                lengths    = new uint[scanCount];

                for (int i = 0; i < scans.Length; ++i)
                {
                    Rectangle rect = scans[i];
                    rect.Intersect(surfaceBounds);

                    if (rect.Width != 0 && rect.Height != 0)
                    {
                        for (int y = rect.Top; y < rect.Bottom; ++y)
                        {
                            ppvBuffers[scanIndex] = surface.GetPointAddressUnchecked(rect.Left, y);
                            lengths[scanIndex]    = (uint)(rect.Width * ColorBgra.SizeOf);
                            ++scanIndex;
                        }
                    }
                }
            }

            if (trueForSave)
            {
                FileSystem.WriteToStreamingFileGather(fileHandle, ppvBuffers, lengths);
            }
            else
            {
                FileSystem.ReadFromStreamScatter(fileHandle, ppvBuffers, lengths);
            }
        }
示例#12
0
        private static unsafe void LoadOrSaveSurfaceRegion(FileStream fileHandle, Surface surface, PdnRegion region, bool trueForSave)
        {
            Rectangle[] scans = region.GetRegionScansReadOnlyInt();
            Rectangle regionBounds = region.GetBoundsInt();
            Rectangle surfaceBounds = surface.Bounds;
            int scanCount = 0;

            void*[] ppvBuffers;
            uint[] lengths;

            regionBounds.Intersect(surfaceBounds);
            long length = (long)regionBounds.Width * (long)regionBounds.Height * (long)ColorBgra.SizeOf;

            if (scans.Length == 1 &&
                length <= uint.MaxValue &&
                surface.IsContiguousMemoryRegion(regionBounds))
            {
                ppvBuffers = new void*[1];
                lengths = new uint[1];

                ppvBuffers[0] = surface.GetPointAddressUnchecked(regionBounds.Location);
                lengths[0] = (uint)length;
            }
            else
            {
                for (int i = 0; i < scans.Length; ++i)
                {
                    Rectangle rect = scans[i];
                    rect.Intersect(surfaceBounds);

                    if (rect.Width != 0 && rect.Height != 0)
                    {
                        scanCount += rect.Height;
                    }
                }

                int scanIndex = 0;
                ppvBuffers = new void*[scanCount];
                lengths = new uint[scanCount];

                for (int i = 0; i < scans.Length; ++i)
                {
                    Rectangle rect = scans[i];
                    rect.Intersect(surfaceBounds);

                    if (rect.Width != 0 && rect.Height != 0)
                    {
                        for (int y = rect.Top; y < rect.Bottom; ++y)
                        {
                            ppvBuffers[scanIndex] = surface.GetPointAddressUnchecked(rect.Left, y);
                            lengths[scanIndex] = (uint)(rect.Width * ColorBgra.SizeOf);
                            ++scanIndex;
                        }
                    }
                }
            }

            if (trueForSave)
            {
                FileSystem.WriteToStreamingFileGather(fileHandle, ppvBuffers, lengths);
            }
            else
            {
                FileSystem.ReadFromStreamScatter(fileHandle, ppvBuffers, lengths);
            }
        }