Jump to content
  • Advertisement
Sign in to follow this  
RomanH

Problem with SDL_BUTTON_LEFT (solved)

This topic is 4417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody I'm currently working on a game that uses mouse- as well as keyboard input. Everything works as it should except taking input from the mouse... I have two problems to be precise: 1. when I press any key on the keyboard and do not move the mouse the program detects the following as true -> sdlEvent.button.button == SDL_BUTTON_LEFT 2. When I move the mouse outside of the window the same thing is considered to be true again (sdlEvent.button.button == SDL_BUTTON_LEFT) Do you have any idea/hints what could be wrong with my program? thanks a lot! RomanH P.S. My program has become pretty big (too big to post here) but if you think you need the entire source code to find the problem I can of course email it to you. [Edited by - RomanH on September 19, 2006 1:47:30 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by RomanH
I have two problems to be precise:
1. when I press any key on the keyboard and do not move the mouse the program detects the following as true -> sdlEvent.button.button == SDL_BUTTON_LEFT
2. When I move the mouse outside of the window the same thing is considered to be true again (sdlEvent.button.button == SDL_BUTTON_LEFT)


Hmm so are you saying that (1) when a keyboard event is generated a mousebutton event is also created? (2) when focus is lost a mousebutton event is generated aswell?

Share this post


Link to post
Share on other sites
You can find out if the mouse is in the window with SDL_GetAppState().
if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) std::cout << "The mouse is in the window";

Here are the defines:

#define SDL_APPMOUSEFOCUS 0x01 /* The app has mouse coverage */
#define SDL_APPINPUTFOCUS 0x02 /* The app has input focus */
#define SDL_APPACTIVE 0x04 /* The application is active */


SDL_APPMOUSEFOCUS means the mouse is in the window
SDL_APPINPUTFOCUS means that the window is selected so you can type in it
I'm not sure what APPACTIVE is, I would think it would mean that the APP is visible on the screen, like not minimized.

Alternatively you can use SDL_GetMouseState, which returns the mouse buttons state. You can then use the SDL_BUTTON macro to determine if a mouse buttons are being pressed. I don't believe SDL_GetMouseState function returns anything if the mouse is not in the window.

if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) std::cout << "Left mouse button pressed";

Share this post


Link to post
Share on other sites
Hi

> (1) when a keyboard event is generated
> a mousebutton event is also created?
> (2) when focus is lost a mousebutton
> event is generated aswell?

yes, that's 100% what I meant.

I'll try to post everything that is relevant. My game has a guy with different tabs. Depending on the tab you are inm, different things happen. Therefore there is a "top-level loop" that is the same for all tabs:


void GameGUI()
{
QuitGame = false;
while(QuitGame == false)
{
getInput();
if(Key_ESCAPE_pressed == true){QuitGame = true;}
drawGameGUI(TabMode);
MouseDetectionAllModes();

if(TabMode == 0){draw_GUI_Tab0();}
if(TabMode == 1){draw_GUI_Tab1();}

if(TabMode != 0){draw_Cursor(0);}

//PrintMultiline(15,15,0, "Roman ist der groesste! Ausserdem kann er unglaublich lange Woerter schreiben.");

Print(580,470,1,"FPS ");
int TempFPS = (int) (SDL_GetTicks()-FPS_Counter);
if(TempFPS < 1){TempFPS = 1;}
PrintInt(607,470,1, (int) (1000/TempFPS));
SDL_UpdateRect(DisplaySurface,0,0,0,0);
FPS_Counter = SDL_GetTicks();
}
}



here's the getInput()-function:


