Beispiel #1
0
		protected override void OnDraw (Context ctx, Rectangle bounds)
		{
			ctx.Save ();
			ctx.Translate (bounds.Location);
			ctx.Scale (bounds.Width / Size.Width, bounds.Height / Size.Height);
			ToolkitEngine.VectorImageRecorderContextHandler.Draw (ctx.Handler, Toolkit.GetBackend (ctx), data);
			ctx.Restore ();
		}
Beispiel #2
0
        protected override void OnDraw(Context ctx, Rectangle bounds)
        {
            var size = !Size.IsZero ? Size : images [0].Size;

            ctx.Save();
            ctx.Translate(bounds.Location);
            if (!size.IsZero)
            {
                ctx.Scale(bounds.Width / size.Width, bounds.Height / size.Height);
            }

            for (int n = 0; n < images.Length; n++)
            {
                var image = images [n];
                if (image.Size != size)
                {
                    image = image.WithSize(size);
                }
                ctx.DrawImage(image, 0, 0);
            }

            ctx.Restore();
        }
Beispiel #3
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.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);
        }
Beispiel #4
0
        protected override sealed void OnDraw(Context ctx, Rectangle bounds)
        {
            var frame = GetFrame (ctx.ScaleFactor);
            var fixedWidth = frame.Bitmap.Width - 2 - frame.StretchableWidth;
            var fixedHeight = frame.Bitmap.Height - 2 - frame.StretchableHeight;
            double totalVariableWidth = bounds.Width - fixedWidth / frame.ScaleFactor;
            double totalVariableHeight = bounds.Height - fixedHeight / frame.ScaleFactor;
            double remainingVariableHeight = totalVariableHeight;

            double y = bounds.Y, yb = 1;
            int tileIndex = 0;

            ctx.Save ();
            if (totalVariableWidth < 0) {
                if (fixedWidth > 0)
                    ctx.Scale (bounds.Width / fixedWidth, 1);
                totalVariableWidth = 0;
            }
            if (totalVariableHeight < 0) {
                if (fixedHeight > 0)
                    ctx.Scale (1, bounds.Height / fixedHeight);
                totalVariableHeight = 0;
            }

            foreach (var vs in frame.VerticalSections) {

                double sh = CalcSectionSize (frame, vs, totalVariableHeight, frame.StretchableHeight, ref remainingVariableHeight);

                double x = bounds.X, xb = 1;
                double remainingVariableWidth = totalVariableWidth;

                foreach (var hs in frame.HorizontalSections) {
                    var sourceRegion = new Rectangle (xb, yb, hs.Size, vs.Size);
                    double sw = CalcSectionSize (frame, hs, totalVariableWidth, frame.StretchableWidth, ref remainingVariableWidth);
                    var targetRegion = new Rectangle (x, y, sw, sh);

                    if (vs.Mode != RenderMode.Tile && hs.Mode != RenderMode.Tile) {
                        var t = GetTile (frame, tileIndex, sourceRegion);
                        ctx.DrawImage (t, targetRegion);
                    } else {
                        double pw = hs.Size / frame.ScaleFactor;
                        double ph = vs.Size / frame.ScaleFactor;
                        if (hs.Mode == RenderMode.Stretch) {
                            pw = targetRegion.Width;
                        }
                        if (vs.Mode == RenderMode.Stretch) {
                            ph = targetRegion.Height;
                        }

                        ctx.Save ();
                        ctx.Translate (targetRegion.Location);
                        targetRegion.Location = Point.Zero;
                        ctx.Pattern = new ImagePattern (GetTile (frame, tileIndex, sourceRegion).WithSize (pw, ph));
                        ctx.NewPath ();
                        ctx.Rectangle (targetRegion);
                        ctx.Fill ();
                        ctx.Restore ();
                    }
                    x += sw;
                    xb += hs.Size;
                    tileIndex++;
                }
                yb += vs.Size;
                y += sh;
            }
            ctx.Restore ();
        }
        public virtual void Scale(Context ctx, double ax, double ay)
        {
            ctx.Save ();
            ctx.Translate (ax, ay);
            ctx.SetColor (Colors.Black);
            ctx.SetLineWidth (1);

            var x = 0d;
            var y = 0d;
            var w = 10d;
            var inc = .1d;
            for (var i = inc; i < 3.5d; i +=inc) {
                ctx.Save ();
                ctx.Scale (i, i);
                ctx.Rectangle (x, y, w, w);
                ctx.SetColor (Colors.Yellow.WithAlpha (1 / i));
                ctx.FillPreserve ();
                ctx.SetColor (Colors.Red.WithAlpha (1 / i));
                ctx.Stroke ();
                ctx.MoveTo (x += w * inc, y += w * inc / 3);
                ctx.Restore ();

            }

            ctx.Restore ();
        }
        protected sealed override void OnDraw(Context ctx, Rectangle bounds)
        {
            if (bounds.Width <= 0 || bounds.Height <= 0)
            {
                return;
            }

            var    frame                   = GetFrame(ctx.ScaleFactor);
            var    fixedWidth              = frame.Bitmap.Width - 2 - frame.StretchableWidth;
            var    fixedHeight             = frame.Bitmap.Height - 2 - frame.StretchableHeight;
            double totalVariableWidth      = bounds.Width - fixedWidth / frame.ScaleFactor;
            double totalVariableHeight     = bounds.Height - fixedHeight / frame.ScaleFactor;
            double remainingVariableHeight = totalVariableHeight;

            double y = bounds.Y, yb = 1;
            int    tileIndex = 0;

            ctx.Save();
            if (totalVariableWidth < 0)
            {
                if (fixedWidth > 0)
                {
                    ctx.Scale(bounds.Width / fixedWidth, 1);
                }
                totalVariableWidth = 0;
            }
            if (totalVariableHeight < 0)
            {
                if (fixedHeight > 0)
                {
                    ctx.Scale(1, bounds.Height / fixedHeight);
                }
                totalVariableHeight = 0;
            }

            foreach (var vs in frame.VerticalSections)
            {
                double sh = CalcSectionSize(frame, vs, totalVariableHeight, frame.StretchableHeight, ref remainingVariableHeight);

                double x = bounds.X, xb = 1;
                double remainingVariableWidth = totalVariableWidth;

                foreach (var hs in frame.HorizontalSections)
                {
                    var    sourceRegion = new Rectangle(xb, yb, hs.Size, vs.Size);
                    double sw           = CalcSectionSize(frame, hs, totalVariableWidth, frame.StretchableWidth, ref remainingVariableWidth);
                    var    targetRegion = new Rectangle(x, y, sw, sh);

                    if (vs.Mode != RenderMode.Tile && hs.Mode != RenderMode.Tile)
                    {
                        var t = GetTile(frame, tileIndex, sourceRegion);
                        ctx.DrawImage(t, targetRegion);
                    }
                    else
                    {
                        double pw = hs.Size / frame.ScaleFactor;
                        double ph = vs.Size / frame.ScaleFactor;
                        if (hs.Mode == RenderMode.Stretch)
                        {
                            pw = targetRegion.Width;
                        }
                        if (vs.Mode == RenderMode.Stretch)
                        {
                            ph = targetRegion.Height;
                        }

                        if (pw <= 0 || ph <= 0)
                        {
                            continue;
                        }

                        ctx.Save();
                        ctx.Translate(targetRegion.Location);
                        targetRegion.Location = Point.Zero;
                        ctx.Pattern           = new ImagePattern(GetTile(frame, tileIndex, sourceRegion).WithSize(pw, ph));
                        ctx.NewPath();
                        ctx.Rectangle(targetRegion);
                        ctx.Fill();
                        ctx.Restore();
                    }
                    x  += sw;
                    xb += hs.Size;
                    tileIndex++;
                }
                yb += vs.Size;
                y  += sh;
            }
            ctx.Restore();
        }
