示例#1
0
        public ExploreItem(FeedItemData item, ThemeConfig theme)
        {
            this.HAnchor = HAnchor.Absolute;
            this.Width   = 400 * GuiWidget.DeviceScale;
            //this.Border = spacing;
            this.Padding = ItemSpacing;
            this.item    = item;
            this.theme   = theme;

            var image = new ImageBuffer(IconSize, IconSize);

            if (item.icon != null)
            {
                var imageWidget = new ImageWidget(image)
                {
                    Selectable = false,
                    VAnchor    = VAnchor.Top,
                    Margin     = new BorderDouble(right: ItemSpacing)
                };

                imageWidget.Load += (s, e) => WebCache.RetrieveImageAsync(image, item.icon, true, new BlenderPreMultBGRA());
                this.AddChild(imageWidget);
            }
            else if (item.widget_url != null)
            {
                var whiteBackground = new GuiWidget(IconSize, IconSize)
                {
                    // these images expect to be on white so change the background to white
                    BackgroundColor = Color.White,
                    Margin          = new BorderDouble(right: ItemSpacing)
                };
                this.AddChild(whiteBackground);

                var imageWidget = new ImageWidget(image)
                {
                    Selectable = false,
                    VAnchor    = VAnchor.Center,
                };

                imageWidget.Load += (s, e) => WebCache.RetrieveImageAsync(image, item.widget_url, true, new BlenderPreMultBGRA());
                whiteBackground.AddChild(imageWidget);
            }

            var wrappedText = new WrappedTextWidget(item.title, textColor: theme.TextColor, pointSize: theme.DefaultFontSize)
            {
                Selectable = false,
                VAnchor    = VAnchor.Center | VAnchor.Fit,
                Margin     = 3
            };

            this.AddChild(wrappedText);
            wrappedText.Load += (s, e) =>
            {
                wrappedText.VAnchor = VAnchor.Top | VAnchor.Fit;
            };

            this.Cursor = Cursors.Hand;
        }
示例#2
0
        public ImageBuffer GetIcon(string oemName)
        {
            var imageBuffer = new ImageBuffer(16, 16);

            WebCache.RetrieveImageAsync(
                imageBuffer,
                ApplicationController.Instance.GetFavIconUrl(oemName),
                scaleToImageX: false);

            return(imageBuffer);
        }
示例#3
0
        public ImageBuffer GetIcon(string oemName)
        {
            var imageBuffer = new ImageBuffer(16, 16);

            string oemUrl = ApplicationController.Instance.GetFavIconUrl(oemName);

            if (!string.IsNullOrWhiteSpace(oemUrl))
            {
                WebCache.RetrieveImageAsync(imageBuffer, oemUrl, scaleToImageX: false);
            }
            else
            {
                var graphics = imageBuffer.NewGraphics2D();
                graphics.Clear(AppContext.Theme.SlightShade);
            }

            return(imageBuffer);
        }
示例#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;
            }
        }
示例#5
0
        public override async void OnLoad(EventArgs args)
        {
            if (string.IsNullOrEmpty(this.StoreID) &&
                File.Exists(printerInfo.ProfilePath))
            {
                // load up the printer profile so we can get the MatterHackers Skew-ID out of it
                var printerSettings = PrinterSettings.LoadFile(printerInfo.ProfilePath);

                // Use the make-model mapping table
                if (OemSettings.Instance.OemPrinters.TryGetValue($"{printerInfo.Make}-{ printerInfo.Model}", out StorePrinterID storePrinterID))
                {
                    this.StoreID = storePrinterID?.SID;
                }
            }

            if (!string.IsNullOrWhiteSpace(StoreID))
            {
                try
                {
                    // put in controls from the feed that show relevant printer information
                    WebCache.RetrieveText($"https://mh-pls-prod.appspot.com/p/1/product-sid/{StoreID}?IncludeListingData=True",
                                          (json) =>
                    {
                        UiThread.RunOnIdle(() =>
                        {
                            var result = JsonConvert.DeserializeObject <ProductSidData>(json);
                            productDataContainer.RemoveChildren();

                            foreach (var addOn in result.ProductSku.ProductListing.AddOns)
                            {
                                WebCache.RetrieveText($"https://mh-pls-prod.appspot.com/p/1/product-sid/{addOn.AddOnSkuReference}?IncludeListingData=True",
                                                      (addOnJson) =>
                                {
                                    var addOnResult = JsonConvert.DeserializeObject <ProductSidData>(addOnJson);

                                    var icon = new ImageBuffer(80, 0);

                                    if (addOnResult?.ProductSku?.FeaturedImage?.ImageUrl != null)
                                    {
                                        WebCache.RetrieveImageAsync(icon, addOnResult.ProductSku.FeaturedImage.ImageUrl, scaleToImageX: true);
                                    }

                                    addOn.Icon = icon;
                                });
                            }

                            CreateProductDataWidgets(result.ProductSku);
                        });
                    });
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Error collecting or loading printer details: " + ex.Message);
                }

                // add a section to hold the data about the printer
                this.AddChild(productDataContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    HAnchor = HAnchor.Stretch
                });
            }

            headingRow.Visible = this.ShowHeadingRow;

            base.OnLoad(args);
        }
