NewPath() публичный Метод

public NewPath ( ) : void
Результат void
 /// <summary>
 /// Draws black in the areas outside the view.
 /// Assumes that controlBounds is starting at (0, 0) in upper left corner.
 /// </summary>
 /// <param name="context">A context to perform drawing.</param>
 /// <param name="controlBounds">Bounds of the control.</param>
 /// <param name="view">The bounds of the view.</param>
 public static void Draw(Context context, Rectangle controlBounds, Rectangle view)
 {
     context.Color = new Cairo.Color (0.0, 0.0, 0.0);
     context.NewPath ();
     context.Rectangle (0.0, 0.0, view.X, controlBounds.Height);
     var wRight = controlBounds.Width - view.X - view.Width;
     context.Rectangle (view.X + view.Width, 0.0, wRight, controlBounds.Height);
     context.Rectangle (view.X, 0.0, view.Width, view.Y);
     var hBottom = controlBounds.Height - view.Y - view.Height;
     context.Rectangle (view.X, view.Y + view.Height, view.Width, hBottom);
     context.Fill ();
 }
Пример #2
0
		public void Execute(Context ctx)
		{
			PointD point;
			var first = true;

			using (var mpath = ctx.CopyPath())
			{
				var path = mpath.GetPath();

				for (var i = 0; i < path.num_data; )
				{
					var hdr = path.GetPathHeader(i); //hdr.Dump();

					switch (hdr.type)
					{
						case NativePath.cairo_path_data_type_t.CAIRO_PATH_MOVE_TO:
							if (first)
							{
								ctx.NewPath();
								first = false;
							}
							point = path.GetPathPoint(i + 1);
							ctx.MoveTo(WarpPoint(point));
							break;
						case NativePath.cairo_path_data_type_t.CAIRO_PATH_LINE_TO:
							point = path.GetPathPoint(i + 1);
							ctx.LineTo(WarpPoint(point));
							break;
						case NativePath.cairo_path_data_type_t.CAIRO_PATH_CURVE_TO:
							var p1 = WarpPoint(path.GetPathPoint(i + 1));
							var p2 = WarpPoint(path.GetPathPoint(i + 2));
							var p3 = WarpPoint(path.GetPathPoint(i + 3));
							ctx.CurveTo(p1, p2, p3);
							break;
						case NativePath.cairo_path_data_type_t.CAIRO_PATH_CLOSE_PATH:
							ctx.ClosePath();
							break;
					}

					i += hdr.length;
				}
			}
		}
Пример #3
0
 internal static void StrokeRectangle(this Cairo.Context g,
                                      Rect rect,
                                      Color topColor,
                                      Color rightColor,
                                      Color bottomColor,
                                      Color leftColor)
 {
     g.NewPath();
     g.MoveTo(rect.TopLeft.X, rect.TopLeft.Y);
     g.SetSourceColor(topColor);
     g.LineTo(rect.TopRight.X, rect.TopRight.Y);       //Top
     g.SetSourceColor(rightColor);
     g.LineTo(rect.BottomRight.X, rect.BottomRight.Y); //Right
     g.SetSourceColor(bottomColor);
     g.LineTo(rect.BottomLeft.X, rect.BottomRight.Y);  //Bottom
     g.SetSourceColor(leftColor);
     g.LineTo(rect.TopLeft.X, rect.TopLeft.Y);         //Left
     g.ClosePath();
     g.Stroke();
 }
Пример #4
0
        protected override bool OnExposeEvent(Gdk.EventExpose ee)
        {
            // get dimensions
            int    width   = this.Allocation.Width;
            int    height  = this.Allocation.Height;
            double centerx = (double)width / 2.0;
            double centery = (double)height / 2.0;

            // init cairo or die.
            Cairo.Context gc = Gdk.CairoHelper.Create(this.GdkWindow);

            // paint widget background
            gc.Rectangle(0, 0, width, height);
            gc.Color = background;
            gc.FillPreserve();
            gc.Clip();

            gc.NewPath();
            gc.Save();
            gc.Matrix = transformMatrix;

            // draw the graphics.
            if (render != null)
            {
                render(gc);
            }

            gc.Restore();

            if (overlay != null)
            {
                overlay(gc);
            }

            PaintZoomScale(gc, width, height, centerx, centery);
            PaintMotionIndicators(gc, width, height, centerx, centery);

            ((IDisposable)gc.Target).Dispose();
            ((IDisposable)gc).Dispose();
            return(true);
        }
Пример #5
0
        /// <summary>Paint on the graphics context</summary>
        /// <param name="context">The graphics context to draw on</param>
        public override void Paint(Cairo.Context context)
        {
            OxyColor outlineColour;

            if (Selected)
            {
                outlineColour = OxyColors.Blue;
            }
            else if (transparent)
            {
                outlineColour = DefaultBackgroundColour;
            }
            else
            {
                outlineColour = DefaultOutlineColour;
            }

            OxyColor backgroundColour = transparent ? DefaultBackgroundColour : Colour;
            OxyColor textColour       = DefaultOutlineColour;

            // Draw circle
            context.SetSourceColor(outlineColour);
            context.LineWidth = 3;
            context.NewPath();
            context.Arc(Location.X, Location.Y, Width / 2, 0, 2 * Math.PI);
            context.StrokePreserve();
            context.SetSourceColor(backgroundColour);
            context.Fill();

            // Write text
            context.LineWidth = 1;
            context.SetSourceColor(textColour);
            context.SetFontSize(13);


            DrawCentredText(context, Name, Location);
        }
