Permalink
Browse files

Mouse cursor uses system cursor again (cursor graphic removed).

Fixed keyboard, mouse input, window resizing with SDL 1.3.
  • Loading branch information...
1 parent 613157e commit 31a9f109a5ba33871fb2a12aad8bf28153ec3746 @acaudwell committed Jan 24, 2012
Showing with 101 additions and 26 deletions.
  1. +1 −1 Makefile.am
  2. BIN data/cursor.png
  3. +0 −1 dev/bin/build_win32.pl
  4. +1 −1 src/core
  5. +72 −17 src/gource.cpp
  6. +3 −0 src/gource.h
  7. +19 −4 src/gource_shell.cpp
  8. +5 −2 src/gource_shell.h
View
2 Makefile.am
@@ -57,7 +57,7 @@ gource_SOURCES = \
AM_CPPFLAGS = -DSDLAPP_RESOURCE_DIR=\"$(pkgdatadir)\"
-dist_pkgdata_DATA = data/beam.png data/bloom.tga data/bloom_alpha.tga data/cursor.png data/file.png data/user.png data/gource.style
+dist_pkgdata_DATA = data/beam.png data/bloom.tga data/bloom_alpha.tga data/file.png data/user.png data/gource.style
shadersdir = $(pkgdatadir)/shaders
dist_shaders_DATA = data/shaders/shadow.vert data/shaders/shadow.frag data/shaders/bloom.vert data/shaders/bloom.frag data/shaders/text.vert data/shaders/text.frag
View
BIN data/cursor.png
Deleted file not rendered
View
1 dev/bin/build_win32.pl
@@ -43,7 +43,6 @@ sub dosify {
doit("cp gource.exe $WINBUILD");
doit("cp data/beam.png $WINBUILD/data/");
-doit("cp data/cursor.png $WINBUILD/data/");
doit("cp data/file.png $WINBUILD/data/");
doit("cp data/user.png $WINBUILD/data/");
doit("cp data/bloom.tga $WINBUILD/data/");
2 src/core
@@ -1 +1 @@
-Subproject commit 8ea748d589e1b6e935b104a505fafec3692d617a
+Subproject commit 4579294425246e47f29617889a2c0ee18bf08413
View
89 src/gource.cpp
@@ -91,9 +91,6 @@ Gource::Gource(FrameExporter* exporter) {
mousedragged = false;
mouseclicked = false;
- cursor.setCursorTexture(texturemanager.grab("cursor.png"));
- cursor.useSystemCursor(false);
-
if(gGourceSettings.hide_mouse) {
cursor.showCursor(false);
}
@@ -452,6 +449,7 @@ void Gource::mouseMove(SDL_MouseMotionEvent *e) {
bool rightmouse = cursor.rightButtonPressed();
+#if not SDL_VERSION_ATLEAST(1,3,0)
if(grab_mouse) {
int warp_x = display.width/2;
int warp_y = display.height/2;
@@ -461,6 +459,7 @@ void Gource::mouseMove(SDL_MouseMotionEvent *e) {
SDL_WarpMouse(warp_x, warp_y);
}
+#endif
//move camera in direction the user dragged the mouse
if(mousedragged || rightmouse) {
@@ -524,6 +523,25 @@ void Gource::zoom(bool zoomin) {
camera.setDistance(distance);
}
+#if SDL_VERSION_ATLEAST(1,3,0)
+void Gource::mouseWheel(SDL_MouseWheelEvent *e) {
+
+ int mouse_x, mouse_y;
+ SDL_GetMouseState(&mouse_x, &mouse_y);
+
+ vec2 mousepos(mouse_x, mouse_y);
+
+ if(e->y > 0) {
+ zoom(true);
+ }
+
+ if(e->y < 0) {
+ zoom(false);
+ }
+}
+
+#endif
+
void Gource::mouseClick(SDL_MouseButtonEvent *e) {
if(commitlog==0) return;
if(gGourceSettings.hide_mouse) return;
@@ -541,9 +559,14 @@ void Gource::mouseClick(SDL_MouseButtonEvent *e) {
if(e->button == SDL_BUTTON_LEFT || e->button == SDL_BUTTON_RIGHT) {
if(!cursor.buttonPressed()) {
- cursor.showCursor(true);
grab_mouse=false;
- SDL_WarpMouse(mousepos.x, mousepos.y);
+#if SDL_VERSION_ATLEAST(1,3,0)
+ SDL_SetRelativeMouseMode(SDL_FALSE);
+ SDL_WarpMouseInWindow(display.sdl_window, mousepos.x, mousepos.y);
+#else
+ SDL_WarpMouse(mousepos.x, mousepos.y);
+#endif
+ cursor.showCursor(true);
}
}
}
@@ -571,6 +594,7 @@ void Gource::mouseClick(SDL_MouseButtonEvent *e) {
if(e->button == SDL_BUTTON_RIGHT) {
cursor.showCursor(false);
grab_mouse=true;
+ SDL_SetRelativeMouseMode(SDL_TRUE);
return;
}
@@ -746,7 +770,38 @@ void Gource::keyPress(SDL_KeyboardEvent *e) {
if (e->type == SDL_KEYUP) return;
if (e->type == SDL_KEYDOWN) {
- if (e->keysym.unicode == SDLK_ESCAPE) {
+
+#if SDL_VERSION_ATLEAST(1,3,0)
+ bool key_escape = e->keysym.scancode == SDL_SCANCODE_ESCAPE;
+ bool key_tab = e->keysym.scancode == SDL_SCANCODE_TAB;
+ bool key_space = e->keysym.scancode == SDL_SCANCODE_SPACE;
+ bool key_plus = e->keysym.scancode == SDL_SCANCODE_EQUALS;
+ bool key_equals = e->keysym.scancode == SDL_SCANCODE_EQUALS;
+ bool key_minus = e->keysym.scancode == SDL_SCANCODE_MINUS;
+ bool key_leftbracket = e->keysym.scancode == SDL_SCANCODE_LEFTBRACKET;
+ bool key_rightbracket = e->keysym.scancode == SDL_SCANCODE_RIGHTBRACKET;
+ bool key_comma = e->keysym.scancode == SDL_SCANCODE_COMMA;
+ bool key_period = e->keysym.scancode == SDL_SCANCODE_PERIOD;
+ bool key_slash = e->keysym.scancode == SDL_SCANCODE_SLASH;
+ bool keypad_plus = e->keysym.scancode == SDL_SCANCODE_KP_PLUS;
+ bool keypad_minus = e->keysym.scancode == SDL_SCANCODE_KP_MINUS;
+#else
+ bool key_escape = e->keysym.unicode == SDLK_ESCAPE;
+ bool key_tab = e->keysym.unicode == SDLK_TAB;
+ bool key_space = e->keysym.unicode == SDLK_SPACE;
+ bool key_plus = e->keysym.unicode == SDLK_PLUS;
+ bool key_equals = e->keysym.unicode == SDLK_EQUALS;
+ bool key_minus = e->keysym.unicode == SDLK_MINUS;
+ bool key_leftbracket = e->keysym.unicode == SDLK_LEFTBRACKET;
+ bool key_rightbracket = e->keysym.unicode == SDLK_RIGHTBRACKET;
+ bool key_comma = e->keysym.unicode == SDLK_COMMA;
+ bool key_period = e->keysym.unicode == SDLK_PERIOD;
+ bool key_slash = e->keysym.unicode == SDLK_SLASH;
+ bool keypad_plus = e->keysym.unicode == SDLK_KP_PLUS;
+ bool keypad_minus = e->keysym.unicode == SDLK_KP_MINUS;
+#endif
+
+ if (key_escape) {
appFinished=true;
}
@@ -873,47 +928,47 @@ void Gource::keyPress(SDL_KeyboardEvent *e) {
recolour=true;
}
- if(e->keysym.unicode == SDLK_TAB) {
+ if(key_tab) {
selectNextUser();
}
- if (e->keysym.unicode == SDLK_SPACE) {
+ if (key_space) {
paused = !paused;
}
- if (e->keysym.unicode == SDLK_EQUALS || e->keysym.unicode == SDLK_PLUS) {
+ if (key_equals || key_plus) {
if(gGourceSettings.days_per_second>=1.0) {
gGourceSettings.days_per_second = std::min(30.0f, floorf(gGourceSettings.days_per_second) + 1.0f);
} else {
gGourceSettings.days_per_second = std::min(1.0f, gGourceSettings.days_per_second * 2.0f);
}
}
- if (e->keysym.unicode == SDLK_MINUS) {
+ if (key_minus) {
if(gGourceSettings.days_per_second>1.0) {
gGourceSettings.days_per_second = std::max(0.0f, floorf(gGourceSettings.days_per_second) - 1.0f);
} else {
gGourceSettings.days_per_second = std::max(0.0f, gGourceSettings.days_per_second * 0.5f);
}
}
- if(e->keysym.sym == SDLK_KP_MINUS) {
+ if(keypad_minus) {
zoom(true);
}
- if(e->keysym.sym == SDLK_KP_PLUS) {
+ if(keypad_plus) {
zoom(false);
}
- if(e->keysym.unicode == SDLK_LEFTBRACKET) {
+ if(key_leftbracket) {
gGourceForceGravity /= 1.1;
}
- if(e->keysym.unicode == SDLK_RIGHTBRACKET) {
+ if(key_rightbracket) {
gGourceForceGravity *= 1.1;
}
- if(e->keysym.unicode == SDLK_PERIOD) {
+ if(key_period) {
if(gGourceSettings.time_scale>=1.0) {
gGourceSettings.time_scale = std::min(4.0f, floorf(gGourceSettings.time_scale) + 1.0f);
@@ -922,7 +977,7 @@ void Gource::keyPress(SDL_KeyboardEvent *e) {
}
}
- if(e->keysym.unicode == SDLK_COMMA) {
+ if(key_comma) {
if(gGourceSettings.time_scale>1.0) {
gGourceSettings.time_scale = std::max(0.0f, floorf(gGourceSettings.time_scale) - 1.0f);
@@ -931,7 +986,7 @@ void Gource::keyPress(SDL_KeyboardEvent *e) {
}
}
- if(e->keysym.unicode == SDLK_SLASH) {
+ if(key_slash) {
gGourceSettings.time_scale = 1.0f;
}
}
View
3 src/gource.h
@@ -289,6 +289,9 @@ class Gource : public SDLApp {
void keyPress(SDL_KeyboardEvent *e);
void mouseMove(SDL_MouseMotionEvent *e);
void mouseClick(SDL_MouseButtonEvent *e);
+#if SDL_VERSION_ATLEAST(1,3,0)
+ void mouseWheel(SDL_MouseWheelEvent *e);
+#endif
};
#endif
View
23 src/gource_shell.cpp
@@ -67,7 +67,7 @@ void GourceShell::toggleFullscreen() {
if(gource!=0) gource->reload();
}
-void GourceShell::resize(SDL_ResizeEvent* e) {
+void GourceShell::resize(int width, int height) {
texturemanager.unload();
shadermanager.unload();
@@ -76,7 +76,7 @@ void GourceShell::resize(SDL_ResizeEvent* e) {
if(gource!=0) gource->unload();
//recreate gl context
- display.resize(e->w, e->h);
+ display.resize(width, height);
texturemanager.reload();
shadermanager.reload();
@@ -89,11 +89,20 @@ void GourceShell::keyPress(SDL_KeyboardEvent *e) {
//Quit demo if the user presses ESC
if (e->type == SDL_KEYDOWN) {
- if (e->keysym.unicode == SDLK_ESCAPE) {
+
+#if SDL_VERSION_ATLEAST(1,3,0)
+ bool key_escape = e->keysym.scancode == SDL_SCANCODE_ESCAPE;
+ bool key_return = e->keysym.scancode == SDL_SCANCODE_RETURN;
+#else
+ bool key_escape = e->keysym.unicode == SDLK_ESCAPE;
+ bool key_return = e->keysym.unicode == SDLK_RETURN;
+#endif
+
+ if (key_escape) {
appFinished=true;
}
- if(e->keysym.unicode == SDLK_RETURN) {
+ if(key_return) {
#if SDL_VERSION_ATLEAST(1,3,0)
Uint8* keystate = SDL_GetKeyboardState(NULL);
@@ -119,6 +128,12 @@ void GourceShell::mouseMove(SDL_MouseMotionEvent *e) {
if(gource!=0) gource->mouseMove(e);
}
+#if SDL_VERSION_ATLEAST(1,3,0)
+void GourceShell::mouseWheel(SDL_MouseWheelEvent *e) {
+ if(gource!=0) gource->mouseWheel(e);
+}
+#endif
+
void GourceShell::mouseClick(SDL_MouseButtonEvent *e) {
if(gource!=0) gource->mouseClick(e);
}
View
7 src/gource_shell.h
@@ -43,13 +43,16 @@ class GourceShell : public SDLApp {
void update(float t, float dt);
- void resize(SDL_ResizeEvent* e);
+ void resize(int width, int height);
+
void toggleFullscreen();
void keyPress(SDL_KeyboardEvent *e);
void mouseMove(SDL_MouseMotionEvent *e);
void mouseClick(SDL_MouseButtonEvent *e);
-
+#if SDL_VERSION_ATLEAST(1,3,0)
+ void mouseWheel(SDL_MouseWheelEvent *e);
+#endif
};
#endif

0 comments on commit 31a9f10

Please sign in to comment.