~widelands-dev/widelands/bug-1390793

« back to all changes in this revision

Viewing changes to src/wlapplication.cc

  • Committer: fios at foramnagaidhlig
  • Date: 2015-06-07 09:37:12 UTC
  • mfrom: (7384.1.87 trunk)
  • Revision ID: fios@foramnagaidhlig.net-20150607093712-37kh4fkvv9mueh6v
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
490
490
        return true;
491
491
}
492
492
 
493
 
bool WLApplication::handle_key(const SDL_Keycode& keycode, int modifiers) {
494
 
        const bool ctrl = (modifiers & KMOD_LCTRL) || (modifiers & KMOD_RCTRL);
495
 
        switch (keycode) {
496
 
        case SDLK_F10:
497
 
                // exits the game.
498
 
                if (ctrl) {
499
 
                        m_should_die = true;
500
 
                }
501
 
                return true;
502
 
 
503
 
        case SDLK_F11:
504
 
                // Takes a screenshot.
505
 
                if (ctrl) {
506
 
                        if (g_fs->disk_space() < MINIMUM_DISK_SPACE) {
507
 
                                log("Omitting screenshot because diskspace is lower than %luMB\n",
508
 
                                    MINIMUM_DISK_SPACE / (1000 * 1000));
509
 
                                break;
510
 
                        }
511
 
                        g_fs->ensure_directory_exists(SCREENSHOT_DIR);
512
 
                        for (uint32_t nr = 0; nr < 10000; ++nr) {
513
 
                                const std::string filename = (boost::format(SCREENSHOT_DIR "/shot%04u.png") % nr).str();
514
 
                                if (g_fs->file_exists(filename)) {
515
 
                                        continue;
516
 
                                }
517
 
                                g_gr->screenshot(filename);
518
 
                                break;
519
 
                        }
520
 
                }
521
 
                return true;
522
 
 
523
 
        case SDLK_f: {
524
 
                // toggle fullscreen
525
 
                bool value = !g_gr->fullscreen();
526
 
                g_gr->set_fullscreen(value);
527
 
                g_options.pull_section("global").set_bool("fullscreen", value);
528
 
                return true;
529
 
        }
530
 
 
531
 
        default:
532
 
                break;
 
493
bool WLApplication::handle_key(bool down, const SDL_Keycode& keycode, int modifiers) {
 
494
        if (down) {
 
495
                const bool ctrl = (modifiers & KMOD_LCTRL) || (modifiers & KMOD_RCTRL);
 
496
                switch (keycode) {
 
497
                case SDLK_F10:
 
498
                        // exits the game.
 
499
                        if (ctrl) {
 
500
                                m_should_die = true;
 
501
                        }
 
502
                        return true;
 
503
 
 
504
                case SDLK_F11:
 
505
                        // Takes a screenshot.
 
506
                        if (ctrl) {
 
507
                                if (g_fs->disk_space() < MINIMUM_DISK_SPACE) {
 
508
                                        log("Omitting screenshot because diskspace is lower than %luMB\n",
 
509
                                                 MINIMUM_DISK_SPACE / (1000 * 1000));
 
510
                                        break;
 
511
                                }
 
512
                                g_fs->ensure_directory_exists(SCREENSHOT_DIR);
 
513
                                for (uint32_t nr = 0; nr < 10000; ++nr) {
 
514
                                        const std::string filename = (boost::format(SCREENSHOT_DIR "/shot%04u.png") % nr).str();
 
515
                                        if (g_fs->file_exists(filename)) {
 
516
                                                continue;
 
517
                                        }
 
518
                                        g_gr->screenshot(filename);
 
519
                                        break;
 
520
                                }
 
521
                        }
 
522
                        return true;
 
523
 
 
524
                case SDLK_f: {
 
525
                        // toggle fullscreen
 
526
                        bool value = !g_gr->fullscreen();
 
527
                        g_gr->set_fullscreen(value);
 
528
                        g_options.pull_section("global").set_bool("fullscreen", value);
 
529
                        return true;
 
530
                }
 
531
 
 
532
                default:
 
533
                        break;
 
534
                }
533
535
        }
534
536
        return false;
535
537
}
539
541
        SDL_Event ev;
540
542
        while (poll_event(ev)) {
541
543
                switch (ev.type) {
 
544
                case SDL_KEYUP:
542
545
                case SDL_KEYDOWN: {
543
546
                        bool handled = false;
544
547
                        if (cb && cb->key) {
545
548
                                handled = cb->key(ev.type == SDL_KEYDOWN, ev.key.keysym);
546
549
                        }
547
550
                        if (!handled) {
548
 
                                handle_key(ev.key.keysym.sym, ev.key.keysym.mod);
 
551
                                handle_key(ev.type == SDL_KEYDOWN, ev.key.keysym.sym, ev.key.keysym.mod);
549
552
                        }
550
553
                } break;
551
554