Пример #6
0
    public Flower( )
    {
        int idx      = -1;
        int last_idx = -1;

        int petal_size = PETAL_MIN + rand() % PETAL_VAR;
        int size       = petal_size * 8;

        int n_groups = rand() % 3 + 1;

        this.ctex = new CairoTexture((uint)size, (uint)size);

        // the using statement make sure the cr is disposed at the end,
        // otherwise we get no bling
        using (Cairo.Context cr = this.ctex.Create())
        {
            cr.Tolerance = 0.1;

            // Clear
            cr.Operator = Operator.Clear;
            cr.Paint();
            cr.Operator = Operator.Over;

            cr.Translate(size / 2, size / 2);

            // petals
            for (int i = 0; i < n_groups; i++)
            {
                int n_petals = rand() % 5 + 4;
                cr.Save();

                cr.Rotate(rand() % 6);

                do
                {
                    idx = (rand() % (colors.Length / 3)) * 3;
                } while (idx == last_idx);

                cr.SetSourceRGBA(colors[idx], colors[idx + 1], colors[idx + 2], 0.5);

                int pm1 = rand() % 20;
                int pm2 = rand() % 4;

                for (int j = 0; j < n_petals; j++)
                {
                    cr.Save();

                    cr.Rotate(((2 * Math.PI) / n_petals) * j);

                    cr.NewPath();
                    cr.MoveTo(0, 0);

                    cr.RelCurveTo(petal_size, petal_size, (pm2 + 2) * petal_size,
                                  petal_size, (2 * petal_size) + pm1, 0);

                    cr.RelCurveTo(0 + (pm2 * petal_size), -petal_size, -petal_size,
                                  -petal_size, -((2 * petal_size) + pm1), 0);

                    cr.ClosePath();
                    cr.Fill();
                    cr.Restore();
                }

                petal_size -= rand() % (size / 8);

                cr.Restore();
            }

            // flower center
            do
            {
                idx = (rand() % (colors.Length / 4 / 3)) * 3;
            } while (idx == last_idx);

            if (petal_size < 0)
            {
                petal_size = rand() % 10;
            }

            cr.SetSourceRGBA(colors[idx], colors[idx + 1], colors[idx + 2], 0.5);

            cr.Arc(0, 0, petal_size, 0, Math.PI * 2);
            cr.Fill();
        }
    }
Пример #7
0
		void DrawTab (Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la)
		{
			// This logic is stupid to have here, should be in the caller!
			if (dragging) {
				tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress);
				tabBounds.X = Clamp (tabBounds.X, tabStartX, tabEndX - tabBounds.Width);
			}
			int padding = LeftRightPadding;
			padding = (int)(padding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0)));

			ctx.LineWidth = 1;
			LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 0, active);
			ctx.ClosePath ();
			using (var gr = new LinearGradient (tabBounds.X, TopBarPadding, tabBounds.X, allocation.Bottom)) {
				if (active) {
					gr.AddColorStop (0, Styles.BreadcrumbGradientStartColor.MultiplyAlpha (tab.Opacity));
					gr.AddColorStop (1, Styles.BreadcrumbBackgroundColor.MultiplyAlpha (tab.Opacity));
				} else {
					gr.AddColorStop (0, CairoExtensions.ParseColor ("f4f4f4").MultiplyAlpha (tab.Opacity));
					gr.AddColorStop (1, CairoExtensions.ParseColor ("cecece").MultiplyAlpha (tab.Opacity));
				}
				ctx.SetSource (gr);
			}
			ctx.Fill ();

			ctx.SetSourceColor (new Cairo.Color (1, 1, 1, .5).MultiplyAlpha (tab.Opacity));
			LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 1, active);
			ctx.Stroke ();

			ctx.SetSourceColor (Styles.BreadcrumbBorderColor.MultiplyAlpha (tab.Opacity));
			LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 0, active);
			ctx.StrokePreserve ();

			if (tab.GlowStrength > 0) {
				Gdk.Point mouse = tracker.MousePosition;
				using (var rg = new RadialGradient (mouse.X, tabBounds.Bottom, 0, mouse.X, tabBounds.Bottom, 100)) {
					rg.AddColorStop (0, new Cairo.Color (1, 1, 1, 0.4 * tab.Opacity * tab.GlowStrength));
					rg.AddColorStop (1, new Cairo.Color (1, 1, 1, 0));

					ctx.SetSource (rg);
					ctx.Fill ();
				}
			} else {
				ctx.NewPath ();
			}

			// Render Close Button (do this first so we can tell how much text to render)

			var ch = allocation.Height - TopBarPadding - BottomBarPadding + CloseImageTopOffset;
			var crect = new Gdk.Rectangle (tabBounds.Right - padding - CloseButtonSize + 3,
				            tabBounds.Y + TopBarPadding + (ch - CloseButtonSize) / 2,
				            CloseButtonSize, CloseButtonSize);
			tab.CloseButtonAllocation = crect;
			tab.CloseButtonAllocation.Inflate (2, 2);

			bool closeButtonHovered = tracker.Hovered && tab.CloseButtonAllocation.Contains (tracker.MousePosition) && tab.WidthModifier >= 1.0f;
			bool drawCloseButton = tabBounds.Width > 60 || highlight || closeButtonHovered;
			if (drawCloseButton) {
				DrawCloseButton (ctx, new Gdk.Point (crect.X + crect.Width / 2, crect.Y + crect.Height / 2), closeButtonHovered, tab.Opacity, tab.DirtyStrength);
			}

			// Render Text
			int w = tabBounds.Width - (padding * 2 + CloseButtonSize);
			if (!drawCloseButton)
				w += CloseButtonSize;

			int textStart = tabBounds.X + padding;

			ctx.MoveTo (textStart, tabBounds.Y + TopPadding + TextOffset + VerticalTextSize);
			if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows) {
				// This is a work around for a linux specific problem.
				// A bug in the proprietary ATI driver caused TAB text not to draw.
				// If that bug get's fixed remove this HACK asap.
				la.Ellipsize = Pango.EllipsizeMode.End;
				la.Width = (int)(w * Pango.Scale.PangoScale);
				ctx.SetSourceColor (tab.Notify ? new Cairo.Color (0, 0, 1) : Styles.TabBarActiveTextColor);
				Pango.CairoHelper.ShowLayoutLine (ctx, la.GetLine (0));
			} else {
				// ellipses are for space wasting ..., we cant afford that
				using (var lg = new LinearGradient (textStart + w - 5, 0, textStart + w + 3, 0)) {
					var color = tab.Notify ? new Cairo.Color (0, 0, 1) : Styles.TabBarActiveTextColor;
					color = color.MultiplyAlpha (tab.Opacity);
					lg.AddColorStop (0, color);
					color.A = 0;
					lg.AddColorStop (1, color);
					ctx.SetSource (lg);
					Pango.CairoHelper.ShowLayoutLine (ctx, la.GetLine (0));
				}
			}
			la.Dispose ();
		}
