Ejemplo n.º 1
0
    void Slider::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (getOrientation() == Horizontal)
        {
            if (key.getValue() == Key::Right)
            {
                setValue(getValue() + getStepLength());
                distributeActionEvent();
                keyEvent.consume();
            }
            else if (key.getValue() == Key::Left)
            {
                setValue(getValue() - getStepLength());
                distributeActionEvent();
                keyEvent.consume();
            }            
        }
        else
        {
            if (key.getValue() == Key::Up)
            {
                setValue(getValue() + getStepLength());
                distributeActionEvent();
                keyEvent.consume();
            }
            else if (key.getValue() == Key::Down)
            {
                setValue(getValue() - getStepLength());
                distributeActionEvent();
                keyEvent.consume();
            }
        }
    }
Ejemplo n.º 2
0
// -- KeyListener notifications
void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
{
    gcn::Key key = keyEvent.getKey();

    if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
    {
        if (keyEvent.isShiftPressed())
        {
            const std::string actionEventId = getActionEventId();
            setActionEventId("default");
            distributeActionEvent();
            setActionEventId(actionEventId);
        }
        else
            distributeActionEvent();
    }
    else if (key.getValue() == Key::UP)
        decrementSelected();
    else if (key.getValue() == Key::DOWN)
        incrementSelected();
    else if (key.getValue() == Key::HOME)
        setSelected(0);
    else if (key.getValue() == Key::END)
        setSelected(getListModel()->getNumberOfElements() - 1);
    else
        return;

    keyEvent.consume();
}
Ejemplo n.º 3
0
void IntTextField::keyPressed(gcn::KeyEvent &event)
{
    int action = static_cast<KeyEvent*>(&event)->getActionId();

    if (action == Input::KEY_GUI_DELETE || action == Input::KEY_GUI_BACKSPACE)
    {
        setText(std::string());
        if (mSendAlwaysEvents)
            distributeActionEvent();

        event.consume();
    }

    if (!event.getKey().isNumber())
        return;

    TextField::keyPressed(event);

    std::istringstream s(getText());
    int i;
    s >> i;
    setValue(i);
    if (mSendAlwaysEvents)
        distributeActionEvent();
}
Ejemplo n.º 4
0
    void Slider::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (getOrientation() == HORIZONTAL)
        {
            if (key.getValue() == Key::RIGHT)
            {
                setValue(getValue() + getStepLength());
                distributeActionEvent();
                keyEvent.consume();
            }
            else if (key.getValue() == Key::LEFT)
            {
                setValue(getValue() - getStepLength());
                distributeActionEvent();
                keyEvent.consume();
            }            
        }
        else
        {
            if (key.getValue() == Key::UP)
            {
                setValue(getValue() + getStepLength());
                distributeActionEvent();
                keyEvent.consume();
            }
            else if (key.getValue() == Key::DOWN)
            {
                setValue(getValue() - getStepLength());
                distributeActionEvent();
                keyEvent.consume();
            }
        }
    }
Ejemplo n.º 5
0
void TextSelectDialog::action(const ActionEvent &event)
{
    const std::string &eventId = event.getId();

    if (eventId == "quit")
    {
        close();
        return;
    }

    const int selectedItem = mItemList->getSelected();

    // The following actions require a valid item selection
    if (selectedItem == -1 ||
        selectedItem >= mModel->getNumberOfElements())
    {
        return;
    }
    else if (eventId == "select")
    {
        const int index = mItemList->getSelected();
        if (index < 0 || index >= CAST_S32(mModel->size()))
            return;
        mText = mModel->getElementAt(index);
        distributeActionEvent();
        close();
    }
}
Ejemplo n.º 6
0
    void Slider::mouseWheelMovedDown(MouseEvent& mouseEvent)
    {
        setValue(getValue() - getStepLength());
        distributeActionEvent();

        mouseEvent.consume();
    }
