Example #1
0
 // Click event handler for the change sign button
 private void change_sign_btn_Click(object sender, EventArgs e)
 {
     // Checks to prevent user error
     if (lastInput == inputTypes.Number || lastInput == inputTypes.RightParen || currentDisplayedInput != "" && currentDisplayedInput[currentDisplayedInput.Length - 1] == '.')
     {
         return;
     }
     currentDisplayedInput = currentDisplayedInput + "-";
     update_calc_output_label();
     lastInput = inputTypes.Operator;
 }
Example #2
0
 // Click event handler for the power button
 private void power_bt_Click(object sender, EventArgs e)
 {
     // Checks to prevent user error
     if (lastInput == inputTypes.Operator || lastInput == inputTypes.LeftParen || lastInput == inputTypes.empty)
     {
         return;
     }
     currentDisplayedInput = currentDisplayedInput + "^";
     update_calc_output_label();
     lastInput = inputTypes.Operator;
 }
Example #3
0
 // Click event handler for the right parenthesis button
 private void right_paren_Click(object sender, EventArgs e)
 {
     // Dont allow right parens without any left parens
     if (LeftParenCount <= 0 || lastInput == inputTypes.LeftParen || lastInput == inputTypes.Operator)
     {
         return;
     }
     currentDisplayedInput = currentDisplayedInput + ")";
     update_calc_output_label();
     lastInput = inputTypes.RightParen;
     // Decrease paren count
     LeftParenCount--;
 }
Example #4
0
 // Click event handler for the left parenthesis button
 private void left_paren_Click(object sender, EventArgs e)
 {
     // Dont allow left parens
     if (lastInput == inputTypes.Number || lastInput == inputTypes.RightParen)
     {
         return;
     }
     currentDisplayedInput = currentDisplayedInput + "(";
     update_calc_output_label();
     lastInput = inputTypes.LeftParen;
     // Increase paren count
     LeftParenCount++;
 }
Example #5
0
        public static void refreshCallbacks(int keyID, inputTypes inputType)
        {
            KeyCode            key  = getKeyNameByID(keyID);
            List <keyRegister> keys = getAllRegisterdByKey(key);

            keycodes.refreshGlobalKeys(keycodes.keys[key], key);
            if (keys.Count > 0)
            {
                foreach (keyRegister rKey in keys)
                {
                    if (rKey.getKeyInputType() != inputTypes.pressed)
                    {
                        // single event
                        keyObj keyobj = keycodes.keys[key];
                        if (rKey.getKeyInputType() == inputTypes.up || rKey.getKeyInputType() == inputTypes.repeatedUp)
                        {
                            if (keyobj.isUp())
                            {
                                rKey.Invoke();
                            }
                        }
                        else
                        {
                            if (keyobj.isDown())
                            {
                                rKey.Invoke();
                            }
                        }
                    }
                    else
                    {
                        // is pressed
                        if (inputType == inputTypes.down)
                        {
                            rKey.Invoke();
                        }
                    }
                }
                cleanListOf(key, inputType);
            }
            if (inputType == inputTypes.up)
            {
                reopenMultipleCallbacks(key);
            }
            // last
            refreshMultipleCallbacks();
        }
Example #6
0
 // Click event handler for the equals/enter button
 private void equals_btn_Click(object sender, EventArgs e)
 {
     if (currentDisplayedInput == "")
     {
         return;
     }
     input_Parsing(currentDisplayedInput);
     // If the displayed value is a number, keep it as the current input
     if (calc_output.Text == "Invalid Input" || calc_output.Text == "Infinity")
     {
         currentDisplayedInput = "";
         lastInput             = inputTypes.empty;
     }
     else
     {
         currentDisplayedInput = calc_output.Text;
         lastInput             = inputTypes.Number;
     }
 }
Example #7
0
        public static void cleanListOf(KeyCode key, inputTypes input, bool force = false)
        {
            bool found = false;

            foreach (keyRegister rKey in registerdKeys)
            {
                if (force)
                {
                    // is key
                    found = true;
                    registerdKeys.Remove(rKey);
                    break;
                }
                else
                if (rKey.getKeyCode() == key && rKey.getKeyInputType() != inputTypes.pressed && rKey.getKeyInputType() != inputTypes.repeatedUp && rKey.getKeyInputType() != inputTypes.repeatedDown)
                {
                    if (input == inputTypes.up)
                    {
                        if (rKey.getKeyInputType() == inputTypes.up || rKey.getKeyInputType() == inputTypes.repeatedUp)
                        {
                            // is key
                            found = true;
                            registerdKeys.Remove(rKey);
                            break;
                        }
                    }
                    else
                    {
                        if (rKey.getKeyInputType() == inputTypes.down || rKey.getKeyInputType() == inputTypes.repeatedDown)
                        {
                            // is key
                            found = true;
                            registerdKeys.Remove(rKey);
                            break;
                        }
                    }
                }
            }
            if (found)
            {
                cleanListOf(key, input, force);
            }
        }
Example #8
0
        // Click event handler for the back button
        private void back_btn_Click(object sender, EventArgs e)
        {
            var delimiters = new[] { ".", "+", "\u2212", "/", "*", "^", "-" };

            if (lastInput == inputTypes.empty)
            {
                return;
            }
            // Remove the last input
            currentDisplayedInput = currentDisplayedInput.Remove(currentDisplayedInput.Length - 1);
            update_calc_output_label();
            // If there is still an item in the currentDisplayedInput, set last input to its type, else set it to empty
            if (currentDisplayedInput != "")
            {
                String pastToken = currentDisplayedInput[currentDisplayedInput.Length - 1].ToString();
                if (delimiters.Contains(pastToken))
                {
                    lastInput = inputTypes.Operator;
                }
                else if (pastToken == "(")
                {
                    lastInput = inputTypes.LeftParen;
                }
                else if (pastToken == ")")
                {
                    lastInput = inputTypes.RightParen;
                }
                else
                {
                    lastInput = inputTypes.Number;
                }
            }
            else
            {
                lastInput = inputTypes.empty;
            }
        }
Example #9
0
 // Click event handler for the clear button
 private void clear_btn_Click(object sender, EventArgs e)
 {
     currentDisplayedInput = "";
     update_calc_output_label();
     lastInput = inputTypes.empty;
 }
Example #10
0
 // Click event handler for the decimal button
 private void decimal_btn_Click(object sender, EventArgs e)
 {
     currentDisplayedInput = currentDisplayedInput + ".";
     update_calc_output_label();
     lastInput = inputTypes.Operator;
 }
Example #11
0
 // Click event handler for the 9 button
 private void num9_btn_Click(object sender, EventArgs e)
 {
     currentDisplayedInput = currentDisplayedInput + "9";
     update_calc_output_label();
     lastInput = inputTypes.Number;
 }
Example #12
0
 public keyRegister(keycodes.registerCallback callback, KeyCode key, inputTypes inputType)
 {
     this.key       = key;
     this.callback  = callback;
     this.inputType = inputType;
 }
Example #13
0
 public static void registerKey(KeyCode key, registerCallback callback, inputTypes inputType)
 {
     registerdKeys.Add(new keyRegister(callback, key, inputType));
 }