dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] pnetlib/System.Windows.Forms ButtonBase.cs, 1.12,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnetlib/System.Windows.Forms ButtonBase.cs, 1.12, 1.13 CheckBox.cs, 1.10, 1.11 RadioButton.cs, 1.6, 1.7
Date: Sat, 22 Nov 2003 01:22:04 +0000

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms
In directory subversions:/tmp/cvs-serv9689/System.Windows.Forms

Modified Files:
        ButtonBase.cs CheckBox.cs RadioButton.cs 
Log Message:


Attempt to reduce button flicker by only redrawing when a real state
change occurs.


Index: ButtonBase.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/ButtonBase.cs,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** ButtonBase.cs       21 Nov 2003 06:47:35 -0000      1.12
--- ButtonBase.cs       22 Nov 2003 01:22:01 -0000      1.13
***************
*** 38,44 ****
        internal bool entered;
        internal bool pressed;
!       private bool hasFocus;
        internal MouseButtons button;
        private StringFormat format;
  
        // Contructor.
--- 38,45 ----
        internal bool entered;
        internal bool pressed;
!       internal bool hasFocus;
        internal MouseButtons button;
        private StringFormat format;
+       private ButtonState prevState;
  
        // Contructor.
***************
*** 49,52 ****
--- 50,54 ----
                                imageIndex = -1;
                                textAlign = ContentAlignment.MiddleCenter;
+                               prevState = (ButtonState)(-1);
                                format = new StringFormat();
                                SetStringFormat();
***************
*** 323,326 ****
--- 325,333 ----
                                                }
                                        }
+                                       if(hasFocus)
+                                       {
+                                               // Special flag that indicates 
a focus rectangle.
+                                               state |= (ButtonState)0x20000;
+                                       }
                                }
                                else
***************
*** 398,401 ****
--- 405,411 ----
                                }
  
+                               // Clear the previous state, for non-trivial 
draw detection.
+                               prevState = (ButtonState)(-1);
+ 
                                // Redraw the button.
                                using(Graphics graphics = CreateGraphics())
***************
*** 403,410 ****
                        }
  
        // Override events from the "Control" class.
        protected override void OnEnabledChanged(EventArgs e)
                        {
!                               Redraw();
                                base.OnEnabledChanged(e);
                        }
--- 413,431 ----
                        }
  
+       // Redraw if a non-trivial state change has occurred.
+       internal void RedrawIfChanged()
+                       {
+                               ButtonState state = CalculateState();
+                               if(state != prevState)
+                               {
+                                       Redraw();
+                                       prevState = state;
+                               }
+                       }
+ 
        // Override events from the "Control" class.
        protected override void OnEnabledChanged(EventArgs e)
                        {
!                               RedrawIfChanged();
                                base.OnEnabledChanged(e);
                        }
***************
*** 412,417 ****
                        {
                                hasFocus = true;
!                               if (flatStyle == FlatStyle.Popup)
!                                       Redraw();
                                base.OnGotFocus(e);
                        }
--- 433,437 ----
                        {
                                hasFocus = true;
!                               RedrawIfChanged();
                                base.OnGotFocus(e);
                        }
***************
*** 432,437 ****
                        {
                                hasFocus = false;
!                               if (flatStyle == FlatStyle.Popup)
!                                       Redraw();
                                base.OnLostFocus(e);
                        }
--- 452,456 ----
                        {
                                hasFocus = false;
!                               RedrawIfChanged();
                                base.OnLostFocus(e);
                        }
***************
*** 442,446 ****
                                        button = e.Button;
                                        pressed = true;
!                                       Redraw();
                                }
                                base.OnMouseDown(e);
--- 461,465 ----
                                        button = e.Button;
                                        pressed = true;
!                                       RedrawIfChanged();
                                }
                                base.OnMouseDown(e);
***************
*** 449,453 ****
                        {
                                entered = true;
!                               Redraw();
                                base.OnMouseEnter(e);
                        }
--- 468,472 ----
                        {
                                entered = true;
!                               RedrawIfChanged();
                                base.OnMouseEnter(e);
                        }
***************
*** 455,459 ****
                        {
                                entered = false;
!                               Redraw();
                                base.OnMouseLeave(e);
                        }
--- 474,478 ----
                        {
                                entered = false;
!                               RedrawIfChanged();
                                base.OnMouseLeave(e);
                        }
***************
*** 468,472 ****
                                        button = MouseButtons.None;
                                        pressed = false;
!                                       Redraw();
                                }
                                base.OnMouseUp(e);
--- 487,491 ----
                                        button = MouseButtons.None;
                                        pressed = false;
!                                       RedrawIfChanged();
                                }
                                base.OnMouseUp(e);
