X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmainloop.cpp;h=314de15765d69f1db051633cacef102b3d5483ab;hb=aec9bf199857d0ae1a5dc54cd96ae37177493deb;hp=55bc630ea08f43be05fe920edc984843bb8b4fd8;hpb=3c1a6970cd520620e6fd3ffe61a7011d23925a17;p=supertux.git diff --git a/src/mainloop.cpp b/src/mainloop.cpp index 55bc630ea..314de1576 100644 --- a/src/mainloop.cpp +++ b/src/mainloop.cpp @@ -49,7 +49,7 @@ static const int MAX_FRAME_SKIP = 2; MainLoop* main_loop = NULL; MainLoop::MainLoop() - : speed(1.0), nextpop(false), nextpush(false) + : speed(1.0), nextpop(false), nextpush(false), fps(0), screenshot_requested(false) { using namespace Scripting; TimeScheduler::instance = new TimeScheduler(); @@ -109,14 +109,20 @@ MainLoop::set_speed(float speed) this->speed = speed; } +float +MainLoop::get_speed() const +{ + return speed; +} + void MainLoop::draw_fps(DrawingContext& context, float fps_fps) { char str[60]; snprintf(str, sizeof(str), "%3.1f", fps_fps); const char* fpstext = "FPS"; - context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_HUD); - context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_HUD); + context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), ALIGN_LEFT, LAYER_HUD); + context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), ALIGN_RIGHT, LAYER_HUD); } void @@ -135,6 +141,11 @@ MainLoop::draw(DrawingContext& context) if(config->show_fps) draw_fps(context, fps); + // if a screenshot was requested, pass request on to drawing_context + if (screenshot_requested) { + context.take_screenshot(); + screenshot_requested = false; + } context.do_drawing(); /* Calculate frames per second */ @@ -173,6 +184,13 @@ MainLoop::process_events() Menu::current()->event(event); if(event.type == SDL_QUIT) quit(); + else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F11) { + config->use_fullscreen = !config->use_fullscreen; + init_video(); + } + else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_PRINT) { + take_screenshot(); + } } } @@ -237,7 +255,7 @@ MainLoop::run() int frames = 0; - if (elapsed_ticks > TICKS_PER_FRAME) { + if (elapsed_ticks > TICKS_PER_FRAME) { while(elapsed_ticks > TICKS_PER_FRAME && frames < MAX_FRAME_SKIP) { elapsed_ticks -= TICKS_PER_FRAME; float timestep = 1.0 / LOGICAL_FPS; @@ -258,3 +276,10 @@ MainLoop::run() SDL_Delay(0); } } + +void +MainLoop::take_screenshot() +{ + screenshot_requested = true; +} +