void CustomGraphicsScene::removeAllShapes() { QPainterPath path; path.addRect(this->sceneRect()); setSelectionArea(path); removeSelectedShapes(); this->clear(); QGraphicsRectItem *item; addItem(item = new QGraphicsRectItem(QRectF(0,0,10000,10000))); item->setVisible(false); }
void Text::draw (QPixmap &buffer, Scaler &scaler, int startIndex, int pixelspace, int startX) { QPainter painter; painter.begin(&buffer); int x2 = data->getX(date); if (x2 == -1) return; int x = startX + (x2 * pixelspace) - (startIndex * pixelspace); if (x == -1) return; painter.setFont(font); painter.setPen(color); int y = scaler.convertToY(getValue()); painter.drawText(x, y, label); QFontMetrics fm = painter.fontMetrics(); clearSelectionArea(); setSelectionArea(new QRegion(x, y - fm.height(), fm.width(label, -1), fm.height(), QRegion::Rectangle)); if (getStatus() == COBase::Selected) { clearGrabHandles(); setGrabHandle(new QRegion(x - HANDLE_WIDTH - 1, y - (fm.height() / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - HANDLE_WIDTH - 1, y - (fm.height() / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); } painter.end(); }
void ULLineEditor::mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent ) { if ( mouseSelect ) { QPainterPath p ( mouseSelectBegin ); p.addRect ( mouseSelectRect->boundingRect() ); setSelectionArea ( p ); mouseSelect = false; removeItem ( mouseSelectRect ); mouseSelectRect->setRect ( 0,0,0,0 ); } else if ( !itemAt ( mouseEvent->scenePos() ) ) { clearFocus(); clearSelection(); } }
void SellArrow::draw (QPixmap &buffer, Scaler &scaler, int startIndex, int pixelspace, int startX) { QPainter painter; painter.begin(&buffer); int x2 = data->getX(date); if (x2 == -1) return; int x = startX + (x2 * pixelspace) - (startIndex * pixelspace); if (x == -1) return; int y = scaler.convertToY(getValue()); arrow.putPoints(0, 7, x, y, x + 5, y - 5, x + 2, y - 5, x + 2, y - 11, x - 2, y - 11, x - 2, y - 5, x - 5, y - 5); painter.setBrush(getColor()); painter.drawPolygon(arrow, TRUE, 0, -1); clearSelectionArea(); setSelectionArea(new QRegion(arrow)); if (getStatus() == COBase::Selected) { clearGrabHandles(); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), y + 1, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), y + 1, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); } painter.end(); }
void CGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { // static int nbMove=0; //qDebug("CGraphicsScene::mouseMoveEvent %i", m_mode); switch (m_mode) { case MODE_IDLE: QGraphicsScene::mouseMoveEvent(event); if (m_itemRect != NULL) { m_itemRect->setMoveablePoint(event->scenePos()); setSelectionArea(m_itemRect->path(), QTransform()); } break; case MODE_CREATE_ITEM: //Q_ASSERT(false); //Normallement ne doit jamais arrive... QGraphicsScene::mouseMoveEvent(event); break; case MODE_IN_ITEM_CREATION: Q_ASSERT(m_currentItem != NULL); m_currentItem->updateCurrentPoint(event->scenePos()); //QGraphicsScene::mouseMoveEvent(event); pas d'appel a la classe de base pour eviter les moves en meme temps que les creations d'item break; case MODE_IN_ITEM_EVOLUTION: Q_ASSERT(m_currentItem != NULL); m_currentItem->onMouseEventOnAnchor(event, m_pressedAnchor); break; default: Q_ASSERT(false); break; } }
void VerticalLine::draw (QPixmap &buffer, Scaler &, int startIndex, int pixelspace, int startX) { QPainter painter; painter.begin(&buffer); int x2 = data->getX(date); if (x2 == -1) return; int x = startX + (x2 * pixelspace) - (startIndex * pixelspace); if (x == -1) return; painter.setPen(getColor()); painter.drawLine (x, 0, x, buffer.height()); clearSelectionArea(); Q3PointArray array; array.putPoints(0, 4, x - (HANDLE_WIDTH / 2), 0, x + (HANDLE_WIDTH / 2), 0, x + (HANDLE_WIDTH / 2), buffer.height(), x - (HANDLE_WIDTH / 2), buffer.height()); setSelectionArea(new QRegion(array)); if (getStatus() == COBase::Selected) { clearGrabHandles(); int t = (int) buffer.height() / 4; setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), 0, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), 0, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t * 2, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t * 2, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t * 3, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t * 3, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t * 4, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t * 4, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); } painter.end(); }
void HorizontalLine::draw (QPixmap &buffer, Scaler &scaler, int, int, int) { QPainter painter; painter.begin(&buffer); painter.setFont(font); int y = scaler.convertToY(getValue()); // if value is off chart then don't draw it if (getValue() < scaler.getLow()) return; painter.setPen(getColor()); QFontMetrics fm(font); QString s; getText(s); int pixelsWide = fm.width(s); painter.drawLine (0, y, buffer.width(), y); painter.drawText(0, y - 1, s, -1); painter.drawText(0 + pixelsWide + 1, y - 1, QString::number(getValue()), -1); clearSelectionArea(); QPointArray array; array.putPoints(0, 4, 0, y - 4, 0, y + 4, buffer.width(), y + 4, buffer.width(), y - 4); setSelectionArea(new QRegion(array)); if (getStatus() == COBase::Selected) { clearGrabHandles(); int t = (int) buffer.width() / 4; setGrabHandle(new QRegion(0, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(0, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(t, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(t, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(t * 2, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(t * 2, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(t * 3, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(t * 3, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(t * 4, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(t * 4, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); } painter.end(); }
void Player::update(b2World &physicsWorld, Events gameEvents, World &gameWorld) { // ------------------------------- Keyboard ------------------------------- if(gameEvents.isNum1) { selectedBoxes.clear(); selectedBoxes = gameWorld.getAllAlliesByType("box"); } if(gameEvents.isNum2) { selectedBoxes.clear(); selectedBoxes = gameWorld.getAllAlliesByType("magicbox"); } if(gameEvents.isNum3) { selectedBoxes.clear(); selectedBoxes = gameWorld.getAllAlliesByType("chargebox"); } if(gameEvents.isNum4) { selectedBoxes.clear(); selectedBoxes = gameWorld.getAllAlliesByType("floatbox"); } if(gameEvents.isNum5) { selectedBoxes.clear(); selectedBoxes = gameWorld.getAllAlliesByType("boombox"); } if(gameEvents.isE) { selectedBoxes.clear(); selectedBoxes = gameWorld.selectAllDynamicBoxes(); } // if(gameEvents.isF) // { // gameWorld.stopAllActions(); // } // if(gameEvents.isG || gameEvents.isGHeld) // { // gameWorld.createGib(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, sf::Color(255, 0, 0, 255), false); // gameWorld.createGib(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, sf::Color(0, 255, 0, 255), false); // gameWorld.createGib(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, sf::Color(0, 0, 255, 255), false); // } // if(gameEvents.isH) // { // gameWorld.createBox(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, 30.0f, 0.35f, 1, "chargebox"); // } // if(gameEvents.isI) // { // if(debug_global_detonateOnContact) // { // std::cout << "GLOBAL: BoomBox detonate on contact disabled." << std::endl; // debug_global_detonateOnContact = false; // } // else // { // std::cout << "GLOBAL: BoomBox detonate on contact enabled." << std::endl; // debug_global_detonateOnContact = true; // } // } // if(gameEvents.isJ) // { // gameWorld.createBox(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, 30.0f, 0.35f, 1, "box"); // } // if(gameEvents.isK) // { // gameWorld.createBox(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, 30.0f, 0.35f, 1, "boombox"); // } // // if(gameEvents.isL) // { // int id = gameWorld.getBoxIdByCoordinates(gameEvents.lastMouse.x, gameEvents.lastMouse.y); // b2Vec2 pos = getGroundCoordsByCoordinates(gameEvents.lastMouse.x, gameEvents.lastMouse.y); // std::string groundId = getIndexByGroundCoordinates(pos.x, pos.y); // // // Check if we have selected a box // if(id >= 0) // { // // Check if element exists in selection and delete it // for(unsigned int i = 0; i < selectedBoxes.size(); i++) // { // if(selectedBoxes.at(i) == id) // { // selectedBoxes.erase(selectedBoxes.begin() + i); // } // } // // // Delete box // //gameWorld.deleteBoxById(id); // gameWorld.getBoxById(id)->isDead = true; // // // Rebuild selected boxes vector // selectedBoxes.clear(); // selectedBoxes = gameWorld.getSelectedBoxes(); // } // // try // { // gameWorld.getGroundBoxes()->at(groundId)->isDead = true; // } // catch(std::out_of_range ex) // { // //std::cout << "No groundBox found." << std::endl; // } // } // // if(gameEvents.isO) // { // gameWorld.regenerateWorld(physicsWorld); // } if(gameEvents.isP) { if(global_isPaused) { global_isPaused = false; } else { global_isPaused = true; } } if(gameEvents.isQ) { if(global_showFriendlyBoxInfo) { global_showFriendlyBoxInfo = false; } else { global_showFriendlyBoxInfo = true; } } if(gameEvents.isR) { if(selectedBoxes.size() > 0) { for(unsigned int i = 0; i < selectedBoxes.size(); i++) { if(!gameWorld.getBoxById(selectedBoxes.at(i))->repeatAttack && gameWorld.getBoxById(selectedBoxes.at(i))->type == "box") { gameWorld.getBoxById(selectedBoxes.at(i))->isAttacking = true; gameWorld.getBoxById(selectedBoxes.at(i))->repeatAttack = true; } else { gameWorld.getBoxById(selectedBoxes.at(i))->resetAttack(); } } } } if(gameEvents.isT) { selectedBoxes.clear(); int selectedBox = gameWorld.getChargedBox(); if(selectedBox >= 0) { selectedBoxes.push_back(selectedBox); hasNewFocus = true; Box* b = gameWorld.getBoxById(selectedBox); newFocus.x = b->getBody()->GetPosition().x * SCALE; newFocus.y = b->getBody()->GetPosition().y * SCALE; } } if(gameEvents.isU) { if(music.getStatus() == sf::Music::Playing) { music.pause(); } else { music.play(); } } if(gameEvents.isY) { if(global_enableAllyAI) { global_enableAllyAI = false; } else { global_enableAllyAI = true; } } if(gameEvents.isZ) { music.stop(); } if(gameEvents.isSpace) { if(selectedBoxes.size() > 0) { for(unsigned int i = 0; i < selectedBoxes.size(); i++) { gameWorld.getBoxById(selectedBoxes.at(i))->isAttacking = true; gameWorld.getBoxById(selectedBoxes.at(i))->repeatAttack = false; } } } // if(gameEvents.isNumPad1) // { // gameWorld.createBox(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, 30.0f, 0.35f, 1, "chargebox"); // } // // if(gameEvents.isNumPad2) // { // gameWorld.createBox(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, 30.0f, 0.35f, 1, "magicbox"); // } // // if(gameEvents.isNumPad3) // { // gameWorld.createBox(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, 30.0f, 0.35f, 1, "boombox"); // } // // if(gameEvents.isNumPad4) // { // gameWorld.createBox(physicsWorld, gameEvents.lastMouse.x, gameEvents.lastMouse.y, 30.0f, 0.35f, 1, "floatbox"); // } if(gameEvents.isEsc) { global_isMenu = true; global_isPaused = true; music.pause(); } // ------------------------------- Mouse ------------------------------- if(gameEvents.mouseLeftClicked && gameEvents.isLCTRLHeld) { int id = gameWorld.getBoxIdByCoordinates(gameEvents.lastMouseLeft.x, gameEvents.lastMouseLeft.y); if(id >= 0 && gameWorld.getBoxById(id)->team == TEAM_ALLY) { if(std::find(selectedBoxes.begin(), selectedBoxes.end(), id) != selectedBoxes.end()) { selectedBoxes.erase(std::remove(selectedBoxes.begin(), selectedBoxes.end(), id), selectedBoxes.end()); } else { selectedBoxes.push_back(id); } gameWorld.toggleBoxSelect(id); } } else if(gameEvents.mouseLeftClicked) { int id = gameWorld.getBoxIdByCoordinates(gameEvents.lastMouseLeft.x, gameEvents.lastMouseLeft.y); if(id >= 0 && gameWorld.getBoxById(id)->team == TEAM_ALLY) { clearActiveBoxes(gameWorld); selectedBoxes.push_back(id); gameWorld.toggleBoxSelect(id); } else { clearActiveBoxes(gameWorld); } } if(gameEvents.mouseLeftHeld) { setSelectionArea(gameEvents); } else { if(selectionAreaActive) { // Do the actual selection std::vector<int> selection = gameWorld.getBoxesBySelection(sf::Vector2f(selectionAreaPosition.x, selectionAreaPosition.y), selectionAreaSize); selectedBoxes.insert(selectedBoxes.end(), selection.begin(), selection.end()); selectionAreaActive = false; } } if(gameEvents.mouseRightClicked) { if(selectedBoxes.size() > 0) { float targetAreaSize = BOX_SIZE/4.0f + selectedBoxes.size() * 2.0f; gameWorld.setBunchTargetArea(selectedBoxes, TargetArea(gameEvents.lastMouseRight.x, gameEvents.lastMouseRight.y, targetAreaSize)); mTargetMarker.createCircle(gameEvents.lastMouseRight.x, gameEvents.lastMouseRight.y, 0.2f, 50.0f, sf::Color(250, 250, 250, 255)); } } if(gameEvents.mouseRightHeld) { if(selectedBoxes.size() == 0) { // Dynamics if(pushBox == NULL) { int id = gameWorld.getBoxIdByCoordinates(gameEvents.lastMouseRight.x, gameEvents.lastMouseRight.y); if(id >= 0) { pushBox = gameWorld.getBoxById(id); if(pushBox->type == "floatbox" || pushBox->type == "foxbox") { pushBox = NULL; } else { setPushVisuals(gameEvents); } } } else { setPushVisuals(gameEvents); } // Statics if(transformBox == NULL) { b2Vec2 pos = getGroundCoordsByCoordinates(gameEvents.lastMouseRight.x, gameEvents.lastMouseRight.y); std::string index = getIndexByGroundCoordinates(pos.x, pos.y); try { transformBox = gameWorld.getGroundBoxes()->at(index); if(!transformBox->getBody()->IsActive() || transformBox->team == TEAM_ENEMY) { transformBox = NULL; } } catch(std::out_of_range) { // blub } } else { setBoxTransformVisuals(gameEvents); } } } else { if(pushBox != NULL) { forcePushBox(gameEvents.lastMouse.x, gameEvents.lastMouse.y); pushActive = false; pushBox = NULL; } if(transformBox != NULL) { transformBoxToAlly(); transformBoxActive = false; transformBox = NULL; } transformCost = 0; } mTargetMarker.update(); }