Пример #8
0
		void DrawTab (Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la)
		{
			// This logic is stupid to have here, should be in the caller!
			if (dragging) {
				tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress);
				tabBounds.X = Clamp (tabBounds.X, tabStartX, tabEndX - tabBounds.Width);
			}
			double rightPadding = (active ? TabActivePadding.Right : TabPadding.Right) - (LeanWidth / 2);
			rightPadding = (rightPadding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0)));
			double leftPadding = (active ? TabActivePadding.Left : TabPadding.Left) - (LeanWidth / 2);
			leftPadding = (leftPadding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0)));
			double bottomPadding = active ? TabActivePadding.Bottom : TabPadding.Bottom;

			DrawTabBackground (this, ctx, allocation, tabBounds.Width, tabBounds.X, active);

			ctx.LineWidth = 1;
			ctx.NewPath ();

			// Render Close Button (do this first so we can tell how much text to render)

			var closeButtonAlloation = new Cairo.Rectangle (tabBounds.Right - rightPadding - (tabCloseImage.Width / 2) - CloseButtonMarginRight,
			                                 tabBounds.Height - bottomPadding - tabCloseImage.Height - CloseButtonMarginBottom,
			                                 tabCloseImage.Width, tabCloseImage.Height);
			
			tab.CloseButtonActiveArea = closeButtonAlloation.Inflate (2, 2);

			bool closeButtonHovered = tracker.Hovered && tab.CloseButtonActiveArea.Contains (tracker.MousePosition);
			bool tabHovered = tracker.Hovered && tab.Allocation.Contains (tracker.MousePosition);
			bool drawCloseButton = active || tabHovered;

			if (!closeButtonHovered && tab.DirtyStrength > 0.5) {
				ctx.DrawImage (this, tabDirtyImage, closeButtonAlloation.X, closeButtonAlloation.Y);
				drawCloseButton = false;
			}

			if (drawCloseButton)
				ctx.DrawImage (this, tabCloseImage.WithAlpha ((closeButtonHovered ? 1.0 : 0.5) * tab.Opacity), closeButtonAlloation.X, closeButtonAlloation.Y);
			
			// Render Text
			double tw = tabBounds.Width - (leftPadding + rightPadding);
			if (drawCloseButton || tab.DirtyStrength > 0.5)
				tw -= closeButtonAlloation.Width / 2;

			double tx = tabBounds.X + leftPadding;
			var baseline = la.GetLine (0).Layout.GetPixelBaseline ();
			double ty = tabBounds.Height - bottomPadding - baseline;

			ctx.MoveTo (tx, ty);
			if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows) {
				// This is a work around for a linux specific problem.
				// A bug in the proprietary ATI driver caused TAB text not to draw.
				// If that bug get's fixed remove this HACK asap.
				la.Ellipsize = Pango.EllipsizeMode.End;
				la.Width = (int)(tw * Pango.Scale.PangoScale);
				ctx.SetSourceColor ((tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor ());
				Pango.CairoHelper.ShowLayout (ctx, la.GetLine (0).Layout);
			} else {
				// ellipses are for space wasting ..., we cant afford that
				using (var lg = new LinearGradient (tx + tw - 10, 0, tx + tw, 0)) {
					var color = (tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor ();
					color = color.MultiplyAlpha (tab.Opacity);
					lg.AddColorStop (0, color);
					color.A = 0;
					lg.AddColorStop (1, color);
					ctx.SetSource (lg);
					Pango.CairoHelper.ShowLayout (ctx, la.GetLine (0).Layout);
				}
			}
            la.Dispose ();
		}
Пример #9
0
        void DrawShape(Context g, int width, int height)
        {
            int inner_x = radius + border + inner;
            int cx = Center.X;
            int cy = Center.Y;

            g.Operator = Operator.Source;
            g.SetSource (new SolidPattern (new Cairo.Color (0,0,0,0)));
            g.Rectangle (0, 0, width, height);
            g.Paint ();

            g.NewPath ();
            g.Translate (cx, cy);
            g.Rotate (angle);

            g.SetSource (new SolidPattern (new Cairo.Color (0.2, 0.2, 0.2, .6)));
            g.Operator = Operator.Over;
            g.Rectangle (0, - (border + inner), inner_x, 2 * (border + inner));
            g.Arc (inner_x, 0, inner + border, 0, 2 * Math.PI);
            g.Arc (0, 0, radius + border, 0, 2 * Math.PI);
            g.Fill ();

            g.SetSource (new SolidPattern (new Cairo.Color (0, 0, 0, 1.0)));
            g.Operator = Operator.DestOut;
            g.Arc (inner_x, 0, inner, 0, 2 * Math.PI);
            #if true
            g.Fill ();
            #else
            g.FillPreserve ();

            g.Operator = Operator.Over;
            RadialGradient rg = new RadialGradient (inner_x - (inner * 0.3), inner * 0.3 , inner * 0.1, inner_x, 0, inner);
            rg.AddColorStop (0, new Cairo.Color (0.0, 0.2, .8, 0.5));
            rg.AddColorStop (0.7, new Cairo.Color (0.0, 0.2, .8, 0.1));
            rg.AddColorStop (1.0, new Cairo.Color (0.0, 0.0, 0.0, 0.0));
            g.Source = rg;
            g.Fill ();
            rg.Destroy ();
            #endif
            g.Operator = Operator.Over;
            g.Matrix = new Matrix ();
            g.Translate (cx, cy);
            if (source != null)
            CairoHelper.SetSourcePixbuf (g, source, -source.Width / 2, -source.Height / 2);

            g.Arc (0, 0, radius, 0, 2 * Math.PI);
            g.Fill ();

            if (overlay != null) {
                CairoHelper.SetSourcePixbuf (g, overlay, -overlay.Width / 2, -overlay.Height / 2);
                g.Arc (0, 0, radius, angle, angle + Math.PI);
                g.ClosePath ();
                g.FillPreserve ();
                g.SetSource (new SolidPattern (new Cairo.Color (1.0, 1.0, 1.0, 1.0)));
                g.Stroke ();
            }
        }
Пример #10
0
 /** FAST */
 bool ClickSortBar(Context cr, double x, double y)
 {
     cr.NewPath ();
     cr.MoveTo (0.0, 0.0);
     TextExtents te;
     cr.Color = ActiveColor;
     cr.RelMoveTo ( 0.0, ToolbarLabelFontSize * 0.4 );
     Helpers.DrawText (cr, ToolbarTitleFontFamily, ToolbarTitleFontSize, SortLabel);
     cr.RelMoveTo ( 0.0, ToolbarLabelFontSize * -0.4 );
     foreach (SortHandler sf in SortFields) {
       cr.Color = (SortField == sf) ? ActiveColor : InActiveColor;
       te = Helpers.GetTextExtents (
     cr, ToolbarLabelFontFamily, ToolbarLabelFontSize, sf.Name);
       if (Helpers.CheckTextExtents(cr, te, x, y)) {
     SortField = sf;
     ResetZoom ();
     UpdateLayout ();
     return true;
       }
       Helpers.DrawText (cr, ToolbarLabelFontFamily, ToolbarLabelFontSize, sf.Name);
       Helpers.DrawText (cr, ToolbarLabelFontFamily, ToolbarLabelFontSize, " ");
     }
     return false;
 }
Пример #11
0
 /** FAST */
 void DrawSortBar(Context cr)
 {
     cr.NewPath ();
     cr.MoveTo (0.0, 0.0);
     cr.Color = ActiveColor;
     cr.RelMoveTo ( 0.0, ToolbarLabelFontSize * 0.4 );
     Helpers.DrawText (cr, ToolbarTitleFontFamily, ToolbarTitleFontSize, SortLabel);
     cr.RelMoveTo ( 0.0, ToolbarLabelFontSize * -0.4 );
     foreach (SortHandler sf in SortFields) {
       cr.Color = (SortField == sf) ? ActiveColor : InActiveColor;
       Helpers.DrawText (cr, ToolbarLabelFontFamily, ToolbarLabelFontSize, sf.Name);
       Helpers.DrawText (cr, ToolbarLabelFontFamily, ToolbarLabelFontSize, " ");
     }
 }
Пример #12
0
    /* Draw main view */
    /** BLOCKING */
    void DrawMainView(Context cr, uint width, uint height)
    {
        cr.Save ();
          cr.NewPath ();
          cr.IdentityMatrix ();
          DrawToolbars (cr, width, height);
          cr.NewPath ();
          cr.IdentityMatrix ();
          Rectangle targetBox = Transform (cr, width, height);
          DrawCurrentDir(cr, targetBox);
        cr.Restore ();

        dirLatencyProfiler.Stop ();
        if (FirstFrameOfDir) {
          dirLatencyProfiler.Time ("Directory latency");
          FirstFrameOfDir = false;
        }
        if (Helpers.StartupProfiler.Watch.IsRunning) {
          Helpers.StartupProfiler.Time ("Draw complete");
          Helpers.StartupProfiler.Total ("Startup complete");
          Helpers.StartupProfiler.Stop ();
          if (QuitAfterFirstFrame) Application.Quit ();
        }
    }
Пример #13
0
 /** FAST */
 void DrawBreadcrumb(Context cr, uint width)
 {
     cr.NewPath ();
     cr.MoveTo (0.0, 0.0);
     Profiler p = new Profiler ();
     p.Time("In breadcrumb");
     TextExtents te = Helpers.GetTextExtents (cr, BreadcrumbFontFamily, BreadcrumbFontSize, String.Join(dirSep, CurrentDirPath.Split(Helpers.DirSepC)) + dirSep);
     p.Time("GetTextExtents");
     cr.Color = Renderer.DirectoryFGColor;
     cr.Save ();
       double areaWidth = width-BreadcrumbMarginLeft-BreadcrumbMarginRight;
       cr.Rectangle (0,0,areaWidth, te.Height);
       cr.Clip ();
       cr.Translate (Math.Min(0,areaWidth-te.Width), 0);
       cr.MoveTo (0.0, 0.0);
       if (CurrentDirPath == Helpers.RootDir) {
     Helpers.DrawText (cr, BreadcrumbFontFamily, BreadcrumbFontSize, rootChar);
       } else {
     p.Time("start DrawText");
     foreach (string s in CurrentDirPath.Split(Helpers.DirSepC)) {
       Helpers.DrawText (cr, BreadcrumbFontFamily, BreadcrumbFontSize, s == "" ? rootChar : (s+dirSep));
     }
     p.Time("DrawText");
       }
     cr.Restore ();
 }
Пример #14
0
 /** FAST */
 void DrawBackground(Context cr, uint width, uint height)
 {
     cr.Save ();
       DrawClear (cr, width, height);
       double t = DateTime.Now.ToFileTime() / 1e7;
       cr.Save ();
     Color ca = Renderer.DirectoryFGColor;
     ca.A = 0.3;
     cr.Color = ca;
     cr.LineWidth = 0.5;
     cr.Translate (270, -50);
     cr.Rotate (0.15);
     for (double y=0; y<6; y++) {
     for (double i=0; i<6-y; i++) {
       cr.Save ();
         double hr = 45;
         double iscale = Math.Sin(-i/20 * Math.PI*2 + CylinderRotation);
         double xscale = Math.Cos(-i/20 * Math.PI*2 + 0.1 + CylinderRotation);
         cr.Translate (iscale * hr * 3, -100 + y*hr*(2*1.732) + hr*(i%2)*1.732);
         hr = 45;
         cr.Scale (xscale, 1);
         cr.NewPath ();
         cr.MoveTo (0, -hr);
         cr.LineTo (0.866*hr, -0.5*hr);
         cr.LineTo (0.866*hr, 0.5*hr);
         cr.LineTo (0, hr);
         cr.LineTo (-0.866*hr, 0.5*hr);
         cr.LineTo (-0.866*hr, -0.5*hr);
         cr.ClosePath ();
         cr.Color = ca;
         cr.Stroke ();
         cr.Color = Renderer.SocketColor;
         cr.Translate (0.75 * -0.866*hr, 0.75 * -0.5*hr);
         double x2 = cr.Matrix.X0, y2 = cr.Matrix.Y0;
         cr.IdentityMatrix ();
         cr.Arc (x2,y2, 1, 0, Math.PI*2);
         cr.Fill ();
       cr.Restore ();
     }
     }
     CylinderRotation += 0.02;
       cr.Restore ();
       if (CurrentDirEntry.InProgress || (t - LastProgress < 3)) {
     if (FirstProgress == 0) { FirstProgress = LastProgress = t; }
     if (CurrentDirEntry.InProgress) LastProgress = t;
     double opacity = Math.Min(3, t-FirstProgress) - Math.Max(0, t-LastProgress);
     t = (t * 0.1) % Math.PI*2;
     Color c = Renderer.RegularFileColor;
     c.A = 0.1*opacity;
     cr.Color = c;
     cr.LineWidth = 1;
     double n = 6;
     double af = Math.PI*2/n;
     double r = 400*(4.4+0.3*cosScale(opacity/3));
     for (double i=0; i<n; i++) {
       cr.Arc (-400*4, 1000/4, r, t+i*af, t+(i+0.7)*af);
       cr.Stroke ();
     }
     for (double i=0; i<n; i++) {
       cr.Arc (-400*4, 1000/4, r+5, -t+i*af, -t+(i+0.7)*af);
       cr.Stroke ();
     }
     if (CurrentDirEntry.InProgress) {
       cr.NewPath ();
         // find FSCache.LastTraversed [or ancestor] y position from model
         // draw line there
       cr.NewPath ();
     }
     LimitedRedraw = true;
       } else {
     FirstProgress = 0;
     LastProgress = 0;
       }
     cr.Restore ();
 }
Пример #15
0
 internal Path RenderToCairoPath(Context context, DirectWriteCairoTextRenderer render, TextLayout textLayout)
 {
     //Debug.WriteLine("Before `Draw`: Current point at <{0},{1}>", (float)context.CurrentPoint.X, (float)context.CurrentPoint.Y);
     Draw(context.Handle, render, (float)context.CurrentPoint.X, (float)context.CurrentPoint.Y);
     var result = context.CopyPath();
     context.NewPath();
     return result;
 }
Пример #16
0
 /** FAST */
 public static bool CheckTextExtents(Context cr, TextExtents te, double x, double y)
 {
     bool retval = false;
     cr.Save ();
       PointD pt = cr.CurrentPoint;
       cr.NewPath ();
       cr.Rectangle (pt.X, pt.Y, te.Width, te.Height);
       cr.IdentityMatrix ();
       retval = cr.InFill (x, y);
       if (ShowTextExtents) {
     cr.Operator = Operator.Over;
     cr.Color = new Color (1,0.5,1,0.5);
     cr.LineWidth = 0.5;
     cr.Stroke ();
       }
     cr.Restore ();
     cr.MoveTo (pt.X, pt.Y);
     return retval;
 }
Пример #17
0
        void DrawTab(Cairo.Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la)
        {
            // This logic is stupid to have here, should be in the caller!
            if (dragging)
            {
                tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress);
                tabBounds.X = Clamp(tabBounds.X, tabStartX, tabEndX - tabBounds.Width);
            }
            int padding = LeftRightPadding;

            padding = (int)(padding * Math.Min(1.0, Math.Max(0.5, (tabBounds.Width - 30) / 70.0)));


            ctx.LineWidth = 1;
            LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 0, active);
            ctx.ClosePath();
            using (LinearGradient gr = new LinearGradient(tabBounds.X, TopBarPadding, tabBounds.X, allocation.Bottom)) {
                if (active)
                {
                    gr.AddColorStop(0, Styles.BreadcrumbGradientStartColor.MultiplyAlpha(tab.Opacity));
                    gr.AddColorStop(1, Styles.BreadcrumbBackgroundColor.MultiplyAlpha(tab.Opacity));
                }
                else
                {
                    gr.AddColorStop(0, CairoExtensions.ParseColor("f4f4f4").MultiplyAlpha(tab.Opacity));
                    gr.AddColorStop(1, CairoExtensions.ParseColor("cecece").MultiplyAlpha(tab.Opacity));
                }
                ctx.Pattern = gr;
            }
            ctx.Fill();

            ctx.Color = new Cairo.Color(1, 1, 1, .5).MultiplyAlpha(tab.Opacity);
            LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 1, active);
            ctx.Stroke();

            ctx.Color = Styles.BreadcrumbBorderColor.MultiplyAlpha(tab.Opacity);
            LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 0, active);
            ctx.StrokePreserve();

            if (tab.GlowStrength > 0)
            {
                Gdk.Point mouse = tracker.MousePosition;
                using (var rg = new RadialGradient(mouse.X, tabBounds.Bottom, 0, mouse.X, tabBounds.Bottom, 100)) {
                    rg.AddColorStop(0, new Cairo.Color(1, 1, 1, 0.4 * tab.Opacity * tab.GlowStrength));
                    rg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0));

                    ctx.Pattern = rg;
                    ctx.Fill();
                }
            }
            else
            {
                ctx.NewPath();
            }

            // Render Close Button (do this first so we can tell how much text to render)

            var ch    = allocation.Height - TopBarPadding - BottomBarPadding + CloseImageTopOffset;
            var crect = new Gdk.Rectangle(tabBounds.Right - padding - CloseButtonSize + 3,
                                          tabBounds.Y + TopBarPadding + (ch - CloseButtonSize) / 2,
                                          CloseButtonSize, CloseButtonSize);

            tab.CloseButtonAllocation = crect;
            tab.CloseButtonAllocation.Inflate(2, 2);

            bool closeButtonHovered = tracker.Hovered && tab.CloseButtonAllocation.Contains(tracker.MousePosition) && tab.WidthModifier >= 1.0f;
            bool drawCloseButton    = tabBounds.Width > 60 || highlight || closeButtonHovered;

            if (drawCloseButton)
            {
                DrawCloseButton(ctx, new Gdk.Point(crect.X + crect.Width / 2, crect.Y + crect.Height / 2), closeButtonHovered, tab.Opacity, tab.DirtyStrength);
            }

            // Render Text
            int w = tabBounds.Width - (padding * 2 + CloseButtonSize);

            if (!drawCloseButton)
            {
                w += CloseButtonSize;
            }

            int textStart = tabBounds.X + padding;

            ctx.MoveTo(textStart, tabBounds.Y + TopPadding + TextOffset + VerticalTextSize);
            // ellipses are for space wasting ..., we cant afford that
            using (var lg = new LinearGradient(textStart + w - 5, 0, textStart + w + 3, 0)) {
                var color = tab.Notify ? new Cairo.Color(0, 0, 1) : Styles.TabBarActiveTextColor;
                color = color.MultiplyAlpha(tab.Opacity);
                lg.AddColorStop(0, color);
                color.A = 0;
                lg.AddColorStop(1, color);
                ctx.Pattern = lg;
                Pango.CairoHelper.ShowLayoutLine(ctx, la.GetLine(0));
            }
            la.Dispose();
        }
        public void Render(Cairo.Context context, StatusArea.RenderArg arg, Gtk.Widget widget)
        {
            context.CachedDraw(surface: ref backgroundSurface,
                               region: arg.Allocation,
                               draw: (c, o) => DrawBackground(c, new Gdk.Rectangle(0, 0, arg.Allocation.Width, arg.Allocation.Height)));

            if (arg.BuildAnimationOpacity > 0.001f)
            {
                DrawBuildEffect(context, arg.Allocation, arg.BuildAnimationProgress, arg.BuildAnimationOpacity);
            }

            if (arg.ErrorAnimationProgress > 0.001 && arg.ErrorAnimationProgress < .999)
            {
                DrawErrorAnimation(context, arg);
            }

            DrawBorder(context, arg.Allocation);

            if (arg.HoverProgress > 0.001f)
            {
                context.Clip();
                int x1 = arg.Allocation.X + arg.MousePosition.X - 200;
                int x2 = x1 + 400;
                using (Cairo.LinearGradient gradient = new LinearGradient(x1, 0, x2, 0))
                {
                    Cairo.Color targetColor      = Styles.StatusBarFill1Color;
                    Cairo.Color transparentColor = targetColor;
                    targetColor.A      = .7;
                    transparentColor.A = 0;

                    targetColor.A = .7 * arg.HoverProgress;

                    gradient.AddColorStop(0.0, transparentColor);
                    gradient.AddColorStop(0.5, targetColor);
                    gradient.AddColorStop(1.0, transparentColor);

                    context.SetSource(gradient);

                    context.Rectangle(x1, arg.Allocation.Y, x2 - x1, arg.Allocation.Height);
                    context.Fill();
                }
                context.ResetClip();
            }
            else
            {
                context.NewPath();
            }

            int progress_bar_x     = arg.ChildAllocation.X;
            int progress_bar_width = arg.ChildAllocation.Width;

            if (arg.CurrentPixbuf != null)
            {
                int y = arg.Allocation.Y + (arg.Allocation.Height - (int)arg.CurrentPixbuf.Size.Height) / 2;
                context.DrawImage(widget, arg.CurrentPixbuf, arg.ChildAllocation.X, y);
                progress_bar_x     += (int)arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
                progress_bar_width -= (int)arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
            }

            int center = arg.Allocation.Y + arg.Allocation.Height / 2;

            Gdk.Rectangle progressArea = new Gdk.Rectangle(progress_bar_x, center - Styles.ProgressBarHeight / 2, progress_bar_width, Styles.ProgressBarHeight);
            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                DrawProgressBar(context, arg.ProgressBarFraction, progressArea, arg);
                ClipProgressBar(context, progressArea);
            }

            int text_x     = progress_bar_x + Styles.ProgressBarInnerPadding;
            int text_width = progress_bar_width - (Styles.ProgressBarInnerPadding * 2);

            double textTweenValue = arg.TextAnimationProgress;

            if (arg.LastText != null)
            {
                double opacity = Math.Max(0.0f, 1.0f - textTweenValue);
                DrawString(arg.LastText, arg.LastTextIsMarkup, context, text_x,
                           center - (int)(textTweenValue * arg.Allocation.Height * 0.3), text_width, opacity, arg.Pango, arg);
            }

            if (arg.CurrentText != null)
            {
                DrawString(arg.CurrentText, arg.CurrentTextIsMarkup, context, text_x,
                           center + (int)((1.0f - textTweenValue) * arg.Allocation.Height * 0.3), text_width, Math.Min(textTweenValue, 1.0), arg.Pango, arg);
            }

            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                context.ResetClip();
            }
        }
