From d1058d8fd598852a22e3d6d741d945c7f6f8f188 Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 11 Jan 2026 02:21:47 +0500 Subject: [PATCH 1/7] added gitignore to solution folder --- .gitignore | 1 + Evil Calculator.sln | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index ca1c7a3..4827bcb 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +.idea/ diff --git a/Evil Calculator.sln b/Evil Calculator.sln index a95165a..649a94d 100644 --- a/Evil Calculator.sln +++ b/Evil Calculator.sln @@ -5,6 +5,12 @@ VisualStudioVersion = 17.13.35931.197 d17.13 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Evil Calculator", "Evil Calculator\Evil Calculator.csproj", "{942928AE-D155-4E97-A49D-174BFD563AF2}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFolder", "SolutionFolder", "{5F98C4DD-6BD6-4E12-94A8-87FB896463CD}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + README.md = README.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU From e09e81073b621d8248d96c4f1c16ef775e3a9760 Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 11 Jan 2026 02:23:50 +0500 Subject: [PATCH 2/7] removed unnecessary this. and .ToString and type specifying --- Evil Calculator/CalculatorBody.cs | 98 +++++++++++------------ Evil Calculator/EquationManager.cs | 21 +++-- Evil Calculator/ReverseNotattionSolver.cs | 20 ++--- Evil Calculator/Token.cs | 10 ++- 4 files changed, 73 insertions(+), 76 deletions(-) diff --git a/Evil Calculator/CalculatorBody.cs b/Evil Calculator/CalculatorBody.cs index 5f9490b..e7e0873 100644 --- a/Evil Calculator/CalculatorBody.cs +++ b/Evil Calculator/CalculatorBody.cs @@ -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); } diff --git a/Evil Calculator/EquationManager.cs b/Evil Calculator/EquationManager.cs index a5c4d09..ead73d9 100644 --- a/Evil Calculator/EquationManager.cs +++ b/Evil Calculator/EquationManager.cs @@ -2,9 +2,9 @@ { class EquationManager { - private ReverseNotationSolver reverseNotationSolver = new ReverseNotationSolver(); + private ReverseNotationSolver reverseNotationSolver = new(); - List equation = new List(); + List 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; } diff --git a/Evil Calculator/ReverseNotattionSolver.cs b/Evil Calculator/ReverseNotattionSolver.cs index 4cc3d7b..28d16fd 100644 --- a/Evil Calculator/ReverseNotattionSolver.cs +++ b/Evil Calculator/ReverseNotattionSolver.cs @@ -2,9 +2,9 @@ { internal class ReverseNotationSolver { - List equation = new List(); + List equation = new(); - public string? ToReverseNotation(ref List equation) + public string ToReverseNotation(ref List equation) { List TEMP = new List(); Stack OPERATORS = new Stack(); @@ -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()); } @@ -46,9 +46,8 @@ return equationToString(); } - - - public string? Solve(ref List equation) + + public string Solve(ref List equation) { ToReverseNotation(ref equation); Stack stack = new Stack(); @@ -99,18 +98,15 @@ return stack.Pop().value; } - - + 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; } - - } } diff --git a/Evil Calculator/Token.cs b/Evil Calculator/Token.cs index f5d4af0..967185d 100644 --- a/Evil Calculator/Token.cs +++ b/Evil Calculator/Token.cs @@ -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) { From 6d7b57c9f94594fec57e90c06c56fab33438245b Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 11 Jan 2026 02:40:53 +0500 Subject: [PATCH 3/7] first time in my life i found a use case for HashSet --- Evil Calculator/EquationManager.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Evil Calculator/EquationManager.cs b/Evil Calculator/EquationManager.cs index ead73d9..877d5a7 100644 --- a/Evil Calculator/EquationManager.cs +++ b/Evil Calculator/EquationManager.cs @@ -2,6 +2,7 @@ { class EquationManager { + private static readonly HashSet _operators = new() { "+", "-", "*", "/", "^", "√" }; private ReverseNotationSolver reverseNotationSolver = new(); List equation = new(); @@ -173,11 +174,11 @@ outerOperandLabel.Text = currentOperand == "" ? "0" : currentOperand; } } - + private bool IsOperator() { if (equation.Count == 0) return false; - return new[] { "+", "-", "*", "/", "^", "√" }.Contains(equation.Last().value); + return _operators.Contains(equation.Last().value); } private bool IsOpen() From 46dc513e8798351cf7239634ceba734e1dffe82b Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 11 Jan 2026 02:48:15 +0500 Subject: [PATCH 4/7] you don't need to use 'ref' with reference types --- Evil Calculator/CalculatorBody.cs | 2 +- Evil Calculator/EquationManager.cs | 4 ++-- Evil Calculator/ReverseNotattionSolver.cs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Evil Calculator/CalculatorBody.cs b/Evil Calculator/CalculatorBody.cs index e7e0873..4f8d6b9 100644 --- a/Evil Calculator/CalculatorBody.cs +++ b/Evil Calculator/CalculatorBody.cs @@ -200,7 +200,7 @@ currentOperandTextBox.ForeColor = Color.White; CalculatorPanel.Controls.Add(currentOperandTextBox); - equationManager.AcquireOutputLabels(ref equationTextBox, ref currentOperandTextBox); + equationManager.AcquireOutputLabels(equationTextBox, currentOperandTextBox); CalculatorPanel.Show(); diff --git a/Evil Calculator/EquationManager.cs b/Evil Calculator/EquationManager.cs index 877d5a7..ed8d0ac 100644 --- a/Evil Calculator/EquationManager.cs +++ b/Evil Calculator/EquationManager.cs @@ -145,12 +145,12 @@ { if (currentOperand != "") equation.Add(new Token(Token.TokenType.Operand, currentOperand)); buttonEquals.Text = "#"; - currentOperand = reverseNotationSolver.Solve(ref equation); + currentOperand = reverseNotationSolver.Solve(equation); UpdateLabels(); } } - public void AcquireOutputLabels(ref Label equationTextBox, ref Label currentOperandTextBox) + public void AcquireOutputLabels(Label equationTextBox, Label currentOperandTextBox) { outerEquationLabel = equationTextBox; outerOperandLabel = currentOperandTextBox; diff --git a/Evil Calculator/ReverseNotattionSolver.cs b/Evil Calculator/ReverseNotattionSolver.cs index 28d16fd..f68b4a3 100644 --- a/Evil Calculator/ReverseNotattionSolver.cs +++ b/Evil Calculator/ReverseNotattionSolver.cs @@ -4,7 +4,7 @@ { List equation = new(); - public string ToReverseNotation(ref List equation) + public string ToReverseNotation(List equation) { List TEMP = new List(); Stack OPERATORS = new Stack(); @@ -47,9 +47,9 @@ } - public string Solve(ref List equation) + public string Solve(List equation) { - ToReverseNotation(ref equation); + ToReverseNotation(equation); Stack stack = new Stack(); foreach (Token token in this.equation) { From 490dc23027968d088bd69ee7adb47102232e04fd Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 11 Jan 2026 02:54:21 +0500 Subject: [PATCH 5/7] removed "equation" field from PeverseNotationSolver because it is not really used and made this class static --- Evil Calculator/EquationManager.cs | 3 +- Evil Calculator/ReverseNotattionSolver.cs | 51 +++++++++-------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/Evil Calculator/EquationManager.cs b/Evil Calculator/EquationManager.cs index ed8d0ac..4d29c7a 100644 --- a/Evil Calculator/EquationManager.cs +++ b/Evil Calculator/EquationManager.cs @@ -3,7 +3,6 @@ class EquationManager { private static readonly HashSet _operators = new() { "+", "-", "*", "/", "^", "√" }; - private ReverseNotationSolver reverseNotationSolver = new(); List equation = new(); string currentOperand = ""; @@ -145,7 +144,7 @@ { if (currentOperand != "") equation.Add(new Token(Token.TokenType.Operand, currentOperand)); buttonEquals.Text = "#"; - currentOperand = reverseNotationSolver.Solve(equation); + currentOperand = ReverseNotationSolver.Solve(equation); UpdateLabels(); } } diff --git a/Evil Calculator/ReverseNotattionSolver.cs b/Evil Calculator/ReverseNotattionSolver.cs index f68b4a3..0350ac2 100644 --- a/Evil Calculator/ReverseNotattionSolver.cs +++ b/Evil Calculator/ReverseNotattionSolver.cs @@ -1,57 +1,55 @@ namespace Lunar.Evil_Calculator { - internal class ReverseNotationSolver + internal static class ReverseNotationSolver { - List equation = new(); - - public string ToReverseNotation(List equation) + private static List ToReverseNotation(List equation) { - List TEMP = new List(); - Stack OPERATORS = new Stack(); + List reversedEquation = new List(); + Stack operators = new Stack(); foreach (Token token in equation) { if (token.tokenType == Token.TokenType.Operand) { - TEMP.Add(token); + reversedEquation.Add(token); } if (token.tokenType == Token.TokenType.Operator) { if (token.value == "(") { - OPERATORS.Push(token); + operators.Push(token); } else if (token.value == ")") { - while (OPERATORS.Peek().value != "(") + while (operators.Peek().value != "(") { - TEMP.Add(OPERATORS.Pop()); + reversedEquation.Add(operators.Pop()); } - OPERATORS.Pop(); + operators.Pop(); } else { - while (OPERATORS.Count != 0 && OPERATORS.Peek().priority >= token.priority) + while (operators.Count != 0 && operators.Peek().priority >= token.priority) { - TEMP.Add(OPERATORS.Pop()); + reversedEquation.Add(operators.Pop()); } - OPERATORS.Push(token); + operators.Push(token); } } } - while (OPERATORS.Count != 0) + while (operators.Count != 0) { - TEMP.Add(OPERATORS.Pop()); + reversedEquation.Add(operators.Pop()); } - this.equation = TEMP; - return equationToString(); + + return reversedEquation; } - public string Solve(List equation) + public static string Solve(List originalEquation) { - ToReverseNotation(equation); + List reversedEquation = ToReverseNotation(originalEquation); Stack stack = new Stack(); - foreach (Token token in this.equation) + foreach (Token token in reversedEquation) { double result, left, right; if (token.tokenType == Token.TokenType.Operand) @@ -97,16 +95,5 @@ } return stack.Pop().value; } - - - public string equationToString() - { - string equationString = ""; - foreach (Token token in equation) - { - equationString += token.value + " "; - } - return equationString; - } } } From 8f065abb81d5709536814892799c6d2cf8a0bcff Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 11 Jan 2026 02:54:43 +0500 Subject: [PATCH 6/7] it is reverse POLISH notation :nerdy-face: --- Evil Calculator/EquationManager.cs | 2 +- ...rseNotattionSolver.cs => ReversePolishNotationSolver.cs} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename Evil Calculator/{ReverseNotattionSolver.cs => ReversePolishNotationSolver.cs} (94%) diff --git a/Evil Calculator/EquationManager.cs b/Evil Calculator/EquationManager.cs index 4d29c7a..70e8973 100644 --- a/Evil Calculator/EquationManager.cs +++ b/Evil Calculator/EquationManager.cs @@ -144,7 +144,7 @@ { if (currentOperand != "") equation.Add(new Token(Token.TokenType.Operand, currentOperand)); buttonEquals.Text = "#"; - currentOperand = ReverseNotationSolver.Solve(equation); + currentOperand = ReversePolishNotationSolver.Solve(equation); UpdateLabels(); } } diff --git a/Evil Calculator/ReverseNotattionSolver.cs b/Evil Calculator/ReversePolishNotationSolver.cs similarity index 94% rename from Evil Calculator/ReverseNotattionSolver.cs rename to Evil Calculator/ReversePolishNotationSolver.cs index 0350ac2..8f47af1 100644 --- a/Evil Calculator/ReverseNotattionSolver.cs +++ b/Evil Calculator/ReversePolishNotationSolver.cs @@ -1,8 +1,8 @@ namespace Lunar.Evil_Calculator { - internal static class ReverseNotationSolver + internal static class ReversePolishNotationSolver { - private static List ToReverseNotation(List equation) + private static List ToReversePolishNotation(List equation) { List reversedEquation = new List(); Stack operators = new Stack(); @@ -47,7 +47,7 @@ public static string Solve(List originalEquation) { - List reversedEquation = ToReverseNotation(originalEquation); + List reversedEquation = ToReversePolishNotation(originalEquation); Stack stack = new Stack(); foreach (Token token in reversedEquation) { From 3d0138643909f990ba2370c3eeb6d0be79e5326a Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 11 Jan 2026 03:05:50 +0500 Subject: [PATCH 7/7] i want to see numbers, not window behind the calculator --- Evil Calculator/CalculatorBody.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Evil Calculator/CalculatorBody.cs b/Evil Calculator/CalculatorBody.cs index 4f8d6b9..d20a5bd 100644 --- a/Evil Calculator/CalculatorBody.cs +++ b/Evil Calculator/CalculatorBody.cs @@ -16,7 +16,7 @@ { InitializeComponent(); BackColor = LunarGray; - Opacity = 0.75; + Opacity = 0.9; FormBorderStyle = FormBorderStyle.None; ClientSize = new Size(300, 500); Text = "Calculator"; @@ -144,7 +144,6 @@ CalculatorPanel.FormBorderStyle = FormBorderStyle.None; CalculatorPanel.BackColor = Color.Gray; CalculatorPanel.TransparencyKey = CalculatorPanel.BackColor; - CalculatorPanel.Opacity = 0.90; CalculatorPanel.StartPosition = FormStartPosition.Manual; CalculatorPanel.DesktopLocation = new Point(Location.X, Location.Y + 30); CalculatorPanel.ClientSize = new Size(Size.Width, Size.Height - 30);