Exemple #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;

            // Create a single text control.
            this.textElement = new Text();
            this.textElement.Font = Resources.GetFont(Resources.FontResources.NinaB);
            this.textElement.TextContent = this.count.ToString();
            this.textElement.HorizontalAlignment = HorizontalAlignment.Center;
            this.textElement.VerticalAlignment = VerticalAlignment.Center;
            // Add the text control to the window.
            mainWindow.Child = this.textElement;

            this.dispatcherTimer = new DispatcherTimer(this.textElement.Dispatcher);
            this.dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            this.dispatcherTimer.Interval = new TimeSpan(0, 0, 1); //one second
            this.dispatcherTimer.Start();

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

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

            return mainWindow;
        }
Exemple #2
0
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="interval">The interval for the timer.</param>
        /// <param name="behavior">The behavior for the timer (run once or continuously).</param>
        public Timer(TimeSpan interval, BehaviorType behavior)
        {
            if (Program.Dispatcher == null)
            {
                Debug.Print("WARN: null Program.Dispatcher in GT.Timer constructor");
            }

            this.dt = new DispatcherTimer(Program.Dispatcher ?? Dispatcher.CurrentDispatcher);
            this.dt.Interval = interval;
            this.dt.Tick += new EventHandler(dt_Tick);
            this.Behavior = behavior;
        }
        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;

            Text help = new Text();
            help.Font = Resources.GetFont(Resources.FontResources.nina14);
            help.TextContent = "Buttons: UP resets, SEL Syncs, DOWN schedules";
            help.HorizontalAlignment = HorizontalAlignment.Center;
            help.VerticalAlignment = VerticalAlignment.Top;

            time.Font = Resources.GetFont(Resources.FontResources.small);
            time.TextContent = "Initializing...";
            time.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            time.VerticalAlignment = Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            // Add the text controls to the window.
            Panel panel = new Panel();
            panel.Children.Add(help);
            panel.Children.Add(time);
            mainWindow.Child = panel;

            // 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;

            clockTimer = new DispatcherTimer(mainWindow.Dispatcher);
            clockTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
            clockTimer.Tick += new EventHandler(ClockTimer_Tick);

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

            TimeService.SystemTimeChanged += new SystemTimeChangedEventHandler(TimeService_SystemTimeChanged);
            TimeService.TimeSyncFailed += new TimeSyncFailedEventHandler(TimeService_TimeSyncFailed);

            clockTimer.Start();

            return mainWindow;
        }
Exemple #4
0
            // Constructor
            public MyWindow()
            {
                time.Font = Resources.GetFont(Resources.FontResources.nina48);
                time.TextContent = DateTime.Now.ToString("hh:mm:ss");
                time.HorizontalAlignment = HorizontalAlignment.Center;
                time.VerticalAlignment = VerticalAlignment.Center;

                dayofWeek.Font = Resources.GetFont(Resources.FontResources.nina14);
                dayofWeek.TextContent = days[(int)DateTime.Now.DayOfWeek];
                dayofWeek.HorizontalAlignment = HorizontalAlignment.Left;
                dayofWeek.VerticalAlignment = VerticalAlignment.Bottom;
                dayofWeek.ForeColor = Colors.Red;

                date.Font = Resources.GetFont(Resources.FontResources.nina14);
                date.TextContent = DateTime.Now.ToString("MM/dd/yyyy");
                date.HorizontalAlignment = HorizontalAlignment.Right;
                date.VerticalAlignment = VerticalAlignment.Bottom;
                date.ForeColor = Colors.Red;

                ip.Font = Resources.GetFont(Resources.FontResources.nina14);
                ip.TextContent = str;
                ip.HorizontalAlignment = HorizontalAlignment.Center;
                ip.VerticalAlignment = VerticalAlignment.Bottom;

                help.Font = Resources.GetFont(Resources.FontResources.nina14);
                help.TextContent = "Buttons: UP resets, SEL Syncs, DOWN schedules";
                help.HorizontalAlignment = HorizontalAlignment.Center;
                help.VerticalAlignment = VerticalAlignment.Top;

                clockTimer = new DispatcherTimer(this.Dispatcher);
                clockTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
                clockTimer.Tick += new EventHandler(ClockTimer_Tick);

                // Add the time control to the window.
                this.Child = panel;
                panel.Children.Add(time);
                panel.Children.Add(dayofWeek);
                panel.Children.Add(date);
                panel.Children.Add(ip);
                panel.Children.Add(help);

                clockTimer.Start();
            }
