Esempio n. 1
0
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            ctx.SetColor(Colors.DarkGray);
            ctx.SetLineWidth(1);
            ctx.MoveTo(0, 0);
            ctx.LineTo(0, Bounds.Height);
            ctx.Stroke();
        }
Esempio n. 2
0
        public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save ();
            ctx.Translate (x + 30, y + 30);
            ctx.SetLineWidth (3);

            // Rotation

            double end = 270;
            double r = 30;

            for (double n = 0; n<=end; n += 5) {
                ctx.Save ();
                ctx.Rotate (n);
                ctx.MoveTo (0, 0);
                ctx.RelLineTo (r, 0);
                double c = n / end;
                ctx.SetColor (new Color (c, c, c));
                ctx.Stroke ();

                // Visual test for TransformPoints
                Point p0 = new Point (0,0);
                Point p1 = new Point (0, -r);
                Point[] p = new Point[] {p0, p1};
                ctx.TransformPoints (p);
                ctx.ResetTransform ();
                ctx.Translate (2 * r + 1, 0);
                ctx.MoveTo (p[0]);
                ctx.LineTo (p[1]);
                c = 1-c;
                ctx.SetColor (new Color (c, c, c));
                ctx.Stroke();
                ctx.Restore ();
            }
            ctx.Restore ();
        }
Esempio n. 3
0
        private void DrawLine(Xwt.Drawing.Color c, BorderStyleEnum bs, float w, Xwt.Drawing.Context g, double x, double y, double x2, double y2)
        {
            if (bs == BorderStyleEnum.None //|| c.IsEmpty
                || w <= 0)   // nothing to draw
                return;

            g.Save();
            //          Pen p = null;
            //          p = new Pen(c, w);
            g.SetColor(c);
            g.SetLineWidth(w);
            switch (bs)
            {
                case BorderStyleEnum.Dashed:
                    //	                p.DashStyle = DashStyle.Dash;
                    g.SetLineDash(0.0, new double[] { 2, 1 });
                    break;
                case BorderStyleEnum.Dotted:
                    //                        p.DashStyle = DashStyle.Dot;
                    g.SetLineDash(0.0, new double[] { 1 });
                    break;
                case BorderStyleEnum.Double:
                case BorderStyleEnum.Groove:
                case BorderStyleEnum.Inset:
                case BorderStyleEnum.Solid:
                case BorderStyleEnum.Outset:
                case BorderStyleEnum.Ridge:
                case BorderStyleEnum.WindowInset:
                default:
                    g.SetLineDash(0.0, new double[] { });
                    break;
            }

            g.MoveTo(x, y);
            g.LineTo(x2, y2);
            g.Stroke();

            g.Restore();
        }
