Exemple #1
0
        void OnExpose(object sender, EventArgs eventArgs)
        {
            DrawingArea drawingArea = this.tree;

            // Get drawing context
            Cairo.Context ctx = Gdk.CairoHelper.Create(drawingArea.GdkWindow);

            // Set initial point
            Cairo.PointD point = new Cairo.PointD()
            {
                X = 150.0,
                Y = 100.0,
            };

            //Setup text style
            ctx.SelectFontFace("Sans", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
            ctx.SetFontSize(15.0);


            // Set current and next point
            Cairo.PointD currentPoint = new Cairo.PointD
            {
                X = 200,
                Y = 125,
            };

            Cairo.PointD newPoint = new Cairo.PointD
            {
                X = 125,
                Y = 225,
            };
            this.DisplayTree(this.ast, ctx, currentPoint, 0, true, false);
        }
        void DrawAlphaBetaMarker(Cairo.Context c, ref Cairo.PointD bottomRight, string text)
        {
            c.SelectFontFace(SplashFontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Bold);
            c.SetFontSize(SplashFontSize);

            // Create a rectangle larger than the text so we can have a nice border
            // And round the value so we don't have a blurry rectangle.
            var extents   = c.TextExtents(text);
            var x         = Math.Round(bottomRight.X - extents.Width * 1.3);
            var y         = Math.Round(bottomRight.Y - extents.Height * 2.8);
            var rectangle = new Cairo.Rectangle(x, y, bottomRight.X - x, bottomRight.Y - y);

            // Draw the background color the text will be overlaid on
            DrawRectangle(c, rectangle);

            // Calculate the offset the text will need to be at to be centralised
            // in the border
            x = x + extents.XBearing + (rectangle.Width - extents.Width) / 2;
            y = y - extents.YBearing + (rectangle.Height - extents.Height) / 2;
            c.MoveTo(x, y);

            // Draw the text
            c.SetSourceRGB(1, 1, 1);
            c.ShowText(text);

            bottomRight.Y -= rectangle.Height - 2;
        }
Exemple #3
0
        /// <summary>
        /// Creates a bitmap for each character in the font.
        /// Characters that the font does not include will not be assigned a bitmap.
        /// </summary>
        private void CreateBitmaps()
        {
            characters = new Dictionary <char, PixelSet>();
            ImageSurface surface = new ImageSurface(Format.RGB24, 1, 1);
            Context      context = new Context(surface);

            context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal);
            context.SetFontSize(Font.Size);
            TextExtents ext   = context.TextExtents("@");
            int         charW = (int)Math.Ceiling(ext.Width);
            int         charH = (int)Math.Ceiling(ext.Height);

            context.Dispose();
            surface.Dispose();

            surface = new ImageSurface(Format.RGB24, charW, charH);
            context = new Context(surface);
            PixelSet missingChar = null;

            for (int i = 0; i < asciiString.Length; i++)
            {
                // Render one character into a PixelSet
                string asciiChar = string.Empty + asciiString[i];
                context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal);
                context.SetFontSize(Font.Size);
                context.SetSourceRGB(0.067, 0.067, 0.067);
                context.Paint();
                context.SetSourceRGB(1, 1, 1);
                ext = context.TextExtents(asciiChar);
                context.MoveTo(ext.XBearing, ext.YBearing * -1);
                context.ShowText(asciiChar);
                PixelSet ch = new PixelSet(surface);

                // Filter out characters the font doesn't include
                // The first character is always unprintable, and serves as
                // a reference for what unprintable characters look like in this font
                if (i == 0)
                {
                    missingChar = ch;
                    continue;
                }
                else if (ch == missingChar)
                {
                    continue;
                }
                characters.Add(asciiString[i], ch);
            }
            context.Dispose();
            surface.Dispose();

            // Add the space manually if it wasn't included
            if (!characters.ContainsKey(' '))
            {
                var en = characters.Values.GetEnumerator();
                en.MoveNext();
                characters.Add(' ', new PixelSet(en.Current.Width, en.Current.Height));
            }
        }
