Haiku: implement get_mouse_pos() and get_mouse_button_state()

This commit is contained in:
Kostadin Damyanov 2015-06-18 22:41:33 +03:00
parent 2102d35e9c
commit f10eb8ffa1
3 changed files with 17 additions and 11 deletions

View File

@ -6,6 +6,7 @@ HaikuDirectWindow::HaikuDirectWindow(BRect p_frame)
{ {
last_mouse_pos_valid = false; last_mouse_pos_valid = false;
last_buttons_state = 0; last_buttons_state = 0;
last_button_mask = 0;
} }
@ -154,11 +155,11 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) {
uint32 buttons = message->FindInt32("buttons"); uint32 buttons = message->FindInt32("buttons");
if (!last_mouse_pos_valid) { if (!last_mouse_pos_valid) {
last_mouse_pos = pos; last_mouse_position = pos;
last_mouse_pos_valid = true; last_mouse_pos_valid = true;
} }
Point2i rel = pos - last_mouse_pos; Point2i rel = pos - last_mouse_position;
InputEvent motion_event; InputEvent motion_event;
motion_event.ID = ++event_id; motion_event.ID = ++event_id;
@ -178,7 +179,7 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) {
motion_event.mouse_motion.relative_x = rel.x; motion_event.mouse_motion.relative_x = rel.x;
motion_event.mouse_motion.relative_y = rel.y; motion_event.mouse_motion.relative_y = rel.y;
last_mouse_pos=pos; last_mouse_position = pos;
input->parse_input_event(motion_event); input->parse_input_event(motion_event);
} }
@ -194,8 +195,8 @@ inline InputModifierState HaikuDirectWindow::GetKeyModifierState(uint32 p_state)
return state; return state;
} }
inline unsigned int HaikuDirectWindow::GetMouseButtonState(uint32 p_state) { inline int HaikuDirectWindow::GetMouseButtonState(uint32 p_state) {
unsigned int state = 0; int state = 0;
if (p_state & B_PRIMARY_MOUSE_BUTTON) { if (p_state & B_PRIMARY_MOUSE_BUTTON) {
state |= 1 << 0; state |= 1 << 0;
@ -209,5 +210,7 @@ inline unsigned int HaikuDirectWindow::GetMouseButtonState(uint32 p_state) {
state |= 1 << 2; state |= 1 << 2;
} }
last_button_mask = state;
return state; return state;
} }

View File

@ -13,9 +13,10 @@ class HaikuDirectWindow : public BDirectWindow
{ {
private: private:
unsigned int event_id; unsigned int event_id;
Point2i last_mouse_pos; Point2i last_mouse_position;
bool last_mouse_pos_valid; bool last_mouse_pos_valid;
uint32 last_buttons_state; uint32 last_buttons_state;
int last_button_mask;
InputDefault* input; InputDefault* input;
HaikuGLView* view; HaikuGLView* view;
@ -24,7 +25,7 @@ private:
void DispatchMouseButton(BMessage* message); void DispatchMouseButton(BMessage* message);
void DispatchMouseMoved(BMessage* message); void DispatchMouseMoved(BMessage* message);
inline InputModifierState GetKeyModifierState(uint32 p_state); inline InputModifierState GetKeyModifierState(uint32 p_state);
inline unsigned int GetMouseButtonState(uint32 p_state); inline int GetMouseButtonState(uint32 p_state);
public: public:
HaikuDirectWindow(BRect p_frame); HaikuDirectWindow(BRect p_frame);
@ -38,6 +39,9 @@ public:
virtual void DirectConnected(direct_buffer_info* info); virtual void DirectConnected(direct_buffer_info* info);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler* handler); virtual void DispatchMessage(BMessage* message, BHandler* handler);
inline Point2i GetLastMousePosition() { return last_mouse_position; };
inline int GetLastButtonMask() { return last_button_mask; };
}; };
#endif #endif

View File

@ -174,19 +174,18 @@ void OS_Haiku::swap_buffers() {
} }
Point2 OS_Haiku::get_mouse_pos() const { Point2 OS_Haiku::get_mouse_pos() const {
ERR_PRINT("get_mouse_pos() NOT IMPLEMENTED"); return window->GetLastMousePosition();
} }
int OS_Haiku::get_mouse_button_state() const { int OS_Haiku::get_mouse_button_state() const {
ERR_PRINT("get_mouse_button_state() NOT IMPLEMENTED"); return window->GetLastButtonMask();
} }
void OS_Haiku::set_cursor_shape(CursorShape p_shape) { void OS_Haiku::set_cursor_shape(CursorShape p_shape) {
ERR_PRINT("set_cursor_shape() NOT IMPLEMENTED"); //ERR_PRINT("set_cursor_shape() NOT IMPLEMENTED");
} }
void OS_Haiku::set_window_title(const String& p_title) { void OS_Haiku::set_window_title(const String& p_title) {
//ERR_PRINT("set_window_title() NOT IMPLEMENTED");
window->SetTitle(p_title.utf8().get_data()); window->SetTitle(p_title.utf8().get_data());
} }