void Slider::GetButtonState() { Input* input = gEngine->GetInput(); POINT cursorPos = input->GetCursorPos(); if(state == Active && input->GetLeftButton()) return; float offset = ((value - minValue)/(maxValue - minValue)) * (screenRect.right - style->sliderBarSize*(screenRect.bottom - screenRect.top) - screenRect.left); float width = style->sliderBarSize * (screenRect.bottom - screenRect.top); if(cursorPos.x > screenRect.left && cursorPos.x < screenRect.right && cursorPos.y > screenRect.top && cursorPos.y < screenRect.bottom && input->GetLeftButton()) { state = Active; return; } if(cursorPos.x > screenRect.left + offset && cursorPos.x < screenRect.left + offset + width && cursorPos.y > screenRect.top && cursorPos.y < screenRect.bottom) { state = Hover; } else state = Normal; }
void ListBox::GetState() { Input* input = gEngine->GetInput(); POINT cursorPos = input->GetCursorPos(); int height = screenRect.bottom - screenRect.top; if(cursorPos.x < (int)screenRect.left || cursorPos.x > (int)screenRect.right || cursorPos.y < (int)screenRect.top || cursorPos.y > (int)screenRect.bottom + (int)items.size() * height) { cursorState = 0; return; } cursorState = (int)(cursorPos.y - screenRect.top) / height + 1; if(cursorState == 1) { if(input->GetLeftButtonUp()) isSelecting = !isSelecting; } else { if(input->GetLeftButtonUp() && isSelecting == true) { selectedIx = cursorState - 2; isSelecting = false; } } }
void Toggle::GetButtonState() { Input* input = gEngine->GetInput(); POINT cursorPos = input->GetCursorPos(); if(cursorPos.x > screenRect.left && cursorPos.x < screenRect.right && cursorPos.y > screenRect.top && cursorPos.y < screenRect.bottom) { if(input->GetLeftButton()) state = Active; else state = Hover; } else state = Normal; }