Пример #1
0
 public static void SetDash(Cairo.Context ctx, bool enabled)
 {
     if (enabled)
     {
         ctx.SetDash(new double[] { 4, 4 }, 1);
         ctx.LineCap = Cairo.LineCap.Butt;
     }
     else
     {
         ctx.SetDash(new double[] { }, 0);
     }
 }
Пример #2
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (!base.OnExposeEvent(evnt))
            {
                return(false);
            }

            if (!CanSelect || !CropHelpers || Selection == Rectangle.Zero)
            {
                return(false);
            }

            using (Cairo.Context ctx = CairoHelper.Create(GdkWindow)) {
                ctx.SetSourceRGBA(.7, .7, .7, .8);
                ctx.SetDash(new double [] { 10, 15 }, 0);
                ctx.LineWidth = .8;
                for (int i = 1; i < 3; i++)
                {
                    Point s = ImageCoordsToWindow(new Point(Selection.X + Selection.Width / 3 * i, Selection.Y));
                    Point e = ImageCoordsToWindow(new Point(Selection.X + Selection.Width / 3 * i, Selection.Y + Selection.Height));
                    ctx.MoveTo(s.X, s.Y);
                    ctx.LineTo(e.X, e.Y);
                    ctx.Stroke();
                }
                for (int i = 1; i < 3; i++)
                {
                    Point s = ImageCoordsToWindow(new Point(Selection.X, Selection.Y + Selection.Height / 3 * i));
                    Point e = ImageCoordsToWindow(new Point(Selection.X + Selection.Width, Selection.Y + Selection.Height / 3 * i));
                    ctx.MoveTo(s.X, s.Y);
                    ctx.LineTo(e.X, e.Y);
                    ctx.Stroke();
                }
            }
            return(true);
        }
Пример #3
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();
        }
Пример #4
0
        private IDisposable SetPen(Pen pen, Size destinationSize)
        {
            if (pen.DashStyle != null)
            {
                if (pen.DashStyle.Dashes != null && pen.DashStyle.Dashes.Count > 0)
                {
                    var cray = pen.DashStyle.Dashes.ToArray();
                    _context.SetDash(cray, pen.DashStyle.Offset);
                }
            }

            _context.LineWidth  = pen.Thickness;
            _context.MiterLimit = pen.MiterLimit;

            // Line caps and joins are currently broken on Cairo. I've defaulted them to sensible defaults for now.
            // Cairo does not have StartLineCap, EndLineCap, and DashCap properties, whereas Direct2D does.
            // TODO: Figure out a solution for this.
            _context.LineJoin = Cairo.LineJoin.Miter;
            _context.LineCap  = Cairo.LineCap.Butt;

            if (pen.Brush == null)
            {
                return(Disposable.Empty);
            }

            return(SetBrush(pen.Brush, destinationSize));
        }
Пример #5
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

            if (values.Count == 0)
            {
                return;
            }
            Rectangle r = ClientRectangle;

            int i = values.Count - 1;

            double ptrX   = (double)r.Right;
            double scaleY = (double)r.Height / (Maximum - Minimum);
            double stepX  = (double)r.Width / (double)(nbValues - 1);

            gr.LineWidth = 1.0;
            gr.SetDash(new double[] { 1.0 }, 0.0);



            LowThresholdFill.SetAsSource(gr);
            gr.MoveTo(r.Left, r.Bottom - LowThreshold * scaleY);
            gr.LineTo(r.Right, r.Bottom - LowThreshold * scaleY);
//			gr.Rectangle (r.Left, r.Bottom - LowThreshold * scaleY, r.Width, LowThreshold * scaleY);
            gr.Stroke();

            HighThresholdFill.SetAsSource(gr);
            gr.MoveTo(r.Left, (Maximum - HighThreshold) * scaleY);
            gr.LineTo(r.Right, (Maximum - HighThreshold) * scaleY);
//			gr.Rectangle (r.Left, r.Top, r.Width, (Maximum - HighThreshold) * scaleY);
            gr.Stroke();

            gr.MoveTo(ptrX, values [i] * scaleY);

            Foreground.SetAsSource(gr);
            gr.SetDash(new double[] { }, 0.0);

            while (i >= 0)
            {
                gr.LineTo(ptrX, r.Bottom - values [i] * scaleY);
                ptrX -= stepX;
                i--;
            }
            gr.Stroke();
        }
