Пример #1
0
        void DrawButtonTabs(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.Color     = (HslColor)parent.Style.Dark(StateType.Normal);
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            int topPadding = 2;

            if (Active || HoverPosition.X >= 0)
            {
                cr.NewPath();
                cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding);
                cr.ClosePath();
                if (Active)
                {
                    cr.Color = (HslColor)parent.Style.Background(StateType.Prelight);
                }
                else if (HoverPosition.X >= 0)
                {
                    double rx = rectangle.X + HoverPosition.X;
                    double ry = rectangle.Y + HoverPosition.Y;
                    Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5,
                                                                             rx, ry, 2);
                    var color = (HslColor)parent.Style.Dark(StateType.Normal);
                    color.L *= 1.1;
                    gradient.AddColorStop(0, color);
                    color.L *= 1.1;
                    gradient.AddColorStop(1, color);
                    cr.Pattern = gradient;
                }
                if (!Active)
                {
                    cr.Fill();
                }
                else
                {
                    cr.FillPreserve();
                    cr.Color     = (HslColor)parent.Style.Dark(StateType.Normal);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
            }

            cr.Save();
            cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2 + topPadding);
            cr.Color = (HslColor)parent.Style.Text(StateType.Normal);

            cr.ShowLayout(layout);

            cr.Restore();
        }
Пример #2
0
	static void draw (Cairo.Context gr, int width, int height)
	{
		gr.Scale (width, height);
		gr.LineWidth = 0.04;
		LinearGradient pat;		
		
		pat = new LinearGradient (0.0, 0.0,  0.0, 1.0);
		pat.AddColorStop (1, new Color (0, 0, 0, 1) );
		pat.AddColorStop (0, new Color (1, 1, 1, 1) );
		gr.Rectangle ( new PointD (0, 0),
			       1, 1
			       );
		
		gr.Pattern =  pat;
		gr.Fill ();
		pat.Destroy ();

		RadialGradient pat2 = new RadialGradient (0.45, 0.4, 0.1,
				     0.4,  0.4, 0.5);
		
		pat2.AddColorStop (0, new Color (1, 1, 1, 1) );
		pat2.AddColorStop (1, new Color (0, 0, 0, 1) );
		gr.Pattern =  pat2;
		gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI);
		gr.Fill ();
		pat2.Destroy ();
	}
		public override void DrawPie (double fraction)
		{
			// Calculate the pie path
			fraction = Theme.Clamp (0.0, 1.0, fraction);
			double a1 = 3.0 * Math.PI / 2.0;
			double a2 = a1 + 2.0 * Math.PI * fraction;
			
			if (fraction == 0.0) {
				return;
			}
			
			Context.Cairo.MoveTo (Context.X, Context.Y);
			Context.Cairo.Arc (Context.X, Context.Y, Context.Radius, a1, a2);
			Context.Cairo.LineTo (Context.X, Context.Y);
			
			// Fill the pie
			Color color_a = Colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected);
			Color color_b = CairoExtensions.ColorShade (color_a, 1.4);
			
			RadialGradient fill = new RadialGradient (Context.X, Context.Y, 0, Context.X, Context.Y, 2.0 * Context.Radius);
			fill.AddColorStop (0, color_a);
			fill.AddColorStop (1, color_b);
			Context.Cairo.Pattern = fill;
			
			Context.Cairo.FillPreserve ();
			fill.Destroy ();
			
			// Stroke the pie
			Context.Cairo.Color = CairoExtensions.ColorShade (color_a, 0.8);
			Context.Cairo.LineWidth = Context.LineWidth;
			Context.Cairo.Stroke ();
		}
Пример #4
0
		protected override void PaintIconSurface (DockySurface surface)
		{
			surface.Context.LineWidth = 1;
			surface.Context.MoveTo ((surface.Width / 2) - 0.5, 0);
			surface.Context.LineTo ((surface.Width / 2) - 0.5, surface.Height);
			
			RadialGradient rg = new RadialGradient (surface.Width / 2, surface.Height / 2, 0, surface.Width / 2, surface.Height / 2, surface.Height / 2);
			rg.AddColorStop (0, new Cairo.Color (1, 1, 1, .5));
			rg.AddColorStop (1, new Cairo.Color (1, 1, 1, 0));
		
			surface.Context.Pattern = rg;
			surface.Context.Stroke ();
			rg.Destroy ();
			
			surface.Context.MoveTo ((surface.Width / 2) + 0.5, 0);
			surface.Context.LineTo ((surface.Width / 2) + 0.5, surface.Height);
			
			rg = new RadialGradient (surface.Width / 2, surface.Height / 2, 0, surface.Width / 2, surface.Height / 2, surface.Height / 2);
			rg.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.5));
			rg.AddColorStop (1, new Cairo.Color (0, 0, 0, 0));
			
			surface.Context.Pattern = rg;
			surface.Context.Stroke ();
			rg.Destroy ();
		}