Exemple #4
0
        public static void DrawText(this Cairo.Context g, Rect rect, string text, double fontSize, Color fontColor)
        {
            g.SetSourceColor(fontColor);
            Point p = rect.TopLeft;

            g.MoveTo(p.ToPointD());
            g.SetFontSize(fontSize);
            g.ShowText(text);
        }
Exemple #5
0
        public override void DrawText(FormattedText formattedText, Point origin)
        {
            cr.Color = new Cairo.Color(formattedText.Foreground.R, formattedText.Foreground.G, formattedText.Foreground.B, formattedText.Foreground.Alfa);
            cr.MoveTo(origin.X, origin.Y + formattedText.Height);

            cr.SelectFontFace(formattedText.FontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
            cr.SetFontSize(formattedText.FontSize);

            cr.ShowText(formattedText.Text);
        }
        void DrawVersionNumber(Cairo.Context c, ref Cairo.PointD bottomRight, string text)
        {
            c.SelectFontFace(SplashFontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
            c.SetFontSize(SplashFontSize);

            var extents = c.TextExtents(text);

            c.MoveTo(bottomRight.X - extents.Width - 1, bottomRight.Y - extents.Height);

            c.SetSourceRGB(1, 1, 1);
            c.ShowText(text);
        }
Exemple #7
0
        public static void Draw(Cairo.Context ctx, object backend, double x, double y)
        {
            var la = (LayoutBackend)backend;

            var text = la.Text;

            var h = ctx.FontExtents.Ascent;

            y += h;

            ctx.MoveTo(x, y);

            if (la.Font != null)
            {
                ctx.SelectFont(la.Font);
                ctx.SetFontSize(la.Font.Size);
            }

            if (la.Width == -1)
            {
                ctx.ShowText(text);
                return;
            }

            if (!la.Measured)
            {
                Measure(backend);
            }

            // Render word by word

            int lastStart = 0;

            for (int i = 0; i < la.LineBreaks.Count; i++)
            {
                if (la.Heigth != -1 && h > la.Heigth)
                {
                    break;
                }

                var    n = la.LineBreaks [i];
                string s = text.Substring(lastStart, n - lastStart).TrimEnd('\n', '\r');
                ctx.ShowText(s);

                var lh = la.LineHeights [i];
                h += lh;
                y += lh;

                ctx.MoveTo(x, y);
                lastStart = n;
            }
        }
Exemple #8
0
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            _humidityValue = CurrentData.GetCurrentValueByIdString(XIVELY_DATA_STREAM_ID);

            GraphContainer.AssignXivelyDatastreamStringById(_graphId, XIVELY_DATA_STREAM_ID);

            GraphContainer.SetGraphColorById(_graphId, G, R, 0.4f);

            X = x;
            Y = y;

            surface.SetSourceRGBA(R, B, G, Alpha);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGB(R, G, B);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();

            string widgetText = _humidityValue + "%";

            surface.SetFontSize(15);
            Cairo.TextExtents text = surface.TextExtents(widgetText);

            surface.SetSourceRGBA(1, 1, 1, Alpha);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2));

            surface.ShowText(widgetText);

            widgetText = "Humidity";
            surface.SetFontSize(13);
            text = surface.TextExtents(widgetText);

            surface.SetSourceRGBA(0.98f, 0.5f, 0.4f, Alpha);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2) + 15);

            surface.ShowText(widgetText);
        }
		private void Measure ()
		{
			var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
			
			using (Cairo.Context cr = new Cairo.Context(surface)) {			
				cr.SelectFontFace (FontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
				cr.SetFontSize (FontSize);
			
				var textExtents = cr.TextExtents (Text);

				Width = textExtents.Width;
				Height = Math.Abs (textExtents.YBearing);		
				Extent = textExtents.Height;
			}
		}
        private void Measure()
        {
            var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 1, 1);

            using (Cairo.Context cr = new Cairo.Context(surface)) {
                cr.SelectFontFace(FontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
                cr.SetFontSize(FontSize);

                var textExtents = cr.TextExtents(Text);

                Width  = textExtents.Width;
                Height = Math.Abs(textExtents.YBearing);
                Extent = textExtents.Height;
            }
        }
Exemple #11
0
        TimerApp()
        {
            win = new Window("Timer Example");
            win.SetDefaultSize(260, 110);

            da = new DrawingArea();

            // For DeleteEvent
            Observable.FromEventPattern <DeleteEventArgs>(win, "DeleteEvent")
            .Subscribe(delegate
            {
                Application.Quit();
            });

            // For Timer
            Observable.Interval(TimeSpan.FromSeconds(1))
            .Subscribe(_ =>
            {
                Gtk.Application.Invoke(delegate
                {
                    da.QueueDraw();
                });
            });

            // For DrawingArea event
            Observable.FromEventPattern <DrawnArgs>(da, "Drawn")
            .Subscribe(args =>
            {
                Cairo.Context cr = args.EventArgs.Cr;

                cr.SetSourceRGB(0.5, 0.5, 0.5);
                cr.Paint();

                cr.SetFontSize(48);
                cr.MoveTo(20, 68);
                string date = DateTime.Now.ToString("HH-mm-ss");
                cr.SetSourceRGB(0.2, 0.23, 0.9);
                cr.ShowText(date);
                cr.Fill();

                ((IDisposable)cr).Dispose();

                args.EventArgs.RetVal = true;
            });

            win.Add(da);
            win.ShowAll();
        }
Exemple #12
0
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;
            Y = y;
            int waveTops    = Radius / 3;
            int waveBottoms = Radius / 2;
            int waveDepths  = Radius / 6;

            WaterTemperature = CurrentData.GetCurrentValueByIdFloat(XIVELY_DATA_STREAM_ID);
            //WaterTemperature = WaterTemperature / 100;


            // CIRCLE
            surface.SetSourceRGBA(1, 1, 1, 0.3);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGBA(1, 1, 1, WaterLight);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();
            surface.Fill();

            // WAVEFORMED CIRCLE
            surface.CurveTo(X - Radius, Y - waveDepths, X - waveBottoms, Y + waveDepths, X - waveTops, Y - waveDepths);
            surface.CurveTo(X - waveTops, Y - waveDepths, X, Y + waveDepths, X + waveTops, Y - waveDepths);
            surface.CurveTo(X + waveTops, Y - waveDepths, X + waveBottoms, Y + waveDepths, X + Radius, Y - waveDepths);
            surface.SetSourceRGBA(colorWater[0], colorWater[1], colorWater[2], alphaChannel);
            surface.Arc(X, Y, Radius, 0, Math.PI * 1);
            surface.Fill();

            // TEXT
            surface.SetSourceRGBA(1, 1, 1, 0.1);
            surface.MoveTo(X, Y);
            surface.SetFontSize(Radius / 2);
            string widgetText = Convert.ToString(WaterTemperature);

            Cairo.TextExtents text = surface.TextExtents(widgetText);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2));
            surface.ShowText(widgetText);
            surface.Fill();
        }