Пример #19
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (this.Controls != null && this.Controls.PlayerPocess != null)
            {
                return(true);
            }

            bool baseDrawnResult = base.OnDrawn(cr);

            var scaledPixbuf = this.ScaledPixbuf;

            if (scaledPixbuf == null)
            {
                this.hasFrameBeenQueued = false;
                return(baseDrawnResult);
            }

            // black background in fullscreen mode
            if (BooruApp.BooruApplication.MainWindow.IsFullscreen)
            {
                cr.SetSourceRGB(0, 0, 0);
                cr.Rectangle(new Rectangle(0, 0, this.Allocation.Width, this.Allocation.Height));
                cr.Fill();
            }

            cr.Rectangle(this.TargetRect);
            Gdk.CairoHelper.SetSourcePixbuf(cr, scaledPixbuf, TargetRect.X, TargetRect.Y);
            if (this.fadeAlpha < 1.0)
            {
                cr.PaintWithAlpha(this.fadeAlpha);
                cr.NewPath();
            }
            else
            {
                cr.Fill();
            }

            cr.SelectFontFace("Noto Mono", FontSlant.Normal, FontWeight.Normal);
            cr.SetFontSize(12.0);
            cr.LineWidth = 3.5;

            if (this.fadeAlpha < 1.0)
            {
                var ext          = cr.TextExtents("Loading...");
                var center       = new Point2D(this.Allocation.Width / 2 - (int)ext.Width / 2, this.Allocation.Height / 2 - (int)ext.Height / 2);
                var whiteInverse = new Color(1, 1, 1, 1 - this.fadeAlpha);
                var blackInverse = new Color(0, 0, 0, 1 - this.fadeAlpha);
                cr.DrawStringAt(center.X, center.Y, "Loading...", blackInverse, whiteInverse);
            }

            var white = new Cairo.Color(1, 1, 1, this.fadeAlpha);
            var black = new Cairo.Color(0, 0, 0, this.fadeAlpha);

            // cr.DrawStringAt (4, 4 + cr.FontExtents.Height, System.IO.Path.GetFileName (this.image.Details.Path), black, white);

            if (this.image.MaxImage > -1)
            {
                string text;
                if (this.image.SubImage < 0)
                {
                    text = string.Format("{0:D} images in file", this.image.MaxImage);
                }
                else
                {
                    text = string.Format("{0:D3}/{1:D3} {2}", this.image.SubImage, this.image.MaxImage, this.image.SubImageName);
                }
                cr.DrawStringAt(4, this.Allocation.Height - cr.FontExtents.Height - 4, text, black, white);
            }

            this.hasFrameBeenQueued = false;
            return(baseDrawnResult);
        }
