Exemple #1
0
	void Root::startRendering()
	{
		if( initialized == false ){
			Logger::getSingleton().log(Logger::WARNING, "Trying to start render loop while motor is not initialized");
			return;
		}
		Logger::getSingleton().log(Logger::INFO, "Motor renderloop started");

        running = true;
		sf::Event Event;
		//FPS counting
		int frameCount = 0;
		float frameTime = 0;
		timer->getElapsedTime(); //t=0
		while(running && window->isOpen() ){
			while(window->pollEvent(Event)) {
				switch( Event.type ){
				case sf::Event::KeyPressed:
					keyDown( Event.key.code , true ); break;
				case sf::Event::KeyReleased:
					keyDown( Event.key.code , false ); break;
				case sf::Event::MouseMoved:
					mouseMoved( Event.mouseMove.x, Event.mouseMove.y );
					//mRenderer->SetMousePosition( Event.motion.x, Event.motion.y );
					break;
				case sf::Event::MouseWheelMoved:
					mouseWheelMoved( Event.mouseWheel.delta );
					break;
				case sf::Event::MouseButtonPressed:
					mouseDown( (MOUSEBUTTON)Event.mouseButton.button, true, Event.mouseButton.x, Event.mouseButton.y );
					break;
				case sf::Event::MouseButtonReleased:
					mouseDown( (MOUSEBUTTON)Event.mouseButton.button, false, Event.mouseButton.x, Event.mouseButton.y );
					break;
				case sf::Event::Closed:
					running = false;
					break;
				default:
					break;
				}
			}

            float elapsedTime = timer->getElapsedTime();
			++frameCount;
			frameTime += elapsedTime;
			if( frameTime > 1.0f ){
				Logger::getSingleton() << Logger::INFO << "FPS: " << (float)frameCount/frameTime;
				Logger::getSingleton() << "\t(frametime " << frameTime/(float)frameCount << ")" << endLog;
				frameCount = 0;
				frameTime = 0;
			}

			//Call frame listeners
			for( std::vector<FrameListener*>::iterator it = frameListeners.begin(); it != frameListeners.end(); ++it ){
				(*it)->onFrame( elapsedTime );
			}

			if( renderOneFrame() == false ) break;
		}
	}
    std::queue<Event> SFMLInputBackend::fetchEvents()
    {
        sf::Event event;
        std::queue<Event> result;

        while (mWindow.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                result.push(closed());
            else if(event.type == sf::Event::Resized)
                result.push(resized(event));
            else if(event.type == sf::Event::LostFocus)
                result.push(lostFocus());
            else if(event.type == sf::Event::GainedFocus)
                result.push(gainedFocus());
            else if(event.type == sf::Event::TextEntered)
                result.push(textEntered(event));
            else if(event.type == sf::Event::KeyPressed)
                result.push(keyPressed(event));
            else if(event.type == sf::Event::KeyReleased)
                result.push(keyReleased(event));
            else if(event.type == sf::Event::MouseWheelMoved)
                result.push(mouseWheelMoved(event));
            else if(event.type == sf::Event::MouseButtonPressed)
                result.push(mouseButtonPressed(event));
            else if(event.type == sf::Event::MouseButtonReleased)
                result.push(mouseButtonReleased(event));
            else if(event.type == sf::Event::MouseMoved)
                result.push(mouseMoved(event));
            else if(event.type == sf::Event::MouseEntered)
                result.push(mouseEntered());
            else if(event.type == sf::Event::MouseLeft)
                result.push(mouseLeft());
            else if(event.type == sf::Event::JoystickButtonPressed)
                result.push(gamepadButtonPressed(event));
            else if(event.type == sf::Event::JoystickButtonReleased)
                result.push(gamepadButtonReleased(event));
            else if(event.type == sf::Event::JoystickMoved)
                result.push(gamepadMoved(event));
            else if(event.type == sf::Event::JoystickConnected)
                result.push(gamepadConnected(event));
            else if(event.type == sf::Event::JoystickDisconnected)
                result.push(gamepadDisconnected(event));
        }

        return result;
    }
Exemple #3
0
//---------------------------------------------------------
//   wheelEvent
//---------------------------------------------------------
void WaveView::wheelEvent(QWheelEvent* ev)
{
  int keyState = ev->modifiers();

  bool shift      = keyState & Qt::ShiftModifier;
  bool ctrl       = keyState & Qt::ControlModifier;

  if (shift) { // scroll vertically
      int delta       = -ev->delta() / WHEEL_DELTA;
      int xpixelscale = 5*MusECore::fast_log10(rmapxDev(1));


      if (xpixelscale <= 0)
            xpixelscale = 1;

      int scrollstep = WHEEL_STEPSIZE * (delta);
      ///if (ev->state() == Qt::ShiftModifier)
  //      if (((QInputEvent*)ev)->modifiers() == Qt::ShiftModifier)
      scrollstep = scrollstep / 10;

      int newXpos = xpos + xpixelscale * scrollstep;

      if (newXpos < 0)
            newXpos = 0;

      //setYPos(newYpos);
      emit horizontalScroll((unsigned)newXpos);


  } else if (ctrl) {  // zoom horizontally
    if (ev->delta()>0)
      emit horizontalZoomIn();
    else
      emit horizontalZoomOut();

  } else { // scroll horizontally
      emit mouseWheelMoved(ev->delta() / 10);
  }

}
Exemple #4
0
	void BaseManager::run()
	{
#ifndef EMSCRIPTEN
		while (!mExit)
#endif
		{
			while (SDL_PollEvent(&mEvent) != 0)
			{
				switch (mEvent.type)
				{
					// keyboard events
				case SDL_KEYDOWN:
					mKeyCode = mEvent.key.keysym.sym;
					keyPressed(mKeyCode, nullptr);
					break;
				case SDL_TEXTINPUT:
					mKeyCode = SDLK_UNKNOWN;
					keyPressed(mKeyCode, &mEvent.text);
					break;
				case SDL_KEYUP:
					keyReleased(mEvent.key);
					break;
					// mouse events
				case SDL_MOUSEMOTION:
					mouseMoved(mEvent.motion);
					break;
				case SDL_MOUSEBUTTONDOWN:
					mousePressed(mEvent.button);
					break;
				case SDL_MOUSEBUTTONUP:
					mouseReleased(mEvent.button);
					break;
				case SDL_MOUSEWHEEL:
					mouseWheelMoved(mEvent.wheel);
					break;
					// drop file events
				case SDL_DROPFILE:
					break;
					// windows events
				case SDL_WINDOWEVENT:
					switch (mEvent.window.event)
					{
					case SDL_WINDOWEVENT_CLOSE:
						mExit = true;
						break;
					case SDL_WINDOWEVENT_RESIZED:
						_windowResized(mEvent.window.data1, mEvent.window.data2);
						break;
					case SDL_WINDOWEVENT_SHOWN:
					case SDL_WINDOWEVENT_RESTORED:
					case SDL_WINDOWEVENT_EXPOSED:
					case SDL_WINDOWEVENT_MAXIMIZED:
						mWindowOn = true;
						break;
					case SDL_WINDOWEVENT_MINIMIZED:
					case SDL_WINDOWEVENT_HIDDEN:
						mWindowOn = false;
					default:
						break;
					}
					break;
				default:
					break;
				}
			}
			glClearColor(0, 0, 0, 1);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			drawOneFrame();
			if (!mWindowOn)
				SDL_Delay(50);
		}
	}