Exemple #13
0
        private void DrawLegends(Cairo.Context canvas)
        {
            canvas.SetFontSize(this.LegendsFontSize);
            canvas.SetSourceColor(this.AxisColor);

            this.DrawString(
                canvas,
                new Gdk.Point(
                    this.FrameWidth,
                    this.FramedEndPosition.Y + (this.FrameWidth / 2)),
                this.LegendX);

            this.DrawString(
                canvas,
                new Gdk.Point(
                    this.FramedOrgPosition.X - (this.FrameWidth / 2),
                    this.FrameWidth),
                this.LegendY);

            canvas.Stroke();
        }
        public void DrawAxisTitle(Cairo.Context cr, string text, int x, int y,
                                  Orientation orientation)
        {
            cr.Save();

            if (orientation == Orientation.Vertical)
            {
                cr.Translate(x, y);
                cr.Rotate(Math.PI / 2);
                cr.SetFontSize(AXIS_TITLE_FONT_SIZE);
                cr.SetSourceRGBA(CairoHelper.GetCairoColor(gtk_style.Foreground(state)).R, CairoHelper.GetCairoColor(gtk_style.Foreground(state)).G, CairoHelper.GetCairoColor(gtk_style.Foreground(state)).B, CairoHelper.GetCairoColor(gtk_style.Foreground(state)).A);

                //cr.Color = CairoHelper.GetCairoColor (gtk_style.Foreground (state));
                cr.ShowText(text);
            }
            else
            {
                DrawText(cr, AXIS_TITLE_FONT_SIZE, text, x, y);
            }

            cr.Restore();
        }