void getInput()
{
//void SDL_PumpEvents(void);
//SDL_PollEvent(&event)
if(SDL_PollEvent(&sdlEvent)==0)
{
keys = SDL_GetKeyState(NULL);

Key_ESCAPE = false;
Key_ENTER = false;
Key_UP = false;
Key_DOWN = false;
Key_LEFT = false;
Key_RIGHT = false;
Button_0 = false;
Button_1 = false;
Button_2 = false;
Button_3 = false;
Key_1 = false;
Key_2 = false;
Key_3 = false;
Key_4 = false;
Key_5 = false;
Key_6 = false;
Key_7 = false;
Key_8 = false;
Key_9 = false;
Key_0 = false;
Key_F11 = false;
Key_F12 = false;

if (keys[SDLK_ESCAPE] == true) {Key_ESCAPE = true;}
if (keys[SDLK_RETURN] == true) {Key_ENTER = true;}
if (keys[SDLK_LEFT] == true) {Key_LEFT = true;}
if (keys[SDLK_RIGHT] == true) {Key_RIGHT = true;}
if (keys[SDLK_DOWN] == true) {Key_DOWN = true;}
if (keys[SDLK_UP] == true) {Key_UP = true;}
if (keys[SDLK_RSHIFT] == true) {Button_1 = true;}
if (keys[SDLK_RCTRL] == true) {Button_2 = true;}
if (keys[SDLK_1] == true) {Key_1 = true;}
if (keys[SDLK_2] == true) {Key_2 = true;}
if (keys[SDLK_3] == true) {Key_3 = true;}
if (keys[SDLK_4] == true) {Key_4 = true;}
if (keys[SDLK_5] == true) {Key_5 = true;}
if (keys[SDLK_6] == true) {Key_6 = true;}
if (keys[SDLK_7] == true) {Key_7 = true;}
if (keys[SDLK_8] == true) {Key_8 = true;}
if (keys[SDLK_9] == true) {Key_9 = true;}
if (keys[SDLK_0] == true) {Key_0 = true;}
if (keys[SDLK_F11] == true) {Key_F11 = true;}
if (keys[SDLK_F12] == true) {Key_F12 = true;}


if (Key_ENTER == false) {Key_ENTER_pressed_value = 0; Key_ESCAPE_pressed = false;} else
{if (Key_ENTER_pressed_value == 2){Key_ENTER_pressed_value = 1; Key_ENTER_pressed = false;}
if (Key_ENTER_pressed_value == 0){Key_ENTER_pressed_value = 2; Key_ENTER_pressed = true;}}
if (Key_ESCAPE == false){Key_ESCAPE_pressed_value = 0; Key_ESCAPE_pressed = false;} else
{if (Key_ESCAPE_pressed_value == 2){Key_ESCAPE_pressed_value = 1; Key_ESCAPE_pressed = false;}
if (Key_ESCAPE_pressed_value == 0){Key_ESCAPE_pressed_value = 2; Key_ESCAPE_pressed = true;}}
if (Key_UP == false) {Key_UP_pressed_value = 0; Key_UP_pressed = false;} else
{if (Key_UP_pressed_value == 2){Key_UP_pressed_value = 1; Key_UP_pressed = false;}
if (Key_UP_pressed_value == 0){Key_UP_pressed_value = 2; Key_UP_pressed = true;}}
if (Key_LEFT == false) {Key_LEFT_pressed_value = 0; Key_LEFT_pressed = false;} else
{if (Key_LEFT_pressed_value == 2){Key_LEFT_pressed_value = 1; Key_LEFT_pressed = false;}
if (Key_LEFT_pressed_value == 0){Key_LEFT_pressed_value = 2; Key_LEFT_pressed = true;}}
if (Key_DOWN == false) {Key_DOWN_pressed_value = 0; Key_DOWN_pressed = false;} else
{if (Key_DOWN_pressed_value == 2){Key_DOWN_pressed_value = 1; Key_DOWN_pressed = false;}
if (Key_DOWN_pressed_value == 0){Key_DOWN_pressed_value = 2; Key_DOWN_pressed = true;}}
if (Key_RIGHT == false) {Key_RIGHT_pressed_value = 0; Key_RIGHT_pressed = false;} else
{if (Key_RIGHT_pressed_value == 2){Key_RIGHT_pressed_value = 1; Key_RIGHT_pressed = false;}
if (Key_RIGHT_pressed_value == 0){Key_RIGHT_pressed_value = 2; Key_RIGHT_pressed = true;}}

if (Key_1 == false) {Key_1_pressed_value = 0; Key_1_pressed = false;} else
{if (Key_1_pressed_value == 2){Key_1_pressed_value = 1; Key_1_pressed = false;}
if (Key_1_pressed_value == 0){Key_1_pressed_value = 2; Key_1_pressed = true;}}
if (Key_2 == false) {Key_2_pressed_value = 0; Key_2_pressed = false;} else
{if (Key_2_pressed_value == 2){Key_2_pressed_value = 1; Key_2_pressed = false;}
if (Key_2_pressed_value == 0){Key_2_pressed_value = 2; Key_2_pressed = true;}}
if (Key_3 == false) {Key_3_pressed_value = 0; Key_3_pressed = false;} else
{if (Key_3_pressed_value == 2){Key_3_pressed_value = 1; Key_3_pressed = false;}
if (Key_3_pressed_value == 0){Key_3_pressed_value = 2; Key_3_pressed = true;}}
if (Key_4 == false) {Key_4_pressed_value = 0; Key_4_pressed = false;} else
{if (Key_4_pressed_value == 2){Key_4_pressed_value = 1; Key_4_pressed = false;}
if (Key_4_pressed_value == 0){Key_4_pressed_value = 2; Key_4_pressed = true;}}
if (Key_5 == false) {Key_5_pressed_value = 0; Key_5_pressed = false;} else
{if (Key_5_pressed_value == 2){Key_5_pressed_value = 1; Key_5_pressed = false;}
if (Key_5_pressed_value == 0){Key_5_pressed_value = 2; Key_5_pressed = true;}}
if (Key_6 == false) {Key_6_pressed_value = 0; Key_6_pressed = false;} else
{if (Key_6_pressed_value == 2){Key_6_pressed_value = 1; Key_6_pressed = false;}
if (Key_6_pressed_value == 0){Key_6_pressed_value = 2; Key_6_pressed = true;}}
if (Key_7 == false) {Key_7_pressed_value = 0; Key_7_pressed = false;} else
{if (Key_7_pressed_value == 2){Key_7_pressed_value = 1; Key_7_pressed = false;}
if (Key_7_pressed_value == 0){Key_7_pressed_value = 2; Key_7_pressed = true;}}
if (Key_8 == false) {Key_8_pressed_value = 0; Key_8_pressed = false;} else
{if (Key_8_pressed_value == 2){Key_8_pressed_value = 1; Key_8_pressed = false;}
if (Key_8_pressed_value == 0){Key_8_pressed_value = 2; Key_8_pressed = true;}}
if (Key_9 == false) {Key_9_pressed_value = 0; Key_9_pressed = false;} else
{if (Key_9_pressed_value == 2){Key_9_pressed_value = 1; Key_9_pressed = false;}
if (Key_9_pressed_value == 0){Key_9_pressed_value = 2; Key_9_pressed = true;}}
if (Key_0 == false) {Key_0_pressed_value = 0; Key_0_pressed = false;} else
{if (Key_0_pressed_value == 2){Key_0_pressed_value = 1; Key_0_pressed = false;}
if (Key_0_pressed_value == 0){Key_0_pressed_value = 2; Key_0_pressed = true;}}
if (Key_F11 == false) {Key_F11_pressed_value = 0; Key_F11_pressed = false;} else
{if (Key_F11_pressed_value == 2){Key_F11_pressed_value = 1; Key_F11_pressed = false;}
if (Key_F11_pressed_value == 0){Key_F11_pressed_value = 2; Key_F11_pressed = true;}}
if (Key_F12 == false) {Key_F12_pressed_value = 0; Key_F12_pressed = false;} else
{if (Key_F12_pressed_value == 2){Key_F12_pressed_value = 1; Key_F12_pressed = false;}
if (Key_F12_pressed_value == 0){Key_F12_pressed_value = 2; Key_F12_pressed = true;}}
if (Button_2 == false) {Button_2_pressed_value = 0; Button_2_pressed = false;} else
{if (Button_2_pressed_value == 2){Button_2_pressed_value = 1; Button_2_pressed = false;}
if (Button_2_pressed_value == 0){Button_2_pressed_value = 2; Button_2_pressed = true;}}
}
SDL_GetMouseState(&MouseX, &MouseY);
}



