Example #1
0
        public static void DrawRoundedRectangle(Cairo.Context gr, double x, double y,
		                                        double width, double height, double radius,
		                                        Cairo.Color color, Cairo.Color borderColor)
        {
            gr.Save();

            if((radius > height / 2) || (radius > width / 2))
                radius = Math.Min(height / 2, width / 2);

            gr.MoveTo(x, y + radius);
            gr.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2);
            gr.LineTo(x + width - radius, y);
            gr.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0);
            gr.LineTo(x + width, y + height - radius);
            gr.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2);
            gr.LineTo(x + radius, y + height);
            gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI);
            gr.ClosePath();
            gr.Restore();

            gr.LineJoin = LineJoin.Round;
            gr.Color = borderColor;
            gr.StrokePreserve();
            gr.Color = color;
            gr.Fill();
        }
Example #2
0
 protected void DrawPaper(Cairo.Context cr, double x, double y, double w, double h)
 {
     // make the background white with a line around
     cr.Rectangle(x+shadowOffset*2,y+shadowOffset*2,w-shadowOffset*2,h-shadowOffset*2);
     cr.Color = shadowColor;
     cr.Fill();
     GetInnerRegion(ref x,ref y,ref w,ref h);
     cr.Rectangle(x,y,w,h);
     cr.Color  = new Cairo.Color(0, 0, 0);
     cr.StrokePreserve();
     cr.Color  = new Cairo.Color(1, 1, 1);
     cr.Fill();
 }
Example #3
0
        protected override void onDraw(Cairo.Context gr)
        {
            gr.Save ();

            int spacing = (Parent as TabView).Spacing;

            gr.MoveTo (0.5, TabTitle.Slot.Bottom-0.5);
            gr.LineTo (TabTitle.Slot.Left - spacing, TabTitle.Slot.Bottom-0.5);
            gr.CurveTo (
                TabTitle.Slot.Left - spacing / 2, TabTitle.Slot.Bottom-0.5,
                TabTitle.Slot.Left - spacing / 2, 0.5,
                TabTitle.Slot.Left, 0.5);
            gr.LineTo (TabTitle.Slot.Right, 0.5);
            gr.CurveTo (
                TabTitle.Slot.Right + spacing / 2, 0.5,
                TabTitle.Slot.Right + spacing / 2, TabTitle.Slot.Bottom-0.5,
                TabTitle.Slot.Right + spacing, TabTitle.Slot.Bottom-0.5);
            gr.LineTo (Slot.Width-0.5, TabTitle.Slot.Bottom-0.5);

            gr.LineTo (Slot.Width-0.5, Slot.Height-0.5);
            gr.LineTo (0.5, Slot.Height-0.5);
            gr.ClosePath ();
            gr.LineWidth = 2;
            Foreground.SetAsSource (gr);
            gr.StrokePreserve ();

            gr.Clip ();
            base.onDraw (gr);
            gr.Restore ();
        }
		protected virtual void DrawBorder (Cairo.Context context, Gdk.Rectangle region)
		{
			LayoutRoundedRectangle (context, region, -1, -1);
			context.LineWidth = 1;
			context.Color = Styles.StatusBarInnerColor;
			context.Stroke ();

			LayoutRoundedRectangle (context, region);
			context.LineWidth = 1;
			context.Color = Styles.StatusBarBorderColor;
			context.StrokePreserve ();
		}
			void DrawArrow (Cairo.Context g, double x, double y)
			{
				var editor = mode.editor;
				double phi = 1.618;
				double arrowLength = editor.LineHeight * phi;
				double arrowHeight = editor.LineHeight / phi;
				
				g.MoveTo (x - arrowLength, y - arrowHeight);
				g.LineTo (x, y);
				g.LineTo (x - arrowLength, y + arrowHeight);
				
				g.LineTo (x - arrowLength / phi, y);
				g.ClosePath ();
				g.SetSourceRGB (1.0, 0, 0);
				g.StrokePreserve ();
				
				g.SetSourceRGBA (1.0, 0, 0, 0.1);
				g.Fill ();
			}
			protected override void DrawBar (Cairo.Context cr)
			{
				if (vadjustment == null || vadjustment.Upper <= vadjustment.PageSize) 
					return;
				var h = Allocation.Height;
				cr.Rectangle (1.5,
					              h * vadjustment.Value / vadjustment.Upper + cr.LineWidth + 0.5,
					              Allocation.Width - 2,
					              h * (vadjustment.PageSize / vadjustment.Upper));
				Cairo.Color color = (TextEditor.ColorStyle != null) ? TextEditor.ColorStyle.Default.CairoColor : new Cairo.Color (0, 0, 0);
				color.A = 0.5;
				cr.Color = color;
				cr.StrokePreserve ();
				
				color.A = 0.05;
				cr.Color = color;
				cr.Fill ();
			}
