コード例 #1
0
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            ctx.Rectangle (0, 0, Bounds.Width, Bounds.Height);
            var g = new LinearGradient (0, 0, Bounds.Width, Bounds.Height);
            g.AddColorStop (0, new Color (1, 0, 0));
            g.AddColorStop (1, new Color (0, 1, 0));
            ctx.Pattern = g;
            ctx.Fill ();

            Rectangle r = rect.Inflate (5, 5);
            ctx.Rectangle (r);
            ctx.SetColor (new Color (0,0,1));
            ctx.SetLineWidth (1);
            ctx.Stroke ();
        }
コード例 #2
0
 protected override void OnDraw(Xwt.Drawing.Context ctx, Xwt.Rectangle dirtyRect)
 {
     ctx.Rectangle(dirtyRect);
     ctx.SetColor(Colors.White);
     ctx.Fill();
     this.Buttons.ForEach(X => DrawGradientButton(ctx, X));
 }
コード例 #3
0
ファイル: AddPluginWidget.cs プロジェクト: fourtf/4Plug
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            //ctx.SetColor(PluginType.GetColor());
            ctx.SetLineDash(0, 4d, 4d);
            ctx.Rectangle(0, 0, PluginWidget.Size.Width, PluginWidget.Size.Height);
            ctx.Stroke();
        }
コード例 #4
0
ファイル: DrawingTransforms.cs プロジェクト: pixelmeister/xwt
        protected override void OnDraw(Xwt.Drawing.Context ctx)
        {
            base.OnDraw (ctx);

            ctx.SetLineDash (15, 10, 10, 5, 5);
            ctx.Rectangle (100, 100, 100, 100);
            ctx.Stroke ();
            ctx.SetLineDash (0);

            ImageBuilder ib = new ImageBuilder (30, 30, ImageFormat.ARGB32);
            ib.Context.Arc (15, 15, 15, 0, 360);
            ib.Context.SetColor (new Color (1, 0, 1));
            ib.Context.Rectangle (0, 0, 5, 5);
            ib.Context.Fill ();
            var img = ib.ToImage ();
            ctx.DrawImage (img, 90, 90);
            ctx.DrawImage (img, 90, 140, 50, 10);

            ctx.Arc (190, 190, 15, 0, 360);
            ctx.SetColor (new Color (1, 0, 1, 0.4));
            ctx.Fill ();

            ctx.Save ();
            ctx.Translate (90, 220);
            ctx.Pattern = new ImagePattern (img);
            ctx.Rectangle (0, 0, 100, 70);
            ctx.Fill ();
            ctx.Restore ();

            ctx.Translate (30, 30);
            double end = 270;

            for (double n = 0; n<=end; n += 5) {
                ctx.Save ();
                ctx.Rotate (n);
                ctx.MoveTo (0, 0);
                ctx.RelLineTo (30, 0);
                double c = n / end;
                ctx.SetColor (new Color (c, c, c));
                ctx.Stroke ();
                ctx.Restore ();
            }
        }
コード例 #5
0
ファイル: LayoutWidget.cs プロジェクト: fourtf/4Plug
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            if (HasBorder)
            {
                ctx.SetColor(PluginType.GetColor());
                ctx.SetLineWidth(1);

                if (HasBorderLineDash)
                    ctx.SetLineDash(0, 4d, 4d);

                ctx.Rectangle(0, 0, WidthRequest, HeightRequest);
                ctx.Stroke();
            }
        }
