Example #1
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));
 }
Example #2
0
        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 ();
            }
        }
Example #3
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 ();
        }
Example #4
0
 void DrawGradientButton(Xwt.Drawing.Context G, GradientButton B)
 {
     DrawingPath P = new DrawingPath();
     P.Rectangle(new Xwt.Rectangle(B.Position, B.Size));
     LinearGradient gr;
     G.AppendPath(P);
     Pattern pat = gr = new LinearGradient(B.Position.X, B.Position.Y, B.Position.X + B.Size.Width, B.Position.Y + B.Size.Height);
     gr.AddColorStop(0, B.Color.BlendWith(Colors.White, 0.8));
     gr.AddColorStop(0.5, B.Color);
     gr.AddColorStop(1, B.Color.BlendWith(Colors.White, 0.8));
     G.Pattern = pat;
     G.Fill();
     G.AppendPath(P);
     G.SetColor(Xwt.Drawing.Colors.Black);
     G.SetLineWidth(1);
     G.Stroke();
     TextLayout L = new TextLayout()
     {
         Font = B.Font,
         Text = B.Text
     };
     Size TextSize = new Size(0.6 * L.Font.Size * L.Text.Count(), L.Font.Size);
     G.DrawTextLayout(L, new Xwt.Point(B.Position.X + B.Size.Width / 2 - TextSize.Width / 2, B.Position.Y + B.Size.Height / 2 - TextSize.Height / 2));
 }
Example #5
0
        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();
        }
Example #6
0
        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);
        }
Example #7
0
 protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
 {
     ctx.SetColor(bg);
     ctx.Rectangle(dirtyRect);
     ctx.Fill();
 }
Example #8
0
        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 ();
        }
Example #9
0
		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 ();
		}
Example #10
0
        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();
        }
Example #11
0
        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();
            //}
        }