Skip to content
Browse files

Dragging on the background controls the camera, instead of clicking.

Mouse automatically hides if inactive for 3 seconds.
  • Loading branch information...
1 parent aac1f03 commit daabce30acda79ca0866622a06f4ba4f2bb8ded8 @acaudwell committed Feb 24, 2010
Showing with 63 additions and 7 deletions.
  1. +3 −1 ChangeLog
  2. +2 −1 README
  3. +1 −1 data/gource.1
  4. +53 −4 src/gource.cpp
  5. +4 −0 src/gource.h
View
4 ChangeLog
@@ -1,9 +1,11 @@
0.25:
* Bazaar support (John Arbash Meinel).
- * Clicking the background moves the camera over where you clicked.
+ * Dragging the mouse on the background moves the camera.
+ * Mouse automatically hides after 3 seconds of inactivity.
* Added --camera-mode option (track,overview).
* Support DOS line endings in logs.
* Improved compatibility of hg log command (Brendan Cully).
+ * Fixed PPM exporter producing blank images on some video cards.
* Fixed parsing of negative timezones from cvs-exp.pl logs.
* Fixed various gdb and compiler warnings.
View
3 README
@@ -247,7 +247,8 @@ may use the mouse to inspect the detail of individual files and users.
TAB cycles through selecting the current visible users.
The camera mode, either tracking activity, or showing the entire code tree, can
-be toggled using the V key.
+be toggled using the V key. You can drag the mouse on the background to
+manually control the camera.
Interactive keyboard commands:
View
2 data/gource.1
@@ -220,7 +220,7 @@ Pressing SPACE at any time will pause/unpause the simulation. While paused you m
TAB cycles through selecting the current visible users.
-The camera mode, either tracking activity, or showing the entire code tree, can be toggled using the V key.
+The camera mode, either tracking activity, or showing the entire code tree, can be toggled using the V key. You can drag the mouse on the background to manually control the camera.
Interactive keyboard commands:
.sp
View
57 src/gource.cpp
@@ -269,6 +269,7 @@ Gource::Gource(std::string logfile) {
draw_loading = true;
mousemoved = false;
+ mousedragged = false;
mouseclicked = false;
splash = -1.0;
@@ -380,6 +381,16 @@ std::string Gource::dateAtPosition(float percent) {
void Gource::mouseMove(SDL_MouseMotionEvent *e) {
if(commitlog==0) return;
+ //move camera in direction the user dragged the mouse
+ if(mousedragged) {
+ backgroundPos += vec2f( e->xrel, e->yrel );
+
+ return;
+ }
+
+ mouse_inactivity = 0.0;
+ SDL_ShowCursor(true);
+
mousepos = vec2f(e->x, e->y);
mousemoved=true;
@@ -413,7 +424,27 @@ void Gource::zoom(bool zoomin) {
}
void Gource::mouseClick(SDL_MouseButtonEvent *e) {
- if(e->type != SDL_MOUSEBUTTONDOWN || commitlog==0) return;
+ if(commitlog==0) return;
+
+ if(e->type == SDL_MOUSEBUTTONUP) {
+
+ if(e->button == SDL_BUTTON_LEFT) {
+
+ mouse_inactivity=0.0;
+ SDL_ShowCursor(true);
+
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+
+ //stop dragging mouse, return the mouse to where
+ //the user started dragging.
+ if(mousedragged) {
+ SDL_WarpMouse(mousepos.x, mousepos.y);
+ mousedragged=false;
+ }
+ }
+ }
+
+ if(e->type != SDL_MOUSEBUTTONDOWN) return;
//wheel up
if(e->button == SDL_BUTTON_WHEELUP) {
@@ -498,12 +529,17 @@ void Gource::selectBackground() {
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
- gluPickMatrix((GLdouble) mousepos.x, (GLdouble) (viewport[3]-mousepos.y), 1.0f, 1.0f, viewport);
-
gluPerspective(90.0f, (GLfloat)display.width/(GLfloat)display.height, 0.1f, -camera.getPos().z);
camera.look();
- backgroundPos = display.unproject(mousepos).truncate();
+ vec2f screen_centre(display.width*0.5,display.height*0.5);
+
+ backgroundPos = display.unproject(screen_centre).truncate();
+
+ SDL_ShowCursor(false);
+ SDL_WM_GrabInput(SDL_GRAB_ON);
+
+ mousedragged=true;
}
//select a user, deselect current file/user
@@ -778,6 +814,9 @@ void Gource::reset() {
mouseclicked=false;
mousemoved=false;
+ mousedragged = false;
+
+ mouse_inactivity = 0.0;
if(root!=0) delete root;
root = new RDirNode(0, "/");
@@ -1299,6 +1338,16 @@ void Gource::logic(float t, float dt) {
slider.logic(dt);
+ //check if mouse has been inactive for 3 seconds
+ //and if so hide it.
+ if(!mouseclicked && mouse_inactivity<3.0) {
+ mouse_inactivity += dt;
+
+ if(mouse_inactivity>=3.0) {
+ SDL_ShowCursor(false);
+ }
+ }
+
//still want to update camera while paused
if(paused) {
updateCamera(dt);
View
4 src/gource.h
@@ -77,6 +77,10 @@ class Gource : public SDLApp {
bool mousemoved;
bool mouseclicked;
+ bool mousedragged;
+
+ float mouse_inactivity;
+
vec2f mousepos;
vec2f backgroundPos;

0 comments on commit daabce3

Please sign in to comment.
Something went wrong with that request. Please try again.