public MatchData getData(string teamAbbr) { // First get the date and time for this week's game. If it has already passed, go to next week's game. var data = from item in curWeek.Descendants("g") where (string)item.Attribute("v") == teamAbbr || (string)item.Attribute("h") == teamAbbr select new { eid = item.Attribute("eid").Value, home = item.Attribute("h").Value, away = item.Attribute("v").Value, time = item.Attribute("t").Value, day = item.Attribute("d").Value }; var p = data.FirstOrDefault(); if ((p == null) || (DatePassed(p.eid.ToString(), p.time.ToString()))) // if p is null then there is probably a Bye week for the selected team { data = from item in nextWeek.Descendants("g") where (string)item.Attribute("v") == teamAbbr || (string)item.Attribute("h") == teamAbbr select new { eid = item.Attribute("eid").Value, home = item.Attribute("h").Value, away = item.Attribute("v").Value, time = item.Attribute("t").Value, day = item.Attribute("d").Value }; p = data.FirstOrDefault(); } MatchData matchData = new MatchData(); if (p != null) { matchData.eid = p.eid.ToString(); matchData.home = p.home.ToString(); matchData.away = p.away.ToString(); matchData.day = p.day.ToString(); matchData.time = p.time.ToString(); } else // if p is still null here, there is something wrong... { logger.Fatal("Unable to find next match for selected team!"); MessageBox.Show("Unable to find next match for selected team!", "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return matchData; }
public Image GenerateWallpaper(MatchData data, string background) { string awayText = GetTeamCity(data.away).ToUpper(); string awayTeam = GetTeamName(data.away).ToUpper(); string homeText = GetTeamCity(data.home).ToUpper(); string homeTeam = GetTeamName(data.home).ToUpper(); CultureInfo enUS = new CultureInfo("en-US"); PointF awayCityLocation = new PointF(0f, 400f); PointF awayTeamLocation = new PointF(-20f, 440f); var assembly = typeof(NFLWallpaper.Program).Assembly; string[] names = assembly.GetManifestResourceNames(); Image image; if (background.Contains("\\")) { image = Image.FromFile(background); } else { image = Image.FromStream(assembly.GetManifestResourceStream("NFLWallpaper.Resources.Background." + background + ".jpg")); } if (image != null) { float backgroundWidth = image.Width; float backgroundHeight = image.Height; float shadowOffset = backgroundHeight / 240f; float helmetHeight = backgroundHeight / 5.660f; float helmetWidth = backgroundHeight / 4.286f; Graphics graphics = Graphics.FromImage(image); graphics.TextRenderingHint = TextRenderingHint.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.SmoothingMode = SmoothingMode.AntiAlias; using (Font teamFont = new Font(pfc.Families[0], backgroundWidth / 10f, FontStyle.Bold, GraphicsUnit.Pixel), cityFont = new Font(pfc.Families[1], backgroundWidth / 30.0f, FontStyle.Bold, GraphicsUnit.Pixel), dayFont = new Font(pfc.Families[1], backgroundHeight / 22.5f, FontStyle.Bold, GraphicsUnit.Pixel)) { StringFormat format = new StringFormat(StringFormat.GenericTypographic); float teamHeight = cityFont.Size * cityFont.FontFamily.GetLineSpacing(FontStyle.Bold) / cityFont.FontFamily.GetEmHeight(FontStyle.Bold); teamHeight += teamFont.Size * teamFont.FontFamily.GetCellAscent(FontStyle.Bold) / teamFont.FontFamily.GetEmHeight(FontStyle.Bold); teamHeight = teamHeight * 1.05f; RectangleF rect = new RectangleF(backgroundWidth / 50, (backgroundHeight - teamHeight - helmetHeight) / 2 + helmetHeight, backgroundWidth / 2, teamHeight); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; DrawText(graphics, awayText, cityFont, rect, format, shadowOffset); format.LineAlignment = StringAlignment.Far; DrawText(graphics, awayTeam, teamFont, rect, format, shadowOffset); rect = new RectangleF(backgroundWidth / 2 - backgroundWidth / 50, (backgroundHeight - teamHeight - helmetHeight) / 2 + helmetHeight, backgroundWidth / 2, teamHeight); format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Near; DrawText(graphics, homeText, cityFont, rect, format, shadowOffset); format.LineAlignment = StringAlignment.Far; DrawText(graphics, homeTeam, teamFont, rect, format, shadowOffset); DateTime localTime = ConvertToLocalTime(data.eid, data.time); rect = new RectangleF(0, backgroundHeight / 24, backgroundWidth, backgroundHeight / 10); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Near; DrawText(graphics, localTime.ToString("D", enUS), dayFont, rect, format, shadowOffset); format.LineAlignment = StringAlignment.Far; DrawText(graphics, localTime.ToString("HH:mm"), dayFont, rect, format, shadowOffset); Image helmet; helmet = Image.FromStream(assembly.GetManifestResourceStream("NFLWallpaper.Resources.Helmets." + data.home + ".png")); helmet.RotateFlip(RotateFlipType.RotateNoneFlipX); graphics.DrawImage(helmet, new RectangleF(backgroundWidth - helmetWidth - backgroundWidth / 50, (backgroundHeight - teamHeight - helmetHeight) / 2, helmetWidth, helmetHeight)); helmet = Image.FromStream(assembly.GetManifestResourceStream("NFLWallpaper.Resources.Helmets." + data.away + ".png")); graphics.DrawImage(helmet, new RectangleF(backgroundWidth / 50, (backgroundHeight - teamHeight - helmetHeight) / 2, helmetWidth, helmetHeight)); } return image; } else { return null; } }