Пример #20
0
			protected override bool OnDrawn (Context ctx)
			{
				int w, h;
				this.GdkWindow.GetSize (out w, out h);
				var bounds = new Xwt.Rectangle (0.5, 0.5, w - 1, h - 1);
				var backgroundColor = Xwt.Drawing.Color.FromBytes (230, 230, 230, 230);
				var black = Xwt.Drawing.Color.FromBytes (60, 60, 60);

				// We clear the surface with a transparent color if possible
				if (supportAlpha)
					ctx.SetSourceRGBA (1.0, 1.0, 1.0, 0.0);
				else
					ctx.SetSourceRGB (1.0, 1.0, 1.0);
				ctx.Operator = Operator.Source;
				ctx.Paint ();
				
				var calibratedRect = RecalibrateChildRectangle (bounds);
				// Fill it with one round rectangle
				RoundRectangle (ctx, calibratedRect, radius);
				ctx.LineWidth = 1;
				ctx.SetSourceRGBA (black.Red, black.Green, black.Blue, black.Alpha);
				ctx.StrokePreserve ();
				ctx.SetSourceRGBA (backgroundColor.Red, backgroundColor.Green, backgroundColor.Blue, backgroundColor.Alpha);
				ctx.Fill ();
				
				// Triangle
				// We first begin by positionning ourselves at the top-center or bottom center of the previous rectangle
				var arrowX = bounds.Center.X;
				var arrowY = arrowPosition == Xwt.Popover.Position.Top ? calibratedRect.Top + ctx.LineWidth : calibratedRect.Bottom - ctx.LineWidth;
				ctx.NewPath ();
				ctx.MoveTo (arrowX, arrowY);
				// We draw the rectangle path
				DrawTriangle (ctx);
				// We use it
				ctx.SetSourceRGBA (black.Red, black.Green, black.Blue, black.Alpha);
				ctx.StrokePreserve ();
				ctx.ClosePath ();
				ctx.SetSourceRGBA (backgroundColor.Red, backgroundColor.Green, backgroundColor.Blue, backgroundColor.Alpha);
				ctx.Fill ();

				return base.OnDrawn (ctx);
			}