Exemple #5
0
            /// <summary>
            /// Constructs a PuzzleBoard with the specified settings.
            /// </summary>
            /// <param name="width"></param>
            /// <param name="height"></param>
            public PuzzleBoard(int width, int height)
                : base(0, 0, width, height)
            {
                blockDimension = (width > height ? height : width) / 3;

                // Use native collection and only look for gestures.
                TouchCollectorConfiguration.CollectionMethod = 
                    CollectionMethod.Native;
                TouchCollectorConfiguration.CollectionMode = 
                    CollectionMode.InkAndGesture;

                // Load all of the puzzle images.
                _blockBitmap[0] = Resources.GetBitmap(Resources.BitmapResources.b1);
                _blockBitmap[1] = Resources.GetBitmap(Resources.BitmapResources.b2);
                _blockBitmap[2] = Resources.GetBitmap(Resources.BitmapResources.b3);
                _blockBitmap[3] = Resources.GetBitmap(Resources.BitmapResources.b4);
                _blockBitmap[4] = Resources.GetBitmap(Resources.BitmapResources.b5);
                _blockBitmap[5] = Resources.GetBitmap(Resources.BitmapResources.b6);
                _blockBitmap[6] = Resources.GetBitmap(Resources.BitmapResources.b7);
                _blockBitmap[7] = Resources.GetBitmap(Resources.BitmapResources.b8);
                _blockBitmap[8] = Resources.GetBitmap(Resources.BitmapResources.b9);

                // Set up the animation timer.
                _animationTimer = new DispatcherTimer(this.Dispatcher);
                _animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 50);
                _animationTimer.Tick += new EventHandler(AnimationTimer_Tick);

#if MF_FRAMEWORK_VERSION_V3_0
                this.Gesture += new InkCollectorGestureEventHandler(PuzzleBoard_GestureHandler);
#endif

                Reset();
            }
        long uploadIntervalMSec = 60000;  // upload interval 1000 msec

        private void Initialize()
        {
            InitializeUpload();

            measureTimer = new DispatcherTimer();
            measureTimer.Interval = TimeSpan.FromTicks(measureIntervalMSec * TimeSpan.TicksPerMillisecond);
            measureTimer.Tick += MeasureTimer_Tick;
            measureTimer.Start();

            uploadTimer = new DispatcherTimer();
            uploadTimer.Interval = TimeSpan.FromTicks(uploadIntervalMSec * TimeSpan.TicksPerMillisecond);
            uploadTimer.Tick += UploadTimer_Tick;
            uploadTimer.Start();
        }
        /// <summary>
        /// Starts game on specified level
        /// </summary>
        /// <param name="startLevel">Leve to start game</param>
        public void StartGame(int startLevel)
        {
            // Prepare universe
            gameUniverse.Init();
            gameUniverse.StartLevel(startLevel);
            gameUniverse.StepUniverse();

            // Start tick timer
            gameTimer = new DispatcherTimer(this.Dispatcher);
            gameTimer.Interval = new TimeSpan(0, 0, 0, 0, gameUniverse.Statistics.Interval);
            gameTimer.Tick += new EventHandler(GameTimer_Tick);
            gameTimer.Start();
        }
        /// <summary>
        /// Creates all WPF controls of the window
        /// </summary>
        private void InitializeComponents()
        {
            blinkTimer = new DispatcherTimer(this.Dispatcher);
            blinkTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);
            blinkTimer.Tick += new EventHandler(BlinkTimer_Tick);

            #region Name Characters
            nameStack = new StackPanel(Orientation.Horizontal);
            nameStack.HorizontalAlignment = HorizontalAlignment.Left;
            nameStack.SetMargin(0, 0, 20, 5);

            for (int i = 0; i < NAME_LENGTH; i++)
            {
                nameLetters[i] = new Text();
                nameLetters[i].Font = Resources.GetFont(Resources.FontResources.Consolas23);
                nameStack.Children.Add(nameLetters[i]);
            }

            UpdateLetters();
            #endregion

            #region Score Label
            scoreLabel = new Text(ScoreToString(this._score));
            scoreLabel.ForeColor = normalColor;
            scoreLabel.Font = Resources.GetFont(Resources.FontResources.Consolas23);
            scoreLabel.TextAlignment = TextAlignment.Right;
            #endregion

            StackPanel mainStack = new StackPanel(Orientation.Horizontal);
            mainStack.HorizontalAlignment = HorizontalAlignment.Center;
            mainStack.Children.Add(nameStack);
            mainStack.Children.Add(scoreLabel);

            this.Child = mainStack;
        }
Exemple #9
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;
        }
        /// <summary>
        /// Accessor function for the private timer member.
        /// </summary>
        private void StartAnimationTimer()
        {
            // Only start the timer if _animationStep is not 0.
            if (_animationStep != 0)
            {
                // The first time through, create the timer.
                if (_animationTimer == null)
                {
                    _animationTimer = new DispatcherTimer(this.Dispatcher);
                    _animationTimer.Interval =
                        new TimeSpan(0, 0, 0, 0, timerInterval);
                    _animationTimer.Tick += new EventHandler(OnAnimationTimer);
                }

                // Keep track of when the timer was started, to deal with missing
                // frames because of a slow processor or being in the emulator.
                _lastTick = DateTime.Now.Ticks;

                // Start the timer
                _animationTimer.Start();
            }
        }