Ejemplo n.º 1
0
        protected override bool OnExposeEvent(Gdk.EventExpose ev)
        {
            base.OnExposeEvent(ev);

            if (thumbnail == null)
            {
                UpdateThumbnail();
            }

            Rectangle rect = GdkWindow.GetBounds();

            Cairo.PointD pos   = PositionToClientPt(Position);
            Cairo.Color  black = new Cairo.Color(0, 0, 0);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                //background
                g.SetSource(thumbnail, 0.0, 0.0);
                g.Paint();

                g.DrawRectangle(new Cairo.Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 1, rect.Height - 1), new Cairo.Color(.75, .75, .75), 1);
                g.DrawRectangle(new Cairo.Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3), black, 1);

                //cursor
                g.DrawLine(new Cairo.PointD(pos.X + 1, rect.Top + 2), new Cairo.PointD(pos.X + 1, rect.Bottom - 2), black, 1);
                g.DrawLine(new Cairo.PointD(rect.Left + 2, pos.Y + 1), new Cairo.PointD(rect.Right - 2, pos.Y + 1), black, 1);

                //point
                g.DrawEllipse(new Cairo.Rectangle(pos.X - 1, pos.Y - 1, 3, 3), black, 2);
            }
            return(true);
        }
Ejemplo n.º 2
0
 public override void Draw(Cairo.Context dc)
 {
     if (TheFill != null)
     {
         dc.FillEllipse(BB); //TheFill,
     }
     if (ThePen != null)
     {
         dc.DrawEllipse(BB); //ThePen,
     }
 }
Ejemplo n.º 3
0
        public override void Draw(Cairo.Context dc)
        {
            Pen  p   = IsSelected ? SelPen : StdPen;
            Rect lBB = GetBB(Parent.Height);

            // draw lines
            if (L1Visible)
            {
                dc.DrawLine(L1Origin, lBB.Center()); //DashedPen,
            }
            if (L2Visible)
            {
                dc.DrawLine(L2Origin, lBB.Center()); //DashedPen,
            }
            // draw CP
            dc.FillEllipse(lBB); //Brushes.Gray,
            dc.DrawEllipse(lBB); //p,
        }