Пример #6
0
        private void SetOutsideLineStyle(Cairo.Context context)
        {
            Color nc = Color.Copy();

            nc.A *= 0.8;

            nc.Set(context);
            context.SetDash(new double[] { LineWidth, LineWidth * 4 }, 0);
        }
Пример #7
0
        private void DrawLine(Cairo.Color c, BorderStyleEnum bs, float w, Cairo.Context g, double x, double y, double x2, double y2)
        {
            if (bs == BorderStyleEnum.None ||//|| c.IsEmpty
                w <= 0)      // nothing to draw
            {
                return;
            }

            g.Save();
//          Pen p = null;
//          p = new Pen(c, w);
            g.Color     = c;
            g.LineWidth = w;
            switch (bs)
            {
            case BorderStyleEnum.Dashed:
//	                p.DashStyle = DashStyle.Dash;
                g.SetDash(new double[] { 2, 1 }, 0.0);
                break;

            case BorderStyleEnum.Dotted:
//                        p.DashStyle = DashStyle.Dot;
                g.SetDash(new double[] { 1 }, 0.0);
                break;

            case BorderStyleEnum.Double:
            case BorderStyleEnum.Groove:
            case BorderStyleEnum.Inset:
            case BorderStyleEnum.Solid:
            case BorderStyleEnum.Outset:
            case BorderStyleEnum.Ridge:
            case BorderStyleEnum.WindowInset:
            default:
                g.SetDash(new double[] { }, 0.0);
                break;
            }

//          g.DrawLine(p, x, y, x2, y2);
            g.MoveTo(x, y);
            g.LineTo(x2, y2);
            g.Stroke();

            g.Restore();
        }
Пример #8
0
        public static void SetLineStyle(Cairo.Context context, double lw, LineStyle style)
        {
            context.LineWidth = lw;

            switch (style)
            {
            case LineStyle.Single:
                context.SetDash(new double[] {}, 0);
                break;

            case LineStyle.Dotted:
                context.SetDash(new double[] { lw, lw * 2 }, 0);
                break;

            case LineStyle.Dashed:
                context.SetDash(new double[] { lw * 4, lw * 4 }, 0);
                break;
            }
        }
Пример #9
0
 public void Apply(Cairo.Context context)
 {
     context.LineWidth = Thickness;
     context.LineCap   = LineCap;
     context.LineJoin  = LineJoin;
     if (cairodashes != null)
     {
         context.SetDash(cairodashes, cairooffset);
     }
     context.MiterLimit = MiterLimit;
     Brush.Apply(context);
 }
Пример #10
0
        protected override void DrawFrame(Cairo.Context context, double lineWidth, Cairo.Color lineColor, Cairo.Color fillColor)
        {
            // base.DrawFrame (context, lineWidth, lineColor, fillColor);

            rect = DisplayBox;
            rect.OffsetDot5();

            // HERZUM SPRINT 1.2
            // CairoFigures.CurvedRectangle(context, rect, 30);
            CairoFigures.AngleFrame(context, rect, 0, 0, 0, 0);
            // END HERZUM SPRINT 1.2

            Cairo.Color fillColorOrigin;
            fillColorOrigin = fillColor;

            lineWidth = 1;
            fillColor = new Cairo.Color(1.0, 1.0, 1.0, 1.0);

            context.Color = fillColor;
            context.FillPreserve();
            context.Color     = lineColor;
            context.LineWidth = lineWidth;

            double[] dash = { 2, 0, 2 };
            context.SetDash(dash, 0);

            context.Stroke();

            rect2        = DisplayBox;
            rect2.Width  = DisplayBox.Width;
            rect2.Height = 30;
            rect2.OffsetDot5();
            CairoFigures.CurvedRectangle(context, rect2, 30);
            fillColor     = fillColorOrigin;
            context.Color = fillColor;
            context.FillPreserve();
            context.Color     = lineColor;
            context.LineWidth = lineWidth;

            context.Stroke();

            // HERZUM SPRINT 2.1
            // m_applicationContext.MainWindow.ExperimentCanvasPad.LoopNodeControlCurrent = this;
            // END HERZUM SPRINT 2.1

            // HERZUM SPRINT 5.0: TLAB-235
            // DrawScope ();
            DrawScope("Enter", "Exit");
            // END HERZUM SPRINT 5.0: TLAB-235
        }
