Fattakh wrote something
This commit is contained in:
parent
e98fbe06d9
commit
cfe68e39cc
@ -1,49 +1,571 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
<Window
|
||||
FontFamily="Consolas"
|
||||
FontSize="24"
|
||||
Height="750"
|
||||
Title="SharpCalculator"
|
||||
Width="600"
|
||||
mc:Ignorable="d"
|
||||
x:Class="SharpCalculator.Avalonia.MainWindow"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" Width="400" Height="500"
|
||||
x:Class="SharpCalculator.Avalonia.MainWindow"
|
||||
Title="SharpCalculator"
|
||||
FontFamily="Consolas"
|
||||
FontSize="24">
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>4* 1* 4*</Grid.RowDefinitions>
|
||||
<TextBox Name="Input" TextChanged="Input_OnTextChanged"/>
|
||||
<TextBlock Grid.Row="1" VerticalAlignment="Center">=</TextBlock>
|
||||
<TextBox Name="Output" Grid.Row="1"
|
||||
Margin="16 0 0 0"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<Grid
|
||||
HorizontalAlignment="Center"
|
||||
Margin="20"
|
||||
VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>* * * * * * *</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>* * * * * * * * * *</Grid.RowDefinitions>
|
||||
|
||||
<!-- 1st row -->
|
||||
|
||||
<TextBlock
|
||||
FontSize="40"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="7"
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Right"
|
||||
Name="Input"
|
||||
Text="" />
|
||||
|
||||
<!-- 2nd row -->
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="ClearButton_OnClick"
|
||||
Content="AC"
|
||||
Grid.Column="0"
|
||||
Grid.Row="2"
|
||||
Name="ClearButton"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="("
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
IsReadOnly="True"
|
||||
BorderThickness="0"
|
||||
/>
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions> * * * * </Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions> * * * * * </Grid.RowDefinitions>
|
||||
<Button Grid.Row="1" Grid.Column="0" Click="MathButton_OnClick">7</Button>
|
||||
<Button Grid.Row="1" Grid.Column="1" Click="MathButton_OnClick">8</Button>
|
||||
<Button Grid.Row="1" Grid.Column="2" Click="MathButton_OnClick">9</Button>
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content=")"
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="MathButton_OnClick"
|
||||
Content="/"
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button Grid.Row="2" Grid.Column="0" Click="MathButton_OnClick">4</Button>
|
||||
<Button Grid.Row="2" Grid.Column="1" Click="MathButton_OnClick">5</Button>
|
||||
<Button Grid.Row="2" Grid.Column="2" Click="MathButton_OnClick">6</Button>
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="^"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button Grid.Row="3" Grid.Column="0" Click="MathButton_OnClick">1</Button>
|
||||
<Button Grid.Row="3" Grid.Column="1" Click="MathButton_OnClick">2</Button>
|
||||
<Button Grid.Row="3" Grid.Column="2" Click="MathButton_OnClick">3</Button>
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="sin"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button Grid.Row="4" Grid.Column="0" Click="MathButton_OnClick">0</Button>
|
||||
<Button Grid.Row="4" Grid.Column="1" Click="MathButton_OnClick">.</Button>
|
||||
<Button Grid.Row="4" Grid.Column="2" Click="MathButton_OnClick">^</Button>
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="asin"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button Grid.Row="1" Grid.Column="3" Click="MathButton_OnClick">/</Button>
|
||||
<Button Grid.Row="2" Grid.Column="3" Click="MathButton_OnClick">*</Button>
|
||||
<Button Grid.Row="3" Grid.Column="3" Click="MathButton_OnClick">-</Button>
|
||||
<Button Grid.Row="4" Grid.Column="3" Click="MathButton_OnClick">+</Button>
|
||||
<!-- 3rd row -->
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="0" Click="ClearButton_OnClick">CLR</Button>
|
||||
<Button Grid.Row="0" Grid.Column="2" Click="MathButton_OnClick">(</Button>
|
||||
<Button Grid.Row="0" Grid.Column="3" Click="MathButton_OnClick">)</Button>
|
||||
</Grid>
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="7"
|
||||
CornerRadius="30"
|
||||
Grid.Column="0"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="8"
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="9"
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="MathButton_OnClick"
|
||||
Content="*"
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="e"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="cos"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="acos"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<!-- 4th row -->
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="4"
|
||||
CornerRadius="30"
|
||||
Grid.Column="0"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="5"
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="6"
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="MathButton_OnClick"
|
||||
Content="-"
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="10^x"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="tan"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="atan"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<!-- 5th row -->
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="1"
|
||||
CornerRadius="30"
|
||||
Grid.Column="0"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="2"
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="3"
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="MathButton_OnClick"
|
||||
Content="+"
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="rand"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="ctg"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="actg"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<!-- 6th row -->
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="0"
|
||||
CornerRadius="30"
|
||||
Grid.Column="0"
|
||||
Grid.Row="6"
|
||||
Height="55"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="%"
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="6"
|
||||
Height="55"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="."
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="6"
|
||||
Height="55"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="ResultButton_OnClick"
|
||||
Content="="
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="6"
|
||||
Height="55"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="π"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="6"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="1/x"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="6"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="log"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="6"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
|
||||
<!-- 7th row -->
|
||||
|
||||
<TextBlock
|
||||
FontSize="25"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="7"
|
||||
Grid.Row="7"
|
||||
Name="History1"
|
||||
Text="" />
|
||||
|
||||
<!-- 8th row -->
|
||||
|
||||
<TextBlock
|
||||
FontSize="25"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="7"
|
||||
Grid.Row="8"
|
||||
Name="History2"
|
||||
Text="" />
|
||||
|
||||
<!-- 9th row -->
|
||||
|
||||
<TextBlock
|
||||
FontSize="25"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="7"
|
||||
Grid.Row="9"
|
||||
Name="History3"
|
||||
Text="" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@ -1,14 +1,33 @@
|
||||
// This implementation of the calculator using
|
||||
// multi-translating programming language Fusion.
|
||||
// The main logic was written on the Fusion,
|
||||
// then retranslated into c#, 'out' module in FusionCalculator
|
||||
// is a translated c# code, that used by SharpCalculator module.
|
||||
// If you want to dive into the logic of the calculator,
|
||||
// you need to check 'out' folder in FusionCalculator module.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using FusionCalculator;
|
||||
using Avalonia.Media;
|
||||
|
||||
|
||||
namespace SharpCalculator.Avalonia;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
static Random _random = new Random(); // Random object for rand() function in calculator
|
||||
double _randomNumber = _random.NextDouble(); // Random variable is between 0 to 1
|
||||
private int _currentIndex = 0; // Current index for checking the length of input text, accordingly for clear button
|
||||
|
||||
private List<string> _history = new List<string>();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -16,32 +35,95 @@ public partial class MainWindow : Window
|
||||
|
||||
private void MathButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button)
|
||||
if (sender is not Button button) // Checking if button exist, if not throw Exception
|
||||
throw new Exception();
|
||||
string text = button.Content!.ToString()!;
|
||||
|
||||
string text; // declaring text for using it in switch case
|
||||
|
||||
ClearButton.Content = "AC"; // clear button content changing to Accurate Clear mode
|
||||
|
||||
switch (Input.Text) // Switch case for checking the inputting functions
|
||||
{
|
||||
case "rand": // rand function add random variable from 0 to 1 into Input
|
||||
Input.Text = "";
|
||||
Input.Text += _randomNumber.ToString(CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case "π": // Pi function add pi value into Input
|
||||
Input.Text = "";
|
||||
Input.Text += "3.1415";
|
||||
break;
|
||||
case "e": // euler function add e value into Input
|
||||
Input.Text = "";
|
||||
Input.Text += "2.71828";
|
||||
break;
|
||||
case "10^x": // ten in power of x function
|
||||
Input.Text = "";
|
||||
Input.Text += "10^";
|
||||
break;
|
||||
case "1/x": // one over x function
|
||||
Input.Text = "";
|
||||
Input.Text += "1/";
|
||||
break;
|
||||
default: // if there is no function input, then just input Button content
|
||||
text = button.Content!.ToString()!;
|
||||
Input.Text += text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// Checking the indexes and the emptiness of the input for clearing one by one
|
||||
if (Input.Text != "" && _currentIndex < Input.Text!.Length)
|
||||
{
|
||||
if ((string)ClearButton.Content! == "AC") // if clear button content equal to AC, clear one by one
|
||||
{
|
||||
Input.Text = Input.Text.Remove(_currentIndex, 1);
|
||||
_currentIndex++;
|
||||
}
|
||||
else if ((string)ClearButton.Content! == "C") // if clear button content equal to C, clear all
|
||||
{
|
||||
Input.Text = "";
|
||||
Output.Text = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case when there's no text or all characters are cleared
|
||||
_currentIndex = 0; // Reset the index for the next round
|
||||
}
|
||||
}
|
||||
|
||||
private void Input_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
private void ResultButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if(Input.Text == null)
|
||||
History1.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
History2.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
History3.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
|
||||
if(Input.Text == null) // checking Input for nullability
|
||||
return;
|
||||
string exprStr = Input.Text;
|
||||
string exprStr = Input.Text; // expression variable, for print result
|
||||
try
|
||||
{
|
||||
double rezult = Calculator.Calculate(exprStr);
|
||||
if(!double.IsNaN(rezult))
|
||||
Output.Text = rezult.ToString(CultureInfo.InvariantCulture);
|
||||
double rezult = Calculator.Calculate(exprStr); // result being processed by calculator object that implemented in FusionCalculator Module
|
||||
if (!double.IsNaN(rezult))
|
||||
{
|
||||
Input.Text = rezult.ToString(CultureInfo.InvariantCulture);
|
||||
_history.Add(rezult.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.WriteLine(exception.ToString());
|
||||
Input.Text = "Error: "+exception.Message;
|
||||
}
|
||||
|
||||
// Display the calculation history in the three TextBlocks
|
||||
if (_history.Count > 0)
|
||||
History1.Text = _history[0];
|
||||
if (_history.Count > 1)
|
||||
History2.Text = _history[1];
|
||||
if (_history.Count > 2)
|
||||
History3.Text = _history[2];
|
||||
|
||||
ClearButton.Content = "C"; // if the expression is printed, then change clear button content ot C, for clearing expression totally
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user