Example #1
0
 /// <summary>
 /// Gets the button paint indices.
 /// </summary>
 /// <param name="button">The button paint info.</param>
 /// <param name="active">A value indicating whether the button is active.</param>
 /// <param name="buttonIndex">Index of the button icon image strip.</param>
 /// <param name="rendererIndex">Index of the button background image strip.</param>
 private static void GetButtonData(CaptionButtonPaintData button, bool active, out int buttonIndex, out int rendererIndex)
 {
     if (!button.Enabled)
     {
         rendererIndex = -1;
         buttonIndex = 4;
     }
     else if (button.Pressed)
     {
         buttonIndex = active ? 2 : 3;
         rendererIndex = 1;
     }
     else if (button.Hovered)
     {
         buttonIndex = active ? 1 : 3;
         rendererIndex = 0;
     }
     else
     {
         buttonIndex = active ? 0 : 3;
         rendererIndex = -1;
     }
 }
Example #2
0
        /// <summary>
        /// Redraws the non client area.
        /// </summary>
        /// <param name="invalidateBuffer">if set to <c>true</c> the buffer is invalidated.</param>
        /// <returns>true if the original painting should be suppressed otherwise false.</returns>
        private bool NcPaint(bool invalidateBuffer)
        {
            if (!IsProcessNcArea)
                return false;
            bool result = false;

            IntPtr hdc = (IntPtr)0;
            Graphics g = null;
            Region region = null;
            IntPtr hrgn = (IntPtr)0;

            try
            {
                // no drawing needed
                if (_parentForm.MdiParent != null && _parentForm.WindowState == FormWindowState.Maximized)
                {
                    _currentCacheSize = Size.Empty;
                    return false;
                }

                // prepare image bounds
                Size borderSize = FormExtenders.GetBorderSize(_parentForm);
                int captionHeight = FormExtenders.GetCaptionHeight(_parentForm);

                RECT rectScreen = new RECT();
                Win32Api.GetWindowRect(_parentForm.Handle, ref rectScreen);

                Rectangle rectBounds = rectScreen.ToRectangle();
                rectBounds.Offset(-rectBounds.X, -rectBounds.Y);

                // prepare clipping
                Rectangle rectClip = rectBounds;
                region = new Region(rectClip);
                rectClip.Inflate(-borderSize.Width, -borderSize.Height);
                rectClip.Y += captionHeight;
                rectClip.Height -= captionHeight;

                // create graphics handle
                hdc = Win32Api.GetDCEx(_parentForm.Handle, (IntPtr)0,
                    (DCXFlags.DCX_CACHE | DCXFlags.DCX_CLIPSIBLINGS | DCXFlags.DCX_WINDOW));
                g = Graphics.FromHdc(hdc);

                // Apply clipping
                region.Exclude(rectClip);
                hrgn = region.GetHrgn(g);
                Win32Api.SelectClipRgn(hdc, hrgn);

                // create new buffered graphics if needed
                if (_bufferGraphics == null || _currentCacheSize != rectBounds.Size)
                {
                    if (_bufferGraphics != null)
                        _bufferGraphics.Dispose();

                    _bufferGraphics = _bufferContext.Allocate(g, new Rectangle(0, 0,
                                rectBounds.Width, rectBounds.Height));
                    _currentCacheSize = rectBounds.Size;
                    invalidateBuffer = true;
                }

                if (invalidateBuffer)
                {
                    // Create painting meta data for form
                    SkinningFormPaintData paintData = new SkinningFormPaintData(_bufferGraphics.Graphics, rectBounds)
                    {
                        Borders = borderSize,
                        CaptionHeight = captionHeight,
                        Active = _formIsActive,
                        HasMenu = FormExtenders.HasMenu(_parentForm),
                        IconSize = SystemInformation.SmallIconSize,
                        IsSmallCaption =
                            captionHeight ==
                            SystemInformation.ToolWindowCaptionHeight,
                        Text = _parentForm.Text
                    };

                    // create painting meta data for caption buttons
                    if (_captionButtons.Count > 0)
                    {
                        paintData.CaptionButtons = new CaptionButtonPaintData[_captionButtons.Count];
                        for (int i = 0; i < _captionButtons.Count; i++)
                        {
                            CaptionButton button = _captionButtons[i];
                            CaptionButtonPaintData buttonData = new CaptionButtonPaintData(_bufferGraphics.Graphics, button.Bounds)
                            {
                                Pressed = button.Pressed,
                                Hovered = button.Hovered,
                                Enabled = button.Enabled,
                                HitTest = button.HitTest
                            };
                            paintData.CaptionButtons[i] = buttonData;
                        }
                    }

                    // paint
                    result = _manager.CurrentSkin.OnNcPaint(_parentForm, paintData);
                }

                // render buffered graphics 
                if (_bufferGraphics != null)
                    _bufferGraphics.Render(g);
            }
            catch (Exception)
            {// error drawing
                result = false;
            }

            // cleanup data
            if (hdc != (IntPtr)0)
            {
                Win32Api.SelectClipRgn(hdc, (IntPtr)0);
                Win32Api.ReleaseDC(_parentForm.Handle, hdc);
            }
            if (region != null && hrgn != (IntPtr)0)
                region.ReleaseHrgn(hrgn);

            if (region != null)
                region.Dispose();

            if (g != null)
                g.Dispose();

            return result;
        }