Пример #1
0
        public override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);
            dc.DrawRectangle(new SolidColorBrush(Colors.Black), new Pen(Colors.Black), 0, 0, 50, 50);

            if (_direction == ArrowDirection.Down)
            {
                int Y, X;
                for (int i = 0; i <= 12; i++)
                {
                    Y = 6 - i;
                    X = 12 - i;
                    dc.DrawLine(new Pen(Color.White), (this.Width / 2 - X), (this.Height / 2 - Y), (this.Width / 2 + X), (this.Height / 2 - Y));
                }
            }
            else
            {
                int Y, X;
                for (int i = 0; i <= 12; i++)
                {
                    Y = 17 - i;
                    X = 12 - i;
                    dc.DrawLine(new Pen(Color.White), (this.Width / 2 - X), Y, (this.Width / 2 + X), Y);
                }
            }
        }
Пример #2
0
        public override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            // draw crosshair
            if (idx < CalibrationManager.CalibrationPoints.Count)
            {
                int x = CalibrationManager.CalibrationPoints.ScreenX[idx];
                int y = CalibrationManager.CalibrationPoints.ScreenY[idx];

                dc.DrawLine(pen, x - 10, y, x - 2, y);
                dc.DrawLine(pen, x + 10, y, x + 2, y);

                dc.DrawLine(pen, x, y - 10, x, y - 2);
                dc.DrawLine(pen, x, y + 10, x, y + 2);
            }
        }
Пример #3
0
        public override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            if (isSelected)
            {
                Pen pen = new Pen(Colors.DarkGray, 1);

                // top border
                dc.DrawLine(pen, 0, 0, ActualWidth - 1, 0);

                // left border
                dc.DrawLine(pen, 0, 0, 0, ActualHeight - 1);

                // right border
                dc.DrawLine(pen, ActualWidth - 1, 0, ActualWidth - 1, ActualHeight - 1);

                // bottom border
                dc.DrawLine(pen, 0, ActualHeight - 1, ActualWidth - 1, ActualHeight - 1);
            }
        }
Пример #4
0
            /// <summary>
            /// Overrides OnRender to do our own drawing.
            /// </summary>
            /// <param name="dc"></param>
            public override void OnRender(DrawingContext dc)
            {
                int x;
                int y;

                SolidColorBrush brush;
                Pen pen;
                Color color;
                Pen shade1;
                Pen shade2;

                // Check the pressed state and draw accordingly.
                if (_pressed)
                {
                    brush = _pressedBackgroundBrush;
                    pen = _pressedBorderPen;
                    color = _pressedForeColor;
                    shade1 = _darkShade;
                    shade2 = _lightShade;
                }
                else
                {
                    brush = _normalBackgroundBrush;
                    pen = _borderPen;
                    color = _foreColor;
                    shade1 = _lightShade;
                    shade2 = _darkShade;
                }

                GetLayoutOffset(out x, out y);

                // Draw the base rectangle of the button.
                dc.DrawRectangle(brush, pen, 1, 1, _width - 1, _height - 1);

                // Draw the caption.
                string caption = _caption;
                dc.DrawText(ref caption, _font, color, 0, _textMarginY, _width, 
                    _height, _alignment, _trimming);

                // Shade the outline of the rectangle for classic button look.
                dc.DrawLine(shade1, 1, 1, _width - 1, 1);
                dc.DrawLine(shade1, 1, 1, 1, _height - 1);
                dc.DrawLine(shade2, _width - 1, 1, _width - 1, _height - 1);
                dc.DrawLine(shade2, 1, _height - 1, _width - 1, _height - 1);
            }
Пример #5
0
            /// <summary>
            /// Handles the render event.
            /// </summary>
            /// <param name="dc"></param>
            public override void OnRender(DrawingContext dc)
            {
                // Loop through all the blocks except the animated block
                // and draw the associated bitmap.
                int i = 0;
                for (i = 0; i < 9; i++)
                {
                    int x = (i % 3) * blockDimension;
                    int y = (i / 3) * blockDimension;

                    if (_animationTargetBlock != i)
                    {
                        DrawBlock(_blocks[i], x, y, dc);
                    }
                }

                // Draw the animated block if there is one.
                if (_animationTargetBlock >= 0)
                {
                    lock (_blockBitmap)
                    {
                        int x = (_animationTargetBlock % 3) * blockDimension;
                        int y = (_animationTargetBlock / 3) * blockDimension;

                        dc.DrawImage(_blockBitmap[8], x, y);

                        if (_animationStep < 9 && activeAnimX != null && activeAnimY != null)
                        {
                            x += activeAnimX[_animationStep];
                            y += activeAnimY[_animationStep];
                        }

                        DrawBlock(_blocks[_animationTargetBlock], x, y, dc);
                    }
                }

                // Draw a rectangle box around the puzzle.
                dc.DrawLine(pen, 0, 0, 0, 239);
                dc.DrawLine(pen, 0, 0, 240, 0);
                dc.DrawLine(pen, 0, 239, 240, 239);
                dc.DrawLine(pen, 240, 0, 240, 239);
            }