Пример #5
0
        void OnDrawingAreaExposed(object o, ExposeEventArgs args)
        {
            if (prevSize != Allocation.Size)
            {
                if (model != null)
                    treeMapModel = new TreeMapModel(model, Allocation.Width, Allocation.Height);
            }

            DrawingArea area = (DrawingArea)o;
            Cairo.Context g = Gdk.CairoHelper.Create(area.GdkWindow);

            if (treeMapModel != null)
            {
                foreach (var item in treeMapModel.Items)
                {
                    double width = item.Rectangle.Width;
                    double height = item.Rectangle.Height;

                    double x1 = item.Rectangle.X;
                    double x2 = item.Rectangle.X + item.Rectangle.Width;
                    double y1 = item.Rectangle.Y;
                    double y2 = item.Rectangle.Y + item.Rectangle.Height;

                    PointD p1, p2, p3, p4;
                    p1 = new PointD(x1, y1);
                    p2 = new PointD(x2, y1);
                    p3 = new PointD(x2, y2);
                    p4 = new PointD(x1, y2);

                    g.MoveTo(p1);
                    g.LineTo(p2);
                    g.LineTo(p3);
                    g.LineTo(p4);
                    g.LineTo(p1);
                    g.ClosePath();

                    g.Save();
                    //using (Gradient pat = new LinearGradient(x1, y1, x2, y2))
                    using (Gradient pat = new RadialGradient(x1 + (x2 - x1) / 4.0, y1 + (y2 - y1) / 4.0, 3, x1 + (x2 - x1) / 4.0, y1 + (y2 - y1) / 4.0, Math.Sqrt(width*width + height*height)))
                    {
                        pat.AddColorStop(0, new Cairo.Color(1, 1, 1, 1));
                        pat.AddColorStop(1, new Cairo.Color(0, 0, 1, 1));
                        g.Pattern = pat;

                        // Fill the path with pattern
                        g.FillPreserve();
                    }

                    // We "undo" the pattern setting here
                    g.Restore();

                    g.Color = new Color(0, 0, 0, 0);
                    g.Stroke();
                }
            }

            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
Пример #6
0
        void DrawCurveTabs(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                return;
            }

            cr.MoveTo(rectangle.X, rectangle.Y);

            double bottom = rectangle.Y + rectangle.Height - 1;

            cr.CurveTo(
                rectangle.X + SpacerWidth / 2, rectangle.Y,
                rectangle.X + SpacerWidth / 2, bottom,
                rectangle.X + SpacerWidth, bottom);

            cr.LineTo(rectangle.X + rectangle.Width - SpacerWidth, bottom);

            cr.CurveTo(
                rectangle.X + rectangle.Width - SpacerWidth / 2, bottom,
                rectangle.X + rectangle.Width - SpacerWidth / 2, rectangle.Y,
                rectangle.X + rectangle.Width, rectangle.Y);

            cr.Color = (HslColor)parent.Style.Dark(StateType.Normal);
            cr.StrokePreserve();
            cr.ClosePath();
            if (Active)
            {
                cr.Color = (HslColor)parent.Style.Background(StateType.Prelight);
            }
            else if (HoverPosition.X >= 0)
            {
                double rx = rectangle.X + HoverPosition.X;
                double ry = rectangle.Y + HoverPosition.Y;
                Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5,
                                                                         rx, ry, 2);
                var color = (HslColor)parent.Style.Mid(StateType.Normal);
                color.L *= 1.05;
                gradient.AddColorStop(0, color);
                color.L *= 1.07;
                gradient.AddColorStop(1, color);
                cr.Pattern = gradient;
            }
            else
            {
                cr.Color = (HslColor)parent.Style.Mid(StateType.Normal);
            }
            cr.Fill();

            cr.Save();
            cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2);
            cr.Color = (HslColor)parent.Style.Text(StateType.Normal);

            cr.ShowLayout(layout);

            cr.Restore();
        }
		protected override void DrawBackground (Context context, Gdk.Rectangle region)
		{
			LayoutRoundedRectangle (context, region);
			context.Clip ();

			context.SetSourceColor (CairoExtensions.ParseColor ("D3E6FF"));
			context.Paint ();

			context.Save ();
			context.Translate (region.X + region.Width / 2.0, region.Y + region.Height);

			using (var rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) {
				var color = CairoExtensions.ParseColor ("E5F0FF");
				rg.AddColorStop (0, color);
				color.A = 0;
				rg.AddColorStop (1, color);

				context.Scale (region.Width / (double)region.Height, 1.0);
				context.SetSource (rg);
				context.Paint ();
			}

			context.Restore ();

			LayoutRoundedRectangle (context, region, -3, -3, 2);
			context.SetSourceRGBA (1, 1, 1, 0.4);
			context.LineWidth = 1;
			context.StrokePreserve ();

			context.Clip ();

			int boxSize = 11;
			int x = region.Left + (region.Width % boxSize) / 2;
			for (; x < region.Right; x += boxSize) {
				context.MoveTo (x + 0.5, region.Top);
				context.LineTo (x + 0.5, region.Bottom);
			}

			int y = region.Top + (region.Height % boxSize) / 2;
			y += boxSize / 2;
			for (; y < region.Bottom; y += boxSize) {
				context.MoveTo (region.Left, y + 0.5);
				context.LineTo (region.Right, y + 0.5);
			}

			context.SetSourceRGBA (1, 1, 1, 0.2);
			context.Stroke ();

			context.ResetClip ();
		}
Пример #8
0
        public static void DrawRadialGradient(this Context g, Surface oldsurface, GradientColorMode mode, Color c1, Color c2, PointD p1, PointD p2, double r1, double r2)
        {
            g.Save();

            Gradient gradient = new Cairo.RadialGradient(p1.X, p1.Y, r1, p2.X, p2.Y, r2);

            if (mode == GradientColorMode.Color)
            {
                gradient.AddColorStop(0, c1);
                gradient.AddColorStop(1, c2);
                g.Source = gradient;
                g.Paint();
            }
            else if (mode == GradientColorMode.Transparency)
            {
                gradient.AddColorStop(0, new Color(0, 0, 0, 1));
                gradient.AddColorStop(1, new Color(0, 0, 0, 0));
                g.Source = new SurfacePattern(oldsurface);
                g.Mask(gradient);
            }

            g.Restore();
        }
Пример #9
0
        private void gradientToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lastSelected = "gradient";
            OnPaintAction = cr =>
            {
                Gradient pat = new LinearGradient(0.0, 0.0, 0.0, 256.0);
                pat.AddColorStopRgba(1, 0, 0, 0, 1);
                pat.AddColorStopRgba(0, 1, 1, 1, 1);
                cr.Rectangle(0, 0, 256, 256);
                cr.SetSource(pat);
                cr.Fill();
                pat.Dispose();

                pat = new RadialGradient(115.2, 102.4, 25.6,
                                         102.4, 102.4, 128.0);
                pat.AddColorStopRgba(0, 1, 1, 1, 1);
                pat.AddColorStopRgba(1, 0, 0, 0, 1);
                cr.SetSource(pat);
                cr.Arc(128.0, 128.0, 76.8, 0, 2 * Math.PI);
                cr.Fill();
                pat.Dispose();
            };

            Invalidate();
        }
Пример #10
0
		public void gradient(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

			LinearGradient lg = new LinearGradient(0.0, 0.0, 0.0, 1.0);
			lg.AddColorStop(1, new Color(0, 0, 0, 1));
			lg.AddColorStop(0, new Color(1, 1, 1, 1));
			cr.Rectangle(0,0,1,1);
			cr.Source = lg;
			cr.Fill();

			RadialGradient rg = new RadialGradient(0.45, 0.4, 0.1, 0.4, 0.4, 0.5);
			rg.AddColorStop(0, new Color (1, 1, 1, 1));
			rg.AddColorStop(1, new Color (0, 0, 0, 1));
			cr.Source = rg;
			cr.Arc(0.5, 0.5, 0.3, 0, 2 * Math.PI);
			cr.Fill();
		}
