~ubuntu-branches/debian/sid/gource/sid

« back to all changes in this revision

Viewing changes to src/gource.cpp

  • Committer: Package Import Robot
  • Author(s): Andrew Caudwell
  • Date: 2014-04-15 16:30:17 UTC
  • mfrom: (1.2.15)
  • Revision ID: package-import@ubuntu.com-20140415163017-ucdr2josj1spzrga
Tags: 0.41-1
* New upstream release
* Made VCS URIs canonical
* Changed watch file to look at Github for releases

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
*/
17
17
 
18
18
#include "gource.h"
 
19
#include "core/png_writer.h"
19
20
 
20
21
bool  gGourceDrawBackground  = true;
21
22
bool  gGourceQuadTreeDebug   = false;
97
98
    mousedragged = false;
98
99
    mouseclicked = false;
99
100
 
 
101
    take_screenshot = false;
 
102
 
100
103
    if(gGourceSettings.hide_mouse) {
101
104
        cursor.showCursor(false);
102
105
    }
141
144
 
142
145
    logmill = new RLogMill(logfile);
143
146
 
144
 
    shutdown = false;
145
 
 
146
147
    if(exporter!=0) setFrameExporter(exporter, gGourceSettings.output_framerate);
147
148
 
148
149
    //if recording a video or in demo mode, or multiple repos, the slider is initially hidden
222
223
}
223
224
 
224
225
void Gource::quit() {
225
 
    shutdown = true;
226
226
}
227
227
 