Ejemplo n.º 7
0
void ProfileChooser::action(const gcn::ActionEvent &actionEvent)
{
	std::string tmp_string;
	int buttons = 0;

	/*
	 * Check which button was pressed
	 */
	if ( actionEvent.getId() == "mOk" ) {
		hide ();
		mCancelPressed = false;
	}
	else if ( actionEvent.getId() == "mCancel" ) {
		hide();
		mCancelPressed = true;
	}
	else if ( actionEvent.getId() == "mCreateNew" ) {
		mNewProfile.setVisible ( mCreateNew.isSelected() );
		mNewProfileLabel.setVisible ( mCreateNew.isSelected() );
		return;
	}

	distributeActionEvent();

} /* end action */
Ejemplo n.º 8
0
    void TextField::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::Left)
            mText->setCaretPosition(mText->getCaretPosition() - 1);

        else if (key.getValue() == Key::Right)
            mText->setCaretPosition(mText->getCaretPosition() + 1);

        else if (key.getValue() == Key::Delete && mEditable)
            mText->remove(1);

        else if (key.getValue() == Key::Backspace && mEditable)
            mText->remove(-1);

        else if (key.getValue() == Key::Enter)
            distributeActionEvent();

        else if (key.getValue() == Key::Home)
            mText->setCaretColumn(0);

        else if (key.getValue() == Key::End)
            mText->setCaretColumn(mText->getNumberOfCharacters(0));

        else if (key.isCharacter()
                 && key.getValue() != Key::Tab
                 && mEditable)
            mText->insert(key.getValue());

        if (key.getValue() != Key::Tab)
            keyEvent.consume();

        fixScroll();
    }
Ejemplo n.º 9
0
void
Wellcome::mousePressed(gcn::MouseEvent &event)
{
    gcn::Rectangle d1, d2, d3, d4;
    d1.setAll(mNext->getDimension().x,
              mNext->getDimension().y + getTitleBarHeight(),
              mNext->getDimension().x + mNext->getDimension().width,
              mNext->getDimension().y + mNext->getDimension().height + getTitleBarHeight());
    d2.setAll(mPrev->getDimension().x,
              mPrev->getDimension().y + getTitleBarHeight(),
              mPrev->getDimension().x + mPrev->getDimension().width,
              mPrev->getDimension().y + mPrev->getDimension().height + getTitleBarHeight());
    d3.setAll(mFinish->getDimension().x,
              mFinish->getDimension().y + getTitleBarHeight(),
              mFinish->getDimension().x + mFinish->getDimension().width,
              mFinish->getDimension().y + mFinish->getDimension().height + getTitleBarHeight());
    d4.setAll(mAgain->getDimension().x,
              mAgain->getDimension().y + getTitleBarHeight(),
              mAgain->getDimension().x + mAgain->getDimension().width,
              mAgain->getDimension().y + mAgain->getDimension().height + getTitleBarHeight());

    if(d1.isPointInRect(event.getX(), event.getY()) ||
       d2.isPointInRect(event.getX(), event.getY()) ||
       d3.isPointInRect(event.getX(), event.getY()) ||
       d4.isPointInRect(event.getX(), event.getY()) ||
       event.getY()<getTitleBarHeight())
    {
        Window::mousePressed(event);
        return;
    }
    setActionEventId("next");
    distributeActionEvent();

}
Ejemplo n.º 10
0
 void RadioButton::mouseClicked(MouseEvent& mouseEvent)
 {
     if (mouseEvent.getButton() == MouseEvent::LEFT)
     {
         setSelected(true);
         distributeActionEvent();
     }
 }
Ejemplo n.º 11
0
void ListBox::mouseReleased1(const MouseEvent &event)
{
    if (event.getButton() == MouseButton::LEFT)
    {
        setSelected(std::max(0, getSelectionByMouse(event.getY())));
        distributeActionEvent();
    }
}
Ejemplo n.º 12
0
 void ListBox::mousePressed(MouseEvent& mouseEvent)
 {
     if (mouseEvent.getButton() == MouseEvent::LEFT)
     {
         setSelected(mouseEvent.getY() / getRowHeight());
         distributeActionEvent();
     }
 }
