Haiku: add support for mouse wheel

This commit is contained in:
Kostadin Damyanov 2015-06-21 22:18:27 +03:00
parent 6f48ddc61d
commit 174df9a276
2 changed files with 35 additions and 0 deletions

View file

@ -7,6 +7,7 @@ HaikuDirectWindow::HaikuDirectWindow(BRect p_frame)
last_mouse_pos_valid = false;
last_buttons_state = 0;
last_button_mask = 0;
last_key_modifier_state = 0;
}
@ -74,6 +75,10 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) {
DispatchMouseMoved(message);
break;
case B_MOUSE_WHEEL_CHANGED:
DispatchMouseWheelChanged(message);
break;
default:
BDirectWindow::DispatchMessage(message, handler);
}
@ -178,7 +183,35 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) {
input->parse_input_event(motion_event);
}
void HaikuDirectWindow::DispatchMouseWheelChanged(BMessage* message) {
float wheel_delta_y = 0;
if (message->FindFloat("be:wheel_delta_y", &wheel_delta_y) != B_OK) {
return;
}
InputEvent mouse_event;
mouse_event.ID = ++event_id;
mouse_event.type = InputEvent::MOUSE_BUTTON;
mouse_event.device = 0;
mouse_event.mouse_button.button_index = wheel_delta_y < 0 ? 4 : 5;
mouse_event.mouse_button.mod = GetKeyModifierState(last_key_modifier_state);
mouse_event.mouse_button.button_mask = last_button_mask;
mouse_event.mouse_button.x = last_mouse_position.x;
mouse_event.mouse_button.y = last_mouse_position.y;
mouse_event.mouse_button.global_x = last_mouse_position.x;
mouse_event.mouse_button.global_y = last_mouse_position.y;
mouse_event.mouse_button.pressed = true;
input->parse_input_event(mouse_event);
mouse_event.ID = ++event_id;
mouse_event.mouse_button.pressed = false;
input->parse_input_event(mouse_event);
}
inline InputModifierState HaikuDirectWindow::GetKeyModifierState(uint32 p_state) {
last_key_modifier_state = p_state;
InputModifierState state;
state.shift = (p_state & B_SHIFT_KEY) != 0;

View file

@ -16,6 +16,7 @@ private:
Point2i last_mouse_position;
bool last_mouse_pos_valid;
uint32 last_buttons_state;
uint32 last_key_modifier_state;
int last_button_mask;
MainLoop* main_loop;
@ -25,6 +26,7 @@ private:
void DispatchMouseButton(BMessage* message);
void DispatchMouseMoved(BMessage* message);
void DispatchMouseWheelChanged(BMessage* message);
inline InputModifierState GetKeyModifierState(uint32 p_state);
inline int GetMouseButtonState(uint32 p_state);