Пример #6
0
            /// <summary>
            /// Handles the render event.
            /// </summary>
            /// <param name="dc"></param>
            public override void OnRender(DrawingContext dc)
            {
                base.OnRender(dc);

                // If the flag is set, draw a circle.
                if (drawCircle)
                {
                    dc.DrawEllipse(brush, pen, cx, cy, r, r);
                }

                // If we have some points, draw lines between them to make a 
                // complete path.
                if (pointIndex > 1)
                {
                    for (int i = 1; i < pointIndex; i++)
                    {
                        dc.DrawLine(pen2, Points[i - 1].x, Points[i - 1].y, 
                            Points[i].x, Points[i].y);
                    }
                }
            }
Пример #7
0
        public override void OnRender(DrawingContext dc)
        {
            // Performance tunning
            // storing properties to variables for faster reuse
            int fieldCols = gameUniverse.Field.Columns;
            int fieldRows = gameUniverse.Field.Rows;

            #region Draw Grid
            int final = fieldRows * ROW_HEIGHT;
            for(int col = 0; col <= fieldCols; col++)
            {
                int x = col * COLUMN_WIDTH;
                dc.DrawLine(gridPen, x, 0, x, final);
            }

            final = fieldCols * COLUMN_WIDTH;
            for (int row = 0; row <= fieldRows; row++)
            {
                int y = row * ROW_HEIGHT;
                dc.DrawLine(gridPen, 0, y, final, y);
            }
            #endregion

            #region Draw the game field
            for (int row = 0; row < fieldRows; row++)
                for (int col = 0; col < fieldCols; col++)
                {
                    int brushType = gameUniverse.Field.GetCell(row, col) - 1;
                    if (brushType >= 0)
                        dc.DrawRectangle(BlockBrushes.Instance.GetBrush(brushType),
                                         blockPen,
                                         col * COLUMN_WIDTH + 1,
                                         row * ROW_HEIGHT + 1,
                                         COLUMN_WIDTH - 1,
                                         ROW_HEIGHT - 1);
                }
            #endregion

            #region Draw the current object
            // Performance tunning
            fieldCols = gameUniverse.CurrentBlock.Columns;
            fieldRows = gameUniverse.CurrentBlock.Rows;

            for (int row = 0; row < fieldRows; row++)
                for(int col = 0; col < fieldCols; col++)
                {
                    int brushType = gameUniverse.CurrentBlock.GetCell(row, col) - 1;
                    if (brushType >= 0)
                        dc.DrawRectangle(BlockBrushes.Instance.GetBrush(brushType),
                                         blockPen,
                                         (col + gameUniverse.BlockX) * COLUMN_WIDTH + 1,
                                         (row + gameUniverse.BlockY) * ROW_HEIGHT + 1,
                                         COLUMN_WIDTH - 1,
                                         ROW_HEIGHT - 1);
                }
            #endregion

            #region Draw Game Over banner
            if (gameUniverse.Statistics.GameOver)
            {
                string gameOverStr = Resources.GetString(Resources.StringResources.GameOver);
                Font gameOverFont = Resources.GetFont(Resources.FontResources.Consolas23);

                int gameOverY = (this.Height - gameOverFont.Height) / 2;
                int gameOverHeight = gameOverFont.Height + 3;

                dc.DrawRectangle(new LinearGradientBrush(Colors.Gray, Colors.White, 0, 0, this.Width, gameOverFont.Height * 2),
                                 new Pen(Color.White),
                                 2,
                                 gameOverY - 5,
                                 this.Width - 4,
                                 gameOverHeight + 5);

                dc.DrawText(ref gameOverStr,
                            gameOverFont,
                            Colors.Red,
                            0,
                            gameOverY,
                            this.Width,
                            gameOverHeight,
                            TextAlignment.Center,
                            TextTrimming.WordEllipsis);
            }
            #endregion

            base.OnRender(dc);
        }