Ejemplo n.º 13
0
    void TextField::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::Left && mCaretPosition > 0)
        {
            --mCaretPosition;
        }

        else if (key.getValue() == Key::Right && mCaretPosition < mText.size())
        {
            ++mCaretPosition;
        }

        else if (key.getValue() == Key::Delete && mCaretPosition < mText.size()
                 && mEditable)
        {
            mText.erase(mCaretPosition, 1);
        }

        else if (key.getValue() == Key::Backspace && mCaretPosition > 0
                 && mEditable)
        {
            mText.erase(mCaretPosition - 1, 1);
            --mCaretPosition;
        }

        else if (key.getValue() == Key::Enter)
        {
            distributeActionEvent();
        }

        else if (key.getValue() == Key::Home)
        {
            mCaretPosition = 0;
        }

        else if (key.getValue() == Key::End)
        {
            mCaretPosition = mText.size();
        }

        else if (key.isCharacter()
                 && key.getValue() != Key::Tab
                 && mEditable)
        {
            mText.insert(mCaretPosition, std::string(1,(char)key.getValue()));
            ++mCaretPosition;
        }

        if (key.getValue() != Key::Tab)
        {
            keyEvent.consume();
        }

        fixScroll();
    }
Ejemplo n.º 14
0
void IntTextField::keyPressed(KeyEvent &event)
{
    const int action = event.getActionId();

    if (action == InputAction::GUI_DELETE
        || action == InputAction::GUI_BACKSPACE)
    {
        setText(std::string());
        if (mSendAlwaysEvents)
            distributeActionEvent();

        event.consume();
    }

#ifdef USE_SDL2
    const int val = event.getKey().getValue();
    if (val != Key::TEXTINPUT)
        return;

    const std::string str = event.getText();
    if (str.empty())
        return;
    const size_t sz = str.size();
    for (size_t f = 0; f < sz; f ++)
    {
        const char chr = str[f];
        if (chr < '0' || chr > '9')
            return;
    }
#else
    if (!event.getKey().isNumber())
        return;
#endif

    TextField::keyPressed(event);

    std::istringstream s(getText());
    int i;
    s >> i;
    setValue(i);
    if (mSendAlwaysEvents)
        distributeActionEvent();
}
Ejemplo n.º 15
0
	void ClickLabel::keyReleased(KeyEvent& keyEvent)
	{
		Key key = keyEvent.getKey();

		if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) && mKeyPressed) {
			mKeyPressed = false;
			distributeActionEvent();
			keyEvent.consume();
		}
	}
Ejemplo n.º 16
0
void ListBox::mouseClicked(gcn::MouseEvent &mouseEvent)
{
    if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
    {
        setSelected(mouseEvent.getY() / getRowHeight());

        if (mouseEvent.getClickCount() == 2)
            distributeActionEvent();
    }
}
Ejemplo n.º 17
0
    void TextField::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::LEFT && mCaretPosition > 0)
        {
            --mCaretPosition;
        }

        else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size())
        {
            ++mCaretPosition;
        }

        else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size())
        {
            mText.erase(mCaretPosition, 1);
        }

        else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0)
        {
            mText.erase(mCaretPosition - 1, 1);
            --mCaretPosition;
        }

        else if (key.getValue() == Key::ENTER)
        {
            distributeActionEvent();
        }

        else if (key.getValue() == Key::HOME)
        {
            mCaretPosition = 0;
        }

        else if (key.getValue() == Key::END)
        {
            mCaretPosition = mText.size();
        }

        else if (key.isCharacter()
                 && key.getValue() != Key::TAB)
        {
            mText.insert(mCaretPosition, std::string(1,(char)key.getValue()));
            ++mCaretPosition;
        }

        if (key.getValue() != Key::TAB)
        {
            keyEvent.consume();
        }
        
        fixScroll();
    }
Ejemplo n.º 18
0
	void ClickLabel::mouseReleased(MouseEvent& mouseEvent)
	{
		if (mouseEvent.getButton() == MouseEvent::LEFT && mMousePressed && mHasMouse) {
			mMousePressed = false;
			distributeActionEvent();
			mouseEvent.consume();
		} else if (mouseEvent.getButton() == MouseEvent::LEFT) {
			mMousePressed = false;
			mouseEvent.consume();
		}
	}
Ejemplo n.º 19
0
    void RadioButton::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::ENTER ||
            key.getValue() == Key::SPACE)
        {
            setSelected(true);
            distributeActionEvent();
            keyEvent.consume();
        }
    }