here's the draw_GUI_Tab0()-function:
(as you can see, the game can be in different "states". You can be outdoors, inside houses, looking at a map, looking at a different map which allows you to beam around, etc.)


void draw_GUI_Tab0()
{
cursorNumber = 9;
MapUsable = false;
draw_MapButton();
draw_inventory();
draw_DirectionArrows();

//if(Key_F12_pressed){GameState=7;} // CHEAT!!!
if(Key_F11_pressed)
{
if(GameState == 1)
{
GameState = 11;
SpeechBubbleX = 50;
SpeechBubbleY = 190;
SpeechBubbleText = "Hallo";
}
if(GameState == 9)
{
GameState = 12;
SpeechBubbleX = 50;
SpeechBubbleY = 190;
SpeechBubbleText = "Hallo";
}
}
if(Key_F12_pressed){create_world();}//{switch_to_room_counter = 0; GameState=8;}

// draw slider...
SDL_BlitSurface(GUISurface,&InventorySliderSrcRect,DisplaySurface,&InventorySliderDstRect);

if(GameState == 1)
{
MapUsable = true;
set_camera();
draw_layer0(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // the ground
draw_layer1(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // cliffs and stuff
draw_layer2(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // objects and stuff
draw_player(Player.currentTileX, Player.currentTileY);
}

if(GameState == 2)
{
MapUsable = true;
draw_Map();
}

if(GameState == 3){moveAreaUP();}
if(GameState == 4){moveAreaRIGHT();}
if(GameState == 5){moveAreaDOWN();}
if(GameState == 6){moveAreaLEFT();}

if(GameState == 7)
{
draw_Map_Beaming();
}

if(GameState == 8)
{
set_camera();
draw_layer0(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // the ground
draw_layer1(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // cliffs and stuff
draw_layer2(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // objects and stuff
draw_player(Player.currentTileX, Player.currentTileY);
switch_to_room();
}

if(GameState == 9)
{
draw_room_layer0(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // the ground
draw_room_layer1(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // cliffs and stuff
draw_room_layer2(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // objects and stuff
draw_room_player(CurrentTileRoomX, CurrentTileRoomY);
}

if(GameState == 11) // speech bubble mode in normal mode
{
set_camera();
draw_layer0(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // the ground
draw_layer1(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // cliffs and stuff
draw_layer2(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // objects and stuff
draw_player(Player.currentTileX, Player.currentTileY);
print_speechbubble(SpeechBubbleX, SpeechBubbleY, 1, SpeechBubbleText);
}

if(GameState == 12) // speech bubble mode in normal mode
{
draw_room_layer0(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // the ground
draw_room_layer1(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // cliffs and stuff
draw_room_layer2(XPosArea, YPosArea, world.currentAreaX, world.currentAreaY); // objects and stuff
draw_room_player(CurrentTileRoomX, CurrentTileRoomY);
print_speechbubble(SpeechBubbleX, SpeechBubbleY, 1, SpeechBubbleText);
}

MouseDetectionTab0();
draw_Cursor(cursorNumber);
}



and here's the source to the MouseDetectionTab0()-function:
(the problem occurs somwhere after the line with the comment "// left mouse button is pressed". At least that's what I'm guessing...)


void MouseDetectionTab0()
{
int i;

// find the position of the mouse on the playing field
MouseTileX = (int) (((MouseX+32)/32)-1);
if(MouseTileX < 1 || MouseTileX > 12){MouseTileX = -1;}
MouseTileY = (int) (((MouseY)/32)-1);
if(MouseTileY < 1 || MouseTileY > 12){MouseTileY = -1;}
RelativeMouseTileX = (XPosArea+MouseTileX)-1;
RelativeMouseTileY = (YPosArea+MouseTileY)-1;


// check where the cursor is in relation to the player
if(MouseY > 48 && MouseX > 16 && MouseX < 432 && MouseY < 464 && (GameState == 1 || GameState == 9))
{
if(MouseY < Player.DstRect.y &&
MouseX < Player.DstRect.x){cursorNumber = 1;}

if(MouseY < Player.DstRect.y &&
MouseX >= Player.DstRect.x &&
MouseX <= Player.DstRect.x + 32){Player.direction = 0; cursorNumber = 2;}

if(MouseY < Player.DstRect.y &&
MouseX > Player.DstRect.x + 32){cursorNumber = 3;}

if(MouseX > Player.DstRect.x + 32 &&
MouseY >= Player.DstRect.y &&
MouseY <= Player.DstRect.y + 32){Player.direction = 1; cursorNumber = 4;}

if(MouseY > Player.DstRect.y + 32 &&
MouseX > Player.DstRect.x + 32){cursorNumber = 5;}

if(MouseY > Player.DstRect.y + 32 &&
MouseX >= Player.DstRect.x &&
MouseX <= Player.DstRect.x + 32){Player.direction = 2; cursorNumber = 6;}

if(MouseY > Player.DstRect.y + 32 &&
MouseX < Player.DstRect.x){cursorNumber = 7;}

if(MouseX < Player.DstRect.x &&
MouseY >= Player.DstRect.y &&
MouseY <= Player.DstRect.y + 32){Player.direction = 3; cursorNumber = 8;}

// cursor on an object next to player
if(MouseTileX > 0 && MouseTileY > 0)
{
if((Player.currentTileY == RelativeMouseTileY-1 && Player.currentTileX == RelativeMouseTileX) ||
(Player.currentTileY == RelativeMouseTileY+1 && Player.currentTileX == RelativeMouseTileX) ||
(Player.currentTileY == RelativeMouseTileY && Player.currentTileX == RelativeMouseTileX-1) ||
(Player.currentTileY == RelativeMouseTileY && Player.currentTileX == RelativeMouseTileX+1))
{
if(world.area[world.currentAreaX][world.currentAreaY].Layer2Array[RelativeMouseTileY][RelativeMouseTileX].type != 0)
{
cursorNumber = 9;
}
}
}
}






// left mouse button is pressed
if(sdlEvent.button.button == SDL_BUTTON_LEFT)
{
// allow mouse to influence slider directly
// might implement scoll wheel...
// http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fMouseButtonEvent
if(MouseY >= 91 &&
MouseY <= 292 &&
inventory_slider_activated == true)
{
inventory_position = (int)((MouseY-92)/(184/MAX_INV_ENTRIES));
if(inventory_position < 0){inventory_position=0;}
if(inventory_position > MAX_INV_ENTRIES){inventory_position=MAX_INV_ENTRIES;}
}
// moving the player
if((GameState == 1 || GameState == 9) && inventory_object_chosen == 0){movePlayerMultipleSteps();}
}





// left mouse button is released
// for some reason this requires one mouse click before is works
// (no real problem but strange)
if(sdlEvent.type == SDL_MOUSEBUTTONUP &&
sdlEvent.button.button == SDL_BUTTON_LEFT)
{
MouseReleased = true;
movement_counter_activated = false;
inventory_slider_activated = false;
PlayerMovementBlocked = false;
}

// inventory arrows...
if(MouseX >= ArrowScrollUPDstRect.x &&
MouseX <= ArrowScrollUPDstRect.x + ArrowScrollUPDstRect.w)
{
if(MouseY >= ArrowScrollUPDstRect.y &&
MouseY <= ArrowScrollUPDstRect.y + ArrowScrollUPDstRect.h &&
inventory_position>0) // arrow up
{
SDL_BlitSurface(GUISurface,&ArrowSrcRect[0][2],DisplaySurface,&ArrowScrollUPDstRect);
}
if(MouseY >= ArrowScrollDOWNDstRect.y &&
MouseY <= ArrowScrollDOWNDstRect.y + ArrowScrollDOWNDstRect.h &&
inventory_position<MAX_INV_ENTRIES) // arrow down
{
SDL_BlitSurface(GUISurface,&ArrowSrcRect[2][2],DisplaySurface,&ArrowScrollDOWNDstRect);
}
}


// right mouse button down...
if(sdlEvent.type == SDL_MOUSEBUTTONDOWN &&
sdlEvent.button.button == SDL_BUTTON_RIGHT)
{
inventory_object_chosen = 0;
if(GameState == 2){GameState = 1;} // quit map mode
if(GameState == 7){GameState = 1;} // quit beam mode
}


// stuff that is to be clicked on once
// clicking on things...
if(sdlEvent.type == SDL_MOUSEBUTTONDOWN &&
sdlEvent.button.button == SDL_BUTTON_LEFT &&
MouseReleased == true)
{
MouseReleased = false;

// moving the player
//if((GameState == 1 || GameState == 9) && inventory_object_chosen == 0){movePlayerSingleStep();}

// inventory scroll arrows
if(MouseX >= ArrowScrollUPDstRect.x &&
MouseX <= ArrowScrollUPDstRect.x + ArrowScrollUPDstRect.w &&
MouseY >= ArrowScrollUPDstRect.y &&
MouseY <= ArrowScrollUPDstRect.y + ArrowScrollUPDstRect.h)
{
if(inventory_position>0){inventory_position--;}
}
if(MouseX >= ArrowScrollDOWNDstRect.x &&
MouseX <= ArrowScrollDOWNDstRect.x + ArrowScrollDOWNDstRect.w &&
MouseY >= ArrowScrollDOWNDstRect.y &&
MouseY <= ArrowScrollDOWNDstRect.y + ArrowScrollDOWNDstRect.h)
{

if(inventory_position<MAX_INV_ENTRIES){inventory_position++;}
}

// map button
if(MouseX >= MapButtonDstRect.x &&
MouseX <= MapButtonDstRect.x + MapButtonDstRect.w &&
MouseY >= MapButtonDstRect.y &&
MouseY <= MapButtonDstRect.y + MapButtonDstRect.h &&
MapUsable == true)
{
if(GameState == 2){GameState = 1;}
else if(GameState != 2){GameState = 2;}
}

// activate inventory slider (so that it reacts to mouse movements)
if(MouseX >= InventorySliderDstRect.x &&
MouseX <= InventorySliderDstRect.x + InventorySliderDstRect.w &&
MouseY >= InventorySliderDstRect.y &&
MouseY <= InventorySliderDstRect.y + InventorySliderDstRect.h)
{
inventory_slider_activated = true;
}

// picking up objects
if(MouseTileX > 0 && MouseTileY > 0)
{
if((Player.currentTileY == RelativeMouseTileY-1 && Player.currentTileX == RelativeMouseTileX) ||
(Player.currentTileY == RelativeMouseTileY+1 && Player.currentTileX == RelativeMouseTileX) ||
(Player.currentTileY == RelativeMouseTileY && Player.currentTileX == RelativeMouseTileX-1) ||
(Player.currentTileY == RelativeMouseTileY && Player.currentTileX == RelativeMouseTileX+1))
{
if(world.area[world.currentAreaX][world.currentAreaY].Layer2Array[RelativeMouseTileY][RelativeMouseTileX].selected == false)
{
world.area[world.currentAreaX][world.currentAreaY].Layer2Array[RelativeMouseTileY][RelativeMouseTileX].selected = true;
}
else if(world.area[world.currentAreaX][world.currentAreaY].Layer2Array[RelativeMouseTileY][RelativeMouseTileX].selected == true)
{
add_to_inventory(world.area[world.currentAreaX][world.currentAreaY].Layer2Array[RelativeMouseTileY][RelativeMouseTileX].type,1);
world.area[world.currentAreaX][world.currentAreaY].Layer2Array[RelativeMouseTileY][RelativeMouseTileX].type = 0;
}
}
}

// beaming
if(!clicking_beam_map_forbidden && MouseTileX > 0 && MouseTileY > 0 && GameState == 7 && world.BeamArea[MouseTileY-1][MouseTileX-1]&& world.visitedArea[MouseTileY-1][MouseTileX-1])
{
GameState = 1;
world.currentAreaX = MouseTileX-1;
world.currentAreaY = MouseTileY-1;
//world.visitedArea[MouseTileY-1][MouseTileX-1] = true; // only needed when cheated :-)
Player.currentTileX = world.BeamTargetX[MouseTileY-1][MouseTileX-1];
Player.currentTileY = world.BeamTargetY[MouseTileY-1][MouseTileX-1];
PlayerMovementBlocked = true; // make sure the player doesn't move with this click
}


// taking something out of the inventory...
for(i = 1; i < 9; i++)
{
if(MouseX >= InventoryDstRect.x &&
MouseX <= InventoryDstRect.x + InventoryDstRect.w &&
MouseY >= InventoryDstRect.y &&
MouseY <= InventoryDstRect.y + InventoryDstRect.h &&
inventory_list[i+inventory_position] != 0)
{
inventory_object_chosen = inventory_list[i+inventory_position];
}
}

// click the speech bubble away
if(MouseX > SpeechBubbleX &&
MouseX < SpeechBubbleX + SpeechBubbleW &&
MouseY > SpeechBubbleY &&
MouseY < SpeechBubbleY + SpeechBubbleH &&
(GameState == 11 || GameState == 12))
{
if(GameState == 11){GameState = 1;}
if(GameState == 12){GameState = 9;}
PlayerMovementBlocked = true;
}

// activate a tile and switch it to another tile...
use_object();

/*
// dropping object again...
if(MouseX < InventoryDstRect[1].x ||
MouseX > InventoryDstRect[1].x + InventoryDstRect[1].w ||
MouseY < InventoryDstRect[1].y ||
MouseY > InventoryDstRect[8].y + InventoryDstRect[8].h)
{
inventory_object_chosen = 0;
}
*/

}

// using weapon
if(sdlEvent.type == SDL_MOUSEBUTTONDOWN && sdlEvent.button.button == SDL_BUTTON_RIGHT) {Player.frame = 2;}
if(sdlEvent.type == SDL_MOUSEBUTTONUP && sdlEvent.button.button == SDL_BUTTON_RIGHT) {Player.frame = 0;}

if(MouseReleased == true){clicking_beam_map_forbidden = false;}
}



I think that's all that might be somehow related to my problem.

Thanks a lot!!!

RomanH

Share this post


Link to post
Share on other sites
Quote:
Original post by ScottC
You can find out if the mouse is in the window with SDL_GetAppState().
if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) std::cout << "The mouse is in the window";


this little solves the second problem! Thanks!!!

RomanH

Share this post


Link to post
Share on other sites
Quote:
Original post by ScottC
SDL_GetMouseState should solve your first problem too.


:-) Yes, of course it does.

Thanks!

RomanH

Share this post


Link to post
Share on other sites
Firstly I do not see the sdl event queue, do you use it at all? have you disabled events which you are not catching?
In void MouseDetectionTab0() it does not take a parameter and I do not see where the sdlevent comes from that the function is using?

the following seems to be a problem, if there are no events grab input else??don't bother with it??
Quote:

void getInput()
{
//void SDL_PumpEvents(void);
//SDL_PollEvent(&event)
if(SDL_PollEvent(&sdlEvent)==0)
{
//check input method
}
SDL_GetMouseState(&MouseX, &MouseY);
}


[edit]
OK after looking at the code again I see that getInput must use a global sdlEvent and therefore the other funcs do aswell.
In MouseDetectionTab0 you check if the button is pressed without knowing if the event is a button press(from what I see).
Quote:
// left mouse button is pressed
if(sdlEvent.button.button == SDL_BUTTON_LEFT)

If you think the problem is solved then fair enough.

[Edited by - dmail on September 18, 2006 3:29:04 PM]

Share this post


Link to post
Share on other sites
Quote:
If you think the problem is solved then fair enough.


:-)

yes, it works like a charm now. But thanks for reading through my code nevertheless.

RomanH

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!