Skip to content

Commit

Permalink
Added property to NovaWindow.cs and NovaToolWindow.cs that allows for…
Browse files Browse the repository at this point in the history
… visibility of caption button boxes on mouse hover
  • Loading branch information
Lexz-08 committed Aug 4, 2023
1 parent 4788af6 commit fe69769
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Demo/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions NovaUI/Controls/NovaToolWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class NovaToolWindow : Form
private bool _stretchCaptions = false;
private bool _canResize = true;
private bool _animateWindow = false;
private bool _showCaptionBox = true;
private bool _useAeroSnap = true;
private bool _useAeroShadow = true;
private bool _useUserSchemeCursor = true;
Expand Down Expand Up @@ -185,6 +186,16 @@ public bool AnimateWindow
}
}

/// <summary>
/// Gets or sets a value indicating whether button boxes will be displayed when the mouse pointer is hovered over the caption buttons.
/// </summary>
[Category("Appearance"), Description("Gets or sets a value indicating whether button boxes will be displayed when the mouse pointer is hovered over the caption buttons.")]
public bool ShowCaptionBox
{
get => _showCaptionBox;
set { _showCaptionBox = value; Invalidate(); }
}

/// <summary>
/// Gets or sets a value indicating whether the form will utilize Windows Aero snapping.
/// </summary>
Expand Down Expand Up @@ -522,6 +533,7 @@ protected override void OnPaint(PaintEventArgs e)
Size captionIcon = new Size(_headerHeight - (_resizeWidth * 2), _headerHeight - (_resizeWidth * 2));
Point mouse = PointToClient(MousePosition);

if (_showCaptionBox) e.Graphics.FillRectangle(_headerColor.Lighter(_close.Contains(mouse) ? 0.1f : 0).ToBrush(), _close.X, _close.Y - _resizeWidth + 1, _headerHeight, _headerHeight - (_useAeroShadow ? 1 : 2));
if (debug)
{
e.Graphics.FillRectangle(_closeColor.ToBrush(), _close);
Expand All @@ -543,6 +555,7 @@ protected override void OnPaint(PaintEventArgs e)
NewColor = _caption1.Contains(mouse) ? _caption1Color : ForeColor
} });

if (_showCaptionBox) e.Graphics.FillRectangle(_headerColor.Lighter(_caption1.Contains(mouse) ? 0.1f : 0).ToBrush(), _caption1.X, _caption1.Y - _resizeWidth + 1, _headerHeight, _headerHeight - (_useAeroShadow ? 1 : 2));
e.Graphics.DrawImage(_caption1Content,
new Rectangle(_caption1.X + (!_stretchCaptions ? ((_caption1.Width - captionIcon.Width) / 2) : 0), _caption1.Y, !_stretchCaptions ? captionIcon.Width : _caption1.Width, !_stretchCaptions ? captionIcon.Height : _caption1.Height)
.Rescale(-_resizeWidth, _resizeWidth * 2).Rescale(2, -4));
Expand All @@ -560,6 +573,7 @@ protected override void OnPaint(PaintEventArgs e)
NewColor = _caption2.Contains(mouse) ? _caption2Color : ForeColor
} });

if (_showCaptionBox) e.Graphics.FillRectangle(_headerColor.Lighter(_caption2.Contains(mouse) ? 0.1f : 0).ToBrush(), _caption2.X, _caption2.Y - _resizeWidth + 1, _headerHeight, _headerHeight - (_useAeroShadow ? 1 : 2));
e.Graphics.DrawImage(_caption2Content,
new Rectangle(_caption2.X + (!_stretchCaptions ? ((_caption2.Width - captionIcon.Width) / 2) : 0), _caption2.Y, !_stretchCaptions ? captionIcon.Width : _caption2.Width, !_stretchCaptions ? captionIcon.Height : _caption2.Height)
.Rescale(-_resizeWidth, _resizeWidth * 2).Rescale(2, -4));
Expand Down
20 changes: 18 additions & 2 deletions NovaUI/Controls/NovaWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class NovaWindow : Form
private bool _stretchCaptions = false;
private bool _canResize = true;
private bool _animateWindow = false;
private bool _showCaptionBox = true;
private bool _useAeroSnap = true;
private bool _useAeroShadow = true;
private bool _useUserSchemeCursor = true;
Expand Down Expand Up @@ -231,6 +232,16 @@ public bool AnimateWindow
}
}

/// <summary>
/// Gets or sets a value indicating whether button boxes will be displayed when the mouse pointer is hovered over the caption buttons.
/// </summary>
[Category("Appearance"), Description("Gets or sets a value indicating whether button boxes will be displayed when the mouse pointer is hovered over the caption buttons.")]
public bool ShowCaptionBox
{
get => _showCaptionBox;
set { _showCaptionBox = value; Invalidate(); }
}

/// <summary>
/// Gets or sets a value indicating whether the form will utilize Windows Aero snapping.
/// </summary>
Expand Down Expand Up @@ -630,6 +641,7 @@ protected override void OnPaint(PaintEventArgs e)
Size captionIcon = new Size(_headerHeight - (_resizeWidth * 2), _headerHeight - (_resizeWidth * 2));
Point mouse = PointToClient(MousePosition);