Пример #11
0
        public void DrawDashedLine(Cairo.Context cr, PlotColor color, int x1, int y1, int x2, int y2)
        {
            cr.Save();

            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.SetDash(standard_dash, 0);
            cr.Stroke();

            cr.Restore();
        }
Пример #12
0
        private void FromState(Cairo.Context graphics, bool transparent)
        {
            double[] color = StateColor();

            if (transparent && color.Length == 4)
            {
                graphics.SetSourceRGBA(color[0], color[1], color[2], color[3]);
            }
            else
            {
                graphics.SetSourceRGB(color[0], color[1], color[2]);
            }

            if (WrappedObject != null && WrappedObject.LinkFocus)
            {
                graphics.LineWidth *= 2;
            }
            else if (WrappedObject != null && WrappedObject.KeyFocus)
            {
                graphics.LineWidth *= 4;
                graphics.SetDash(new double[] { graphics.LineWidth, graphics.LineWidth }, 0);
            }
            else if (Style == Renderer.DrawStyle.Icon)
            {
                graphics.LineWidth *= 3;
            }
            else if (Standalone)
            {
                graphics.LineWidth *= 4;
            }
            else if (WrappedObject != null && WrappedObject.MouseFocus)
            {
                if (WrappedObject.Selected)
                {
                    graphics.LineWidth *= 4;
                }
                else
                {
                    graphics.LineWidth *= 3;
                }
            }
            else if (WrappedObject != null && WrappedObject.Selected)
            {
                graphics.LineWidth *= 3;
            }
        }
Пример #13
0
        public void DrawLinkedFocusLine(Cairo.Context cr, int x1, int y1, int x2, int y2)
        {
            cr.Save();

            cr.MoveTo(x1 + DEFUZZ, y1);
            cr.LineTo(x2 + DEFUZZ, y2);

            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.GetCairoColorWithAlpha (gtk_style.Foreground (state), 0.4f);

            cr.SetDash(linked_dash, 0);
            cr.LineWidth = 1.0f;
            cr.Stroke();

            cr.Restore();
        }
Пример #14
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics layout, int startOffset, int endOffset)
        {
            if (DebuggingService.IsDebugging)
            {
                return;
            }
            int markerStart = Segment.Offset;
            int markerEnd   = Segment.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double drawFrom;
            double drawTo;
            double y         = layout.LineYRenderStartPosition;
            double startXPos = layout.TextRenderStartPosition;
            double endXPos   = layout.TextRenderEndPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                drawTo = endXPos;
                var line   = editor.GetLineByOffset(startOffset);
                int offset = line.GetIndentation(editor.Document).Length;
                drawFrom = startXPos + (layout.Layout.IndexToPos(offset).X / Pango.Scale.PangoScale);
            }
            else
            {
                int start;
                if (startOffset < markerStart)
                {
                    start = markerStart;
                }
                else
                {
                    var line   = editor.GetLineByOffset(startOffset);
                    int offset = line.GetIndentation(editor.Document).Length;
                    start = startOffset + offset;
                }
                int end = endOffset < markerEnd ? endOffset : markerEnd;
                int x_pos;

                x_pos    = layout.Layout.IndexToPos(start - startOffset).X;
                drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                x_pos    = layout.Layout.IndexToPos(end - startOffset).X;

                drawTo = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            drawFrom = Math.Max(drawFrom, editor.TextViewMargin.XOffset);
            drawTo   = Math.Max(drawTo, editor.TextViewMargin.XOffset);
            if (drawFrom >= drawTo)
            {
                return;
            }

            double height = editor.LineHeight / 5;

            cr.SetSourceColor(Color);
            if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.WavedLine)
            {
                Pango.CairoHelper.ShowErrorUnderline(cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height);
            }
            else if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.DottedLine)
            {
                cr.Save();
                cr.LineWidth = 1;
                cr.MoveTo(drawFrom + 1, y + editor.LineHeight - 1 + 0.5);
                cr.RelLineTo(Math.Min(drawTo - drawFrom, 4 * 3), 0);
                cr.SetDash(new double[] { 2, 2 }, 0);
                cr.Stroke();
                cr.Restore();
            }
            else
            {
                cr.MoveTo(drawFrom, y + editor.LineHeight - 1);
                cr.LineTo(drawTo, y + editor.LineHeight - 1);
                cr.Stroke();
            }
        }
