void TINS12Game::onLogic()
{
	if (Input::isPressed(Button_ToggleFullscreen))
	{
		toggleFullscreen();
	}

	if (Input::isPressed(Button_ToggleSlowMotion))
	{
		toggleSlowMotion();
	}

	if (Input::isPressed(Button_ToggleVSync))
	{
		toggleVSync();
	}

	if (Input::isPressed(Button_ToggleWideScreen))
	{
		toggleWideScreen();
	}

	if (Input::isPressed(Button_ForceQuit) || ScreenManager::isEmpty())
	{
		halt();
	}
}
MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    webView = new QWebView();
    webView->setWindowTitle("contentEditor preview");
    webView->setWindowFlags(Qt::WindowStaysOnTopHint); // | Qt::FramelessWindowHint

    pageHandler::loadPages();
    pageHandler::treeWidget = ui->pagesList;
    pageHandler::pageStack = ui->pageStack;
    pageHandler::webView = webView;
    pageHandler::setup();

    setGeometry(50, 50, 1200, 700);

    connect(ui->savePage,SIGNAL(triggered()),pageHandler::getSingleton(), SLOT(savePage()));
    connect(ui->togglePagesList,SIGNAL(triggered()),this, SLOT(togglePagesList()));
    connect(ui->toggleFullscreen,SIGNAL(triggered()),this, SLOT(toggleFullscreen()));
    connect(ui->togglePreview,SIGNAL(triggered()),this, SLOT(togglePreview()));
    connect(ui->newPage,SIGNAL(triggered()),this, SLOT(addPage()));
    connect(ui->newField,SIGNAL(triggered()),this, SLOT(addField()));
    connect(ui->backgroundColor, SIGNAL(triggered()), pageHandler::getSingleton(), SLOT(setFieldBackgroundColor()));
    connect(ui->addImage, SIGNAL(triggered()), pageHandler::getSingleton(), SLOT(addImage()));
    connect(ui->toggleText, SIGNAL(triggered()), pageHandler::getSingleton(), SLOT(toggleTextEdit()));
    connect(ui->pageBackgroundColor, SIGNAL(triggered()), pageHandler::getSingleton(), SLOT(setPageBackgroundColor()));
    connect(ui->printPDF, SIGNAL(triggered()), pageHandler::getSingleton(), SLOT(exportPDF()));


    lastWebViewGeometry = QRect(200,200,500,400);
}
Exemple #3
0
void App::setFullscreen(bool enabled)
{
    if (fullscreen_ != enabled)
    {
        toggleFullscreen();
    }
}
Exemple #4
0
void TuioDemo::processEvents()
{
    SDL_Event event;

    while( SDL_PollEvent( &event ) ) {

        switch( event.type ) {
		case SDL_KEYDOWN:
			if( event.key.keysym.sym == SDLK_ESCAPE ){
				running = false;
				SDL_ShowCursor(true);
				SDL_Quit();
			} else if( event.key.keysym.sym == SDLK_F1 ){
				toggleFullscreen();
			} else if( event.key.keysym.sym == SDLK_v ){
				verbose = !verbose;	
			} 

			break;
		case SDL_QUIT:
			running = false;
			SDL_ShowCursor(true);
			SDL_Quit();
			break;
        }
    }
}
Exemple #5
0
int MainWindow::exec()
{
    sf::Clock clock;
    float goalTime = clock.GetElapsedTime();
    float interval = 1.0f / c_fps;

    while (m_window->IsOpened()) {
        // Process events
        sf::Event event;
        while (m_window->GetEvent(event)) {
            if (event.Type == sf::Event::Closed)
                m_window->Close();
            else if(event.Type == sf::Event::KeyPressed) {
                if (event.Key.Code == sf::Key::F4 && event.Key.Alt)
                    m_window->Close();
                else if (event.Key.Alt && event.Key.Code == sf::Key::Return)
                    toggleFullscreen();
            }
        }

        // next logic frame in the gameplay
        m_gameplay->nextFrame();
        goalTime += interval;

        // draw. frame skip if we're too late!
        if (clock.GetElapsedTime() < goalTime) {
            m_gameplay->updateDisplay();
            m_window->Display();
        }
    }

    return (m_gameplay != NULL && m_gameplay->isGood()) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Exemple #6
0
void UIYabause::fullscreenRequested( bool f )
{
	if ( isFullScreen() && !f )
	{
#ifdef USE_UNIFIED_TITLE_TOOLBAR
		setUnifiedTitleAndToolBarOnMac( true );
#endif
		toggleFullscreen(0, 0, false, -1 );
		showNormal();

		VolatileSettings* vs = QtYabause::volatileSettings();
		int menubarHide = vs->value( "View/Menubar" ).toInt();
		if ( menubarHide == BD_HIDEFS ||
			  menubarHide == BD_SHOWONFSHOVER)
			menubar->show();
		if ( vs->value( "View/Toolbar" ).toInt() == BD_HIDEFS )
			toolBar->show();

		setCursor(Qt::ArrowCursor);
		hideMouseTimer->stop();
	}
	else if ( !isFullScreen() && f )
	{
#ifdef USE_UNIFIED_TITLE_TOOLBAR
		setUnifiedTitleAndToolBarOnMac( false );
#endif
		VolatileSettings* vs = QtYabause::volatileSettings();

		setMaximumSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
		setMinimumSize( 0,0 );

		toggleFullscreen(vs->value("Video/FullscreenWidth").toInt(), vs->value("Video/FullscreenHeight").toInt(), 
						f, vs->value("Video/VideoFormat").toInt());

		showFullScreen();

		if ( vs->value( "View/Menubar" ).toInt() == BD_HIDEFS )
			menubar->hide();
		if ( vs->value( "View/Toolbar" ).toInt() == BD_HIDEFS )
			toolBar->hide();

		hideMouseTimer->start(3 * 1000);
	}
	if ( aViewFullscreen->isChecked() != f )
		aViewFullscreen->setChecked( f );
	aViewFullscreen->setIcon( QIcon( f ? ":/actions/no_fullscreen.png" : ":/actions/fullscreen.png" ) );
}
Exemple #7
0
LargePhotoView::LargePhotoView(QString path, QWidget *parent, ThumbnailView *listArea) : QWidget(parent) {
    layout = new QGridLayout(this);
    this->listArea = listArea;

    fullscreen = false;

    photoWidget = new LargePhotoWidget(path,this);
    layout->addWidget(photoWidget,1,0);

    toolbar = new QToolBar("",this);
    layout->addWidget(toolbar,2,0);
    setLayout(layout);

    QString shortCut("O");
    QAction *action = toolbar->addAction(QIcon::fromTheme("folder"),getShortcutLabel("Open in file manager",shortCut),
                                         this,SLOT(openInFileManager()));
    action->setShortcut(QKeySequence(shortCut));
    shortCut = QString("E");
    action = toolbar->addAction(QIcon::fromTheme("image-x-generic"),getShortcutLabel("Edit photo in other application",shortCut),
                                this,SLOT(editPhoto()));
    action->setShortcut(QKeySequence(shortCut));
    toolbar->addSeparator();
    shortCut = QString("Ctrl+Shift+R");
    action = toolbar->addAction(QIcon::fromTheme("object-rotate-left"),getShortcutLabel("Rotate anti-clockwise",shortCut),
                                this,SLOT(rotatePhotoAntiClockwise()));
    action->setShortcut(QKeySequence(shortCut));
    shortCut = QString("Ctrl+R");
    action = toolbar->addAction(QIcon::fromTheme("object-rotate-right"),getShortcutLabel("Rotate clockwise",shortCut),
                                this,SLOT(rotatePhotoClockwise()));
    action->setShortcut(QKeySequence(shortCut));

    toolbar->addSeparator();

    shortCut = QString("Escape");
    action = toolbar->addAction(QIcon::fromTheme("go-up"),getShortcutLabel("Back to event",shortCut),
                                this,SLOT(backAction()));
    action->setShortcut(QKeySequence(shortCut));

    shortCut = QString("Left");
    action = toolbar->addAction(QIcon::fromTheme("go-previous"),getShortcutLabel("Previous photo",shortCut),
                                this,SLOT(prevPhoto()));
    action->setShortcut(QKeySequence(shortCut));

    shortCut = QString("Right");
    action = toolbar->addAction(QIcon::fromTheme("go-next"),getShortcutLabel("Next photo",shortCut),
                                this,SLOT(nextPhoto()));
    action->setShortcut(QKeySequence(shortCut));

    toolbar->addSeparator();

    shortCut = QString("F11");
    action = toolbar->addAction(QIcon::fromTheme("view-fullscreen"),getShortcutLabel("Toggle Fullscreen",shortCut),this,SLOT(toggleFullscreen()));
    action->setShortcut(QKeySequence(shortCut));

    connect(photoWidget,SIGNAL(doubleClicked()),this,SLOT(toggleFullscreen()));

    setFocus();
}
Exemple #8
0
SeparateWindow::SeparateWindow() : QMainWindow()
{
  // Create a new splitViewWidget and set it as center widget
  splitView = new splitViewWidget(this, true);
  setCentralWidget(splitView);
  splitView->setAttribute(Qt::WA_AcceptTouchEvents);

  connect(splitView, SIGNAL(signalToggleFullScreen()), this, SLOT(toggleFullscreen()));
};
Exemple #9
0
void screenKeyboard(const SDL_KeyboardEvent &key)
{
  // Global key commands
  if (key.type == SDL_KEYDOWN && key.keysym.sym == SDLK_F11)
    toggleFullscreen();
  
  // Send events to the current screen
  if (!screenStack.empty())
    screenStack.back()->keyboard(key);
}
Exemple #10
0
	int cmdGraphics(CmdContext* /*_context*/, void* /*_userData*/, int _argc, char const* const* _argv)
	{
		if (_argc > 1)
		{
			if (setOrToggle(s_reset, "vsync",       BGFX_RESET_VSYNC,              1, _argc, _argv)
			||  setOrToggle(s_reset, "maxaniso",    BGFX_RESET_MAXANISOTROPY,      1, _argc, _argv)
			||  setOrToggle(s_reset, "hmd",         BGFX_RESET_HMD,                1, _argc, _argv)
			||  setOrToggle(s_reset, "hmddbg",      BGFX_RESET_HMD_DEBUG,          1, _argc, _argv)
			||  setOrToggle(s_reset, "hmdrecenter", BGFX_RESET_HMD_RECENTER,       1, _argc, _argv)
			||  setOrToggle(s_reset, "msaa",        BGFX_RESET_MSAA_X16,           1, _argc, _argv)
			||  setOrToggle(s_reset, "flush",       BGFX_RESET_FLUSH_AFTER_RENDER, 1, _argc, _argv)
			||  setOrToggle(s_reset, "flip",        BGFX_RESET_FLIP_AFTER_RENDER,  1, _argc, _argv)
			||  setOrToggle(s_reset, "hidpi",       BGFX_RESET_HIDPI,              1, _argc, _argv)
			||  setOrToggle(s_reset, "depthclamp",  BGFX_RESET_DEPTH_CLAMP,        1, _argc, _argv)
			   )
			{
				return 0;
			}
			else if (setOrToggle(s_debug, "stats",     BGFX_DEBUG_STATS,     1, _argc, _argv)
				 ||  setOrToggle(s_debug, "ifh",       BGFX_DEBUG_IFH,       1, _argc, _argv)
				 ||  setOrToggle(s_debug, "text",      BGFX_DEBUG_TEXT,      1, _argc, _argv)
				 ||  setOrToggle(s_debug, "wireframe", BGFX_DEBUG_WIREFRAME, 1, _argc, _argv) )
			{
				bgfx::setDebug(s_debug);
				return 0;
			}
			else if (0 == strcmp(_argv[1], "screenshot") )
			{
				if (_argc > 2)
				{
					bgfx::saveScreenShot(_argv[2]);
				}
				else
				{
					time_t tt;
					time(&tt);

					char filePath[256];
					bx::snprintf(filePath, sizeof(filePath), "temp/screenshot-%d", tt);
					bgfx::saveScreenShot(filePath);
				}

				return 0;
			}
			else if (0 == strcmp(_argv[1], "fullscreen") )
			{
				WindowHandle window = { 0 };
				toggleFullscreen(window);
				return 0;
			}
		}

		return 1;
	}
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: togglePagesList((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 1: togglePagesList(); break;
        case 2: toggleFullscreen((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 3: toggleFullscreen(); break;
        case 4: togglePreview((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 5: togglePreview(); break;
        case 6: onPreviewHide(); break;
        case 7: addPage(); break;
        case 8: addField(); break;
        default: ;
        }
        _id -= 9;
    }
    return _id;
}
Exemple #12
0
void SeparateWindow::keyPressEvent( QKeyEvent * event )
{
  int key = event->key();
  bool control = (event->modifiers() == Qt::ControlModifier);
  if (key == Qt::Key_F && control)
    toggleFullscreen();
  else if (key == Qt::Key_1 && control)
    emit signalSingleWindowMode();
  else if (key == Qt::Key_0 && control)
    splitView->resetViews();
  else if (key == Qt::Key_9 && control)
    splitView->zoomToFit();
  else if (key == Qt::Key_Plus && control)
    splitView->zoomIn();
  else if (key == Qt::Key_BracketRight && control)
    // This seems to be a bug in the Qt localization routine. On the german keyboard layout this key is returned
    // if Ctrl + is pressed. 
    splitView->zoomIn();
  else if (key == Qt::Key_Minus && control)
    splitView->zoomOut();
  else if (key == Qt::Key_Escape)
  {
    if (isFullScreen())
      toggleFullscreen();
  }
  else if (key == Qt::Key_Space)
    emit signalPlayPauseToggle();
  else if (key == Qt::Key_Right)
    emit signalNextFrame();
  else if (key == Qt::Key_Left)
    emit signalPreviousFrame();
  else if (key == Qt::Key_Down)
    emit signalNextItem();
  else if (key == Qt::Key_Up)
    emit signalPreviousItem();
  else
    QWidget::keyPressEvent(event);
}
void GameWindow::update()
{
    sf::Event event;
    while (_window.pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
        {
            _isDone = true;
        }
        else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F5)
        {
            toggleFullscreen();
        }
    }
}
Exemple #14
0
void
key (unsigned char mychar, int x, int y)
{
    switch (mychar) {
    case 'f':
        toggleFullscreen ();
        break;
    case 'i':
        dset.displayInfo = dset.displayInfo ? 0 : 1;
        break;
    case 27:
    case 'q':
        exit (EXIT_SUCCESS);
    default:
        break;
    }
}
Exemple #15
0
Spaceinium::Spaceinium() {
	Preferences::init();

	createWindow(Preferences::windowedVideoMode, false);
	load();
	init();

	currentState = NULL;
	switchState(new MenuState());

	while (window.isOpen()) {
		sf::Event event;
		while (window.pollEvent(event)) {
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::F)) {
				toggleFullscreen();
			}

			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
				window.close();

			if (event.type == sf::Event::KeyPressed) {
				Input::addDown(event.key.code);
			}

			if (event.type == sf::Event::KeyReleased) {
				Input::removeHeld(event.key.code);
			}

			if (event.type == sf::Event::Resized)
				window.setView(
						getViewportBox(window.getView(), event.size.width,
								event.size.height));

			if (event.type == sf::Event::Closed)
				window.close();
		}

		Input::updateMousePos(sf::Mouse::getPosition(Spaceinium::window));

		render();
		window.display();
		update();

		Input::clearInput();
	}
}
Exemple #16
0
bool App::launch()
{
    if (osc_recv_port_ == 0)
        if (verbose_)
            std::cout << "OSC receiving disabled." << std::endl;
    else
        startOSC();
    // Poll OSC receiver only when we render a Clutter frame.

    if (stage_)
    {
        std::cerr << "cannot create stage twice" << std::endl;
        //return false;
    }
    stage_ = clutter_stage_get_default();
    clutter_actor_set_size(stage_, 1024, 768);
    ClutterColor black = { 0x00, 0x00, 0x00, 0xff };
    clutter_stage_set_color(CLUTTER_STAGE(stage_), &black);
    g_signal_connect(stage_, "destroy", G_CALLBACK(clutter_main_quit), NULL);
    clutter_actor_set_reactive(stage_, TRUE);

    // timeline to attach a callback for each frame that is rendered
    ClutterTimeline *timeline;
    timeline = clutter_timeline_new(60); // ms
    clutter_timeline_set_loop(timeline, TRUE);
    clutter_timeline_start(timeline);

    g_signal_connect(timeline, "new-frame", G_CALLBACK(on_frame_cb), this);
    g_signal_connect(stage_, "key-press-event", G_CALLBACK(key_event_cb), this);
    g_signal_connect(stage_, "button-press-event", G_CALLBACK(button_press_cb), this);
    g_signal_connect(stage_, "button-release-event", G_CALLBACK(button_released_cb), this);
    g_signal_connect(stage_, "motion-event", G_CALLBACK(motion_event_cb), this);

    if (fullscreen_)
    {
        fullscreen_ = false;
        toggleFullscreen();
    }

    createPalette();

    clutter_actor_show(stage_);
    return true;
}
Exemple #17
0
RenderWidget::RenderWidget(QString title, Emulator* emu, QWidget* parent /*= 0*/) :
    _emu(emu),
    QWidget(parent)
{
    setAttribute(Qt::WA_PaintOnScreen, true);
    setAttribute(Qt::WA_NativeWindow, true);
    setAttribute(Qt::WA_NoSystemBackground);
    setAttribute(Qt::WA_OpaquePaintEvent);

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(displayVI()));
    timer->start(1000);

    romName = title;
    setWindowTitle(romName);

    QShortcut* flscrn = new QShortcut(QKeySequence("F11"), this);
    connect(flscrn, SIGNAL(activated()), this, SLOT(toggleFullscreen()));
}
int main(int argc, char* argv[]) {
    getScreenshot(std::string(SCRSHOT_NAME));
    std::this_thread::sleep_for(std::chrono::microseconds(10000)); //give the screenshot script time to run
    int h=0;
    if (SDL_Init(SDL_INIT_VIDEO) < 0 ) {
        printf("Unable to initialize SDL");
        return 1;
    }
    if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL))) {
        SDL_Quit();
        return 1;
    }
