public override void OnRender(DrawingContext dc)
 {
     dc.DrawRectangle(_cyanBrush, _darkCyanPen, 0, 0, Width, Height);
     dc.DrawText(ref _name,
                 _font,
                 Color.Black,
                 0,
                 2,
                 Width,
                 Height - 2,
                 TextAlignment.Center,
                 TextTrimming.None);
 }
Exemple #2
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);
            }
        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);
        }
            /// <summary>
            /// Renders the items in the list view.
            /// </summary>
            /// <param name="dc"></param>
            /// <param name="x"></param>
            /// <param name="y"></param>
            /// <param name="headerHeight"></param>
            /// <param name="itemHeight"></param>
            protected virtual void RenderItems(DrawingContext dc, int x, int y,
                int headerHeight, int itemHeight)
            {

                // Create the brushes and pens for drawing the items.
                Brush[] brushes = new Brush[] { _emptyBrush, _lightCyanBrush, 
                    _grayBrush };
                Pen[] pens = new Pen[] { _emptyPen, _cyanPen };

                // Set the starting location for the first item.  Offset the 
                // location by _sx and _sy, which are the scroll positions.
                int cx = x + 6 - _sx;
                int cy = y + headerHeight + 2 - _sy;
                int j = 0;

                // Iterate through all the items.
                for (int ii = 0; ii < Items.Count; ii++)
                {
                    // Only draw the items that are visible.
                    if (cy >= _columnHeaderHeight)
                    {

                        // If the item is selected...
                        if (((ListViewItem)Items[ii]) == _selectedItem)
                        {
                            // Draw a rectangle alternately shaded and 
                            // transparent.
                            dc.DrawRectangle(brushes[2], pens[j & 1], x + 2, cy,
                            _width - 4, _itemHeight);
                        }
                        else
                        {
                            // Draw a rectangle alternately shaded and 
                            // transparent.
                            dc.DrawRectangle(brushes[j & 1], pens[j & 1], x + 2,
                                cy, _width - 4, _itemHeight);
                        }

                        // Set the starting location for the first column.
                        // Offset the location by _sx, which is the scroll 
                        // position.
                        cx = 4 - _sx;
                        int i = 0;
                        int newcx = 0;

                        // Iterate through the sub-items, which are columns.
                        for (int e = 0; e < ((ListViewItem)Items[ii]).SubItems.Count; e++)
                        {
                            // Calculate the x position of the next column.
                            newcx = cx + ((ListViewColumn)Columns[i]).Width;

                            // Draw only the items that will appear on the 
                            // screen.
                            if (newcx > 0)
                            {
                                dc.DrawText(((ListViewSubItem)((ListViewItem)Items[ii]).SubItems[e]).Text, _font, Color.Black,
                                    cx, cy + 2);
                            }

                            // Move to the next column.
                            cx = newcx;
                            i++;

                            // If the location is past the right side of the 
                            // screen, don't show any more columns.
                            if (cx > _width)
                                break;
                        }
                    }

                    // Increment to the next item.
                    cy += itemHeight;
                    j++;

                    // If the location is past the bottom of the screen, don't 
                    // show any more items.
                    if (cy > _height)
                        break;
                }
            }
            /// <summary>
            /// Renders the column titles of the list view.
            /// </summary>
            /// <param name="dc"></param>
            /// <param name="x"></param>
            /// <param name="y"></param>
            /// <param name="headerHeight"></param>
            protected virtual void RenderColumns(DrawingContext dc, int x,
                int y, int headerHeight)
            {

                // Draw the header background.
                dc.DrawRectangle(_cyanBrush, _darkCyanPen, x, y + 2, _width,
                    headerHeight);

                // Iterate through the columns.
                int cx = 5 - _sx;
                for (int i = 0; i < Columns.Count; i++)
                {
                    // Draw the column text.
                    dc.DrawText(((ListViewColumn)Columns[i]).Name, _font, Color.Black, cx, y + 2);

                    // Increment by the column width.
                    cx += ((ListViewColumn)Columns[i]).Width;
                }

                // Store the total column width.
                totalColumnWidth = cx;
            }
            /// <summary>
            /// Renders the buttons.
            /// </summary>
            /// <param name="dc">The drawing context.</param>
            /// <param name="x">The width of a button.</param>
            /// <param name="y">The height of a button.</param>
            protected virtual void RenderButtons(DrawingContext dc, int x,
                int y)
            {

                // Calculate the width of a single button.
                int buttonWidth = _width / 5;

                // Render the New File button.
                dc.DrawRectangle(_cyanBrush, _darkCyanPen, x, y, buttonWidth,
                    20);
                string sNewFile = "New File";
                dc.DrawText(ref sNewFile, _font, Color.Black, x, y + 2,
                    buttonWidth, 16, TextAlignment.Center,
                    TextTrimming.None);

                // Render the New Directory button.
                dc.DrawRectangle(_cyanBrush, _darkCyanPen, x + buttonWidth, y,
                    buttonWidth, 20);
                string sNewDir = "New Dir";
                dc.DrawText(ref sNewDir, _font, Color.Black, x + buttonWidth,
                    y + 2, buttonWidth, 16,
                    TextAlignment.Center, TextTrimming.None);

                // Render the Move button.
                dc.DrawRectangle(_cyanBrush, _darkCyanPen, x + (buttonWidth * 2),
                    y, buttonWidth, 20);
                string sMove = "Move";
                dc.DrawText(ref sMove, _font, Color.Black, x + (buttonWidth * 2),
                    y + 2, buttonWidth, 16,
                    TextAlignment.Center, TextTrimming.None);

                // Render the Delete button.
                dc.DrawRectangle(_cyanBrush, _darkCyanPen, x + (buttonWidth * 3),
                    y, buttonWidth, 20);
                string sDelete = "Delete";
                dc.DrawText(ref sDelete, _font, Color.Black,
                    x + (buttonWidth * 3), y + 2, buttonWidth, 16,
                    TextAlignment.Center, TextTrimming.None);

                // Render the Format button.
                dc.DrawRectangle(_cyanBrush, _darkCyanPen, x + (buttonWidth * 4),
                    y, buttonWidth, 20);
                string sFormat = "Format";
                dc.DrawText(ref sFormat, _font,
                    Color.Black, x + (buttonWidth * 4), y + 2, buttonWidth, 16,
                    TextAlignment.Center, TextTrimming.None);
            }
