Esempio n. 1
0
 private void DrawMenuItem(Graphics g, Rectangle bounds, ButtonSelectedState state)
 {
     if (state == ButtonSelectedState.Pressed)
     {
         bounds.Inflate(-1, -1);
         using (Brush backBrush = new SolidBrush(this.MenuImageMarginColor))
             g.FillRectangle(backBrush, bounds);
         // draw connecting frame
         if (this.MenuImageMarginColor != Color.Transparent)
         {
             using (Pen framePen = new Pen(this.MenuBorderColorDark))
                 g.DrawLine(framePen, new Point(24, bounds.Y), new Point(24, bounds.Height));
         }
     }
     else if (state == ButtonSelectedState.Focused)
     {
         DrawSelectorBar(g, bounds);
     }
 }
Esempio n. 2
0
 protected override void OnMouseUp(MouseEventArgs e)
 {
     _bCheckState = !_bCheckState;
     if (CheckStyle && _bCheckState && _eButtonStyle == ButtonStyle.MediaButton)
         _eButtonState = ButtonSelectedState.Checked;
     else
         _eButtonState = ButtonSelectedState.Depressed;
     DrawButton();
     base.OnMouseUp(e);
 }
Esempio n. 3
0
 protected override void OnMouseLeave(EventArgs e)
 {
     if (this.Focused && this.FocusOnHover && _eButtonStyle == ButtonStyle.CustomButton)
     {
         _eButtonState = ButtonSelectedState.Focused;
     }
     else if (!(this.Focused && _eButtonStyle == ButtonStyle.MenuButton))
     {
         _eButtonState = ButtonSelectedState.None;
         Repaint();
     }
     base.OnMouseLeave(e);
 }
Esempio n. 4
0
 protected override void OnMouseHover(EventArgs e)
 {
     if (!this.Focused && this.FocusOnHover && _eButtonStyle == ButtonStyle.CustomButton)
     {
         this.Focus();
     }
     else if (!(this.Focused && _eButtonStyle == ButtonStyle.MenuButton))
     {
         _eButtonState = ButtonSelectedState.Hover;
         DrawButton();
     }
     base.OnMouseHover(e);
 }
Esempio n. 5
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     // if !FocusOnClick, let it run, go to focus on first click w/ menu style
     if (_eButtonStyle == ButtonStyle.MenuButton && !this.Focused && !this.FocusOnClick)
     {
         base.OnMouseDown(e);
     }
     else
     {
         _eButtonState = ButtonSelectedState.Pressed;
         DrawButton();
         base.OnMouseDown(e);
     }
 }
Esempio n. 6
0
 protected override void OnLostFocus(EventArgs e)
 {
     _eButtonState = ButtonSelectedState.None;
     Repaint();
     base.OnLostFocus(e);
 }
Esempio n. 7
0
 protected override void OnGotFocus(EventArgs e)
 {
     if (_eButtonStyle == ButtonStyle.MenuButton)
     {
         if (_bHasInitialized && this.Visible)
         {
             if (this.FocusOnClick)
             {
                 MouseButtons mb = MouseButtons;
                 if (mb != MouseButtons.Left)
                     _eButtonState = ButtonSelectedState.Focused;
             }
             else
             {
                 _eButtonState = ButtonSelectedState.Focused;
             }
             Repaint();
         }
     }
     else
     {
         MouseButtons mb = MouseButtons;
         if (mb != MouseButtons.Left)
             _eButtonState = ButtonSelectedState.Focused;
         Repaint();
     }
     base.OnGotFocus(e);
 }