228
228
void Gource::update(float t, float dt) {
251
251
    draw(runtime, scaled_dt);
252
252
 
253
253
    //extract frames based on frameskip setting if frameExporter defined
254
 
    if(frameExporter != 0 && commitlog && !shutdown) {
 
254
    if(frameExporter != 0 && commitlog && !gGourceSettings.shutdown) {
255
255
        if(framecount % (frameskip+1) == 0) {
256
256
            frameExporter->dump();
257
257
        }
286
286
    return date;
287
287
}
288
288
 
 
289
void Gource::grabMouse(bool grab_mouse) {
 
290
    this->grab_mouse = grab_mouse;
 
291
 
 
292
#if SDL_VERSION_ATLEAST(2,0,0)
 
293
    if(grab_mouse) {
 
294
        if(!SDL_GetRelativeMouseMode()) {
 
295
            // NOTE: SDL_SetWindowGrab needed as well to work around this bug:
 
296
            // http://bugzilla.libsdl.org/show_bug.cgi?id=1967
 
297
 
 
298
            SDL_SetWindowGrab(display.sdl_window, SDL_TRUE);
 
299
            SDL_SetRelativeMouseMode(SDL_TRUE);
 
300
        }
 
301
    } else {
 
302
        if(SDL_GetRelativeMouseMode()) {
 
303
            SDL_SetWindowGrab(display.sdl_window, SDL_FALSE);
 
304
            SDL_SetRelativeMouseMode(SDL_FALSE);
 
305
        }
 
306
    }
 
307
#endif
 
308
 
 
309
#if not SDL_VERSION_ATLEAST(2,0,0)
 
310
    if(!grab_mouse) {
 
311
        // restore old mouse position
 
312
        SDL_WarpMouse(mousepos.x, mousepos.y);
 
313
    }
 
314
#endif
 
315
 
 
316
    cursor.showCursor(!grab_mouse);
 
317
}
 
318
 
289
319
void Gource::mouseMove(SDL_MouseMotionEvent *e) {
290
320
    if(commitlog==0) return;
291
321
    if(gGourceSettings.hide_mouse) return;
292
322
 
293
 
    bool rightmouse = cursor.rightButtonPressed();
294
 
 
295
 
#if not SDL_VERSION_ATLEAST(1,3,0)
296
323
    if(grab_mouse) {
 
324
#if not SDL_VERSION_ATLEAST(2,0,0)
297
325
         int warp_x = display.width/2;
298
326
         int warp_y = display.height/2;
299
327
 
301
329
         if(e->x == warp_x && e->y == warp_y) return;
302
330
 
303
331
         SDL_WarpMouse(warp_x, warp_y);
 
332
#endif
304
333
    }
305
 
#endif
 
334
 
 
335
    bool rightmouse = cursor.rightButtonPressed();
306
336
 
307
337
    //move camera in direction the user dragged the mouse
308
338
    if(mousedragged || rightmouse) {
366
396
    camera.setDistance(distance);
367
397
}
368
398
 
369
 
#if SDL_VERSION_ATLEAST(1,3,0)
 
399
#if SDL_VERSION_ATLEAST(2,0,0)
370
400
void Gource::mouseWheel(SDL_MouseWheelEvent *e) {
371
401
 
372
 
   int mouse_x, mouse_y;
373
 
    SDL_GetMouseState(&mouse_x, &mouse_y);
374
 
 
375
 
    vec2 mousepos(mouse_x, mouse_y);
376
 
 
377
402
    if(e->y > 0) {
378
403
        zoom(true);
379
404
    }
402
427
 
403
428
        if(e->button == SDL_BUTTON_LEFT || e->button == SDL_BUTTON_RIGHT) {
404
429
            if(!cursor.buttonPressed()) {
405
 
                grab_mouse=false;
406
 
#if SDL_VERSION_ATLEAST(1,3,0)
407
 
                SDL_SetRelativeMouseMode(SDL_FALSE);
408
 
                SDL_WarpMouseInWindow(display.sdl_window, mousepos.x, mousepos.y);
409
 
#else
410
 
                SDL_WarpMouse(mousepos.x, mousepos.y);
411
 
#endif
412
 
                cursor.showCursor(true);
 
430
                grabMouse(false);
413
431
            }
414
432
        }
415
433
    }
416
434
 
417
435
    if(e->type != SDL_MOUSEBUTTONDOWN) return;
418
436
 
 
437
 
 
438
#if not SDL_VERSION_ATLEAST(2,0,0)
419
439
    //wheel up
420
440
    if(e->button == SDL_BUTTON_WHEELUP) {
421
441
        zoom(true);
427
447
        zoom(false);
428
448
        return;
429
449
    }
 
450
#endif
430
451
 
431
452
    if(e->button == SDL_BUTTON_MIDDLE) {
432
453
        toggleCameraMode();
435
456
 
436
457
 
437
458
    if(e->button == SDL_BUTTON_RIGHT) {
438
 
        cursor.showCursor(false);
439
 
        grab_mouse=true;
440
 
#if SDL_VERSION_ATLEAST(1,3,0)
441
 
        SDL_SetRelativeMouseMode(SDL_TRUE);
442
 
#endif
 
459
        grabMouse(true);
443
460
        return;
444
461
    }
445
462
 
510
527
 
511
528
    manual_camera = true;
512
529
 
513
 
    cursor.showCursor(false);
514
 
    grab_mouse=true;
515
530
    mousedragged=true;
 
531
 
 
532
    grabMouse(true);
516
533
}
517
534
 
518
535
//select a user, deselect current file/user
616
633
 
617
634
    if (e->type == SDL_KEYDOWN) {
618
635
 
619
 
#if SDL_VERSION_ATLEAST(1,3,0)
620
 
        bool key_escape       = e->keysym.scancode == SDL_SCANCODE_ESCAPE;
621
 
        bool key_tab          = e->keysym.scancode == SDL_SCANCODE_TAB;
622
 
        bool key_space        = e->keysym.scancode == SDL_SCANCODE_SPACE;
623
 
        bool key_plus         = e->keysym.scancode == SDL_SCANCODE_EQUALS;
624
 
        bool key_equals       = e->keysym.scancode == SDL_SCANCODE_EQUALS;
625
 
        bool key_minus        = e->keysym.scancode == SDL_SCANCODE_MINUS;
626
 
        bool key_leftbracket  = e->keysym.scancode == SDL_SCANCODE_LEFTBRACKET;
627
 
        bool key_rightbracket = e->keysym.scancode == SDL_SCANCODE_RIGHTBRACKET;
628
 
        bool key_comma        = e->keysym.scancode == SDL_SCANCODE_COMMA;
629
 
        bool key_period       = e->keysym.scancode == SDL_SCANCODE_PERIOD;
630
 
        bool key_slash        = e->keysym.scancode == SDL_SCANCODE_SLASH;
 
636
 
 
637
#if SDL_VERSION_ATLEAST(2,0,0)
 
638
        bool key_escape       = e->keysym.sym == SDLK_ESCAPE;
 
639
        bool key_tab          = e->keysym.sym == SDLK_TAB;
 
640
        bool key_space        = e->keysym.sym == SDLK_SPACE;
 
641
        bool key_plus         = e->keysym.sym == SDLK_PLUS;
 
642
        bool key_equals       = e->keysym.sym == SDLK_EQUALS;
 
643
        bool key_minus        = e->keysym.sym == SDLK_MINUS;
 
644
        bool key_leftbracket  = e->keysym.sym == SDLK_LEFTBRACKET;
 
645
        bool key_rightbracket = e->keysym.sym == SDLK_RIGHTBRACKET;
 
646
        bool key_comma        = e->keysym.sym == SDLK_COMMA;
 
647
        bool key_period       = e->keysym.sym == SDLK_PERIOD;
 
648
        bool key_slash        = e->keysym.sym == SDLK_SLASH;
631
649
#else
632
650
        bool key_escape       = e->keysym.unicode == SDLK_ESCAPE;
633
651
        bool key_tab          = e->keysym.unicode == SDLK_TAB;
641
659
        bool key_period       = e->keysym.unicode == SDLK_PERIOD;
642
660
        bool key_slash        = e->keysym.unicode == SDLK_SLASH;
643
661
#endif
644
 
 
645
662
        if (key_escape) {
646
663
            quit();
647
664
        }
649
666
        if(commitlog==0) return;
650
667
 
651
668
        if(e->keysym.sym == SDLK_F12) {
652
 
            screenshot();
 
669
            take_screenshot = true;
653
670
        }
654
671
 
655
672
        if (e->keysym.sym == SDLK_q) {
1086
1103
    //debugLog("readLog()\n");
1087
1104
 
1088
1105
    // read commits until either we are ahead of currtime
1089
 
    while(!commitlog->isFinished() && (commitqueue.empty() || (commitqueue.back().timestamp <= currtime && commitqueue.size() < commitqueue_max_size)) ) {
 
1106
    while((commitlog->hasBufferedCommit() || !commitlog->isFinished()) && (commitqueue.empty() || (commitqueue.back().timestamp <= currtime && commitqueue.size() < commitqueue_max_size)) ) {
1090
1107
 
1091
1108
        RCommit commit;
1092
1109
 
1097
1114
            continue;
1098
1115
        }
1099
1116
 
1100
 
         commitqueue.push_back(commit);
 
1117
        if(gGourceSettings.stop_timestamp != 0 && commit.timestamp > gGourceSettings.stop_timestamp) {
 
1118
            stop_position_reached = true;
 
1119
            break;
 
1120
        }
 
1121
 
 
1122
        commitqueue.push_back(commit);
1101
1123
    }
1102
1124
 
1103
1125
    if(first_read && commitqueue.empty()) {
1113
1135
 
1114
1136
    bool is_finished = commitlog->isFinished();
1115
1137
 
1116
 
    if(   (gGourceSettings.stop_at_end && is_finished)
1117
 
       || (gGourceSettings.stop_position > 0.0 && commitlog->isSeekable() && (is_finished || last_percent >= gGourceSettings.stop_position)) ) {
 
1138
 
 
1139
    if(
 
1140
       // end reached
 
1141
       (gGourceSettings.stop_at_end && is_finished)
 
1142
 
 
1143
       // stop position reached
 
1144
       || (gGourceSettings.stop_position > 0.0 && commitlog->isSeekable() && (is_finished || last_percent >= gGourceSettings.stop_position))
 
1145
    ) {
1118
1146
        stop_position_reached = true;
1119
1147
    }
1120
1148
 
1504
1532
 
1505
1533
void Gource::logic(float t, float dt) {
1506
1534
 
1507
 
    if(shutdown && logmill->isFinished()) {
 
1535
    if(gGourceSettings.shutdown && logmill->isFinished()) {
1508
1536
        appFinished=true;
1509
1537
        return;
1510
1538
    }
1552
1580
    bool up    = false;
1553
1581
    bool down  = false;
1554
1582
 
1555
 
#if SDL_VERSION_ATLEAST(1,3,0)
1556
 
    Uint8 *keystate = SDL_GetKeyboardState(0);
 
1583
#if SDL_VERSION_ATLEAST(2,0,0)
 
1584
    const Uint8 *keystate = SDL_GetKeyboardState(0);
1557
1585
 
1558
1586
    right = keystate[SDL_SCANCODE_RIGHT];
1559
1587
    left  = keystate[SDL_SCANCODE_LEFT];
1931
1959
            break;
1932
1960
    }
1933
1961
 
1934
 
    const char* action = !shutdown ? "Reading Log" : "Aborting";
 
1962
    const char* action = !gGourceSettings.shutdown ? "Reading Log" : "Aborting";
1935
1963
 
1936
1964
    int width = font.getWidth(action);
1937
1965
    font.setColour(vec4(1.0f));
2150
2178
void Gource::screenshot() {
2151
2179
 
2152
2180
    //get next free recording name
2153
 
    char tganame[256];
 
2181
    char pngname[256];
2154
2182
    struct stat finfo;
2155
 
    int tgano = 1;
 
2183
    int pngno = 1;
2156
2184
 
2157
 
    while(tgano < 10000) {
2158
 
        snprintf(tganame, 256, "gource-%04d.tga", tgano);
2159
 
        if(stat(tganame, &finfo) != 0) break;
2160
 
        tgano++;
 
2185
    while(pngno < 10000) {
 
2186
        snprintf(pngname, 256, "gource-%04d.png", pngno);
 
2187
        if(stat(pngname, &finfo) != 0) break;
 
2188
        pngno++;
2161
2189
    }
2162
2190
 
2163
 
    //write tga
2164
 
    std::string filename(tganame);
2165
 
 
2166
 
    TGAWriter tga(gGourceSettings.transparent ? 4 : 3);
2167
 
    tga.screenshot(filename);
2168
 
 
2169
 
    setMessage("Wrote screenshot %s", tganame);
 
2191
    //write png
 
2192
    std::string filename(pngname);
 
2193
 
 
2194
    PNGWriter png(gGourceSettings.transparent ? 4 : 3);
 
2195
    png.screenshot(filename);
 
2196
 
 
2197
    setMessage("Wrote screenshot %s", pngname);
2170
2198
}
2171
2199
 
2172
2200
void Gource::updateVBOs(float dt) {
2573
2601
        caption->draw();
2574
2602
    }
2575
2603
 
2576
 
    if(message_timer>0.0f) {
2577
 
         fontmedium.draw(1, 3, message);
2578
 
    }
2579
 
 
2580
2604
    //file key
2581
2605
    file_key.draw();
2582
2606
    file_key.setShow(gGourceSettings.show_key);
2674
2698
 
2675
2699
    mousemoved=false;
2676
2700
    mouseclicked=false;
 
2701
 
 
2702
    if(take_screenshot) {
 
2703
        screenshot();
 
2704
        take_screenshot = false;
 
2705
    }
 
2706
 
 
2707
    if(message_timer > 0.0f) {
 
2708
        font.setColour(vec4(1.0f));
 
2709
 
 
2710
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
2711
        glEnable(GL_BLEND);
 
2712
        glEnable(GL_TEXTURE_2D);
 
2713
 
 
2714
        font.draw(1, 3, message);
 
2715
    }
2677
2716
}