void WDisplay::setPositions(int iNoPos) { resetPositions(); if (iNoPos < 0) { qWarning() << "Negative NumberStates for Display."; iNoPos = 0; } // QVector inserts NULLs for the new pixmaps. m_pixmaps.resize(iNoPos); m_disabledPixmaps.resize(iNoPos); }
FilenameBox::FilenameBox(std::string caption){ //initialise infoReady = 0; setCaption( caption ); input = new gcn::TextField(""); bodyText = new gcn::Label( "Filename: " ); //add widgets to window add(bodyText); add(input); resetPositions(); }
GameGui::GameGui(SDL_Surface *screen, Character *characterSource){ init(); if( characterSource != NULL ){ statBox->setCharacterSource(characterSource); statBox->setStatsSource(&characterSource->stats); healthBox->setCharacterSource(characterSource); healthBox->setStatsSource(&characterSource->stats); inventoryBox->setInventory(&characterSource->inventory); } setTarget(screen); //reset the position of all UI objects resetPositions(); }
//removes char from position in args and changes subsequent objects to be drawn properly void textIn::removeChar(int _i){ try{ //creates an iterator for text vector assigned from arg 1 auto it = text.begin(); if(_i != 1){ //remove the character in the vector at index using the iterator text.erase(it + (_i -1)); //iterates all text in front of inserted text to be drawn in front of the char before it (shimmies all the other letters along) for(int x = (_i-1); x < text.size(); x++){ text.at(x).setPosition((text.at(x -1).getPosition().x + text.at(x -1).getLocalBounds().width) , getPosY() - (getHeight()/5)); } }else if(_i != 0){ //delete first element text.erase(it); //set first element to be at the front of the text box text.at(0).setPosition(getPosX() , getPosY() - (getHeight()/5)); //iterates all text in front of inserted text to be drawn in front of the char before it (shimmies all the other letters along) for(int x = 1; x < text.size(); x++){ text.at(x).setPosition((text.at(x -1).getPosition().x + text.at(x -1).getLocalBounds().width) , getPosY()- (getHeight()/5)); } } if(_i != 0){ //reorganises all positions of caret resetPositions(); caretIndex--; setCaret(caretPosition.at(caretIndex), getPosY(), getHeight()); //stores the new position of the character at the very front caretPosition.push_back(text.at(text.size() -1).getPosition().x + text.at(text.size() -1).getLocalBounds().width); } }catch( std::out_of_range){ std::cout<< "Range error removing char"; } }
void Level::update() { //printf("offset %d \n", m_virtualPosition); if (m_virtualPosition <= 0) { resetPositions(); } for (std::vector<GameObject*>::iterator it = m_levelObjects.begin() ; it != m_levelObjects.end(); ++it) { (*it)->scroll(m_scrollSpeed); (*it)->update(); } m_virtualPosition -= m_scrollSpeed; }
/*** Public functions ***/ RobotControl::RobotControl(std::string port, unsigned int baud_rate) : io(), serial(io, port) { try { serial.set_option(boost::asio::serial_port_base::baud_rate(baud_rate)); serial.set_option(boost::asio::serial_port_base::character_size(8)); serial.set_option(boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none)); serial.set_option(boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::two)); serial.set_option(boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::even)); Sleep(500); resetPositions(); Sleep(500); start(); BOOST_LOG_TRIVIAL(info) << "RobotControl setup complete"; } catch (int e){ BOOST_LOG_TRIVIAL(error) << "Unable to setup robotcontrol: " << e; } }
void GameManager::restart(){ _vidas=5; resetSpeed(1); resetPositions(1); }
WVuMeter::~WVuMeter() { resetPositions(); }
GameGui::GameGui(SDL_Surface *screen){ init(); setTarget(screen); //reset the position of all UI objects resetPositions(); }
GameGui::GameGui(){ init(); //reset the position of all UI objects resetPositions(); }
void Console::init(){ if( !initialised ){ setTabbingEnabled(false); username = ""; lines = 1; textW = 640; textH = 400; container->setOpaque(0); //initialise the form objects textArea = new gcn::TextBox("Welcome to the Infraelly Console"); textScroller = new InfraellyScroller(textArea); inputField = new gcn::TextField; sendButton = new gcn::Button("Send"); //add objects to self container->add(textScroller); container->add(inputField); container->add(sendButton); //set the console as the gui's top widget setTop(container); //CONFIGURE FORM OBJECTS // add 'this' as a mouse listener sendButton->addMouseListener(this); //add the input field as key listener inputField->addKeyListener(this); //make the text area non editable textArea->setEditable(0); //make the scroll bars (dis)appear automaticaly textScroller->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); textScroller->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); //not focus sendButton->setFocusable(0); textArea->setFocusable(0); //dont allow tabbing container->setTabOutEnabled(false); textArea->setTabOutEnabled(false); textScroller->setTabOutEnabled(false); inputField->setTabOutEnabled(false); sendButton->setTabOutEnabled(false); //set the colours of the objects // bases container->setBaseColor( gcn::Color(0, 0, 0) ); //the bg black inputField->setBaseColor( gcn::Color(0, 0, 200) ); //input d_black textArea->setForegroundColor( gcn::Color(255, 255, 255) ); //scoller (white) textScroller->setBaseColor( gcn::Color(0, 100, 200) ); //scoller (blue) sendButton->setBaseColor( gcn::Color(0, 0, 0) ); //the button (black) // background inputField->setBackgroundColor( gcn::Color(0, 0, 0) ); // black textScroller->setBackgroundColor( gcn::Color(0, 0, 0) ); //scoller (black) sendButton->setBackgroundColor( gcn::Color(0, 0, 0) ); //the button (black) //foreground (text color) inputField->setForegroundColor( gcn::Color(0, 255, 0) ); //input(green) textArea->setForegroundColor( gcn::Color(255, 255, 255) ); //text (white) textScroller->setForegroundColor( gcn::Color(255, 255, 255) ); //scroller (white) sendButton->setForegroundColor( gcn::Color(255, 0, 0) ); //the button (red) //give it a readable font textArea->setFont(font::guiTitleFont.at(font::stdGuiTitleFontSize)); inputField->setFont(font::guiTitleFont.at(font::stdGuiTitleFontSize)); sendButton->setFont(font::guiTitleFont.at(font::stdGuiTitleFontSize)); //give the button no border sendButton->setFrameSize(0); //make the text area not opaque textArea->setOpaque(0); //set sizes //textArea //100 px hight textArea->setHeight(100); //500px wide textArea->setWidth(500); //textScroller // match textArea textScroller->setDimension( textArea->getDimension() ); //input field // match the textArea in width, but leave space for the button inputField->setWidth( textArea->getWidth() - sendButton->getWidth() ); inputField->setHeight( 20 ); //button //make button same hight as input field sendButton->setHeight( inputField->getHeight() ); //set the x-y resetPositions(); inputField->requestFocus(); // set initialised initialised = 1; } }
WDisplay::~WDisplay() { resetPositions(); }
//listens to key presses when selected, records all keyboard input void textIn::keyListen(sf::Event &e){ try{ //if there are any text objects to cycle through if(text.size() != 0){ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && caretIndex > 0){ //this is on the condition that the caret is not moved to the back of the box when it is //writing text that is longer than the box, the user can delete stuff rather than go back //to see what they have written as this kind of input box is very small and needs to be lower in //overhead if(caret2.getPosition().x - 16 > getPosX()){ caretIndex--; setCaret(caretPosition.at(caretIndex), getPosY(), getHeight()); } } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && (caretIndex < caretPosition.size() -1)){ caretIndex++; setCaret(caretPosition.at(caretIndex), getPosY(), getHeight()); } } //this is not key pressed event at all this is textEntered its entirely different if (e.type == sf::Event::TextEntered){ if (e.text.unicode < 128 && getSelected()){ //if the same key as the last one was pressed not too recently if(lastKey == e.text.unicode ){ //if a second has passed if(getTicks(0.7)){ //if the caret is next to the front most text object append text to the front of the vector else //insert the character to the point where the caret is colliding if(text.size() == 0 || caretX > (text.back().getPosition().x + text.back().getLocalBounds().width) - 10){ addChar(e.text.unicode); }else{ insertChar( textIndex(), e.text.unicode); } } //if backspace has been hit }else if( 8 == e.text.unicode){ //if the caret is next to the front most text object remove the front most object with remove char //else remove the character at the point where the caret is colliding if( text.size() == 0 || caretX > (text.back().getPosition().x + text.back().getLocalBounds().width) - 10){ removeChar(); }else{ if(caretIndex != 0) removeChar(textIndex()); } //if the caret is next to the front most text object append text to the front of the vector else //insert the character to the point where the caret is colliding }else if(text.size() == 0 || caretX > (text.back().getPosition().x + text.back().getLocalBounds().width) - 10) { addChar(e.text.unicode); lastKey = e.text.unicode; getTicks(0.03); }else{ insertChar(textIndex(), e.text.unicode); lastKey = e.text.unicode; getTicks(0.03); } } } }catch(...){ std::cout<< "mystery error in key listen function caught"; //seems to stabilise mystery eror 75% of the time resetPositions(); } }
void textIn::insertChar( int _i, int _c){ try{ //creates an iterator for text vector assigned from arg 1 auto it = text.begin(); //creates a text graphic assigns a font and colour and size and pushes it to back of text vector sf::Text temp; temp.setFont(font); temp.setColor(sf::Color::White); temp.setCharacterSize(getHeight()); //if char to insert is pesky spacebar character... if(_c == 32){ //...then replace it with an underscore, no need to draw that underscore just a space must behave like a character temp.setString("_"); }else{ temp.setString( static_cast<char>(_c)); } if(_i != 0){ //insert the text in the vector at index using the iterator text.insert(it + _i, temp); text.at(_i).setPosition((text.at(_i ).getPosition().x + text.at(_i ).getLocalBounds().width) , getPosY() - (getHeight()/5)); //iterates all text in front of inserted text to be drawn in front of the char before it (shimmies all the other letters along) for(int x = _i; x < text.size(); x++){ text.at(x).setPosition((text.at(x -1).getPosition().x + text.at(x -1).getLocalBounds().width) , getPosY() - (getHeight()/5)); } }else{ //insert the text in the vector at index using the iterator text.insert(it, temp); //sets position of first character to be at front of text box text.at(0).setPosition(getPosX() , getPosY() - - (getHeight()/5)); //iterates all text in front of inserted text to be drawn in front of the char before it (shimmies all the other letters along) for(int x = 1; x < text.size(); x++){ text.at(x).setPosition((text.at(x -1).getPosition().x + text.at(x -1).getLocalBounds().width) , getPosY() - - (getHeight()/5)); } } }catch( std::out_of_range){ std::cout << "range error in textIn"; } //reorganises all positions of text resetPositions(); //moves caret along one setCaret( text.at(caretIndex).getPosition().x + text.at(caretIndex).getLocalBounds().width, getPosY(), getHeight()); //stores the new position of the character at the very front caretPosition.push_back(text.at(text.size() -1).getPosition().x + text.at(text.size() -1).getLocalBounds().width); caretIndex++; }
void GameManager::gameOver(){ _gameOver=true; resetSpeed(0); resetPositions(0); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { thread = new QThread(); reader = new Reader(); reader->moveToThread(thread); connect(reader, SIGNAL(sendPoint(int,int,double)), this, SLOT(setPointProb(int,int,double))); connect(reader, SIGNAL(workRequested()), thread, SLOT(start())); connect(thread, SIGNAL(started()), reader, SLOT(doWork())); connect(reader, SIGNAL(finished()), thread, SLOT(quit()) , Qt::DirectConnection); connect(reader, SIGNAL(finished()), this, SLOT(fileFinished())); connect(reader, SIGNAL(sendReset()), this, SLOT(resetPositions())); setFixedSize(800,600); p_scene = new QGraphicsScene(this); p_view = new QGraphicsView(p_scene, this); QPixmap background(QCoreApplication::applicationDirPath() + "/img/sol.png"); if (background.isNull()) { std::cout << "Ouverture de sol.png échouée, ouverture de sol.jpg" << std::endl; background = QPixmap(QCoreApplication::applicationDirPath() + "/img/sol.jpg"); } p_scene->setBackgroundBrush(QBrush(background)); p_view->setGeometry(10,10,505,505); p_addPosition = new QPushButton("Ajouter position", this); p_addPosition->setGeometry(590,90, 120, 30); p_deletePos = new QPushButton("Réinitialiser positions", this); p_deletePos->setGeometry(590,130, 120, 30); p_openFile = new QPushButton("Ouvrir fichier", this); p_openFile->setGeometry(590, 170, 120, 30); p_changeTableSize = new QPushButton("Changer taille table", this); p_changeTableSize->setGeometry(50, 560, 120, 30); pauseButton = new QPushButton("", this); QIcon pauseIcon(QCoreApplication::applicationDirPath() + "/img/pause.png"); if (pauseIcon.isNull()) { std::cout << "Ouverture de pause.png échouée, ouverture de pause.jpg" << std::endl; pauseIcon = QIcon((QCoreApplication::applicationDirPath() + "/img/pause.jpg")); } pauseButton->setIcon(pauseIcon); pauseButton->setGeometry(590, 250, 30, 30); pauseButton->setDisabled(true); stopButton = new QPushButton("", this); QIcon stopIcon(QCoreApplication::applicationDirPath() + "/img/stop.png"); if (stopIcon.isNull()) { std::cout << "Ouverture de stop.png échouée, ouverture de stop.jpg" << std::endl; pauseIcon = QIcon((QCoreApplication::applicationDirPath() + "/img/stop.jpg")); } stopButton->setIcon(stopIcon); stopButton->setGeometry(630, 250, 30, 30); stopButton->setDisabled(true); stepButton = new QPushButton("", this); QIcon stepIcon(QCoreApplication::applicationDirPath() + "/img/step.png"); if (stepIcon.isNull()) { std::cout << "Ouverture de step.png échouée, ouverture de step.jpg" << std::endl; stepIcon = QIcon((QCoreApplication::applicationDirPath() + "/img/step.jpg")); } stepButton->setIcon(stepIcon); stepButton->setGeometry(670, 250, 30, 30); stepButton->setDisabled(true); p_quit = new QPushButton("Quitter", this); p_quit->setGeometry(600, 560, 100, 30); p_addPosX = new QLineEdit(this); p_addPosY = new QLineEdit(this); p_addPosP = new QLineEdit(this); p_addPosX->setGeometry(580, 50, 40, 30); p_addPosY->setGeometry(630, 50, 40, 30); p_addPosP->setGeometry(680, 50, 40, 30); p_addPosX->setPlaceholderText("Abscisse"); p_addPosY->setPlaceholderText("Ordonnée"); p_addPosP->setPlaceholderText("Proba"); currentDate = new QLabel("Pas de fichier en cours", this); currentDate->setGeometry(580, 300, 140, 30); QObject::connect(p_addPosition, SIGNAL(clicked()), this, SLOT(sendPointProbValues())); QObject::connect(this, SIGNAL(pointProbValues(int,int,double)), this, SLOT(setPointProb(int,int,double))); QObject::connect(p_deletePos, SIGNAL(clicked()), this, SLOT(resetPositions())); QObject::connect(p_quit, SIGNAL(clicked()), qApp, SLOT(quit())); QObject::connect(p_openFile, SIGNAL(clicked()), this, SLOT(readMatrixFromFile())); QObject::connect(p_changeTableSize, SIGNAL(clicked()), this, SLOT(changeTableSize())); QObject::connect(pauseButton, SIGNAL(clicked()), this, SLOT(pauseRead())); QObject::connect(stopButton, SIGNAL(clicked()), this, SLOT(stopRead())); QObject::connect(reader, SIGNAL(sendDate(QString)), this, SLOT(setDate(QString))); QObject::connect(stepButton, SIGNAL(clicked()), this, SLOT(clickNextDate())); }
MapperGui::MapperGui(){ init(); resetPositions(); }