Skip to content

Commit db2b533

Browse files
committed
Improved ScrollBarEx update 1
Updated XML Documentation of modified methods. One minor change: check colorsInvalidated inside ResetColors().
1 parent 2090f4e commit db2b533

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

PluginCore/PluginCore/Controls/ScrollBarEx.cs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ScrollBarEx : Control
3232
private Color backColor/* = SystemColors.ActiveBorder*/;
3333
private Color backColorDisabled/* = SystemColors.ControlLight*/;
3434

35-
private bool colorsValidated;
35+
private bool colorsInvalidated;
3636

3737
/// <summary>
3838
/// Resets the component colors to default values.
@@ -50,18 +50,21 @@ private void InitializeColors()
5050
arrowColorPressed = SystemColors.HotTrack;
5151
backColor = SystemColors.Control;
5252
backColorDisabled = SystemColors.ControlLight;
53-
colorsValidated = true;
53+
colorsInvalidated = false;
5454
Invalidate();
5555
}
5656

5757
/// <summary>
58-
/// Validates any unassigned colors to either default to associated colors.
58+
/// Validates any unassigned colors to either default or to associated colors.
5959
/// Calling this method without assigning any new colors will set all colors to default.
60+
/// <para/>
61+
/// Call this method after the theme has been changed.
6062
/// </summary>
6163
public void ValidateColors()
6264
{
63-
if (colorsValidated)
65+
if (!colorsInvalidated)
6466
{
67+
// No colors defined explicitly -> Reset colors to default.
6568
InitializeColors();
6669
return;
6770
}
@@ -73,20 +76,22 @@ public void ValidateColors()
7376
if (foreColorPressed.IsEmpty) foreColorPressed = SystemColors.ControlDarkDark;
7477
if (backColor.IsEmpty) backColor = SystemColors.Control;
7578
if (backColorDisabled.IsEmpty) backColorDisabled = SystemColors.ControlLight;
76-
// new colors
79+
// Newly introduced color options - do not assign default colors. Instead fall back to associated colors
7780
if (foreColorHot.IsEmpty) foreColorHot = foreColor;
7881
if (arrowColor.IsEmpty) arrowColor = foreColor;
7982
if (arrowColorHot.IsEmpty) arrowColorHot = foreColorHot;
8083
if (arrowColorPressed.IsEmpty) arrowColorPressed = foreColorPressed;
8184

82-
colorsValidated = true;
85+
colorsInvalidated = false;
8386
}
8487

8588
/// <summary>
86-
/// Resets all colors to null values.
89+
/// Resets all validated colors to null values. Call this method before setting new colors.
8790
/// </summary>
8891
private void ResetColors()
8992
{
93+
if (colorsInvalidated) return;
94+
9095
curPosColor =
9196
borderColor =
9297
borderColorDisabled =
@@ -99,7 +104,7 @@ private void ResetColors()
99104
backColor =
100105
backColorDisabled =
101106
Color.Empty;
102-
colorsValidated = false;
107+
colorsInvalidated = true;
103108
}
104109

105110
/// <summary>
@@ -237,11 +242,11 @@ private void DrawBackgroundHorizontal(Graphics g, Rectangle rect)
237242
}
238243

239244
/// <summary>
240-
/// Draws the thumb.
245+
/// Draws the vertical thumb.
241246
/// </summary>
242247
/// <param name="g">The <see cref="Graphics"/> used to paint.</param>
243248
/// <param name="rect">The rectangle in which to paint.</param>
244-
/// <param name="state">The <see cref="ScrollBarState"/> of the thumb.</param>
249+
/// <param name="color">The color to draw the thumb with.</param>
245250
private void DrawThumbVertical(Graphics g, Rectangle rect, Color color)
246251
{
247252
var innerRect = new Rectangle(rect.Left + ScaleHelper.Scale(2), rect.Top, rect.Width - ScaleHelper.Scale(4), rect.Height);
@@ -253,11 +258,11 @@ private void DrawThumbVertical(Graphics g, Rectangle rect, Color color)
253258
}
254259

255260
/// <summary>
256-
/// Draws the thumb.
261+
/// Draws the horizontal thumb.
257262
/// </summary>
258263
/// <param name="g">The <see cref="Graphics"/> used to paint.</param>
259264
/// <param name="rect">The rectangle in which to paint.</param>
260-
/// <param name="state">The <see cref="ScrollBarState"/> of the thumb.</param>
265+
/// <param name="color">The color to draw the thumb with.</param>
261266
private void DrawThumbHorizontal(Graphics g, Rectangle rect, Color color)
262267
{
263268
var innerRect = new Rectangle(rect.Left, rect.Top + ScaleHelper.Scale(2), rect.Width, rect.Height - ScaleHelper.Scale(4));
@@ -268,11 +273,11 @@ private void DrawThumbHorizontal(Graphics g, Rectangle rect, Color color)
268273
}
269274