Example #7
0
        public void Draw(Cairo.Context g, double scale, bool fillSelection)
        {
            g.Save ();
            g.Translate (0.5, 0.5);
            g.Scale (scale, scale);

            g.AppendPath (selection_path);

            if (fillSelection)
            {
                g.Color = new Cairo.Color (0.7, 0.8, 0.9, 0.2);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.FillPreserve ();
            }

            g.LineWidth = 1 / scale;

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

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

            g.Stroke ();
            g.Restore ();
        }
Example #8
0
		void DrawBar (Cairo.Context cr)
		{
			if (adj == null || adj.Upper <= adj.PageSize) 
				return;
			int h = Allocation.Height - Allocation.Width - 6;
			cr.Rectangle (1.5,
				              h * adj.Value / adj.Upper + cr.LineWidth + 0.5,
				              Allocation.Width - 2,
				              h * (adj.PageSize / adj.Upper));
			Cairo.Color color = (TextEditor.ColorStyle != null) ? TextEditor.ColorStyle.Default.CairoColor : new Cairo.Color (0, 0, 0);
			color.A = 0.5;
			cr.Color = color;
			cr.StrokePreserve ();
			
			color.A = 0.05;
			cr.Color = color;
			cr.Fill ();
		}
Example #9
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.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 ();
		}
Example #10
0
        //Draws the dots on the screen, end is a moot parameter
        public void DrawDot(Cairo.Context ctx, PointD start, PointD end)
        {
            if (!start.Equals (prevDot)) {

                    ctx.SetSourceRGBA (R, G, B, A);
                    ctx.Arc (start.X, start.Y, 1, 0, 2 * Math.PI);
                    ctx.StrokePreserve ();
                    ctx.Fill ();
                if (startRecordPoints) {

                    currentDrawnPoints.Add (start);

                }
                prevDot = start;

            }
        }
			void DrawArrow (Cairo.Context g, int x, int y)
			{
				TextEditor editor = mode.editor;
				double phi = 1.618;
				double arrowLength = editor.LineHeight * phi;
				double arrowHeight = editor.LineHeight / phi;
				
				g.MoveTo (x - arrowLength, y - arrowHeight);
				g.LineTo (x, y);
				g.LineTo (x - arrowLength, y + arrowHeight);
				
				g.LineTo (x - arrowLength / phi, y);
				g.ClosePath ();
				g.Color = new Cairo.Color (1.0, 0, 0);
				g.StrokePreserve ();
				
				g.Color = new Cairo.Color (1.0, 0, 0, 0.1);
				g.Fill ();
			}
