public ImageLinkSimpleX(string url) { this.HAnchor = HAnchor.Stretch; this.VAnchor = VAnchor.Fit; this.Selectable = false; this.Url = url; bool showAnimations = true; if (showAnimations) { var imageSequence = new ImageSequence(icon); //var sequenceWidget = new ImageSequenceWidget(imageSequence); var sequenceWidget = new ResponsiveImageSequenceWidget(imageSequence); this.AddChild(sequenceWidget); if (url.StartsWith("http")) { ApplicationController.Instance.DownloadToImageSequenceAsync(imageSequence, url); } } else { var imageBuffer = new ImageBuffer(icon); //var imageWidget = new ImageWidget(imageBuffer); var imageWidget = new ResponsiveImageWidget(imageBuffer); this.AddChild(imageWidget); if (url.StartsWith("http")) { ApplicationController.Instance.DownloadToImageAsync(imageBuffer, url, false); } } }
private void AddContentItem(FeedSectionData content) { switch (content.content_type) { case "headline": { break; // use the Golden Ratio to calculate an attractive size relative to the banner var image = new ImageBuffer(1520, (int)(170 / 1.618)); var imageWidget = new ResponsiveImageWidget(image) { Margin = new BorderDouble(5), Cursor = Cursors.Hand }; var graphics2D = image.NewGraphics2D(); image.SetRecieveBlender(new BlenderPreMultBGRA()); graphics2D.Clear(theme.AccentMimimalOverlay); // use the Golden Ratio to calculate an attractive size for the text relative to the text banner var pixelsPerPoint = 96.0 / 72.0; var goalPointSize = image.Height / pixelsPerPoint / 1.618; var printer = new TypeFacePrinter(content.text, goalPointSize); graphics2D.DrawString(content.text, image.Width / 2, image.Height / 2 + printer.TypeFaceStyle.EmSizeInPixels / 2, goalPointSize, Justification.Center, Baseline.BoundsTop, theme.TextColor); if (content.link != null) { imageWidget.Cursor = Cursors.Hand; imageWidget.Click += (s, e) => { if (e.Button == MouseButtons.Left) { ApplicationController.Instance.LaunchBrowser(content.link); } }; } this.AddChild(imageWidget); } break; case "banner_rotate": // TODO: make this make a carousel rather than add the first item and rotate between all the items var rand = new Random(); AddContentItem(content.banner_list[rand.Next(content.banner_list.Count)]); break; case "banner_image": { // Our banners seem to end with something like "=w1520-h170" // if present use that to get the right width and height int expectedWidth = 1520; GCodeFile.GetFirstNumberAfter("=w", content.image_url, ref expectedWidth); int expectedHeight = 170; GCodeFile.GetFirstNumberAfter("-h", content.image_url, ref expectedHeight); if ((content.theme_filter == "dark" && theme.IsDarkTheme) || (content.theme_filter == "light" && !theme.IsDarkTheme) || (content.theme_filter == "all")) { var image = new ImageBuffer(expectedWidth, expectedHeight); var imageWidget = new ResponsiveImageWidget(image) { Margin = new BorderDouble(5), Cursor = Cursors.Hand }; if (content.link != null) { imageWidget.Cursor = Cursors.Hand; imageWidget.Click += (s, e) => { if (e.Button == MouseButtons.Left) { ApplicationController.Instance.LaunchBrowser(content.link); } }; } imageWidget.Load += (s, e) => WebCache.RetrieveImageAsync(image, content.image_url, false, new BlenderPreMultBGRA()); this.AddChild(imageWidget); } } break; case "article_group": case "product_group": if (currentContentContainer == null) { currentContentContainer = new FlowLeftRightWithWrapping(); this.AddChild(currentContentContainer); } currentContentContainer.AddChild(new ExploreSection(content, theme)); break; } }
private void AddContentItem(ThemeConfig theme, FeedSectionData content) { switch (content.content_type) { case "headline": /* * { * // use the Golden Ratio to calculate an attractive size relative to the banner * var image = new ImageBuffer(1520, (int)(170 / 1.618)); * var imageWidget = new ResponsiveImageWidget(image) * { * Margin = new BorderDouble(5), * Cursor = Cursors.Hand * }; * * var graphics2D = image.NewGraphics2D(); * image.SetRecieveBlender(new BlenderPreMultBGRA()); * graphics2D.Clear(theme.AccentMimimalOverlay); * * // use the Golden Ratio to calculate an attractive size for the text relative to the text banner * var pixelsPerPoint = 96.0 / 72.0; * var goalPointSize = image.Height / pixelsPerPoint / 1.618; * * var printer = new TypeFacePrinter(content.text, goalPointSize); * * graphics2D.DrawString(content.text, image.Width/2, image.Height/2 + printer.TypeFaceStyle.EmSizeInPixels / 2, goalPointSize, * Justification.Center, Baseline.BoundsTop, * theme.TextColor); * * if (content.link != null) * { * imageWidget.Cursor = Cursors.Hand; * imageWidget.Click += (s, e) => * { * if (e.Button == MouseButtons.Left) * { * ApplicationController.LaunchBrowser(content.link); * } * }; * } * * container.Add(imageWidget); * } */ break; case "banner_rotate": // TODO: make this make a carousel rather than add the first item and rotate between all the items var rand = new Random(); AddContentItem(theme, content.banner_list[rand.Next(content.banner_list.Count)]); break; case "banner_image": { // Our banners seem to end with something like "=w1520-h170" // if present use that to get the right width and height int expectedWidth = 1520; GCodeFile.GetFirstNumberAfter("=w", content.image_url, ref expectedWidth); int expectedHeight = 170; GCodeFile.GetFirstNumberAfter("-h", content.image_url, ref expectedHeight); if ((content.theme_filter == "dark" && theme.IsDarkTheme) || (content.theme_filter == "light" && !theme.IsDarkTheme) || (content.theme_filter == "all")) { var image = new ImageBuffer(expectedWidth, expectedHeight); var imageWidget = new ResponsiveImageWidget(image) { Margin = new BorderDouble(5), Cursor = Cursors.Hand }; if (content.link != null) { imageWidget.Cursor = Cursors.Hand; imageWidget.Click += (s, e) => { if (e.Button == MouseButtons.Left) { ApplicationController.LaunchBrowser(content.link); } }; } AfterDraw += (s, e) => { if (!loaded) { loaded = true; WebCache.RetrieveImageAsync(image, content.image_url, false); } }; topBanner.AddChild(imageWidget); } } break; case "article_group": { // add the article group button to the button group // add a content section connected to the button var sectionButton = new TextButton(content.group_title, theme); sectionSelectButtons.AddChild(sectionButton); var articleSection = new ArticleSection(content, theme) { Visible = false, Name = content.group_title }; contentSection.AddChild(articleSection); sectionButton.Click += (s, e) => { foreach (var contentWidget in contentSection.Children) { contentWidget.Visible = contentWidget == articleSection; } }; } break; case "product_group": { var sectionButton = new TextButton(content.group_title, theme); sectionSelectButtons.AddChild(sectionButton); var exploreSection = new ProductSection(content, theme) { Name = content.group_title }; contentSection.AddChild(exploreSection); sectionButton.Click += (s, e) => { foreach (var contentWidget in contentSection.Children) { contentWidget.Visible = contentWidget == exploreSection; } }; } break; } }