#if startFullscreen
    toggleFullscreen();
#endif
    //set up SDL's OpenGL defaults
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,            8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,          8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,           8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,          8);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,          16);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,         32);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,      8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,    8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,     8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,    8);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,  1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,  2);
    setScreenSize(getImageSize(SCRSHOT_NAME));
    WIDTH = getScreenSize().w;    HEIGHT = getScreenSize().h;
    printf("Screen size detected as: (%d,%d)\n",getScreenSize().w,getScreenSize().h);
    loadGame();
    running = true;
    startFPSCounter();
    startInputListener();
    startAutomaticFiring();
    while(running) {
        drawScreen(screen,h++);
    }
    SDL_Quit();
    return 0;
}
Exemple #19
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    switch(iMsg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
        break;

        case WM_ACTIVATE:
            isActive = (HIWORD(wParam) == 0);
        break;

        case WM_SIZE:
            resize(LOWORD(lParam), HIWORD(lParam));
        break;

        case WM_KEYDOWN:
            switch(wParam)
            {
                case VK_ESCAPE:
                    isEscapeKeyPressed = true;;
                break;

                // 0x46 is hex value for key 'F' or 'f'
                case 0x46:
                    isFullscreen = !isFullscreen;
                    toggleFullscreen(isFullscreen);
                break;

                default:
                break;
            }

        break;

        default:
        break;
    }

    return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
