/* Read button in a loop */ private void buttonReader() { bool curr = false, prev = false; while (!cts.Token.IsCancellationRequested) { /* Read current button state */ curr = switchPin.read(); if (curr != prev) { if (curr == true && prev == false) { this.currState = BUTTON_STATE.BUTTON_DOWN; stateChanged?.Invoke(BUTTON_STATE.BUTTON_DOWN); } else { this.currState = BUTTON_STATE.BUTTON_UP; stateChanged?.Invoke(BUTTON_STATE.BUTTON_UP); } prev = curr; } Thread.Sleep(1); } }
public void SetActionState(string action, BUTTON_STATE state) { if (actionStates.ContainsKey(action)) { actionStates[action] = state; } }
public Button(Sprite sprite, MouseInput mouseInput) { _buttonSprite = sprite; _buttonSprite.BindParent(this); _mouseInput = mouseInput; _state = BUTTON_STATE.RELEASED; _selection = BUTTON_SELECT.NONE; _lock = LOCK.LOCKED; }
public static bool CheckKeyboardAction(string action, BUTTON_STATE state, KeyBoardComponent kbc) { if (kbc != null) { if (kbc.GetActionState(action) == state) { return(true); } } return(false); }
protected override void onMouse(Point inPosition, bool isPressed) { // We check if the mouse is inside our rectangle if (inPosition.X > AbsolutePosition.X && inPosition.Y > AbsolutePosition.Y && inPosition.X < AbsolutePosition.X + Measure.Width && inPosition.Y < AbsolutePosition.Y + Measure.Height) { if (isPressed == true) { ButtonState = BUTTON_STATE.MOUSE_DOWN; MousePressOnButton = true; } else { ButtonState = BUTTON_STATE.MOUSE_OVER; if (MousePressOnButton == true) { // The mouse was pressed over the button and // now released. This is the usual "click" // of a button MousePressOnButton = false; if (Click != null) { // Execute the Click event Click(); } } } } else { // Mouse is not over our Button ButtonState = BUTTON_STATE.MOUSE_UP; MousePressOnButton = false; } }
protected virtual void OnPress() { _state = BUTTON_STATE.PRESSED; }
/****************************************************** * Function: GetButton * Parameters: * whichPlayer - Players ONE through FOUR * whichButton - A, B, X, Y, Bumper L, Bumper R, * Leftstick Click, Rightstick Click, Start, * Back * whichState - Up or Down * Return: * Returns true or false for the desired state of * the desired button of the desired player * *NOTE* - Any advancement of menus should use A for * confirm and B for cancel as Start and Back are * not Android friendly ******************************************************/ public static bool GetButton(PLAYER_NUMBER whichPlayer, CONTROLLER_BUTTON whichButton, BUTTON_STATE whichState) { bool buttonValue = false; string inputToCheck = "P" + ((int)whichPlayer).ToString() + "_"; switch (whichButton) { case CONTROLLER_BUTTON.A: inputToCheck += "Button_A"; break; case CONTROLLER_BUTTON.B: inputToCheck += "Button_B"; break; case CONTROLLER_BUTTON.X: inputToCheck += "Button_X"; break; case CONTROLLER_BUTTON.Y: inputToCheck += "Button_Y"; break; case CONTROLLER_BUTTON.BUMPER_L: inputToCheck += "Bumper_L"; break; case CONTROLLER_BUTTON.BUMPER_R: inputToCheck += "Bumper_R"; break; case CONTROLLER_BUTTON.START: inputToCheck += "Start"; break; case CONTROLLER_BUTTON.BACK: inputToCheck += "Back"; break; case CONTROLLER_BUTTON.LEFTSTICK_CLICK: inputToCheck += "LeftStick_Click"; break; case CONTROLLER_BUTTON.RIGHTSTICK_CLICK: inputToCheck += "RightStick_Click"; break; default: break; } if (whichState == BUTTON_STATE.DOWN) buttonValue = Input.GetButtonDown(inputToCheck); else if (whichState == BUTTON_STATE.UP) buttonValue = Input.GetButtonUp(inputToCheck); else if (whichState == BUTTON_STATE.HELD) buttonValue = Input.GetButton(inputToCheck); return buttonValue; }
protected virtual void OnRelease() { _state = BUTTON_STATE.RELEASED; }
/// <summary> /// 初期化 /// </summary> public void Init(Func <TTTButton, bool> clickFunc) { m_func = clickFunc; this.State = BUTTON_STATE.EMPTY; this.Text = this.State.ToString(); }
// Update is called once per frame void Update() { currentState = nextState; }
public override void Draw( blindGUILayout parentLayout, bool active ) { // If autosize flag is true, resize button based on idle texture if (m_autoSizeToTexture) { if (m_idleImage != null) { m_size.x = m_idleImage.width; m_size.y = m_idleImage.height; } } SetButtonGraphics( active & m_enabled ); Rect buttonFrame = GetFrame(parentLayout); if (m_enabled && active) { // Toggle button if (m_buttonType == blindGUIButton.BUTTON_TYPE.ToggleButton) { m_pushed = GUI.Toggle(buttonFrame, m_pushed, "",m_style); if (m_pushed) { m_buttonState = blindGUIButton.BUTTON_STATE.Pressed; } else { m_buttonState = blindGUIButton.BUTTON_STATE.Idle; } if ((m_prevPushState != m_pushed) && (m_buttonStateChangedDelegate != null)) { m_buttonStateChangedDelegate(this, m_pushed); } m_prevPushState = m_pushed; // Radio Button } else if (m_buttonType == blindGUIButton.BUTTON_TYPE.RadioButton) { bool m_stateBeforePush = m_pushed; m_pushed = GUI.Toggle(buttonFrame, m_pushed, "",m_style); if (m_stateBeforePush && !m_pushed) { m_pushed = true; } if (!m_stateBeforePush && m_pushed) { m_buttonState = blindGUIButton.BUTTON_STATE.Pressed; foreach (blindGUIButton button in m_radiobuttonsInGroup) { button.m_pushed = false; if (button.m_buttonStateChangedDelegate != null) { button.m_buttonStateChangedDelegate( button, false); } } if (m_buttonStateChangedDelegate != null) { m_buttonStateChangedDelegate(this, m_pushed); } } if (m_pushed) { m_buttonState = blindGUIButton.BUTTON_STATE.Pressed; } else { m_buttonState = blindGUIButton.BUTTON_STATE.Idle; } //m_prevPushState = m_pushed; // Repeat Button } else if (m_buttonType == blindGUIButton.BUTTON_TYPE.RepeatButton) { m_buttonState = blindGUIButton.BUTTON_STATE.Idle; bool buttonResult = GUI.RepeatButton(buttonFrame, "", m_style); if (buttonResult && (m_buttonClickDelegate != null)) { m_buttonClickDelegate(this); } // Default click button } else { m_buttonState = blindGUIButton.BUTTON_STATE.Idle; bool buttonResult = GUI.Button(buttonFrame, "", m_style); if (buttonResult && (m_buttonClickDelegate != null)) { m_buttonClickDelegate(this); } } } else { GUI.Button(buttonFrame, "", m_style); } base.Draw(parentLayout, active & m_enabled); }
public override void Draw(blindGUILayout parentLayout, bool active) { // If autosize flag is true, resize button based on idle texture if (m_autoSizeToTexture) { if (m_idleImage != null) { m_size.x = m_idleImage.width; m_size.y = m_idleImage.height; } } SetButtonGraphics(active & m_enabled); Rect buttonFrame = GetFrame(parentLayout); if (m_enabled && active) { // Toggle button if (m_buttonType == blindGUIButton.BUTTON_TYPE.ToggleButton) { m_pushed = GUI.Toggle(buttonFrame, m_pushed, "", m_style); if (m_pushed) { m_buttonState = blindGUIButton.BUTTON_STATE.Pressed; } else { m_buttonState = blindGUIButton.BUTTON_STATE.Idle; } if ((m_prevPushState != m_pushed) && (m_buttonStateChangedDelegate != null)) { m_buttonStateChangedDelegate(this, m_pushed); } m_prevPushState = m_pushed; // Radio Button } else if (m_buttonType == blindGUIButton.BUTTON_TYPE.RadioButton) { bool m_stateBeforePush = m_pushed; m_pushed = GUI.Toggle(buttonFrame, m_pushed, "", m_style); if (m_stateBeforePush && !m_pushed) { m_pushed = true; } if (!m_stateBeforePush && m_pushed) { m_buttonState = blindGUIButton.BUTTON_STATE.Pressed; foreach (blindGUIButton button in m_radiobuttonsInGroup) { button.m_pushed = false; if (button.m_buttonStateChangedDelegate != null) { button.m_buttonStateChangedDelegate(button, false); } } if (m_buttonStateChangedDelegate != null) { m_buttonStateChangedDelegate(this, m_pushed); } } if (m_pushed) { m_buttonState = blindGUIButton.BUTTON_STATE.Pressed; } else { m_buttonState = blindGUIButton.BUTTON_STATE.Idle; } //m_prevPushState = m_pushed; // Repeat Button } else if (m_buttonType == blindGUIButton.BUTTON_TYPE.RepeatButton) { m_buttonState = blindGUIButton.BUTTON_STATE.Idle; bool buttonResult = GUI.RepeatButton(buttonFrame, "", m_style); if (buttonResult && (m_buttonClickDelegate != null)) { m_buttonClickDelegate(this); } // Default click button } else { m_buttonState = blindGUIButton.BUTTON_STATE.Idle; bool buttonResult = GUI.Button(buttonFrame, "", m_style); if (buttonResult && (m_buttonClickDelegate != null)) { m_buttonClickDelegate(this); } } } else { GUI.Button(buttonFrame, "", m_style); } base.Draw(parentLayout, active & m_enabled); }
public static void changeStateButton(BUTTON_STATE newState) { nextState = newState; }
public void SetAction(string action, BUTTON_STATE state) { ActionStates[action] = state; }
void Start() { instance = this; nextState = BUTTON_STATE.IN_DEFFAULT; }