コード例 #6
0
ファイル: RenderXwt.cs プロジェクト: hardsoft/My-FyiReporting
        private void DrawImageSized(PageImage pi, Xwt.Drawing.Image im, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            double height, width;      // some work variables
            StyleInfo si = pi.SI;

            Xwt.Rectangle r2 = new Xwt.Rectangle(r.X + PixelsX(si.PaddingLeft),
                                                      r.Y + PixelsY(si.PaddingTop),
                                                      r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                                      r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            Xwt.Rectangle ir;   // int work rectangle
            switch (pi.Sizing)
            {
                case ImageSizingEnum.AutoSize:

                    float imwidth = PixelsX( (float)im.Size.Width);
                    float imheight = PixelsX( (float)im.Size.Height);
                    ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                                    imwidth, imheight);

                    im.Scale((int)r2.Width, (int)r2.Height);
                    g.DrawImage(im, ir);

                    break;
                case ImageSizingEnum.Clip:
                    g.Save();
                    g.Rectangle(r2);
                    g.Clip();

                    ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                                    im.Size.Width, im.Size.Height);

                    g.DrawImage(im, ir);
                    g.Restore();
                    break;
                case ImageSizingEnum.FitProportional:
                    double ratioIm = (float)im.Size.Height / (float)im.Size.Width;
                    double ratioR = r2.Height / r2.Width;
                    height = r2.Height;
                    width = r2.Width;
                    if (ratioIm > ratioR)
                    {
                        // this means the rectangle width must be corrected
                        width = height * (1 / ratioIm);
                    }
                    else if (ratioIm < ratioR)
                    {
                        // this means the ractangle height must be corrected
                        height = width * ratioIm;
                    }
                    r2 = new Xwt.Rectangle(r2.X, r2.Y, width, height);
                    g.DrawImage(im, r2);
                    break;
                case ImageSizingEnum.Fit:
                default:
                    g.DrawImage(im, r2);
                    break;
            }
        }
コード例 #7
0
ファイル: DrawingText.cs プロジェクト: sergueik/xwt_swd
        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);
        }
コード例 #8
0
ファイル: ImageButton.cs プロジェクト: fourtf/4Plug
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            if (!Sensitive)
            {
                ctx.GlobalAlpha = .5d;
            }
            if (image == null)
            {
                ctx.SetColor(bg);
                ctx.Rectangle(dirtyRect);
                ctx.Fill();
            }
            else
                ctx.DrawImage(image, new Rectangle(0, 0, WidthRequest, HeightRequest));

            if (mOver && Sensitive)
            {
                ctx.SetColor(mOverColor);
                ctx.Rectangle(dirtyRect);
                ctx.Fill();
            }

            if (mDown)
            {
                ctx.SetColor(mOverColor);
                ctx.Rectangle(dirtyRect);
                ctx.Fill();
            }

            //ctx.SetColor(Colors.Red);
            //ctx.Rectangle(0, 0, WidthRequest, HeightRequest);
            //ctx.Stroke();
        }