Exemple #7
0
        /// <summary>
        /// Override OnRender to handle drawing.
        /// </summary>
        /// <param name="dc"></param>
        public override void OnRender(DrawingContext dc)
        {
            // Call the base class.
            base.OnRender(dc);

            // Set the status string to a default of Off.
            string status = "Off";

            // Get a bitmap depending on the current status.
            Bitmap bmp = null;
            if (_status == StatusType.Cool)
            {

                // Set the status text to Cool.
                status = "Cool";

                // Get the bitmap that represents a status of Cool.
                bmp = Resources.GetBitmap(Resources.BitmapResources.snowflake);
            }
            else if (_status == StatusType.Heat)
            {

                // Set the status text to Heat.
                status = "Heat";

                // Get the bitmap that represents a status of Heat.
                bmp = Resources.GetBitmap(Resources.BitmapResources.fire);
            }

            // Draw the status text.
            dc.DrawText("Status: " + status,
                Resources.GetFont(Resources.FontResources.small), Color.Black,
                10, 10);

            // If a bitmap was loaded, display it.
            if (bmp != null)
                dc.DrawImage(bmp, 100, 0);
        }
Exemple #8
0
        public override void OnRender(DrawingContext dc)
        {
            if (_font != null && _text != null)
            {
                int height = _textWrap ? _renderHeight : _font.Height;

                string txt = _text;
                dc.DrawText(ref txt, _font, _foreColor, 0, 0, _renderWidth, height, _alignment, _trimming);
            }
        }