Esempio n. 4
0
        public virtual void Texts(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save ();

            ctx.Translate (x, y);

            ctx.SetColor (Colors.Black);

            var col1 = new Rectangle ();
            var col2 = new Rectangle ();

            var text = new TextLayout ();
            text.Font = this.Font.WithSize (24);
            Console.WriteLine (text.Font.Size);

            // first text
            text.Text = "Lorem ipsum dolor sit amet,";
            var size1 = text.GetSize ();
            col1.Width = size1.Width;
            col1.Height += size1.Height + 10;
            ctx.DrawTextLayout (text, 0, 0);

            // proofing width; test should align with text above
            ctx.SetColor (Colors.DarkMagenta);
            text.Text = "consetetur sadipscing elitr, sed diam nonumy";
            text.Width = col1.Width;
            var size2 = text.GetSize ();

            ctx.DrawTextLayout (text, 0, col1.Bottom);
            col1.Height += size2.Height + 10;

            ctx.SetColor (Colors.Black);

            // proofing scale, on second col
            ctx.Save ();
            ctx.SetColor (Colors.Red);
            col2.Left = col1.Right + 10;

            text.Text = "eirmod tempor invidunt ut.";

            var scale = 1.2;
            text.Width = text.Width / scale;
            var size3 = text.GetSize ();
            col2.Height = size3.Height * scale;
            col2.Width = size3.Width * scale + 5;
            ctx.Scale (scale, scale);
            ctx.DrawTextLayout (text, col2.Left / scale, col2.Top / scale);
            ctx.Restore ();

            // proofing heigth, on second col
            ctx.Save ();
            ctx.SetColor (Colors.DarkCyan);
            text.Text = "Praesent ac lacus nec dolor pulvinar feugiat a id elit.";
            var size4 = text.GetSize ();
            text.Height = size4.Height / 2;
            text.Trimming=TextTrimming.WordElipsis;
            ctx.DrawTextLayout (text, col2.Left, col2.Bottom + 5);

            ctx.SetLineWidth (1);
            ctx.SetColor (Colors.Blue);
            ctx.Rectangle (new Rectangle (col2.Left, col2.Bottom + 5, text.Width, text.Height));
            ctx.Stroke();
            ctx.Restore ();

            // drawing col line
            ctx.SetLineWidth (1);

            ctx.SetColor (Colors.Black.WithAlpha (.5));
            ctx.MoveTo (col1.Right + 5, col1.Top);
            ctx.LineTo (col1.Right + 5, col1.Bottom);
            ctx.Stroke ();
            ctx.MoveTo (col2.Right + 5, col2.Top);
            ctx.LineTo (col2.Right + 5, col2.Bottom);
            ctx.Stroke ();
            ctx.SetColor (Colors.Black);

            // proofing rotate, and printing size to see the values
            ctx.Save ();

            text.Font = this.Font.WithSize (10);
            text.Text = string.Format ("Size 1 {0}\r\nSize 2 {1}\r\nSize 3 {2} Scale {3}",
                                       size1, size2, size3, scale);
            text.Width = -1; // this clears textsize
            text.Height = -1;
            ctx.Rotate (5);
            // maybe someone knows a formula with angle and textsize to calculyte ty
            var ty = 30;
            ctx.DrawTextLayout (text, ty, col1.Bottom + 10);

            ctx.Restore ();

            // scale example here:

            ctx.Restore ();

            TextLayout tl0 = new TextLayout (this);

            tl0.Font = this.Font.WithSize (10);
            tl0.Text = "This text contains attributes.";
            tl0.SetUnderline ( 0, "This".Length);
            tl0.SetForeground (new Color (0, 1.0, 1.0), "This ".Length, "text".Length);
            tl0.SetBackground (new Color (0, 0, 0), "This ".Length, "text".Length);
            tl0.SetFontWeight (FontWeight.Bold, "This text ".Length, "contains".Length);
            tl0.SetFontStyle (FontStyle.Italic, "This text ".Length, "contains".Length);
            tl0.SetStrikethrough ("This text contains ".Length, "attributes".Length);

            ctx.SetColor(Colors.DarkGreen);
            ctx.DrawTextLayout (tl0, col2.Left, col2.Bottom + 100);

            // Text boces

            y = 180;

            // Without wrapping

            TextLayout tl = new TextLayout (this);
            tl.Text = "Stright text";
            DrawText (ctx, tl, ref y);

            // With wrapping

            tl = new TextLayout (this);
            tl.Text = "The quick brown fox jumps over the lazy dog";
            tl.Width = 100;
            DrawText (ctx, tl, ref y);

            // With blank lines

            tl = new TextLayout (this);
            tl.Text = "\nEmpty line above\nLine break above\n\nEmpty line above\n\n\nTwo empty lines above\nEmpty line below\n";
            tl.Width = 200;
            DrawText (ctx, tl, ref y);
        }
Esempio n. 5
0
        public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y)
        {
            // draws a line along the x-axis from (0,0) to (r,0) with a constant translation and an increasing
            // rotational component. This composite transform is then applied to a vertical line, with inverse
            // color, and an additional x-offset, to form a mirror image figure for easy visual comparison.
            // These transformed points must be drawn with the identity CTM, hence the Restore() each time.

            ctx.Save ();	// save caller's context (assumed to be the Identity CTM)
            ctx.SetLineWidth (3);	// should align exactly if drawn with half-pixel coordinates

            // Vector length (pixels) and rotation limit (degrees)
            double r = 30;
            double end = 270;

            for (double n = 0; n<=end; n += 5) {
                ctx.Save ();	// save context and identity CTM for each line

                // Set up translation to centre point of first figure, ensuring pixel alignment
                ctx.Translate (x + 30.5, y + 30.5);
                ctx.Rotate (n);
                ctx.MoveTo (0, 0);
                ctx.RelLineTo (r, 0);
                double c = n / end;
                ctx.SetColor (new Color (c, c, c));
                ctx.Stroke ();	// stroke first figure with composite Translation and Rotation CTM

                // Generate mirror image figure as a visual test of TransformPoints
                Point p0 = new Point (0,0);
                Point p1 = new Point (0, -r);
                Point[] p = new Point[] {p0, p1};
                ctx.TransformPoints (p);	// using composite transformation

                ctx.Restore ();	// restore identity CTM
                ctx.Save ();	// save again (to restore after additional Translation)

                ctx.Translate (2 * r + 1, 0);	// extra x-offset to clear first figure
                ctx.MoveTo (p[0]);
                ctx.LineTo (p[1]);
                c = 1-c;
                ctx.SetColor (new Color (c, c, c));
                ctx.Stroke();		// stroke transformed points with offset in CTM

                ctx.Restore ();		// restore identity CTM for next line
            }
            ctx.Restore ();	// restore caller's context
        }