コード例 #9
0
ファイル: EditorWidget.cs プロジェクト: fourtf/4Plug
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            var w = System.Diagnostics.Stopwatch.StartNew();
            base.OnDraw(ctx, dirtyRect);

            // char size
            var charSize = new TextLayout(this) { Text = "X", Font = font }.GetSize();
            double charWidth = CharWidth = charSize.Width;
            double charHeight = CharHeight = charSize.Height;

            // scroll bars
            updateScrollBars();

            // calculations
            int start = Math.Max(0, (int)(Source.ViewOffset.Y / charHeight));
            int end = Math.Min(Source.Count, (int)((Source.ViewOffset.Y + Size.Height) / charHeight));

            double lineNrWidth = ((int)Math.Log10(Source.Count) + 2) * CharWidth;
            TextXOffset = lineNrWidth - Source.ViewOffset.X;

            // selection
            Range selection = Source.Selection;
            bool hasSelection = !selection.IsEmpty;
            bool isRectSelection = selection.Type == SelectionType.Rectangular;

            // text
            for (int i = start; i < end; i++)
            {
                Line line = Source[i];
                string text = line.GetString();

                if (hasSelection)
                {
                    if (i >= selection.Start.Y && i <= selection.End.Y)
                    {
                        ctx.SetColor(Colors.LightSkyBlue);
                        if (isRectSelection)
                        {
                            ctx.Rectangle(selection.Start.X * charWidth + lineNrWidth - Source.ViewOffset.X,
                                (i * charHeight) - Source.ViewOffset.Y,
                                Math.Abs(selection.End.X - selection.Start.X) * charWidth,
                                charHeight);
                            ctx.Fill();
                        }
                        else
                        {
                            if (selection.Start.Y == selection.End.Y)
                            {
                                ctx.Rectangle(selection.Start.X * charWidth + TextXOffset, (i * charHeight) - Source.ViewOffset.Y, (selection.End.X - selection.Start.X) * charWidth + 2, charHeight);
                            }
                            else
                            {
                                if (i == selection.Start.Y)
                                    ctx.Rectangle(selection.Start.X * charWidth + TextXOffset, (i * charHeight) - Source.ViewOffset.Y, (Source[i].Count - selection.Start.X) * charWidth + 2, charHeight);
                                else if (i == selection.End.Y)
                                    ctx.Rectangle(TextXOffset, (i * charHeight) - Source.ViewOffset.Y, selection.End.X * charWidth + 2, charHeight);
                                else
                                    ctx.Rectangle(TextXOffset, (i * charHeight) - Source.ViewOffset.Y, Source[i].Count * charWidth + 2, charHeight);
                                ctx.Fill();
                            }
                        }
                    }
                }

                //ctx.SetColor(Colors.Black);
                //var layout = new TextLayout(this)
                //{
                //    Text = text,
                //    Font = font,
                //};
                //ctx.DrawTextLayout(layout, -Source.ViewOffset.X + lineNrWidth, (i * charHeight) - Source.ViewOffset.Y);
            }

            for (int ic = 0; ic < colors.Length; ic++)
            {
                ctx.SetColor(colors[ic]);
                CharpStyle style = (CharpStyle)ic;
                StringBuilder builder = new StringBuilder(1024);
                bool draw = false;

                for (int y = start; y < end; y++)
                {
                    Line line = Source[y];
                    for (int x = 0; x < line.Count; x++)
                    {
                        char c = line[x].Char;
                        if (c != ' ' && (line[x].Style & CharpStyle.ColorAll) == style)
                        {
                            if (c == '\t')
                                builder.Append(' ');
                            else
                            {
                                builder.Append(line[x].Char);
                                draw = true;
                            }
                        }
                        else
                            builder.Append(' ');
                    }
                    builder.AppendLine(" ");
                }

                TextLayout layout = new TextLayout(this)
                {
                    Text = builder.ToString(),
                    Font = font,
                };
                if (draw)
                    ctx.DrawTextLayout(layout, TextXOffset, 0);
            }

            // line left
            ctx.SetColor(Colors.LightGray);
            ctx.Rectangle(0, 0, lineNrWidth, Size.Height);
            ctx.Fill();

            // line numbers, markers
            for (int i = start; i < end; i++)
            {
                ctx.SetColor(Colors.Black);
                ctx.DrawTextLayout(new TextLayout(this) { Text = (i + 1).ToString(), Font = font }, 0, (i * charHeight) - Source.ViewOffset.Y);
                if ((Source[i].LineStyle & LineStyle.Unsaved) == LineStyle.Unsaved)
                {
                    ctx.SetColor(Colors.Red);
                    ctx.Rectangle(TextXOffset - charWidth / 2 - 1, (i * charHeight) - Source.ViewOffset.Y, 2, charHeight);
                    ctx.Fill();
                }
            }

            // caret
            Loc caret = Source.GetSanitizedLoc(Source.CaretPosition);
            ctx.Rectangle((int)(charWidth * caret.X - Source.ViewOffset.X + lineNrWidth), (int)(charHeight * caret.Y - Source.ViewOffset.Y), 2, charHeight);
            ctx.SetColor(Colors.Red);
            ctx.Fill();

            // stopwatch
            w.Stop();
            //Console.WriteLine("Drawing: " + w.Elapsed.TotalMilliseconds);
        }
コード例 #10
0
ファイル: PluginWidgetLayout.cs プロジェクト: fourtf/4Plug
 protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
 {
     ctx.SetColor(bg);
     ctx.Rectangle(dirtyRect);
     ctx.Fill();
 }
