bool Input::RBUTTONPressed() { //Check the mouse right button is pressed or not if (BUTTONDOWN(m_MouseState, 1)) { ButtonWasDown[1] = true; return false; } if (!BUTTONDOWN(m_MouseState,1) && ButtonWasDown[1]) { ButtonWasDown[1] = false; return true; } return false; }
bool Input::LBUTTONPressed() { //Check the mouse left button is pressed or not if (BUTTONDOWN(m_MouseState, 0)) { ButtonWasDown[0] = true; return false; } if (!BUTTONDOWN(m_MouseState,0) && ButtonWasDown[0]) { ButtonWasDown[0] = false; return true; } return false; }
void KeyboardDemo::Update( float dt ) { keyboardDevice_->GetDeviceState( sizeof( keyboardKeys_ ), ( LPVOID )&keyboardKeys_ ); mouseDevice_->GetDeviceState( sizeof ( mouseState_ ), ( LPVOID ) &mouseState_ ); if( GetAsyncKeyState( VK_ESCAPE ) ) { PostQuitMessage( 0 ); } if( KEYDOWN( prevKeyboardKeys_, DIK_DOWN ) && !KEYDOWN( keyboardKeys_, DIK_DOWN ) ) { selectedColor_--; } if( KEYDOWN( prevKeyboardKeys_, DIK_UP ) && !KEYDOWN( keyboardKeys_, DIK_UP ) ) { selectedColor_++; } if( BUTTONDOWN( mouseState_, 0 ) && !BUTTONDOWN( prevMouseState_, 0 ) ) { selectedColor_++; } if( BUTTONDOWN( mouseState_, 1 ) && !BUTTONDOWN( prevMouseState_, 1 ) ) { selectedColor_--; } mousePosX_ += mouseState_.lX; mousePosY_ += mouseState_.lY; mouseWheel_ += mouseState_.lZ; memcpy( prevKeyboardKeys_, keyboardKeys_, sizeof( keyboardKeys_ ) ); memcpy( &prevMouseState_, &mouseState_, sizeof( mouseState_ ) ); if( selectedColor_ < 0 ) selectedColor_ = 2; if( selectedColor_ > 2 ) selectedColor_ = 0; }
bool FNX_GUIBaseElement::Update(FNX_Input* Input) { if(!Active)return false; ///focus for(int i=0;i<(int)Elements.size();++i)Elements[i]->SetFocus(false); SetFocus(false); if(!None) { if(Choosen!=NULL)Choosen->SetFocus(true); else SetFocus(true); }; ///focus if(!Input->LastFramePressed && BUTTONDOWN(Input->MouseState,0)) { None=true;//none is choosen for(int i=0;i<(int)Elements.size();++i) { if(Elements[i]->Update(Input)){None=false;Choosen=Elements[i];return true;}//if interaction with this element then stop updating; }; bool r=Update_This(Input); if(r){Choosen=NULL;None=false;};//self return r; }; if(Input->LastFramePressed && !None) { if(Choosen!=NULL) return Choosen->Update(Input); else return Update_This(Input); }; if(!None) { if(Choosen!=NULL) return Choosen->Update(Input); else return Update_This(Input,false);//keyboard update of selected item }; return false; };
bool FNX_GUIComboBox::Update_This(FNX_Input *Input, bool ByMouse) { if(ByMouse) { if(!Input->LastFramePressed) { if(Button->TouchesPoint(Input->MousePos)) { temp=true; return true; }; }; if(Input->LastFramePressed) { if(!BUTTONDOWN(Input->MouseState,0)) { if(Button->TouchesPoint(Input->MousePos)) { temp=false; DropedDown=!DropedDown; EventOccured(FNX_GUIEvent_OnClick); return true; }; temp=false; }; }; return false; }; return false; };
void SplashScreen::Update( float dt, DIMOUSESTATE mouseState, long mousePosX, long mousePosY, long mouseWheel ) { // update the mouse position mouseCursor_->GetSprite( )->SetPosition( XMFLOAT2( ( float ) mousePosX, ( float ) mousePosY ) ); switch( screenState_ ) { case START: if( mousePosX > play_.x && mousePosX < play_.y && mousePosY > play_.z && mousePosY < play_.w ) { sprite_.SetCurrentAnimation( "menu_play" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { // if button clicks... game_->PlaySound( "thud" ); game_->SetGameState(GAME); } } else if( mousePosX > instructions_.x && mousePosX < instructions_.y && mousePosY > instructions_.z && mousePosY < instructions_.w ) { sprite_.SetCurrentAnimation( "menu_instructions" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { // if button clicks... game_->PlaySound( "thud" ); sprite_.SetCurrentAnimation( "instructions" ); screenState_ = INSTRUCTIONS; } } else if( mousePosX > credits_.x && mousePosX < credits_.y && mousePosY > credits_.z && mousePosY < credits_.w ) { sprite_.SetCurrentAnimation( "menu_credits" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { // if button clicks... game_->PlaySound( "thud" ); sprite_.SetCurrentAnimation( "credits" ); screenState_ = CREDITS; } } else if( mousePosX > exit_.x && mousePosX < exit_.y && mousePosY > exit_.z && mousePosY < exit_.w ) { sprite_.SetCurrentAnimation( "menu_exit" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { game_->PlaySound( "thud" ); // if button clicks... PostQuitMessage(0); } } else { sprite_.SetCurrentAnimation( "menu" ); } break; case INSTRUCTIONS: if( mousePosX > back_.x && mousePosX < back_.y && mousePosY > back_.z && mousePosY < back_.w ) { sprite_.SetCurrentAnimation( "instructions_back" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { // if button clicks... game_->PlaySound( "thud" ); sprite_.SetCurrentAnimation( "menu" ); screenState_ = START; } } else { sprite_.SetCurrentAnimation( "instructions" ); } break; case CREDITS: if( mousePosX > back_.x && mousePosX < back_.y && mousePosY > back_.z && mousePosY < back_.w ) { sprite_.SetCurrentAnimation( "credits_back" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { // if button clicks... game_->PlaySound( "thud" ); sprite_.SetCurrentAnimation( "menu" ); screenState_ = START; } } else { sprite_.SetCurrentAnimation( "credits" ); } break; case END: if( mousePosX > replay_.x && mousePosX < replay_.y && mousePosY > replay_.z && mousePosY < replay_.w ) { sprite_.SetCurrentAnimation( "game_over_replay" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { // if button clicks... game_->PlaySound( "thud" ); HINSTANCE h = game_->GetInstance(); HWND hw = game_->GetWindow(); GameTimer* gt = game_->GetTimer(); game_->Reset( ); game_->SetGameState(GAME); } } else if( mousePosX > menu_.x && mousePosX < menu_.y && mousePosY > menu_.z && mousePosY < menu_.w ) { sprite_.SetCurrentAnimation( "game_over_menu" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { // if button clicks... game_->PlaySound( "thud" ); HINSTANCE h = game_->GetInstance(); HWND hw = game_->GetWindow(); GameTimer* gt = game_->GetTimer(); game_->Reset( ); game_->SetGameState(MENU); } } else { sprite_.SetCurrentAnimation( "game_over" ); } break; case VICTORY: //back button if( mousePosX > back_.x && mousePosX < back_.y && mousePosY > back_.z && mousePosY < back_.w ) { sprite_.SetCurrentAnimation( "victory_back" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { // if button clicks... game_->PlaySound( "thud" ); HINSTANCE h = game_->GetInstance(); HWND hw = game_->GetWindow(); GameTimer* gt = game_->GetTimer(); game_->Reset( ); game_->SetGameState(MENU); } } else if( mousePosX > replay_.x && mousePosX < replay_.y && mousePosY > replay_.z && mousePosY < replay_.w ) { sprite_.SetCurrentAnimation( "victory_replay" ); // get intput and update accordingly if( BUTTONDOWN( mouseState, 0 ) ) { // if button clicks... game_->PlaySound( "thud" ); HINSTANCE h = game_->GetInstance(); HWND hw = game_->GetWindow(); GameTimer* gt = game_->GetTimer(); game_->Reset( ); game_->SetGameState(GAME); } } else { sprite_.SetCurrentAnimation( "victory" ); } break; default: break; } game_->SetMousePosX( mousePosX + mouseState.lX ); game_->SetMousePosY( mousePosY - mouseState.lY ); game_->SetMouseWheel( mouseWheel + mouseState.lZ ); }
bool DInput::MouseHeld( int button ) { return ( BUTTONDOWN( prev_mouse_state_, button ) && BUTTONDOWN( mouse_state_, button ) ); }
bool FNX_GUIListBox::Update_This(FNX_Input* Input,bool ByMouse) { int LineCount=(int)Scale.y/Font->GetHeight();//max lines if(ByMouse) { int sub=(int)((BackGround->GetPosition().y+Scale.y/2+Font->GetHeight()/2)-Input->MousePos.y); int s=sub/Font->GetHeight(); // if(s==0)s=1; s-=1; if(BackGround->TouchesPoint(Input->MousePos)) { if(Input->LastFramePressed && !BUTTONDOWN(Input->MouseState,0)) { EventOccured(FNX_GUIEvent_OnClick); HaveChanged=true; }; if(s+ScrollBar->GetSPosition()>=(int)Lines.size() || s<0)return true; if(s==LineCount)return true; if(!MultiSelect || (!KEYDOWN(Input->buffer,DIK_LCONTROL) && !KEYDOWN(Input->buffer,DIK_RCONTROL))) { ChoosenList.clear(); ChoosenList.push_back(ScrollBar->GetSPosition()+s); EventOccured(FNX_GUIEvent_OnChange); return true; }else if(!Input->LastFramePressed) { bool t=false; for(int i=0;i<(int)ChoosenList.size();++i) { if(ChoosenList[i]==s+ScrollBar->GetSPosition()) { t=true; ChoosenList.erase(ChoosenList.begin()+i); break; }; }; if(s+ScrollBar->GetSPosition()<(int)Lines.size())if(!t)ChoosenList.push_back(ScrollBar->GetSPosition()+s); EventOccured(FNX_GUIEvent_OnChange); return true; }; return true; }; if(Input->LastFramePressed && BUTTONDOWN(Input->MouseState,0)) { if(Input->MousePos.y>BackGround->GetPosition().y-BackGround->GetScale().y/2){ScrollBar->SetSPosition(ScrollBar->GetSPosition()-1);s=ScrollBar->GetSPosition();}; if(Input->MousePos.y<BackGround->GetPosition().y+BackGround->GetScale().y/2){ScrollBar->SetSPosition(ScrollBar->GetSPosition()+1);s=ScrollBar->GetSPosition()+(int)Scale.y/Font->GetHeight();}; if(Input->MousePos.y<BackGround->GetPosition().y-BackGround->GetScale().y/2) if(Input->MousePos.y>BackGround->GetPosition().y+BackGround->GetScale().y/2)s=-100; if(!MultiSelect || (MultiSelect && (!KEYDOWN(Input->buffer,DIK_LCONTROL) && !KEYDOWN(Input->buffer,DIK_RCONTROL)))) { if(s!=-100)ChoosenList.clear(); if(s>=(int)Lines.size())s=(int)Lines.size()-1; if(s>=ScrollBar->GetSPosition()+LineCount)s=ScrollBar->GetSPosition()+LineCount-1; if(s!=-100)ChoosenList.push_back(s); }; return true; }; return false; }; if(KEYDOWN(Input->buffer,DIK_UPARROW)) { if(ChoosenList.size()<=0)return true; int s=ChoosenList[0]; ChoosenList.clear(); ChoosenList.push_back(s); if(ChoosenList[0]>ScrollBar->GetSPosition())ChoosenList[0]--; else { ScrollBar->SetSPosition(ScrollBar->GetSPosition()-1); if(ChoosenList[0]>ScrollBar->GetSPosition())ChoosenList[0]--; if(ChoosenList[0]>(int)Lines.size())ChoosenList[0]=(int)Lines.size(); if(ChoosenList[0]<0)ChoosenList[0]=0; }; return true; }; if(KEYDOWN(Input->buffer,DIK_DOWNARROW)) { if(ChoosenList.size()<=0)return true; int s=ChoosenList[0]; ChoosenList.clear(); ChoosenList.push_back(s); ChoosenList[0]++; if(ChoosenList[0]>ScrollBar->GetSPosition()+LineCount-1) { ScrollBar->SetSPosition(ScrollBar->GetSPosition()+ChoosenList[0]-(ScrollBar->GetSPosition()+LineCount)+1); }; if(ChoosenList[0]>=(int)Lines.size())ChoosenList[0]=(int)Lines.size()-1; /* if(ChoosenList[0]<ScrollBar->GetSPosition()+LineCount)ChoosenList[0]++; if(ChoosenList[0]>ScrollBar->GetSPosition()+LineCount) { ScrollBar->SetSPosition(ScrollBar->GetSPosition()+1); ChoosenList[0]=ScrollBar->GetSPosition()+LineCount-1; }; if(ChoosenList[0]>=(int)Lines.size())ChoosenList[0]=(int)Lines.size()-1; if(ChoosenList[0]<0)ChoosenList[0]=0; */ return true; }; return false; };