removed unnecessary this. and .ToString and type specifying
This commit is contained in:
@@ -5,21 +5,21 @@
|
||||
private bool mouseDown;
|
||||
private bool onTop;
|
||||
private Point lastLocation;
|
||||
private static Color LunarGray = System.Drawing.ColorTranslator.FromHtml("#2b292d");
|
||||
private static Color LunarOrange = System.Drawing.ColorTranslator.FromHtml("#ff8700");
|
||||
private static Color LunarGray = ColorTranslator.FromHtml("#2b292d");
|
||||
private static Color LunarOrange = ColorTranslator.FromHtml("#ff8700");
|
||||
|
||||
private Form CalculatorPanel = new Form();
|
||||
private EquationManager equationManager = new EquationManager();
|
||||
private Form CalculatorPanel = new();
|
||||
private EquationManager equationManager = new();
|
||||
|
||||
|
||||
public CalculatorBody()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.BackColor = LunarGray;
|
||||
this.Opacity = 0.75;
|
||||
this.FormBorderStyle = FormBorderStyle.None;
|
||||
this.ClientSize = new Size(300, 500);
|
||||
this.Text = "Calculator";
|
||||
BackColor = LunarGray;
|
||||
Opacity = 0.75;
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
ClientSize = new Size(300, 500);
|
||||
Text = "Calculator";
|
||||
MyTitleBar();
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
TitleBar.MouseDown += TitleBar_MouseDown;
|
||||
TitleBar.MouseMove += TitleBar_MouseMove;
|
||||
TitleBar.MouseUp += TitleBar_MouseUp;
|
||||
this.Controls.Add(TitleBar);
|
||||
Controls.Add(TitleBar);
|
||||
|
||||
Button ButtonMinimize = new Button
|
||||
{
|
||||
@@ -67,7 +67,7 @@
|
||||
};
|
||||
ButtonMinimize.FlatAppearance.BorderSize = 0;
|
||||
ButtonMinimize.FlatAppearance.BorderColor = LunarGray;
|
||||
ButtonMinimize.Click += (s, e) => this.WindowState = FormWindowState.Minimized;
|
||||
ButtonMinimize.Click += (s, e) => WindowState = FormWindowState.Minimized;
|
||||
TitleBar.Controls.Add(ButtonMinimize);
|
||||
|
||||
Button ButtonMaximize = new Button
|
||||
@@ -83,7 +83,7 @@
|
||||
ButtonMaximize.FlatAppearance.BorderColor = LunarGray;
|
||||
ButtonMaximize.Click += (s, e) =>
|
||||
{
|
||||
this.WindowState = (this.WindowState == FormWindowState.Normal) ? FormWindowState.Maximized : FormWindowState.Normal;
|
||||
WindowState = (WindowState == FormWindowState.Normal) ? FormWindowState.Maximized : FormWindowState.Normal;
|
||||
};
|
||||
TitleBar.Controls.Add(ButtonMaximize);
|
||||
|
||||
@@ -98,12 +98,12 @@
|
||||
};
|
||||
ButtonClose.FlatAppearance.BorderSize = 0;
|
||||
ButtonClose.FlatAppearance.BorderColor = LunarGray;
|
||||
ButtonClose.Click += (s, e) => this.Close();
|
||||
ButtonClose.Click += (s, e) => Close();
|
||||
TitleBar.Controls.Add(ButtonClose);
|
||||
|
||||
Label titleLabel = new Label
|
||||
{
|
||||
Text = this.Text,
|
||||
Text = Text,
|
||||
Location = new Point(8, 7),
|
||||
AutoSize = true,
|
||||
ForeColor = Color.White
|
||||
@@ -120,10 +120,10 @@
|
||||
{
|
||||
if (mouseDown)
|
||||
{
|
||||
this.Location = new Point(
|
||||
(this.Location.X - lastLocation.X) + e.X, (this.Location.Y - lastLocation.Y) + e.Y);
|
||||
Location = new Point(
|
||||
(Location.X - lastLocation.X) + e.X, (Location.Y - lastLocation.Y) + e.Y);
|
||||
|
||||
this.Update();
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,9 +134,9 @@
|
||||
|
||||
void Titlebar_BaseTextChanged(object? sender, EventArgs e)
|
||||
{
|
||||
titleLabel.Text = this.Text;
|
||||
titleLabel.Text = Text;
|
||||
}
|
||||
this.TextChanged += Titlebar_BaseTextChanged;
|
||||
TextChanged += Titlebar_BaseTextChanged;
|
||||
}
|
||||
|
||||
private void CalculatorPanelInit()
|
||||
@@ -146,8 +146,8 @@
|
||||
CalculatorPanel.TransparencyKey = CalculatorPanel.BackColor;
|
||||
CalculatorPanel.Opacity = 0.90;
|
||||
CalculatorPanel.StartPosition = FormStartPosition.Manual;
|
||||
CalculatorPanel.DesktopLocation = new Point(this.Location.X, this.Location.Y + 30);
|
||||
CalculatorPanel.ClientSize = new Size(this.Size.Width, this.Size.Height - 30);
|
||||
CalculatorPanel.DesktopLocation = new Point(Location.X, Location.Y + 30);
|
||||
CalculatorPanel.ClientSize = new Size(Size.Width, Size.Height - 30);
|
||||
CalculatorPanel.Owner = this;
|
||||
CalculatorPanel.ShowInTaskbar = false;
|
||||
|
||||
@@ -206,9 +206,9 @@
|
||||
|
||||
void ToggleTopButton_Click(object? sender, EventArgs e)
|
||||
{
|
||||
this.Text = this.onTop ? "Calculator" : "Calculator [pinned]";
|
||||
this.onTop = !this.onTop;
|
||||
this.TopMost = !this.TopMost;
|
||||
Text = onTop ? "Calculator" : "Calculator [pinned]";
|
||||
onTop = !onTop;
|
||||
TopMost = !TopMost;
|
||||
CalculatorPanel.TopMost = !CalculatorPanel.TopMost;
|
||||
}
|
||||
|
||||
@@ -220,16 +220,16 @@
|
||||
public CalculatorButton(string Text, Point Location, Form Panel, EquationManager equationManager)
|
||||
{
|
||||
this.Text = Text;
|
||||
this.Font = new Font("Arial", 12);
|
||||
Font = new Font("Arial", 12);
|
||||
this.Location = Location;
|
||||
this.Width = 50;
|
||||
this.Height = 40;
|
||||
this.FlatStyle = FlatStyle.Flat;
|
||||
this.BackColor = LunarGray;
|
||||
this.FlatAppearance.BorderSize = 0;
|
||||
this.FlatAppearance.BorderColor = LunarGray;
|
||||
Width = 50;
|
||||
Height = 40;
|
||||
FlatStyle = FlatStyle.Flat;
|
||||
BackColor = LunarGray;
|
||||
FlatAppearance.BorderSize = 0;
|
||||
FlatAppearance.BorderColor = LunarGray;
|
||||
ForeColor = Color.White;
|
||||
this.Click += equationManager.ProcessButtonInput;
|
||||
Click += equationManager.ProcessButtonInput;
|
||||
Panel.Controls.Add(this);
|
||||
}
|
||||
}
|
||||
@@ -238,17 +238,17 @@
|
||||
{
|
||||
public EqualsButton(Point Location, Form Panel, EquationManager equationManager)
|
||||
{
|
||||
this.Text = "=";
|
||||
this.Font = new Font("Arial", 12);
|
||||
Text = "=";
|
||||
Font = new Font("Arial", 12);
|
||||
this.Location = Location;
|
||||
this.Width = 50;
|
||||
this.Height = 40;
|
||||
this.FlatStyle = FlatStyle.Flat;
|
||||
this.BackColor = LunarOrange;
|
||||
this.FlatAppearance.BorderSize = 0;
|
||||
this.FlatAppearance.BorderColor = LunarOrange;
|
||||
Width = 50;
|
||||
Height = 40;
|
||||
FlatStyle = FlatStyle.Flat;
|
||||
BackColor = LunarOrange;
|
||||
FlatAppearance.BorderSize = 0;
|
||||
FlatAppearance.BorderColor = LunarOrange;
|
||||
ForeColor = Color.White;
|
||||
this.Click += equationManager.EqualsButtonPressed;
|
||||
Click += equationManager.EqualsButtonPressed;
|
||||
Panel.Controls.Add(this);
|
||||
}
|
||||
}
|
||||
@@ -257,15 +257,15 @@
|
||||
{
|
||||
public ToggleTopButton(Point Location, Form Panel)
|
||||
{
|
||||
this.Text = "Toggle\ntop";
|
||||
this.Font = new Font("Arial", 7);
|
||||
Text = "Toggle\ntop";
|
||||
Font = new Font("Arial", 7);
|
||||
this.Location = Location;
|
||||
this.Width = 50;
|
||||
this.Height = 40;
|
||||
this.FlatStyle = FlatStyle.Flat;
|
||||
this.BackColor = LunarGray;
|
||||
this.FlatAppearance.BorderSize = 0;
|
||||
this.FlatAppearance.BorderColor = LunarGray;
|
||||
Width = 50;
|
||||
Height = 40;
|
||||
FlatStyle = FlatStyle.Flat;
|
||||
BackColor = LunarGray;
|
||||
FlatAppearance.BorderSize = 0;
|
||||
FlatAppearance.BorderColor = LunarGray;
|
||||
ForeColor = Color.White;
|
||||
Panel.Controls.Add(this);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
{
|
||||
class EquationManager
|
||||
{
|
||||
private ReverseNotationSolver reverseNotationSolver = new ReverseNotationSolver();
|
||||
private ReverseNotationSolver reverseNotationSolver = new();
|
||||
|
||||
List<Token> equation = new List<Token>();
|
||||
List<Token> equation = new();
|
||||
string currentOperand = "";
|
||||
Label? outerEquationLabel;
|
||||
Label? outerOperandLabel;
|
||||
@@ -24,11 +24,8 @@
|
||||
|
||||
public void ProcessButtonInput(object? sender, EventArgs e)
|
||||
{
|
||||
Button? buttonPressed = sender as Button;
|
||||
if (buttonPressed != null)
|
||||
if (sender is Button buttonPressed)
|
||||
{
|
||||
|
||||
|
||||
switch (buttonPressed.Text)
|
||||
{
|
||||
//CLEAR
|
||||
@@ -136,26 +133,26 @@
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateLabels();
|
||||
}
|
||||
}
|
||||
|
||||
public void EqualsButtonPressed(object? sender, EventArgs e)
|
||||
{
|
||||
Button? buttonEquals = sender as Button;
|
||||
if (buttonEquals != null)
|
||||
if (sender is Button buttonEquals)
|
||||
{
|
||||
if (currentOperand != "") equation.Add(new Token(Token.TokenType.Operand, currentOperand));
|
||||
buttonEquals.Text = "#";
|
||||
this.currentOperand = reverseNotationSolver.Solve(ref equation);
|
||||
currentOperand = reverseNotationSolver.Solve(ref equation);
|
||||
UpdateLabels();
|
||||
}
|
||||
}
|
||||
|
||||
public void AcquireOutputLabels(ref Label equationTextBox, ref Label currentOperandTextBox)
|
||||
{
|
||||
this.outerEquationLabel = equationTextBox;
|
||||
this.outerOperandLabel = currentOperandTextBox;
|
||||
outerEquationLabel = equationTextBox;
|
||||
outerOperandLabel = currentOperandTextBox;
|
||||
}
|
||||
|
||||
public string equationToString()
|
||||
@@ -163,7 +160,7 @@
|
||||
string equationString = "";
|
||||
foreach (Token token in equation)
|
||||
{
|
||||
equationString += token.value.ToString() + " ";
|
||||
equationString += token.value + " ";
|
||||
}
|
||||
return equationString;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
{
|
||||
internal class ReverseNotationSolver
|
||||
{
|
||||
List<Token> equation = new List<Token>();
|
||||
List<Token> equation = new();
|
||||
|
||||
public string? ToReverseNotation(ref List<Token> equation)
|
||||
public string ToReverseNotation(ref List<Token> equation)
|
||||
{
|
||||
List<Token> TEMP = new List<Token>();
|
||||
Stack<Token> OPERATORS = new Stack<Token>();
|
||||
@@ -30,7 +30,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
while (OPERATORS.Count != 0 ? OPERATORS.Peek().priority >= token.priority : false)
|
||||
while (OPERATORS.Count != 0 && OPERATORS.Peek().priority >= token.priority)
|
||||
{
|
||||
TEMP.Add(OPERATORS.Pop());
|
||||
}
|
||||
@@ -47,8 +47,7 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string? Solve(ref List<Token> equation)
|
||||
public string Solve(ref List<Token> equation)
|
||||
{
|
||||
ToReverseNotation(ref equation);
|
||||
Stack<Token> stack = new Stack<Token>();
|
||||
@@ -100,17 +99,14 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string equationToString()
|
||||
{
|
||||
string equationString = "";
|
||||
foreach (Token token in this.equation)
|
||||
foreach (Token token in equation)
|
||||
{
|
||||
equationString += token.value.ToString() + " ";
|
||||
equationString += token.value + " ";
|
||||
}
|
||||
return equationString;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
{
|
||||
internal class Token
|
||||
{
|
||||
public enum TokenType { Operator, Operand };
|
||||
public enum TokenType
|
||||
{
|
||||
Operator,
|
||||
Operand,
|
||||
}
|
||||
|
||||
public TokenType tokenType;
|
||||
public string value = "";
|
||||
public string value;
|
||||
public int? priority;
|
||||
|
||||
public Token() { }
|
||||
|
||||
public Token(TokenType tokenType, string value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user