Exemple #15
0
        public static void DrawCaption(DrawingArea da, int width, int height, string text, double posX, double posY, double size = 3.75)
        {
            if (posX <= 1 && posY <= 1)
            {
                posX *= width;
                posY *= height;
            }

            Cairo.Context texTcr = Gdk.CairoHelper.Create(da.GdkWindow);

            texTcr.SelectFontFace("", Cairo.FontSlant.Normal, Cairo.FontWeight.Bold);
            texTcr.SetFontSize(size * width / 100f);
            texTcr.MoveTo(posX, posY);
            texTcr.TextPath(text);
            texTcr.SetSourceRGB(1, 1, 1);
            texTcr.FillPreserve();
            texTcr.LineWidth = width / 100f / 3;
            texTcr.SetSourceRGB(0, 0, 0);
            texTcr.Stroke();
            texTcr.Dispose();
            return;
        }
Exemple #16
0
        /// <summary>
        /// Draw on specified surface.
        /// </summary>
        /// <param name="surface">Surface.</param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;
            Y = y;

            surface.SetSourceRGB(R, G, B);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGBA(0, 0, 0, 0.5f);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();

            string widgetText = "Preferences";

            surface.SetFontSize(15);
            Cairo.TextExtents text = surface.TextExtents(widgetText);

            surface.SetSourceRGBA(1, 1, 1, _textAlpha);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2));

            surface.ShowText(widgetText);
        }
