当前位置: 首页>>代码示例>>C#>>正文


C# Cairo.CachedDraw方法代码示例

本文整理汇总了C#中Cairo.CachedDraw方法的典型用法代码示例。如果您正苦于以下问题:C# Cairo.CachedDraw方法的具体用法?C# Cairo.CachedDraw怎么用?C# Cairo.CachedDraw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cairo的用法示例。


在下文中一共展示了Cairo.CachedDraw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Render

		public void Render (Cairo.Context context, StatusArea.RenderArg arg)
		{
			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.Pattern = 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 - arg.CurrentPixbuf.Height) / 2;
				Gdk.CairoHelper.SetSourcePixbuf (context, arg.CurrentPixbuf, arg.ChildAllocation.X, y);
				context.Paint ();
				progress_bar_x += arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
				progress_bar_width -= 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 ();
		}
开发者ID:wickedshimmy,项目名称:monodevelop,代码行数:81,代码来源:StatusAreaTheme.cs

示例2: DrawErrorAnimation

		void DrawErrorAnimation (Cairo.Context context, StatusArea.RenderArg arg)
		{
			const int surfaceWidth = 2000;
			double opacity;
			int progress;

			if (arg.ErrorAnimationProgress < .5f) {
				progress = (int) (arg.ErrorAnimationProgress * arg.Allocation.Width * 2.4);
				opacity = 1.0d;
			} else {
				progress = (int) (arg.ErrorAnimationProgress * arg.Allocation.Width * 2.4);
				opacity = 1.0d - (arg.ErrorAnimationProgress - .5d) * 2;
			}

			LayoutRoundedRectangle (context, arg.Allocation);

			context.Clip ();
			context.CachedDraw (surface: ref errorSurface,
			                    position: new Gdk.Point (arg.Allocation.X - surfaceWidth + progress, arg.Allocation.Y),
			                    size: new Gdk.Size (surfaceWidth, arg.Allocation.Height),
			                    opacity: (float)opacity,
			                    draw: (c, o) => {
				// The smaller the pixel range of our gradient the less error there will be in it.
				using (var lg = new LinearGradient (surfaceWidth - 250, 0, surfaceWidth, 0)) {
					lg.AddColorStop (0.00, Styles.WithAlpha (Styles.StatusBarErrorColor, 0.15 * o));
					lg.AddColorStop (0.10, Styles.WithAlpha (Styles.StatusBarErrorColor, 0.15 * o));
					lg.AddColorStop (0.88, Styles.WithAlpha (Styles.StatusBarErrorColor, 0.30 * o));
					lg.AddColorStop (1.00, Styles.WithAlpha (Styles.StatusBarErrorColor, 0.00 * o));

					c.Pattern = lg;
					c.Paint ();
				}
			});
			context.ResetClip ();
		}
开发者ID:wickedshimmy,项目名称:monodevelop,代码行数:35,代码来源:StatusAreaTheme.cs


注:本文中的Cairo.CachedDraw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。