Esempio n. 1
0
        public MenuItemFactory WithTooltip(string text, Color?color = null)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            Tooltip = new TooltipWrapper(text, color);
            return(this);
        }
Esempio n. 2
0
		static void ExtractTooltips()
		{
			var dstPath = @"..\..\..\!Data\Tooltips";
			var imagesPath = Path.Combine(dstPath, "images");
				
			var specificTooltip = "";

			var files = Directory.GetFiles(dstPath, "1920x1200*_imagesearch.bmp");//.Take(10).ToArray();
			int i = 1;

			var html = new StringBuilder();			
			html.AppendLine("<!DOCTYPE html>");
			html.AppendLine(@"<html xmlns=""http://www.w3.org/1999/xhtml"">");
			html.AppendLine("<head>");
			html.AppendLine(@"<link rel=""Stylesheet"" type=""text/css"" href=""styles.css"">");
			html.AppendLine("</head>");
			html.AppendLine("<body>").AppendLine(@"<table cellpadding=""0"" cellspacing=""0"">");

			WarmUp(files[0]);

			var results1 = new List<Results>();
			var results2 = new List<Results>();

			foreach (var file in files)
			{
				if (!string.IsNullOrEmpty(specificTooltip) && !file.Contains(specificTooltip))
				{
					continue;
				}

				var filename = Path.GetFileName(file);

				var m = Regex.Match(filename, @"(?<W>\d+)x(?<H>\d+)");
				int width = int.Parse(m.Groups["W"].Value);
				int height = int.Parse(m.Groups["H"].Value);

				Bitmap bitmap = Bitmap.FromFile(file) as Bitmap;

				var path = Path.Combine(imagesPath, Path.GetFileNameWithoutExtension(file) + ".jpg");
				if (!File.Exists(path))
				{
					bitmap.Save(path, ImageFormat.Jpeg);
				}

				var tt2 = new TooltipWrapper<Tooltip>(new Tooltip(bitmap), width, height);
				var result2 = new Results(tt2);
				tt2.WrappedTooltip.Save(Path.Combine(dstPath, "tmp_v2", filename));

				//var tt = new TooltipWrapper<Tooltip_old>(new Tooltip_old(bitmap), width, height);
				//var result1 = new Results(tt);
				//tt.WrappedTooltip.Save(Path.Combine(dstPath, "tmp", filename));

				var diffClass = ""; // result1.GetHashCode() == result2.GetHashCode() ? "" : "different";

				html.AppendLine(@"<tr class=""{0}"">", diffClass);
				
				html.AppendLine(@"<td class=""tooltip"">");
				html.AppendLine("<div>");
				html.AppendLine("<img src='images/{0}' />", Path.GetFileName(path));
				html.AppendLine("<span>{0}x{1}</span>", width, height);
				html.AppendLine("</div>");
				html.AppendLine("</td>");

				html.AppendLine("<td class='tt1'>");
				html.AppendLine("<img src='tmp/{0}' />", filename);
				html.AppendLine("</td>");

				html.AppendLine("<td class='tt2'>");
				html.AppendLine("<img src='tmp_v2/{0}' />", filename);
				html.AppendLine("</td>");

				//html.AppendLine(@"<td class=""original"">");
				//html.AppendLine("<pre>");
				//RenderResults(html, result1);
				//html.AppendLine("</pre>");
				//html.AppendLine("</td>");

				html.AppendLine(@"<td class=""improved"">");
				html.AppendLine("<pre>");
				RenderResults(html, result2);
				html.AppendLine("</pre>");
				html.AppendLine("</td>");
				
				html.AppendLine("</tr>");

				//results1.Add(result1);
				results2.Add(result2);

				Console.WriteLine("{0}/{1}", i++, files.Count());
			}

			var r1 = results1.Sum(r => r.TimeTaken) / 1000.0;
			var	r2 = results2.Sum(r => r.TimeTaken) / 1000.0;

			html.AppendLine("<tr>{0}<td class='performance'>{1:0.00}s</td><td class='performance'>{2:0.00}s ({3:0%})</td></tr>", 
				string.Join("", Enumerable.Repeat("<td></td>", 3)), 
				r1, r2, (r2 - r1) / r1
			);

			html.AppendLine("</table>");
			html.AppendLine("</body>").AppendLine("</html>");

			File.WriteAllText(Path.Combine(dstPath, "results.html"), html.ToString());
		}