***************
*** 474,477 ****
--- 493,497 ----
        protected override void OnPaint(PaintEventArgs e)
                        {
+                               prevState = CalculateState();
                                Draw(e.Graphics);
                                base.OnPaint(e);

Index: CheckBox.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/CheckBox.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** CheckBox.cs 21 Nov 2003 23:44:37 -0000      1.10
--- CheckBox.cs 22 Nov 2003 01:22:01 -0000      1.11
***************
*** 51,54 ****
--- 51,91 ----
                        }
  
+       // Calculate the current state of the button for its visual appearance.
+       internal override ButtonState CalculateState()
+                       {
+                               ButtonState checkState;
+                               if(state == CheckState.Unchecked)
+                               {
+                                       checkState = ButtonState.Normal;
+                               }
+                               else if(state == CheckState.Checked)
+                               {
+                                       checkState = ButtonState.Checked;
+                               }
+                               else if(state == CheckState.Indeterminate)
+                               {
+                                       // Special flag for 
"IThemePainter.DrawCheckBox".
+                                       checkState = ButtonState.Checked | 
(ButtonState)0x10000;
+                               }
+                               if(pressed && entered)
+                               {
+                                       checkState |= ButtonState.Pushed;
+                               }
+                               if(!Enabled)
+                               {
+                                       checkState |= ButtonState.Inactive;
+                               }
+                               if(FlatStyle == FlatStyle.Flat)
+                               {
+                                       checkState |= ButtonState.Flat;
+                               }
+                               if(hasFocus)
+                               {
+                                       // Special flag that indicates a focus 
rectangle.
+                                       checkState |= (ButtonState)0x20000;
+                               }
+                               return checkState;
+                       }
+ 
        // Draw the contents of this check box.
        internal override void Draw(Graphics graphics)
***************
*** 112,141 ****
                                                break;
                                }
!                               ButtonState checkState;
!                               if(state == CheckState.Unchecked)
!                               {
!                                       checkState = ButtonState.Normal;
!                               }
!                               else if(state == CheckState.Checked)
!                               {
!                                       checkState = ButtonState.Checked;
!                               }
!                               else if(state == CheckState.Indeterminate)
!                               {
!                                       // Special flag for 
"IThemePainter.DrawCheckBox".
!                                       checkState = ButtonState.Checked | 
(ButtonState)0x10000;
!                               }
!                               if(pressed && entered)
!                               {
!                                       checkState |= ButtonState.Pushed;
!                               }
!                               if(!Enabled)
!                               {
!                                       checkState |= ButtonState.Inactive;
!                               }
!                               if(FlatStyle == FlatStyle.Flat)
!                               {
!                                       checkState |= ButtonState.Flat;
!                               }
                                ControlPaint.DrawCheckBox
                                        (graphics, checkX, checkY,
--- 149,153 ----
                                                break;
                                }
!                               ButtonState checkState = CalculateState();
                                ControlPaint.DrawCheckBox
                                        (graphics, checkX, checkY,
***************
*** 340,344 ****
                                                state = value;
                                                bool checkedAfter = (state != 
CheckState.Unchecked);
!                                               Redraw();
                                                if(checkedBefore != 
checkedAfter)
                                                {
--- 352,356 ----
                                                state = value;
                                                bool checkedAfter = (state != 
CheckState.Unchecked);
!                                               RedrawIfChanged();
                                                if(checkedBefore != 
checkedAfter)
                                                {

Index: RadioButton.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/RadioButton.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** RadioButton.cs      21 Nov 2003 23:44:37 -0000      1.6
--- RadioButton.cs      22 Nov 2003 01:22:01 -0000      1.7
***************
*** 189,193 ****
                                        // Record the value and redraw this 
radio button.
                                        isChecked = value;
!                                       Redraw();
  
                                        // Disable the other radio buttons in 
the group.
--- 189,193 ----
                                        // Record the value and redraw this 
radio button.
                                        isChecked = value;
!                                       RedrawIfChanged();
  
                                        // Disable the other radio buttons in 
the group.
***************
*** 273,276 ****
--- 273,281 ----
                                                state |= ButtonState.Pushed;
                                        }
+                                       if(hasFocus)
+                                       {
+                                               // Special flag that indicates 
a focus rectangle.
+                                               state |= (ButtonState)0x20000;
+                                       }
                                }
                                else
***************
*** 483,490 ****
--- 488,497 ----
        protected override void OnEnter(EventArgs e)
                        {
+                       #if false       // TODO: uncomment once "MouseButtons" 
works
                                if(MouseButtons == MouseButtons.None)
                                {
                                        OnClick(e);
                                }
+                       #endif
                                base.OnEnter(e);
                        }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]