Beispiel #7
0
        bool Draw(Context ctx, Rectangle dirtyRect, double scale)
        {
            bool redraw = false;
            ctx.Save();
            ctx.Scale(scale, scale);

            // draw all edges
            foreach (PipelineNode pNode in nodes) {
                foreach (MarkerNode mNode in pNode.mNodes) {
                    if (!mNode.IsInput) {
                        mNode.DrawEdges(ctx);
                    }
                }
            }

            // draw all nodes
            foreach (PipelineNode node in nodes) {
                if (!mouseAction.HasFlag(MouseAction.MoveNode) || node != lastSelectedNode) {
                    if (node.bound.IntersectsWith(dirtyRect) || !initialScrollPosition.IsEmpty) {
                        if (node.Draw(ctx)) {
                            redraw = true;
                            QueueDraw(node.bound);
                        }
                    }
                }
            }

            // draw all markers
            foreach (PipelineNode pNode in nodes) {
                foreach (MarkerNode mNode in pNode.mNodes) {
                    mNode.Draw(ctx);
                }
            }

            // draw selected node last
            if (mouseAction.HasFlag(MouseAction.MoveNode)) {
                if (lastSelectedNode.Draw(ctx)) {
                    redraw = true;
                    QueueDraw(lastSelectedNode.bound);
                }
                foreach (MarkerNode mNode in lastSelectedNode.mNodes) {
                    mNode.Draw(ctx);
                }
            }

            ctx.Restore();
            return redraw;
        }