Exemple #17
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

            if (lines == null)
            {
                return;
            }

            gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight);
            gr.SetFontSize(Font.Size);

            Rectangle r = ClientRectangle;

            Foreground.SetAsSource(gr);

            double y = ClientRectangle.Y;
            double x = ClientRectangle.X;

            for (int i = 0; i < visibleLines; i++)
            {
                if (i + ScrollY >= Lines.Count)
                {
                    break;
                }
                //if ((lines [i + Scroll] as string).StartsWith ("error", StringComparison.OrdinalIgnoreCase)) {
                //	errorFill.SetAsSource (gr);
                //	gr.Rectangle (x, y, (double)r.Width, fe.Height);
                //	gr.Fill ();
                //	Foreground.SetAsSource (gr);
                //}
                gr.MoveTo(x, y + fe.Ascent);
                gr.ShowText(lines[i + ScrollY] as string);
                y += fe.Height;
                gr.Fill();
            }
        }
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;
            Y = y;

            string widgetText = "";

            if (Connection.IsAlive)
            {
                widgetText = "Online";
                surface.SetSourceRGB(R, G, B);
            }
            else
            {
                widgetText = "Offline";
                surface.SetSourceRGB(G, R, B);
            }

            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            if (!UserSettings.UserSetupCompleted)
            {
                surface.SetSourceRGB(1, 0, 0);
            }
            else
            {
                surface.SetSourceRGB(R, G, 0);
            }
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();

            surface.SetFontSize(15);
            Cairo.TextExtents text = surface.TextExtents(widgetText);
            surface.SetSourceRGBA(0, 0, 0, _textAlpha);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2));
            surface.ShowText(widgetText);


            if (!UserSettings.UserSetupCompleted)
            {
                widgetText = "Settings Incomplete";
                surface.SetFontSize(10);
                text = surface.TextExtents(widgetText);
                surface.SetSourceRGBA(0, 0, 0, Alpha);
                surface.MoveTo(X - (text.Width / 2), Y + (text.Height));
                surface.ShowText(widgetText);
            }
            if (!UserSettings.CorrectKey && UserSettings.UserSetupCompleted)
            {
                widgetText = "Settings Incomplete";
                surface.SetFontSize(10);
                text = surface.TextExtents(widgetText);
                surface.SetSourceRGBA(0, 0, 0, Alpha);
                surface.MoveTo(X - (text.Width / 2), Y + (text.Height) + 10);
                surface.ShowText(widgetText);
                widgetText = "Wrong Key";
                surface.SetFontSize(10);
                text = surface.TextExtents(widgetText);
                surface.SetSourceRGBA(0.4f, 0, 0, Alpha);
                surface.MoveTo(X - (text.Width / 2), Y + (text.Height) + (text.Height) + 10);
                surface.ShowText(widgetText);
            }
            if (UserSettings.CorrectKey && UserSettings.UserSetupCompleted)
            {
                widgetText = "Settings OK!";
                surface.SetFontSize(10);
                text = surface.TextExtents(widgetText);
                surface.SetSourceRGBA(0, 0, 0, _textAlpha);
                surface.MoveTo(X - (text.Width / 2), Y + (text.Height) + 10);
                surface.ShowText(widgetText);
            }
        }
Exemple #19
0
 public static void SetFont(this Cairo.Context cr, FontInfo fontInfo)
 {
     cr.SetSourceRGB(fontInfo.Color.Red, fontInfo.Color.Green, fontInfo.Color.Blue);
     cr.SelectFontFace(fontInfo.Family, fontInfo.Slant, fontInfo.Weight);
     cr.SetFontSize(fontInfo.Scale);
 }
Exemple #20
0
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            //PHValue = CurrentData.GetCurrentValueByIdFloat("ph");

            PHValue = CurrentData.GetCurrentValueByIdFloat(XIVELY_DATA_STREAM_ID);
            PHValue = PHValue % 14;

            X = x;
            Y = y;
            int barHeight = Radius / 2;
            //int barLength = Radius + (Radius / 2);
            int sectionSize      = Radius / 5;
            int pushLength       = sectionSize + 1;
            int amountOfSections = 8;

            int selectwidth  = Radius / 10;
            int selectHeight = Radius / 2;

            float phSelect      = (((float)sectionSize * (float)amountOfSections) / 14.0f) * PHValue;
            int   distanceOnBar = X - ((sectionSize * amountOfSections) / 2) + (int)phSelect;

            // CIRCLE
            surface.SetSourceRGBA(1, 1, 1, 0.3);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGBA(1, 1, 1, PHLight);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();
            surface.Fill();

            // WAVEFORMED CIRCLE
            surface.SetSourceRGB(0.8, 0.0, 0.0);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.6, 0.0, 0.0);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.4, 0.0, 0.0);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 2), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.3, 0.0, 0.0);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 3), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.0, 0.0, 0.3);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 4), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.0, 0.0, 0.4);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 5), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.0, 0.0, 0.6);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 6), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.0, 0.0, 0.8);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 7), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            // TEXT
            surface.SetSourceRGBA(1, 1, 1, 0.5);
            surface.MoveTo(X, Y);
            surface.SetFontSize(Radius / 2);
            string widgetText = Convert.ToString(PHValue);

            Cairo.TextExtents text = surface.TextExtents(widgetText);
            surface.MoveTo(distanceOnBar - (text.Width / 2), Y + (text.Height / 2) - barHeight);
            surface.ShowText(widgetText);
            surface.Fill();

            surface.SetSourceRGB(1, 1, 1);
            surface.Rectangle(distanceOnBar - (selectwidth / 2), Y - barHeight / 2, selectwidth, selectHeight);
            surface.Stroke();
            surface.Fill();
        }
