Exemple #1
0
 /// <summary>
 /// Raises the PaintBackground event.
 /// </summary>
 /// <param name="pevent">A PaintEventArgs that contains the event data.</param>
 protected override void OnPaintBackground(PaintEventArgs pevent)
 {
     if ((_style == VisualStyle.Office2003) && _defaultBackColor)
     {
         CommandDraw.DrawGradientBackground(pevent.Graphics,
                                            this,
                                            _colorDetails.BaseColor,
                                            _colorDetails.BaseColor1,
                                            _colorDetails.BaseColor2,
                                            _office2003GradBack);
     }
     else if ((_style == VisualStyle.IDE2005) && _defaultBackColor)
     {
         CommandDraw.DrawGradientBackground(pevent.Graphics,
                                            this,
                                            _colorDetails.BaseColor,
                                            _colorDetails.BaseColor1,
                                            _colorDetails.BaseColor2,
                                            _ide2005GradBack);
     }
     else
     {
         base.OnPaintBackground(pevent);
     }
 }
        //This region handles all the drawing commands called on the invoker

        /// <summary>
        /// Start the drawing process,
        /// it is run once when the mouse button is pressed,
        /// and has to be finished with the Draw function.
        /// </summary>
        /// <param name="x1">The x axis of the drawing's first point</param>
        /// <param name="y1">The y axis of the drawing's first point</param>
        /// <param name="shape">The Shape object to draw with</param>
        public void StartDraw(double x1, double y1, Shape shape)
        {
            //Rounding positions to int to comply with mandatory saving grammar
            ICommand cmd = new CommandDraw((int)Math.Round(x1), (int)Math.Round(y1), shape, decoratorContext);

            decoratorContext = null;
            actionsDone.Push(cmd);
        }
Exemple #3
0
 /// <summary>
 /// Reset the colors based on the tracking start color.
 /// </summary>
 /// <param name="track">Tracking start color.</param>
 public void DefineTrackColors(Color track)
 {
     _trackBaseColor            = CommandDraw.TrackBaseFromTrack(track, _256Colors);
     _trackLightColor           = CommandDraw.TrackLightFromTrack(track, _256Colors);
     _trackLightLightColor      = CommandDraw.TrackLightLightFromTrack(track, _baseColor, _256Colors);
     _trackDarkColor            = CommandDraw.TrackDarkFromTrack(track, _256Colors);
     _trackMenuInsideColor      = CommandDraw.TrackMenuInsideFromTrack(track, _256Colors);
     _menuCheckInsideColor      = CommandDraw.MenuCheckInsideColor(track, _256Colors);
     _trackMenuCheckInsideColor = CommandDraw.TrackMenuCheckInsideColor(track, _256Colors);
 }
Exemple #4
0
 /// <summary>
 /// Reset the colors based on the base.
 /// </summary>
 /// <param name="baseColor">Base color.</param>
 public void DefineBaseColors(Color baseColor)
 {
     _baseColor          = baseColor;
     _baseDarkColor      = CommandDraw.BaseDarkFromBase(_baseColor, _256Colors);
     _baseDarkerColor    = ColorHelper.MergeColors(_baseColor, 0.95f, _baseDarkColor, .05f);
     _baseLightColor     = CommandDraw.BaseLightFromBase(_baseColor, _256Colors);
     _openBaseColor      = CommandDraw.OpenBaseFromBase(_baseColor, _256Colors);
     _openBorderColor    = CommandDraw.OpenBorderFromBase(_baseColor, _256Colors);
     _menuSeparatorColor = CommandDraw.MenuSeparatorFromBase(_baseColor, _256Colors);
 }
 /// <summary>
 /// Draw the command as a Separator.
 /// </summary>
 /// <param name="g">Graphics reference used in calculations.</param>
 /// <param name="details">Source details needed to perform calculation.</param>
 /// <param name="drawRect">Bounding rectangle for drawing command.</param>
 /// <param name="state">State of the command to be drawn.</param>
 /// <param name="topLevel">Drawing as a top level item.</param>
 public override void Draw(Graphics g,
                           ICommandDetails details,
                           Rectangle drawRect,
                           ItemState state,
                           bool topLevel)
 {
     // Use a helper method for perform drawing
     CommandDraw.DrawSeparatorCommand(g,
                                      details.Style,
                                      details.Direction,
                                      drawRect,
                                      details.SepDarkColor,
                                      details.SepLightColor);
 }
