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


C# Canvas.DrawTextBackground方法代码示例

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


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

示例1: Canvas

		void ICmpRenderer.Draw(IDrawDevice device)
		{
			Profile.BeginMeasure(@"ProfileRenderer");
			Canvas canvas = new Canvas(device);
			canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White, null));
			
			bool anyTextReport = this.textReportPerf || this.textReportStat;
			bool anyGraph = this.drawGraphs && this.counterGraphs.Count > 0;

			// Determine geometry
			int areaWidth = (int)device.TargetSize.X - 20;
			if (anyGraph && anyTextReport)
				areaWidth = (areaWidth - 10) / 2;
			Rect textReportRect = new Rect(
				10, 
				10, 
				anyTextReport ? areaWidth : 0, 
				(int)device.TargetSize.Y - 20);
			Rect graphRect = new Rect(
				anyTextReport ? (textReportRect.MaximumX + 10) : 10, 
				10, 
				anyGraph ? areaWidth : 0, 
				(int)device.TargetSize.Y - 20);

			// Text Reports
			if (anyTextReport)
			{
				// Update Report
				IEnumerable<ProfileCounter> counters = Profile.GetUsedCounters();
				if (!this.textReportPerf) counters = counters.Where(c => !(c is TimeCounter));
				if (!this.textReportStat) counters = counters.Where(c => !(c is StatCounter));
				if (this.textReport == null || (Time.MainTimer - this.textReportLast).TotalMilliseconds > this.updateInterval)
				{
					string report = Profile.GetTextReport(counters, this.textReportOptions | ReportOptions.FormattedText);

					if (this.textReport == null)
					{
						this.textReport = new FormattedText();
						this.textReport.Fonts = new[] { Font.GenericMonospace8 };
					}
					this.textReport.MaxWidth = (int)textReportRect.W;
					this.textReport.SourceText = report;
					this.textReportLast = Time.MainTimer;
				}

				// Draw Report
				canvas.DrawTextBackground(textReport, textReportRect.X, textReportRect.Y);
				canvas.DrawText(textReport, ref textReportTextVert, ref textReportIconVert, textReportRect.X, textReportRect.Y);
			}

			// Counter Graphs
			if (anyGraph)
			{
				// Mark graph cache as unused
				foreach (GraphCacheEntry entry in this.graphCache.Values)
				{
					entry.WasUsed = false;
				}

				int space = 5;
				int graphY = (int)graphRect.Y;
				int graphH = MathF.Min((int)(graphRect.H / this.counterGraphs.Count) - space, (int)graphRect.W / 2);
				foreach (string counterName in this.counterGraphs)
				{
					ProfileCounter counter = Profile.GetCounter<ProfileCounter>(counterName);
					if (counter == null) return;

					// Create or retrieve graph cache entry
					GraphCacheEntry cache = null;
					if (!this.graphCache.TryGetValue(counterName, out cache))
					{
						cache = new GraphCacheEntry();
						cache.GraphValues = new float[ProfileCounter.ValueHistoryLen];
						cache.GraphColors = new ColorRgba[ProfileCounter.ValueHistoryLen];
						this.graphCache[counterName] = cache;
					}
					cache.WasUsed = true;

					float cursorRatio = 0.0f;
					if (counter is TimeCounter)
					{
						TimeCounter timeCounter = counter as TimeCounter;
						for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++)
						{
							float factor = timeCounter.ValueGraph[i] / Time.MsPFMult;
							cache.GraphValues[i] = factor * 0.75f;
							cache.GraphColors[i] = ColorRgba.Lerp(ColorRgba.White, ColorRgba.Red, factor);
						}
						canvas.CurrentState.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
						canvas.FillRect(graphRect.X, graphY, graphRect.W, graphH);
						canvas.CurrentState.ColorTint = ColorRgba.White;
						canvas.DrawHorizontalGraph(cache.GraphValues, cache.GraphColors, ref cache.VertGraph, graphRect.X, graphY, graphRect.W, graphH);
						cursorRatio = (float)timeCounter.ValueGraphCursor / (float)ProfileCounter.ValueHistoryLen;
					}
					else if (counter is StatCounter)
					{
						StatCounter statCounter = counter as StatCounter;
						for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++)
						{
							cache.GraphValues[i] = (float)(statCounter.ValueGraph[i] - statCounter.MinValue) / statCounter.MaxValue;
//.........这里部分代码省略.........
开发者ID:KETMGaming,项目名称:duality,代码行数:101,代码来源:ProfileRenderer.cs

示例2: OnCollectOverlayDrawcalls

		protected internal override void OnCollectOverlayDrawcalls(Canvas canvas)
		{
			base.OnCollectOverlayDrawcalls(canvas);
			bool noActionText = string.IsNullOrEmpty(this.View.ActiveState.ActionText);
			bool mouseover = this.View.ActiveState.Mouseover;

			Point cursorPos = this.PointToClient(Cursor.Position);
			if (noActionText && mouseover &&
				cursorPos.X > 0 && cursorPos.X < this.ClientSize.Width &&
				cursorPos.Y > 0 && cursorPos.Y < this.ClientSize.Height)
			{
				var cursorSpacePos = this.GetSpaceCoord(new Vector2(cursorPos.X, cursorPos.Y));

				cursorPos.X += 30;
				cursorPos.Y += 10;

				string[] text = new string[]
				{
					string.Format("X:{0,7:0}", cursorSpacePos.X),
					string.Format("Y:{0,7:0}", cursorSpacePos.Y)
				};
				canvas.DrawTextBackground(text, cursorPos.X, cursorPos.Y);
				canvas.DrawText(text, cursorPos.X, cursorPos.Y);
			}
		}
开发者ID:Andrea,项目名称:duality-withsvn-history,代码行数:25,代码来源:GridCamViewLayer.cs


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