Exemplo n.º 1
0
        public ProductSection(FeedSectionData content, ThemeConfig theme)
        {
            Proportional = true;
            VAnchor      = VAnchor.Fit | VAnchor.Top;
            this.content = content;
            this.theme   = theme;

            foreach (var item in content.group_items)
            {
                allIconViews.Add(new ProductItem(item, theme)
                {
                    //BackgroundColor = theme.MinimalShade,
                });
            }

            AddContent();
        }
Exemplo n.º 2
0
        public ExploreSection(FeedSectionData content, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            VAnchor      = VAnchor.Fit | VAnchor.Top;
            this.content = content;
            this.theme   = theme;

            foreach (var item in content.group_items)
            {
                allIconViews.Add(new ExploreItem(item, theme)
                {
                    BackgroundColor = theme.MinimalShade,
                    VAnchor         = VAnchor.Fit,
                });
            }

            AddContent();
        }
Exemplo n.º 3
0
        public ArticleSection(FeedSectionData content, ThemeConfig theme)
        {
            Proportional = true;
            VAnchor      = VAnchor.Fit | VAnchor.Top;
            this.content = content;
            this.theme   = theme;

            var cultureInfo = new CultureInfo("en-US");

            foreach (var item in content.group_items.OrderByDescending(i => DateTime.Parse(i.date_published, cultureInfo)))
            {
                allIconViews.Add(new ArticleItem(item, theme)
                {
                    BackgroundColor = theme.MinimalShade,
                    VAnchor         = VAnchor.Fit,
                });
            }

            AddContent();
        }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        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;
            }
        }