Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
0
        public static void ShadowedText(Cairo.Context g, Cairo.Color c, string text, double x, double y)
        {
            g.Save();

            g.MoveTo(x + Graphics.SHADOW_SPACING, y + Graphics.SHADOW_SPACING);
            g.Color = new Cairo.Color(0, 0, 0);
            g.ShowText(text);

            g.MoveTo(x, y);
            g.Color = c;
            g.ShowText(text);

            g.Restore();
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
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));
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public static void SaveToPng(List <LibTessDotNet.ContourVertex> path)
        {
            if (path == null || path.Count <= 1)
            {
                return;
            }
            using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.Argb32, (int)Form.current.Size.Width, (int)Form.current.Size.Height))
                using (Cairo.Context g = new Cairo.Context(surface))
                {
                    g.MoveTo(path[0].Position.X, path[0].Position.Y);
                    for (int i = 1; i < path.Count; i++)
                    {
                        var x0 = path[i - 1].Position.X;
                        var y0 = path[i - 1].Position.Y;
                        var x1 = path[i].Position.X;
                        var y1 = path[i].Position.Y;

                        g.LineTo(x1, y1);

                        {
                            // draw index number
                            g.RelMoveTo(5, 5);
                            g.ShowText(i.ToString());
                            g.MoveTo(x1, y1);

                            // draw arrow
                            var dx = x1 - x0;
                            var dy = y1 - y0;

                            if (MathEx.AmostZero(dx) && MathEx.AmostZero(dy))
                            {
                                continue;
                            }

                            var n0 = new Vector(-dy, dx); n0.Normalize();
                            var n1 = new Vector(dy, -dx); n1.Normalize();

                            var B = new Point(x1, y1);
                            var d = new Vector(x0 - x1, y0 - y1); d.Normalize();

                            var arrowEnd0 = B + 5 * (d + n0);
                            var arrowEnd1 = B + 5 * (d + n1);
                            g.MoveTo(x1, y1);
                            g.LineTo(new Cairo.PointD(arrowEnd0.X, arrowEnd0.Y));
                            g.MoveTo(x1, y1);
                            g.LineTo(new Cairo.PointD(arrowEnd1.X, arrowEnd1.Y));
                            g.MoveTo(x1, y1);
                        }
                    }
                    g.Stroke();
                    surface.WriteToPng(@"D:\contour_test.png");
                }
        }
        public static void DrawText(Cairo.Context context, float x, float y, double angle, string text)
        {
            var ext = context.TextExtents(text);

            context.Save();
            context.Translate(x, y);
            context.Rotate(angle - Math.PI / 2);
            context.Translate(-ext.Width / 2, 0);
            context.ShowText(text);
            context.Stroke();

            context.Restore();
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 13
0
        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();
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Draws the Axis and other componets of the chart
        /// </summary>
        /// <param name="height">Height of drawing area.</param>
        /// <param name="width">Width of drawing area.</param>
        /// <param name="canvas">The cairo context.</param>
        void DrawAxis(int height, int width, Cairo.Context canvas)
        {
            Char[] VALUE = this.ValueLabel.ToCharArray();

            //Draws the Legend of the chart
            DrawLegendAndTitle(height, width, canvas);

            canvas.SetSourceRGB(0, 0, 0);

            //Set the Axis labels
            canvas.MoveTo(XStart, Padding + 15);
            canvas.ShowText(Encoding.UTF8.GetBytes(VALUE));
            canvas.Stroke();

            //Create the Axis with the markers
            canvas.LineWidth = 4;
            canvas.MoveTo(XStart, YStart);
            canvas.LineTo(XStart, YEnd);
            canvas.LineTo(XEnd, YEnd);

            canvas.Stroke();

            // .... creates de Y markers

            double totalHeigth    = (YEnd - YStart);
            double intervalHeight = totalHeigth / ValueResolution;

            for (double i = 0; i <= ValueResolution; i++)
            {
                canvas.LineWidth = 0.5;
                canvas.SetSourceRGB(0, 0, 0);
                string value = (((MinValue * PixelsPerUnit) + ((((MaxValue * PixelsPerUnit) - (MinValue * PixelsPerUnit)) / ValueResolution) * (ValueResolution - i))) / PixelsPerUnit).ToString();

                canvas.MoveTo(XStart - ((value.Length + 1) * widthByChar), YStart + i * intervalHeight);
                canvas.ShowText(Encoding.UTF8.GetBytes(value));

                canvas.MoveTo(XStart - lenghtLineValue, YStart + i * intervalHeight);
                canvas.LineTo((!ShowGridLines) ? XStart : XEnd, YStart + i * intervalHeight);

                canvas.Stroke();
            }

            // .... creates de X markers
            //If dont exist Custom Data Set, Default set wil be Draw.
            Boolean drawSetDefault = (GetSetCount() == 0);

            double totalWidth = (XEnd - XStart);

            if (drawSetDefault)
            {
                int    numBars        = data["Default"].Count;
                int    actualBar      = 0;
                double maxWidthPerBar = (totalWidth - PaddingSets * 2) / (double)(numBars);
                foreach (BarData bd in data["Default"])
                {
                    canvas.LineWidth = 0.5;
                    canvas.SetSourceRGB(0, 0, 0);
                    string value = bd.Name;

                    canvas.MoveTo(XStart + PaddingSets + (actualBar * maxWidthPerBar) + (maxWidthPerBar / 2) - ((value.Length * PixelsPerUnit) / 2), YEnd + 15);
                    canvas.ShowText(Encoding.UTF8.GetBytes(value));

                    canvas.MoveTo(XStart + PaddingSets + (actualBar * maxWidthPerBar) + (maxWidthPerBar), YEnd + lenghtLineValue);
                    canvas.LineTo(XStart + PaddingSets + (actualBar * maxWidthPerBar) + (maxWidthPerBar), YEnd);

                    canvas.Stroke();

                    actualBar++;
                }

                return;
            }

            int    Sets           = GetSetCount();
            double maxWidthPerSet = (totalWidth / (double)Sets);

            int actualSet = 0;

            foreach (String key in GetSetIds())
            {
                if (key.Equals("Default"))
                {
                    continue;
                }

                int    numBars   = data[key].Count;
                double XSetStart = XStart + maxWidthPerSet * actualSet;
                double XSetEnd   = XSetStart + maxWidthPerSet;

                canvas.LineWidth = 0.5;
                canvas.SetSourceRGB(0, 0, 0);
                string value = key;

                canvas.MoveTo(XSetStart + maxWidthPerSet / 2, YEnd + 15);
                canvas.ShowText(Encoding.UTF8.GetBytes(value));

                canvas.MoveTo(XSetEnd, YEnd + lenghtLineValue);
                canvas.LineTo(XSetEnd, YEnd);

                canvas.Stroke();
                actualSet++;
            }
        }
Exemplo n.º 18
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();
        }