コード例 #11
0
ファイル: DrawingTransforms.cs プロジェクト: chkn/xwt
        protected override void OnDraw(Xwt.Drawing.Context ctx)
        {
            base.OnDraw (ctx);

            // Simple rectangles

            ctx.SetLineWidth (1);
            ctx.Rectangle (100, 5, 10, 10);
            ctx.SetColor (Color.Black);
            ctx.Fill ();

            ctx.Rectangle (115, 5, 10, 10);
            ctx.SetColor (Color.Black);
            ctx.Stroke ();

            //

            ctx.SetLineWidth (3);
            ctx.Rectangle (100, 20, 10, 10);
            ctx.SetColor (Color.Black);
            ctx.Fill ();

            ctx.Rectangle (115, 20, 10, 10);
            ctx.SetColor (Color.Black);
            ctx.Stroke ();

            // Rectangle with hole

            ctx.Rectangle (10, 100, 40, 40);
            ctx.MoveTo (45, 135);
            ctx.RelLineTo (0, -20);
            ctx.RelLineTo (-20, 0);
            ctx.RelLineTo (0, 20);
            ctx.ClosePath ();
            ctx.SetColor (Color.Black);
            ctx.Fill ();

            // Dashed lines

            ctx.SetLineDash (15, 10, 10, 5, 5);
            ctx.Rectangle (100, 100, 100, 100);
            ctx.Stroke ();
            ctx.SetLineDash (0);

            ImageBuilder ib = new ImageBuilder (30, 30, ImageFormat.ARGB32);
            ib.Context.Arc (15, 15, 15, 0, 360);
            ib.Context.SetColor (new Color (1, 0, 1));
            ib.Context.Rectangle (0, 0, 5, 5);
            ib.Context.Fill ();
            var img = ib.ToImage ();
            ctx.DrawImage (img, 90, 90);
            ctx.DrawImage (img, 90, 140, 50, 10);

            ctx.Arc (190, 190, 15, 0, 360);
            ctx.SetColor (new Color (1, 0, 1, 0.4));
            ctx.Fill ();

            ctx.Save ();
            ctx.Translate (90, 220);
            ctx.Pattern = new ImagePattern (img);
            ctx.Rectangle (0, 0, 100, 70);
            ctx.Fill ();
            ctx.Restore ();

            ctx.Translate (30, 30);
            double end = 270;

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

            ctx.ResetTransform ();
        }
コード例 #12
0
ファイル: CanvasWithWidget.cs プロジェクト: m13253/xwt
		protected override void OnDraw (Xwt.Drawing.Context ctx, Rectangle dirtyRect)
		{
			if (Bounds.IsEmpty)
				return;

			ctx.Rectangle (0, 0, Bounds.Width, Bounds.Height);
			Gradient g = null;
			if (Linear)
				g = new LinearGradient (xStart, 0, xEnd, Bounds.Height);
			else
				g = new RadialGradient (Bounds.Width / 2, Bounds.Height / 2, Bounds.Width / 2, Bounds.Width / 2, Bounds.Height / 2, xStart/4 + Bounds.Width / 8);

			g.AddColorStop (0, stop1);
			g.AddColorStop (1, stop2);
			ctx.Pattern = g;
			ctx.Fill ();
			
			Rectangle r = rect.Inflate (5, 5);
			ctx.Rectangle (r);
			ctx.SetColor (new Color (0,0,1));
			ctx.SetLineWidth (1);
			ctx.Stroke ();
		}
コード例 #13
0
ファイル: PluginWidget.cs プロジェクト: fourtf/4Plug
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            //bg
            ctx.SetColor(installed ? BgColorInstalled : BgColorUninstalled);
            //ctx.SetColor(Colors.White);
            ctx.Rectangle(dirtyRect);
            ctx.Fill();

            //border
            ctx.SetColor(installed ? BorderColorInstalled : BorderColorUninstalled);
            ctx.SetLineWidth(1);
            ctx.Rectangle(0, 0, WidthRequest, HeightRequest);
            ctx.Stroke();
        }
コード例 #14
0
ファイル: PluginWidget.cs プロジェクト: fourtf/4Plug
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            //bg
            //ctx.SetColor(installed ? BgColorInstalled : BgColorUninstalled);
            //ctx.SetColor(Disabled ? Colors.Gray.WithAlpha(.15) : (installed ? PluginType.GetBGColor() : Colors.White));
            ctx.SetColor(installed ? PluginType.GetBGColor() : Colors.White);
            //ctx.SetColor(Colors.White);
            ctx.Rectangle(dirtyRect);
            ctx.Fill();

            //border
            //ctx.SetColor(installed ? BorderColorInstalled : BorderColorUninstalled);
            //ctx.SetColor(installed ? PluginType.GetColor() : Colors.White); // Color.FromBytes(220, 220, 220));
            ctx.SetColor(SettingsActive ? Colors.Gray : PluginType.GetColor());
            ctx.SetLineWidth(1);

            if (!installed)
                ctx.SetLineDash(0, 1, 3);
            ctx.Rectangle(0, 0, WidthRequest, HeightRequest);
            ctx.Stroke();

            //if (Disabled)
            //{
            //    ctx.SetColor(new Color(1, .5, 0, .1));
            //    ctx.Rectangle(dirtyRect);
            //    ctx.Fill();
            //}
        }