Пример #11
0
        /// <summary>Draws an application button.</summary>
        public void DrawApplicationButton(Context cr, Gdk.Rectangle bodyAllocation, ButtonState state, double lineWidth, BaseButton widget)
        {
            const double dropShadowOffset = 1;
            double radius = (bodyAllocation.Height - dropShadowOffset) / 2;

            double x = bodyAllocation.X + radius + dropShadowOffset;
            double y = bodyAllocation.Y + radius + dropShadowOffset;
            cr.Arc (x, y, radius, 0, 2 * Math.PI);
            cr.Color = new Color (0, 0, 0, 0.5);
            cr.Fill ();

            cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, 2 * Math.PI);
            switch(state)
            {
            case ButtonState.Hover:
                cr.Color = new Color (0.9, 0.815, 0.533);
                break;
            case ButtonState.Pressed:
                cr.Color = new Color (0.886, 0.639, 0.356);
                break;
            default:
                cr.Color = new Color (0.8, 0.8, 0.8);
                break;
            }
            cr.Fill ();

            cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, 2 * Math.PI);
            LinearGradient linGrad = new LinearGradient (0, bodyAllocation.Y, 0, bodyAllocation.Y + bodyAllocation.Height);
            linGrad.AddColorStop (0.0, new Color (1, 1, 1, 0.9));
            linGrad.AddColorStop (0.5, new Color (1, 1, 1, 0.0));
            linGrad.AddColorStop (1.0, new Color (1, 1, 1, 1.0));
            cr.Pattern = linGrad;
            cr.Fill ();
            linGrad.Destroy ();

            cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, 2 * Math.PI);
            linGrad = new LinearGradient (0, bodyAllocation.Y, 0, bodyAllocation.Y + bodyAllocation.Height);
            linGrad.AddColorStop (0.0, new Color (0, 0, 0, 0.0));
            linGrad.AddColorStop (0.4, new Color (0, 0, 0, 0.0));
            linGrad.AddColorStop (0.5, new Color (0, 0, 0, 0.1));
            linGrad.AddColorStop (0.75, new Color (0, 0, 0, 0.0));
            linGrad.AddColorStop (1.0, new Color (0, 0, 0, 0.0));
            cr.Pattern = linGrad;
            cr.Fill ();
            linGrad.Destroy ();

            cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, Math.PI);
            linGrad = new LinearGradient (0, bodyAllocation.Y + radius, 0, bodyAllocation.Y + bodyAllocation.Height);
            linGrad.AddColorStop (0.0, new Color (0, 0, 0, 0.0));
            linGrad.AddColorStop (1.0, new Color (0, 0, 0, 0.5));
            cr.Pattern = linGrad;
            cr.LineWidth = 1.0;
            cr.Stroke ();
            linGrad.Destroy ();

            cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, Math.PI, 0);
            linGrad = new LinearGradient (0, bodyAllocation.Y, 0, bodyAllocation.Y + radius);
            linGrad.AddColorStop (0.0, new Color (1, 1, 1, 0.5));
            linGrad.AddColorStop (1.0, new Color (1, 1, 1, 0.0));
            cr.LineWidth = 1.0;
            cr.Stroke ();
            linGrad.Destroy ();

            cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, 2 * Math.PI);
            RadialGradient radGrad = new RadialGradient (bodyAllocation.X + radius, bodyAllocation.Y + 1.5 * radius, 0, bodyAllocation.X + radius, bodyAllocation.Y + 1.5 * radius, 0.5 * radius);
            radGrad.AddColorStop (0, new Color (1, 1, 1, 0.4));
            radGrad.AddColorStop (1, new Color (1, 1, 1, 0.0));
            cr.Pattern = radGrad;
            cr.Fill ();
            radGrad.Destroy ();
        }
Пример #12
0
        public static void DrawRadialGradient(this Context g, Surface oldsurface, GradientColorMode mode, Cairo.Color c1, Cairo.Color c2, PointD p1, PointD p2, double r1, double r2)
        {
            g.Save ();

            Gradient gradient = new Cairo.RadialGradient (p1.X, p1.Y, r1, p2.X, p2.Y, r2);

            if (mode == GradientColorMode.Color) {
                gradient.AddColorStop (0, c1);
                gradient.AddColorStop (1, c2);
                g.Source = gradient;
                g.Paint ();
            }
            else if (mode == GradientColorMode.Transparency) {
                gradient.AddColorStop (0, new Cairo.Color (0, 0, 0, 1));
                gradient.AddColorStop (1, new Cairo.Color (0, 0, 0, 0));
                g.Source = new SurfacePattern (oldsurface);
                g.Mask (gradient);
            }

            g.Restore ();
        }
Пример #13
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 ();
		}
Пример #14
0
		DockySurface CreateIndicatorBuffer (int size, Cairo.Color color)
		{
			DockySurface surface = new DockySurface (size, size, background_buffer);
			surface.Clear ();
			
			Cairo.Context cr = surface.Context;
			
			double x = size / 2;
			double y = x;
				
			cr.MoveTo (x, y);
			cr.Arc (x, y, size / 2, 0, Math.PI * 2);
				
			RadialGradient rg = new RadialGradient (x, y, 0, x, y, size / 2);
			rg.AddColorStop (0, new Cairo.Color (1, 1, 1, 1));
			rg.AddColorStop (.10, color.SetAlpha (1.0));
			rg.AddColorStop (.20, color.SetAlpha (.60));
			rg.AddColorStop (.25, color.SetAlpha (.25));
			rg.AddColorStop (.50, color.SetAlpha (.15));
			rg.AddColorStop (1.0, color.SetAlpha (0.0));
			
			cr.Pattern = rg;
			cr.Fill ();
			rg.Destroy ();
			
			return surface;
		}
Пример #15
0
        public override void DrawPie(double fraction)
        {
            // Calculate the pie path
            fraction = Theme.Clamp (0.0, 1.0, fraction);
            double a1 = 3.0 * Math.PI / 2.0;
            double a2 = a1 + 2.0 * Math.PI * fraction;

            if (fraction == 0.0) {
                return;
            }

            Context.Cairo.MoveTo (Context.X, Context.Y);
            Context.Cairo.Arc (Context.X, Context.Y, Context.Radius, a1, a2);
            Context.Cairo.LineTo (Context.X, Context.Y);

            // Fill the pie
            Color color_a = CairoExtensions.GdkRGBAToCairoColor (
                Widget.StyleContext.GetBackgroundColor (StateFlags.Selected));
            Color color_b = CairoExtensions.ColorShade (color_a, 1.4);

            using (var fill = new RadialGradient (Context.X, Context.Y, 0, Context.X, Context.Y,
                                                  2.0 * Context.Radius)) {
                fill.AddColorStop (0, color_a);
                fill.AddColorStop (1, color_b);
                Context.Cairo.SetSource (fill);

                Context.Cairo.FillPreserve ();
            }

            // Stroke the pie
            Context.Cairo.SetSourceColor (CairoExtensions.ColorShade (color_a, 0.8));
            Context.Cairo.LineWidth = Context.LineWidth;
            Context.Cairo.Stroke ();
        }
        public override void Render (CellContext context)
        {
            if (inner_allocation.IsEmpty) {
                return;
            }

            // Need to call this again here to make sure we have the latest artwork
            var album = BoundObject as AlbumInfo;
            if (album != null) {
                image_surface = artwork_manager != null
                    ? artwork_manager.LookupScaleSurface (album.ArtworkId, (int)ImageSize, true)
                    : null;
            }

            context.Context.Translate (inner_allocation.X, inner_allocation.Y);

            RenderImageSurface (context, image_allocation, image_surface);

            // Render the overlay
            if (IsGridLayout && prelight_opacity > 0) {
                var cr = context.Context;
                var x = image_allocation.Width / 2.0;
                var y = image_allocation.Height / 2.0;
                var grad = new RadialGradient (x, y, 0, x, y, x);
                grad.AddColorStop (0, new Color (0, 0, 0, 0.1 * prelight_opacity));
                grad.AddColorStop (1, new Color (0, 0, 0, 0.35 * prelight_opacity));
                cr.Pattern = grad;
                CairoExtensions.RoundedRectangle (cr, image_allocation.X, image_allocation.Y,
                    image_allocation.Width, image_allocation.Height, context.Theme.Context.Radius);
                cr.Fill ();
                grad.Destroy ();

                /*cr.Save ();
                cr.LineWidth = 2;
                cr.Antialias = Cairo.Antialias.Default;

                // math prep for rendering multiple controls...
                double max_controls = 3;
                double spacing = 4;
                double radius = (width - ((max_controls + 1) * spacing)) / max_controls / 2;

                // render first control
                cr.Arc (width / 2, height - radius - 2 * spacing, radius, 0, 2 * Math.PI);

                cr.Color = new Color (0, 0, 0, 0.4);
                cr.FillPreserve ();
                cr.Color = new Color (1, 1, 1, 0.8);
                cr.Stroke ();

                cr.Restore ();*/
            }

            if (lines == null || lines.Length < 2) {
                return;
            }

            var text_color = context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, context.State);

            var layout = context.Layout;
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.Width = (int)(first_line_allocation.Width * Pango.Scale.PangoScale);

            int normal_size = layout.FontDescription.Size;
            int small_size = (int)(normal_size * Pango.Scale.Small);

            if (!String.IsNullOrEmpty (lines[0])) {
                layout.FontDescription.Size = small_size;
                layout.SetText (lines[0]);

                context.Context.Color = text_color;
                context.Context.MoveTo (first_line_allocation.X, first_line_allocation.Y);
                PangoCairoHelper.ShowLayout (context.Context, layout);
            }

            if (!String.IsNullOrEmpty (lines[1])) {
                layout.FontDescription.Weight = Pango.Weight.Normal;
                layout.FontDescription.Size = small_size;
                layout.SetText (lines[1]);

                text_color.A = 0.60;
                context.Context.Color = text_color;
                context.Context.MoveTo (second_line_allocation.X, second_line_allocation.Y);
                PangoCairoHelper.ShowLayout (context.Context, layout);
            }

            layout.FontDescription.Size = normal_size;
        }