Пример #21
0
		public void clip_image(Context cr, int width, int height)
		{
			Normalize (cr, width, height);
			cr.Arc (0.5, 0.5, 0.3, 0, 2*Math.PI);
			cr.Clip ();
			cr.NewPath (); // path not consumed by clip()

			ImageSurface image = new ImageSurface ("data/romedalen.png");
			int w = image.Width;
			int h = image.Height;

			cr.Scale (1.0/w, 1.0/h);

			cr.SetSourceSurface (image, 0, 0);
			cr.Paint ();

			image.Destroy ();
		}
Пример #22
0
		public void xxx_clip_rectangle(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

			cr.NewPath();
			cr.MoveTo(.25, .25);
			cr.LineTo(.25, .75);
			cr.LineTo(.75, .75);
			cr.LineTo(.75, .25);
			cr.LineTo(.25, .25);
			cr.ClosePath();

			cr.Clip();

			cr.MoveTo(0, 0);
			cr.LineTo(1, 1);
			cr.Stroke();
		}
Пример #23
0
		public void clip(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

			cr.Arc(0.5, 0.5, 0.3, 0, 2 * Math.PI);
			cr.Clip();

			cr.NewPath();  // current path is not consumed by cairo_clip()
			cr.Rectangle(0, 0, 1, 1);
			cr.Fill();
			cr.Color = new Color (0, 1, 0);
			cr.MoveTo(0, 0);
			cr.LineTo(1, 1);
			cr.MoveTo(1, 0);
			cr.LineTo(0, 1);
			cr.Stroke();
		}