Пример #15
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.Color = 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.Color = PintaCore.Palette.SecondaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, CurrentTextEngine.Layout);
                    g.Stroke ();
                } else if (StrokeText) {
                    g.Color = 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.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    g.SetDash(new double[] { 2, 4 }, 0);
                    g.Color = new Cairo.Color(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;
        }
Пример #16
0
        public override void Draw(TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
        {
            if (Debugger.DebuggingService.IsDebugging)
            {
                return;
            }
            int markerStart = Segment.Offset;
            int markerEnd   = Segment.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            bool drawOverlay = result.InspectionMark == IssueMarker.GrayOut;

            if (drawOverlay && editor.IsSomethingSelected)
            {
                var selectionRange = editor.SelectionRange;
                if (selectionRange.Contains(markerStart) && selectionRange.Contains(markerEnd))
                {
                    return;
                }
                if (selectionRange.Contains(markerEnd))
                {
                    markerEnd = selectionRange.Offset;
                }
                if (selectionRange.Contains(markerStart))
                {
                    markerStart = selectionRange.EndOffset;
                }
                if (markerEnd <= markerStart)
                {
                    return;
                }
            }

            double drawFrom;
            double drawTo;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                drawFrom = startXPos;
                drawTo   = endXPos;
            }
            else
            {
                int             start = startOffset < markerStart ? markerStart : startOffset;
                int             end   = endOffset < markerEnd ? endOffset : markerEnd;
                int /*lineNr,*/ x_pos;

                x_pos    = layout.IndexToPos(start - startOffset).X;
                drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                x_pos    = layout.IndexToPos(end - startOffset).X;

                drawTo = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            drawFrom = System.Math.Max(drawFrom, editor.TextViewMargin.XOffset);
            drawTo   = System.Math.Max(drawTo, editor.TextViewMargin.XOffset);
            if (drawFrom >= drawTo)
            {
                return;
            }

            double height = editor.LineHeight / 5;

            cr.SetSourceColor(GetColor(editor, Result));
            if (drawOverlay)
            {
                cr.Rectangle(drawFrom, y, drawTo - drawFrom, editor.LineHeight);
                var color = editor.ColorStyle.PlainText.Background;
                color.A = 0.6;
                cr.SetSourceColor(color);
                cr.Fill();
            }
            else if (result.InspectionMark == IssueMarker.WavedLine)
            {
                Pango.CairoHelper.ShowErrorUnderline(cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height);
            }
            else if (result.InspectionMark == IssueMarker.DottedLine)
            {
                cr.Save();
                cr.LineWidth = 1;
                cr.MoveTo(drawFrom + 1, y + editor.LineHeight - 1 + 0.5);
                cr.RelLineTo(System.Math.Min(drawTo - drawFrom, 4 * 3), 0);
                cr.SetDash(new double[] { 2, 2 }, 0);
                cr.Stroke();
                cr.Restore();
            }
            else
            {
                cr.MoveTo(drawFrom, y + editor.LineHeight - 1);
                cr.LineTo(drawTo, y + editor.LineHeight - 1);
                cr.Stroke();
            }
        }
Пример #17
0
 public void SetLineDash(object backend, double offset, params double[] pattern)
 {
     Cairo.Context ctx = ((GtkContext)backend).Context;
     ctx.SetDash(pattern, offset);
 }
Пример #18
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);
            if (!drawGrid)
            {
                return;
            }


            Rectangle    cb            = ClientRectangle;
            const double gridLineWidth = 0.1;
            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) {
                using (Cairo.Surface surf = new Cairo.ImageSurface(imlVE.bmp, Cairo.Format.Argb32,
                                                                   imlVE.ClientRectangle.Width, imlVE.ClientRectangle.Height, imlVE.ClientRectangle.Width * 4)) {
                    gr.SetSourceSurface(surf, cb.Left, cb.Top);
                    gr.Paint();
                }
                imlVE.IsDirty = false;
            }

            Rectangle hr;

            if (imlVE.HoverWidget != null)
            {
                hr = imlVE.HoverWidget.ScreenCoordinates(imlVE.HoverWidget.getSlot());
//			gr.SetSourceColor (Color.LightGray);
//			gr.DrawCote (new Cairo.PointD (hr.X, hr.Center.Y), new Cairo.PointD (hr.Right, hr.Center.Y));
//			gr.DrawCote (new Cairo.PointD (hr.Center.X, hr.Y), new Cairo.PointD (hr.Center.X, hr.Bottom));
                //hr.Inflate (2);
                gr.SetSourceColor(Color.LightGray);
                gr.SetDash(new double[] { 3.0, 3.0 }, 0.0);
                gr.Rectangle(hr, 1.0);
            }

            if (SelectedItem == null)
            {
                return;
            }
            hr = SelectedItem.ScreenCoordinates(SelectedItem.getSlot());
            hr.Inflate(1);
            gr.SetSourceColor(Color.Yellow);
            gr.SetDash(new double[] { 5.0, 3.0 }, 0.0);
            gr.Rectangle(hr, 1.0);
        }
