// Handle and events void TEXTBOX::Handle(INPUT_RECORD *inpt, int i){ switch (inpt[i].EventType) { case KEY_EVENT: // keyboard input { KEY_EVENT_RECORD ker = inpt[i].Event.KeyEvent; if (ker.bKeyDown && this->focus){ switch (ker.wVirtualKeyCode){ case VK_BACK: BackSpace(); break; case VK_RIGHT: case VK_NUMPAD6: MoveRight(); break; case VK_LEFT: case VK_NUMPAD4: MoveLeft(); break; case VK_RETURN: break; case VK_DELETE: Delete(); break; default: if ((ker.wVirtualKeyCode >= 65 && ker.wVirtualKeyCode <= 90) || (ker.wVirtualKeyCode >= 97 && ker.wVirtualKeyCode <= 122) || (ker.wVirtualKeyCode >= 48 && ker.wVirtualKeyCode <= 57) || (ker.wVirtualKeyCode == 32)) PutChar(ker.wVirtualKeyCode); break; } } } break; case MOUSE_EVENT: // mouse input { MOUSE_EVENT_RECORD ker = inpt[i].Event.MouseEvent; if (ker.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED){ if (IsClicked(ker.dwMousePosition)){ SetColors(); SetFocus(&ker.dwMousePosition); } else{ SetFocus(NULL); } } } break; case WINDOW_BUFFER_SIZE_EVENT: // scrn buf. resizing break; case FOCUS_EVENT: // disregard focus events case MENU_EVENT: // disregard menu events break; default: break; } }
void HexGame::MakeMovement() { // 1 When there is a left click iterate trough the board to know the cell clicked // 2 We check if it's empty // 3 We put the red hex piece on the board if (board.CurrentPlayer() == PLAYER) { if (event.type == sf::Event::MouseButtonPressed) { if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) { sf::Vector2f mouse_click = static_cast<sf::Vector2f>(sf::Mouse::getPosition(screen)); for (auto itr = board_sfml.begin(); itr != board_sfml.end(); itr++) { if (itr->IsClicked(mouse_click).first && itr->GetState() == EMPTY) { itr->ChangeState(BLUE, texture_manager); board.InputPlayer(std::distance(board_sfml.begin(), itr)); RefreshState = true; } } } } } else if (board.CurrentPlayer() == COMPUTER) { int pos = board.InputComputer(); board_sfml[pos].ChangeState(RED, texture_manager); RefreshState = true; } }
void CCheckBox::Update() { if (IsOn == true) { IsOff = false; } else if (IsOff == true) { IsOn = false; } if (MouseOver() == true) { if (IsClicked() == true && IsOff == true) { CurrentState = BOX_IS_ON; } else if (IsClicked() == true && IsOn == true) { CurrentState = BOX_NOT_ON; } else { CurrentState = MOUSE_OVER_BOX; } } else { CurrentState = BOX_NOT_ON; } int TempWidth = 0; int TempHeight = 0; SDL_QueryTexture(m_tCheckBox,NULL,NULL,&TempWidth,&TempHeight); m_Width = TempWidth / 3; m_Height = TempHeight; CheckBoxSprite.SetSourceRect(m_Width*CurrentState,0,m_Width,m_Height); }
void ribi::DialWidget::Click(const int x,const int y) noexcept { if (!IsClicked(x,y)) return; const int midx = GetGeometry().GetX() + (GetGeometry().GetWidth() / 2); const int midy = GetGeometry().GetY() + (GetGeometry().GetHeight() / 2); const double dx = boost::numeric_cast<double>(x - midx); const double dy = boost::numeric_cast<double>(y - midy); const double angle = Dial::GetAngle(dx,dy); const double pi = boost::math::constants::pi<double>(); const double position = angle / (2.0 * pi); assert(position >= 0.0); assert(position <= 1.0); m_dial->SetPosition(position); }