Ejemplo n.º 20
0
    void ListBox::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
        {
            distributeActionEvent();
            keyEvent.consume();
        }
        else if (key.getValue() == Key::UP)
        {
            setSelected(mSelected - 1);

            if (mSelected == -1)
            {
                if (mWrappingEnabled)
                {
                    setSelected(getListModel()->getNumberOfElements() - 1);
                }
                else
                {
                    setSelected(0);
                }
            }
            
            keyEvent.consume();
        }
        else if (key.getValue() == Key::DOWN)
        {
            if (mWrappingEnabled
                && getSelected() == getListModel()->getNumberOfElements() - 1)
            {
                setSelected(0);
            }
            else
            {
                setSelected(getSelected() + 1);
            }
            
            keyEvent.consume();
        }
        else if (key.getValue() == Key::HOME)
        {
            setSelected(0);
            keyEvent.consume();
        }
        else if (key.getValue() == Key::END)
        {
            setSelected(getListModel()->getNumberOfElements() - 1);
            keyEvent.consume();
        }
    }
Ejemplo n.º 21
0
    void ListBox::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::Enter || key.getValue() == Key::Space)
        {
            distributeActionEvent();
            keyEvent.consume();
        }
        else if (key.getValue() == Key::Up)
        {
            setSelected(mSelected - 1);

            if (mSelected == -1)
            {
                if (mWrappingEnabled)
                {
                    setSelected(getListModel()->getNumberOfElements() - 1);
                }
                else
                {
                    setSelected(0);
                }
            }
            
            keyEvent.consume();
        }
        else if (key.getValue() == Key::Down)
        {
            if (mWrappingEnabled
                && getSelected() == getListModel()->getNumberOfElements() - 1)
            {
                setSelected(0);
            }
            else
            {
                setSelected(getSelected() + 1);
            }
            
            keyEvent.consume();
        }
        else if (key.getValue() == Key::Home)
        {
            setSelected(0);
            keyEvent.consume();
        }
        else if (key.getValue() == Key::End)
        {
            setSelected(getListModel()->getNumberOfElements() - 1);
            keyEvent.consume();
        }
    }
Ejemplo n.º 22
0
    void Button::keyReleased(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if ((key.getValue() == Key::Enter
             || key.getValue() == Key::Space)
            && mKeyPressed)
        {
            mKeyPressed = false;
            distributeActionEvent();
            keyEvent.consume();
        }
    }
Ejemplo n.º 23
0
/*
void GuildListBox::setSelected(int selected)
{
    if (!mListModel)
    {
        mSelected = -1;
    }
    else
    {
        // Update mSelected with bounds checking
        mSelected = std::min(mListModel->getNumberOfElements() - 1,
                             std::max(-1, selected));

        gcn::Widget *parent;
        parent = (gcn::Widget*)getParent();
        if (parent)
        {
            gcn::Rectangle scroll;
            scroll.y = (mSelected < 0) ? 0 : getFont()->getHeight() * mSelected;
            scroll.height = getFont()->getHeight();
            parent->showWidgetPart(this, scroll);
        }
    }

    distributeValueChangedEvent();
}
*/
void GuildListBox::mousePressed(gcn::MouseEvent &event)
{
    if (event.getButton() == gcn::MouseEvent::LEFT)
    {
        int y = event.getY();
        setSelected(y / getFont()->getHeight());
        distributeActionEvent();
    }
    // TODO: Add guild functions, ie private messaging
    if (event.getButton() == gcn::MouseEvent::RIGHT)
    {
        // Show context menu
    }
}
Ejemplo n.º 24
0
    void Slider::mouseDragged(MouseEvent& mouseEvent)
    {
        if (getOrientation() == HORIZONTAL)
        {
            setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2));
        }
        else
        {
            setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2));
        }

        distributeActionEvent();

        mouseEvent.consume();
    }
Ejemplo n.º 25
0
    void Menu::keyPressed(gcn::KeyEvent& keyEvent) {
        std::cout << "Menu::keyPressed" << std::endl;
        hikari::Input::Button button =
            InputHelper::getMappedButtonForKey(keyEvent.getKey());

        if(button == Input::BUTTON_UP) {
            selectPreviousItem();
            keyEvent.consume();
        } else if(button == Input::BUTTON_DOWN) {
            selectNextItem();
            keyEvent.consume();
        } else if(button == Input::BUTTON_START || button == Input::BUTTON_SHOOT) {
            distributeActionEvent();
        }
    }