Пример #19
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

            int x = (int)PintaCore.Workspace.Offset.X;
            int y = (int)PintaCore.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            Rectangle canvas_bounds = new Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);

            canvas_bounds.Intersect(e.Area);

            if (canvas_bounds.IsEmpty)
            {
                return(true);
            }

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize(PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our 1 px black border
                g.DrawRectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color(0, 0, 0), 1);

                // Set up our clip rectangle
                g.Rectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
                g.Clip();

                g.Translate(x, y);

                bool checker = true;

                // Resize each layer and paint it to the screen
                foreach (Layer layer in PintaCore.Layers.GetLayersToPaint())
                {
                    cr.Render(layer.Surface, canvas, canvas_bounds.Location, checker);
                    g.SetSourceSurface(canvas, canvas_bounds.X + (int)(layer.Offset.X * scale), canvas_bounds.Y + (int)(layer.Offset.Y * scale));
                    g.PaintWithAlpha(layer.Opacity);

                    if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
                    {
                        cr.Render(PintaCore.LivePreview.LivePreviewSurface, canvas, canvas_bounds.Location, checker);

                        g.Save();
                        g.Scale(scale, scale);
                        g.AppendPath(PintaCore.Layers.SelectionPath);
                        g.Clip();

                        g.Scale(1 / scale, 1 / scale);
                        g.SetSourceSurface(canvas, canvas_bounds.X, canvas_bounds.Y);
                        g.PaintWithAlpha(layer.Opacity);

                        g.Restore();
                    }

                    checker = false;
                }

                // If we are at least 200% and grid is requested, draw it
                if (PintaCore.Actions.View.PixelGrid.Active && cr.ScaleFactor.Ratio <= 0.5d)
                {
                    gr.Render(canvas, canvas_bounds.Location);
                    g.SetSourceSurface(canvas, canvas_bounds.X, canvas_bounds.Y);
                    g.Paint();
                }

                // Selection outline
                if (PintaCore.Layers.ShowSelection)
                {
                    g.Save();
                    g.Translate(0.5, 0.5);
                    g.Scale(scale, scale);

                    g.AppendPath(PintaCore.Layers.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains("Select") && !PintaCore.Tools.CurrentTool.Name.Contains("Selected"))
                    {
                        g.Color    = new Cairo.Color(0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    // Draw a black dashed line over the white line
                    g.SetDash(new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color(0, 0, 0);

                    g.Stroke();
                    g.Restore();
                }
            }

            return(true);
        }
        public override void DrawEditor(IBitmapView view)
        {
            Gdk.Drawable  target             = ((FloatPixmapViewWidget)view).GdkWindow;
            Gdk.Rectangle image_position     = ((FloatPixmapViewWidget)view).CurrentImagePosition;
            ToneStageOperationParameters pms = (ToneStageOperationParameters)Parameters;


            Gdk.GC gc = new Gdk.GC(target);

            gc.Function = Gdk.Function.Copy;

            if (pms.AutoDarkTone)
            {
                // Drawing dark selection
                Point scrDarkCenter = new Point(image_position.X + (int)(pms.AutoDarkCenter.X * view.Image.Width),
                                                image_position.Y + (int)(pms.AutoDarkCenter.Y * view.Image.Height));
                double scrDarkRadius = pms.AutoDarkRadius * (view.Image.Width + view.Image.Height) / 2;

                using (Cairo.Context cc = Gdk.CairoHelper.Create(target))
                {
                    cc.LineCap  = Cairo.LineCap.Round;
                    cc.LineJoin = Cairo.LineJoin.Round;

                    cc.Color = new Cairo.Color(1, 1, 1, 0.3);

                    cc.LineWidth = 3;
                    cc.Arc(scrDarkCenter.X, scrDarkCenter.Y, scrDarkRadius, 0, 2 * Math.PI);
                    cc.ClosePath();
                    cc.Stroke();

                    cc.Color = new Cairo.Color(0, 0, 0, 1);

                    cc.LineWidth = 1;
                    cc.SetDash(new double[] { 3, 3 }, 0);
                    cc.Arc(scrDarkCenter.X, scrDarkCenter.Y, scrDarkRadius, 0, 2 * Math.PI);
                    cc.ClosePath();
                    cc.Stroke();
                }
            }

            if (pms.AutoLightTone)
            {
                // Drawing light selection
                Point scrLightCenter = new Point(image_position.X + (int)(pms.AutoLightCenter.X * view.Image.Width),
                                                 image_position.Y + (int)(pms.AutoLightCenter.Y * view.Image.Height));
                double scrLightRadius = pms.AutoLightRadius * (view.Image.Width + view.Image.Height) / 2;

                using (Cairo.Context cc = Gdk.CairoHelper.Create(target))
                {
                    cc.LineCap  = Cairo.LineCap.Round;
                    cc.LineJoin = Cairo.LineJoin.Round;

                    cc.Color = new Cairo.Color(0, 0, 0, 0.3);

                    cc.LineWidth = 3;
                    cc.Arc(scrLightCenter.X, scrLightCenter.Y, scrLightRadius, 0, 2 * Math.PI);
                    cc.ClosePath();
                    cc.Stroke();

                    cc.Color = new Cairo.Color(1, 1, 1, 1);

                    cc.LineWidth = 1;
                    cc.SetDash(new double[] { 3, 3 }, 0);
                    cc.Arc(scrLightCenter.X, scrLightCenter.Y, scrLightRadius, 0, 2 * Math.PI);
                    cc.ClosePath();
                    cc.Stroke();
                }
            }
        }
Пример #21
0
 public override void SetLineDash(object backend, double offset, params double[] pattern)
 {
     Cairo.Context ctx = ((CairoContextBackend)backend).Context;
     ctx.SetDash(pattern, offset);
 }
Пример #22
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

            int x = (int)PintaCore.Workspace.Offset.X;
            int y = (int)PintaCore.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            Rectangle canvas_bounds = new Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);

            canvas_bounds.Intersect(e.Area);

            if (canvas_bounds.IsEmpty)
            {
                return(true);
            }

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize(PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our canvas drop shadow
                g.DrawRectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color(.5, .5, .5), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, PintaCore.Workspace.CanvasSize.Width + 3, PintaCore.Workspace.CanvasSize.Height + 3), new Cairo.Color(.8, .8, .8), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, PintaCore.Workspace.CanvasSize.Width + 5, PintaCore.Workspace.CanvasSize.Height + 5), new Cairo.Color(.9, .9, .9), 1);

                // Set up our clip rectangle
                g.Rectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
                g.Clip();

                g.Translate(x, y);

                // Render all the layers to a surface
                var layers = PintaCore.Layers.GetLayersToPaint();
                if (layers.Count == 0)
                {
                    canvas.Clear();
                }
                cr.Render(layers, canvas, canvas_bounds.Location);

                // Paint the surface to our canvas
                g.SetSourceSurface(canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale));
                g.Paint();

                // Selection outline
                if (PintaCore.Layers.ShowSelection)
                {
                    g.Save();
                    g.Translate(0.5, 0.5);
                    g.Scale(scale, scale);

                    g.AppendPath(PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains("Select") && !PintaCore.Tools.CurrentTool.Name.Contains("Selected"))
                    {
                        g.Color    = new Cairo.Color(0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    // Draw a black dashed line over the white line
                    g.SetDash(new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color(0, 0, 0);

                    g.Stroke();
                    g.Restore();
                }
            }

            return(true);
        }
Пример #23
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 = CurrentTextLayout.GetLayoutBounds();

            r.Inflate(10 + OutlineWidth, 10 + OutlineWidth);
            InflateAndInvalidate(r);
            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.Layers.CurrentUserLayer.Surface;
            }
            else
            {
                //Draw text on the current UserLayer's TextLayer's surface as re-editable text.
                surf = PintaCore.Workspace.ActiveDocument.Layers.CurrentUserLayer.TextLayer.Layer.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 CurrentTextLayout.SelectionRectangles)
                    {
                        g.FillRectangle(rect.ToCairoRectangle(), c);
                    }
                }

                if (selection != null)
                {
                    selection.Clip(g);
                }

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

                g.SetSourceColor(PintaCore.Palette.PrimaryColor);

                //Fill in background
                if (BackgroundFill)
                {
                    using (var g2 = new Cairo.Context(surf)) {
                        if (selection != null)
                        {
                            selection.Clip(g2);
                        }

                        g2.FillRectangle(CurrentTextLayout.GetLayoutBounds().ToCairoRectangle(), PintaCore.Palette.SecondaryColor);
                    }
                }

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

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

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

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

                if (showCursor)
                {
                    var loc   = CurrentTextLayout.GetCursorLocation();
                    var color = PintaCore.Palette.PrimaryColor;

                    g.Antialias = Cairo.Antialias.None;
                    g.DrawLine(new Cairo.PointD(loc.X, loc.Y),
                               new Cairo.PointD(loc.X, loc.Y + loc.Height),
                               color, 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(CurrentTextBounds.ToCairoRectangle())) {
                        g.AppendPath(p);
                    }

                    g.LineWidth = 1;

                    g.SetSourceColor(new Cairo.Color(1, 1, 1));
                    g.StrokePreserve();

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

                    g.Stroke();

                    g.Restore();
                }
            }

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

            old_cursor_bounds = cursorBounds;
        }