Пример #17
0
		DockySurface CreateUrgentGlowBuffer ()
		{
			// FIXME: create gconf value
			Gdk.Color gdkColor = Style.Backgrounds [(int) StateType.Selected].SetMinimumValue (90);
			Cairo.Color color = new Cairo.Color ((double) gdkColor.Red / ushort.MaxValue,
											(double) gdkColor.Green / ushort.MaxValue,
											(double) gdkColor.Blue / ushort.MaxValue,
											1.0);
			color = color.AddHue (DockServices.Theme.UrgentHueShift).SetSaturation (1);
			
			int size = (int) 2.5 * IconSize;
			
			DockySurface surface = new DockySurface (size, size, background_buffer);
			surface.Clear ();
			
			Cairo.Context cr = surface.Context;
			
			double x = size / 2;
			double y = x;
				
			cr.MoveTo (x, y);
			cr.Arc (x, y, size / 2, 0, Math.PI * 2);
				
			RadialGradient rg = new RadialGradient (x, y, 0, x, y, size / 2);
			rg.AddColorStop (0, new Cairo.Color (1, 1, 1, 1));
			rg.AddColorStop (.33, color.SetAlpha (.66));
			rg.AddColorStop (.66, color.SetAlpha (.33));
			rg.AddColorStop (1.0, color.SetAlpha (0.0));
			
			cr.Pattern = rg;
			cr.Fill ();
			rg.Destroy ();
			
			return surface;
		}
Пример #18
0
 bool DrawEffects(Context cr, uint w, uint h)
 {
     if (!SillyFlare) return false;
     if (FlareGradient == null) {
       FGRadius = Helpers.ImageWidth(FlareGradientImage);
       FlareGradient = Helpers.RadialGradientFromImage(FlareGradientImage);
       BlackGradient = new RadialGradient(0,0,0, 0,0,FGRadius);
       BlackGradient.AddColorStop(0, new Color(0,0,0,1));
       BlackGradient.AddColorStop(1, new Color(0,0,0,0));
       FlareSpike = new ImageSurface(FlareSpikeImage);
       RainbowSprite = new ImageSurface(RainbowSpriteImage);
     }
     cr.Save ();
     //       double t = DateTime.Now.ToFileTime() / 1e7;
       double dx = flareTargetX - flareX;
       double dy = flareTargetY - flareY;
       flareX += dx / 20;
       flareY += dy / 20;
       double s = Math.Min(1, Math.Max(0.02, 0.35 / (1 + 0.002*(dx*dx + dy*dy))));
       if (s < 0.03)
     s *= 1 + rng.NextDouble();
       cr.Translate(flareX, flareY);
       cr.Save ();
     cr.Scale (s, s);
     /*        cr.Arc(0, 0, FGRadius, 0, Math.PI * 2);
     cr.Source = BlackGradient;
     cr.Operator = Operator.Over;*/
     cr.FillPreserve ();
     cr.Source = FlareGradient;
     cr.Operator = Operator.Add;
     cr.Fill ();
       cr.Restore ();
       cr.Save ();
     cr.Scale (s, s);
     cr.Operator = Operator.Add;
     using (SurfacePattern p = new SurfacePattern(RainbowSprite)) {
       cr.Save ();
       cr.Translate (10, -RainbowSprite.Height/2);
       cr.Rectangle (0, 0, RainbowSprite.Width, RainbowSprite.Height);
       cr.Source = p;
       cr.Fill ();
       cr.Restore ();
       cr.Save ();
       cr.Scale(-1, 1);
       cr.Translate (10, -RainbowSprite.Height/2);
       cr.Rectangle (0, 0, RainbowSprite.Width, RainbowSprite.Height);
       cr.Source = p;
       cr.Fill ();
       cr.Restore ();
     }
       cr.Restore ();
       cr.Save ();
     cr.Scale (Math.Sqrt(s), Math.Sqrt(s));
     using (SurfacePattern p = new SurfacePattern(FlareSpike)) {
       cr.Translate (-FlareSpike.Width/2.0, -FlareSpike.Height/2.0);
       cr.Rectangle (0, 0, FlareSpike.Width, FlareSpike.Height);
       cr.Operator = Operator.Add;
       cr.Source = p;
       cr.Fill ();
     }
       cr.Restore ();
     cr.Restore ();
     if (dx*dx < 1 && dy*dy < 1) return false;
     return true;
 }
Пример #19
0
        private Pattern CreateMask()
        {
            double max = Math.Max (blur.Bounds.Width, blur.Bounds.Height) * .25;
            double scale = blur.Bounds.Width / (double) info.Bounds.Width;

            RadialGradient circle;

            // FIXME ugh cairo 1.0.2 is so broken why are we still shipping it.
            if (CairoAPI.cairo_version () > (1 * 10000 + 2 * 100 + 0)) {
                circle = new RadialGradient (center.X * scale, center.Y * scale, radius * max * .7,
                                 center.X * scale, center.Y * scale, radius * max + max * .2);

                circle.AddColorStop (0, new Cairo.Color (0.0, 0.0, 0.0, 0.0));
                circle.AddColorStop (1.0, new Cairo.Color (1.0, 1.0, 1.0, 1.0));
                } else {
                circle = new RadialGradient (center.X * scale, center.Y * scale, radius * max + max * .2,
                                 center.X * scale, center.Y * scale, radius * max * .7);

                circle.AddColorStop (1.0, new Cairo.Color (0.0, 0.0, 0.0, 0.0));
                circle.AddColorStop (0, new Cairo.Color (1.0, 1.0, 1.0, 1.0));
            }
            return circle;
        }
Пример #20
0
        protected override void OnSizeAllocated(Gdk.Rectangle rect)
        {
            x = rect.Width / 2.0;
            y = rect.Height / 2.0;
            radius = Math.Min(rect.Width / 2, rect.Height / 2) - 5;
            base_line_width = Math.Sqrt(radius) * 0.2;

            bg_gradient = new RadialGradient(x, y, 0, x, y, radius);
            bg_gradient.AddColorStop(0, disc_color_a);
            bg_gradient.AddColorStop(1, disc_color_b);

            fg_gradient = new RadialGradient(x, y, 0, x, y, radius * 2);
            fg_gradient.AddColorStop(0, fill_color_a);
            fg_gradient.AddColorStop(1, fill_color_b);

            fg_gradient_full = new RadialGradient(x, y, 0, x, y, radius);
            fg_gradient_full.AddColorStop(0, disc_color_b);
            fg_gradient_full.AddColorStop(1, red_color);

            bound_gradient = new RadialGradient(x, y, 0, x, y, radius * 2);
            bound_gradient.AddColorStop(0, bound_color_a);
            bound_gradient.AddColorStop(1, bound_color_b);

            base.OnSizeAllocated(rect);
        }
