void MainWindow::deleteLevelPropertyClicked() { int row = ui->levelPlistTableWidget->currentRow(); if(row == -1) // nothing selected return; if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); // iterate to the deleted row QMap<QString, QVariant>::const_iterator it = levelPlist.constBegin(); for(int i = 0; i < row; i++) ++it; levelPlist.remove(it.key()); updateGraphics(); updateLevelPlistTable(); noEmit = false; }
void MainWindow::loadFile() { // Clean up previous level selectedObjects.clear(); initializing = true; spriteSheet = QImage(PATH_SPRITE_IMAGE); loadSpritePlist(); QString fileName = QFileDialog::getOpenFileName(this, tr("Open Level"), PATH_BALLGAME_DIR, tr("Level file (*.level)")); if(fileName == "") // no file selected return; currentFileName = fileName; loadLevelPlist(fileName); // populate tables updateLevelPlistTable(); updateObjectTable(0); updateObjectComboBox(); // draw objects on screen; scene = new QGraphicsScene(); justLoaded = true; updateGraphics(); initializing = false; }
void GraphicsComponent::updatePrimaryState(PrimaryState* ps) { enterGraphic = ps->enterGraphic; graphic = ps->graphic; exitGraphic = ps->exitGraphic; if (enterGraphic == nullptr) playerGraphic = graphic; updateGraphics(); }
//Run the app void Application::go() { Ogre::Timer loopTimer; long lastTick,currentTick; lastTick=loopTimer.getMillisecondsCPU(); float fpsStep = 1.0f/(float)FPS; float frameDelta; bool continueRunning=true; while(continueRunning) { Ogre::WindowEventUtilities::messagePump(); capture(); currentTick=loopTimer.getMillisecondsCPU(); frameDelta = (currentTick-lastTick)*0.001; static float logicUpdateCounter=0; logicUpdateCounter+=frameDelta; while (logicUpdateCounter>fpsStep) { logicUpdateCounter-=fpsStep; updateLogic(fpsStep); updateGraphics(fpsStep); } bool windowClosed = m_window->isClosed(); continueRunning &= ! windowClosed; bool renderFrameSuccess = m_root->renderOneFrame(); continueRunning &= renderFrameSuccess; continueRunning &= ! m_exitRequested; lastTick=currentTick; } }
void MainWindow::on_normalChordsComboBox_activated(const QString &arg1) { QList<QString> chordsFound = findChords(ui->normalChordsComboBox->currentText()); ui->chordsModificatorsComboBox->clear(); ui->chordsModificatorsComboBox->addItems(chordsFound); updateGraphics(); }
void MainWindow::rotationSliderMoved(int value) { int objId = ui->objectSelectorComboBox->currentIndex(); if(objId == -1) // nothing selected return; if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); float rot = (value * 360.0 / 99); // dividing by 99 instead of 100 so that 360 can actually be reached int rotation = (int)rot / 5 * 5; // round to the nearest 5 levelObjects[objId].insert("rotation", QString::number(rotation)); updateGraphics(); noEmit = false; updateObjectTable(objId); }
void MainWindow::wallThicknessClicked() { qDebug("Triggered"); // Push an Undo object pushUndo(); int thickness = ui->wallThicknessEdit->text().toInt(); if(thickness <= 0) // invalid input return; for(int i = 0; i < levelObjects.count(); i++) { if(levelObjects[i].value("type").toString().toLower().contains("wall")) { bool xSmaller = true; if(levelObjects[i].value("height").toInt() < levelObjects[i].value("width").toInt()) xSmaller = false; if(xSmaller) levelObjects[i].insert("width", QString::number(thickness)); else levelObjects[i].insert("height", QString::number(thickness)); } } updateGraphics(); updateObjectTable(ui->objectSelectorComboBox->currentIndex()); }
int main () { for (int count = 0; count <= 9; count++) { makeLine (count*100,100,(count+1)*100,150); //makeLine () } for (double x = 0; x <= 1000; x++) { drawPixel (x/2,150+20.0*sin(x/5.0)); } updateGraphics(); std::cout << "Press any key to continue..."; std::cin.get(); std::cout << std::endl; return 0; }
void MainWindow::newObjectClicked(QModelIndex index) { // Make sure we can undo this later pushUndo(); // Get filename of object template QString filename = QString(PATH_OBJECT_TEMPLATES + ui->newObjectListWidget->currentItem()->text() + ".template"); // Construct new object from template file QMap<QString, QVariant> newObject = loadObjectFromTemplateFile(filename); // Get center of viewport QRect rect = ui->graphicsView->rect(); int newX = ui->graphicsView->horizontalScrollBar()->value() + rect.width() / 2; int newY = levelPlist.value("level_height").toInt() - ui->graphicsView->verticalScrollBar()->value() - rect.height() / 2; // Rename object newObject.insert("name", getNameForCopy(newObject.value("name").toString())); // Set object's x/y to center of viewport if(newObject.contains("x")) newObject.insert("x", QString("%1").arg(newX)); if(newObject.contains("y")) newObject.insert("y", QString("%1").arg(newY)); // Add new object to levelObjects levelObjects.append(newObject); // Update display ui->objectSelectorComboBox->setCurrentIndex(ui->objectSelectorComboBox->count() - 1); updateGraphics(); updateObjectComboBox(); }
int main() { sgb::Chip8 chip8; chip8.loadGame("PONG2"); back.create(64, 32, sf::Color::Black); backshape.setPosition(0, 0); backtext.loadFromImage(back); backshape.setTexture(&backtext); while(window.isOpen()){ sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } // emulate one cycle chip8.emulateCycle(); // if drawflag is set, update screen; if (chip8.drawFlag) updateGraphics(chip8); //query keys chip8.setKeys(); sf::sleep(sf::seconds(1.0f/500.0f)); } return 0; }
/** Updates the current position and rotation from the corresponding physics * body, and then calls updateGraphics to position the model correctly. * \param float dt Time step size. */ void Moveable::update(float dt) { if(m_body->getInvMass()!=0) m_motion_state->getWorldTransform(m_transform); m_velocityLC = getVelocity()*m_transform.getBasis(); updatePosition(); updateGraphics(dt, Vec3(0,0,0), btQuaternion(0, 0, 0, 1)); } // update
void TiledLevel::draw(sf::RenderTarget& target, sf::RenderStates states) const { if (_graphicsNeedsUpdate) updateGraphics(); states.transform = getTransform(); states.texture = _tilesetTexture; target.draw(_vertexArray, states); }
void MainWindow::popUndo() { if(!undoStack.isEmpty()) { UndoObject u = undoStack.pop(); // Redo functionality UndoObject r; r.levelObjects = levelObjects; r.levelPlist = levelPlist; r.selectedObjects = selectedObjects; redoStack.push(r); // Restore state from undo object levelObjects = u.levelObjects; levelPlist = u.levelPlist; selectedObjects = u.selectedObjects; // Make sure we don't end up in an infinite loop noEmit = true; // Update stuff to reflect new state updateGraphics(); updateObjectComboBox(); updateLevelPlistTable(); if(selectedObjects.length() > 0) { if(selectedObjects[0] != -1) // not the player { ui->objectSelectorComboBox->setCurrentIndex(selectedObjects[0]); updateObjectTable(selectedObjects[0]); } else { ui->objectSelectorComboBox->setCurrentIndex(0); updateObjectTable(0); } } else { ui->objectSelectorComboBox->setCurrentIndex(0); updateObjectTable(0); } noEmit = false; } else { QMessageBox msgBox; msgBox.setText("Nothing to undo!"); msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); } //qDebug(QString("Popped Undo - %1").arg(undoStack.count()).toAscii()); }
void AntBot::updatePosition( const AntPosition& position ) { m_position = position; /* In case the query always returns neighbours in a specific order, e.g. N, E, S, W, add another touch of randomised variation to the entire procedure. */ m_neighbours.clear(); m_neighbours = queryTerrain( m_position ); std::random_shuffle( std::begin( m_neighbours ), std::end( m_neighbours ) ); updateGraphics( m_position ); }
void MainWindow::newLevel() { // ToDo: implement "do you want to save?" here currentFileName = ""; QString levelPlistPath = QString(PATH_OBJECT_TEMPLATES) + QString("TemplateLevel.level"); loadLevelPlist(levelPlistPath); updateGraphics(); clearObjectTable(); updateLevelPlistTable(); updateObjectComboBox(); }
void QtRosNode::run() { ros::Rate loop(60); while(ros::ok() && !this->gui_closed) { //std::cout << "Ros node running..." << std::endl; emit updateGraphics(); loop.sleep(); ros::spinOnce(); } emit onRosNodeFinished(); }
void MainWindow::needToRescale(QString type, int id, double width, double height, double x, double y, bool objectStillDragging) { // Invert y y = levelPlist.value("level_height").toInt() - y; if(!objectStillDragging) { width = (int) width; height = (int) height; x = (int) x; y = (int) y; } QString sWidth = QString::number(width); QString sHeight = QString::number(height); QString sX = QString::number(x); QString sY = QString::number(y); // If we are the player if(id == -1) { levelPlist.insert("starting_size", sHeight); levelPlist.insert("start_x", sX); levelPlist.insert("start_y", sY); // Update UI with new size and position updateLevelPlistTable(); } // We are not the player else { levelObjects[id].insert("width", sWidth); levelObjects[id].insert("height", sHeight); levelObjects[id].insert("x", sX); levelObjects[id].insert("y", sY); // Update UI with new size and position updateObjectTable(id); } // Enormous performance boost if(!objectStillDragging) { updateGraphics(); } else { updateSelectedObjects(ui->graphicsView->scene(), true); } }
void MainWindow::newObjectClicked() { // Push an Undo object pushUndo(); levelObjects.append(QMap<QString, QVariant>()); updateGraphics(); updateObjectComboBox(); ui->objectSelectorComboBox->setCurrentIndex(levelObjects.count()-1); updateObjectTable(levelObjects.count() - 1); }
void MainWindow::deleteObjectClicked() { if(selectedObjects.count() == 0) // nothing selected return; // Push an Undo object pushUndo(); // Sort Selected Objects backwards so we can remove safely below (Whee, Bubblesort!) for(int i = 0; i < selectedObjects.count(); i++) { for(int j = i; j < selectedObjects.count(); j++) { if(selectedObjects[i] < selectedObjects[j]) { int temp = selectedObjects[i]; selectedObjects[i] = selectedObjects[j]; selectedObjects[j] = temp; } } } for(int i = 0; i < selectedObjects.count(); i++) { // This is safe because we just sorted :P levelObjects.removeAt(selectedObjects[i]); } selectedObjects.clear(); // Make sure we can't paste anything after this without re-copying copyObjects.clear(); if(noEmit) return; noEmit = true; updateGraphics(); updateObjectComboBox(); if(levelObjects.count() != 0) { ui->objectSelectorComboBox->setCurrentIndex(0); updateObjectTable(0); } else { clearObjectTable(); } noEmit = false; }
void CollectionView::addTile(std::string imgPath, sf::Vector2f textureOffset, sf::Vector2f textureSize) { auto tile = std::make_shared<GUI::Button>(); tile->setText(""); tile->drawRect(true); tile->drawSprite(true); sf::Texture* texture = new sf::Texture(); if (textureSize.x != -1){ texture->loadFromFile(imgPath,sf::IntRect((int) textureOffset.x, (int) textureOffset.y,(int)textureSize.x, (int)textureSize.y)); } else texture->loadFromFile(imgPath); tile->setNormalTexture(texture); tile->setPressedColor(sf::Color(75,131,204)); tile->setToggle(true); mTiles.push_back(tile); updateGraphics(); }
/** Updates the current position and rotation from the corresponding physics * body, and then calls updateGraphics to position the model correctly. * \param float dt Time step size. */ void Moveable::update(float dt) { if(m_body->getInvMass()!=0) m_motion_state->getWorldTransform(m_transform); m_velocityLC = getVelocity()*m_transform.getBasis(); Vec3 forw_vec = m_transform.getBasis().getColumn(0); m_heading = -atan2f(forw_vec.getZ(), forw_vec.getX()); // The pitch in hpr is in between -pi and pi. But for the camera it // must be restricted to -pi/2 and pi/2 - so recompute it by restricting // y to positive values, i.e. no pitch of more than pi/2. Vec3 up = getTrans().getBasis().getColumn(1); m_pitch = atan2(up.getZ(), fabsf(up.getY())); m_roll = atan2(up.getX(), up.getY()); updateGraphics(dt, Vec3(0,0,0), btQuaternion(0, 0, 0, 1)); } // update
void MainWindow::addLevelPropertyClicked() { if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); levelPlist.insert("new_property", "null"); updateGraphics(); updateLevelPlistTable(); noEmit = false; }
int main(int argc, char *argv[]) { printf("%s %d",argv[0],argc); dataStore *test = calloc(1,sizeof(dataStore)); highscoreTestdata(test); SDL_Surface* screen=initSDL(); readDataStore(test); menuStart(screen, test); saveDataStore(test); /* just for testing*/ makeTestData(test); //createRandomField(test); updateGraphics(screen,test); graphicLoop(screen,test); // gameloop(test,screen); quitSDL(); // free(test); return 0; }
void MainWindow::addPropertyClicked() { // Push an Undo object pushUndo(); int objId = ui->objectSelectorComboBox->currentIndex(); if(objId == -1) // nothing selected return; levelObjects[objId].insert("new_property", "null"); updateGraphics(); updateObjectComboBox(); updateObjectTable(objId); }
void MainWindow::redoClicked() { if(!redoStack.isEmpty()) { UndoObject r = redoStack.pop(); // Push current state to undo stack pushUndo(false); // Restore state from undo object levelObjects = r.levelObjects; levelPlist = r.levelPlist; selectedObjects = r.selectedObjects; // Make sure we don't end up in an infinite loop noEmit = true; // Update stuff to reflect new state updateGraphics(); updateObjectComboBox(); updateLevelPlistTable(); if(selectedObjects.length() > 0) { ui->objectSelectorComboBox->setCurrentIndex(selectedObjects[0]); updateObjectTable(selectedObjects[0]); } else { ui->objectSelectorComboBox->setCurrentIndex(0); updateObjectTable(0); } noEmit = false; } else { QMessageBox msgBox; msgBox.setText("Nothing to redo!"); msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); } }
void MainWindow::createCopyOfObjects(QList<int> objects) { selectedObjects.clear(); // Get mouse point in physics coordinates QPoint mouseGlobal = QCursor::pos(); QPoint mouseGraphicsView = ui->graphicsView->mapFromGlobal(mouseGlobal); QPointF mouseGraphicsScene = ui->graphicsView->mapToScene(mouseGraphicsView); for(int i = 0; i < objects.count(); i++) { int index = objects.at(i); levelObjects.append(QMap<QString, QVariant>(levelObjects[index])); // Rename copy QString newName = levelObjects[levelObjects.count()-1].value("name").toString(); newName = getNameForCopy(newName); // Update name levelObjects[levelObjects.count()-1].insert("name", newName); // Increment x and y by some amount int newX = mouseGraphicsScene.x(); int newY = levelPlist.value("level_height").toFloat() - mouseGraphicsScene.y(); // For pasting multiple objects (add position of current object's source, and subtract last selected object's source) newX += (levelObjects[objects.at(i)].value("x").toFloat() - levelObjects[objects.at(objects.count()-1)].value("x").toFloat()); newY += (levelObjects[objects.at(i)].value("y").toFloat() - levelObjects[objects.at(objects.count()-1)].value("y").toFloat()); levelObjects[levelObjects.count()-1].insert("x", QString("%1").arg(newX)); levelObjects[levelObjects.count()-1].insert("y", QString("%1").arg(newY)); // Make sure object is selected when we're done selectedObjects.append(levelObjects.count()-1); } updateGraphics(); noEmit = true; updateObjectComboBox(); ui->objectSelectorComboBox->setCurrentIndex(levelObjects.count()-1); noEmit = false; }
void MainWindow::doneEditingSublist() { qDebug("Signal received!"); /* // iterate to the changed row QMap<QString, QVariant>::iterator it = levelObjects[objId].begin(); for(int i = 0; i < objProp; i++) ++it; QString name = it.key(); levelObjects[objId].insert(name, list); */ updateGraphics(); updateObjectComboBox(); updateObjectTable(ui->objectSelectorComboBox->currentIndex()); }
bool subObservationVisualiserBase::eventFilter(QObject* object, QEvent *event) { if(event->type() == QEvent::GraphicsSceneMouseMove && object == graphicsScene) { QGraphicsSceneMouseEvent* mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event); QPointF position = mouseEvent->scenePos(); emit positionChanged(position.x(), position.y()); return true; } else if(event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); if(keyEvent->key() == Qt::Key_Left && keyEvent->modifiers() & Qt::ShiftModifier) { emit observationLeft(); return true; } else if(keyEvent->key() == Qt::Key_Right && keyEvent->modifiers() & Qt::ShiftModifier) { emit observationRight(); return true; } else if(keyEvent->key() == Qt::Key_Up && keyEvent->modifiers() & Qt::ShiftModifier) { emit observationDown(); return true; } else if(keyEvent->key() == Qt::Key_Down && keyEvent->modifiers() & Qt::ShiftModifier) { emit observationUp(); return true; } } else if(event->type() == QEvent::Leave && object == graphicsScene) { updateGraphics(); return true; } return false; }
void MainWindow::objectChanged(QTableWidgetItem* newItem) { int column = ui->objectsTableWidget->currentColumn(); // Nothing selected, abort. if(column < 0) return; int row = ui->objectsTableWidget->currentRow(); int objId = ui->objectSelectorComboBox->currentIndex(); if(objId == -1 || row == -1) // not initialized yet return; if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); // iterate to the changed row QMap<QString, QVariant>::const_iterator it = levelObjects[objId].constBegin(); for(int i = 0; i < row; i++) ++it; if(column == 1) { levelObjects[objId].insert(it.key(), newItem->text()); } else if(column == 0) { QString value = levelObjects[objId].value(it.key()).toString(); levelObjects[objId].remove(it.key()); levelObjects[objId].insert(newItem->text(), value); } updateGraphics(); updateObjectComboBox(); noEmit = false; }
void MainWindow::levelPlistChanged(QTableWidgetItem* newItem) { int column = ui->levelPlistTableWidget->currentColumn(); // Nothing selected, abort. if(column < 0) return; if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); int row = ui->levelPlistTableWidget->currentRow(); // iterate to the changed row QMap<QString, QVariant>::const_iterator it = levelPlist.constBegin(); for(int i = 0; i < row; i++) ++it; if(column == 1) { levelPlist.insert(it.key(), newItem->text()); } else if(column == 0) { QString value = levelPlist.value(it.key()).toString(); levelPlist.remove(it.key()); levelPlist.insert(newItem->text(), value); } updateGraphics(); updateLevelPlistTable(); noEmit = false; }