Ejemplo n.º 26
0
void DropDown::mousePressed(gcn::MouseEvent& mouseEvent)
{
    gcn::DropDown::mousePressed(mouseEvent);

    if (0 <= mouseEvent.getY() && mouseEvent.getY() < getHeight() &&
        mouseEvent.getX() >= 0 && mouseEvent.getX() < getWidth() &&
        mouseEvent.getButton() == gcn::MouseEvent::LEFT && mDroppedDown &&
        mouseEvent.getSource() == mListBox)
    {
        mPushed = false;
        foldUp();
        releaseModalMouseInputFocus();
        distributeActionEvent();
    }
}
Ejemplo n.º 27
0
// -- MouseListener notifications
void GuiTable::mousePressed(gcn::MouseEvent& mouseEvent)
{
    if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
    {
        int row = getRowForY(mouseEvent.getY());
        int column = getColumnForX(mouseEvent.getX());

        if (row > -1 && column > -1 &&
            row < mModel->getRows() && column < mModel->getColumns())
        {
            mSelectedColumn = column;
            mSelectedRow = row;
        }

        distributeActionEvent();
    }
}
Ejemplo n.º 28
0
// -- KeyListener notifications
void GuiTable::keyPressed(gcn::KeyEvent& keyEvent)
{
    gcn::Key key = keyEvent.getKey();

    if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
    {
        distributeActionEvent();
        keyEvent.consume();
    }
    else if (key.getValue() == Key::UP)
    {
        setSelectedRow(mSelectedRow - 1);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::DOWN)
    {
        setSelectedRow(mSelectedRow + 1);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::LEFT)
    {
        setSelectedColumn(mSelectedColumn - 1);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::RIGHT)
    {
        setSelectedColumn(mSelectedColumn + 1);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::HOME)
    {
        setSelectedRow(0);
        setSelectedColumn(0);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::END)
    {
        setSelectedRow(mModel->getRows() - 1);
        setSelectedColumn(mModel->getColumns() - 1);
        keyEvent.consume();
    }
}
Ejemplo n.º 29
0
// -- KeyListener notifications
void GuiTable::keyPressed(KeyEvent& event)
{
    const InputActionT action = event.getActionId();

    if (action == InputAction::GUI_SELECT)
    {
        distributeActionEvent();
        event.consume();
    }
    else if (action == InputAction::GUI_UP)
    {
        setSelectedRow(mSelectedRow - 1);
        event.consume();
    }
    else if (action == InputAction::GUI_DOWN)
    {
        setSelectedRow(mSelectedRow + 1);
        event.consume();
    }
    else if (action == InputAction::GUI_LEFT)
    {
        setSelectedColumn(mSelectedColumn - 1);
        event.consume();
    }
    else if (action == InputAction::GUI_RIGHT)
    {
        setSelectedColumn(mSelectedColumn + 1);
        event.consume();
    }
    else if (action == InputAction::GUI_HOME)
    {
        setSelectedRow(0);
        setSelectedColumn(0);
        event.consume();
    }
    else if (action == InputAction::GUI_END && mModel)
    {
        setSelectedRow(mModel->getRows() - 1);
        setSelectedColumn(mModel->getColumns() - 1);
        event.consume();
    }
}
Ejemplo n.º 30
0
void ListBox::keyPressed(KeyEvent &event)
{
    const InputActionT action = event.getActionId();
    if (action == InputAction::GUI_SELECT)
    {
        distributeActionEvent();
        event.consume();
    }
    else if (action == InputAction::GUI_UP)
    {
        if (mSelected > 0)
        {
            setSelected(mSelected - 1);
        }
        else if (mSelected == 0 &&
                 mWrappingEnabled &&
                 getListModel() != nullptr)
        {
            setSelected(getListModel()->getNumberOfElements() - 1);
        }
        event.consume();
    }
    else if (action == InputAction::GUI_DOWN)
    {
        const int num = getListModel()->getNumberOfElements() - 1;
        if (mSelected < num)
            setSelected(mSelected + 1);
        else if (mSelected == num && mWrappingEnabled)
            setSelected(0);
        event.consume();
    }
    else if (action == InputAction::GUI_HOME)
    {
        setSelected(0);
        event.consume();
    }
    else if (action == InputAction::GUI_END && (getListModel() != nullptr))
    {
        setSelected(getListModel()->getNumberOfElements() - 1);
        event.consume();
    }
}