Ejemplo n.º 1
0
        public void DrawBar(Cairo.Context cr, PlotColor color, int x, int y, int width, int height, bool is_focused)
        {
            // Draw the fill
            cr.Rectangle(x, y, width, height);
            Cairo.Color fill = colors[(int)color];
            fill.A = 0.6;
            //cr.Color = fill;
            cr.SetSourceRGBA(fill.R, fill.G, fill.B, fill.A);
            cr.Fill();

            // Stroke just the top, left and right sides
            cr.MoveTo(x - DEFUZZ, y + height - DEFUZZ);
            cr.RelLineTo(0, -height);
            cr.RelLineTo(width, 0);
            cr.RelLineTo(0, height);

            // decrease saturation by 40%
            //cr.Color = CairoHelper.Darken (colors[(int)color], 0.4f);
            cr.SetSourceRGBA(CairoHelper.Darken(colors[(int)color], 0.4f).R, CairoHelper.Darken(colors[(int)color], 0.4f).G, CairoHelper.Darken(colors[(int)color], 0.4f).B, CairoHelper.Darken(colors[(int)color], 0.4f).A);

            cr.LineWidth = 1.0f;

            cr.Stroke();

            if (is_focused)
            {
                DrawFocusRect(cr, x - FOCUS_BORDER, y - FOCUS_BORDER,
                              width + (FOCUS_BORDER * 2), height + FOCUS_BORDER);
            }
        }
Ejemplo n.º 2
0
        void RenderLineNumberIcon(Widget widget, Cairo.Context cr, Gdk.Rectangle cell_area, int markupHeight, int yOffset)
        {
            if (!IsStackFrame)
            {
                return;
            }

            cr.Save();

                        #if CENTER_ROUNDED_RECTANGLE
            cr.Translate(cell_area.X + Padding, (cell_area.Y + (cell_area.Height - RoundedRectangleHeight) / 2.0));
                        #else
            cr.Translate(cell_area.X + Padding, cell_area.Y + Padding + yOffset);
                        #endif

            cr.Antialias = Cairo.Antialias.Subpixel;

            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.Clip();

            if (IsUserCode)
            {
                cr.SetSourceRGBA(0.90, 0.60, 0.87, 1.0);                  // 230, 152, 223
            }
            else
            {
                cr.SetSourceRGBA(0.77, 0.77, 0.77, 1.0);                  // 197, 197, 197
            }
            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.Fill();

            cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.11);
            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.LineWidth = 2;
            cr.Stroke();

            using (var layout = PangoUtil.CreateLayout(widget, LineNumber != -1 ? LineNumber.ToString() : "???")) {
                layout.Alignment       = Pango.Alignment.Left;
                layout.FontDescription = LineNumberFont;

                int width, height;
                layout.GetPixelSize(out width, out height);

                double y_offset = (RoundedRectangleHeight - height) / 2.0;
                double x_offset = (RoundedRectangleWidth - width) / 2.0;

                // render the text shadow
                cr.Save();
                cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.34);
                cr.Translate(x_offset, y_offset + 1);
                cr.ShowLayout(layout);
                cr.Restore();

                cr.SetSourceRGBA(1.0, 1.0, 1.0, 1.0);
                cr.Translate(x_offset, y_offset);
                cr.ShowLayout(layout);
            }

            cr.Restore();
        }
Ejemplo n.º 3
0
        protected virtual void PaintFill()
        {
            double r, g, b;

            r = (double)fillColor.Red / ushort.MaxValue;
            g = (double)fillColor.Green / ushort.MaxValue;
            b = (double)fillColor.Blue / ushort.MaxValue;

            cairo.Save();
            GetFrame(cairo);

            if (!drawGradient)
            {
                cairo.SetSourceRGBA(r, g, b, fillAlpha);
            }
            else
            {
                using (var grad = CreateGradient()) {
                    cairo.SetSource(grad);
                }
            }

            cairo.FillPreserve();
            cairo.Restore();
        }