Пример #24
0
        public override void DrawEditor(IBitmapView view)
        {
            if (view.Image == null || view.Image.Width == 0 || view.Image.Height == 0)
            {
                return;
            }

            Gdk.Drawable  target         = ((FloatPixmapViewWidget)view).GdkWindow;
            Gdk.Rectangle image_position = ((FloatPixmapViewWidget)view).CurrentImagePosition;

            CrotateStageOperationParameters pm = ((CrotateStageOperationParameters)Parameters);

            Gdk.GC gc = new Gdk.GC(target);

            // Draw center square dot
            Point C = new Point(pm.Center.X, pm.Center.Y);

            int scr_c_x = image_position.X + (int)(image_position.Width * C.X);
            int scr_c_y = image_position.Y + (int)(image_position.Height * C.Y);


            // Calculating new picture's real dimensions
            int    trueWidth = image_position.Width, trueHeight = image_position.Height;
            double w1, h1;

            w1 = pm.CropWidth * image_position.Width;
            h1 = pm.CropHeight * image_position.Height;

            double asp_rat;

            if (pm.AspectRatioCustom)
            {
                asp_rat = pm.AspectRatio;
            }
            else
            {
                asp_rat = pm.PresetAspectRatioValues[pm.AspectRatioPreset];
            }

            switch (pm.Mode)
            {
            case CatEye.Core.CrotateStageOperation.Mode.Disproportional:
                trueWidth  = (int)w1;
                trueHeight = (int)h1;
                break;

            case CatEye.Core.CrotateStageOperation.Mode.ProportionalWidthFixed:
                trueWidth  = (int)w1;
                trueHeight = (int)(w1 / asp_rat);
                break;

            case CatEye.Core.CrotateStageOperation.Mode.ProportionalHeightFixed:
                trueWidth  = (int)(h1 * asp_rat);
                trueHeight = (int)h1;
                break;
            }

            // Calculating new corners positions and "round" dot position
            double ang = pm.Angle / 180 * Math.PI;

            CatEye.Core.Point lt_corner = new CatEye.Core.Point(
                -trueWidth / 2,
                -trueHeight / 2);
            lt_corner_rot = CatEye.Core.Point.Rotate(lt_corner, ang, new Point(0, 0));
            Gdk.Point scr_lt = new Gdk.Point(
                (int)(scr_c_x + lt_corner_rot.X),
                (int)(scr_c_y + lt_corner_rot.Y));


            CatEye.Core.Point rt_corner = new CatEye.Core.Point(
                +trueWidth / 2,
                -trueHeight / 2);
            rt_corner_rot = CatEye.Core.Point.Rotate(rt_corner, ang, new Point(0, 0));
            Gdk.Point scr_rt = new Gdk.Point(
                (int)(scr_c_x + rt_corner_rot.X),
                (int)(scr_c_y + rt_corner_rot.Y));


            CatEye.Core.Point rb_corner = new CatEye.Core.Point(
                +trueWidth / 2,
                +trueHeight / 2);
            rb_corner_rot = CatEye.Core.Point.Rotate(rb_corner, ang, new Point(0, 0));
            Gdk.Point scr_rb = new Gdk.Point(
                (int)(scr_c_x + rb_corner_rot.X),
                (int)(scr_c_y + rb_corner_rot.Y));


            CatEye.Core.Point lb_corner = new CatEye.Core.Point(
                -trueWidth / 2,
                +trueHeight / 2);
            lb_corner_rot = CatEye.Core.Point.Rotate(lb_corner, ang, new Point(0, 0));
            Gdk.Point scr_lb = new Gdk.Point(
                (int)(scr_c_x + lb_corner_rot.X),
                (int)(scr_c_y + lb_corner_rot.Y));

            Gdk.Point scr_rnd = new Gdk.Point(
                (int)(scr_c_x + (rt_corner_rot.X + rb_corner_rot.X) / 2),
                (int)(scr_c_y + (rt_corner_rot.Y + rb_corner_rot.Y) / 2));


            // Drawing frame

            using (Cairo.Context cc = Gdk.CairoHelper.Create(target))
            {
                cc.LineCap  = Cairo.LineCap.Round;
                cc.LineJoin = Cairo.LineJoin.Round;

                cc.Color     = new Cairo.Color(0, 0, 0, 0.5);
                cc.LineWidth = 3;
                cc.MoveTo(scr_lt.X, scr_lt.Y);
                cc.LineTo(scr_lb.X, scr_lb.Y);
                cc.LineTo(scr_rb.X, scr_rb.Y);
                cc.LineTo(scr_rt.X, scr_rt.Y);
                cc.LineTo(scr_lt.X, scr_lt.Y);
                cc.ClosePath();
                cc.Stroke();

                cc.Color     = new Cairo.Color(1, 1, 1, 1);
                cc.LineWidth = 1;
                cc.SetDash(new double[] { 3, 3 }, 0);
                cc.MoveTo(scr_lt.X, scr_lt.Y);
                cc.LineTo(scr_lb.X, scr_lb.Y);
                cc.LineTo(scr_rb.X, scr_rb.Y);
                cc.LineTo(scr_rt.X, scr_rt.Y);
                cc.LineTo(scr_lt.X, scr_lt.Y);
                cc.ClosePath();
                cc.Stroke();
            }


            // Drawing center "triangle" dot.
            using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.triangle_dot.png"))
            {
                target.DrawPixbuf(gc, buf,
                                  0, 0, (int)(scr_c_x - buf.Width / 2), (int)(scr_c_y - buf.Height / 2),
                                  buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0);
            }

            // Drawing side "round" dot.
            using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.round_dot.png"))
            {
                target.DrawPixbuf(gc, buf,
                                  0, 0,
                                  (int)(scr_rnd.X - buf.Width / 2),
                                  (int)(scr_rnd.Y - buf.Height / 2),
                                  buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0);
            }

            // Drawing corner "square" dot.
            using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.square_dot.png"))
            {
                target.DrawPixbuf(gc, buf,
                                  0, 0,
                                  (int)(scr_rb.X - buf.Width / 2),
                                  (int)(scr_rb.Y - buf.Height / 2),
                                  buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0);
            }
        }