Esempio n. 8
0
 /// <summary>
 /// Dispose resources and timer teardown
 /// </summary>
 private void StopSwishTimer()
 {
     if (_cSwishTimer != null)
     {
         if (_cTempDc != null)
             _cTempDc.Dispose();
         // tear down the timer class
         _cSwishTimer.Reset();
         _cSwishTimer.Tick -= _cSwishTimer_Tick;
         _cSwishTimer.Complete -= _cSwirlTimer_Complete;
         _cSwishTimer.Dispose();
         _cSwishTimer = null;
         _bSwishTimerOn = false;
         _eButtonState = ButtonSelectedState.Focused;
         ClickThis();
         DrawButton();
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Dispose of Fader class and reset
 /// </summary>
 private void StopResizeTimer()
 {
     if (_cResizeTimer != null)
     {
         // tear down the timer class
         _cResizeTimer.Reset();
         _cResizeTimer.Tick -= _cResizeTimer_Tick;
         _cResizeTimer.Complete -= _cResizeTimer_Complete;
         _cResizeTimer.Dispose();
         _cResizeTimer = null;
         _bResizeTimerOn = false;
         _eButtonState = ButtonSelectedState.Focused;
         DrawButton();
         ClickThis();
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Create the GraphicsPath and region, load buffers
 /// </summary>
 private void Init()
 {
     DeInit();
     _bFirstFocus = !this.DesignMode && _bResizeOnLoad;
     // set style
     SetButtonStyle(_eButtonStyle);
     if (_eButtonStyle != ButtonStyle.MenuButton)
     {
         Control ct = (Control)this;
         Rectangle bounds = new Rectangle(0, 0, this.Width, this.Height);
         // create the path and region
         using (Graphics g = Graphics.FromHwnd(this.Handle))
         {
             _gpButtonPath = CreateRoundRectanglePath(g, 0, 0, ct.Bounds.Width, ct.Bounds.Height, CornerRadius);
             _hButtonRegion = new Region(_gpButtonPath);
             ct.Region = _hButtonRegion;
         }
     }
     LoadBuffers();
     _eButtonState = ButtonSelectedState.None;
     _bHasInitialized = true;
 }
Esempio n. 11
0
        /// <summary>
        /// Menu style Render hub
        /// </summary>
        private void DrawMenuButton(Rectangle bounds)
        {
            if (_cButtonDc != null)
            {
                Rectangle imageRect = new Rectangle();
                Rectangle textRect = new Rectangle();

                if (Image != null)
                    imageRect = GetImageRectangle(ImageAlign, bounds, new Rectangle(0, 0, Image.Width, Image.Height));
                if (this.Text.Length != 0)
                {
                    SizeF sz = MeasureText(this.Text);
                    textRect = GetTextRectangle(TextAlign, bounds, new Rectangle(0, 0, (int)sz.Width, (int)sz.Height));
                }

                if (_bFirstFocus)
                    _eButtonState = ButtonSelectedState.Pressed;

                using (Graphics g = Graphics.FromHdc(_cButtonDc.Hdc))
                {
                    switch (_eButtonState)
                    {
                        case ButtonSelectedState.Checked:
                        case ButtonSelectedState.Pressed:
                            {
                                if (_bSwirlTimerOn)
                                    StopSwirlTimer();
                                if (!_bResizeTimerOn)
                                {
                                    // backfill
                                    DrawButtonBackGround(g, bounds);
                                    // draw image
                                    if (ImageFocused != null)
                                        DrawImage(g, ImageFocused, imageRect);
                                    else if (Image != null)
                                        DrawImage(g, Image, imageRect);
                                    // draw mask and border
                                    DrawMenuButtonMask(g, imageRect);
                                    // draw text
                                    if (this.Text.Length != 0)
                                        DrawText(g, this.Text, textRect);
                                    // allow control to load for effect
                                    if (_bFirstFocus)
                                        WaitTimer(2);
                                    // start resize
                                    if (!_bInDesigner)
                                        StartResizeTimer(_bFirstFocus);
                                }
                            }
                            break;

                        case ButtonSelectedState.Depressed:
                            {
                                if (_bResizeTimerOn)
                                    _cResizeTimer.FadeStyle = FadeTimer.FadeType.FadeOut;
                                // draw text
                                if (this.Text.Length != 0)
                                    DrawText(g, this.Text, textRect);
                            }
                            break;

                        case ButtonSelectedState.Disabled:
                            {
                                if (_bSwirlTimerOn)
                                    StopSwirlTimer();
                                DrawButtonBackGround(g, bounds);
                                if (Image != null)
                                    DrawDisabledImage(g, Image, imageRect);
                                // draw text
                                if (this.Text.Length != 0)
                                    DrawText(g, this.Text, textRect);
                            }
                            break;

                        case ButtonSelectedState.Focused:
                            {
                                if (!_bSwirlTimerOn)
                                {
                                    if (_bResizeTimerOn)
                                        StopResizeTimer();
                                    DrawButtonBackGround(g, bounds);
                                    if (ImageFocused != null)
                                        DrawImage(g, ImageFocused, imageRect);
                                    else if (Image != null)
                                        DrawImage(g, Image, imageRect);
                                    DrawMenuButtonMask(g, imageRect);
                                    // draw text
                                    if (this.Text.Length != 0)
                                        DrawText(g, this.Text, textRect);
                                    StartSwirlTimer();
                                }
                            }
                            break;

                        case ButtonSelectedState.Hover:
                            {
                                if (!_bSwirlTimerOn)
                                {
                                    DrawButtonBackGround(g, bounds);
                                    // draw text
                                    if (this.Text.Length != 0)
                                        DrawText(g, this.Text, textRect);
                                    if (Image != null)
                                    {
                                        if (Image.IsAlphaPixelFormat(PixelFormat.Alpha))
                                            DrawImage(g, Image, imageRect);
                                        else
                                            DrawBrightImage(g, Image, imageRect, 0.2f);
                                    }
                                }
                            }
                            break;

                        case ButtonSelectedState.None:
                            {
                                if (_bSwirlTimerOn)
                                    StopSwirlTimer();
                                DrawButtonBackGround(g, bounds);
                                // draw text
                                if (this.Text.Length != 0)
                                    DrawText(g, this.Text, textRect);
                                if (Image != null)
                                {
                                    if (Image.IsAlphaPixelFormat(PixelFormat.Alpha))
                                        AlphaBlend(g, (Bitmap)Image, imageRect, .7f);
                                    else
                                        DrawImage(g, Image, imageRect);
                                }
                            }
                            break;
                    }
                }
                _bFirstFocus = false;

                if (!(_bSwirlTimerOn || _bResizeTimerOn))
                {
                    // draw buffer to control
                    using (Graphics g = Graphics.FromHwnd(this.Handle))
                    {
                        BitBlt(g.GetHdc(), 0, 0, _cButtonDc.Width, _cButtonDc.Height, _cButtonDc.Hdc, 0, 0, 0xCC0020);
                        g.ReleaseHdc();
                    }
                    RECT r = new RECT(0, 0, this.Width, this.Height);
                    ValidateRect(this.Handle, ref r);
                }
            }
        }
Esempio n. 12
0
        private void drawMenuItemBackground(Graphics g, Rectangle bounds, ButtonSelectedState state)
        {
            // access current theme choice
            if (MenuStyle == MenuType.Custom)
            {
                if (state == ButtonSelectedState.Pressed)
                {
                    drawPressedButton(g, bounds);
                }
                else if (state == ButtonSelectedState.Focused)
                {
                    if (ButtonHoverEffect == ButtonHoverType.Bevelled)
                        drawBevelledMask(g, bounds, 10);
                    else if (ButtonHoverEffect == ButtonHoverType.Flat)
                        drawFlatMask(g, bounds, 10);
                    else if (ButtonHoverEffect == ButtonHoverType.Glass)
                        drawGlassButton(g, bounds, 10);
                    else if (ButtonHoverEffect == ButtonHoverType.Glow)
                        drawDiffusedGlow(g, bounds, 10);
                    else if (ButtonHoverEffect == ButtonHoverType.Raised)
                        drawRaisedButton(g, bounds, 10);
                }
            }
            // draw a flat menu
            else if (MenuStyle == MenuType.Office)
            {
                if (state == ButtonSelectedState.Pressed)
                {
                    // draw connecting frame
                    using (Pen framePen = new Pen(Color.LightGray))
                    {
                        g.DrawLine(framePen, new Point(bounds.X, bounds.Y), new Point(bounds.X, bounds.Height));
                        g.DrawLine(framePen, new Point(bounds.X + 1, bounds.Y), new Point(bounds.Width - 1, bounds.Y));
                        g.DrawLine(framePen, new Point(bounds.Width - 1, bounds.Y + 1), new Point(bounds.Width - 1, bounds.Height - 1));
                    }

                    bounds.Inflate(-1, -1);
                    using (Brush backBrush = new SolidBrush(MenuImageMarginGradientBegin))
                        g.FillRectangle(backBrush, bounds);
                }
                else if (state == ButtonSelectedState.Focused)
                {
                    drawOfficeMenuButton(g, bounds);
                }
            }
            // draw office style menu
            else if (MenuStyle == MenuType.Flat)
            {
                // flat style menu button
                if ((state == ButtonSelectedState.Pressed) || (state == ButtonSelectedState.Focused))
                    drawFlatMask(g, bounds, 10);
            }
            // draw vista style menu
            else if (MenuStyle == MenuType.Vista)
            {
                // draw a raised style menu button
                if ((state == ButtonSelectedState.Pressed) || (state == ButtonSelectedState.Focused))
                    drawVistaMenuButton(g, bounds);
            }
        }