Skip to content

Commit

Permalink
Version 3.13.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaskohl committed Aug 17, 2021
1 parent 5623fac commit 0e659b4
Show file tree
Hide file tree
Showing 49 changed files with 4,900 additions and 2,265 deletions.
54 changes: 34 additions & 20 deletions CapsLockIndicatorV3/AdvancedSettings.Designer.cs

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

17 changes: 17 additions & 0 deletions CapsLockIndicatorV3/AdvancedSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public AdvancedSettings()
{
InitializeComponent();

listView1.ContextMenu = contextMenu1;

HandleCreated += (sender, e) =>
{
DarkModeChanged += AdvancedSettings_DarkModeChanged;
Expand Down Expand Up @@ -46,6 +48,8 @@ public AdvancedSettings()
var parts = Regex.Split(ln, "\t+"); // vv just in case vv
propertyDescriptions[parts[0]] = parts[1].Replace("\r", "");
}

pictureBox1.Image = IconExtractor.GetIcon("imageres.dll", 79, 48)?.ToBitmap();
}

private void ListView1_ItemActivate(object sender, EventArgs e)
Expand Down Expand Up @@ -140,6 +144,7 @@ private void AdvancedSettings_DarkModeChanged(object sender, EventArgs e)
richTextLabel1.ForeColor = ForeColor;

checkBox1.FlatStyle = dark ? FlatStyle.Standard : FlatStyle.System;
checkBox1.DarkMode = dark;

ControlScheduleSetDarkMode(checkBox1, dark);
ControlScheduleSetDarkMode(button1, dark);
Expand Down Expand Up @@ -182,5 +187,17 @@ private void listView1_SelectedIndexChanged(object sender, EventArgs e)

richTextLabel1.Rtf = RichTextLabel.ParseFormattedString(propertyDescriptions[key]);
}

private void menuItem1_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count < 1)
return;
var key = listView1.SelectedItems[0].Text;
SettingsManager.Reset(key);
var (newType, newValue) = SettingsManager.GetRaw(key);

listView1.SelectedItems[0].SubItems[1].Text = newType.Name;
listView1.SelectedItems[0].SubItems[2].Text = newValue.ToString();
}
}
}
3 changes: 3 additions & 0 deletions CapsLockIndicatorV3/AdvancedSettings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@
<data name="label3.Text" xml:space="preserve">
<value>Changing advanced settings may cause unexpected behaviour and may lead to an unstable state of CapsLock Indicator. Please restart CapsLock Indicator after changing settings. Only change settings if you know what you are doing! Use this editor at your own risk!</value>
</data>
<metadata name="contextMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
153 changes: 153 additions & 0 deletions CapsLockIndicatorV3/BetterCheckBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CapsLockIndicatorV3
{
public class BetterCheckBox : CheckBox
{
private bool _darkMode;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
public bool DarkMode
{
get => _darkMode;
set
{
_darkMode = value;
Invalidate();
}
}

const int STARTX = 16;
const int STARTY = 1;

private static readonly Color N_Border = Color.FromArgb(137, 137, 137);
private static readonly Color N_Background = Color.FromArgb(0, 0, 0);
private static readonly Color N_Check = Color.FromArgb(222, 222, 222);
private static readonly Color H_Border = Color.FromArgb(102, 132, 156);
private static readonly Color H_Background = Color.FromArgb(0, 30, 53);
private static readonly Color H_Check = Color.FromArgb(166, 196, 220);
private static readonly Color A_Border = Color.FromArgb(74, 83, 91);
private static readonly Color A_Background = Color.FromArgb(0, 9, 16);
private static readonly Color A_Check = Color.FromArgb(120, 130, 187);

public BetterCheckBox() : base()
{
DoubleBuffered = true;
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
}

protected override void OnPaint(PaintEventArgs e)
{
var bgColor = Parent?.BackColor ?? BackColor;

if (!_darkMode)
{
base.OnPaint(e);

if (!Enabled && FlatStyle != FlatStyle.System)
{
e.Graphics.SetClip(new Rectangle(STARTX, 0, Width - STARTX, Height));
e.Graphics.Clear(bgColor);
e.Graphics.ResetClip();
// Use legacy "DrawText" to make it look exactly the same as default
TextRenderer.DrawText(e.Graphics, Text, Font, new Point(STARTX, STARTY), ForeColor.Blend(bgColor, 0.5d));
}
}
else
{

var border = N_Border;
var background = N_Background;
var check = N_Check;
var fg = ForeColor;

if (!Enabled)
{
border = N_Border.Blend(bgColor, 0.5d);
background = N_Background.Blend(bgColor, 0.5d);
check = N_Check.Blend(bgColor, 0.5d);
fg = ForeColor.Blend(bgColor, 0.5d);
}
else if (Native.GetButtonFlag(this, Native.ButtonFlags.MouseDown))
{
border = A_Border;
background = A_Background;
check = A_Check;
}
else if (Native.GetButtonFlag(this, Native.ButtonFlags.MouseOver))
{
border = H_Border;
background = H_Background;
check = H_Check;
}

const int boxSize = 13;
const int boxRectInnerMargin = 2;
const int checkPenWidth = 2;
const int textMargin = 3;

var boxY = Height / 2 - boxSize / 2;

var boxRect = new Rectangle(0, boxY, 13, 13);
var boxRectPen = boxRect;
var boxRectInner = boxRect;
--boxRectPen.Width;
--boxRectPen.Height;
boxRectInner.X += boxRectInnerMargin;
boxRectInner.Y += boxRectInnerMargin;
boxRectInner.Width -= 2 * boxRectInnerMargin;
boxRectInner.Height -= 2 * boxRectInnerMargin;

var checkPoints = new Point[]
{
new Point(boxRectInner.X, boxRectInner.Y + boxRectInner.Height / 2),
new Point(boxRectInner.X + boxRectInner.Width / 3, boxRectInner.Bottom - checkPenWidth),
new Point(boxRectInner.Right - (checkPenWidth / 2), boxRectInner.Y)
};

e.Graphics.Clear(bgColor);

using (var b = new SolidBrush(background))
e.Graphics.FillRectangle(b, boxRect);

using (var p = new Pen(border))
e.Graphics.DrawRectangle(p, boxRectPen);

if (CheckState == CheckState.Indeterminate)
{
using (var b = new SolidBrush(check))
e.Graphics.FillRectangle(b, boxRectInner);
}
else if (CheckState == CheckState.Checked)
{
var _m = e.Graphics.SmoothingMode;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
using (var p = new Pen(check, checkPenWidth))
e.Graphics.DrawLines(p, checkPoints);
e.Graphics.SmoothingMode = _m;
}

var textSz = TextRenderer.MeasureText(e.Graphics, Text, Font);
var textY = Height / 2 - textSz.Height / 2;
var textPt = new Point(boxSize + textMargin, textY);

TextRenderer.DrawText(e.Graphics, Text, Font, textPt, fg);

var focusRect = new Rectangle(textPt, textSz);

if (Focused && ShowFocusCues)
{
ControlPaint.DrawFocusRectangle(e.Graphics, focusRect, fg, bgColor);
}
}
}
}
}
Loading

0 comments on commit 0e659b4

Please sign in to comment.