Exemple #9
0
 public override void OnRender(DrawingContext dc)
 {
     if (font != null && !Utils.StringIsNullOrEmpty(text))
         dc.DrawText(text, font, foreColor, 0, 0);
 }
        /// <summary>
        /// Override the OnRender method to do the actual drawing of the menu.
        /// </summary>
        /// <param name="dc">The drawing context to render.</param>
        public override void OnRender(DrawingContext dc)
        {
            // Call the base class in case this control contains other controls.  
            // Depending on where those controls are placed, this call might not 
            // be optimal.
            base.OnRender(dc);

            // Calculate some initial values for positioning and drawing the 
            // MenuItems.

            // Set the width of each MenuItem.
            int largeX = Resources.GetBitmap(
                Resources.BitmapResources.Canvas_Panel_Icon).Width +
                xOffsetSeparation;

            // Set the starting x position.
            int x = (_width / 2) - ((largeX * 2) + (largeX / 2));

            // Set the starting y position.
            int y = 6;

            // Set the scaling of the current MenuItem.
            int scale = 0;

            // Set the scaling offset based on the animation step.
            int scaleOffset = System.Math.Abs(_animationStep);

            // Adjust the x based on the animation step.
            x += _animationStep * 5;

            // Iterate through the children, limiting them to 2 in front and 2 
            // behind the current child.  This places the current MenuItem in the 
            // middle of the menu.
            for (int i = _currentChild - 2; i < _currentChild + 3; i++)
            {
                // If we are on the current child...
                if (i == _currentChild)
                {
                    // Scale the current child based on the current animation step 
                    // value.  The current child is getting smaller, so take the 
                    // largest value (maxStep) and subtract the current scaling 
                    // offset.
                    scale = maxStep - scaleOffset;
                }
                else
                {
                    // If we are moving left and are drawing the child to the left, 
                    // or we are moving right and are drawing the child to the 
                    // right, then that child needs to be growing in size.  Else the 
                    // child is drawn without any scaling.
                    if ((_animationStep < 0 && i == _currentChild + 1) ||
                        (_animationStep > 0 && i == _currentChild - 1))
                        scale = scaleOffset;
                    else
                        scale = 0;
                }

                // Variable to point to the current MenuItem we want to draw.
                MenuItem menuItem = null;

                // Get the correct MenuItem from the array based on the value of i.
                // Because we are looking 2 left and 2 right, if the current child
                // is near the beginning or end of the array, we have to watch for
                // wrapping around the ends.
                if (i < 0)
                    menuItem = (MenuItem)MenuItemList[MenuItemList.Count + i];
                else if (i > MenuItemList.Count - 1)
                    menuItem = (MenuItem)MenuItemList[i - MenuItemList.Count];
                else
                    menuItem = (MenuItem)MenuItemList[i];

                // Have the MenuItem render itself based on the position and scaling 
                // calculated.
                menuItem.Render(dc, x, y, scale);

                // Increment the x position by the size of the MenuItems
                x += largeX;
            }

            // Draw the current menuItem's text.
            if (_width > 0)
            {
                // Check the window size for displaying instructions.
                int step = 20;
                int row = 120;

                // Check for portrait display.
                if (_width < _height)
                    step = 40;

                // Draw the description of the current MenuItem.
                string text = ((MenuItem)MenuItemList[_currentChild]).Description;
                dc.DrawText(ref text,
                    Resources.GetFont(Resources.FontResources.NinaBFont),
                    Color.White, 10, row, _width - 20, step, TextAlignment.Center,
                    TextTrimming.None);

                // Draw the basic instructions for the menu.
                text = Resources.GetString(Resources.StringResources.MenuScrolling);
                row += (step * 2);
                dc.DrawText(ref text,
                    Resources.GetFont(Resources.FontResources.NinaBFont),
                    Color.White, 10, row, _width - 20, step, TextAlignment.Center,
                    TextTrimming.None);
                text = Resources.GetString(Resources.StringResources.MenuSelection);
                row += step;
                dc.DrawText(ref text,
                    Resources.GetFont(Resources.FontResources.NinaBFont),
                    Color.White, 10, row, _width - 20, step, TextAlignment.Center,
                    TextTrimming.None);
                text = Resources.GetString(Resources.StringResources.ReturnToMenu);
                row += step;
                dc.DrawText(ref text,
                    Resources.GetFont(Resources.FontResources.NinaBFont),
                    Color.White, 10, row, _width - 20, step, TextAlignment.Center,
                    TextTrimming.None);
            }

            // Start the animation timer.  The animation timer is called every time 
            // the menu is rendered.  The animation timer will handle decrementing 
            // the _animationStep member and stopping the timer when _animationStep 
            // reaches 0.
            StartAnimationTimer();
        }
        /// <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
        }
Exemple #12
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();
            }
        /// <summary>
        /// Renders the column titles of the list view.
        /// </summary>
        /// <param name="dc"></param>
        protected virtual void RenderColumns(DrawingContext dc)
        {
            // Draw the header background.
            dc.DrawRectangle(_cyanBrush, _darkCyanPen, 0, 2, Width, _columnHeaderHeight);

            int columnWidthSum = 5 - _horizontalScroll;
            for (int i = 0; i < Columns.Count; i++)
            {
                // Draw the column text.
                dc.DrawText(((ListViewColumn)Columns[i]).Name, _font, Color.Black, columnWidthSum, 2);

                // Increment by the column width.
                columnWidthSum += ((ListViewColumn)Columns[i]).Width;
            }

            // Store the total column width.
            _totalViewWidth = columnWidthSum;
        }