Ejemplo n.º 4
0
        public void DrawEventTag(Cairo.Context cr, PlotColor color,
                                 int x, int y, Orientation orientation)
        {
            cr.MoveTo(x + DEFUZZ, y);

            if (orientation == Orientation.Vertical)
            {
                cr.RelLineTo(-1 * EVENT_TAG_HALF_WIDTH, -1 * EVENT_TAG_SEGMENT_HEIGHT);
                cr.RelLineTo(0, -2 * EVENT_TAG_SEGMENT_HEIGHT);
                cr.RelLineTo(EVENT_TAG_HALF_WIDTH * 2, 0);
                cr.RelLineTo(0, 2 * EVENT_TAG_SEGMENT_HEIGHT);
            }
            else
            {
                cr.RelLineTo(EVENT_TAG_SEGMENT_HEIGHT, -1 * EVENT_TAG_HALF_WIDTH);
                cr.RelLineTo(EVENT_TAG_SEGMENT_HEIGHT * 2, 0);
                cr.RelLineTo(0, EVENT_TAG_HALF_WIDTH * 2);
                cr.RelLineTo(-2 * EVENT_TAG_SEGMENT_HEIGHT, 0);
            }

            cr.ClosePath();
            //cr.Color = CairoHelper.GetCairoColor (gtk_style.Base (state));
            cr.SetSourceRGBA(CairoHelper.GetCairoColor(gtk_style.Base(state)).R, CairoHelper.GetCairoColor(gtk_style.Base(state)).G, CairoHelper.GetCairoColor(gtk_style.Base(state)).B, CairoHelper.GetCairoColor(gtk_style.Base(state)).A);

            cr.FillPreserve();

            cr.LineWidth = 1.0f;
            //cr.Color = colors[(int)color];
            cr.SetSourceRGBA(colors[(int)color].R, colors[(int)color].G, colors[(int)color].B, colors[(int)color].A);

            cr.Stroke();
        }
Ejemplo n.º 5
0
        public void DrawSelectionRectangle(Cairo.Context cr, int x, int y, int width, int height)
        {
            cr.Rectangle(x + DEFUZZ, y + DEFUZZ,
                         width, height);

            //cr.Color = CairoHelper.GetCairoColorWithAlpha (gtk_style.Foreground (state), 0.1f);
            cr.SetSourceRGBA(CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.1f).R, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.1f).G, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.1f).B, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.1f).A);
            cr.FillPreserve();

            //cr.Color = CairoHelper.GetCairoColorWithAlpha (gtk_style.Foreground (state), 0.7f);
            cr.SetSourceRGBA(CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.7f).R, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.7f).G, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.7f).B, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.7f).A);

            cr.LineWidth = 1.0f;
            cr.Stroke();
        }
Ejemplo n.º 6
0
        public void DrawSelectedPoint(Cairo.Context cr, PlotColor color,
                                      PointShape type, int x, int y)
        {
            DrawPointGlyph(cr, type, x, y, POINT_SIZE);

            //cr.Color = CairoHelper.GetCairoColor (gtk_style.Base (state));
            cr.SetSourceRGBA(CairoHelper.GetCairoColor(gtk_style.Base(state)).R, CairoHelper.GetCairoColor(gtk_style.Base(state)).G, CairoHelper.GetCairoColor(gtk_style.Base(state)).B, CairoHelper.GetCairoColor(gtk_style.Base(state)).A);

            cr.FillPreserve();

            //cr.Color = colors[(int)color];
            cr.SetSourceRGBA(colors[(int)color].R, colors[(int)color].G, colors[(int)color].B, colors[(int)color].A);

            cr.LineWidth = 2.0f;
            cr.Stroke();
        }
Ejemplo n.º 7
0
        public void DrawGridLine(Cairo.Context cr, int x1, int y1, int x2, int y2)
        {
            if (x1 == x2)
            {
                // vertical line
                cr.MoveTo(x1 + DEFUZZ, y1);
                cr.LineTo(x2 + DEFUZZ, y2);
            }
            else if (y1 == y2)
            {
                // horizontal line
                cr.MoveTo(x1, y1 + DEFUZZ);
                cr.LineTo(x2, y2 + DEFUZZ);
            }
            else
            {
                cr.MoveTo(x1 + DEFUZZ, y1 + DEFUZZ);
                cr.LineTo(x2 + DEFUZZ, y2 + DEFUZZ);
            }

            cr.SetSourceRGBA(CairoHelper.GetCairoColor(gtk_style.Background(state)).R, CairoHelper.GetCairoColor(gtk_style.Background(state)).G, CairoHelper.GetCairoColor(gtk_style.Background(state)).B, CairoHelper.GetCairoColor(gtk_style.Background(state)).A);


            //cr.Color = CairoHelper.GetCairoColor (gtk_style.Background (state));
            cr.LineWidth = 1.0f;
            cr.Stroke();
        }
