Exemple #1
0
void PiwigoWindow::slotAlbumSelected()
{
    QTreeWidgetItem* const item = d->albumView->currentItem();

    // stop loading if user clicked an image
    if (item && item->text(2) == i18n("Image") )
        return;

    if (!item)
    {
        startButton()->setEnabled(false);
    }
    else
    {
        qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Album selected\n";

        int albumId = item->data(1, Qt::UserRole).toInt();
        qCDebug(DIGIKAM_WEBSERVICES_LOG) << albumId << "\n";

        if (d->talker->loggedIn() && albumId )
        {
            startButton()->setEnabled(true);
        }
        else
        {
            startButton()->setEnabled(false);
        }
    }
}
Exemple #2
0
PiwigoWindow::PiwigoWindow(DInfoInterface* const iface,
                           QWidget* const /*parent*/)
    : WSToolDialog(nullptr, QLatin1String("PiwigoSync Dialog")),
      d(new Private(this, iface))
{
    d->pPiwigo = new PiwigoSession();

    setWindowTitle( i18n("Piwigo Export") );
    setModal(false);

    // "Start Upload" button
    startButton()->setText( i18n("Start Upload") );
    startButton()->setEnabled(false);

    connect(startButton(), SIGNAL(clicked()),
            this, SLOT(slotAddPhoto()));

    // we need to let d->talker work..
    d->talker      = new PiwigoTalker(iface, d->widget);

    // setting progressDlg and its numeric hints
    d->progressDlg = new QProgressDialog(this);
    d->progressDlg->setModal(true);
    d->progressDlg->setAutoReset(true);
    d->progressDlg->setAutoClose(true);
    d->progressDlg->setMaximum(0);
    d->progressDlg->reset();

    d->pUploadList = new QStringList;

    // connect functions
    connectSignals();

    QPointer<PiwigoLoginDlg> configDlg;
    KConfig config;

    if (!config.hasGroup("Piwigo Settings") )
    {
        configDlg = new PiwigoLoginDlg(QApplication::activeWindow(),
                                       d->pPiwigo,
                                       i18n("Edit Piwigo Data") );

        if (configDlg->exec() != QDialog::Accepted)
        {
            delete configDlg;
        }
    }

    readSettings();
    slotDoLogin();
}
Exemple #3
0
void PiwigoWindow::slotBusy(bool val)
{
    if (val)
    {
        setCursor(Qt::WaitCursor);
        startButton()->setEnabled(false);
    }
    else
    {
        setCursor(Qt::ArrowCursor);
        bool loggedIn = d->talker->loggedIn();
        startButton()->setEnabled(loggedIn && d->albumView->currentItem());
    }
}
void ImageshackWindow::slotLoginDone(int errCode, const QString& errMsg)
{
    m_widget->updateLabels();

    if (!errCode && m_imageshack->loggedIn())
    {
        m_imageshack->saveSettings();
        startButton()->setEnabled(!m_widget->imagesList()->imageUrls().isEmpty());
        m_talker->getGalleries();
    }
    else
    {
        QMessageBox::critical(this, QString(), i18n("Login failed: %1\n", errMsg));
        startButton()->setEnabled(false);
        m_widget->m_progressBar->setVisible(false);
        slotBusy(false);
    }
}
void ImageshackWindow::slotBusy(bool val)
{
    if (val)
    {
        setCursor(Qt::WaitCursor);
        m_widget->m_chgRegCodeBtn->setEnabled(false);
        startButton()->setEnabled(false);
        setRejectButtonMode(QDialogButtonBox::Cancel);
    }
    else
    {
        setCursor(Qt::ArrowCursor);
        m_widget->m_chgRegCodeBtn->setEnabled(true);
        startButton()->setEnabled(m_imageshack->loggedIn() &&
                                  !m_widget->imagesList()->imageUrls().isEmpty());
        setRejectButtonMode(QDialogButtonBox::Close);
    }
}
Exemple #6
0
void VkontakteWindow::updateBusyStatus(bool busy)
{
    if (m_albumsBox)
        m_albumsBox->setEnabled(!busy && m_vkapi->isAuthenticated());

    if (!busy)
    {
        setCursor(Qt::ArrowCursor);
        startButton()->setEnabled(m_vkapi->isAuthenticated());
        setRejectButtonMode(QDialogButtonBox::Close);
    }
    else
    {
        setCursor(Qt::WaitCursor);
        startButton()->setEnabled(false);
        setRejectButtonMode(QDialogButtonBox::Cancel);
    }
}
Exemple #7
0
menu::menu() :QGraphicsView()/*, QMainWindow()*/
{
start = new QPushButton("Start",this);
connect(start, SIGNAL (clicked()), this, SLOT (startButton()));
start->setGeometry(QRect(QPoint(100, 50),QSize(200, 50)));

kilep = new QPushButton("Kilep",this);
connect(kilep, SIGNAL (clicked()), this, SLOT (kilepButton()));
kilep->setGeometry(QRect(QPoint(100, 100),QSize(200, 50)));

menuscene = new QGraphicsScene(this);
menuscene->setSceneRect(0,0,400,400);
setScene(menuscene);
}
Exemple #8
0
int main(void){

	initPIC32();
	closedLoopControl( false );
	setVel2(0, 0); //Stop Engines

	while(1){
		printf("Press start to continue\n");
					
		while(!startButton());
		
		do{

			waitTick40ms();

			int ground = readLineSensors(0);
			
			 if(NEAR_LEFT_BLACK(ground))
			
				setVel2(0, 50);
				
			else if(NEAR_RIGHT_BLACK(ground))
			
				setVel2(50, 0);
				
			else if(FAR_LEFT_BLACK(ground))
			
				setVel2(-50, 50);
				
			else if (FAR_RIGHT_BLACK(ground))	
			
				setVel2(50, -50);
			
			else if(GROUND_CENTER_BLACK(ground))
				setVel2(55, 60);
			else
				setVel2(50, -50);
			

		}while(!stopButton());
	}

return 0;

}
Exemple #9
0
void sab_execute() {
  if(!followPoints){
    followPoints = 1;
    firstTime=1;
    visible=1;

    setVel2(0,0);
    
    printf("Beacon found at %2.0f %2.0f\n", x, y);
    while (!startButton());
  }else {
    if(beaconDir > 0) {
        setVel2(30, -30);
    } else {
        setVel2(-30, 30);
    }
  }
}
Exemple #10
0
	int main(void){
	
	initPIC32();
	closedLoopControl( false );
		setVel2(0, 0); //Stop Engines


	int start, oldStart = 2;
	resetCoreTimer();
		while(1){
			start = startButton();
				if(start != oldStart)
					printf("%10d %d\n",readCoreTimer()/1000, start);

			oldStart = start;
		}
	return 0;

}
Exemple #11
0
void Lobby::init(int playerType, sf::IpAddress* serverip, unsigned short serverPort) {
    // Setting up network
    switch (playerType)
	{
        case SERVER:
        {
            localHost = new Server(game);
            window->setTitle("SERVER");
            
            LobbyPlayer host(1, "host", colors[0]);
            game->setLocalID(1);
            
            connected.push_back(host);
        }
            break;
        case CLIENT:
        {
            localHost = new Client(game, *serverip, serverPort);
            dynamic_cast<Client*>(localHost)->connect();
            window->setTitle("CLIENT");
            
            game->setLocalID(9999);
            
            // Get all connected lobby players and add this new client
            // This will also send a LOCAL_ID message to client sending this message
            game->getSynchronizer()->requestConnectedPlayers();
        }
            break;
        default:
            break;
	}
	network = new thread(&UDPNetwork::listen, localHost);
    
    game->setLocalHost(localHost);
    
    // Buttons
    Button startButton(sf::Vector2i(window->getSize().x/2, window->getSize().y-100),
                       sf::Vector2i(100, 50), "STARTBUTTON");
    buttons.push_back(startButton);
    director->addButton(startButton);
}
Exemple #12
0
int main (void)
{
	int countCiclos = 100;
	//iniciçao da pic
  	initPIC32 ();
  	closedLoopControl( true );
  	setVel2(0, 0);


	printStr(__FILE__); // para saber o nome do ficheiro que esta a correr no robot
	printf("\r    battery: %d ", batteryVoltage());
	if(batteryVoltage() <94){
		printf("_Bateria fraca, MUDAR Bateria\n");

	}
	printStr("\n");
	while(1)
	{	
		while(!tick40ms);
		tick40ms=0;
		readAnalogSensors();

		//state buttons

		if(startButton() == 1) 				// Botao start(preto) primido
		{
			estado = 1;
			enableObstSens();
			leds(0x0);						//leds off
			countCiclos = 100;
		}

		else if(stopButton() == 1) 			//Botao stop(vermelho) primido
		{
			printf("Red button pressed!!! \n");
			estado = 0;
			disableObstSens();
		}

		if(estado == 1) 
		{
			TimeOut();						// timeOut => tb devia ir para uma inturrupcao
			Chegada_Farol();
			if(countCiclos++ >= 100)
			{

				Ver_Farol();
				countCiclos = 0;
			}
			Run_Beacon();
		}

		if(estado == 2)
		{
			leds(0x1);
			Stop_robot();
		}

		if(estado == 3)
			Fim();

		else if(stopButton() == 1 || estado == 0)		// deslica o funcionamento, nenhum led activo
		{
			Stop_robot();
		}
 	}
  return (0);
}
Exemple #13
0
HelpDialog::HelpDialog()
    : KPToolDialog(0)
{
    setWindowIcon(QIcon::fromTheme(QString::fromLatin1("kipi-ogl")));
    setWindowTitle(i18n("Usage of OpenGL Image Viewer"));
    startButton()->setVisible(false);

    KPAboutData* about = new KPAboutData(ki18n("OpenGL Image Viewer"), 0,
                                         KAboutLicense::GPL,
                                         ki18n("A Kipi plugin to view image using OpenGL."),
                                         ki18n("(c) 2007-2008, Markus Leuthold\n"
                                               "(c) 2008-2013, Gilles Caulier"));

    about->addAuthor(i18n("Markus Leuthold"), i18n("Author"),
                     QString::fromLatin1("kusi at forum dot titlis dot org"));

    about->addAuthor(i18n("Gilles Caulier"), i18n("Developer"),
                     QString::fromLatin1("caulier dot gilles at gmail dot com"));

    setAboutData(about);

    // -------------------------------------------------------------------------------------------------------------------

    QTextBrowser* brw = new QTextBrowser(this);
    setMainWidget(brw);

    brw->setHtml(i18n(
        "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\""
        "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
        "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
        "p, li { white-space: pre-wrap; }\n"
        "</style></head><body style=\" font-family:'Sans Serif'; font-size:10pt; "
        "font-weight:400; font-style:normal;\">\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
        "-qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:x-large; "
        "font-weight:600; color:#5500ff;\">Image Access</span><br /></p>\n"
        "<table border=\"0\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;\" cellspacing=\"2\" cellpadding=\"0\">\n"
        "<tr>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">next image  </p></td>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">scrollwheel down/down arrow"
                            "/right arrow/PgDown/Space/n   </p></td></tr>\n"
        "<tr>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">previous image   </p></td>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">scrollwheel up/up arrow/left arrow/PgUp/p   </p></td></tr>\n"
        "<tr>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">quit  </p></td>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Esc    </p></td></tr></table>\n"
        "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"
                            "\"><span style=\" font-size:x-large; color:#5500ff;\">Display</span></p>\n"
        "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:x-large; font-weight:600; color:#5500ff;\"></p>\n"
        "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:x-large; font-weight:600; color:#5500ff;\"></p>\n"
        "<table border=\"0\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;\" cellspacing=\"2\" cellpadding=\"0\">\n"
        "<tr>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">toggle fullscreen/normal   </p></td>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">f    </p></td></tr>\n"
        "<tr>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:"
                            "0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">toggle scrollwheel action  </p></td>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">c (either zoom or change image)   </p></td></tr>\n"
        "<tr>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">rotation   </p></td>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">r    </p></td></tr>\n"
        "<tr>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">reset view   </p></td>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">double click    </p></td></tr>\n"
        "<tr>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-l"
                            "eft:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">original size  </p></td>\n"
        "<td>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">o   </p></td></tr></table>\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /><span style=\" font-size:x-large; font-weight:600; color:#5500ff;\">Zooming</span></p>\n"
        "<ul style=\"-qt-list-indent: 1;\"><li style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">move mouse in up/down-direction while pressing the right mouse button</li>\n"
        "<li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">alternatively, press c and use the scrollwheel<br /></li>\n"
        "<li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">plus/minu"
                            "s</li>\n"
        "<li style=\" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">ctrl + scrollwheel</li></ul>\n"
        "<p style=\" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:x-large; font-weight:600; color:#5500ff;\"><span style=\" font-size:x-large;\">Panning</span></p>\n"
        "<ul style=\"-qt-list-indent: 1;\"><li style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">move mouse while pressing the left button</li></ul></body></html>",
    0));

    brw->setProperty("text", QVariant(i18n(
        "<b><font color=\"#5500ff\">"
        "<font size=\"+2\">Image Access</font></font></b><br>\n"
        "<TABLE> \n"
        " <TR> \n"
        " <TD>next image</TD> \n"
        " <TD>scrollwheel down/down arrow/right arrow/PgDown/Space/n</TD>\n"
        " </TR> \n"
        " <TR> \n"
        " <TD>previous image </TD> \n"
        " <TD>scrollwheel up/up arrow/left arrow/PgUp/p </TD> \n"
        " </TR>\n"
        "<TR> \n"
        " <TD>quit</TD> \n"
        " <TD>Esc</TD> \n"
        " </TR> \n"
        " </TABLE>\n"
        "<br>\n"
        " <TH><b><font color=\"#5500ff\"><font size=\"+2\">Display</font></font></b></TH> </br>\n"
        "<TABLE> \n"
        " <TR> \n"
        " <TD>toggle fullscreen/normal </TD> \n"
        " <TD>f</TD> \n"
        " </TR> \n"
        " <TR> \n"
        " <TD>toggle scrollwheel action</TD> \n"
        " <TD>c (either zoom or change image)</TD> \n"
        " </TR>\n"
        " <TR> \n"
        " <TD>rotation </TD> \n"
        " <TD>r</TD> \n"
        " </TR> \n"
        " <TR> \n"
        " <TD>reset view </TD> \n"
        " <TD>double click</TD> \n"
        " </TR> \n"
        " <TR> \n"
        " <TD>original size</TD> \n"
        " <TD>o</TD> \n"
        " </TR>\n"
        " </TABLE>\n"
        "<br>\n"
        "\n"
        "\n"
        "<b><font color=\"#5500ff\" size=\"+2\">Zooming</font></b><br> \n"
        "<UL>\n"
        ""
        "<LI>move mouse in up/down-direction while pressing the right mouse button\n"
        "<LI>alternatively, press c and use the scrollwheel<br>\n"
        "<LI>plus/minus\n"
        "<LI>ctrl + scrollwheel\n"
        "</UL>\n"
        "\n"
        "<b><font color=\"#5500ff\" size=\"+2\">Panning</font></b><br>\n"
        "<UL> \n"
        "<LI>move mouse while pressing the left button\n"
        "</UL>",
    0)));

    // ---------------------------------------------------------------------------------------------------------------------

    resize(700, 550);
}
void SendImagesDialog::slotImagesCountChanged()
{
    startButton()->setEnabled(!d->imagesList->imagesList().isEmpty());
}
void SmugWindow::slotImageListChanged()
{
    startButton()->setEnabled(!(m_widget->m_imgList->imageUrls().isEmpty()));
}
Exemple #16
0
void servoControl(){
    //printf("BeaconVisible=%d beaconDir=%d left=%d right=%d ServoPos=%d\n", beaconVisible, beaconDir, left, right, currServoPos);

    //led(3,visible);

    if(followPoints){
	    //printf("FOLLOW POINT\n"); 
    	getLastPoint();
    	targetX=lastPointX;
    	targetY=lastPointY;
	    if( checkPointsRadius() ){
	    	if(removePoint()){
				// update point
				printf("Found home!\n");
				setVel2(0,0);
				while (!startButton());
			}
	    }
	    //double myNorm, targetNorm;
	    double meToTargetVector [2];
		double myDirectionVector [2];
	    double myX=x, myY=y, myDir=t;	// 0.35 radians
		

		meToTargetVector[0]=(targetX-myX);
		meToTargetVector[1]=(targetY-myY);
		myDirectionVector[0]=cos(myDir);
		myDirectionVector[1]=sin(myDir);

		double radianBeaconDir = atan2(meToTargetVector[1], meToTargetVector[0]) - atan2(myDirectionVector[1], myDirectionVector[0]);

		beaconDir=-normalizeAngle(radianBeaconDir)*(180 / PI);
		int servoPos = beaconDir/6;

		printf("My position %2.1f,%2.1f;      Target Position %d,%d;         MyAngle %2.0f     AngleToNextPoint %d\n", 
		       myX, myY, targetX, targetY, (myDir*180/PI), beaconDir);   //NEGATIVO PRA ESQUERDA
		
		if(servoPos > POS_RIGHT)
		  setServoPos(POS_RIGHT);
		else if( servoPos < POS_LEFT )
		  setServoPos(POS_LEFT);
		else
		  setServoPos(servoPos);
	    
	    
    }else{
		bVis=readBeaconSens();

		if(bVis && !oldBVis){							// Started seeing beacon!
		    if(rotate_right){ 
		    	left = currServoPos; 
		    	//if(left<0 && right>=POS_RIGHT)
		    	//	right=left+15;
		    }
		    else { 
		    	right = currServoPos; 
		    	//if(right>0 && left<=POS_LEFT)
		    	//	left=right-15;
		    }
		    
		    if(currServoPos==POS_RIGHT || currServoPos==POS_LEFT){	// Got to the end of the line
		      rotate_right=!rotate_right;
		    }
		}
		else if(!bVis && oldBVis){						// Stopped seeing beacon!
		    if(rotate_right){ right = currServoPos-1; }
		    else { left = currServoPos+1; }

		    rotate_right=!rotate_right;
		} else if(currServoPos==POS_RIGHT || currServoPos==POS_LEFT){	// Got to the end of the line
		    if(currServoPos==POS_RIGHT){ right = POS_RIGHT+1; }
		    else { left = POS_LEFT-1; }

		    rotate_right=!rotate_right;
		}

		visible = bVis||oldBVis||oldBVis2;
		//led(2, visible);

		oldBVis2=oldBVis;
		oldBVis=bVis;

		beaconDir = (left + right)/2*6;
		
		//printf("Beacon at %d\n",beaconDir);

		modder = rotate_right ? 1 : -1;
		//currServoPos+=modder;

		currServoPos = visible ? currServoPos+modder*1 : currServoPos+modder*2;
		if(currServoPos>POS_RIGHT){ currServoPos=POS_RIGHT; }
		else if(currServoPos<POS_LEFT){ currServoPos=POS_LEFT; }

		setServoPos(currServoPos);
    }
    
}
Exemple #17
0
int main() {
	sf::ContextSettings settings;
	settings.antialiasingLevel = 8; //smoother shapes
	window.create(sf::VideoMode(800, 600), "AKB48 Ongaku Geimu (alpha) v0.4", sf::Style::Default, settings);
	window.setVerticalSyncEnabled(true);

	/*
	window.setMouseCursorVisible(false); // Hide cursor
	sf::View fixed = window.getView(); // Create a fixed view

	// Load image and create sprite
	sf::Texture mouseTexture;
	mouseTexture.loadFromFile("cursors/mayuyu.png");
	sf::Sprite mouseSprite(mouseTexture);
	mouseSprite.rotate(-45);
	*/

	srand(time(NULL)); //seed random based on time

	//load fonts
	sf::Font gameFont;
	if (!gameFont.loadFromFile("gothic.ttf")) {
		//error
		std::cout << "Cannot load font\n";
	}
	sf::Font japaneseFont;
	if (!japaneseFont.loadFromFile("msmincho.ttc")) {
		//error
		std::cout << "Cannot load font\n";
	}

	//load background
	sf::Texture backTexture;
	if (!backTexture.loadFromFile("title_screen.png")) {
		//error
	}
	backTexture.setSmooth(true);
	backTexture.setRepeated(false);
	sf::Sprite backSprite;
	backSprite.setTexture(backTexture);
	backSprite.setColor(sf::Color(255, 255, 255, 224)); //semi-transparent

	//Load title text
	sf::Text titleText;
	titleText.setCharacterSize(50);

	//load buttons
	sf::RectangleShape startButton(sf::Vector2f(300,100));
	startButton.setFillColor(sf::Color(200, 50, 5, 128));
	startButton.setOutlineThickness(5);
	startButton.setOutlineColor(sf::Color(200, 50, 5, 128));
	startButton.setPosition(250, 250);

	sf::RectangleShape createButton(sf::Vector2f(300, 100));
	createButton.setFillColor(sf::Color(10, 150, 55, 192));
	createButton.setOutlineThickness(5);
	createButton.setOutlineColor(sf::Color(10, 150, 55, 192));
	createButton.setPosition(250, 400);

	//load button text
	sf::Text startText;
	startText.setCharacterSize(50);

	sf::Text createText;
	createText.setCharacterSize(40);

	//load music player graphics
	//music player black container
	sf::RectangleShape musicBox(sf::Vector2f(311, 30));
	musicBox.setFillColor(sf::Color(32, 32, 32, 224));
	musicBox.setPosition(sf::Vector2f(484, 565));
	//play button
	sf::CircleShape playButton;
	playButton.setPointCount(3);
	playButton.setRotation(210);
	playButton.setRadius(10);
	playButton.setFillColor(sf::Color(224, 224, 224, 224));
	playButton.setOutlineColor(sf::Color(128, 128, 128, 224));
	playButton.setPosition(sf::Vector2f(498, 593));
	//stop button
	sf::CircleShape stopButton;
	stopButton.setPointCount(4);
	stopButton.setRadius(11);
	stopButton.setRotation(45);
	stopButton.setFillColor(sf::Color(224, 224, 224, 224));
	stopButton.setOutlineColor(sf::Color(128, 128, 128, 224));
	stopButton.setPosition(sf::Vector2f(523, 565));
	//skip left button
	sf::CircleShape skipLeftButton;
	skipLeftButton.setPointCount(3);
	skipLeftButton.setRotation(30);
	skipLeftButton.setRadius(5);
	skipLeftButton.setFillColor(sf::Color(224, 224, 224, 224));
	skipLeftButton.setOutlineColor(sf::Color(128, 128, 128, 224));
	//skip right button
	sf::CircleShape skipRightButton;
	skipRightButton.setPointCount(3);
	skipRightButton.setRotation(210);
	skipRightButton.setRadius(5);
	skipRightButton.setFillColor(sf::Color(224, 224, 224, 224));
	skipRightButton.setOutlineColor(sf::Color(128, 128, 128, 224));
	//music text used for displaying time and song title
	sf::Text musicText;
	musicText.setFont(gameFont);
	musicText.setCharacterSize(12);
	//duration bar
	sf::RectangleShape timeDurBar(sf::Vector2f(100, 10));
	timeDurBar.setFillColor(sf::Color(160, 160, 160, 224));
	timeDurBar.setPosition(sf::Vector2f(632, 582));
	//current time bar
	sf::RectangleShape curTimeBar(sf::Vector2f(5, 12));
	curTimeBar.setFillColor(sf::Color(224, 224, 224, 224));
	//song name bar container
	sf::RectangleShape songNameBar(sf::Vector2f(170,10));
	songNameBar.setFillColor(sf::Color(16, 16, 16, 160));
	songNameBar.setPosition(sf::Vector2f(597, 568));
	//volume container
	sf::RectangleShape volBar(sf::Vector2f(20,24));
	volBar.setFillColor(sf::Color(16, 16, 16, 160));
	volBar.setPosition(sf::Vector2f(772, 568));
	//current volume
	sf::RectangleShape curVolBar;
	curVolBar.setFillColor(sf::Color(224, 224, 224, 224));
	//divider for buttons
	sf::RectangleShape buttonDivider(sf::Vector2f(2, 30));
	buttonDivider.setFillColor(sf::Color(160, 160, 160, 224));

	//randomly play music on title screen
	bool musicPermaStop = false; //permanently stops music (do not play next music) if stop button was pressed
	std::deque<std::string> previousPlayedSongs; //holds previous played songs (for skip left button)
	sf::Music music;
	std::string titleMusic[5] = { "Heavy Rotation", "Aitakatta", "Koi Suru Fortune Cookie", "Halloween Night", "Yankee Machine Gun" };
	std::string musicChoice = titleMusic[rand() % 5];
	if (!music.openFromFile(musicChoice + ".ogg")) {
		return -1; // error
	}
	music.setVolume(50);
	music.play();

	while (window.isOpen()) {
		//window.setMouseCursorVisible(false); // Hide cursor whenever we return to the title screen
		//if music ended, pick another song from our title screen jukebox (could be the same song again)
		if (music.getStatus() == 0 && !musicPermaStop) {
			previousPlayedSongs.push_back(musicChoice); //finished playing current song, push it to previous played song list
			musicChoice = titleMusic[rand() % 5];
			if (!music.openFromFile(musicChoice + ".ogg")) {
				return -1; // error
			}
			music.play();
		}

		sf::Event event;
		while (window.pollEvent(event)) {
			if (event.type == sf::Event::TextEntered) {
				std::cout << event.text.unicode << "\n"; //debug
			}
			if (event.type == sf::Event::MouseMoved) {
				sf::Vector2i localPos = sf::Mouse::getPosition(window);

				if (localPos.x >= 250 && localPos.x <= 550
					&& localPos.y >= 250 && localPos.y <= 350) {
					//start button
					startButton.setFillColor(sf::Color(200, 50, 5, 224));
					startButton.setOutlineColor(sf::Color(200, 50, 5, 224));
				}
				else if (localPos.x >= 250 && localPos.x <= 550
					&& localPos.y >= 400 && localPos.y <= 500) {
					//create button
					createButton.setFillColor(sf::Color(10, 150, 55, 224));
					createButton.setOutlineColor(sf::Color(10, 150, 55, 224));
				}
				else if (localPos.x >= 484 && localPos.x <= 509
					&& localPos.y >= 565 && localPos.y <= 595) {
					//play button
					playButton.setFillColor(sf::Color(35, 149, 207, 224));
					//reset colors of other buttons
					stopButton.setFillColor(sf::Color(224, 224, 224, 224));
					skipLeftButton.setFillColor(sf::Color(224, 224, 224, 224));
					skipRightButton.setFillColor(sf::Color(224, 224, 224, 224));
				}
				else if (localPos.x >= 511 && localPos.x <= 536
					&& localPos.y >= 565 && localPos.y <= 595) {
					//stop button
					stopButton.setFillColor(sf::Color(35, 149, 207, 224));
					//reset colors of other buttons
					playButton.setFillColor(sf::Color(224, 224, 224, 224));
					skipLeftButton.setFillColor(sf::Color(224, 224, 224, 224));
					skipRightButton.setFillColor(sf::Color(224, 224, 224, 224));
				}
				else if (localPos.x >= 538 && localPos.x <= 563
					&& localPos.y >= 565 && localPos.y <= 595) {
					//skip left button
					skipLeftButton.setFillColor(sf::Color(35, 149, 207, 224));
					//reset colors of other buttons
					playButton.setFillColor(sf::Color(224, 224, 224, 224));
					stopButton.setFillColor(sf::Color(224, 224, 224, 224));
					skipRightButton.setFillColor(sf::Color(224, 224, 224, 224));
				}
				else if (localPos.x >= 565 && localPos.x <= 590
					&& localPos.y >= 565 && localPos.y <= 595) {
					//skip right button
					skipRightButton.setFillColor(sf::Color(35, 149, 207, 224));
					//reset colors of other buttons
					playButton.setFillColor(sf::Color(224, 224, 224, 224));
					stopButton.setFillColor(sf::Color(224, 224, 224, 224));
					skipLeftButton.setFillColor(sf::Color(224, 224, 224, 224));
				}
				else {
					//reset colors
					startButton.setFillColor(sf::Color(200, 50, 5, 192));
					createButton.setFillColor(sf::Color(10, 150, 55, 192));
					startButton.setOutlineColor(sf::Color(200, 50, 5, 192));
					createButton.setOutlineColor(sf::Color(10, 150, 55, 192));
					playButton.setFillColor(sf::Color(224, 224, 224, 224));
					stopButton.setFillColor(sf::Color(224, 224, 224, 224));
					skipLeftButton.setFillColor(sf::Color(224, 224, 224, 224));
					skipRightButton.setFillColor(sf::Color(224, 224, 224, 224));
				}
			}
			if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left) {
				sf::Vector2i localPos = sf::Mouse::getPosition(window);

				if (localPos.x >= 250 && localPos.x <= 550
					&& localPos.y >= 250 && localPos.y <= 350) {
					//start button
					//std::cout << "Starting campaign\n"; //debug
					music.stop();
					//window.setMouseCursorVisible(true);
					song_selection(&window, "battle");
				}
				else if (localPos.x >= 250 && localPos.x <= 550
					&& localPos.y >= 400 && localPos.y <= 500) {
					//create button
					//std::cout << "Starting beat maker\n"; //debug
					music.stop();
					//window.setMouseCursorVisible(true);
					song_selection(&window, "make");
				}
				else if (localPos.x >= 484 && localPos.x <= 509
					&& localPos.y >= 565 && localPos.y <= 595) {
					//play button
					std::cout << "status code: " << music.getStatus() << "\n"; //debug
					if (music.getStatus() == 0 || music.getStatus() == 1) {
						std::cout << "\ttrying to play music\n"; //debug
						music.play();
						musicPermaStop = false;
					}
					else if (music.getStatus() == 2) {
						std::cout << "\ttrying to pause music\n"; //debug
						music.pause();
						musicPermaStop = false;
					}
					std::cout << "\tcode now: " << music.getStatus() << "\n"; //debug
				}
				else if (localPos.x >= 511 && localPos.x <= 536
					&& localPos.y >= 565 && localPos.y <= 595) {
					//stop button
					std::cout << "stopping music\n"; //debug
					music.stop();
					musicPermaStop = true;
					std::cout << "\tcode now: " << music.getStatus() << "\n"; //debug
				}
				else if (localPos.x >= 538 && localPos.x <= 563
					&& localPos.y >= 565 && localPos.y <= 595) {
					//skip left button
					if (previousPlayedSongs.size() > 0) {
						//play the most recent previously played song
						music.stop();
						musicChoice = previousPlayedSongs.back();
						previousPlayedSongs.pop_back();
						music.openFromFile(musicChoice + ".ogg");
						music.play();
					}
					else {
						music.setPlayingOffset(sf::milliseconds(0)); //just reset current song if we don't have any previous played songs
					}
				}
				else if (localPos.x >= 565 && localPos.x <= 590
					&& localPos.y >= 565 && localPos.y <= 595) {
					//skip right button
					music.stop();
				}
				else if (localPos.x >= 632 && localPos.x <= 732
					&& localPos.y >= 582 && localPos.y <= 592) {
					//set playing offset for music
					float xDelta = localPos.x - timeDurBar.getPosition().x;
					float timeMultiplier = xDelta / timeDurBar.getSize().x;
					music.setPlayingOffset(sf::milliseconds( int(music.getDuration().asMilliseconds() * timeMultiplier) ));
				}
				else if (localPos.x >= volBar.getPosition().x && localPos.x <= volBar.getPosition().x + volBar.getSize().x
					&& localPos.y >= volBar.getPosition().y && localPos.y <= volBar.getPosition().y + volBar.getSize().y) {
					//set volume
					float yDelta = localPos.y - volBar.getPosition().y;
					float volMultiplier = (volBar.getSize().y - yDelta) / volBar.getSize().y;
					const int maxVolume = 100.0;
					music.setVolume(maxVolume * volMultiplier);
				}
			}
			if (event.type == sf::Event::Closed) {
				window.close();
			}
		}

		//drawing stage
		window.clear(sf::Color::Black);

		window.draw(backSprite);

		titleText.setFont(gameFont);
		titleText.setString("AKB48");
		titleText.setPosition(200, 20);
		window.draw(titleText);
		
		//hacky-ish way of displaying unicode non-English characters on the title screen
		//this is hardcoded, so can't do this for long japanese inputs
		sf::Uint32 titleUniCharList[5] = { sf::Uint32(38899), sf::Uint32(27005), sf::Uint32(12466), sf::Uint32(12452), sf::Uint32(12512) };
		titleText.setFont(japaneseFont);
		for (int i = 0; i < 5; i++) {
			titleText.setString(titleUniCharList[i]);
			titleText.setPosition(300 + 50 * (i+1), 20);
			window.draw(titleText);
		}
		
		window.draw(startButton);
		window.draw(createButton);

		//hacky-ish way of displaying unicode non-English characters on the title screen
		//this is hardcoded, so can't do this for long japanese inputs
		sf::Uint32 startUniCharList[6] = { sf::Uint32(12461), sf::Uint32(12515), sf::Uint32(12531), sf::Uint32(12506), sf::Uint32(12540), sf::Uint32(12531) };
		startText.setFont(japaneseFont);
		for (int i = 0; i < 6; i++) {
			startText.setString(startUniCharList[i]);
			startText.setPosition(250 + 50 * i, 265);
			window.draw(startText);
		}
		//hacky-ish way of displaying unicode non-English characters on the title screen
		//this is hardcoded, so can't do this for long japanese inputs
		sf::Uint32 createUniCharList[7] = { sf::Uint32(12499), sf::Uint32(12540), sf::Uint32(12488), sf::Uint32(12513), sf::Uint32(12540), sf::Uint32(12459), sf::Uint32(12540) };
		createText.setFont(japaneseFont);
		for (int i = 0; i < 7; i++) {
			createText.setString(createUniCharList[i]);
			createText.setPosition(260 + 40 * i, 420);
			window.draw(createText);
		}

		//draw music player
		window.draw(musicBox);
		window.draw(playButton);
		buttonDivider.setPosition(sf::Vector2f(509, 565));
		window.draw(buttonDivider);
		window.draw(stopButton);
		buttonDivider.setPosition(sf::Vector2f(536, 565));
		window.draw(buttonDivider);
		skipLeftButton.setPosition(sf::Vector2f(544, 572));
		window.draw(skipLeftButton);
		skipLeftButton.setPosition(sf::Vector2f(554, 572));
		window.draw(skipLeftButton);
		buttonDivider.setPosition(sf::Vector2f(563, 565));
		window.draw(buttonDivider);
		skipRightButton.setPosition(sf::Vector2f(574, 585));
		window.draw(skipRightButton);
		skipRightButton.setPosition(sf::Vector2f(584, 585));
		window.draw(skipRightButton);
		buttonDivider.setPosition(sf::Vector2f(590, 565));
		window.draw(buttonDivider);
		window.draw(timeDurBar);
		//calculate position of curTimeBar based on current position in the song
		sf::Time musicCurTime = music.getPlayingOffset();
		sf::Time musicTotalDur = music.getDuration();
		curTimeBar.setPosition(sf::Vector2f(632 +
			(float(musicCurTime.asMilliseconds())/musicTotalDur.asMilliseconds()) *
			(timeDurBar.getSize().x-curTimeBar.getSize().x), 581));
		window.draw(curTimeBar);
		window.draw(songNameBar);
		//display song title
		musicText.setPosition(sf::Vector2f(597, 565));
		musicText.setString(musicChoice);
		window.draw(musicText);
		//display current time in song
		musicText.setPosition(sf::Vector2f(597, 580));
		std::string leftSideCurTime = std::to_string(int(musicCurTime.asSeconds()) / 60);
		if (leftSideCurTime.length() == 1) {
			leftSideCurTime = "0" + leftSideCurTime;
		}
		std::string rightSideCurTime = std::to_string(int(musicCurTime.asSeconds()) % 60);
		if (rightSideCurTime.length() == 1) {
			rightSideCurTime = "0" + rightSideCurTime;
		}
		musicText.setString(leftSideCurTime + ":" + rightSideCurTime);
		window.draw(musicText);
		//display total song duration
		musicText.setPosition(sf::Vector2f(737, 580));
		std::string leftSideTotalDur = std::to_string(int(musicTotalDur.asSeconds()) / 60);
		if (leftSideTotalDur.length() == 1) {
			leftSideTotalDur = "0" + leftSideTotalDur;
		}
		std::string rightSideTotalDur = std::to_string(int(musicTotalDur.asSeconds()) % 60);
		if (rightSideTotalDur.length() == 1) {
			rightSideTotalDur = "0" + rightSideTotalDur;
		}
		musicText.setString(leftSideTotalDur + ":" + rightSideTotalDur);
		window.draw(musicText);
		window.draw(volBar);
		const float maxVolume = 100.0;
		float curVolume = music.getVolume();
		curVolBar.setSize(sf::Vector2f(volBar.getSize().x, volBar.getSize().y * curVolume/maxVolume));
		curVolBar.setPosition(sf::Vector2f(volBar.getPosition().x, volBar.getPosition().y + volBar.getSize().y - curVolBar.getSize().y));
		window.draw(curVolBar);

		/*
		// Set mouse sprite position        
		mouseSprite.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
		window.draw(mouseSprite);
		*/

		window.display();
	}
	return 0;
}
Exemple #18
0
int main (void)
{
	//iniciçao da pic
  	initPIC32 ();
  	closedLoopControl( true );
  	setVel2(0, 0);

  	T4CONbits.TCKPS=5;
PR4=(PBCLK/32/3)-1;//fout 20MHz/(32*(62499+1))*10Hz,freq a 1 hz
TMR4=0;//Reset timer T2
T4CONbits.TON=1;
//Interrupts
IFS0bits.T4IF=0;//reset do timer
IPC4bits.T4IP=2;//priority
IEC0bits.T4IE=1;//enable timer3
EnableInterrupts();

	printStr(__FILE__); // para saber o nome do ficheiro que esta a correr no robot
	printf("\r    battery: %d ", batteryVoltage());
	printStr("\n");
	

//desligar os leds para o inicio
	leds(0b1111);	//leds off


  #if 0

	while(1)
	{
		while(!tick40ms);
		tick40ms=0;
		readAnalogSensors();
		


	}


  #endif



  while (TRUE)
    {
	
	
	TimeOut();		// timeOut => tb devia ir para uma inturrupcao

	//Sensor(); 	 //leitura os sensores tem de se por numa interropecao

	


	//botao de estado 

	if(startButton() == 1) // Botao start(preto) primido
	{
		estado = 1;
		resetCoreTimer();
		leds(0x1);
	
	}
	else if(stopButton() == 1) //Botao stop(vermelho) primido
	{
		estado = 0;
		leds(0x0);
	}

 	//funcoa de funcionameneto
	if(estado == 1) // robot fica em presesamento
	{
		Ver_Farol();
		printf("D: %d   F: %d   E: %d     LINHA: %d    Farol: %d \r",	sensor_dir,sensor_frente,sensor_esq,linha ,farolsen );
		ANDAR2();
	}
	//quando e primido o botao stop
	else if(stopButton() == 1)		// deslica o funcionamento, nenhum led activo
	{
		
		Stop_robot();
	
	}

    }
  return (0);
}
void SmugWindow::buttonStateChange(bool state)
{
    m_widget->m_newAlbumBtn->setEnabled(state);
    m_widget->m_reloadAlbumsBtn->setEnabled(state);
    startButton()->setEnabled(state);
}