if (_showCaptionBox) e.Graphics.FillRectangle(_headerColor.Lighter(_close.Contains(mouse) ? 0.1f : 0).ToBrush(), _close.X, _close.Y - _resizeWidth + 1, _headerHeight, _headerHeight - (_useAeroShadow ? 1 : 2));
if (debug)
{
e.Graphics.FillRectangle(_closeColor.ToBrush(), _close);
Expand All @@ -649,6 +661,7 @@ protected override void OnPaint(PaintEventArgs e)
_maximize = new Rectangle(_close.X - _headerHeight - x, _resizeWidth + y, _headerHeight, _headerHeight - (_resizeWidth * 2));
_minimize = new Rectangle(_maximize.X - _headerHeight - x, _resizeWidth + y, _headerHeight, _headerHeight - (_resizeWidth * 2));

if (_showCaptionBox) e.Graphics.FillRectangle(_headerColor.Lighter(_maximize.Contains(mouse) ? 0.1f : 0).ToBrush(), _maximize.X, _maximize.Y - _resizeWidth + 1, _headerHeight, _headerHeight - (_useAeroShadow ? 1 : 2));
if (debug)
{
e.Graphics.FillRectangle(_maxColor.ToBrush(), _maximize);
Expand All @@ -665,6 +678,7 @@ protected override void OnPaint(PaintEventArgs e)
.Rescale(-_resizeWidth, _resizeWidth * 2));
}

if (_showCaptionBox) e.Graphics.FillRectangle(_headerColor.Lighter(_minimize.Contains(mouse) ? 0.1f : 0).ToBrush(), _minimize.X, _minimize.Y - _resizeWidth + 1, _headerHeight, _headerHeight - (_useAeroShadow ? 1 : 2));
if (debug)
{
e.Graphics.FillRectangle(_minColor.ToBrush(), _minimize);
Expand All @@ -678,7 +692,7 @@ protected override void OnPaint(PaintEventArgs e)

if (_allowCaption1)
{
_caption1 = new Rectangle((MinimizeBox ? _minimize : _close).X - _headerHeight - x, y, _headerHeight, _headerHeight - (_resizeWidth * 2));
_caption1 = new Rectangle((MinimizeBox ? _minimize : _close).X - _headerHeight - x, _resizeWidth + y, _headerHeight, _headerHeight - (_resizeWidth * 2));

ImageAttributes attributes = new ImageAttributes();
attributes.SetRemapTable(new ColorMap[] { new ColorMap
Expand All @@ -687,14 +701,15 @@ protected override void OnPaint(PaintEventArgs e)
NewColor = _caption1.Contains(mouse) ? _caption1Color : ForeColor
} });

if (_showCaptionBox) e.Graphics.FillRectangle(_headerColor.Lighter(_caption1.Contains(mouse) ? 0.1f : 0).ToBrush(), _caption1.X, _caption1.Y - _resizeWidth + 1, _headerHeight, _headerHeight - (_useAeroShadow ? 1 : 2));
e.Graphics.DrawImage(_caption1Content,
new Rectangle(_caption1.X + (!_stretchCaptions ? ((_caption1.Width - captionIcon.Width) / 2) : 0), _caption1.Y, !_stretchCaptions ? captionIcon.Width : _caption1.Width, !_stretchCaptions ? captionIcon.Height : _caption1.Height)
.Rescale(-_resizeWidth, _resizeWidth * 2).Rescale(2, -4));
}

if (_allowCaption2)
{
_caption2 = new Rectangle(_caption1.X - _headerHeight - x, y, _headerHeight, _headerHeight - (_resizeWidth * 2));
_caption2 = new Rectangle(_caption1.X - _headerHeight - x, _resizeWidth + y, _headerHeight, _headerHeight - (_resizeWidth * 2));

ImageAttributes attributes = new ImageAttributes();
attributes.SetRemapTable(new ColorMap[] {
Expand All @@ -704,6 +719,7 @@ protected override void OnPaint(PaintEventArgs e)
NewColor = _caption2.Contains(mouse) ? _caption2Color : ForeColor
} });

if (_showCaptionBox) e.Graphics.FillRectangle(_headerColor.Lighter(_caption2.Contains(mouse) ? 0.1f : 0).ToBrush(), _caption2.X, _caption2.Y - _resizeWidth + 1, _headerHeight, _headerHeight - (_useAeroShadow ? 1 : 2));
e.Graphics.DrawImage(_caption2Content,
new Rectangle(_caption2.X + (!_stretchCaptions ? ((_caption2.Width - captionIcon.Width) / 2) : 0), _caption2.Y, !_stretchCaptions ? captionIcon.Width : _caption2.Width, !_stretchCaptions ? captionIcon.Height : _caption2.Height)
.Rescale(-_resizeWidth, _resizeWidth * 2).Rescale(2, -4));
Expand Down
2 changes: 1 addition & 1 deletion NovaUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2")]
[assembly: AssemblyVersion("1.0.3")]
[assembly: AssemblyFileVersion("1.0.0")]

0 comments on commit fe69769

Please sign in to comment.