bool ListBox::keyPress(const Key& key) { bool ret = false; if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) { generateAction(); ret = true; } else if (key.getValue() == Key::UP) { selectNextPrevElement(-1); ret = true; } else if (key.getValue() == Key::DOWN) { selectNextPrevElement(+1); ret = true; } else if (key.getValue() == Key::PAGE_UP) { ret = selectNextPrevPage(-1); } else if (key.getValue() == Key::PAGE_DOWN) { ret = selectNextPrevPage(+1); } return ret; }
void AnimationHandler::generateAnimations(std::vector<AnimationDescriptor*> animationList) { CCLOG("AnimationHandler::generateAnimations initialized"); CCLOG("=Generating animations objects."); int animCount = animationList.size(); Vector<SpriteFrame*>* vectorBuffer = new Vector<SpriteFrame*>[animCount]; for(int c = 0; c < animCount;c++) { auto elem = animationList.at(c); std::string pattern = elem->getPattern(); int frameCount = elem->getFrameCount(); float speed = elem->getAnimationSpeed() == 0? DEFAULT_SPEED : elem->getAnimationSpeed(); std::string status = elem->getStatus(); this->loadFrameBuffer(vectorBuffer[c], frameCount, pattern); _animations.push_back(Animation::createWithSpriteFrames(vectorBuffer[c], speed)); _actions[status] = generateAction(elem, _animations.at(c)); _actions[status]->retain(); } delete[] vectorBuffer; CCLOG("AnimationHandler::generateAnimations done."); }
void ListBox::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::LEFT) { setSelected(mouseEvent.getY() / getFont()->getHeight()); generateAction(); } }
void ListBox::mousePress(int x, int y, int button) { if (button == MouseInput::LEFT && hasMouse()) { setSelected(y / getFont()->getHeight()); generateAction(); } }
void ListBox::selectNextPrevElement(int sign) { int index = mSelected + sign; if (index < 0) { index = 0; } setSelected(index); generateAction(selectEventId); }
void TileSelector::mousePressed(gcn::MouseEvent& mouseEvent) { if (mouseEvent.getX() <= mTileSetBitmap->w && mouseEvent.getY() <= mTileSetBitmap->h) { mSelectedTile = mouseEvent.getX() / 16 + (mouseEvent.getY() / 16) * mTileSetBitmap->w / 16; generateAction(); } }
void Slider::lostFocus() { //Wyrmgus start if (mMouseDrag) { //sliders now generate their actions when the mouse is released, not pressed generateAction(); } //Wyrmgus end mMouseDrag = false; }
//Wyrmgus start // void Slider::mouseRelease(int, int, int) void Slider::mouseRelease(int x, int y, int button) //Wyrmgus end { //Wyrmgus start if (mMouseDrag) { //sliders now generate their actions when the mouse is released, not pressed generateAction(); } //Wyrmgus end mMouseDrag = false; }
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) { generateAction(); } 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(); }
void Button::keyReleased(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) && mKeyPressed) { mKeyPressed = false; generateAction(); keyEvent.consume(); } }
bool Slider::keyPress(const Key& key) { bool ret = false; if (getOrientation() == HORIZONTAL) { if (key.getValue() == Key::K_RIGHT) { setValue(getValue() + getStepLength()); generateAction(); ret = true; } else if (key.getValue() == Key::K_LEFT) { setValue(getValue() - getStepLength()); generateAction(); ret = true; } } else { if (key.getValue() == Key::K_UP) { setValue(getValue() + getStepLength()); generateAction(); ret = true; } else if (key.getValue() == Key::K_DOWN) { setValue(getValue() - getStepLength()); generateAction(); ret = true; } } return ret; }
void Button::mouseReleased(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::LEFT && mMousePressed && mHasMouse) { mMousePressed = false; generateAction(); mouseEvent.consume(); } else if (mouseEvent.getButton() == MouseEvent::LEFT) { mMousePressed = false; mouseEvent.consume(); } }
void Slider::mouseMotion(int x, int y) { if (mMouseDrag) { if (getOrientation() == HORIZONTAL) { setValue(markerPositionToValue(x - getMarkerLength() / 2)); } else { setValue(markerPositionToValue(getHeight() - y - getMarkerLength() / 2)); } generateAction(); setDirty(true); } }
void MultiSelector::keyPressed(gcn::KeyEvent& keyEvent) { if (keyEvent.getKey().getValue() == gcn::Key::DOWN) { setSelected(getSelected() + 1); } else if (keyEvent.getKey().getValue() == gcn::Key::UP) { setSelected(getSelected() - 1); } else if (keyEvent.getKey().getValue() == gcn::Key::SPACE || keyEvent.getKey().getValue() == gcn::Key::LEFT_ALT || keyEvent.getKey().getValue() == gcn::Key::LEFT_CONTROL || keyEvent.getKey().getValue() == gcn::Key::ENTER) { generateAction(); } }
void ListBox::keyPressed(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) { generateAction(); keyEvent.consume(); } else if (key.getValue() == Key::UP) { setSelected(mSelected - 1); if (mSelected == -1) { if (isWrappingKeyboardSelection()) { setSelected(getListModel()->getNumberOfElements() - 1); } else { setSelected(0); } } keyEvent.consume(); } else if (key.getValue() == Key::DOWN) { if (isWrappingKeyboardSelection() && getSelected() == getListModel()->getNumberOfElements() - 1) { setSelected(0); } else { setSelected(getSelected() + 1); } keyEvent.consume(); } }
void Slider::mousePress(int x, int y, int button) { if (button == gcn::MouseInput::LEFT && x >= 0 && x <= getWidth() && y >= 0 && y <= getHeight()) { if (getOrientation() == HORIZONTAL) { setValue(markerPositionToValue(x - getMarkerLength() / 2)); } else { setValue(markerPositionToValue(getHeight() - y - getMarkerLength() / 2)); } mMouseDrag = true; generateAction(); } else { mMouseDrag = false; } }
void Menu::action(const gcn::ActionEvent& actionEvent) { if (actionEvent.getSource() == mMainMultiSelector) { if (!mCancelLabel->isVisible() && mMainMultiSelector->getSelected() == 3) { // Erase selected mEraseLabel->setVisible(false); mCancelLabel->setVisible(true); mEraseGameLabel->setVisible(true); mSelectGameLabel->setVisible(false); mMainMultiSelector->setSelected(0); } else if (mCancelLabel->isVisible() && mMainMultiSelector->getSelected() == 3) { // Cancel selected mEraseLabel->setVisible(true); mCancelLabel->setVisible(false); mEraseGameLabel->setVisible(false); mSelectGameLabel->setVisible(true); mMainMultiSelector->setSelected(0); } else if (!mCancelLabel->isVisible() && mMainMultiSelector->getSelected() != 3) { GameStateManager::getInstance()->loadSlot(mMainMultiSelector->getSelected()); generateAction(); } else if (mCancelLabel->isVisible() && mMainMultiSelector->getSelected() != 3) { mCancelLabel->setVisible(false); mQueryEraseLabel->setVisible(true); mNoLabel->setVisible(true); mYesLabel->setVisible(true); mQueryMultiSelector->setVisible(true); mQueryMultiSelector->requestFocus(); } } else if (actionEvent.getSource() == mQueryMultiSelector) { if (mQueryMultiSelector->getSelected() == 0) { // No selected mEraseLabel->setVisible(true); mCancelLabel->setVisible(false); mEraseGameLabel->setVisible(false); mSelectGameLabel->setVisible(true); mMainMultiSelector->requestFocus(); mQueryMultiSelector->setVisible(false); mQueryEraseLabel->setVisible(false); mNoLabel->setVisible(false); mYesLabel->setVisible(false); } else if (mQueryMultiSelector->getSelected() == 1) { // Yes selected, slot should be erased mEraseLabel->setVisible(true); mCancelLabel->setVisible(false); mEraseGameLabel->setVisible(false); mSelectGameLabel->setVisible(true); mMainMultiSelector->requestFocus(); mQueryMultiSelector->setVisible(false); mQueryEraseLabel->setVisible(false); mNoLabel->setVisible(false); mYesLabel->setVisible(false); GameStateManager::getInstance()->erase(mMainMultiSelector->getSelected()); mGameSlotOne->update(0); mGameSlotTwo->update(1); mGameSlotThree->update(2); } } }
void Widget::generateAction() { generateAction(mEventId); }
void Shop::action(const gcn::ActionEvent& actionEvent) { if (actionEvent.getSource() == mLeaveButton) { generateAction(); } else if (actionEvent.getSource() == mBuyLifeButton) { if (GameState::getInstance()->getEnergyOrbs() < LIFE_COST) { mDialog->setText("C CUDDELZ: I'm sorry but you don't have enough } for buying a life."); mDialog->setVisible(true); return; } GameState::getInstance()->setEnergyOrbs(GameState::getInstance()->getEnergyOrbs() - LIFE_COST); GameState::getInstance()->setLives(GameState::getInstance()->getLives() + 1); mLivesEquipedLabel->setCaption(toString(GameState::getInstance()->getLives()) + "x~"); mLivesEquipedLabel->adjustSize(); play_sample(mBuySample, 128, 128, 1000, 0); } else if (actionEvent.getSource() == mBuyPodButton) { if (GameState::getInstance()->getEnergyOrbs() < POD_COST) { mDialog->setText("C CUDDELZ: I'm sorry but you don't have enough } for buying a pod."); mDialog->setVisible(true); return; } GameState::getInstance()->setEnergyOrbs(GameState::getInstance()->getEnergyOrbs() - POD_COST); GameState::getInstance()->setPods(GameState::getInstance()->getPods() + 1); mPodsEquipedLabel->setCaption(toString(GameState::getInstance()->getPods()) + "x{"); mPodsEquipedLabel->adjustSize(); play_sample(mBuySample, 128, 128, 1000, 0); } else if (actionEvent.getSource() == mBuyCannonUpgradeButton) { if (GameState::getInstance()->getEnergyOrbs() < CANNON_UPGRADE_COST) { mDialog->setText("C CUDDELZ: I'm sorry but you don't have enough } for a cannon upgrade."); mDialog->setVisible(true); return; } GameState::getInstance()->setEnergyOrbs(GameState::getInstance()->getEnergyOrbs() - CANNON_UPGRADE_COST); GameState::getInstance()->setCannonLevel(GameState::getInstance()->getCannonLevel() + 1); mCannonUpgradeEquipedLabel->setCaption("LEVEL " + toString(GameState::getInstance()->getCannonLevel())); mCannonUpgradeEquipedLabel->adjustSize(); play_sample(mBuySample, 128, 128, 1000, 0); } else if (actionEvent.getSource() == mBuyMegaBlastButton) { if (GameState::getInstance()->getEnergyOrbs() < MEGA_BLAST_COST) { mDialog->setText("C CUDDELZ: I'm sorry but you don't have enough } for buying a mega blast."); mDialog->setVisible(true); return; } GameState::getInstance()->setEnergyOrbs(GameState::getInstance()->getEnergyOrbs() - MEGA_BLAST_COST); GameState::getInstance()->setMegaBlasts(GameState::getInstance()->getMegaBlasts() + 1); mMegaBlastsEquippedLabel->setCaption(toString(GameState::getInstance()->getMegaBlasts()) + "x["); mMegaBlastsEquippedLabel->adjustSize(); play_sample(mBuySample, 128, 128, 1000, 0); } mEnergyOrbsLabel->setCaption("YOU HAVE " + toString(GameState::getInstance()->getEnergyOrbs()) + "x}"); mEnergyOrbsLabel->adjustSize(); }
void CheckBox::toggle() { mMarked = !mMarked; generateAction(); }
void DropDown::action(const ActionEvent& actionEvent) { foldUp(); releaseModalMouseInputFocus(); generateAction(); }