Пример #8
0
        public override void OnRender(DrawingContext dc)
        {
            dc.DrawRectangle(pressed ? brushPressed : brushUnpressed, null, 0, 0, ActualWidth, ActualHeight);
            //if (pressed)
            //    dc.Bitmap.DrawRectangle(Color.Black, 0, 0, 0, ActualWidth, ActualHeight, 0, 0, ColorUtility.ColorFromRGB(128, 255, 0), 0, 0, ColorUtility.ColorFromRGB(128, 255, 0), ActualWidth, ActualHeight, 150);
            //else
            //    dc.Bitmap.DrawRectangle(Color.Black, 0, 0, 0, ActualWidth, ActualHeight, 0, 0, Colors.Black, 0, 0, Colors.Black, ActualWidth, ActualHeight, 10);

            // border
            int corner = 2;
            int right = ActualWidth - 1;
            int bottom = ActualHeight - 1;
            dc.DrawLine(border, corner, 0, right - corner, 0); // top
            dc.DrawLine(border, corner, bottom, right - corner, bottom); // bottom
            dc.DrawLine(border, 0, corner, 0, bottom - corner); // left
            dc.DrawLine(border, right, corner, right, bottom - corner); // rigth
            dc.DrawLine(border, corner, 0, 0, corner); // upper-left
            dc.DrawLine(border, right - corner, 0, right, corner); // upper-right
            dc.DrawLine(border, 0, bottom - corner, corner, bottom); // bottom-left
            dc.DrawLine(border, right, bottom - corner, right - corner, bottom); // bottom-right

            // transparent corners
            ArrayList transparentPoints = new ArrayList();
            transparentPoints.Add(new Point(0, 0));
            transparentPoints.Add(new Point(1, 0));
            transparentPoints.Add(new Point(0, 1));

            transparentPoints.Add(new Point(right, 0));
            transparentPoints.Add(new Point(right - 1, 0));
            transparentPoints.Add(new Point(right, 1));

            transparentPoints.Add(new Point(0, bottom));
            transparentPoints.Add(new Point(1, bottom));
            transparentPoints.Add(new Point(0, bottom - 1));

            transparentPoints.Add(new Point(right, bottom));
            transparentPoints.Add(new Point(right - 1, bottom));
            transparentPoints.Add(new Point(right, bottom - 1));

            foreach (Point p in transparentPoints)
                //dc.DrawRectangle(brushTransparent, null, p.X, p.Y, 1, 1);
                dc.Bitmap.DrawRectangle(Color.Black, 0, p.X, p.Y, 1, 1, 0, 0, Colors.Red, 0, 0, Colors.Red, 0, 0, 0);
        }
        /// <summary>
        /// Override the OnRender and draw using the DrawingContext that is passed 
        /// in.
        /// </summary>
        /// <param name="dc"></param>
        public override void OnRender(DrawingContext dc)
        {
            // Paint the background.
            dc.DrawRectangle(
                new SolidColorBrush(ColorUtility.ColorFromRGB(128, 0, 255)),
                new Pen(ColorUtility.ColorFromRGB(128, 0, 255)),
                0, 0, Width, Height);

            // Draw some circles.
            for (int i = 0; i < 3; i++)
                dc.DrawEllipse(
                    new SolidColorBrush(ColorUtility.ColorFromRGB((byte)(64 * i),
                        128, 128)),
                    new Pen(ColorUtility.ColorFromRGB(255, (byte)(64 * i), 255)),
                    Width / 5, Height / 5, i * (Width / 10 - (i * 2)),
                    i * (Height / 10 - (i * 2)));

            // Draw some lines.
            for (int i = 0; i < 20; i++)
                dc.DrawLine(new Pen(ColorUtility.ColorFromRGB((byte)(16 * i),
                    (byte)(16 * (20 - i)), (byte)(16 * (2 * i)))),
#if MF_FRAMEWORK_VERSION_V3_0
                Microsoft.SPOT.Math.Random(Width / 2) + Width / 3,
                Microsoft.SPOT.Math.Random(Height / 3) + Height / 3,
                Microsoft.SPOT.Math.Random(Width / 4) + Width / 2,
                Microsoft.SPOT.Math.Random(Height / 4) + Height / 2);
#else
 _random.Next(Width / 2) + Width / 3,
                    _random.Next(Height / 3) + Height / 3,
                    _random.Next(Width / 4) + Width / 2,
                    _random.Next(Height / 4) + Height / 2);