Exemple #6
0
        /// <summary>
        /// Draw the command as a Button.
        /// </summary>
        /// <param name="g">Graphics reference used in calculations.</param>
        /// <param name="details">Source details needed to perform calculation.</param>
        /// <param name="drawRect">Bounding rectangle for drawing command.</param>
        /// <param name="state">State of the command to be drawn.</param>
        /// <param name="topLevel">Drawing as a top level item.</param>
        public override void Draw(Graphics g,
                                  ICommandDetails details,
                                  Rectangle drawRect,
                                  ItemState state,
                                  bool topLevel)
        {
            string       drawText;
            CommandImage drawImage;

            // Decide if the Text of the button should be drawn
            if (details.ImageAndText == ImageAndText.ImageOnly)
            {
                drawText = string.Empty;
            }
            else
            {
                drawText = Text;
            }

            // Decide if the Image of the button should be drawn
            if (details.ImageAndText == ImageAndText.TextOnly)
            {
                drawImage = CommandImage.Empty;
            }
            else
            {
                drawImage = CommandImage;
            }

            // Use the provided layout direction by default
            LayoutDirection direction = details.Direction;

            // Do we need to override for drawing?
            if (details.OnlyHorizontalText)
            {
                direction = LayoutDirection.Horizontal;
            }

            // Use a helper method to draw command appropriately
            CommandDraw.DrawButtonCommand(g, details.Style,
                                          direction, drawRect, state, Enabled,
                                          details.TextEdge, details.Font, details.TextColor,
                                          details.BaseColor, drawText, drawImage, null,
                                          details.TrackBaseColor1, details.TrackBaseColor2,
                                          details.TrackLightColor1, details.TrackLightColor2,
                                          details.TrackLightLightColor1, details.TrackLightLightColor2,
                                          details.TrackDarkColor, _buttonStyle, _pushed, false, false);
        }
Exemple #7
0
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            // Calculate the correct drawing state
            ItemState state;

            // If the mouse is over the button itself
            if (_mouseOver)
            {
                if (_mouseCapture)
                {
                    state = ItemState.Pressed;
                }
                else
                {
                    state = ItemState.HotTrack;
                }
            }
            else
            {
                if (_mouseCapture)
                {
                    state = ItemState.HotTrack;
                }
                else
                {
                    state = ItemState.Normal;
                }
            }

            // Draw the button using helper function
            CommandDraw.DrawButtonCommand(e.Graphics, _colorDetails.Style, _direction,
                                          ClientRectangle, state, (AlwaysDrawEnabled ? true : Enabled),
                                          _textEdge, Font, ForeColor, _colorDetails.BaseColor,
                                          Text, _image, _imageAttr,
                                          _colorDetails.TrackBaseColor1, _colorDetails.TrackBaseColor2,
                                          _colorDetails.TrackLightColor1, _colorDetails.TrackLightColor2,
                                          _colorDetails.TrackLightLightColor1, _colorDetails.TrackLightLightColor2,
                                          _colorDetails.TrackDarkColor, _buttonStyle, _pushed, _staticIDE,
                                          AlwaysDrawBorder);

            base.OnPaint(e);
        }
Exemple #8
0
 private void OnPanelPaintBackground(object sender, PaintEventArgs pevent)
 {
     if ((_style == VisualStyle.Office2003) && _defaultBackColor)
     {
         CommandDraw.DrawGradientBackground(pevent.Graphics,
                                            sender as Control,
                                            _colorDetails.BaseColor,
                                            _colorDetails.BaseColor1,
                                            _colorDetails.BaseColor2,
                                            _office2003GradBack);
     }
     else if ((_style == VisualStyle.IDE2005) && _defaultBackColor)
     {
         CommandDraw.DrawGradientBackground(pevent.Graphics,
                                            sender as Control,
                                            _colorDetails.BaseColor,
                                            _colorDetails.BaseColor1,
                                            _colorDetails.BaseColor2,
                                            _ide2005GradBack);
     }
 }