Пример #24
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.SetSourceColor(Styles.SubTabBarSeparatorColor.ToCairoColor());
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            if (Active || HoverPosition.X >= 0)
            {
                if (Active)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    cr.SetSourceColor(Styles.SubTabBarActiveBackgroundColor.ToCairoColor());
                    cr.Fill();
                }
                else if (HoverPosition.X >= 0)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    cr.SetSourceColor(Styles.SubTabBarHoverBackgroundColor.ToCairoColor());
                    cr.Fill();
                }
            }

            if (Active)
            {
                cr.SetSourceColor(Styles.SubTabBarActiveTextColor.ToCairoColor());
                layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11, Pango.Weight.Bold);
            }
            else
            {
                cr.SetSourceColor(Styles.SubTabBarTextColor.ToCairoColor());
                layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11);
            }

            layout.Width = (int)rectangle.Width;

            cr.MoveTo(rectangle.X + (int)(rectangle.Width / 2), (rectangle.Height - h) / 2 - 1);
            Pango.CairoHelper.ShowLayout(cr, layout);

            if (parent.HasFocus && Focused)
            {
                cr.LineWidth = 1.0;
                cr.SetDash(new double[] { 1, 1 }, 0.5);
                if (Active)
                {
                    cr.SetSourceColor(Styles.SubTabBarActiveTextColor.ToCairoColor());
                }
                else
                {
                    cr.SetSourceColor(Styles.FocusColor.ToCairoColor());
                }
                cr.Rectangle(rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
                cr.Stroke();
            }
        }