Пример #21
0
        Pattern CreateMask()
        {
            double max = Math.Max (blur.Bounds.Width, blur.Bounds.Height) * .25;
            double scale = blur.Bounds.Width / (double)info.Bounds.Width;

            RadialGradient circle;

            circle = new RadialGradient (Center.X * scale, Center.Y * scale, radius * max * .7,
                Center.X * scale, Center.Y * scale, radius * max + max * .2);

            circle.AddColorStop (0, new Cairo.Color (0.0, 0.0, 0.0, 0.0));
            circle.AddColorStop (1.0, new Cairo.Color (1.0, 1.0, 1.0, 1.0));
            return circle;
        }
        private void Render(Clutter.CairoTexture texture, int with_state, bool outwards)
        {
            texture.Clear ();
            Cairo.Context context = texture.Create ();

            double alpha_f = with_state == 0 ? 0.5 : (with_state == 1 ? 0.8 : 1);

            double lwidth = 1;
            double hlwidth = lwidth*0.5;
            context.LineWidth = lwidth;

            if (outwards) {
                context.MoveTo (texture.Width*0.5-texture.Height*0.45, texture.Height*0.9);
                context.CurveTo (texture.Width*0.3, texture.Height, texture.Width*0.6, texture.Height, texture.Width*0.5+texture.Height*0.45, texture.Height*0.9);
                context.ArcNegative (texture.Width*0.5, texture.Height*0.9, texture.Height*0.45, 0, Math.PI);
                context.ClosePath ();
                Gradient g1 = new LinearGradient (0, texture.Height/2, 0, texture.Height);
                g1.AddColorStop (0, new Cairo.Color (0.6, 0.6, 0.6, 1.0*alpha_f));
                g1.AddColorStop (1.0, new Cairo.Color (1.0, 1.0, 1.0, 1.0*alpha_f));
                context.Pattern = g1;
                context.FillPreserve ();
                context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0*alpha_f);
                context.Stroke ();
                ((IDisposable) g1).Dispose ();

                context.Arc (Width*0.5, Height*0.33+lwidth, Height*0.33, 0, Math.PI*2);
                context.ClosePath ();
                context.Operator = Operator.Source;
                Gradient g2 = new RadialGradient (texture.Width*0.5, texture.Height*0.25, 0, texture.Width*0.5, texture.Height*0.25, texture.Width*0.5);
                g2.AddColorStop (0, new Cairo.Color (1.0, 1.0, 1.0, 1.0*alpha_f));
                g2.AddColorStop (1.0, new Cairo.Color (0.6, 0.6, 0.6, 1.0*alpha_f));
                context.Pattern = g2;
                //context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0*alpha_f);
                context.FillPreserve ();
                Gradient g3 = new LinearGradient (0, 0, 0, texture.Height*0.5);
                g3.AddColorStop (0, new Cairo.Color (1.0, 1.0, 1.0, 1.0*alpha_f));
                g3.AddColorStop (1.0, new Cairo.Color (0, 0, 0, 1.0*alpha_f));
                context.Pattern = g3;
                //context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0*alpha_f);
                context.Stroke ();
                ((IDisposable) g2).Dispose ();
                ((IDisposable) g3).Dispose ();

            } else {
                Cairo.PointD c = new Cairo.PointD (texture.Width*0.5, texture.Height*0.5);
                double max_r = Math.Min (c.X, c.Y) - hlwidth;

                context.Arc (c.X, c.Y, max_r, 0, Math.PI*2);
                context.ArcNegative (c.X, c.Y, max_r*0.25, Math.PI*2, 0);
                context.ClosePath ();
                context.SetSourceRGBA (0.5, 0.5, 0.5, 1.0*alpha_f);
                context.StrokePreserve ();
                Gradient g1 = new LinearGradient (0, texture.Height, texture.Width, 0);
                g1.AddColorStop(0, new Cairo.Color (1.0, 1.0, 1.0, 1.0*alpha_f));
                g1.AddColorStop(0.5, new Cairo.Color (0.7, 0.7, 0.7, 1.0*alpha_f));
                g1.AddColorStop(1, new Cairo.Color (0.9, 0.9, 0.9, 1.0*alpha_f));
                context.Pattern = g1;
                context.Fill ();
                ((IDisposable) g1).Dispose ();

                context.ArcNegative (c.X, c.Y, max_r*0.25+lwidth, Math.PI*1.75, Math.PI*0.75);
                context.Arc (c.X, c.Y, max_r, Math.PI*0.75, Math.PI*1.75);
                context.ClosePath ();
                Gradient g2 = new LinearGradient (c.X, c.Y, c.X*0.35, c.Y*0.35);
                g2.AddColorStop(0, new Cairo.Color (1.0, 1.0, 1.0, 1.0*alpha_f));
                g2.AddColorStop(1, new Cairo.Color (1.0, 1.0, 1.0, 0.0));
                context.Pattern = g2;
                context.Fill ();
                ((IDisposable) g2).Dispose ();

                context.ArcNegative (c.X, c.Y, max_r*0.25+lwidth, Math.PI*2, 0);
                context.Arc (c.X, c.Y, max_r*0.45, 0, Math.PI*2);
                context.SetSourceRGBA (1.0, 1.0, 1.0, 0.8*alpha_f);
                context.Fill ();

                context.Arc (c.X, c.Y, max_r-lwidth, 0, Math.PI*2);
                Gradient g3 = new LinearGradient (0, texture.Height, texture.Width, 0);
                g3.AddColorStop(0, new Cairo.Color (1.0, 1.0, 1.0, 0.0));
                g3.AddColorStop(1, new Cairo.Color (0.9, 0.9, 0.9, 1.0*alpha_f));
                context.Pattern = g3;
                context.Stroke ();
                ((IDisposable) g3).Dispose ();
            }

            ((IDisposable) context.Target).Dispose ();
            ((IDisposable) context).Dispose ();
        }
