Esempio n. 1
0
        private void HandleModifierPressed(object sender, ModifierPressedEventArgs e)
        {
            switch (e.Modifier)
            {
            case Modifier.Equal:
                if (parenClosed)
                {
                    current           = parenStack[0];
                    this.view.Display = current.Result.ToString("0.####");
                    mode        = Mode.Replace;
                    parenClosed = false;
                    break;
                }

                current.RightOperand = storedOperation;
                this.view.Display    = current.Result.ToString("0.####");
                mode = Mode.Replace;
                break;

            case Modifier.Period:
                current           = storedOperation;
                this.view.Display = current.Result.ToString("0.####");
                mode  = Mode.Replace;
                entry = Entry.Decimal;
                break;

            case Modifier.Invert:
                storedOperation   = storedOperation.Result * -1;
                current           = storedOperation;
                this.view.Display = current.Result.ToString("0.####");
                break;

            case Modifier.OpenParen:
                parenStack.Add(current.Clone());
                parenStackCount++;
                mode = Mode.Replace;
                this.view.Display = "0";
                break;

            case Modifier.ClosedParen:
                parenStackCount--;
                current.RightOperand = storedOperation;
                parenStack[parenStackCount].RightOperand = current;
                parenClosed       = true;
                mode              = Mode.Replace;
                this.view.Display = current.Result.ToString("0.####");
                break;
            }
        }
Esempio n. 2
0
        private void HandleModifierPressed(object sender, ModifierPressedEventArgs e)
        {
            switch (e.Modifier)
            {
            case Modifier.Clear:
                this.view.Display = "";
                mode            = Mode.Replace;
                current         = 0;
                storedOperation = 0;
                parenStack      = new Stack <Operation>();
                parenFlag       = false;
                break;

            case Modifier.Equal:
                if (parenFlag)
                {
                    this.view.Display = current.Result.ToString("0.####");
                    mode      = Mode.Replace;
                    parenFlag = false;
                    break;
                }

                if (equalFlag)
                {
                    UpdateCurrentOperands(current, current.Result, storedOperation);
                }

                current.RightOperand = storedOperation;
                this.view.Display    = current.Result.ToString("0.####");
                equalFlag            = true;
                mode = Mode.Replace;
                break;

            case Modifier.Period:
                current           = storedOperation;
                this.view.Display = current.Result.ToString("0.");
                mode  = Mode.Replace;
                entry = Entry.Decimal;
                break;

            case Modifier.Invert:
                if (current.GetType() == typeof(Constant))
                {
                    current         = current.Result * -1;
                    storedOperation = storedOperation.Result * -1;
                }
                else if (current.LeftOperand == null && current.RightOperand == null)
                {
                    storedOperation = storedOperation.Result * -1;
                }
                else if (current.LeftOperand != null && current.RightOperand == null)
                {
                    current.LeftOperand = current.LeftOperand.Result * -1;
                    storedOperation     = current.LeftOperand;
                }
                else if (current.LeftOperand != null && current.RightOperand != null)
                {
                    current = current.Result * -1;
                }
                this.view.Display = "-" + this.view.Display;
                break;

            case Modifier.OpenParen:
                parenStack.Push(current.Clone());
                current           = 0;
                mode              = Mode.Replace;
                this.view.Display = "0";
                break;

            case Modifier.ClosedParen:
                current.RightOperand = storedOperation;
                var old = parenStack.Pop();
                old.RightOperand  = current;
                this.view.Display = current.Result.ToString("0.####");
                current           = old;
                mode      = Mode.Replace;
                parenFlag = true;
                break;
            }
        }