Exemple #9
0
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            // Do we need to layout controls again?
            if (_layoutRequired)
            {
                LayoutControl();
            }

            if (_details.DefaultBaseColor && (_style == VisualStyle.Office2003))
            {
                CommandDraw.DrawGradientBackground(e.Graphics,
                                                   this,
                                                   _details.BaseColor,
                                                   _details.BaseColor1,
                                                   _details.BaseColor2,
                                                   _office2003GradBack);
            }
            else if (_details.DefaultBaseColor && (_style == VisualStyle.IDE2005))
            {
                CommandDraw.DrawGradientBackground(e.Graphics,
                                                   this,
                                                   _details.BaseColor,
                                                   _details.BaseColor1,
                                                   _details.BaseColor2,
                                                   _ide2005GradBack);
            }
            else
            {
                // Draw the entire clipping rectangle in require base color
                using (SolidBrush backBrush = new SolidBrush(_details.BaseColor))
                    e.Graphics.FillRectangle(backBrush, e.ClipRectangle);
            }

            // Ask each command to draw itself
            foreach (CommandState state in _states)
            {
                state.Draw(e.Graphics, e.ClipRectangle);
            }
        }
Exemple #10
0
        /// <summary>
        /// Raises the PaintBackground event.
        /// </summary>
        /// <param name="pevent">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            // Office2003 style might need to perform its own drawing
            if (_style == VisualStyle.Office2003)
            {
                // If the background color has not be overriden
                if (BackColor == SystemColors.Control)
                {
                    // Draw the invalidate area in the appropriate theme color
                    using (SolidBrush backBrush = new SolidBrush(_colorDetails.BaseColor))
                        pevent.Graphics.FillRectangle(backBrush, pevent.ClipRectangle);

                    // Do not let the base draw!
                    return;
                }
            }
            else if (_style == VisualStyle.IDE2005)
            {
                // If the background color has not be overriden
                if (BackColor == SystemColors.Control)
                {
                    // Use helper function to draw background correctly
                    CommandDraw.DrawGradientBackground(pevent.Graphics,
                                                       this,
                                                       _colorDetails.BaseColor,
                                                       _colorDetails.BaseColor1,
                                                       _colorDetails.BaseColor2,
                                                       true);

                    // Do not let the base draw!
                    return;
                }
            }

            base.OnPaintBackground(pevent);
        }
        /// <summary>
        /// Calculate required drawing size for push button.
        /// </summary>
        /// <param name="g">Graphics reference used in calculations.</param>
        /// <param name="details">Source details needed to perform calculation.</param>
        /// <param name="topLevel">Drawing as a top level item.</param>
        /// <returns>Size of required area for command.</returns>
        public override Size CalculateDrawSize(Graphics g, ICommandDetails details, bool topLevel)
        {
            int width  = 0;
            int height = 0;

            // The size of the button area is calculated as....
            //
            // Size needed for image	(the image is not rotated when shown vertically)
            // Size needed for the text (the text is rotated when shown vertically)
            //

            // Do we have an image that needs positioning?
            if ((Image != null) && (details.ImageAndText != ImageAndText.TextOnly))
            {
                Size imageSize = ImageSpace(details.Style);

                width  = imageSize.Width;
                height = imageSize.Height;

                // With an image we need an extra pixel gap to the left (IDE and Office2003 only)
                if ((details.Style == VisualStyle.IDE) ||
                    (details.Style == VisualStyle.IDE2005) ||
                    (details.Style == VisualStyle.Office2003))
                {
                    width += SPACE_LEFT_EXTRA;
                }
            }

            // Do we have any text to position?
            if ((Text.Length > 0) && (details.ImageAndText != ImageAndText.ImageOnly))
            {
                // Get regular size of the text (horizontally)
                Size textSize = CommandDraw.TextSize(g, details.Font, Text);

                // Are we drawing the contents as if horizontal
                if ((details.Direction == LayoutDirection.Horizontal) || details.OnlyHorizontalText)
                {
                    // Position the text drawn horizontal
                    switch (details.TextEdge)
                    {
                    case TextEdge.Left:
                    case TextEdge.Right:
                        // Increase width by text width
                        width += textSize.Width;

                        // If we have an image as well then need a spacing gap
                        if (Image != null)
                        {
                            width += SPACE_GAP_WIDTH;
                        }

                        // Make sure height is enough for text
                        if (height < textSize.Height)
                        {
                            height = textSize.Height;
                        }
                        break;

                    case TextEdge.Top:
                    case TextEdge.Bottom:
                        // Increase height by text height
                        height += SPACE_HEIGHT + textSize.Height;

                        // If we have an image as well then need a spacing gap
                        if (Image != null)
                        {
                            height += SPACE_HEIGHT;
                        }

                        // Make sure width is enough for text
                        if (width < textSize.Width)
                        {
                            width = textSize.Width;
                        }
                        break;
                    }
                }
                else
                {
                    // Position the text drawn vertical
                    switch (details.TextEdge)
                    {
                    case TextEdge.Left:
                    case TextEdge.Right:
                        // Increase height text height
                        height += textSize.Width;

                        // If we have an image as well then need a spacing gap
                        if (Image != null)
                        {
                            height += SPACE_GAP_WIDTH;
                        }

                        // Make sure width is enough for text
                        if (width < textSize.Height)
                        {
                            width = textSize.Height;
                        }
                        break;

                    case TextEdge.Top:
                    case TextEdge.Bottom:
                        // Increase height by text height
                        width += textSize.Height;

                        // If we have an image as well then need a spacing gap
                        if (Image != null)
                        {
                            width += SPACE_HEIGHT;
                        }

                        // Make sure width is enough for text
                        if (height < textSize.Width)
                        {
                            height = textSize.Width;
                        }
                        break;
                    }
                }
            }

            // Calculate total area using borders and spacing gaps around inner size
            width  += (BORDER_WIDTH * 2) + (SPACE_WIDTH * 2);
            height += (BORDER_HEIGHT * 2) + (SPACE_HEIGHT * 2);

            // The width and height are always the same no matter which direction we are in
            return(new Size(width, height));
        }