270275
/// <summary>
271-
/// Draws an arrow button.
276+
/// Draws arrow buttons for vertical scroll bar.
272277
/// </summary>
273278
/// <param name="g">The <see cref="Graphics"/> used to paint.</param>
274279
/// <param name="rect">The rectangle in which to paint.</param>
275-
/// <param name="state">The <see cref="ScrollBarArrowButtonState"/> of the arrow button.</param>
280+
/// <param name="color">The color to draw the arrow buttons with.</param>
276281
/// <param name="arrowUp">true for an up arrow, false otherwise.</param>
277282
private void DrawArrowButtonVertical(Graphics g, Rectangle rect, Color color, bool arrowUp)
278283
{
@@ -310,11 +315,11 @@ private void DrawArrowButtonVertical(Graphics g, Rectangle rect, Color color, bo
310315
}
311316

312317
/// <summary>
313-
/// Draws an arrow button.
318+
/// Draws arrow buttons for horizontal scroll bar.
314319
/// </summary>
315320
/// <param name="g">The <see cref="Graphics"/> used to paint.</param>
316321
/// <param name="rect">The rectangle in which to paint.</param>
317-
/// <param name="state">The <see cref="ScrollBarArrowButtonState"/> of the arrow button.</param>
322+
/// <param name="color">The color to draw the arrow buttons with.</param>
318323
/// <param name="arrowUp">true for an up arrow, false otherwise.</param>
319324
private void DrawArrowButtonHorizontal(Graphics g, Rectangle rect, Color color, bool arrowUp)
320325
{
@@ -886,7 +891,7 @@ public Color BorderColor
886891
}
887892
set
888893
{
889-
if (colorsValidated) ResetColors();
894+
ResetColors();
890895
this.borderColor = value;
891896
this.Invalidate();
892897
}
@@ -906,7 +911,7 @@ public Color DisabledBorderColor
906911
}
907912
set
908913
{
909-
if (colorsValidated) ResetColors();
914+
ResetColors();
910915
this.borderColorDisabled = value;
911916
this.Invalidate();
912917
}
@@ -926,7 +931,7 @@ public override Color BackColor
926931
}
927932
set
928933
{
929-
if (colorsValidated) ResetColors();
934+
ResetColors();
930935
this.backColor = value;
931936
this.Invalidate();
932937
}
@@ -946,7 +951,7 @@ public Color DisabledBackColor
946951
}
947952
set
948953
{
949-
if (colorsValidated) ResetColors();
954+
ResetColors();
950955
this.backColorDisabled = value;
951956
this.Invalidate();
952957
}
@@ -966,7 +971,7 @@ public override Color ForeColor
966971
}
967972
set
968973
{
969-
if (colorsValidated) ResetColors();
974+
ResetColors();
970975
this.foreColor = value;
971976
this.Invalidate();
972977
}
@@ -983,7 +988,7 @@ public Color HotForeColor
983988
get { return this.foreColorHot; }
984989
set
985990
{
986-
if (colorsValidated) ResetColors();
991+
ResetColors();
987992
this.foreColorHot = value;
988993
this.Invalidate();
989994
}
@@ -1003,7 +1008,7 @@ public Color ActiveForeColor
10031008
}
10041009
set
10051010
{
1006-
if (colorsValidated) ResetColors();
1011+
ResetColors();
10071012
this.foreColorPressed = value;
10081013
this.Invalidate();
10091014
}
@@ -1020,7 +1025,7 @@ public Color ArrowColor
10201025
get { return this.arrowColor; }
10211026
set
10221027
{
1023-
if (colorsValidated) ResetColors();
1028+
ResetColors();
10241029
this.arrowColor = value;
10251030
this.Invalidate();
10261031
}
@@ -1037,7 +1042,7 @@ public Color HotArrowColor
10371042
get { return this.arrowColorHot; }
10381043
set
10391044
{
1040-
if (colorsValidated) ResetColors();
1045+
ResetColors();
10411046
this.arrowColorHot = value;
10421047
this.Invalidate();
10431048
}
@@ -1054,7 +1059,7 @@ public Color ActiveArrowColor
10541059
get { return this.arrowColorPressed; }
10551060
set
10561061
{
1057-
if (colorsValidated) ResetColors();
1062+
ResetColors();
10581063
this.arrowColorPressed = value;
10591064
this.Invalidate();
10601065
}
@@ -1074,7 +1079,7 @@ public Color CurrentPositionColor
10741079
}
10751080
set
10761081
{
1077-
if (colorsValidated) ResetColors();
1082+
ResetColors();
10781083
this.curPosColor = value;
10791084
this.Invalidate();
10801085
}

0 commit comments

Comments
 (0)