Exemplo n.º 19
0
        private void DisplayTree(CoreParser.Parser.AST.Node n, Cairo.Context ctx, Cairo.PointD currentPoint, int level, bool left, bool leftTree)
        {
            // Init width and height
            int width  = 0;
            int height = 0;

            // Get window size
            this.GetSize(out width, out height);


            // Set y value
            double y = (level * 50) + 15;

            // initialise x value
            double x = 0;


            // Calculate x value
            if (level == 0)
            {
                x = (width) - 50;
                ctx.MoveTo(x, y);
                //ctx.ShowText(n.Token);
            }
            else
            {
                if (leftTree)
                {
                    x = currentPoint.X - 50.0;
                }
                else
                {
                    x = currentPoint.X + 45.0;
                }
            }
            if (n.HasChildren())
            {
                // Get node's children
                int childrenLength = n.Children().Count;
                for (int i = 0; i < childrenLength; i++)
                {
                    // loop over children and calc level
                    CoreParser.Parser.AST.Node node = n.Children()[i];
                    y = ((level + 1) * 20) + 15;

                    // Calculate left or right
                    if (i % 2 == 0)
                    {
                        x = x - 50.0;

                        if (node.HasChildren())
                        {
                            DisplayTree(node, ctx, new Cairo.PointD
                            {
                                X = x + 45,
                                Y = y,
                            }, level + 1, true, true);
                        }
                    }
                    else
                    {
                        x = x + 100.0;

                        if (node.HasChildren())
                        {
                            DisplayTree(node, ctx, new Cairo.PointD
                            {
                                X = x + 65,
                                Y = y,
                            }, level + 1, true, true);
                        }
                    }
                    // Render the node's value to the window
                    ctx.MoveTo(x, y);
                    ctx.ShowText(node.Token.token);
                }
            }
        }
