Beispiel #1
0
        public void SetToDefaults()
        {
            this.antiAliasing   = true;
            this.fontSmoothing  = FontSmoothing.Smooth;
            this.primaryColor   = ColorBgra.FromBgra(0, 0, 0, 255);
            this.secondaryColor = ColorBgra.FromBgra(255, 255, 255, 255);
            this.gradientInfo   = new GradientInfo(GradientType.LinearClamped, false);
            this.penInfo        = new PenInfo(PenInfo.DefaultDashStyle, 2.0f, PenInfo.DefaultLineCap, PenInfo.DefaultLineCap, PenInfo.DefaultCapScale);
            this.brushInfo      = new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);

            try
            {
                this.fontInfo = new FontInfo(new FontFamily("Arial"), 12, FontStyle.Regular);
            }

            catch (Exception)
            {
                this.fontInfo = new FontInfo(new FontFamily(GenericFontFamilies.SansSerif), 12, FontStyle.Regular);
            }

            this.textAlignment = TextAlignment.Left;
            this.shapeDrawType = ShapeDrawType.Outline;
            this.alphaBlending = true;
            this.tolerance     = 0.5f;

            this.colorPickerClickBehavior = ColorPickerClickBehavior.NoToolSwitch;
            this.resamplingAlgorithm      = ResamplingAlgorithm.Bilinear;
            this.selectionCombineMode     = CombineMode.Replace;
            this.floodMode             = FloodMode.Local;
            this.selectionDrawModeInfo = SelectionDrawModeInfo.CreateDefault();
        }
        public void DrawBasicSquareWithExtraAttributes()
        {
            Point canvasCoordinate = inkCanvas.Coordinates.LocationInViewport;
            Size  squareSize       = new Size(inkCanvas.Size.Width * 3 / 5, inkCanvas.Size.Height * 3 / 5);
            Point A = new Point(canvasCoordinate.X + inkCanvas.Size.Width / 5, canvasCoordinate.Y + inkCanvas.Size.Height / 5);

            // A        B
            //  ┌──────┐   Draw a basic ABCD square using Pen through the Actions API
            //  │      │   in pointer origin mode:
            //  │      │   - X is relative to the previous X position in this session
            //  └──────┘   - Y is relative to the previous Y position in this session
            // D        C
            PointerInputDevice penDevice          = new PointerInputDevice(PointerKind.Pen);
            ActionSequence     sequence           = new ActionSequence(penDevice, 0);
            PenInfo            penExtraAttributes = new PenInfo {
                TiltX = 45, TiltY = 45, Twist = 45
            };

            // Draw line AB from point A to B with attributes defined in penExtraAttributes
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Pointer, A.X, A.Y, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact, penExtraAttributes));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Pointer, squareSize.Width, 0, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            // Draw line BC from point B to C and apply maximum (0.9f) pressure as the pen draw between the points
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Pointer, 0, squareSize.Height, TimeSpan.Zero, new PenInfo {
                Pressure = 0.9f
            }));
            sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            // Draw line CD from point C to D and keep the maximum pressure by not changing the pressure attribute
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Pointer, -squareSize.Width, 0, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            // Draw line DA from point D to A and reduce the pressure to minimum (0.1f) as the pen draw between the points
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Pointer, 0, -squareSize.Height, TimeSpan.Zero, new PenInfo {
                Pressure = 0.1f
            }));
            sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            newStickyNoteSession.PerformActions(new List <ActionSequence> {
                sequence
            });

            try
            {
                var result = newStickyNoteSession.FindElementByAccessibilityId("RichEditBox");
                Assert.Fail("RichEditBox should not be defined anymore after a pen input is successfully performed.");
            }
            catch { }
        }
Beispiel #3
0
        public override void WriteJson(JsonWriter writer, Pen <Rgba32> value, JsonSerializer serializer)
        {
            var props = new PenInfo
            {
                strokeFill    = value.StrokeFill,
                strokeWidth   = value.StrokeWidth,
                strokePattern = value.StrokePattern.ToArray()
            };

            serializer.Serialize(writer, props);
        }
Beispiel #4
0
 public Pen CreatePen(bool swapColors)
 {
     if (!swapColors)
     {
         return(PenInfo.CreatePen(BrushInfo, PrimaryColor.ToColor(), SecondaryColor.ToColor()));
     }
     else
     {
         return(PenInfo.CreatePen(BrushInfo, SecondaryColor.ToColor(), PrimaryColor.ToColor()));
     }
 }
Beispiel #5
0
        internal static Pen smethod_0(PenInfo penInfo)
        {
            Pen pen;

            if (!Class1072.dictionary_1.TryGetValue(penInfo, out pen))
            {
                pen            = new Pen(Class1072.smethod_1(penInfo.Color), penInfo.LineWidth);
                pen.MiterLimit = 2.0;
                pen.Freeze();
                Class1072.dictionary_1[penInfo] = pen;
            }
            return(pen);
        }
Beispiel #6
0
 public void LoadFrom(ToolEnvironment toolEnvironment)
 {
     this.textAlignment            = toolEnvironment.textAlignment;
     this.gradientInfo             = toolEnvironment.gradientInfo.Clone();
     this.fontSmoothing            = toolEnvironment.fontSmoothing;
     this.fontInfo                 = toolEnvironment.fontInfo.Clone();
     this.penInfo                  = toolEnvironment.penInfo.Clone();
     this.brushInfo                = toolEnvironment.brushInfo.Clone();
     this.primaryColor             = toolEnvironment.primaryColor;
     this.secondaryColor           = toolEnvironment.secondaryColor;
     this.alphaBlending            = toolEnvironment.alphaBlending;
     this.shapeDrawType            = toolEnvironment.shapeDrawType;
     this.antiAliasing             = toolEnvironment.antiAliasing;
     this.colorPickerClickBehavior = toolEnvironment.colorPickerClickBehavior;
     this.resamplingAlgorithm      = toolEnvironment.resamplingAlgorithm;
     this.tolerance                = toolEnvironment.tolerance;
     this.selectionCombineMode     = toolEnvironment.selectionCombineMode;
     this.floodMode                = toolEnvironment.floodMode;
     this.selectionDrawModeInfo    = toolEnvironment.selectionDrawModeInfo.Clone();
     PerformAllChanged();
 }
Beispiel #7
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();
        }
Beispiel #8
0
 private static void ChangePenSettings(Pen drawPen, PenInfo pInfo)
 {
     drawPen.Color = pInfo.Color;
     drawPen.Width = pInfo.Width;
     drawPen.DashStyle = pInfo.Style;
 }