Skip to content

Commit

Permalink
Got mouse cursor mostly working.
Browse files Browse the repository at this point in the history
Still currently draws cursor when real mouse cursor is offscreen.
  • Loading branch information
acaudwell committed Jun 8, 2010
1 parent b8db217 commit b193677
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -15,6 +15,7 @@ gource_SOURCES = \
src/core/frustum.cpp src/core/frustum.h \
src/core/fxfont.cpp src/core/fxfont.h \
src/core/logger.cpp src/core/logger.h \
src/core/mousecursor.cpp src/core/mousecursor.h \
src/core/pi.h \
src/core/plane.cpp src/core/plane.h \
src/core/ppm.cpp src/core/ppm.h \
Expand Down
51 changes: 28 additions & 23 deletions src/gource.cpp
Expand Up @@ -71,6 +71,11 @@ Gource::Gource(FrameExporter* exporter) {
mousedragged = false;
mouseclicked = false;

if(1) {
cursor.setCursorTexture(texturemanager.grab("cursor.png"));
cursor.useSystemCursor(false);
}

if(gGourceSettings.hide_mouse) {
cursor.showCursor(false);
}
Expand Down Expand Up @@ -261,6 +266,8 @@ void Gource::update(float t, float dt) {
}
}

cursor.draw(mousepos);

framecount++;
}

Expand Down Expand Up @@ -290,6 +297,16 @@ void Gource::mouseMove(SDL_MouseMotionEvent *e) {

bool rightmouse = cursor.rightButtonPressed();

if(grab_mouse) {
int warp_x = display.width/2;
int warp_y = display.height/2;

//this is an even we generated by warping the mouse below
if(e->x == warp_x && e->y == warp_y) return;

SDL_WarpMouse(warp_x, warp_y);
}

//move camera in direction the user dragged the mouse
if(mousedragged || rightmouse) {
vec2f mag( e->xrel, e->yrel );
Expand Down Expand Up @@ -355,14 +372,10 @@ void Gource::mouseClick(SDL_MouseButtonEvent *e) {
mousedragged=false;
}

Uint8 ms = SDL_GetMouseState(0,0);


if(e->button == SDL_BUTTON_LEFT || e->button == SDL_BUTTON_RIGHT) {
if(!(ms & SDL_BUTTON(SDL_BUTTON_RIGHT) || ms & SDL_BUTTON(SDL_BUTTON_LEFT))) {
//SDL_WM_GrabInput(SDL_GRAB_OFF);
if(!cursor.buttonPressed()) {
cursor.showCursor(true);
grab_mouse=false;
SDL_ShowCursor(true);
SDL_WarpMouse(mousepos.x, mousepos.y);
}
}
Expand All @@ -389,11 +402,8 @@ void Gource::mouseClick(SDL_MouseButtonEvent *e) {


if(e->button == SDL_BUTTON_RIGHT) {

cursor.showCursor(false);
grab_mouse=true;
//SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(false);

return;
}

Expand Down Expand Up @@ -455,18 +465,15 @@ void Gource::toggleCameraMode() {
void Gource::selectBackground() {
//is the left mouse button down?

Uint8 ms = SDL_GetMouseState(0,0);

if(!(ms & SDL_BUTTON(SDL_BUTTON_LEFT))) return;
if(!cursor.leftButtonPressed()) return;

selectUser(0);

backgroundSelected = true;

backgroundPos = camera.getPos().truncate();

SDL_ShowCursor(false);
// SDL_WM_GrabInput(SDL_GRAB_ON);
cursor.showCursor(false);
grab_mouse=true;
mousedragged=true;
}
Expand Down Expand Up @@ -595,15 +602,14 @@ void Gource::keyPress(SDL_KeyboardEvent *e) {

if (e->keysym.sym == SDLK_m) {

Uint8 ms = SDL_GetMouseState(0,0);

//toggle mouse visiblity unless mouse clicked/pressed/dragged
if(!(mousedragged || mouseclicked || ms & SDL_BUTTON(SDL_BUTTON_LEFT))) {
if(SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) {
SDL_ShowCursor(false);
if(!(mousedragged || mouseclicked || cursor.leftButtonPressed() )) {

if(cursor.isVisible()) {
cursor.showCursor(false);
gGourceSettings.hide_mouse = true;
} else {
SDL_ShowCursor(true);
cursor.showCursor(true);
gGourceSettings.hide_mouse = false;
}
}
Expand Down Expand Up @@ -1215,8 +1221,7 @@ void Gource::updateCamera(float dt) {

float dratio = 0.95f;

Uint8 ms = SDL_GetMouseState(0,0);
bool rightmouse = ms & SDL_BUTTON(SDL_BUTTON_RIGHT);
bool rightmouse = cursor.rightButtonPressed();

if(!rightmouse && dir_bounds.area() > 10000.0f) {

Expand Down

0 comments on commit b193677

Please sign in to comment.