Exemplo n.º 20
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();
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Draws the Axis and other componets of the chart
        /// </summary>
        /// <param name="height">Height of drawing area.</param>
        /// <param name="width">Width of drawing area.</param>
        /// <param name="canvas">The cairo context.</param>
        void DrawAxis(int height, int width, Cairo.Context canvas)
        {
            Char[] Y = this.YLabel.ToCharArray();
            Char[] X = this.XLabel.ToCharArray();

            //Draws the Legend of the chart
            DrawLegendAndTitle(height, width, canvas);

            canvas.SetSourceRGB(0, 0, 0);



            //Set the Axis labels
            canvas.MoveTo(XStart, Padding + 15);
            canvas.ShowText(Encoding.UTF8.GetBytes(Y));
            canvas.Stroke();
            //canvas.MoveTo(width - (Padding + (X.Length * widthByChar)), height - Padding);
            canvas.MoveTo(width - (Padding + (X.Length * widthByChar)), YEnd + 30);
            canvas.ShowText(Encoding.UTF8.GetBytes(X));
            canvas.Stroke();
            //Create the Axis X and Y with the markers
            canvas.LineWidth = 4;
            canvas.MoveTo(XStart, YStart);
            canvas.LineTo(XStart, YEnd);
            canvas.LineTo(XEnd, YEnd);

            canvas.Stroke();

            // .... creates de Y markers

            double totalHeigth    = (YEnd - YStart);
            double intervalHeight = totalHeigth / YResolution;

            for (double i = 0; i <= YResolution; i++)
            {
                canvas.LineWidth = 0.5;
                canvas.SetSourceRGB(0, 0, 0);
                string value = (((MinYValue * PixelsPerUnit) + ((((MaxYValue * PixelsPerUnit) - (MinYValue * PixelsPerUnit)) / YResolution) * (YResolution - i))) / PixelsPerUnit).ToString();

                canvas.MoveTo(XStart - ((value.Length + 1) * widthByChar), YStart + i * intervalHeight);
                canvas.ShowText(Encoding.UTF8.GetBytes(value));

                canvas.MoveTo(XStart - lenghtLineValue, YStart + i * intervalHeight);
                canvas.LineTo((!ShowGridLines) ? XStart : XEnd, YStart + i * intervalHeight);

                canvas.Stroke();
            }

            // .... creates de X markers
            double totalWidth    = (XEnd - XStart);
            double intervalWidth = totalWidth / XResolution;

            for (double i = 0; i <= XResolution; i++)
            {
                canvas.LineWidth = 0.5;
                canvas.SetSourceRGB(0, 0, 0);
                string value = (((MinXValue * PixelsPerUnit) + ((((MaxXValue * PixelsPerUnit) - (MinXValue * PixelsPerUnit)) / XResolution) * i)) / PixelsPerUnit).ToString();

                canvas.MoveTo(XStart + i * intervalWidth - ((value.Length * PixelsPerUnit) / 2), YEnd + 15);
                canvas.ShowText(Encoding.UTF8.GetBytes(value));

                canvas.MoveTo(XStart + i * intervalWidth, YEnd + lenghtLineValue);
                canvas.LineTo(XStart + i * intervalWidth, (!ShowGridLines) ? YEnd : YStart);

                canvas.Stroke();
            }
            canvas.SetSourceRGB(0, 0, 0);
        }
Exemplo n.º 22
0
 private void DrawString(Cairo.Context canvas, Gdk.Point pos, string text)
 {
     canvas.MoveTo(pos.X, pos.Y);
     canvas.ShowText(text);
 }
Exemplo n.º 23
0
        bool DrawLegendAndTitle(int height, int width, Cairo.Context canvas)
        {
            canvas.MoveTo((width / 2) - ((Title.Length / 2) * widthByChar), Padding);
            canvas.ShowText(Encoding.UTF8.GetBytes(Title));

            Char[] Y = this.YLabel.ToCharArray();

            if (ShowLegend)
            {
                int count = GetSetCount();
                if (count != 0)
                {
                    IconosLeyenda = new Dictionary <string, Cairo.Rectangle>();

                    List <String> keys = data.Keys.ToList();
                    keys.Sort();

                    int ItemLegendMaxWidth = 0;
                    int i = 0;
                    foreach (String set in keys)
                    {
                        canvas.SetSourceRGB(0, 0, 0);
                        if (set.Equals("Default"))
                        {
                            continue;
                        }


                        canvas.MoveTo(Padding, height / 2 - (15 * (i - count / 2)));
                        canvas.ShowText(Encoding.UTF8.GetBytes(set));
                        canvas.Stroke();


                        //Console.WriteLine(ColorSets[set].R + " " + ColorSets[set].G + " " + ColorSets[set].B);
                        canvas.SetSourceRGB(ColorSets[set].R, ColorSets[set].G, ColorSets[set].B);

                        canvas.LineWidth = 1;
                        Cairo.Rectangle rect = new Cairo.Rectangle(new Cairo.Point(Padding - 14, height / 2 - (15 * (i - count / 2))), 10, -10);
                        canvas.Rectangle(rect);
                        IconosLeyenda.Add(set, rect);
                        canvas.Fill();
                        canvas.Stroke();


                        if (set.Length > ItemLegendMaxWidth)
                        {
                            ItemLegendMaxWidth = set.Length;
                        }
                        i++;
                    }

                    XStart = Padding + ((ItemLegendMaxWidth + 1) * widthByChar) + ((Y.Length + 1) * widthByChar);
                    XEnd   = width - Padding;

                    YStart = Padding + 30;
                    YEnd   = height - (Padding + 30);
                    return(true);
                }
            }
            XStart = Padding;
            XEnd   = width - Padding;

            YStart = Padding + 30;
            YEnd   = height - (Padding + 30);

            return(false);
        }