Exemple #20
0
void OptionsMenuUserInterface::processSelection(U32 index)
{
   switch(index)
   {
   case 0:
      controlsRelative = !controlsRelative;
      break;
   case 1:
      toggleFullscreen();
      break;
   case 2:
      joystickType++;
      if(joystickType > XBoxController)
         joystickType = -1;
      break;
   case 3:
      echoVoice = !echoVoice;
      break;
   };
   setupMenus();
}
Exemple #21
0
MapOverlay::MapOverlay(MapWidget *mapWidget) {
  qDebug() << __FUNCTION__;

  // create a buttonmanager and fill with buttons
  m_mapButtonManager = new MapButtonManager(mapWidget);
  
  MapButton *zoom_in = m_mapButtonManager->create("zoom_in", 1, 1);
  QObject::connect(zoom_in, SIGNAL(clicked()), mapWidget, SLOT(zoomIn()));
  
  MapButton *gps = m_mapButtonManager->create("gps", 1, 2, MapButton::Disabled);
  QObject::connect(gps, SIGNAL(clicked()), mapWidget, SLOT(gpsFollow()));
  
  MapButton *zoom_out = m_mapButtonManager->create("zoom_out", 1, 3);
  QObject::connect(zoom_out, SIGNAL(clicked()), mapWidget, SLOT(zoomOut()));
  
  MapButton *update = m_mapButtonManager->create("update", -1, 1, MapButton::Hidden);
  QObject::connect(update, SIGNAL(clicked()), mapWidget, SLOT(manualUpdate()));

  MapButton *fullscreen = m_mapButtonManager->create("fs", -1, -1);
  QObject::connect(fullscreen, SIGNAL(clicked()), mapWidget, SLOT(toggleFullscreen()));
};
Exemple #22
0
void GameWindow::mainLoop() {
    bool bExit = false;
    while (!bExit) {
        SDL_Event event;
        while (SDL_PollEvent(&event)) { // not thead save; calls SDL_PumpEvents(); call only from main/video-init thread
            if (event.type == SDL_QUIT)
                bExit = true;
            if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
                bExit = true;
            if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE)
                bExit = true;
            if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F10) {
                toggleFullscreen();
            }
        }
        // render the next frame and swap the buffers
        opengl_->renderFrame();
        SDL_GL_SwapWindow(sdl_window_);
        //Sleep(5); // to get lower fps
    }
    printf("Terminating...\n");
}
Exemple #23
0
bool Device::run()
{
	int ticks = SDL_GetTicks();
	if (ticks - lastticks < TBF)
		SDL_Delay(TBF-(ticks-lastticks));
	lastticks = ticks;
	SDL_Event e;
	while(SDL_PollEvent(&e))
	{
		switch(e.type)
		{
			case SDL_QUIT:
				done = true;
				break;
			case SDL_KEYDOWN:
				switch (e.key.keysym.sym)
				{
					case SDLK_F4:
						if (e.key.keysym.mod & KMOD_ALT)
							done = true;
						break;
					case SDLK_F11:
						toggleFullscreen();
						break;
					default:
						break;
				}
				break;
			case SDL_MOUSEMOTION:
				mousepos.x = e.motion.x;
				mousepos.y = e.motion.y;
				break;
			default:
				break;
		}
		eventStack.push(e);
	}
	return !done;
}
Exemple #24
0
void SimpleSimulator::processEvents()
{
    SDL_Event event;

    while( SDL_PollEvent( &event ) ) {

        switch( event.type ) {
		case SDL_KEYDOWN:
			if( event.key.keysym.sym == SDLK_ESCAPE ){
				running = false;
				SDL_ShowCursor(true);
				SDL_Quit();
			} else if( event.key.keysym.sym == SDLK_F1 ){
				toggleFullscreen();
			} else if( event.key.keysym.sym == SDLK_v ){
				verbose = !verbose;	
				tuioServer->setVerbose(verbose);
			} 
			break;
				
		case SDL_MOUSEMOTION:
			if (event.button.button & SDL_BUTTON(1)) mouseDragged((float)event.button.x/width, (float)event.button.y/height);
			break;
		case SDL_MOUSEBUTTONDOWN:
			if (event.button.button & SDL_BUTTON(1)) mousePressed((float)event.button.x/width, (float)event.button.y/height);
			break;
		case SDL_MOUSEBUTTONUP:
			if (event.button.button & SDL_BUTTON(1)) mouseReleased((float)event.button.x/width, (float)event.button.y/height);
			break;
		case SDL_QUIT:
			running = false;
			SDL_ShowCursor(true);
			SDL_Quit();
			break;
        }
    }
}
void Application::update()
{
	Event event;
	while (window.pollEvent(event) && window.isOpen())
	{
		switch(event.type)
		{
		case Event::Closed:window.close();
			break;
		case Event::KeyPressed:
			if(Keyboard::isKeyPressed(Keyboard::LAlt) && Keyboard::isKeyPressed(Keyboard::Return))
			{
				toggleFullscreen();
			}
			else
				elems.top()->handleEvent(event);
			break;
		default: elems.top()->handleEvent(event);
		}
	}

	if(window.isOpen())
	elems.top()->update();
}
Exemple #26
0
void inputPoll(SDL_Joystick *joy)
{

	//internal_input_state.buttons=0;
	while(SDL_PollEvent(&eventjoy))
	{
	    switch(eventjoy.type)
	    {

		case SDL_JOYAXISMOTION:
	        	if( eventjoy.jaxis.axis == 0){
		//		internal_input_state.axis1x=eventjoy.jaxis.value;
				if(eventjoy.jaxis.value < -3200){
					internal_input_state.buttons&=~INPUTBUTTONRIGHT;
					internal_input_state.buttons|=INPUTBUTTONLEFT;
				}else if(eventjoy.jaxis.value > 3200){
					internal_input_state.buttons&=~INPUTBUTTONLEFT;
					internal_input_state.buttons|=INPUTBUTTONRIGHT;
				}else{
					internal_input_state.buttons&=~INPUTBUTTONLEFT;
					internal_input_state.buttons&=~INPUTBUTTONRIGHT;
				}

			}
			if( eventjoy.jaxis.axis == 1){
		//		internal_input_state.axis1y=eventjoy.jaxis.value;
				if(eventjoy.jaxis.value < -3200){
					internal_input_state.buttons&=~INPUTBUTTONDOWN;
					internal_input_state.buttons|=INPUTBUTTONUP;
				}else if(eventjoy.jaxis.value > 3200){
					internal_input_state.buttons&=~INPUTBUTTONUP;
					internal_input_state.buttons|=INPUTBUTTONDOWN;
				}else{
					internal_input_state.buttons&=~INPUTBUTTONUP;
					internal_input_state.buttons&=~INPUTBUTTONDOWN;
				}
			}
		break;

		case SDL_JOYBUTTONDOWN:

			if(eventjoy.jbutton.button==joystick0.buttona)
			{
				internal_input_state.buttons|=INPUTBUTTONA;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonb)
			{
				internal_input_state.buttons|=INPUTBUTTONB;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonc)
			{
				internal_input_state.buttons|=INPUTBUTTONC;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonl)
			{
				internal_input_state.buttons|=INPUTBUTTONL;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonr)
			{
				internal_input_state.buttons|=INPUTBUTTONR;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonx)
			{
				internal_input_state.buttons|=INPUTBUTTONX;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonp)
			{
				internal_input_state.buttons|=INPUTBUTTONP;
			}

		break;

		case SDL_JOYBUTTONUP:

			if(eventjoy.jbutton.button==joystick0.buttona)
			{
				internal_input_state.buttons&=~INPUTBUTTONA;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonb)
			{
				internal_input_state.buttons&=~INPUTBUTTONB;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonc)
			{
				internal_input_state.buttons&=~INPUTBUTTONC;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonl)
			{
				internal_input_state.buttons&=~INPUTBUTTONL;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonr)
			{
				internal_input_state.buttons&=~INPUTBUTTONR;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonx)
			{
				internal_input_state.buttons&=~INPUTBUTTONX;
			}
			else if(eventjoy.jbutton.button==joystick0.buttonp)
			{
				internal_input_state.buttons&=~INPUTBUTTONP;
			}

		break;

		case SDL_QUIT:
			isexit=1;break;

		case SDL_KEYDOWN:
	                switch( eventjoy.key.keysym.sym ){
				case SDLK_LEFT:
					internal_input_state.buttons&=~INPUTBUTTONRIGHT;
					internal_input_state.buttons|=INPUTBUTTONLEFT;
						break;
				case SDLK_RIGHT:
					internal_input_state.buttons|=INPUTBUTTONRIGHT;
					internal_input_state.buttons&=~INPUTBUTTONLEFT;
						break;
				case SDLK_UP:
					internal_input_state.buttons|=INPUTBUTTONUP;
					internal_input_state.buttons&=~INPUTBUTTONDOWN;
						break;
				case SDLK_DOWN:
					internal_input_state.buttons&=~INPUTBUTTONUP;
					internal_input_state.buttons|=INPUTBUTTONDOWN;
						break;
				case SDLK_z:
			        	internal_input_state.buttons|=INPUTBUTTONC;
						break;
				case SDLK_x:
		        		internal_input_state.buttons|=INPUTBUTTONB;
						break;
				case SDLK_c:
		        		internal_input_state.buttons|=INPUTBUTTONA;
						break;
				case SDLK_v:
		        		internal_input_state.buttons|=INPUTBUTTONR;
						break;
				case SDLK_a:
		        		internal_input_state.buttons|=INPUTBUTTONX;
						break;
				case SDLK_s:
		        		internal_input_state.buttons|=INPUTBUTTONP;
						break;
				case SDLK_f:
		        		internal_input_state.buttons|=INPUTBUTTONL;
						break;
				default:
					break;
			}break;

		case SDL_KEYUP:
	                switch( eventjoy.key.keysym.sym ){
				case SDLK_LEFT:
					internal_input_state.buttons&=~INPUTBUTTONRIGHT;
					internal_input_state.buttons&=~INPUTBUTTONLEFT;
					break;
				case SDLK_RIGHT:
					internal_input_state.buttons&=~INPUTBUTTONRIGHT;
					internal_input_state.buttons&=~INPUTBUTTONLEFT;
					break;
				case SDLK_UP:
					internal_input_state.buttons&=~INPUTBUTTONUP;
					internal_input_state.buttons&=~INPUTBUTTONDOWN;
					break;
				case SDLK_DOWN:
					internal_input_state.buttons&=~INPUTBUTTONUP;
					internal_input_state.buttons&=~INPUTBUTTONDOWN;
					break;
				case SDLK_z:
			        	internal_input_state.buttons&=~INPUTBUTTONC;
						break;
				case SDLK_x:
		        		internal_input_state.buttons&=~INPUTBUTTONB;
						break;
				case SDLK_c:
		        		internal_input_state.buttons&=~INPUTBUTTONA;
						break;
				case SDLK_v:
		        		internal_input_state.buttons&=~INPUTBUTTONR;
						break;
				case SDLK_a:
		        		internal_input_state.buttons&=~INPUTBUTTONX;
						break;
				case SDLK_s:
		        		internal_input_state.buttons&=~INPUTBUTTONP;
						break;
				case SDLK_f:
		        		internal_input_state.buttons&=~INPUTBUTTONL;
						break;
				case SDLK_F11:
		        		fullscreen^=1;
						if(fullscreen)toggleFullscreen();
				case SDLK_ESCAPE:
		        		isexit=1;
						break;
				default:
					break;
			}break;

	    }
	}

}
Exemple #27
0
void
Gui::notify_key_event(gnash::key::code k, int modifier, bool pressed) 
{

    // Handle GUI shortcuts
    if (pressed) {
        if (k == gnash::key::ESCAPE) {
            if (isFullscreen()) {
                _stage->setStageDisplayState(movie_root::DISPLAYSTATE_NORMAL);
            }
        }
	
        if (modifier & gnash::key::GNASH_MOD_CONTROL) {
            switch (k) {
              case gnash::key::o:
              case gnash::key::O:
                  takeScreenShot();
                  break;
              case gnash::key::r:
              case gnash::key::R:
                  restart();
                  break;
              case gnash::key::p:
              case gnash::key::P:
                  pause();
                  break;
              case gnash::key::l:
              case gnash::key::L:
                  refreshView();
                  break;
              case gnash::key::q:
              case gnash::key::Q:
              case gnash::key::w:
              case gnash::key::W:
                  quit();
                  break;
              case gnash::key::f:
              case gnash::key::F:
                  toggleFullscreen();
                  break;
              case gnash::key::h:
              case gnash::key::H:
                  showUpdatedRegions(!showUpdatedRegions());
                  break;
              case gnash::key::MINUS:
              {
                  // Max interval allowed: 1 second (1FPS)
                  const size_t ni = std::min<size_t>(_interval + 2, 1000u);
                  setInterval(ni);
                  break;
              }
              case gnash::key::PLUS:
              {
                  // Min interval allowed: 1/100 second (100FPS)
                  const size_t ni = std::max<size_t>(_interval - 2, 10u);
                  setInterval(ni);
                  break;
              }
              case gnash::key::EQUALS:
              {
                  if (_stage) {
                      const float fps = _stage->getRootMovie().frameRate();
                      // Min interval allowed: 1/100 second (100FPS)
                      const size_t ni = 1000.0/fps;
                      setInterval(ni);
                  }
                  break;
              }
              default:
                  break;
            }
            
#ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS
            if ( _keyboardMouseMovements ) {
                int step = _keyboardMouseMovementsStep; 
                // x5 if SHIFT is pressed
                if (modifier & gnash::key::GNASH_MOD_SHIFT) step *= 5; 
                switch (k) {
                  case gnash::key::UP:
                  {
                      int newx = _xpointer;
                      int newy = _ypointer-step;
                      if ( newy < 0 ) newy=0;
                      notifyMouseMove(newx, newy);
                      break;
                  }
                  case gnash::key::DOWN:
                  {
                      int newx = _xpointer;
                      int newy = _ypointer+step;
                      if ( newy >= _height ) newy = _height-1;
                      notifyMouseMove(newx, newy);
                      break;
                  }
                  case gnash::key::LEFT:
                  {
                      int newx = _xpointer-step;
                      int newy = _ypointer;
                      if ( newx < 0 ) newx = 0;
                      notifyMouseMove(newx, newy);
                      break;
                  }
                  case gnash::key::RIGHT:
                  {
                      const int newy = _ypointer;
                      int newx = _xpointer + step;
                      if ( newx >= _width ) newx = _width-1;
                      notifyMouseMove(newx, newy);
                      break;
                  }
                  default:
                      break;
                }
            }
#endif // ENABLE_KEYBOARD_MOUSE_MOVEMENTS
        }
    }
    
    if (!_started) return;
    
    if (_stopped) return;
    
    if (_stage->keyEvent(k, pressed)) {
        // any action triggered by the
        // event required screen refresh
        display(_stage);
    }
    
}
MainWindow::MainWindow(QString url, int quality, int listen_port, bool view_only):
    QMainWindow(0),
    vnc_view(0),
    scroll_area(new ScrollArea(this)),
    input_toolbuttons(new QActionGroup(this)),
    key_menu(0)
{
    setWindowTitle("Presence VNC");
#ifdef Q_WS_MAEMO_5
    setContextMenuPolicy(Qt::NoContextMenu);
    setAttribute(Qt::WA_Maemo5StackedWindow);
#endif

    migrateConfiguration();

    //set up toolbar
    toolbar = new QToolBar(0);
    key_menu_button = input_toolbuttons->addAction(toolbar->addAction(QChar(0x2026), this, SLOT(showKeyMenu()))); //"..." button
    key_menu_button->setCheckable(true); //used to indicate wether a modifier key is still pressed
    input_toolbuttons->addAction(toolbar->addAction(tr("Tab"), this, SLOT(sendTab())));
    input_toolbuttons->addAction(toolbar->addAction(tr("Esc"), this, SLOT(sendEsc())));
    input_toolbuttons->addAction(toolbar->addAction(tr("PgUp"), this, SLOT(sendPgUp())));
    input_toolbuttons->addAction(toolbar->addAction(tr("PgDn"), this, SLOT(sendPgDn())));
#ifdef Q_WS_MAEMO_5
    input_toolbuttons->addAction(toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/chat_enter.png"), "", this, SLOT(sendReturn())));
    input_toolbuttons->addAction(toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/control_keyboard.png"), "", this, SLOT(showInputPanel())));
#endif

    QSettings settings;
    zoom_slider = new QSlider(Qt::Horizontal, 0);
    zoom_slider->setRange(0, 100);
    connect(zoom_slider, SIGNAL(valueChanged(int)),
            this, SLOT(setZoomLevel(int)));
    connect(zoom_slider, SIGNAL(sliderReleased()),
            this, SLOT(zoomSliderReleased()));
    zoom_slider->setValue(settings.value("zoomlevel", 95).toInt());
    toolbar->addWidget(zoom_slider);

#ifdef Q_WS_MAEMO_5
    toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/general_fullsize.png"), "", this, SLOT(toggleFullscreen()));
#else
    toolbar->addAction(tr("Toggle Fullscreen"), this, SLOT(toggleFullscreen()));
#endif
    addToolBar(toolbar);
    toolbar->setVisible(settings.value("show_toolbar", true).toBool());
    toolbar->setEnabled(false);

    //set up menu
    QAction *connect_action = new QAction(tr("Connect"), this);
    disconnect_action = new QAction(tr("Disconnect"), this);
    show_toolbar = new QAction(tr("Show toolbar"), this);
    show_toolbar->setCheckable(true);
    show_toolbar->setChecked(settings.value("show_toolbar", true).toBool());
    QAction *pref_action = new QAction(tr("Preferences"), this);
    QAction *about_action = new QAction(tr("About"), this);

#ifdef Q_WS_MAEMO_5
    menuBar()->addAction(connect_action);
    menuBar()->addAction(disconnect_action);
    menuBar()->addAction(show_toolbar);
    menuBar()->addAction(pref_action);
    menuBar()->addAction(about_action);
#else
    QMenu* session_menu = menuBar()->addMenu(tr("&Session"));
    session_menu->addAction(connect_action);
    session_menu->addAction(disconnect_action);
    session_menu->addSeparator();
    session_menu->addAction(pref_action);
    session_menu->addSeparator();
    session_menu->addAction(tr("&Quit"), this, SLOT(close()));

    QMenu* view_menu = menuBar()->addMenu(tr("&View"));
    view_menu->addAction(show_toolbar);

    QMenu* help_menu = menuBar()->addMenu(tr("&Help"));
    help_menu->addAction(about_action);
#endif

    connect(about_action, SIGNAL(triggered()),
            this, SLOT(about()));
    connect(pref_action, SIGNAL(triggered()),
            this, SLOT(showPreferences()));
    connect(connect_action, SIGNAL(triggered()),
            this, SLOT(showConnectDialog()));
    connect(disconnect_action, SIGNAL(triggered()),
            this, SLOT(disconnectFromHost()));
    connect(show_toolbar, SIGNAL(toggled(bool)),
            toolbar, SLOT(setVisible(bool)));
    connect(show_toolbar, SIGNAL(toggled(bool)),
            this, SLOT(updateScreenSpaceDelayed()));
#ifdef Q_WS_MAEMO_5
    QDBusConnection::systemBus().connect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DISPLAY_SIG,
                                         this, SLOT(displayStateChanged(QString)));
#endif

    setCentralWidget(scroll_area);

    connect(scroll_area, SIGNAL(fullscreenButtonClicked()),
            this, SLOT(toggleFullscreen()));

    grabZoomKeys(true);
    reloadSettings();

    if(url.isEmpty() and listen_port == 0) {
        disconnect_action->setEnabled(false);
        showConnectDialog();
    } else {
        connectToHost(url, quality, listen_port, view_only);
    }
}
Exemple #29
0
Window::Window()
	: m_toolbar(0),
	m_fullscreen(true),
	m_typewriter_sounds(true),
	m_auto_save(true),
	m_save_positions(true),
	m_goal_type(0),
	m_time_goal(0),
	m_wordcount_goal(0),
	m_current_time(0),
	m_current_wordcount(0)
{
	setAcceptDrops(true);
	setAttribute(Qt::WA_DeleteOnClose);
	setContextMenuPolicy(Qt::NoContextMenu);
	setWindowIcon(QIcon(":/focuswriter.png"));

	// Set up icons
	if (QIcon::themeName().isEmpty()) {
		QIcon::setThemeName("hicolor");
		setIconSize(QSize(22,22));
	}

	// Create window contents first so they stack behind documents
	menuBar();
	m_toolbar = new QToolBar(this);
	m_toolbar->setFloatable(false);
	m_toolbar->setMovable(false);
	addToolBar(m_toolbar);
	QWidget* contents = new QWidget(this);
	setCentralWidget(contents);

	// Create documents
	m_documents = new Stack(this);
	m_sessions = new SessionManager(this);
	m_timers = new TimerManager(m_documents, this);
	m_load_screen = new LoadScreen(this);
	connect(m_documents, SIGNAL(footerVisible(bool)), m_timers->display(), SLOT(setVisible(bool)));
	connect(m_documents, SIGNAL(formattingEnabled(bool)), this, SLOT(setFormattingEnabled(bool)));
	connect(m_documents, SIGNAL(updateFormatActions()), this, SLOT(updateFormatActions()));
	connect(m_documents, SIGNAL(updateFormatAlignmentActions()), this, SLOT(updateFormatAlignmentActions()));
        connect(m_documents, SIGNAL(updateFormatHeadingActions()), this, SLOT(updateFormatHeadingActions()));
	connect(m_sessions, SIGNAL(themeChanged(Theme)), m_documents, SLOT(themeSelected(Theme)));

	// Set up menubar and toolbar
	initMenus();

	// Set up details
	m_footer = new QWidget(contents);
	QWidget* details = new QWidget(m_footer);
	m_wordcount_label = new QLabel(tr("Words: 0"), details);
	m_page_label = new QLabel(tr("Pages: 0"), details);
	m_paragraph_label = new QLabel(tr("Paragraphs: 0"), details);
	m_character_label = new QLabel(tr("Characters: 0"), details);
	m_progress_label = new QLabel(tr("0% of daily goal"), details);
	m_clock_label = new QLabel(details);
	updateClock();

	// Set up clock
	m_clock_timer = new QTimer(this);
	m_clock_timer->setInterval(60000);
	connect(m_clock_timer, SIGNAL(timeout()), this, SLOT(updateClock()));
	connect(m_clock_timer, SIGNAL(timeout()), m_timers, SLOT(saveTimers()));
	int delay = (60 - QTime::currentTime().second()) * 1000;
	QTimer::singleShot(delay, m_clock_timer, SLOT(start()));
	QTimer::singleShot(delay, this, SLOT(updateClock()));

	// Set up tabs
	m_tabs = new QTabBar(m_footer);
	m_tabs->setShape(QTabBar::RoundedSouth);
	m_tabs->setDocumentMode(true);
	m_tabs->setExpanding(false);
	m_tabs->setMovable(true);
	m_tabs->setTabsClosable(true);
	m_tabs->setUsesScrollButtons(true);
	connect(m_tabs, SIGNAL(currentChanged(int)), this, SLOT(tabClicked(int)));
	connect(m_tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosed(int)));
	connect(m_tabs, SIGNAL(tabMoved(int, int)), this, SLOT(tabMoved(int, int)));
	new QShortcut(QKeySequence::NextChild, this, SLOT(nextDocument()));
	new QShortcut(QKeySequence::PreviousChild, this, SLOT(previousDocument()));

	// Lay out details
	QHBoxLayout* clock_layout = new QHBoxLayout;
	clock_layout->setMargin(0);
	clock_layout->setSpacing(6);
	clock_layout->addWidget(m_timers->display(), 0, Qt::AlignCenter);
	clock_layout->addWidget(m_clock_label);

	QHBoxLayout* details_layout = new QHBoxLayout(details);
	details_layout->setSpacing(25);
	details_layout->setMargin(6);
	details_layout->addWidget(m_wordcount_label);
	details_layout->addWidget(m_page_label);
	details_layout->addWidget(m_paragraph_label);
	details_layout->addWidget(m_character_label);
	details_layout->addStretch();
	details_layout->addWidget(m_progress_label);
	details_layout->addStretch();
	details_layout->addLayout(clock_layout);

	// Lay out footer
	QVBoxLayout* footer_layout = new QVBoxLayout(m_footer);
	footer_layout->setSpacing(0);
	footer_layout->setMargin(0);
	footer_layout->addWidget(details);
	footer_layout->addWidget(m_tabs);

	// Lay out window
	QVBoxLayout* layout = new QVBoxLayout(contents);
	layout->setSpacing(0);
	layout->setMargin(0);
	layout->addStretch();
	layout->addWidget(m_footer);

	// Load current daily progress
	QSettings settings;
	if (settings.value("Progress/Date").toDate() != QDate::currentDate()) {
		settings.remove("Progress");
	}
	settings.setValue("Progress/Date", QDate::currentDate().toString(Qt::ISODate));
	m_current_wordcount = settings.value("Progress/Words", 0).toInt();
	m_current_time = settings.value("Progress/Time", 0).toInt();
	updateProgress();

	// Load settings
	Preferences preferences;
	loadPreferences(preferences);
	m_documents->themeSelected(settings.value("ThemeManager/Theme").toString());

	// Restore window geometry
	setMinimumSize(640, 480);
	resize(800, 600);
	restoreGeometry(settings.value("Window/Geometry").toByteArray());
	m_fullscreen = !settings.value("Window/Fullscreen", true).toBool();
	toggleFullscreen();
	m_actions["Fullscreen"]->setChecked(m_fullscreen);
	show();

	// Update themes
	m_load_screen->setText(tr("Loading themes"));
	Theme::copyBackgrounds();

	// Load sounds
	m_load_screen->setText(tr("Loading sounds"));
	m_key_sound = new Sound("keyany.wav", this);
	m_enter_key_sound = new Sound("keyenter.wav", this);

	// Update margin
	m_tabs->blockSignals(true);
	m_tabs->addTab(tr("Untitled"));
	updateMargin();
	m_tabs->removeTab(0);
	m_tabs->blockSignals(false);

	// Open previous documents
	QString session = settings.value("SessionManager/Session").toString();
	QStringList files = QApplication::arguments().mid(1);
	if (!files.isEmpty()) {
		session.clear();
		settings.setValue("Save/Current", files);
		settings.setValue("Save/Positions", QStringList());
		settings.setValue("Save/Active", 0);
	}
	m_sessions->setCurrent(session);
}
Exemple #30
0
void InputHandler::handleEvent(sf::Event Event) {
    float time;

    // Close window : exit
    if (Event.Type == sf::Event::Closed)
        context->window->Close();

    // Handle text input for chat
    if (InChat && Event.Type == sf::Event::TextEntered) {

        // Ignore the first char (which is t)
        if (inputWaiting) {
            inputWaiting = false;
            return;
        }

        // Handle ASCII characters only
        if (Event.Text.Unicode == 8) { // TODO: use KeyPressed?
            if (context->hud->chatEntry.size() > 0)
                context->hud->chatEntry.erase(context->hud->chatEntry.size() - 1, 1);
        } else if (Event.Text.Unicode < 128) {
            context->hud->chatEntry += static_cast<char>(Event.Text.Unicode);
        }
    }

    // Handle enter to send message
    if (InChat && Event.Type == sf::Event::KeyPressed) {
        switch(Event.Key.Code) {
        // F11 : toggle fullscreen
        case sf::Key::F11:
            toggleFullscreen();
            break;

        // Escape key : cancel message
        case sf::Key::Escape:
            context->hud->chatEntry = "";
            InChat = false;
            return; // don't run the handlers from down there

        // Enter : send message
        case sf::Key::Return:
            context->socket->SendChat(context->hud->chatEntry);
            context->hud->chatEntry = "";
            InChat = false;
            return; // don't run the handlers from down there

        }
    }

    // Otherwise....
    if (!InChat && Event.Type == sf::Event::KeyPressed) {
        switch(Event.Key.Code) {
        // Escape key : exit
        case sf::Key::Escape:
            context->inGame = false;
            break;
        // F11 : toggle fullscreen
        case sf::Key::F11:
            toggleFullscreen();
            break;

        // T : chat
        case sf::Key::T:
            context->hud->chatEntry = ""; // TODO: needed?
            InChat = true;
            inputWaiting = true;
            break;

        // W : forward
        case sf::Key::W:
            context->player->Forward = true;
            break;
        // S : backward
        case sf::Key::S:
            context->player->Backward = true;
            break;
        // A : left
        case sf::Key::A:
            context->player->Left = true;
            break;
        // D : right
        case sf::Key::D:
            context->player->Right = true;
            break;

        // Left Control, C : crouch
        case sf::Key::LControl:
        case sf::Key::C:
            MovementTimer.Reset();
            WasCrouching = context->player->Crouching;
            context->player->Crouching = true;
            break;

        // V : crawl
        case sf::Key::V:
            MovementTimer.Reset();
            WasCrawling = context->player->Crawling;
            context->player->Crawling = true;
            break;

        // Left Shift : run
        case sf::Key::LShift:
            MovementTimer.Reset();
            WasRunning = context->player->Running;
            context->player->Running = true;
            break;

        // Space : jump
        case sf::Key::Space:
            context->player->Jumping = true;
            break;
        }
    }

    if (Event.Type == sf::Event::KeyReleased) {
        time = MovementTimer.GetElapsedTime();

        switch(Event.Key.Code) {
        // W : forward
        case sf::Key::W:
            context->player->Forward = false;
            break;
        // S : backward
        case sf::Key::S:
            context->player->Backward = false;
            break;
        // A : left
        case sf::Key::A:
            context->player->Left = false;
            break;
        // D : right
        case sf::Key::D:
            context->player->Right = false;
            break;

        // Left Control, C : crouch
        case sf::Key::LControl:
        case sf::Key::C:
            if (time > 0.1)
                context->player->Crouching = false;
            else
                context->player->Crouching = !WasCrouching;
            break;

        // V : crawl
        case sf::Key::V:
            if (time > 0.1)
                context->player->Crawling = false;
            else
                context->player->Crawling = !WasCrawling;
            break;

        // Left Shift : run
        case sf::Key::LShift:
            if (time > 0.1)
                context->player->Running = false;
            else
                context->player->Running = !WasRunning;

        // Space : jump
        case sf::Key::Space:
            context->player->Jumping = false;
            break;
        }
    }

    // Resize event : adjust viewport
    if (Event.Type == sf::Event::Resized)
        glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}