private async Task InitializeAsync()
        {
            lineDisplay = await rootPage.ClaimScenarioLineDisplayAsync();

            if (lineDisplay != null)
            {
                Size screenSize  = lineDisplay.GetAttributes().ScreenSizeInCharacters;
                int  windowCount = 1;

                if (lineDisplay.Capabilities.IsHorizontalMarqueeSupported && (windowCount < lineDisplay.Capabilities.SupportedWindows))
                {
                    // Create a horizontal scrollable window by creating a window
                    // whose width is wider than the viewport.
                    horizontalScrollableWindow = await lineDisplay.TryCreateWindowAsync(
                        new Rect()
                    {
                        X      = 0,
                        Y      = 0,
                        Width  = screenSize.Width,
                        Height = screenSize.Height
                    },
                        new Size()
                    {
                        Width  = screenSize.Width * 2,
                        Height = screenSize.Height
                    });

                    if (horizontalScrollableWindow != null)
                    {
                        windowCount++;
                        ScrollDirectionComboBox.Items.Add(LineDisplayScrollDirection.Left);
                        ScrollDirectionComboBox.Items.Add(LineDisplayScrollDirection.Right);
                    }
                }

                if (lineDisplay.Capabilities.IsVerticalMarqueeSupported && (windowCount < lineDisplay.Capabilities.SupportedWindows))
                {
                    // Create a vertical scrollable window by creating a window
                    // whose height is taller than the viewport.
                    verticalScrollableWindow = await lineDisplay.TryCreateWindowAsync(
                        new Rect()
                    {
                        X      = 0,
                        Y      = 0,
                        Width  = screenSize.Width,
                        Height = screenSize.Height
                    },
                        new Size()
                    {
                        Width  = screenSize.Width,
                        Height = screenSize.Height * 2
                    });

                    if (verticalScrollableWindow != null)
                    {
                        windowCount++;
                        ScrollDirectionComboBox.Items.Add(LineDisplayScrollDirection.Up);
                        ScrollDirectionComboBox.Items.Add(LineDisplayScrollDirection.Down);
                    }
                }
            }

            if (ScrollDirectionComboBox.Items.Count > 0)
            {
                ScrollDirectionComboBox.SelectedIndex = 0;
                StartScrollingButton.IsEnabled        = true;
                StopScrollingButton.IsEnabled         = true;
            }
        }
Example #2
0
        private async void NewWindowButton_Click(object sender, RoutedEventArgs e)
        {
            rootPage.NotifyUser("", NotifyType.StatusMessage);

            Rect viewportBounds = new Rect()
            {
                X      = Helpers.ParseUIntWithFallback(NewViewportX, -1.0),
                Y      = Helpers.ParseUIntWithFallback(NewViewportY, -1.0),
                Width  = Helpers.ParseUIntWithFallback(NewViewportWidth, 0.0),
                Height = Helpers.ParseUIntWithFallback(NewViewportHeight, 0.0),
            };

            if ((viewportBounds.Width <= 0) || (viewportBounds.Height <= 0))
            {
                rootPage.NotifyUser("Viewport size must be be positive.", NotifyType.ErrorMessage);
                return;
            }

            // Viewport cannot extend beyond the screen.
            Size screenSizeInCharacters = lineDisplay.GetAttributes().ScreenSizeInCharacters;

            if ((viewportBounds.X < 0) || (viewportBounds.Y < 0) ||
                (viewportBounds.X + viewportBounds.Width > screenSizeInCharacters.Width) ||
                (viewportBounds.Y + viewportBounds.Height > screenSizeInCharacters.Height))
            {
                rootPage.NotifyUser("Viewport cannot extend beyond the screen.", NotifyType.ErrorMessage);
                return;
            }

            Size windowSize = new Size()
            {
                Width  = Helpers.ParseUIntWithFallback(NewWindowWidth, 0.0),
                Height = Helpers.ParseUIntWithFallback(NewWindowHeight, 0.0),
            };

            if ((windowSize.Width <= 0) || (windowSize.Height <= 0))
            {
                rootPage.NotifyUser("Window size must be be positive.", NotifyType.ErrorMessage);
                return;
            }

            // Windows must be at least as large as their viewports.
            if ((viewportBounds.Width > windowSize.Width) || (viewportBounds.Height > windowSize.Height))
            {
                rootPage.NotifyUser("Window must be at least as large as viewport.", NotifyType.ErrorMessage);
                return;
            }

            // Window taller than viewport requires IsVerticalMarqueeSupported.
            if ((windowSize.Height > viewportBounds.Height) && !lineDisplay.Capabilities.IsVerticalMarqueeSupported)
            {
                rootPage.NotifyUser("Window cannot be taller than viewport on this line display.", NotifyType.ErrorMessage);
                return;
            }

            // Window wider than viewport requires IsHorizontalMarqueeSupported.
            if ((windowSize.Width > viewportBounds.Width) && !lineDisplay.Capabilities.IsHorizontalMarqueeSupported)
            {
                rootPage.NotifyUser("Window cannot be wider than viewport on this line display.", NotifyType.ErrorMessage);
                return;
            }

            // Window cannot be larger than viewport in both directions.
            // (Two-dimensional scrolling is not supported.)
            if ((windowSize.Width > viewportBounds.Width) && (windowSize.Height > viewportBounds.Height))
            {
                rootPage.NotifyUser("Window cannot be larger than viewport in both dimensions.", NotifyType.ErrorMessage);
                return;
            }

            LineDisplayWindow newWindow = await lineDisplay.TryCreateWindowAsync(viewportBounds, windowSize);

            if (newWindow != null)
            {
                var newWindowInfo = new WindowInfo(newWindow, nextWindowId);
                WindowList.Add(newWindowInfo);
                nextWindowId++;

                rootPage.NotifyUser($"Created window {newWindowInfo.Id}.", NotifyType.StatusMessage);
            }
            else
            {
                // We probably lost our claim.
                rootPage.NotifyUser("Failed to create a new window", NotifyType.ErrorMessage);
            }
        }