Exemplo n.º 24
0
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            //base.OnPaint(pe);
            Cairo.Context dc = Gdk.CairoHelper.Create(args.Window);

            // Draw white background
            //Graphics dc = pe.Graphics;
            dc.IdentityMatrix();

            dc.SetSourceRGB(1.0, 1.0, 1.0);
            dc.Rectangle(0, 0, Allocation.Width, Allocation.Height);
            dc.Fill();

            // Draw the raster
            Cairo.Matrix t = TheRasterModel.GetTikzToScreenTransform().ToCairoMatrix();
            //t.Freeze();

            dc.Save();

            dc.LineWidth = 0.01;            // todo: always 1 pixel
            dc.SetSourceRGB(0.7, 0.7, 0.7); // whitesmoke?
            {
                dc.Transform(t);

                TheRasterModel.DrawRaster(
                    (p1, p2) => { dc.MoveTo(p1.X, p1.Y); dc.LineTo(p2.X, p2.Y); dc.Stroke(); },
                    (r1, r2) =>
                {
                    dc.DrawEllipse(0, 0, 2 * r1, 2 * r2);
                });
            }

            dc.Restore();

            // draw unavailable note
            if (TheDisplayModel.IsUnavailable)
            {
                dc.SetSourceRGB(0, 0, 0);
                dc.SelectFontFace("Arial", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
                //StringFormat f = new StringFormat();
                //f.Alignment = StringAlignment.Center;
                //f.LineAlignment = StringAlignment.Center;
                //dc.DrawString("<Unavailable>", new Font("Arial", 16), Brushes.Black, ClientRectangle, f);
                dc.MoveTo(Allocation.Width / 2, Allocation.Height / 2); //todo
                dc.ShowText("<Unavailable>");
            }

            // draw the pdf image
            if (TheDisplayModel.IsImageVisible && TheDisplayModel.Bmp != null)
            {
                Point p = new Point((Allocation.Width - TheDisplayModel.Bmp.Width) / 2, (Allocation.Height - TheDisplayModel.Bmp.Height) / 2);
                //dc.DrawImageUnscaled(TheDisplayModel.Bmp, p);
                dc.SetSource(TheDisplayModel.Bmp, p.X, p.Y);
                //dc.Rectangle(p.X, p.Y, TheDisplayModel.Bmp.Width, TheDisplayModel.Bmp.Height);
                dc.Paint();
            }

            // draw the overlay
            if (ShowOverlay)
            {
                dc.SetSourceRGB(0, 0, 0);
                // draw shapes from parsetree
                foreach (var osv in OSViews)
                {
                    osv.Draw(dc);
                }

                // draw (visible) auxiliary shapes
                foreach (var ps in PreviewShapes.Where(o => o.Visible))
                {
                    ps.Draw(dc);
                }
            }

            // draw adorner(s)
            foreach (var scope in this.OSViews.OfType <OverlayScopeView>().Where(v => v.IsAdornerVisible))
            {
                dc.SetSourceRGB(0.5, 0.5, 0.5);
                dc.LineWidth = 5;
                System.Windows.Rect ShowAt = scope.GetBB(Allocation.Height);
                ShowAt.Inflate(6, 6);

                dc.Rectangle(ShowAt.ToCairoRectangle());  //(PensAndBrushes.AdornerPen, ShowAt.ToRectangleF());
                dc.Stroke();
            }


            // draw the object marker
            if (MarkObject_ShowMarker && MarkObject_Marked != null)
            {
                System.Windows.Rect ShowAt = MarkObject_Marked.GetBB(Allocation.Height);
                ShowAt.Inflate(15, 15);
                //using (Pen p = new Pen(Brushes.Red, 6))
                {
                    dc.SetSourceRGB(1, 0, 0);
                    dc.LineWidth = 6;
                    dc.DrawEllipse(ShowAt);//p,
                }
            }

            ((IDisposable)dc.Target).Dispose();
            ((IDisposable)dc).Dispose();

            return(true);
        }