* Automatically updates the slider * when the mouse moves. * @param action Pointer to an action. * @param state State that the action handlers belong to. */
| 171 | * @param state State that the action handlers belong to. |
| 172 | */ |
| 173 | void Slider::handle(Action *action, State *state) |
| 174 | { |
| 175 | InteractiveSurface::handle(action, state); |
| 176 | //_button->handle(action, state); |
| 177 | if (_pressed && (action->getDetails()->type == SDL_MOUSEMOTION || action->getDetails()->type == SDL_MOUSEBUTTONDOWN)) |
| 178 | { |
| 179 | int cursorX = action->getAbsoluteXMouse(); |
| 180 | double buttonX = std::min(std::max(_minX, cursorX + _offsetX), _maxX); |
| 181 | double pos = (buttonX - _minX) / (_maxX - _minX); |
| 182 | int value = _min + (int)Round((_max - _min) * pos); |
| 183 | setValue(value); |
| 184 | if (_change) |
| 185 | { |
| 186 | (state->*_change)(action); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Moves the slider to the new position. |
nothing calls this directly
no test coverage detected