Example #1
0
        public Window CreateWindow()
        {
            // Create a window object and set its size to the
            // size of the display.
            mainWindow = new Window();
            mainWindow.Height = SystemMetrics.ScreenHeight;
            mainWindow.Width = SystemMetrics.ScreenWidth;

            Font font = Resources.GetFont(Resources.FontResources.NinaB);
            Font smallFont = Resources.GetFont(Resources.FontResources.small);

            TextFlow textFlow = new TextFlow();
            textFlow.TextRuns.Add("Hello world.", font, Colors.Black);
            textFlow.TextRuns.Add(" Hello world.", smallFont, Colors.Red);
            textFlow.TextRuns.Add(TextRun.EndOfLine);
            textFlow.TextRuns.Add("Hello world.", font, Colors.Green);

            // Add the text flow to the window.
            mainWindow.Child = textFlow;

            // Set the window visibility to visible.
            mainWindow.Visibility = Visibility.Visible;

            return mainWindow;
        }
        public ConsoleUi(string windowTitle)
        {
            var panel = new StackPanel();

            _timeText = new Text(_arial14, windowTitle)
                            {
                                TextAlignment = TextAlignment.Right,
                                VerticalAlignment = VerticalAlignment.Top,
                                ForeColor = ColorUtility.ColorFromRGB(255, 255, 0)
                            };

            panel.Children.Add(_timeText);

            var scroll = new ScrollViewer
                             {
                                 Height = SystemMetrics.ScreenHeight - _arial14.Height,
                                 Width = SystemMetrics.ScreenWidth,
                                 ScrollingStyle = ScrollingStyle.Last,
                                 Background = null,
                                 LineHeight = _small.Height
                             };

            panel.Children.Add(scroll);

            _log = new TextFlow
                       {
                           HorizontalAlignment = HorizontalAlignment.Left,
                           VerticalAlignment = VerticalAlignment.Top
                       };

            scroll.Child = _log;

            Background = _solidBlack;
            Child = panel;
        }
Example #3
0
        public Window CreateWindow()
        {
            // Create a window object and set its size to the
            // size of the display.
            mainWindow = new Window();
            mainWindow.Height = SystemMetrics.ScreenHeight;
            mainWindow.Width = SystemMetrics.ScreenWidth;

            Font normalFont = Resources.GetFont(Resources.FontResources.NinaB);
            Font smallFont = Resources.GetFont(Resources.FontResources.small);

            TextFlow textFlow = new TextFlow();
            // set the scrolling style to LineByLine or PageByPage
            textFlow.ScrollingStyle = ScrollingStyle.LineByLine;
            // Add text
            Color[] colors = new Color[] { Colors.Black, Colors.Gray,
                                           Colors.Red, Colors.Green, Colors.Blue};
            for (int i = 0; i < 100; ++i)
            {
                Font font = (i % 2 == 0) ? normalFont : smallFont;
                Color color = colors[i % colors.Length];
                textFlow.TextRuns.Add("Hello world. ", font, color);
                if (i % 2 == 0)
                    textFlow.TextRuns.Add(TextRun.EndOfLine);
            }

            // Add the text flow to the window.
            mainWindow.Child = textFlow;

            // Set the window visibility to visible.
            mainWindow.Visibility = Visibility.Visible;

            // Let the user scroll the text with buttons
            Buttons.Focus(textFlow);

            return mainWindow;
        }
        /// <summary>
        /// Creates all WPF controls of the window
        /// </summary>
        private void InitializeComponents()
        {
            this.Width = SystemMetrics.ScreenWidth;
            this.Height = SystemMetrics.ScreenHeight;
            this.Background = new SolidColorBrush(Colors.Black);

            #region Caption
            Text caption = new Text(Resources.GetString(Resources.StringResources.HighScore));
            caption.Font = Resources.GetFont(Resources.FontResources.Consolas23);
            caption.ForeColor = Colors.Red;
            caption.SetMargin(0, 10, 0, 15);
            caption.TextAlignment = TextAlignment.Center;
            #endregion

            #region Score ListBox
            scoreListBox = new ListBox();
            scoreListBox.Background = this.Background;
            scoreListBox.HorizontalAlignment = HorizontalAlignment.Center;

            foreach (ScoreRecord scoreRecord in parentApp.HighScore.Table)
            {
                ScoreItem scoreItem = new ScoreItem(scoreRecord.Name, scoreRecord.Score);
                scoreItem.Background = scoreListBox.Background;
                scoreListBox.Items.Add(scoreItem);
            }
            #endregion

            #region HintLabel
            hintTextFlow = new TextFlow();
            hintTextFlow.SetMargin(0, 15, 0, 0);
            hintTextFlow.TextAlignment = TextAlignment.Center;
            UpdateHint();
            #endregion

            StackPanel mainStack = new StackPanel(Orientation.Vertical);
            mainStack.HorizontalAlignment = HorizontalAlignment.Center;
            mainStack.Children.Add(caption);
            mainStack.Children.Add(scoreListBox);
            mainStack.Children.Add(hintTextFlow);

            this.Child = mainStack;

            this.Visibility = Visibility.Visible;
            Buttons.Focus(this);
        }
 internal TextRunCollection(TextFlow textFlow)
 {
     this._textFlow = textFlow;
     _textRuns = new ArrayList();
 }
        object TextFlow_UpdateWindow(object obj)
        {
            txtFlow = new TextFlow();
            if (_txtRun)
            {
                txtFlow.TextRuns.Add(tr1);
                txtFlow.TextRuns.Add("1st Text", _font, _color);
                txtFlow.TextRuns.Add(tr1);
            }

            if (_lineCount)
            {
                txtFlow.TextRuns.Add(_longStr, _font, _color);
                txtFlow.TextRuns.Add(TextRun.EndOfLine);
                for (int i = 0; i < count; i++)
                {
                    txtFlow.TextRuns.Add("Text " + i, _font, _color);
                    txtFlow.TextRuns.Add(TextRun.EndOfLine);
                }
            }

            trc = txtFlow.TextRuns;
            txtFlow.ScrollingStyle = _style;
            _getStyle = txtFlow.ScrollingStyle;
            mainWindow.Child = txtFlow;

            return obj;
        }