Exemple #12
0
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data. </param>
        protected override void OnPaint(PaintEventArgs e)
        {
            Pen borderPen = new Pen(ControlPaint.LightLight(base.ForeColor));

            // Fill background in required color
            if (_style == VisualStyle.IDE)
            {
                using (SolidBrush fillBrush = new SolidBrush(_backIDE))
                    e.Graphics.FillRectangle(fillBrush, this.ClientRectangle);
            }
            else if (_style == VisualStyle.IDE2005)
            {
                borderPen.Dispose();
                if (this.dockingManager.Customize)
                {
                    CommandDraw.DrawGradientBackground(e.Graphics,
                                                       this,
                                                       ColorCustomize.BackColor,
                                                       ColorCustomize.BackColor,
                                                       ColorCustomize.BackColor,
                                                       true);
                    borderPen = new Pen(ColorCustomize.BorderColor);
                }
                else
                {
                    CommandDraw.DrawGradientBackground(e.Graphics,
                                                       this,
                                                       _colorDetails.BaseColor,
                                                       _colorDetails.BaseColor1,
                                                       _colorDetails.BaseColor2,
                                                       true);
                    borderPen = new Pen(SystemColors.ControlDark);
                }
            }
            else if (_style == VisualStyle.Office2003)
            {
                using (SolidBrush fillBrush = new SolidBrush(_colorDetails.BaseColor))
                    e.Graphics.FillRectangle(fillBrush, this.ClientRectangle);

                borderPen.Dispose();
                borderPen = new Pen(_colorDetails.MenuSeparatorColor);
            }
            else
            {
                using (SolidBrush fillBrush = new SolidBrush(this.BackColor))
                    e.Graphics.FillRectangle(fillBrush, this.ClientRectangle);
            }

            // Style specific outline drawing
            DrawOutline(e.Graphics, true);

            // Draw each of the draw objects
            foreach (DrawTab dt in _drawTabs)
            {
                Rectangle drawRect = dt.DrawRect;

                AdjustRectForEdge(ref drawRect);

                // Style specific cell outline drawing
                DrawOutlineForCell(e.Graphics, borderPen, drawRect);

                // Draw the image in the left/top of the cell
                Crownwood.DotNetMagic.Controls.TabPage page = dt.TabPage;

                int xDraw;
                int yDraw;

                switch (_edge)
                {
                case Edge.Left:
                case Edge.Right:
                    xDraw = drawRect.Left + (drawRect.Width - _imageVector) / 2;
                    yDraw = drawRect.Top + _imageGap;
                    break;

                case Edge.Top:
                case Edge.Bottom:
                case Edge.None:
                default:
                    xDraw = drawRect.Left + _imageGap;
                    yDraw = drawRect.Top + (drawRect.Height - _imageVector) / 2;
                    break;
                }

                if ((page.Icon != null) || (page.Image != null) || ((page.ImageIndex != -1) && (page.ImageList != null)))
                {
                    if (page.Icon != null)
                    {
                        // Draw the actual icon
                        e.Graphics.DrawIcon(page.Icon, new Rectangle(xDraw, yDraw, _imageVector, _imageVector));
                    }
                    else
                    {
                        Image drawImage;

                        if (page.Image != null)
                        {
                            drawImage = page.Image;
                        }
                        else
                        {
                            drawImage = page.ImageList.Images[page.ImageIndex];
                        }

                        // Draw the actual image
                        e.Graphics.DrawImage(drawImage, new Rectangle(xDraw, yDraw, _imageVector, _imageVector));

                        // Must dispose of images taken from an image list, as they are copies and not references
                        if (page.Image == null)
                        {
                            drawImage.Dispose();
                        }
                    }
                }

                // Is anything currently selected
                if ((_selectedIndex != -1) || _stubsShowAll)
                {
                    // Is this page selected?
                    if ((page == _tabPages[_selectedIndex]) || _stubsShowAll)
                    {
                        Rectangle textRect;

                        using (StringFormat drawFormat = new StringFormat())
                        {
                            drawFormat.FormatFlags   = StringFormatFlags.NoClip | StringFormatFlags.NoWrap;
                            drawFormat.Alignment     = StringAlignment.Center;
                            drawFormat.LineAlignment = StringAlignment.Center;

                            // Create text drawing rectangle
                            switch (_edge)
                            {
                            case Edge.Left:
                            case Edge.Right:
                                textRect = new Rectangle(drawRect.Left, yDraw + _imageVector + _imageGap,
                                                         drawRect.Width, drawRect.Height - _imageVector - _imageGap * 2);
                                drawFormat.FormatFlags |= StringFormatFlags.DirectionVertical;
                                break;

                            case Edge.Top:
                            case Edge.Bottom:
                            case Edge.None:
                            default:
                                textRect = new Rectangle(xDraw + _imageVector + _imageGap, drawRect.Top,
                                                         drawRect.Width - _imageVector - _imageGap * 2, drawRect.Height);
                                break;
                            }

                            Color brushColor = this.ForeColor;

                            if (_style == VisualStyle.IDE)
                            {
                                brushColor = ControlPaint.Light(brushColor);
                            }

                            using (SolidBrush drawBrush = new SolidBrush(brushColor))
                                e.Graphics.DrawString(page.Title, this.Font, drawBrush, textRect, drawFormat);
                        }
                    }
                }
            }

            borderPen.Dispose();

            // Style specific outline drawing
            DrawOutline(e.Graphics, false);

            base.OnPaint(e);
        }