Example #12
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 ();
		}
		/// <summary>
		/// Paints an overview of the forecast including high/low temps and a condition icon.
		/// </summary>
		/// <param name="cr">
		/// A <see cref="Cairo.Context"/> to do the painting.
		/// </param>
		void DrawVertForecast (Cairo.Context cr)
		{
			int cellHeight = (int) ((Allocation.Height - BUTTON_SIZE) / WeatherController.Weather.ForecastDays / 1.5);
			double xOffset = 0;
			double yOffset = cellHeight / 4.0;
			
			using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {
				Pango.Rectangle inkRect, logicalRect;
				
				layout.FontDescription = new Gtk.Style().FontDescription;
				layout.FontDescription.Weight = Pango.Weight.Bold;
				layout.Ellipsize = Pango.EllipsizeMode.None;
				layout.Width = Pango.Units.FromPixels (cellHeight);
				
				for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) {
					layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellHeight / 5));
					
					cr.Color = colorTitle;
					layout.SetText (string.Format ("{0}", WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow)));
					layout.GetPixelExtents (out inkRect, out logicalRect);
					cr.MoveTo (xOffset + (cellHeight - inkRect.Width) / 2, yOffset);
					Pango.CairoHelper.LayoutPath (cr, layout);
					cr.Fill ();
					
					cr.Color = colorHigh;
					layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].high, AbstractWeatherSource.TempUnit));
					layout.GetPixelExtents (out inkRect, out logicalRect);
					cr.MoveTo (xOffset + (cellHeight - inkRect.Width) / 2, yOffset + (cellHeight - logicalRect.Height) / 2);
					Pango.CairoHelper.LayoutPath (cr, layout);
					cr.Fill ();
					
					cr.Color = colorLow;
					layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].low, AbstractWeatherSource.TempUnit));
					layout.GetPixelExtents (out inkRect, out logicalRect);
					cr.MoveTo (xOffset + (cellHeight - inkRect.Width) / 2, yOffset + cellHeight - logicalRect.Height);
					Pango.CairoHelper.LayoutPath (cr, layout);
					cr.Fill ();
					
					using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon (WeatherController.Weather.Forecasts [day].image, cellHeight - 5)) {
						Gdk.CairoHelper.SetSourcePixbuf (cr, pbuf, xOffset + 5 + cellHeight, yOffset + 2);
						cr.PaintWithAlpha (WeatherController.Weather.Forecasts [day].chanceOf ? .6 : 1);
					}
					
					if (WeatherController.Weather.Forecasts [day].chanceOf) {
						layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellHeight / 2));
						
						layout.SetText ("?");
						
						layout.GetPixelExtents (out inkRect, out logicalRect);
						cr.MoveTo (xOffset + cellHeight + (cellHeight - inkRect.Width) / 2, yOffset + (cellHeight - logicalRect.Height) / 2);
						
						cr.LineWidth = 4;
						cr.Color = new Cairo.Color (0, 0, 0, 0.3);
						Pango.CairoHelper.LayoutPath (cr, layout);
						cr.StrokePreserve ();
						
						cr.Color = new Cairo.Color (1, 1, 1, .6);
						cr.Fill ();
					}
					
					yOffset += (int) (1.5 * cellHeight);
				}
				
				layout.FontDescription.Dispose ();
				layout.Context.Dispose ();
			}
		}