Ejemplo n.º 8
0
        public void DrawAxisTick(Cairo.Context cr, int x, int y, AxisLocation loc)
        {
            //cr.Color = CairoHelper.GetCairoColor (gtk_style.Foreground (state));
            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.LineWidth = 1.0f;

            switch (loc)
            {
            case AxisLocation.Left:
                cr.MoveTo(x, y + DEFUZZ);
                cr.LineTo(x + TICK_SIZE, y + DEFUZZ);
                break;

            case AxisLocation.Right:
                cr.MoveTo(x, y + DEFUZZ);
                cr.LineTo(x + TICK_SIZE, y + DEFUZZ);
                break;

            case AxisLocation.Top:
                cr.MoveTo(x + DEFUZZ, y);
                cr.LineTo(x + DEFUZZ, y - TICK_SIZE);
                break;

            case AxisLocation.Bottom:
                cr.MoveTo(x + DEFUZZ, y);
                cr.LineTo(x + DEFUZZ, y + TICK_SIZE);
                break;
            }

            cr.Stroke();
        }
        public static void Ellipse(Cairo.Context context, PointF p, double r, Color color, bool filled, double width = 1.0)
        {
            context.Save();
            context.Translate(p.X, p.Y);

            if (!filled)
            {
                context.LineWidth = width;
                context.LineCap   = Cairo.LineCap.Butt;
                context.LineJoin  = Cairo.LineJoin.Bevel;
            }
            var c = color.ToCairo();

            context.SetSourceRGBA(c.R, c.G, c.B, c.A);

            context.Arc(0, 0, r, 0, Math.PI * 2);

            if (filled)
            {
                context.Fill();
            }
            else
            {
                context.Stroke();
            }

            context.Restore();
        }
        public static void Arc(Cairo.Context context, PointF p, double r, double a1, double a2, bool clockwise, Color color, bool filled, double width = 1.0)
        {
            context.Save();
            context.Translate(p.X, p.Y);

            if (!filled)
            {
                context.LineWidth = width;
                context.LineCap   = Cairo.LineCap.Butt;
                context.LineJoin  = Cairo.LineJoin.Bevel;
            }
            var c = color.ToCairo();

            context.SetSourceRGBA(c.R, c.G, c.B, c.A);

            if (clockwise)
            {
                context.Arc(0, 0, r, a1, a2);
            }
            else
            {
                context.ArcNegative(0, 0, r, a1, a2);
            }

            if (filled)
            {
                context.Fill();
            }
            else
            {
                context.Stroke();
            }

            context.Restore();
        }
Ejemplo n.º 11
0
        protected virtual void DrawFocus(Cairo.Context graphics)
        {
            double uw = graphics.LineWidth;

            graphics.LineWidth *= 6;

            int fw = 12;
            int dw = 0;

            double w = Allocation.Width;
            double h = Allocation.Height;

            graphics.SetSourceRGBA(0.6, 0.6, 0.6, 0.5);

            graphics.MoveTo(-uw * dw, uw * fw);
            graphics.LineTo(-uw * dw, -uw * dw);
            graphics.LineTo(uw * fw, -uw * dw);
            graphics.Stroke();

            graphics.MoveTo(w - uw * fw, -uw * dw);
            graphics.LineTo(w + uw * dw, -uw * dw);
            graphics.LineTo(w + uw * dw, uw * fw);
            graphics.Stroke();

            graphics.MoveTo(w + uw * dw, h - uw * fw);
            graphics.LineTo(w + uw * dw, h + uw * dw);
            graphics.LineTo(w - uw * fw, h + uw * dw);
            graphics.Stroke();

            graphics.MoveTo(uw * fw, h + uw * dw);
            graphics.LineTo(-uw * dw, h + uw * dw);
            graphics.LineTo(-uw * dw, h - uw * fw);
            graphics.Stroke();
        }