Example #7
0
        /// <summary>
        /// Creates the main window.
        /// </summary>
        /// <returns>The main window.</returns>
        public Window CreateWindow()
        {
            // Create a window object and set its size to the size of the 
            // display.
            mainWindow = new Window();
            mainWindow.Width = SystemMetrics.ScreenWidth;
            mainWindow.Height = SystemMetrics.ScreenHeight;

            // Detect landscape or portrait so the program can adjust its 
            // layout.
            bool portrait =
                SystemMetrics.ScreenWidth < SystemMetrics.ScreenHeight;

            // Create the main stack panel.
            StackPanel stack = new StackPanel(portrait ?
                Orientation.Vertical : Orientation.Horizontal);

            // Create stack panels for the current temperature and target 
            // temperature.
            StackPanel stack1 = new StackPanel(Orientation.Vertical);
            StackPanel stack2 = new StackPanel(Orientation.Vertical);

            // Create border panels for the current temperature and target 
            // temperature.
            BorderPanel panel1;
            BorderPanel panel2;

            // Detect portrait or landscape orientation.
            if (portrait)
            {

                // If in portrait mode, set the width to the screen width and 
                // height to 1/4 and 3/4.
                panel1 = new BorderPanel(SystemMetrics.ScreenWidth,
                    (int)(SystemMetrics.ScreenHeight * .25));
                panel2 = new BorderPanel(SystemMetrics.ScreenWidth,
                    (int)(SystemMetrics.ScreenHeight * .75));
            }
            else
            {
                // Otherwise, set the width and height to 1/2 and 1/2, 
                // respectively.
                panel1 = new BorderPanel(SystemMetrics.ScreenWidth / 2,
                    SystemMetrics.ScreenHeight);
                panel2 = new BorderPanel(SystemMetrics.ScreenWidth / 2,
                    SystemMetrics.ScreenHeight);
            }

            // Add the border panels to the panels containing the current 
            // temperature and target temperature.
            panel1.Children.Add(stack1);
            panel2.Children.Add(stack2);

            // Add the stack panels to the border panels.
            stack.Children.Add(panel1);
            stack.Children.Add(panel2);

            // Create text controls for the current temperature.
            _textCurrentTemp = new Text();
            _textCurrentTemp.Font =
                Resources.GetFont(Resources.FontResources.nina48);
            _textCurrentTemp.TextContent =
                Resources.GetString(Resources.StringResources.InitialTemp);
            _textCurrentTemp.HorizontalAlignment =
                Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            _textCurrentTemp.VerticalAlignment =
                Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            Text currentLabel = new Text();
            currentLabel.Font =
                Resources.GetFont(Resources.FontResources.nina14);
            currentLabel.TextContent =
                Resources.GetString(Resources.StringResources.CurrentTemp);
            currentLabel.HorizontalAlignment =
                Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            currentLabel.VerticalAlignment =
                Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            // Add the text controls to the current temperature stack panel.
            stack1.Children.Add(currentLabel);
            stack1.Children.Add(_textCurrentTemp);

            // Create controls for the target temperature.
            _textTargetTemp = new Text();
            _textTargetTemp.Font =
                Resources.GetFont(Resources.FontResources.nina48);
            _textTargetTemp.TextContent =
                Resources.GetString(Resources.StringResources.InitialTemp);
            _textTargetTemp.HorizontalAlignment =
                HorizontalAlignment.Center;
            _textTargetTemp.VerticalAlignment =
                VerticalAlignment.Center;

            Text targetLabel = new Text();
            targetLabel.Font =
                Resources.GetFont(Resources.FontResources.nina14);
            targetLabel.TextContent =
                Resources.GetString(Resources.StringResources.TargetTemp);
            targetLabel.HorizontalAlignment = HorizontalAlignment.Center;
            targetLabel.VerticalAlignment = VerticalAlignment.Center;

            // Create the air conditioner or heater status indicator.
            _statusIndicator = new StatusIndicator();

            // Add the controls to the target temperature stack panel.
            stack2.Children.Add(targetLabel);
            stack2.Children.Add(_textTargetTemp);
            stack2.Children.Add(_statusIndicator);

            // Add instructions to the target temperature stack panel.
            TextFlow instructions = new TextFlow();
            instructions.HorizontalAlignment = HorizontalAlignment.Center;
            instructions.VerticalAlignment = VerticalAlignment.Center;
            instructions.TextAlignment = TextAlignment.Center;
            instructions.TextRuns.Add(new TextRun("Up Button to Increase",
                Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            instructions.TextRuns.Add(TextRun.EndOfLine);
            instructions.TextRuns.Add(new TextRun("Down Button to Decrease",
                Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            instructions.TextRuns.Add(TextRun.EndOfLine);
            instructions.TextRuns.Add(new TextRun(
                "Select Button to Toggle Celsius / Fahrenheit",
                Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            stack2.Children.Add(instructions);

            // Set the main window child to the main horizontal stack panel.
            mainWindow.Child = stack;

            // Connect the button handler to all of the buttons.
            mainWindow.AddHandler(Buttons.ButtonUpEvent,
                new RoutedEventHandler(OnButtonUp), false);

            // Set the window visibility to Visible.
            mainWindow.Visibility = Visibility.Visible;

            // Attach the button focus to the window.
            Buttons.Focus(mainWindow);

            // Create the timer that will check the current temperature.
            _timer = new DispatcherTimer(mainWindow.Dispatcher);
            _timer.Interval = new TimeSpan(0, 0, 0, 0, 50);
            _timer.Tick += new EventHandler(OnTimer);
            _timer.Start();

            return mainWindow;
        }
Example #8
0
        public Window CreateWindow()
        {
            // Create a window object and set its size to the
            // size of the display.
            mainWindow = new Window();
            mainWindow.Height = SystemMetrics.ScreenHeight;
            mainWindow.Width = SystemMetrics.ScreenWidth;
            // Add a gradient color background to the window
            mainWindow.Background = new LinearGradientBrush(Colors.White, Colors.Red,
                                                            0, 0,
                                                            mainWindow.Width, mainWindow.Height);

            Font normalFont = Resources.GetFont(Resources.FontResources.NinaB);
            Font smallFont = Resources.GetFont(Resources.FontResources.small);

            // Create a list box control and add text items
            ListBox listBox = new ListBox();
            // set the width so that it fills the entire screen
            listBox.Child.Width = mainWindow.Width;
            // make the list box transparent
            listBox.Background = null;
            // make the enclosed scroll viewer transparent also
            // we get the scroll viewer via the child property but
            // need to cast it to Control in order to clear the background
            ((Control)listBox.Child).Background = null;

            // Add simple text items
            for (int i = 0; i < 2; ++i)
            {
                string str = "Simple text item";
                Text text = new Text(normalFont, str);
                text.SetMargin(2);
                ListBoxItem item = new HighlightableListBoxItem(text);
                listBox.Items.Add(item);
            }

            // Add a separator
            listBox.Items.Add(new SeparatorListBoxItem());

            // Add a text item with icon
            {
                // Create the stack panel to align the elements
                StackPanel stackPanel = new StackPanel(Orientation.Horizontal);

                // Icon
                Bitmap bmp = Resources.GetBitmap(Resources.BitmapResources.Clock);
                // Make the bitmap transparent using
                // the color of the top left corner pixel.
                // Therefore the image should not be in the Bitmap and Jpeg format
                // because that requires to create a copy in order to make it
                // transparent. Use Gif instead.
                bmp.MakeTransparent(bmp.GetPixel(0, 0));
                Image image = new Image(bmp);
                image.SetMargin(2); // set a margin to separate the image
                // vertically center the icon within the item
                image.VerticalAlignment = VerticalAlignment.Center;
                stackPanel.Children.Add(image);

                // Text
                Text text = new Text(normalFont, "Item with a icon and text");
                text.SetMargin(2); // set margin to separate the text
                // vertically center the icon within the item
                text.VerticalAlignment = VerticalAlignment.Center;
                stackPanel.Children.Add(text);

                // Create a highlightable list box item
                ListBoxItem item = new HighlightableListBoxItem(stackPanel);
                listBox.Items.Add(item);
            }

            // Add a separator
            listBox.Items.Add(new SeparatorListBoxItem());

            // Add two items with multiple columns
            // use i to add a right aligned number to the first column
            for (int i = 0; i <= 100; i += 50)
            {
                //create the stack panel to align the elements
                StackPanel stackPanel = new StackPanel(Orientation.Horizontal);

                // Add right aligned text
                Text text1 = new Text(normalFont, i.ToString());
                text1.Width = 30;
                text1.SetMargin(2); // set margin to separate the text
                text1.TextAlignment = TextAlignment.Right;
                // vertically center the icon within the item
                text1.VerticalAlignment = VerticalAlignment.Center;
                stackPanel.Children.Add(text1);

                // Icon
                Bitmap bmp = Resources.GetBitmap(Resources.BitmapResources.Audio);
                // Make the bitmap transparent using
                // the color of the top left corner pixel.
                // Therefore the image should not be in the Bitmap and Jpeg format
                // because that requires to create a copy in order to make it
                // transparent. Use Gif instead.
                bmp.MakeTransparent(bmp.GetPixel(0, 0));
                Image image = new Image(bmp);
                image.SetMargin(2); // set a margin to separate the image
                // vertically center the icon within the item
                image.VerticalAlignment = VerticalAlignment.Center;
                stackPanel.Children.Add(image);

                // Text
                Text text = new Text(normalFont, "Item with multiple columns");
                text.SetMargin(2); // set margin to separate the text
                // vertically center the icon within the item
                text.VerticalAlignment = VerticalAlignment.Center;
                stackPanel.Children.Add(text);

                // Create a highlightable list box item
                ListBoxItem item = new HighlightableListBoxItem(stackPanel);
                listBox.Items.Add(item);
            }

            // Add a separator
            listBox.Items.Add(new SeparatorListBoxItem());

            // Add two multi line text item
            for (int i = 0; i < 2; ++i)
            {
                TextFlow textFlow = new TextFlow();
                textFlow.TextRuns.Add("This is the first line.", normalFont, Colors.Black);
                textFlow.TextRuns.Add(TextRun.EndOfLine);
                textFlow.TextRuns.Add("Second line.", normalFont, Colors.Green);
                textFlow.TextRuns.Add(TextRun.EndOfLine);
                textFlow.TextRuns.Add("Third line.", smallFont, Colors.Red);
                textFlow.SetMargin(2);

                ListBoxItem item = new HighlightableListBoxItem(textFlow);
                listBox.Items.Add(item);
            }

            // Add the text control to the window.
            mainWindow.Child = listBox;

            // Set the window visibility to visible.
            mainWindow.Visibility = Visibility.Visible;

            // Let the user select items with the up and down buttons.
            Buttons.Focus(listBox);
            // Get notified when the selected item was changed.
            listBox.SelectionChanged += new SelectionChangedEventHandler(listBox_SelectionChanged);
            // Get notified when a selected item was pressed
            // using the select button.
            listBox.AddHandler(Buttons.ButtonDownEvent, new ButtonEventHandler(listBox_ButtonDown), false);

            return mainWindow;
        }
Example #9
0
 internal TextRunCollection(TextFlow textFlow)
 {
     this._textFlow = textFlow;
     _textRuns      = new ArrayList();
 }
Example #10
0
        public Window CreateUI()
        {

            Window      window       = new Window();
            StackPanel  panel        = new StackPanel();
            panel.Orientation        = Orientation.Vertical;

            Text   text         = new Text();
            text.Font           = Resources.GetFont(Resources.FontResources.FONT);
            text.TextContent    = "Hello";
            text.ForeColor      = Colors.Red;
            text.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Left;
            text.VerticalAlignment   = Microsoft.SPOT.Presentation.VerticalAlignment.Stretch;

            panel.Children.Add(text);

            text                = new Text();
            text.Font           = Resources.GetFont(Resources.FontResources.FONT);
            text.TextContent    = "comma";
            text.ForeColor      = Colors.Green;
            text.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            text.VerticalAlignment   = Microsoft.SPOT.Presentation.VerticalAlignment.Stretch;

            panel.Children.Add(text);

            text                = new Text();
            text.Font           = Resources.GetFont(Resources.FontResources.FONT);
            text.TextContent    = "World!";
            text.ForeColor      = Colors.Blue;
            text.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Right;
            text.VerticalAlignment   = Microsoft.SPOT.Presentation.VerticalAlignment.Stretch;

            panel.Children.Add(text);            

            TextFlow textFlow = new TextFlow();
            textFlow.Height = 60;            
            textFlow.TextRuns.Add("[BEGIN] ", Resources.GetFont(Resources.FontResources.FONT), Colors.Green);
            textFlow.TextRuns.Add("Call me Ishmael. ", Resources.GetFont(Resources.FontResources.FONT), Colors.Gray);
            textFlow.TextRuns.Add("Some years ago - never mind how long precisely - having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. ", Resources.GetFont(Resources.FontResources.FONT), Colors.Gray);
            textFlow.TextRuns.Add("It is a way I have of driving off the spleen, and regulating the circulation. ", Resources.GetFont(Resources.FontResources.FONT), Colors.Gray);
            textFlow.TextRuns.Add("A_very_long_sentence_with_no_whitespace_that_should_trigger_an_emergency_break. ", Resources.GetFont(Resources.FontResources.FONT), Colors.Blue);
            textFlow.TextRuns.Add("[END] ", Resources.GetFont(Resources.FontResources.FONT), Colors.Green);

            panel.Children.Add(textFlow);

            text = new Text();
            text.Font = Resources.GetFont(Resources.FontResources.FONT);
            text.TextContent = "";
            text.ForeColor = Colors.Gray;
            text.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            text.VerticalAlignment = Microsoft.SPOT.Presentation.VerticalAlignment.Stretch;

            panel.Children.Add(text);

            _buttonText = text;

            text = new Text();
            text.Font = Resources.GetFont(Resources.FontResources.FONT);
            text.TextContent = "";
            text.ForeColor = Colors.Gray;
            text.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            text.VerticalAlignment = Microsoft.SPOT.Presentation.VerticalAlignment.Stretch;

            panel.Children.Add(text);

            _timeText = text;            

            window.Child        = panel;

            window.AddHandler(Buttons.ButtonDownEvent, new RoutedEventHandler(OnButtonDown), false);
            window.AddHandler(Buttons.GotFocusEvent, new RoutedEventHandler(OnGotFocus), false);

            window.Width = SystemMetrics.ScreenWidth;
            window.Height = SystemMetrics.ScreenHeight;
            window.Visibility = Visibility.Visible;

            // Buttons.Focus(window);

            Buttons.Focus(textFlow);

            return window;
        }