示例#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 scrollviewer
            ScrollViewer scrollViewer = new ScrollViewer();
            scrollViewer.Background = new SolidColorBrush(Colors.Gray);
            // scroll line by line with 10 pixels per line
            scrollViewer.ScrollingStyle = ScrollingStyle.LineByLine;
            scrollViewer.LineWidth = 10;
            scrollViewer.LineHeight = 10;

            // Create a canvas and add ellipse shapes
            Canvas canvas = new Canvas();
            for (int x = 0; x <= 20; ++x)
            {
                for (int y = 0; y <= 20; ++y)
                {
                    Ellipse ellipse = new Ellipse(10, 10);
                    ellipse.Stroke = new Pen(Colors.White);
                    canvas.Children.Add(ellipse);
                    Canvas.SetLeft(ellipse, x * 30);
                    Canvas.SetTop(ellipse, y * 30);
                }
            }
            //we need to set the size of a canvas explicitly
            //because it doesn´t calculate the desired size from its content
            canvas.Width = 20 * 30 + 10 * 2;
            canvas.Height = 20 * 30 + 10 * 2;
            scrollViewer.Child = canvas;

            // Add the scroll viewer to the window.
            mainWindow.Child = scrollViewer;

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

            // Attach the button focus to the scroll viewer
            // to be able to scroll with the up down right and left buttons
            Buttons.Focus(scrollViewer);

            return mainWindow;
        }
        object DrawEllipse(object arg)
        {
            Point pt = arg as Point;
            if (pt == null)
            {
                _ellipse = new Ellipse(0, 0);
                if (!_defConstructor)
                {
                    try
                    {
                        _ellipse.Width = w;
                        _ellipse.Height = h;
                    }
                    catch (ArgumentException ex)
                    {
                        Log.Comment("Caught : " + ex.Message + " when setting w = '" + w + "' and h = '" + h + "'");
                        eCounter++;
                    }
                }
            }
            else if ((pt.x < 0) || (pt.y < 0))
            {
                try
                {
                    _ellipse = new Ellipse(pt.x, pt.y);
                }
                catch (ArgumentException e)
                {
                    Log.Comment("Caught : " + e.Message + " when new Ellipse(" + pt.x + ", " + pt.y + ")");
                    eCounter++;
                }
            }
            else
            {
                _ellipse = new Ellipse(pt.x, pt.y);
            }

            if (_ellipsePen == null)
            {
                _ellipse.Stroke = new Pen(_pen.Color, 1);
            }
            else
            {
                _ellipse.Stroke = _ellipsePen;
            }

            _ellipse.Fill = _brush;
            Master_Shapes._panel.Children.Add(_ellipse);
            return null;
        }
示例#3
0
 private void DrawSlider(Canvas canvas)
 {
     Line horizontal = new Line(50, 0);
     circle = new Ellipse(7, 7);
     horizontal.Stroke = new Pen(Colors.Black);
     circle.Stroke = new Pen(Colors.DarkGray);
     circle.Fill = new SolidColorBrush(Colors.Blue);
     circle.TouchDown+=new TouchEventHandler(slider_TouchDown);
     Canvas.SetTop(circle, 180);
     Canvas.SetLeft(circle, 80);
     Canvas.SetTop(horizontal, 187);
     Canvas.SetLeft(horizontal, 75);
     canvas.Children.Add(horizontal);
     canvas.Children.Add(circle);
 }
示例#4
0
        private void DrawGraph(Canvas canvas)
        {
            canvas.Children.Clear();
            if (tempMode) //Temperature mode
            {
                //Determine the maximum and minimum registered values
                int min=666, max=-666;
                if(weatherData[0]!=null)
                    for (int i = 0; i < weatherData.Length; i++)
                    {
                        if (weatherData[i].temperature != -666 && weatherData[i].temperature < min)
                            min = (int)weatherData[i].temperature;
                        if (weatherData[i].temperature != -666 && weatherData[i].temperature >max)
                            max = (int)weatherData[i].temperature;
                    }

                if (HwDevices.fahrenheit)
                {
                    min = (int)(min * 1.8 + 32);
                    max = (int)(max * 1.8 + 32);
                }

                minText = new Text("" + min);
                minText.Font=Resources.GetFont(Resources.FontResources.small);
                maxText = new Text("" + max);
                maxText.Font=Resources.GetFont(Resources.FontResources.small);

                Line horizontal = new Line(0, canvas.Height-10);
                horizontal.Stroke = new Pen(Colors.Black);

                Canvas.SetTop(maxText, 5);
                Canvas.SetTop(minText, 130);
                Canvas.SetTop(horizontal, 5);
                Canvas.SetLeft(horizontal, 20);

                int px = 20;
                int py = 135;
                int x = 25;
                if (weatherData[0] != null)
                    for (int i = 0; i < 30; i++)
                    {
                        if (weatherData[i].temperature != -666)
                        {
                            int t;
                            if (HwDevices.fahrenheit)
                                t = (int)(weatherData[i].temperature * 1.8 + 32);
                            else
                                t = (int)(weatherData[i].temperature);
                            int y = (int)(t * 135);
                            y = 135-(y / max-min ) +5;
                            Ellipse auxCircle = new Ellipse(3, 3);
                            auxCircle.Stroke = new Pen(Colors.Orange);
                            auxCircle.Fill = new SolidColorBrush(Colors.Red);
                            Canvas.SetTop(auxCircle, y);
                            Canvas.SetLeft(auxCircle, x);
                            graph.Children.Add(auxCircle);
                            px = x;
                            py = y;
                        }
                        x += 6;
                    }

                canvas.Children.Add(minText);
                canvas.Children.Add(maxText);
                canvas.Children.Add(horizontal);
            }
            else //Humidity mode
            {
                //Determine the maximum and minimum registered values
                int min = 666, max = -666;
                for (int i = 0; i < weatherData.Length; i++)
                {
                    if (weatherData[i].humidity != -666 && weatherData[i].humidity < min)
                        min = (int)weatherData[i].humidity;
                    if (weatherData[i].humidity != -666 && weatherData[i].humidity > max)
                        max = (int)weatherData[i].humidity;
                }

                minText = new Text("" + min);
                minText.Font = Resources.GetFont(Resources.FontResources.small);
                maxText = new Text("" + max);
                maxText.Font = Resources.GetFont(Resources.FontResources.small);

                Line horizontal = new Line(0, canvas.Height - 10);
                horizontal.Stroke = new Pen(Colors.Black);

                Canvas.SetTop(maxText, 5);
                Canvas.SetTop(minText, 130);
                Canvas.SetTop(horizontal, 5);
                Canvas.SetLeft(horizontal, 20);

                int px = 20;
                int py = 135;
                int x = 25;
                for (int i = 0; i < 30; i++)
                {
                    if (weatherData[i].humidity != -666)
                    {
                        int y = (int)(weatherData[i].humidity * 135);
                        y = 135 - (y / max) + 5;
                        Ellipse auxCircle = new Ellipse(3, 3);
                        auxCircle.Stroke = new Pen(Colors.Blue);
                        auxCircle.Fill = new SolidColorBrush(Colors.Cyan);
                        Canvas.SetTop(auxCircle, y);
                        Canvas.SetLeft(auxCircle, x);
                        graph.Children.Add(auxCircle);

                        px = x;
                        py = y;
                    }
                    x += 6;
                }

                canvas.Children.Add(minText);
                canvas.Children.Add(maxText);
                canvas.Children.Add(horizontal);

            }
        }