Ejemplo n.º 12
0
        public virtual void DrawAnnotation(Cairo.Context context, Cdn.AnnotationInfo info)
        {
            var uw    = context.LineWidth;
            var alloc = AnnotationAllocation(1 / uw, context);

            alloc.Offset(-Allocation.X / uw, -Allocation.Y / uw);

            context.Save();
            context.Scale(context.LineWidth, context.LineWidth);
            context.LineWidth = 1;

            context.Rectangle(alloc.X, alloc.Y, alloc.Width, alloc.Height);
            context.SetSourceRGBA(1, 1, 1, 0.75);
            context.Fill();

            context.Rectangle(alloc.X + 2, alloc.Y + 2, alloc.Width - 4, alloc.Height - 4);
            context.SetSourceRGB(0.95, 0.95, 0.95);
            context.SetDash(new double[] { 5, 5 }, 0);
            context.Stroke();

            Pango.Layout layout = Pango.CairoHelper.CreateLayout(context);
            Pango.CairoHelper.UpdateLayout(context, layout);
            layout.FontDescription = Settings.Font;

            layout.SetText(info.Text.Trim());

            context.MoveTo(alloc.X + 2, alloc.Y + 2);
            context.SetSourceRGB(0.5, 0.5, 0.5);
            Pango.CairoHelper.ShowLayout(context, layout);

            context.Restore();
        }
        protected virtual void SetupBackground()
        {
            background.Clear();
            Cairo.Context context = background.Create();

            double lwidth  = 1;
            double hlwidth = lwidth * 0.5;

            double margin = Margin;

            //left curvature:
            context.MoveTo(-hlwidth, -hlwidth);
            context.CurveTo(margin * 0.33, -hlwidth,
                            margin * 0.5, Height * 0.4,
                            margin * 0.5, Height * 0.5);
            context.CurveTo(margin * 0.5, Height * 0.6,
                            margin * 0.66, Height - hlwidth,
                            margin - hlwidth, Height - hlwidth);


            //straight bottom:
            context.LineTo(Width - margin - hlwidth, Height - hlwidth);

            //right curvature:
            context.CurveTo(Width - margin * 0.66, Height - hlwidth,
                            Width - margin * 0.5, Height * 0.6,
                            Width - margin * 0.5, Height * 0.5);
            context.CurveTo(Width - margin * 0.5, Height * 0.4,
                            Width - margin * 0.33, -hlwidth,
                            Width - hlwidth, -hlwidth);

            //straight top:
            context.LineTo(-hlwidth, -hlwidth);
            context.ClosePath();

            context.LineWidth = lwidth;
            context.SetSourceRGBA(1.0, 1.0, 1.0, 1.0);
            context.StrokePreserve();
            context.SetSourceRGBA(1.0, 1.0, 1.0, 0.10);
            context.Fill();

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Ejemplo n.º 14
0
        public void DrawLine(Cairo.Context cr, PlotColor color, int x1, int y1, int x2, int y2)
        {
            cr.MoveTo(x1 + DEFUZZ, y1 + DEFUZZ);
            cr.LineTo(x2 + DEFUZZ, y2 + DEFUZZ);

            //cr.Color = colors[(int)color];
            cr.SetSourceRGBA(colors[(int)color].R, colors[(int)color].G, colors[(int)color].B, colors[(int)color].A);

            cr.LineWidth = 1.0f;
            cr.Stroke();
        }
Ejemplo n.º 15
0
 protected void paintTrail(Cairo.Context context, int x, int y)
 {
     context.Save();
     context.SetSourceRGB(0, 1, 0);
     context.Translate(x, y);
     context.Rectangle(new Cairo.Rectangle(0, 0, fieldSize, fieldSize));
     context.SetSourceRGBA(0, 1, 0, 0.3);
     context.FillPreserve();
     context.NewPath();
     context.Restore();
 }
Ejemplo n.º 16
0
 private void SetColor(Cairo.Context graphics, double[] color)
 {
     if (color.Length == 3)
     {
         graphics.SetSourceRGB(color[0], color[1], color[2]);
     }
     else
     {
         graphics.SetSourceRGBA(color[0], color[1], color[2], color[3]);
     }
 }
Ejemplo n.º 17
0
 protected void paintSquare(Cairo.Context context, int x, int y, bool fill)
 {
     context.Save();
     context.SetSourceRGB(0, 0, 1);
     context.Translate(x, y);
     context.Rectangle(new Cairo.Rectangle(0, 0, fieldSize, fieldSize));
     context.SetSourceRGBA(0, 0, 0, fill ? 0.5 : 0.3);
     context.FillPreserve();
     context.NewPath();
     context.Restore();
 }
Ejemplo n.º 18
0
 public void RenderOverlay(string text)
 {
     Gdk.Window canvas = area.GdkWindow;
     using (Cairo.Context context = Gdk.CairoHelper.Create(canvas)) {
         context.SetSourceRGBA(1, 1, 0, 0.5);
         context.Rectangle(new Cairo.Rectangle(0, 0, fieldSize * (width), fieldSize * (height)));
         context.Paint();
         context.SetSourceRGBA(1, 1, 1, 1);
         Pango.Layout layout = Pango.CairoHelper.CreateLayout(context);
         layout.Width           = (int)(width * fieldSize * Pango.Scale.PangoScale);
         layout.Alignment       = Pango.Alignment.Center;
         layout.Wrap            = Pango.WrapMode.Word;
         layout.FontDescription = Pango.FontDescription.FromString("sans-serif 30");
         layout.SetText(text);
         int layoutWidth, layoutHeight;
         layout.GetPixelSize(out layoutWidth, out layoutHeight);
         context.MoveTo(0, (height * fieldSize - layoutHeight) / 2);
         Pango.CairoHelper.UpdateLayout(context, layout);
         Pango.CairoHelper.ShowLayout(context, layout);
     }
 }
Ejemplo n.º 19
0
		void OnDraw (object data)
		{
			Action<Cairo.Context> callback = (Action<Cairo.Context>) data;

			using (var context = new Cairo.Context (surface.Surface)) {
				context.Operator = Cairo.Operator.Source;
				context.SetSourceRGBA (0, 0, 0, 0);
				context.Paint ();
				context.Operator = Cairo.Operator.Over;

				context.Scale (Scale, Scale);
				callback (context);
			}
			runningSignal.Set ();
		}
Ejemplo n.º 20
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="showCursor">Whether or not to show the mouse cursor in the drawing.</param>
        /// <param name="useTextLayer">Whether or not to use the TextLayer (as opposed to the Userlayer).</param>
        private void RedrawText(bool showCursor, bool useTextLayer)
        {
            Rectangle r = CurrentTextEngine.GetLayoutBounds();
            r.Inflate(10 + OutlineWidth, 10 + OutlineWidth);
            CurrentTextBounds = r;

            Rectangle cursorBounds = Rectangle.Zero;

            Cairo.ImageSurface surf;

            if (!useTextLayer)
            {
                //Draw text on the current UserLayer's surface as finalized text.
                surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface;
            }
            else
            {
                //Draw text on the current UserLayer's TextLayer's surface as re-editable text.
                surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.TextLayer.Surface;

                ClearTextLayer();
            }

            using (var g = new Cairo.Context (surf)) {
                g.Save ();

                // Show selection if on text layer
                if (useTextLayer) {
                    // Selected Text
                    Cairo.Color c = new Cairo.Color (0.7, 0.8, 0.9, 0.5);
                    foreach (Rectangle rect in CurrentTextEngine.SelectionRectangles)
                        g.FillRectangle (rect.ToCairoRectangle (), c);
                }
                g.AppendPath (PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();

                g.MoveTo (new Cairo.PointD (CurrentTextEngine.Origin.X, CurrentTextEngine.Origin.Y));

                g.SetSourceRGBA (PintaCore.Palette.PrimaryColor);

                //Fill in background
                if (BackgroundFill) {
                    using (var g2 = new Cairo.Context (surf)) {
                        g2.FillRectangle(CurrentTextEngine.GetLayoutBounds().ToCairoRectangle(), PintaCore.Palette.SecondaryColor);
                    }
                }

                // Draw the text
                if (FillText)
                    Pango.CairoHelper.ShowLayout (g, CurrentTextEngine.Layout);

                if (FillText && StrokeText) {
                    g.SetSourceRGBA (PintaCore.Palette.SecondaryColor);
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, CurrentTextEngine.Layout);
                    g.Stroke ();
                } else if (StrokeText) {
                    g.SetSourceRGBA (PintaCore.Palette.PrimaryColor);
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, CurrentTextEngine.Layout);
                    g.Stroke ();
                }

                if (showCursor) {
                    var loc = CurrentTextEngine.GetCursorLocation ();

                    g.Antialias = Cairo.Antialias.None;
                    g.DrawLine (new Cairo.PointD (loc.X, loc.Y), new Cairo.PointD (loc.X, loc.Y + loc.Height), new Cairo.Color (0, 0, 0, 1), 1);

                    cursorBounds = Rectangle.Inflate (loc, 2, 10);
                }

                g.Restore ();

                if (useTextLayer && (is_editing || ctrlKey) && !CurrentTextEngine.IsEmpty())
                {
                    //Draw the text edit rectangle.

                    g.Save();

                    g.Translate(.5, .5);

                    using (Cairo.Path p = g.CreateRectanglePath(new Cairo.Rectangle(CurrentTextBounds.Left, CurrentTextBounds.Top,
                        CurrentTextBounds.Width, CurrentTextBounds.Height - FontSize)))
                    {
                        g.AppendPath(p);
                    }

                    g.LineWidth = 1;

                    g.SetSourceRGB (1, 1, 1);
                    g.StrokePreserve();

                    g.SetDash(new double[] { 2, 4 }, 0);
                    g.SetSourceRGB (1, .1, .2);

                    g.Stroke();

                    g.Restore();
                }
            }

            InflateAndInvalidate(PintaCore.Workspace.ActiveDocument.CurrentUserLayer.previousTextBounds);
            PintaCore.Workspace.Invalidate(old_cursor_bounds);
            PintaCore.Workspace.Invalidate(r);
            PintaCore.Workspace.Invalidate(cursorBounds);

            old_cursor_bounds = cursorBounds;
        }