Haiku: read the status of the key modifiers and mouse buttons

This commit is contained in:
Kostadin Damyanov 2015-06-17 22:27:45 +03:00
parent 1505d65ac9
commit 2102d35e9c
2 changed files with 51 additions and 22 deletions

View file

@ -92,6 +92,7 @@ void HaikuDirectWindow::DispatchMouseButton(BMessage* message) {
return;
}
uint32 modifiers = message->FindInt32("modifiers");
uint32 buttons = message->FindInt32("buttons");
uint32 button = buttons ^ last_buttons_state;
last_buttons_state = buttons;
@ -107,9 +108,8 @@ void HaikuDirectWindow::DispatchMouseButton(BMessage* message) {
mouse_event.type = InputEvent::MOUSE_BUTTON;
mouse_event.device = 0;
// TODO: implement the modifier state getters
//mouse_event.mouse_button.mod = get_key_modifier_state(event.xbutton.state);
//mouse_event.mouse_button.button_mask = get_mouse_button_state(event.xbutton.state);
mouse_event.mouse_button.mod = GetKeyModifierState(modifiers);
mouse_event.mouse_button.button_mask = GetMouseButtonState(buttons);
mouse_event.mouse_button.x = where.x;
mouse_event.mouse_button.y = where.y;
mouse_event.mouse_button.global_x = where.x;
@ -118,17 +118,14 @@ void HaikuDirectWindow::DispatchMouseButton(BMessage* message) {
switch (button) {
default:
case B_PRIMARY_MOUSE_BUTTON:
ERR_PRINT("PRIMARY");
mouse_event.mouse_button.button_index = 1;
break;
case B_SECONDARY_MOUSE_BUTTON:
ERR_PRINT("SECONDARY");
mouse_event.mouse_button.button_index = 2;
break;
case B_TERTIARY_MOUSE_BUTTON:
ERR_PRINT("MIDDLE");
mouse_event.mouse_button.button_index = 3;
break;
}
@ -153,10 +150,12 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) {
}
Point2i pos(where.x, where.y);
uint32 modifiers = message->FindInt32("modifiers");
uint32 buttons = message->FindInt32("buttons");
if (!last_mouse_pos_valid) {
last_mouse_pos=pos;
last_mouse_pos_valid=true;
last_mouse_pos = pos;
last_mouse_pos_valid = true;
}
Point2i rel = pos - last_mouse_pos;
@ -166,9 +165,8 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) {
motion_event.type = InputEvent::MOUSE_MOTION;
motion_event.device = 0;
// TODO: implement the modifier state getters
//motion_event.mouse_motion.mod = get_key_modifier_state(event.xmotion.state);
//motion_event.mouse_motion.button_mask = get_mouse_button_state(event.xmotion.state);
motion_event.mouse_motion.mod = GetKeyModifierState(modifiers);
motion_event.mouse_motion.button_mask = GetMouseButtonState(buttons);
motion_event.mouse_motion.x = pos.x;
motion_event.mouse_motion.y = pos.y;
input->set_mouse_pos(pos);
@ -184,3 +182,32 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) {
input->parse_input_event(motion_event);
}
inline InputModifierState HaikuDirectWindow::GetKeyModifierState(uint32 p_state) {
InputModifierState state;
state.shift = (p_state & B_SHIFT_KEY) != 0;
state.control = (p_state & B_CONTROL_KEY) != 0;
state.alt = (p_state & B_OPTION_KEY) != 0;
state.meta = (p_state & B_COMMAND_KEY) != 0;
return state;
}
inline unsigned int HaikuDirectWindow::GetMouseButtonState(uint32 p_state) {
unsigned int state = 0;
if (p_state & B_PRIMARY_MOUSE_BUTTON) {
state |= 1 << 0;
}
if (p_state & B_SECONDARY_MOUSE_BUTTON) {
state |= 1 << 1;
}
if (p_state & B_TERTIARY_MOUSE_BUTTON) {
state |= 1 << 2;
}
return state;
}

View file

@ -23,6 +23,8 @@ private:
void DispatchMouseButton(BMessage* message);
void DispatchMouseMoved(BMessage* message);
inline InputModifierState GetKeyModifierState(uint32 p_state);
inline unsigned int GetMouseButtonState(uint32 p_state);
public:
HaikuDirectWindow(BRect p_frame);