Skip to content

Commit

Permalink
Fixed UI bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lich426 committed Sep 29, 2021
1 parent 5b0669d commit b02131d
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 101 deletions.
2 changes: 1 addition & 1 deletion FanCtrl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PublisherName>Lich</PublisherName>
<SuiteName>FanCtrl</SuiteName>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.4.2.0</ApplicationVersion>
<ApplicationVersion>1.4.3.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down
198 changes: 101 additions & 97 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class MainForm : Form
private List<TextBox> mTempNameTextBoxList = new List<TextBox>();
private List<Label> mFanLabelList = new List<Label>();
private List<TextBox> mFanNameTextBoxList = new List<TextBox>();
private List<TextBox> mControlTextBoxList = new List<TextBox>();
private List<NumericUpDown> mControlNumericUpDownList = new List<NumericUpDown>();
private List<Label> mControlLabelList = new List<Label>();
private List<TextBox> mControlNameTextBoxList = new List<TextBox>();

Expand Down Expand Up @@ -131,6 +131,9 @@ protected override void OnLoad(EventArgs e)

this.Resize += (s2, e2) =>
{
if (this.WindowState == FormWindowState.Minimized)
return;
if (mIsUserResize == false)
{
mIsUserResize = true;
Expand Down Expand Up @@ -168,7 +171,7 @@ private void reload()
mTempNameTextBoxList.Clear();
mFanLabelList.Clear();
mFanNameTextBoxList.Clear();
mControlTextBoxList.Clear();
mControlNumericUpDownList.Clear();
mControlLabelList.Clear();
mControlNameTextBoxList.Clear();

Expand All @@ -186,39 +189,45 @@ private void reload()

this.resizeForm();

int checkCount = (mIsFirstLoad == true) ? 3 : 0;
mIsFirstLoad = false;
while (true)
{
// start hardware manager
HardwareManager.getInstance().start();
var task = new Task(delegate {
int checkCount = (mIsFirstLoad == true) ? 3 : 0;
mIsFirstLoad = false;
while (true)
{
// start hardware manager
HardwareManager.getInstance().start();

// set hardware name
bool isDifferent = false;
if (HardwareManager.getInstance().read(ref isDifferent) == false)
break;
// set hardware name
bool isDifferent = false;
if (HardwareManager.getInstance().read(ref isDifferent) == false)
break;

if (isDifferent == true && checkCount > 0)
{
// restart
HardwareManager.getInstance().stop();
Util.sleep(50);
checkCount--;
continue;
if (isDifferent == true && checkCount > 0)
{
// restart
HardwareManager.getInstance().stop();
Util.sleep(50);
checkCount--;
continue;
}
break;
}
break;
}

// set hardware name to file
HardwareManager.getInstance().write();
// set hardware name to file
HardwareManager.getInstance().write();

// read auto fan curve
ControlManager.getInstance().read();
// read auto fan curve
ControlManager.getInstance().read();

// read osd data
OSDManager.getInstance().read();
// read osd data
OSDManager.getInstance().read();

this.onMainLoad();
this.BeginInvoke(new Action(delegate ()
{
this.onMainLoad();
}));
});
task.Start();
}

private void onMainLoad()
Expand Down Expand Up @@ -442,6 +451,19 @@ private void createComponent()
int fanHeight = mFanPanel.Height;
int controlHeight = mControlPanel.Height;

int fontPointY = 0;
float fontSize = 9.0f;
FontFamily fontFamily = null;
try
{
fontFamily = new FontFamily("Gulim");
fontPointY = -5;
}
catch
{
fontFamily = FontFamily.GenericSansSerif;
}

// temperature
int pointY = 15;
for (int i = 0; i < hardwareManager.TempList.Count(); i++)
Expand All @@ -455,7 +477,7 @@ private void createComponent()
libLabel.Text = Define.cLibraryTypeString[i];
libLabel.AutoSize = true;
libLabel.ForeColor = Color.Red;
libLabel.Font = new Font(libLabel.Font, FontStyle.Bold);
libLabel.Font = new Font(fontFamily, fontSize, FontStyle.Bold);
mTempPanel.Controls.Add(libLabel);

var libLabel2 = new Label();
Expand All @@ -478,6 +500,7 @@ private void createComponent()
hardwareLabel.Height = 20;
hardwareLabel.Text = hardwareDevice.Name;
hardwareLabel.ForeColor = Color.Blue;
hardwareLabel.Font = new Font(fontFamily, fontSize, FontStyle.Regular);
mTempPanel.Controls.Add(hardwareLabel);

var hardwareLabel2 = new Label();
Expand All @@ -495,16 +518,17 @@ private void createComponent()
var device = hardwareDevice.DeviceList[k];

var label = new Label();
label.Location = new System.Drawing.Point(3, pointY);
label.Size = new System.Drawing.Size(40, 23);
label.Location = new System.Drawing.Point(0, pointY);
label.Size = new System.Drawing.Size(45, 23);
label.Text = "";
label.AutoSize = false;
label.TextAlign = ContentAlignment.TopRight;
label.Font = new Font(fontFamily, fontSize, FontStyle.Regular);
mTempPanel.Controls.Add(label);
mTempLabelList.Add(label);

var textBox = new TextBox();
textBox.Location = new System.Drawing.Point(label.Right + 5, label.Top - 5);
textBox.Location = new System.Drawing.Point(label.Right + 2, label.Top + fontPointY);
textBox.Size = new System.Drawing.Size(mTempPanel.Width - 70, 23);
textBox.Multiline = false;
textBox.MaxLength = 40;
Expand Down Expand Up @@ -553,7 +577,7 @@ private void createComponent()
libLabel.Text = Define.cLibraryTypeString[i];
libLabel.AutoSize = true;
libLabel.ForeColor = Color.Red;
libLabel.Font = new Font(libLabel.Font, FontStyle.Bold);
libLabel.Font = new Font(fontFamily, fontSize, FontStyle.Bold);
mFanPanel.Controls.Add(libLabel);

var libLabel2 = new Label();
Expand All @@ -576,6 +600,7 @@ private void createComponent()
hardwareLabel.Height = 20;
hardwareLabel.Text = hardwareDevice.Name;
hardwareLabel.ForeColor = Color.Blue;
hardwareLabel.Font = new Font(fontFamily, fontSize, FontStyle.Regular);
mFanPanel.Controls.Add(hardwareLabel);

var hardwareLabel2 = new Label();
Expand All @@ -593,16 +618,17 @@ private void createComponent()
var device = hardwareDevice.DeviceList[k];

var label = new Label();
label.Location = new System.Drawing.Point(3, pointY);
label.Size = new System.Drawing.Size(60, 23);
label.Location = new System.Drawing.Point(0, pointY);
label.Size = new System.Drawing.Size(67, 23);
label.Text = "";
label.AutoSize = false;
label.TextAlign = ContentAlignment.TopRight;
label.Font = new Font(fontFamily, fontSize, FontStyle.Regular);
mFanPanel.Controls.Add(label);
mFanLabelList.Add(label);

var textBox = new TextBox();
textBox.Location = new System.Drawing.Point(label.Right + 5, label.Top - 5);
textBox.Location = new System.Drawing.Point(label.Right + 2, label.Top + fontPointY);
textBox.Size = new System.Drawing.Size(mFanPanel.Width - 90, 23);
textBox.Multiline = false;
textBox.MaxLength = 40;
Expand Down Expand Up @@ -660,7 +686,7 @@ private void createComponent()
libLabel.Text = Define.cLibraryTypeString[i];
libLabel.AutoSize = true;
libLabel.ForeColor = Color.Red;
libLabel.Font = new Font(libLabel.Font, FontStyle.Bold);
libLabel.Font = new Font(fontFamily, fontSize, FontStyle.Bold);
mControlPanel.Controls.Add(libLabel);

var libLabel2 = new Label();
Expand All @@ -683,6 +709,7 @@ private void createComponent()
hardwareLabel.Height = 20;
hardwareLabel.Text = hardwareDevice.Name;
hardwareLabel.ForeColor = Color.Blue;
hardwareLabel.Font = new Font(fontFamily, fontSize, FontStyle.Regular);
mControlPanel.Controls.Add(hardwareLabel);

var hardwareLabel2 = new Label();
Expand All @@ -699,42 +726,59 @@ private void createComponent()
{
var device = (BaseControl)hardwareDevice.DeviceList[k];

var textBox = new TextBox();
textBox.Location = new System.Drawing.Point(10, pointY - 5);
textBox.Size = new System.Drawing.Size(40, 23);
textBox.Multiline = false;
textBox.MaxLength = 3;
textBox.Text = "" + device.Value;
textBox.KeyPress += (object sender, KeyPressEventArgs e) =>
var number = new NumericUpDown();
number.Location = new System.Drawing.Point(10, pointY + fontPointY);
number.Size = new System.Drawing.Size(40, 23);
number.Maximum = 100;
number.Minimum = 0;
number.Value = 0;
number.Increment = 1;

int z = mControlNumericUpDownList.Count;
number.ValueChanged += (object sender, EventArgs e) =>
{
if (e.KeyChar == (char)Keys.Enter)
var tempNumber = (NumericUpDown)sender;
var controlBaseList = hardwareManager.ControlBaseList;
var controlDevice = controlBaseList[z];
int originValue = controlDevice.Value;
int nowValue = Decimal.ToInt32(tempNumber.Value);
int minSpeed = controlBaseList[z].getMinSpeed();
int maxSpeed = controlBaseList[z].getMaxSpeed();
if (nowValue >= minSpeed && nowValue <= maxSpeed)
{
this.onControlTextBoxLeaves(sender, EventArgs.Empty);
int changeValue = hardwareManager.addChangeValue(nowValue, controlDevice);
if (changeValue != originValue)
{
tempNumber.Value = changeValue;
}
Console.WriteLine("numericIndex : " + z);
}
else if (char.IsDigit(e.KeyChar) == false)
else
{
e.Handled = true;
tempNumber.Value = originValue;
mToolTip.Show(minSpeed + " ≤ value ≤ " + maxSpeed, tempNumber, 2000);
}
};
textBox.Leave += onControlTextBoxLeaves;

mControlPanel.Controls.Add(textBox);
mControlTextBoxList.Add(textBox);
mControlPanel.Controls.Add(number);
mControlNumericUpDownList.Add(number);

int minValue = device.getMinSpeed();
int maxValue = device.getMaxSpeed();
var tooltipString = minValue + " ≤ value ≤ " + maxValue;
mToolTip.SetToolTip(textBox, tooltipString);
mToolTip.SetToolTip(number, minValue + " ≤ value ≤ " + maxValue);

var label = new Label();
label.Location = new System.Drawing.Point(textBox.Right + 2, pointY);
label.Location = new System.Drawing.Point(number.Right + 1, pointY);
label.Size = new System.Drawing.Size(15, 23);
label.Text = "%";
label.Font = new Font(fontFamily, fontSize, FontStyle.Regular);
mControlPanel.Controls.Add(label);
mControlLabelList.Add(label);

var textBox2 = new TextBox();
textBox2.Location = new System.Drawing.Point(label.Right + 5, label.Top - 5);
textBox2.Location = new System.Drawing.Point(label.Right + 7, label.Top + fontPointY);
textBox2.Size = new System.Drawing.Size(mControlPanel.Width - 95, 23);
textBox2.Multiline = false;
textBox2.MaxLength = 40;
Expand Down Expand Up @@ -788,46 +832,6 @@ private void createComponent()
this.resizeForm();
}

private void onControlTextBoxLeaves(object sender, EventArgs e)
{
var textBox = (TextBox)sender;
var hardwareManager = HardwareManager.getInstance();
var controlBaseList = hardwareManager.ControlBaseList;

try
{
int value = int.Parse(textBox.Text);
for (int i = 0; i < mControlTextBoxList.Count; i++)
{
if (mControlTextBoxList[i].Equals(sender) == true)
{
var controlDevice = controlBaseList[i];
int originValue = controlDevice.Value;

int minValue = controlBaseList[i].getMinSpeed();
int maxValue = controlBaseList[i].getMaxSpeed();

if (value >= minValue && value <= maxValue)
{
int changeValue = hardwareManager.addChangeValue(value, controlDevice);
if (changeValue != originValue)
{
textBox.Text = changeValue.ToString();
}
}
else
{
textBox.Text = originValue.ToString();
var tooltipString = minValue + " ≤ value ≤ " + maxValue;
mToolTip.Show(tooltipString, textBox, 2000);
}
break;
}
}
}
catch { }
}

private void onNameTextBoxLeaves(TextBox textBox, NAME_TYPE nameType, ref List<TextBox> nameTextBoxList)
{
try
Expand Down Expand Up @@ -905,9 +909,9 @@ private void onUpdate()
for (int i = 0; i < hardwareManager.ControlBaseList.Count; i++)
{
var device = hardwareManager.ControlBaseList[i];
if (mControlTextBoxList[i].Focused == false)
if (mControlNumericUpDownList[i].Focused == false)
{
mControlTextBoxList[i].Text = device.Value.ToString();
mControlNumericUpDownList[i].Value = device.Value;
}
}

Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
[assembly: AssemblyVersion("1.4.2")]
[assembly: AssemblyFileVersion("1.4.2")]
[assembly: AssemblyInformationalVersion("1.4.2")]
[assembly: AssemblyVersion("1.4.3")]
[assembly: AssemblyFileVersion("1.4.3")]
[assembly: AssemblyInformationalVersion("1.4.3")]

0 comments on commit b02131d

Please sign in to comment.