Пример #25
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.SetSourceColor(parent.Style.Dark(StateType.Normal).ToCairoColor());
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            if (Active || HoverPosition.X >= 0)
            {
                if (Active)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        gr.AddColorStop(0, Tabstrip.ActiveGradientStart);
                        gr.AddColorStop(1, Tabstrip.ActiveGradientEnd);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                    cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5, rectangle.Width - 1, rectangle.Height - 1);
                    cr.SetSourceRGBA(1, 1, 1, 0.05);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
                else if (HoverPosition.X >= 0)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        var c1 = Tabstrip.ActiveGradientStart;
                        var c2 = Tabstrip.ActiveGradientEnd;
                        c1.A = 0.2;
                        c2.A = 0.2;
                        gr.AddColorStop(0, c1);
                        gr.AddColorStop(1, c2);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                }
            }

            if (Active)
            {
                cr.SetSourceRGB(1, 1, 1);
            }
            else
            {
                cr.SetSourceColor(parent.Style.Text(StateType.Normal).ToCairoColor());
            }

            if (layout.Width != (int)rectangle.Width)
            {
                layout.Width = (int)rectangle.Width;
            }

                        #if MAC
            /* On Cocoa, Pango doesn't render text correctly using layout width/height computation.
             * For instance here we need to balance some kind of internal padding by two pixels which
             * only happens on Mac.
             */
            const int verticalOffset = -2;
                        #else
            const int verticalOffset = 0;
                        #endif

            cr.MoveTo(rectangle.X + (int)(rectangle.Width / 2), (rectangle.Height - h) / 2 + verticalOffset);
            Pango.CairoHelper.ShowLayout(cr, layout);
        }