Пример #23
0
            public static void DrawShadow(Cairo.Context cr, double x, double y, double width,
                                          double height, double radius, ShadowParameters shadowParams)
            {
                using (Surface sr = cr.CreateSimilarToTarget((int)width + (int)(2 * shadowParams.shadowRadius) + (int)x,
                                                             (int)height + (int)(2 * shadowParams.shadowRadius) + (int)y))
                {
                    using (Context cairo = new Context(sr))
                    {
                        radius++;
                        y++;
                        height--;
                        Cairo.Gradient shadow;
                        /* Top Left */
                        using (shadow = new Cairo.RadialGradient(x + radius, y + radius, radius,
                                                                 x + radius, y + radius, radius + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(x - shadowParams.shadowRadius, y - shadowParams.shadowRadius,
                                            radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }
                        /* Top */
                        using (shadow = new Cairo.LinearGradient(0.0, y, 0.0, y - shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(x + radius, y - shadowParams.shadowRadius,
                                            width - radius * 2, shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }
                        /* Top Right */
                        using (shadow = new Cairo.RadialGradient(width + x - radius, y + radius, radius,
                                                                 width + x - radius, y + radius, radius + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(width + x - radius, y - shadowParams.shadowRadius,
                                            radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Right */
                        using (shadow = new Cairo.LinearGradient(width + x, 0.0,
                                                                 width + x + shadowParams.shadowRadius, 0.0))
                        {
                            cairo.Rectangle(width + x, y + radius, shadowParams.shadowRadius, height - radius * 2);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Bottom Right */
                        using (shadow = new Cairo.RadialGradient(width + x - radius, height + y - radius, radius,
                                                                 width + x - radius, height + y - radius, radius + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(width + x - radius, height + y - radius,
                                            radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Bottom */
                        using (shadow = new Cairo.LinearGradient(0.0, height + y,
                                                                 0.0, height + y + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(x + radius, height + y,
                                            width - radius * 2, shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Bottom Left */
                        using (shadow = new Cairo.RadialGradient(x + radius, height + y - radius, radius,
                                                                 x + radius, height + y - radius, radius + shadowParams.shadowRadius))
                        {
                            cairo.Rectangle(x - shadowParams.shadowRadius, height + y - radius,
                                            radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        /* Left */
                        using (shadow = new Cairo.LinearGradient(x, 0.0,
                                                                 x - shadowParams.shadowRadius, 0.0))
                        {
                            cairo.Rectangle(x - shadowParams.shadowRadius, y + radius,
                                            radius + shadowParams.shadowRadius, height - radius * 2);
                            FillShadowPattern(cairo, shadow, shadowParams);
                        }

                        y--;
                        height++;
                        /* Clear inner rectangle */
                        GetFrame(cairo, x, y, width, height, radius);
                        cairo.Operator = Cairo.Operator.Clear;
                        cairo.Fill();

                        cr.SetSource(sr);
                        cr.Paint();
                    }
                }
            }
Пример #24
0
 /** BLOCKING */
 public static RadialGradient RadialGradientFromImage(string path)
 {
     using (ImageSurface s = new ImageSurface (path)) {
       RadialGradient g = new RadialGradient(0,0,0, 0,0,s.Width);
       for (int i=0; i<s.Width; i++)
     g.AddColorStop((double)i / ((double)s.Width-1), Sample(s, i, 0));
       return g;
     }
 }
Пример #25
0
		protected override bool OnExposeEvent (EventExpose evnt)
		{
			if (!IsRealized)
				return false;
			
			using (Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window)) {
				cr.LineWidth = 1;
				
				int x = Allocation.X;
				int width = Allocation.Width;
				int right = x + width;
				int xMiddle = x + width / 2;
				double yMiddle = Allocation.Y + Allocation.Height / 2.0;
				
				if (!string.IsNullOrEmpty (title))
					using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {
						layout.SetText (title);
						layout.Width = Pango.Units.FromPixels (Allocation.Width - Allocation.Height);
						layout.FontDescription = Style.FontDescription;
						layout.Ellipsize = Pango.EllipsizeMode.End;
						layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (8);
						layout.FontDescription.Weight = Pango.Weight.Bold;
						
						Pango.Rectangle logical, ink;
						layout.GetPixelExtents (out ink, out logical);
						
						cr.MoveTo (Allocation.X + 2, Allocation.Y + (Allocation.Height - logical.Height) / 2);
						Pango.CairoHelper.LayoutPath (cr, layout);
						cr.Color = TextColor.SetAlpha (.6);
						cr.Fill ();
						
						x += logical.Width + 5;
						
						layout.Context.Dispose ();
					}
				
				if (DrawLine) {
					cr.MoveTo (x, yMiddle);
					cr.LineTo (right, yMiddle);
					
					RadialGradient rg = new RadialGradient (
						xMiddle, 
						yMiddle, 
						0, 
						xMiddle, 
						yMiddle, 
						width / 2);
					rg.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.4));
					rg.AddColorStop (1, new Cairo.Color (0, 0, 0, 0));
					
					cr.Pattern = rg;
					cr.Stroke ();
					rg.Destroy ();
					
					cr.MoveTo (x, yMiddle + 1);
					cr.LineTo (right, yMiddle + 1);
					
					rg = new RadialGradient (
						xMiddle, 
						yMiddle + 1, 
						0, 
						xMiddle, 
						yMiddle + 1, 
						width / 2);
					rg.AddColorStop (0, new Cairo.Color (1, 1, 1, .4));
					rg.AddColorStop (1, new Cairo.Color (1, 1, 1, 0));
					
					cr.Pattern = rg;
					cr.Stroke ();
					rg.Destroy ();
				}
				
				(cr.Target as IDisposable).Dispose ();
			}
			return false;
		}
Пример #26
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 ();
            }
        }
Пример #27
0
		void PaintBadgeSurface (DockySurface surface)
		{
			if (string.IsNullOrEmpty (BadgeText))
				return;
			
			int padding = 4;
			int lineWidth = 2;
			double size = (IsSmall ? 0.9 : 0.65) * Math.Min (surface.Width, surface.Height);
			double x = surface.Width - size / 2;
			double y = size / 2;
			
			if (!IsSmall) {
				// draw outline shadow
				surface.Context.LineWidth = lineWidth;
				surface.Context.Color = new Cairo.Color (0, 0, 0, 0.5);
				surface.Context.Arc (x, y + 1, size / 2 - lineWidth, 0, Math.PI * 2);
				surface.Context.Stroke ();
				
				// draw filled gradient
				RadialGradient rg = new RadialGradient (x, lineWidth, 0, x, lineWidth, size);
				rg.AddColorStop (0, badgeColors [0]);
				rg.AddColorStop (1.0, badgeColors [1]);
				
				surface.Context.Pattern = rg;
				surface.Context.Arc (x, y, size / 2 - lineWidth, 0, Math.PI * 2);
				surface.Context.Fill ();
				rg.Destroy ();
				
				// draw outline
				surface.Context.Color = new Cairo.Color (1, 1, 1, 1);
				surface.Context.Arc (x, y, size / 2 - lineWidth, 0, Math.PI * 2);
				surface.Context.Stroke ();
				
				surface.Context.LineWidth = lineWidth / 2;
				surface.Context.Color = badgeColors [1];
				surface.Context.Arc (x, y, size / 2 - 2 * lineWidth, 0, Math.PI * 2);
				surface.Context.Stroke ();
				
				surface.Context.Color = new Cairo.Color (0, 0, 0, 0.2);
			} else {
				lineWidth = 0;
				padding = 2;
			}
			
			using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ())
			{
				layout.Width = Pango.Units.FromPixels (surface.Height / 2);
				layout.Ellipsize = Pango.EllipsizeMode.None;
				layout.FontDescription = new Gtk.Style ().FontDescription;
				layout.FontDescription.Weight = Pango.Weight.Bold;
				
				Pango.Rectangle inkRect, logicalRect;
				layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (surface.Height / 2);
				layout.SetText (BadgeText);
				layout.GetPixelExtents (out inkRect, out logicalRect);
				
				size -= 2 * padding + 2 * lineWidth;
				
				double scale = Math.Min (1, Math.Min (size / (double) logicalRect.Width, size / (double) logicalRect.Height));
				
				if (!IsSmall) {
					surface.Context.Color = new Cairo.Color (0, 0, 0, 0.2);
				} else {
					surface.Context.Color = new Cairo.Color (0, 0, 0, 0.6);
					x = surface.Width - scale * logicalRect.Width / 2;
					y = scale * logicalRect.Height / 2;
				}
				
				surface.Context.MoveTo (x - scale * logicalRect.Width / 2, y - scale * logicalRect.Height / 2);
				
				// draw text
				surface.Context.Save ();
				if (scale < 1)
					surface.Context.Scale (scale, scale);
				
				surface.Context.LineWidth = 2;
				Pango.CairoHelper.LayoutPath (surface.Context, layout);
				surface.Context.StrokePreserve ();
				surface.Context.Color = new Cairo.Color (1, 1, 1, 1);
				surface.Context.Fill ();
				surface.Context.Restore ();
				
				layout.FontDescription.Dispose ();
				layout.Context.Dispose ();
			}
		}
Пример #28
0
		// VERY SLOW, only use on cached renders
		public static void RenderOuterShadow (this Cairo.Context self, Gdk.Rectangle area, int size, int rounding, double strength)
		{
			area.Inflate (-1, -1);
			size++;

			int doubleRounding = rounding * 2;
			// left side
			self.Rectangle (area.X - size, area.Y + rounding, size, area.Height - doubleRounding - 1);
			using (var lg = new LinearGradient (area.X, 0, area.X - size, 0)) {
				ShadowGradient (lg, strength);
				self.Pattern = lg;
				self.Fill ();
			}

			// right side
			self.Rectangle (area.Right, area.Y + rounding, size, area.Height - doubleRounding - 1);
			using (var lg = new LinearGradient (area.Right, 0, area.Right + size, 0)) {
				ShadowGradient (lg, strength);
				self.Pattern = lg;
				self.Fill ();
			}

			// top side
			self.Rectangle (area.X + rounding, area.Y - size, area.Width - doubleRounding - 1, size);
			using (var lg = new LinearGradient (0, area.Y, 0, area.Y - size)) {
				ShadowGradient (lg, strength);
				self.Pattern = lg;
				self.Fill ();
			}

			// bottom side
			self.Rectangle (area.X + rounding, area.Bottom, area.Width - doubleRounding - 1, size);
			using (var lg = new LinearGradient (0, area.Bottom, 0, area.Bottom + size)) {
				ShadowGradient (lg, strength);
				self.Pattern = lg;
				self.Fill ();
			}

			// top left corner
			self.Rectangle (area.X - size, area.Y - size, size + rounding, size + rounding);
			using (var rg = new RadialGradient (area.X + rounding, area.Y + rounding, rounding, area.X + rounding, area.Y + rounding, size + rounding)) {
				ShadowGradient (rg, strength);
				self.Pattern = rg;
				self.Fill ();
			}

			// top right corner
			self.Rectangle (area.Right - rounding, area.Y - size, size + rounding, size + rounding);
			using (var rg = new RadialGradient (area.Right - rounding, area.Y + rounding, rounding, area.Right - rounding, area.Y + rounding, size + rounding)) {
				ShadowGradient (rg, strength);
				self.Pattern = rg;
				self.Fill ();
			}

			// bottom left corner
			self.Rectangle (area.X - size, area.Bottom - rounding, size + rounding, size + rounding);
			using (var rg = new RadialGradient (area.X + rounding, area.Bottom - rounding, rounding, area.X + rounding, area.Bottom - rounding, size + rounding)) {
				ShadowGradient (rg, strength);
				self.Pattern = rg;
				self.Fill ();
			}

			// bottom right corner
			self.Rectangle (area.Right - rounding, area.Bottom - rounding, size + rounding, size + rounding);
			using (var rg = new RadialGradient (area.Right - rounding, area.Bottom - rounding, rounding, area.Right - rounding, area.Bottom - rounding, size + rounding)) {
				ShadowGradient (rg, strength);
				self.Pattern = rg;
				self.Fill ();
			}
		}
Пример #29
0
		void DrawCurveTabs (Cairo.Context cr, Cairo.Rectangle rectangle)
		{
			if (IsSeparator)
				return;
			
			cr.MoveTo (rectangle.X, rectangle.Y);
			
			double bottom = rectangle.Y + rectangle.Height - 1;
			
			cr.CurveTo (
				rectangle.X + SpacerWidth / 2, rectangle.Y,
				rectangle.X + SpacerWidth / 2, bottom,
				rectangle.X + SpacerWidth, bottom);
			
			cr.LineTo (rectangle.X + rectangle.Width - SpacerWidth, bottom);
			
			cr.CurveTo (
				rectangle.X + rectangle.Width - SpacerWidth / 2, bottom,
				rectangle.X + rectangle.Width - SpacerWidth / 2, rectangle.Y,
				rectangle.X + rectangle.Width, rectangle.Y);
			
			cr.Color = (HslColor)parent.Style.Dark (StateType.Normal);
			cr.StrokePreserve ();
			cr.ClosePath ();
			if (Active) {
				cr.Color = (HslColor)parent.Style.Background (StateType.Prelight);
			} else if (HoverPosition.X >= 0) {
				double rx = rectangle.X + HoverPosition.X;
				double ry = rectangle.Y + HoverPosition.Y;
				Cairo.RadialGradient gradient = new Cairo.RadialGradient (rx, ry, rectangle.Height * 1.5, 
					rx, ry, 2);
				var color = (HslColor)parent.Style.Mid (StateType.Normal);
				color.L *= 1.05;
				gradient.AddColorStop (0, color);
				color.L *= 1.07;
				gradient.AddColorStop (1, color);
				cr.Pattern = gradient;
			} else {
				cr.Color = (HslColor)parent.Style.Mid (StateType.Normal);
			}
			cr.Fill ();
			
			cr.Save ();
			cr.Translate (rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2);
			cr.Color = (HslColor)parent.Style.Text (StateType.Normal);
			
			cr.ShowLayout (layout);
			
			cr.Restore ();
		}
Пример #30
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            int x = (int)point.X;
            int y = (int)point.Y;

            if (args.Event.Button == 1)//Left
            {
                //Select an origin with Ctrl + Click
                if((args.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask)
                {
                    from_point = new Point (x, y);
                    stamp = new Cairo.ImageSurface (PintaCore.Layers.CurrentLayer.Surface.Format, BrushWidth*2, BrushWidth*2);
                    from_point = ClampPoint(from_point);

                    using (Context g = new Context (stamp)) {
                        g.SetSourceSurface (PintaCore.Layers.CurrentLayer.Surface,
                                            0 - (from_point.X - BrushWidth),
                                            0 - (from_point.Y - BrushWidth));//dest - source

                        g.Rectangle(0, 0, BrushWidth * 2, BrushWidth * 2);

                        Gradient radpat = new RadialGradient(from_point.X, from_point.Y, BrushWidth, from_point.X, from_point.Y, BrushWidth);
                        radpat.AddColorStop(0, new Color(0, 0, 0, 1));
                        radpat.AddColorStop(1, new Color(0, 0, 0, 0));

                        g.Mask(radpat);

                        g.Fill ();
                    }

                // Draw the copy
                } else {
                    to_point = new Point (x, y);

                    if (PintaCore.Workspace.PointInCanvas (point) && !from_point.Equals (point_empty))
                    {
                        to_point = ClampPoint(to_point);
                        surface_modified = true;

                        undo_surface = PintaCore.Layers.CurrentLayer.Surface.Clone ();

                        ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

                        using (Context g = new Context (surf)) {
                            g.SetSourceSurface (stamp, to_point.X - BrushWidth, to_point.Y - BrushWidth);
                            g.Paint ();
                        }

                        Gdk.Rectangle r = GetRectangleFromPoints (to_point, to_point);

                        PintaCore.Workspace.Invalidate ();
                        PintaCore.History.PushNewItem(new SimpleHistoryItem (Icon, Name,undo_surface, PintaCore.Layers.CurrentLayerIndex));
                    }
                    from_point = point_empty;
                }
            }
            base.OnMouseDown (canvas, args, point);
        }
Пример #31
0
		void DrawButtonTabs (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.Color = (HslColor)parent.Style.Dark (StateType.Normal);
				cr.LineWidth = 1;
				cr.Stroke ();
				return;
			}
			
			int topPadding = 2;
			
			if (Active || HoverPosition.X >= 0) {
				cr.Rectangle (rectangle.X + 1, rectangle.Y + 1 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding);
				if (Active) {
					cr.Color = (HslColor)parent.Style.Background (StateType.Prelight);
				} else if (HoverPosition.X >= 0) {
					double rx = rectangle.X + HoverPosition.X;
					double ry = rectangle.Y + HoverPosition.Y;
					Cairo.RadialGradient gradient = new Cairo.RadialGradient (rx, ry, rectangle.Height * 1.5, 
						rx, ry, 2);
					var color = (HslColor)parent.Style.Dark (StateType.Normal);
					color.L *= 1.1;
					gradient.AddColorStop (0, color);
					color.L *= 1.1;
					gradient.AddColorStop (1, color);
					cr.Pattern = gradient;
				}
				cr.Fill ();
				
				if (Active) {
					cr.Rectangle (rectangle.X + 0.5, rectangle.Y + 0.5 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding);
					cr.Color = (HslColor)parent.Style.Dark (StateType.Normal);
					cr.LineWidth = 1;
					cr.Stroke ();
				}
			}
			
			cr.Save ();
			cr.Translate (rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2 + topPadding);
			cr.Color = (HslColor)parent.Style.Text (StateType.Normal);
			
			cr.ShowLayout (layout);
			
			cr.Restore ();
		}
Пример #32
0
		protected virtual void DrawBackground (Cairo.Context context, Gdk.Rectangle region)
		{	
			LayoutRoundedRectangle (context, region);
			context.ClipPreserve ();

			using (LinearGradient lg = new LinearGradient (region.X, region.Y, region.X, region.Y + region.Height)) {
				lg.AddColorStop (0, Styles.StatusBarFill1Color);
				lg.AddColorStop (1, Styles.StatusBarFill4Color);

				context.Pattern = lg;
				context.FillPreserve ();
			}

			context.Save ();
			double midX = region.X + region.Width / 2.0;
			double midY = region.Y + region.Height;
			context.Translate (midX, midY);

			using (RadialGradient rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) {
				rg.AddColorStop (0, Styles.StatusBarFill1Color);
				rg.AddColorStop (1, Styles.WithAlpha (Styles.StatusBarFill1Color, 0));

				context.Scale (region.Width / (double)region.Height, 1.0);
				context.Pattern = rg;
				context.Fill ();
			}
			context.Restore ();

			using (LinearGradient lg = new LinearGradient (0, region.Y, 0, region.Y + region.Height)) {
				lg.AddColorStop (0, Styles.StatusBarShadowColor1);
				lg.AddColorStop (1, Styles.WithAlpha (Styles.StatusBarShadowColor1, Styles.StatusBarShadowColor1.A * 0.2));

				LayoutRoundedRectangle (context, region, 0, -1);
				context.LineWidth = 1;
				context.Pattern = lg;
				context.Stroke ();
			}

			using (LinearGradient lg = new LinearGradient (0, region.Y, 0, region.Y + region.Height)) {
				lg.AddColorStop (0, Styles.StatusBarShadowColor2);
				lg.AddColorStop (1, Styles.WithAlpha (Styles.StatusBarShadowColor2, Styles.StatusBarShadowColor2.A * 0.2));

				LayoutRoundedRectangle (context, region, 0, -2);
				context.LineWidth = 1;
				context.Pattern = lg;
				context.Stroke ();
			}

			context.ResetClip ();
		}
Пример #33
0
		protected override void PaintIconSurface (DockySurface surface)
		{
			int size = Math.Min (surface.Width, surface.Height);
			Context cr = surface.Context;
			
			double center = size / 2.0;
			Cairo.Color base_color = new Cairo.Color (1, .3, .3, .5).SetHue (120 * (1 - CPUUtilization));
			
			double radius = Math.Max (Math.Min (CPUUtilization * 1.3, 1), .001);
			
			// draw underlay
			cr.Arc (center, center, center * RadiusPercent, 0, Math.PI * 2);
			cr.Color = new Cairo.Color (0, 0, 0, .5);
			cr.FillPreserve ();
			
			RadialGradient rg = new RadialGradient (center, center, 0, center, center, center * RadiusPercent);
			rg.AddColorStop (0, base_color);
			rg.AddColorStop (0.2, base_color);
			rg.AddColorStop (1, new Cairo.Color (base_color.R, base_color.G, base_color.B, 0.15));
			cr.Pattern = rg;
			cr.FillPreserve ();
			
			rg.Destroy ();
			
			// draw cpu indicator
			rg = new RadialGradient (center, center, 0, center, center, center * RadiusPercent * radius);
			rg.AddColorStop (0, new Cairo.Color (base_color.R, base_color.G, base_color.B, 1));
			rg.AddColorStop (0.2, new Cairo.Color (base_color.R, base_color.G, base_color.B, 1));
			rg.AddColorStop (1, new Cairo.Color (base_color.R, base_color.G, base_color.B, Math.Max (0, CPUUtilization * 1.3 - 1)));
			cr.Pattern = rg;
			cr.Fill ();
			
			rg.Destroy ();
			
			// draw highlight
			cr.Arc (center, center * .8, center * .6, 0, Math.PI * 2);
			LinearGradient lg = new LinearGradient (0, 0, 0, center);
			lg.AddColorStop (0, new Cairo.Color (1, 1, 1, .35));
			lg.AddColorStop (1, new Cairo.Color (1, 1, 1, 0));
			cr.Pattern = lg;
			cr.Fill ();
			lg.Destroy ();
			
			// draw outer circles
			cr.LineWidth = 1;
			cr.Arc (center, center, center * RadiusPercent, 0, Math.PI * 2);
			cr.Color = new Cairo.Color (1, 1, 1, .75);
			cr.Stroke ();
			
			cr.LineWidth = 1;
			cr.Arc (center, center, center * RadiusPercent - 1, 0, Math.PI * 2);
			cr.Color = new Cairo.Color (.8, .8, .8, .75);
			cr.Stroke ();
			
			// draw memory indicate
			cr.LineWidth = size / 32.0;
			cr.ArcNegative (center, center, center * RadiusPercent - 1, Math.PI, Math.PI - Math.PI * (2 * MemoryUtilization));
			cr.Color = new Cairo.Color (1, 1, 1, .8);
			cr.Stroke ();
		}