#endif

            // Draw a rectangle.
            dc.DrawRectangle(new SolidColorBrush(ColorUtility.ColorFromRGB(
                255, 0, 0)),
                new Pen(ColorUtility.ColorFromRGB(0, 0, 255)), Width - 40, 0, 30,
                100);

            // Draw a polyline.
            int[] points = { 10, 230, 30, 210, 0, 180, 30, 130, 50, 130, 80, 180, 
                           50, 210, 70, 230 };
            if (Width > Height)
                for (int i = 1; i < points.Length; i += 2)
                    points[i] -= 20;
            dc.DrawPolygon(new SolidColorBrush(ColorUtility.ColorFromRGB(
                32, 0, 128)),
                new Pen(ColorUtility.ColorFromRGB(0, 0, 0)), points);

            // Draw some text.
            dc.DrawText(Resources.GetString(
                Resources.StringResources.DrawTextSample),
                Resources.GetFont(Resources.FontResources.NinaBFont),
                ColorUtility.ColorFromRGB(255, 255, 255),
#if MF_FRAMEWORK_VERSION_V3_0
            Microsoft.SPOT.Math.Random(Width / 4), Height - 20);
#else
 _random.Next(Width / 4), Height - 20);
#endif
        }
            /// <summary>
            /// To manual draw, override the OnRender method and draw using 
            /// standard drawing type functions.
            /// </summary>
            /// <param name="dc"></param>
            public override void OnRender(DrawingContext dc)
            {
                // Draw a line from top, left to bottom, right
                dc.DrawLine(base.Stroke, 0, 0, Width, Height);

                // Draw a line from top, right to bottom, left
                dc.DrawLine(base.Stroke, Width, 0, 0, Height);
            }
Пример #11
0
            public override void OnRender(DrawingContext dc)
            {
                if (_pushClippingRectangle)
                {
                    try
                    {
                        dc.PushClippingRectangle(x0, y0, xDimension, yDimension);
                    }
                    catch (ArgumentException ex)
                    {
                        Log.Comment("Caught " + ex.Message + " when Pushing a clipping rectangle at (" + x0 + ", " + y0 + ")" +
                            " and Width = " + xDimension + " Height = " + yDimension);
                        _argumentException = true;
                    }
                }
                if (_popClippingRectangle)
                {
                    dc.PopClippingRectangle();
                }
                if (_getClippingRectangle)
                {
                    dc.GetClippingRectangle(out x1, out y1, out wd, out ht);
                }
                if (_drawLine)
                {
                    dc.DrawLine(_pen, x0, y0, x1, y1);
                }
                if (_drawRectangle)
                {
                    try
                    {
                        dc.DrawRectangle(_brush, _pen, r, s, xDimension, yDimension);
                    }
                    catch (ArgumentException ex)
                    {
                        Log.Comment("Caught " + ex.Message + " when drawing a Rectangle at (" + r + ", " + s + ")" +
                            " Width = " + xDimension + " Height = " + yDimension);
                        _argumentException = true;
                    }
                }
                if (_drawEllipse)
                {
                    dc.DrawEllipse(_brush, _pen, r, s, xDimension, yDimension);
                }
                if (_drawPolygon)
                {
                    dc.DrawPolygon(_brush, _pen, pts);
                }
                if (_clear)
                {
                    dc.Clear();
                }
                if (_setPixel)
                {
                    dc.SetPixel(_color, r, s);
                }
                if (_drawImage)
                {
                    try
                    {
                        dc.DrawImage(bmp1, r, s);
                    }
                    catch (NullReferenceException ex)
                    {
                        Log.Comment("Caught " + ex.Message + " when drawing a null Image");
                        _nullReferenceException = true;
                    }
                }
                if (_drawCroppedImage)
                {
                    try
                    {
                        dc.DrawImage(bmp1, r, s, x0, y0, xDimension, yDimension);
                    }                   
                    catch (ArgumentException ex)
                    {
                        Log.Comment("Caught " + ex.Message + " when drawing an Image at (" + r + ", " + s + ")" +
                            "from a source Image at(" + x0 + ", " + y0 + ") Width = " + xDimension + " Height = " + yDimension);
                        _argumentException = true;
                    }
                    catch (NullReferenceException ex)
                    {
                        Log.Comment("Caught " + ex.Message + " when drawing a null Image");
                        _nullReferenceException = true;
                    }
                }
                if (_translate)
                {
                    dc.Translate(r, s);
                }
                if (_blendImage)
                {
                    dc.BlendImage(bmp2, x0, y0, x1, y1, xDimension, yDimension, _opacity);
                }
                if (_drawText)
                {
                    _textFits = dc.DrawText(ref _str, _font, _color, r, s, xDimension, yDimension, _alignment, _trimming);
                }
                base.OnRender(dc);
                _pBitmap = dc.Bitmap;

                Master_Media.autoEvent.Set();
            }