Exemple #21
0
		public override void ComputeGeometry()
		{
			base.ComputeGeometry();

			// compute the font size
			if (ParentControl != null && ParentControl is Menu)
				_lastFontSize = (ParentControl as Menu).FontSize;
			else
				_lastFontSize = DefaultFontSize;
			
			// compute the text extents
			using (var cr = new Cairo.Context(DummySurface))
			{
				cr.SetFontSize(_lastFontSize);
				var extents = cr.TextExtents(Text);
				MinSize.X = extents.Width + 2 * Padding;
				MinSize.Y = extents.Height + 2 * Padding;
			}
			RenderSize = MinSize;
		}
Exemple #22
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

            if (events == null)
            {
                return;
            }

            gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight);
            gr.SetFontSize(Font.Size);

            Rectangle r = ClientRectangle;

            double y = ClientRectangle.Y;
            double x = ClientRectangle.X;

            int spaces = 0;

            uint [] evts;
            lock (eventsDic)
                evts = eventsDic.ToArray();

            int idx = Array.BinarySearch(evts, (uint)ScrollY);

            if (idx < 0)
            {
                idx = ~idx - 1;
            }
            if (idx < 0)
            {
                return;
            }

            int diff = ScrollY - (int)evts [idx];

            int i = 0;

            while (i < visibleLines)
            {
                if (idx >= events.Count)
                {
                    break;
                }
                //if ((lines [i + Scroll] as string).StartsWith ("error", StringComparison.OrdinalIgnoreCase)) {
                //	errorFill.SetAsSource (gr);
                //	gr.Rectangle (x, y, (double)r.Width, fe.Height);
                //	gr.Fill ();
                //	Foreground.SetAsSource (gr);
                //}

                BuildEventArgs evt = events[idx] as BuildEventArgs;

                if (evt is BuildMessageEventArgs)
                {
                    BuildMessageEventArgs msg = evt as BuildMessageEventArgs;
                    switch (msg.Importance)
                    {
                    case MessageImportance.High:
                        gr.SetSourceColor(Colors.White);
                        break;

                    case MessageImportance.Normal:
                        gr.SetSourceColor(Colors.Grey);
                        break;

                    case MessageImportance.Low:
                        gr.SetSourceColor(Colors.Jet);
                        break;
                    }
                }
                else if (evt is BuildStartedEventArgs)
                {
                    gr.SetSourceColor(Colors.White);
                }
                else if (evt is BuildFinishedEventArgs)
                {
                    gr.SetSourceColor(Colors.White);
                }
                else if (evt is BuildErrorEventArgs)
                {
                    gr.SetSourceColor(Colors.Red);
                }
                else if (evt is BuildEventArgs)
                {
                    gr.SetSourceColor(Colors.Yellow);
                }
                else if (evt is BuildStatusEventArgs)
                {
                    gr.SetSourceColor(Colors.Green);
                }

                string[] lines = Regex.Split(evt.Message, "\r\n|\r|\n|\\\\n");

                for (int j = diff; j < lines.Length; j++)
                {
                    gr.MoveTo(x, y + fe.Ascent);
                    gr.ShowText(new string (' ', spaces) + lines[j]);
                    y += fe.Height;
                    i++;
                    if (y > ClientRectangle.Bottom)
                    {
                        break;
                    }
                }
                diff = 0;
                idx++;

                gr.Fill();
            }
        }