示例#6
0
        //private void CreateProductDataWidgets(PrinterSettings printerSettings, ProductSkuData product)
        private void CreateProductDataWidgets(ProductSkuData product)
        {
            var row = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                Margin  = new BorderDouble(top: theme.DefaultContainerPadding)
            };

            productDataContainer.AddChild(row);

            var image = new ImageBuffer(150, 10);

            row.AddChild(new ImageWidget(image)
            {
                Margin  = new BorderDouble(right: theme.DefaultContainerPadding),
                VAnchor = VAnchor.Top
            });

            WebCache.RetrieveImageAsync(image, product.FeaturedImage.ImageUrl, scaleToImageX: true);

            var descriptionBackground = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit | VAnchor.Top,
                Padding = theme.DefaultContainerPadding
            };

            var description = new MarkdownWidget(theme)
            {
                MinimumSize = new VectorMath.Vector2(50, 0),
                HAnchor     = HAnchor.Stretch,
                VAnchor     = VAnchor.Fit,
                AutoScroll  = false,
                Markdown    = product.ProductDescription.Trim()
            };

            descriptionBackground.AddChild(description);
            descriptionBackground.BeforeDraw += (s, e) =>
            {
                var rect = new RoundedRect(descriptionBackground.LocalBounds, 3);
                e.Graphics2D.Render(rect, theme.SlightShade);
            };

            row.AddChild(descriptionBackground);

            if (this.ShowProducts)
            {
                var padding = theme.DefaultContainerPadding;

                var addonsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Padding = new BorderDouble(padding, padding, padding, 0),
                    HAnchor = HAnchor.Stretch
                };

                var addonsSection = new SectionWidget("Upgrades and Accessories", addonsColumn, theme);
                productDataContainer.AddChild(addonsSection);
                theme.ApplyBoxStyle(addonsSection);
                addonsSection.Margin = addonsSection.Margin.Clone(left: 0);

                foreach (var item in product.ProductListing.AddOns)
                {
                    var addOnRow = new AddOnRow(item.AddOnTitle, theme, null, item.Icon)
                    {
                        HAnchor = HAnchor.Stretch,
                        Cursor  = Cursors.Hand
                    };

                    foreach (var child in addOnRow.Children)
                    {
                        child.Selectable = false;
                    }

                    addOnRow.Click += (s, e) =>
                    {
                        ApplicationController.LaunchBrowser($"https://www.matterhackers.com/store/l/{item.AddOnListingReference}/sk/{item.AddOnSkuReference}");
                    };

                    addonsColumn.AddChild(addOnRow);
                }
            }

            //if (false)
            //{
            //	var settingsPanel = new GuiWidget()
            //	{
            //		HAnchor = HAnchor.Stretch,
            //		VAnchor = VAnchor.Stretch,
            //		MinimumSize = new VectorMath.Vector2(20, 20),
            //		DebugShowBounds = true
            //	};

            //	settingsPanel.Load += (s, e) =>
            //	{
            //		var printer = new PrinterConfig(printerSettings);

            //		var settingsContext = new SettingsContext(
            //			printer,
            //			null,
            //			NamedSettingsLayers.All);

            //		settingsPanel.AddChild(
            //			new ConfigurePrinterWidget(settingsContext, printer, theme)
            //			{
            //				HAnchor = HAnchor.Stretch,
            //				VAnchor = VAnchor.Stretch,
            //			});
            //	};

            //	this.AddChild(new SectionWidget("Settings", settingsPanel, theme, expanded: false, setContentVAnchor: false)
            //	{
            //		VAnchor = VAnchor.Stretch
            //	});
            //}
        }
示例#7
0
        public ProductItem(FeedItemData item, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.Padding = ItemSpacing;
            this.item    = item;
            this.theme   = theme;

            var image = new ImageBuffer(IconSize, IconSize);

            image.SetRecieveBlender(new BlenderPreMultBGRA());
            BackgroundRadius = 5 * GuiWidget.DeviceScale;

            if (item.widget_url != null)
            {
                var whiteBackground = new GuiWidget(IconSize, IconSize)
                {
                    // these images expect to be on white so change the background to white
                    BackgroundColor  = Color.White,
                    BackgroundRadius = 5 * GuiWidget.DeviceScale,
                    Margin           = new BorderDouble(3, 0, 3, 3),
                    Selectable       = false
                };
                this.AddChild(whiteBackground);

                var imageWidget = new ImageWidget(image)
                {
                    Selectable = false,
                    VAnchor    = VAnchor.Center,
                };

                Load += (s, e) => WebCache.RetrieveImageAsync(image, item.widget_url, true);
                whiteBackground.AddChild(imageWidget);
            }

            var titleText = new FlowLeftRightWithWrapping()
            {
                Selectable = false,
                VAnchor    = VAnchor.Fit,
                HAnchor    = HAnchor.Stretch,
                Margin     = new BorderDouble(3, 3, 3, 9),
                Center     = true
            };

            titleText.AddText(item.title, textColor: theme.TextColor, pointSize: theme.FontSize14);

            this.AddChild(titleText);

            var descriptionText = new FlowLeftRightWithWrapping()
            {
                Selectable = false,
                VAnchor    = VAnchor.Fit,
                HAnchor    = HAnchor.Stretch,
                Margin     = 3,
                Center     = true
            };

            descriptionText.AddText(item.subtitle, textColor: theme.TextColor.WithAlpha(.7), pointSize: theme.FontSize8);

            this.AddChild(descriptionText);

            this.Cursor = Cursors.Hand;

            this.VAnchor = VAnchor.Fit | VAnchor.Top;
        }
示例#8
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;
            }
        }