Example #14
0
        private void RenderNodeGroup(NodeGroup ng, Network network, Cairo.Context gc)
        {
            gc.Save();

            SizeD size = CalculateNodeGroupSize(ng, gc);
            ng.Dimension = size;
            CreateRoundedRectPath(gc, ng.Position.X, ng.Position.Y, size.Width, size.Height, 20);
            gc.Color = new Cairo.Color(0, 0, 0, 0.5);
            gc.FillPreserve();

            if (selectedGroup == ng) {
                gc.Save();
                gc.Color = orangeOverlay;
                gc.StrokePreserve();
                gc.Restore();
            }

            var titleTextSize = CalculateNodeGroupTitleTextSize(ng, gc);
            var titleSize = new SizeD(size.Width, titleTextSize.Height + (Padding * 2.0));

            gc.Clip();
            gc.Rectangle(ng.Position.X, ng.Position.Y, titleSize.Width, titleSize.Height);
            gc.Fill();
            gc.ResetClip();

            gc.Color = lightGray;

            double hostTextX = ng.Position.X + (titleSize.Width / 2.0) - (titleTextSize.Width / 2.0);
            double hostTextY = ng.Position.Y + (titleSize.Height / 2.0) - (titleTextSize.Height / 2.0);
            gc.MoveTo(hostTextX, hostTextY /* + titleTextSize.Height */);

            Pango.Layout layout = new Pango.Layout(this.PangoContext);
            layout.FontDescription = this.PangoContext.FontDescription.Copy();
            layout.FontDescription.Size = Pango.Units.FromDouble(NodegroupNameFontSize);
            layout.SetText(ng.Name);
            Pango.CairoHelper.ShowLayout(gc, layout);

            SizeD nodesSize = CalculateNodeGroupSize(ng, gc);

            if (ng.Nodes.Count == 1) {
                double positionY = ng.Position.Y + titleSize.Height + Padding;
                double positionX = ng.Position.X + (ng.Dimension.Width / 2.0) - HalfAvatarDimension;
                RenderNode(gc, (Node)ng.Nodes[0], positionX, positionY);
            } else if (ng.Nodes.Count == 2) {
                // position them side-by-side, separated by (padding) number of pixels, centered in the
                // space.
                double positionY = ng.Position.Y + titleSize.Height + Padding;
                double position1X = ng.Position.X + (ng.Dimension.Width / 2.0) - (Padding / 2.0) - AvatarDimension;
                double position2X = position1X + Padding + AvatarDimension;
                RenderNode(gc, (Node)ng.Nodes[0], position1X, positionY);
                RenderNode(gc, (Node)ng.Nodes[1], position2X, positionY);
            } else {
                double deg = 0;
                double x = 0;
                double y = 0;

                var contentY = ng.Position.Y + titleSize.Height;
                var contentHeight = size.Height - titleSize.Height;
                var middle = new System.Drawing.Point(Convert.ToInt32(ng.Position.X + size.Width - (size.Width / 2.0)),
                                                      Convert.ToInt32(contentY + contentHeight - (contentHeight / 2.0)));

                int nodeSize = Convert.ToInt32(AvatarDimension);
                for (int i = 0; i < ng.Nodes.Count; i++) {
                    x = Math.Sin(deg) * ((size.Width / 2.0) - (nodeSize)) + middle.X - (nodeSize / 2.0);
                    y = Math.Cos(deg) * ((contentHeight / 2.0) - (nodeSize)) + middle.Y - (nodeSize / 2.0);
                    RenderNode(gc, (Node)ng.Nodes[i], x, y);
                    deg += Math.PI / (ng.Nodes.Count / 2.0);
                }
            }
            gc.Restore();
        }
		protected override void OnRender (Cairo.Context context)
		{
			context.RoundedRectangle (0.5, 0.5, Width - 1, Height - 1, Rounding);
			if (Relief) {
				using (var lg = new Cairo.LinearGradient (0, 0, 0, Height)) {
					CreateGradient (lg, State, Opacity);
					context.Pattern = lg;
					context.FillPreserve ();
				}
				
				context.LineWidth = 1;
				context.Color = new Cairo.Color (0.8, 0.8, 0.8, Opacity);
				context.StrokePreserve ();
			}
			context.Clip ();
			base.OnRender (context);
		}
Example #16
0
        public void Render(Cairo.Context cr, Layout layout, double x, double y, double width, double height)
        {
            cr.Save();
            cr.Translate (x,y);

            // make the background white
            cr.Rectangle(1,1,width-2,height-2);
            cr.LineWidth = 1;
            cr.Color  = new Cairo.Color(0, 0, 0);
            cr.StrokePreserve();
            cr.Color  = new Cairo.Color(1, 1, 1);
            cr.Fill();
            cr.Restore();
        }