Exemple #23
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

            Rectangle cb = new Rectangle(0, 0, designWidth, designHeight);

            gr.Save();

            double z = zoom / 100.0;

            gr.Scale(z, z);

            if (drawGrid)
            {
                double gridLineWidth = 0.2 / z;
                double glhw          = gridLineWidth / 2.0;
                int    nbLines       = cb.Width / gridSpacing;
                double d             = cb.Left + gridSpacing;
                for (int i = 0; i < nbLines; i++)
                {
                    gr.MoveTo(d - glhw, cb.Y);
                    gr.LineTo(d - glhw, cb.Bottom);
                    d += gridSpacing;
                }
                nbLines = cb.Height / gridSpacing;
                d       = cb.Top + gridSpacing;
                for (int i = 0; i < nbLines; i++)
                {
                    gr.MoveTo(cb.X, d - glhw);
                    gr.LineTo(cb.Right, d - glhw);
                    d += gridSpacing;
                }
                gr.LineWidth = gridLineWidth;
                Foreground.SetAsSource(gr, cb);
                gr.Stroke();
            }

            lock (imlVE.RenderMutex) {
                gr.SetSourceSurface(imlVE.surf, cb.Left, cb.Top);
                gr.Paint();
                imlVE.IsDirty = false;
            }

            /*if (Error == null) {
             *      gr.SetSourceColor (Color.Black);
             *      gr.Rectangle (cb, 1.0 / z);
             * } else {
             *      gr.SetSourceColor (Color.LavenderBlush);
             *      gr.Rectangle (cb, 2.0 / z);
             *      string[] lerrs = Error.ToString ().Split ('\n');
             *      Point p = cb.Center;
             *      p.Y -= lerrs.Length * 20;
             *      foreach (string le in lerrs) {
             *              drawCenteredTextLine(gr, p, le);
             *              p.Y += 20;
             *
             *      }
             * }
             * gr.Stroke ();*/

            Rectangle hr;

            if (SelectedItem?.Parent != null)
            {
                gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight);
                gr.SetFontSize(Font.Size);
                gr.FontOptions = Interface.FontRenderingOptions;
                gr.Antialias   = Interface.Antialias;

                Widget g = SelectedItem;
                hr = g.ScreenCoordinates(g.getSlot());

//				Rectangle rIcons = new Rectangle (iconSize);
//				rIcons.Width *= 4;
//				rIcons.Top = hr.Bottom;
//				rIcons.Left = hr.Right - rIcons.Width + iconSize.Width;
                Rectangle rIcoMove = new Rectangle(hr.BottomRight, iconSize);
//				Rectangle rIcoStyle = rIcoMove;
//				rIcoStyle.Left += iconSize.Width + 4;

                using (Surface mask = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) {
                    using (Context ctx = new Context(mask)) {
                        ctx.Save();
                        ctx.SetSourceRGBA(1.0, 1.0, 1.0, 0.4);
                        ctx.Paint();
                        ctx.Rectangle(hr);
                        ctx.Operator = Operator.Clear;
                        ctx.Fill();
                    }

                    gr.SetSourceSurface(mask, 0, 0);
                    gr.Paint();

                    using (Surface ol = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) {
                        using (Context ctx = new Context(ol)) {
                            ctx.SetSourceColor(Colors.Black);
                            drawDesignOverlay(ctx, g, cb, hr, 0.4 / z, 6.5);
                        }

                        gr.SetSourceSurface(ol, 0, 0);
                        gr.Paint();
                    }

                    drawIcon(gr, icoMove, rIcoMove);
                    //drawIcon (gr, icoStyle, rIcoStyle);
                }
            }
            if (HoverWidget != null)
            {
                hr = HoverWidget.ScreenCoordinates(HoverWidget.getSlot());
                gr.SetSourceColor(Colors.SkyBlue);
                //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0);
                gr.Rectangle(hr, 0.4 / z);
            }
            gr.Restore();
        }
Exemple #24
0
 public static void SelectTagOverlayFont(this Cairo.Context cr)
 {
     cr.SelectFontFace("Noto Mono", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
     cr.SetFontSize(12.0);
     cr.Antialias = Cairo.Antialias.Gray;
 }