/// <summary> /// Mení veľkosť textu v text displeji /// </summary> private void FixAnsFontSize() { string textAnsText = OutputProcessor.RemoveChars(this.text_display.Text, new[] { ',', '-' }); // odstráni nenumerické znaky double size = TextFontSize; if (textAnsText.Length > TextFontLength) { size -= TextFontSizePercentage * (textAnsText.Length - TextFontLength) * ((100 - (textAnsText.Length - TextFontLength) * 2) / 100.0); } this.text_display.FontSize = size; }
/// <summary> /// Formátuje čísla do slovenského formátu /// </summary> /// <param name="value">Čísla na formátovanie vo formáte double</param> /// <returns>Formátované čísla</returns> private string FormatNumericValue(double value) { CultureInfo cultureInfo = new CultureInfo(lang); string formatedValue = value.ToString("R", cultureInfo); // remove non numeric chars except spaces int formatedValueLenght = OutputProcessor.RemoveChars(formatedValue, new[] { ',', '-' }).Length; formatedValue = formatedValueLenght > TextMaxLength || formatedValue.Contains("E") ? value.ToString("g2", cultureInfo) : this.FormatNumericValue(formatedValue); return(formatedValue); }
public MainWindow() { this.InitializeComponent(); this.outputProcessor = new OutputProcessor(this.text_display, this.log_display); this.mathProcessor = new MathProcessor(this.outputProcessor); }
/// <summary> /// Spracovanie stlačených tlačítok /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">KeyEventArgs</param> private void Window_KeyDown(object sender, KeyEventArgs e) { bool shiftPressed = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift; // Vypíš číslo if (!shiftPressed && OutputProcessor.IsNumericKey(e.Key)) { KeyConverter keyConverter = new KeyConverter(); this.outputProcessor.PrintNumber(keyConverter.ConvertToString(e.Key)); } // Vypíš desatinnú čiarku if (!shiftPressed && (e.Key == Key.Decimal || e.Key == Key.OemComma || e.Key == Key.OemPeriod)) { this.outputProcessor.PrintComma(); } // Vypočítaj výsledok if (e.Key == Key.Enter || e.Key == Key.Return || !shiftPressed && e.Key == Key.OemPlus) { this.mathProcessor.CalculateResult(this.GetNumericAns(), false, true); } // Odstráň posledné číslo pomocou backspace if (e.Key == Key.Back) { this.outputProcessor.Backspace(); } // Add if (e.Key == Key.Add || shiftPressed && e.Key == Key.OemPlus) { this.mathProcessor.ProcessAdd(this.GetNumericAns()); } // Substract if (e.Key == Key.Subtract || !shiftPressed && e.Key == Key.OemMinus) { this.mathProcessor.ProcessSubstract(this.GetNumericAns()); } // Multiply if (e.Key == Key.Multiply || shiftPressed && e.Key == Key.D8) { this.mathProcessor.ProcessMultiply(this.GetNumericAns()); } // Divide if (e.Key == Key.Divide || !shiftPressed && e.Key == Key.OemQuestion) { this.mathProcessor.ProcessDivide(this.GetNumericAns()); } // Factorial (Fact) if (shiftPressed && e.Key == Key.D1) { this.mathProcessor.ProcessFact(this.GetNumericAns()); } // Power (Pow) if (shiftPressed && e.Key == Key.D6) { this.mathProcessor.ProcessPow(this.GetNumericAns()); } }
/// <summary> /// Math procesor /// </summary> /// <param name="outputProcessor">Output result procesor</param> public MathProcessor(OutputProcessor outputProcessor) { this.outputProcessor = outputProcessor; this.math = new Math.Math(); }