Ejemplo n.º 4
0
        protected override bool OnExposeEvent(Gdk.EventExpose ev)
        {
            base.OnExposeEvent(ev);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                Cairo.Rectangle ourRect  = Rectangle.Inflate(GdkWindow.GetBounds(), -1, -1).ToCairoRectangle();
                double          diameter = Math.Min(ourRect.Width, ourRect.Height);

                double radius = (diameter / 2.0);

                Cairo.PointD center = new Cairo.PointD(
                    (float)(ourRect.X + radius),
                    (float)(ourRect.Y + radius));

                double theta = (this.angleValue * 2.0 * Math.PI) / 360.0;

                Cairo.Rectangle ellipseRect        = new Cairo.Rectangle(ourRect.Location(), diameter, diameter);
                Cairo.Rectangle ellipseOutlineRect = ellipseRect;

                g.DrawEllipse(ellipseOutlineRect, new Cairo.Color(.1, .1, .1), 1);

                double endPointRadius = radius - 2;

                Cairo.PointD endPoint = new Cairo.PointD(
                    (float)(center.X + (endPointRadius * Math.Cos(theta))),
                    (float)(center.Y - (endPointRadius * Math.Sin(theta))));

                float           gripSize        = 2.5f;
                Cairo.Rectangle gripEllipseRect = new Cairo.Rectangle(center.X - gripSize, center.Y - gripSize, gripSize * 2, gripSize * 2);

                g.FillEllipse(gripEllipseRect, new Cairo.Color(.1, .1, .1));
                g.DrawLine(center, endPoint, new Cairo.Color(.1, .1, .1), 1);
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a cursor icon with a shape that visually represents the tool's thickness.
        /// </summary>
        /// <param name="imgName">A string containing the name of the tool's icon image to use.</param>
        /// <param name="shape">The shape to draw.</param>
        /// <param name="shapeWidth">The width of the shape.</param>
        /// <param name="imgToShapeX">The horizontal distance between the image's top-left corner and the shape center.</param>
        /// <param name="imgToShapeY">The verical distance between the image's top-left corner and the shape center.</param>
        /// <param name="shapeX">The X position in the returned Pixbuf that will be the center of the shape.</param>
        /// <param name="shapeY">The Y position in the returned Pixbuf that will be the center of the shape.</param>
        /// <returns>The new cursor icon with an shape that represents the tool's thickness.</returns>
        public static Gdk.Pixbuf CreateIconWithShape(string imgName, CursorShape shape, int shapeWidth,
                                                     int imgToShapeX, int imgToShapeY,
                                                     out int shapeX, out int shapeY)
        {
            Gdk.Pixbuf img = PintaCore.Resources.GetIcon(imgName);

            double zoom = 1d;

            if (PintaCore.Workspace.HasOpenDocuments)
            {
                zoom = Math.Min(30d, PintaCore.Workspace.ActiveDocument.Workspace.Scale);
            }

            shapeWidth = (int)Math.Min(800d, ((double)shapeWidth) * zoom);
            int halfOfShapeWidth = shapeWidth / 2;

            // Calculate bounding boxes around the both image and shape
            // relative to the image top-left corner.
            Gdk.Rectangle imgBBox   = new Gdk.Rectangle(0, 0, img.Width, img.Height);
            Gdk.Rectangle shapeBBox = new Gdk.Rectangle(
                imgToShapeX - halfOfShapeWidth,
                imgToShapeY - halfOfShapeWidth,
                shapeWidth,
                shapeWidth);

            // Inflate shape bounding box to allow for anti-aliasing
            shapeBBox.Inflate(2, 2);

            // To determine required size of icon,
            // find union of the image and shape bounding boxes
            // (still relative to image top-left corner)
            Gdk.Rectangle iconBBox = imgBBox.Union(shapeBBox);

            // Image top-left corner in icon co-ordinates
            int imgX = imgBBox.Left - iconBBox.Left;
            int imgY = imgBBox.Top - iconBBox.Top;

            // Shape center point in icon co-ordinates
            shapeX = imgToShapeX - iconBBox.Left;
            shapeY = imgToShapeY - iconBBox.Top;

            using (var i = CairoExtensions.CreateImageSurface(Cairo.Format.ARGB32, iconBBox.Width, iconBBox.Height)) {
                using (var g = new Cairo.Context(i)) {
                    // Don't show shape if shapeWidth less than 3,
                    if (shapeWidth > 3)
                    {
                        int             diam      = Math.Max(1, shapeWidth - 2);
                        Cairo.Rectangle shapeRect = new Cairo.Rectangle(shapeX - halfOfShapeWidth,
                                                                        shapeY - halfOfShapeWidth,
                                                                        diam,
                                                                        diam);

                        Cairo.Color outerColor = new Cairo.Color(255, 255, 255, 0.75);
                        Cairo.Color innerColor = new Cairo.Color(0, 0, 0);

                        switch (shape)
                        {
                        case CursorShape.Ellipse:
                            g.DrawEllipse(shapeRect, outerColor, 2);
                            shapeRect = shapeRect.Inflate(-1, -1);
                            g.DrawEllipse(shapeRect, innerColor, 1);
                            break;

                        case CursorShape.Rectangle:
                            g.DrawRectangle(shapeRect, outerColor, 1);
                            shapeRect = shapeRect.Inflate(-1, -1);
                            g.DrawRectangle(shapeRect, innerColor, 1);
                            break;
                        }
                    }

                    // Draw the image
                    g.DrawPixbuf(img, new Cairo.Point(imgX, imgY));
                }

                return(CairoExtensions.ToPixbuf(i));
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
 public static void DrawEllipse(this Cairo.Context dc, System.Windows.Rect r)
 {
     dc.DrawEllipse(r.Center().X, r.Center().Y, r.Width, r.Height);
 }