* Called whenever an action occurs, and processes it to * check if it's relevant to the surface and convert it * into a meaningful interaction like a "click", calling * the respective handlers. * @param action Pointer to an action. * @param state State that the action handlers belong to. */
| 105 | * @param state State that the action handlers belong to. |
| 106 | */ |
| 107 | void InteractiveSurface::handle(Action *action, State *state) |
| 108 | { |
| 109 | if (!_visible || _hidden) |
| 110 | return; |
| 111 | |
| 112 | action->setSender(this); |
| 113 | |
| 114 | if (action->getDetails()->type == SDL_MOUSEBUTTONUP || action->getDetails()->type == SDL_MOUSEBUTTONDOWN) |
| 115 | { |
| 116 | action->setMouseAction(action->getDetails()->button.x, action->getDetails()->button.y, getX(), getY()); |
| 117 | } |
| 118 | else if (action->getDetails()->type == SDL_MOUSEMOTION) |
| 119 | { |
| 120 | action->setMouseAction(action->getDetails()->motion.x, action->getDetails()->motion.y, getX(), getY()); |
| 121 | } |
| 122 | |
| 123 | if (action->isMouseAction()) |
| 124 | { |
| 125 | if ((action->getAbsoluteXMouse() >= getX() && action->getAbsoluteXMouse() < getX() + getWidth()) && |
| 126 | (action->getAbsoluteYMouse() >= getY() && action->getAbsoluteYMouse() < getY() + getHeight())) |
| 127 | { |
| 128 | if (!_isHovered) |
| 129 | { |
| 130 | _isHovered = true; |
| 131 | mouseIn(action, state); |
| 132 | } |
| 133 | if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION) |
| 134 | { |
| 135 | _buttonsPressed = SDL_GetMouseState(0, 0); |
| 136 | for (Uint8 i = 1; i <= NUM_BUTTONS; ++i) |
| 137 | { |
| 138 | if (isButtonPressed(i)) |
| 139 | { |
| 140 | action->getDetails()->button.button = i; |
| 141 | mousePress(action, state); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | mouseOver(action, state); |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | if (_isHovered) |
| 150 | { |
| 151 | _isHovered = false; |
| 152 | mouseOut(action, state); |
| 153 | if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION) |
| 154 | { |
| 155 | for (Uint8 i = 1; i <= NUM_BUTTONS; ++i) |
| 156 | { |
| 157 | if (isButtonPressed(i)) |
| 158 | { |
| 159 | setButtonPressed(i, false); |
| 160 | } |
| 161 | action->getDetails()->button.button = i; |
| 162 | mouseRelease(action, state); |
| 163 | } |
| 164 | } |
nothing calls this directly
no test coverage detected