Fix Right-Click (Ctrl-Click) on OS X
This commit is contained in:
parent
cf286ed287
commit
2c27501c3f
1 changed files with 31 additions and 73 deletions
|
@ -80,6 +80,7 @@ static int mouse_y = 0;
|
||||||
static int prev_mouse_x = 0;
|
static int prev_mouse_x = 0;
|
||||||
static int prev_mouse_y = 0;
|
static int prev_mouse_y = 0;
|
||||||
static int button_mask = 0;
|
static int button_mask = 0;
|
||||||
|
static bool mouse_down_control = false;
|
||||||
|
|
||||||
@interface GodotApplication : NSApplication
|
@interface GodotApplication : NSApplication
|
||||||
@end
|
@end
|
||||||
|
@ -285,41 +286,48 @@ static int button_mask = 0;
|
||||||
//setModeCursor(window, window->cursorMode);
|
//setModeCursor(window, window->cursorMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDown:(NSEvent *)event {
|
static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) {
|
||||||
|
if (pressed) {
|
||||||
button_mask |= BUTTON_MASK_LEFT;
|
button_mask |= mask;
|
||||||
|
} else {
|
||||||
|
button_mask &= ~mask;
|
||||||
|
}
|
||||||
|
|
||||||
Ref<InputEventMouseButton> mb;
|
Ref<InputEventMouseButton> mb;
|
||||||
mb.instance();
|
mb.instance();
|
||||||
|
|
||||||
get_key_modifier_state([event modifierFlags], mb);
|
get_key_modifier_state([event modifierFlags], mb);
|
||||||
mb->set_button_index(BUTTON_LEFT);
|
mb->set_button_index(index);
|
||||||
mb->set_pressed(true);
|
mb->set_pressed(pressed);
|
||||||
mb->set_position(Vector2(mouse_x, mouse_y));
|
mb->set_position(Vector2(mouse_x, mouse_y));
|
||||||
mb->set_global_position(Vector2(mouse_x, mouse_y));
|
mb->set_global_position(Vector2(mouse_x, mouse_y));
|
||||||
mb->set_button_mask(button_mask);
|
mb->set_button_mask(button_mask);
|
||||||
mb->set_doubleclick([event clickCount] == 2);
|
if (index == BUTTON_LEFT && pressed) {
|
||||||
|
mb->set_doubleclick([event clickCount] == 2);
|
||||||
|
}
|
||||||
OS_OSX::singleton->push_input(mb);
|
OS_OSX::singleton->push_input(mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)mouseDown:(NSEvent *)event {
|
||||||
|
if (([event modifierFlags] & NSControlKeyMask)) {
|
||||||
|
mouse_down_control = true;
|
||||||
|
_mouseDownEvent(event, BUTTON_RIGHT, BUTTON_MASK_RIGHT, true);
|
||||||
|
} else {
|
||||||
|
mouse_down_control = false;
|
||||||
|
_mouseDownEvent(event, BUTTON_LEFT, BUTTON_MASK_LEFT, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)mouseDragged:(NSEvent *)event {
|
- (void)mouseDragged:(NSEvent *)event {
|
||||||
[self mouseMoved:event];
|
[self mouseMoved:event];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseUp:(NSEvent *)event {
|
- (void)mouseUp:(NSEvent *)event {
|
||||||
|
if (mouse_down_control) {
|
||||||
button_mask &= ~BUTTON_MASK_LEFT;
|
_mouseDownEvent(event, BUTTON_RIGHT, BUTTON_MASK_RIGHT, false);
|
||||||
Ref<InputEventMouseButton> mb;
|
} else {
|
||||||
mb.instance();
|
_mouseDownEvent(event, BUTTON_LEFT, BUTTON_MASK_LEFT, false);
|
||||||
|
}
|
||||||
get_key_modifier_state([event modifierFlags], mb);
|
|
||||||
mb->set_button_index(BUTTON_LEFT);
|
|
||||||
mb->set_pressed(false);
|
|
||||||
mb->set_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_global_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_button_mask(button_mask);
|
|
||||||
mb->set_doubleclick([event clickCount] == 2);
|
|
||||||
OS_OSX::singleton->push_input(mb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseMoved:(NSEvent *)event {
|
- (void)mouseMoved:(NSEvent *)event {
|
||||||
|
@ -347,20 +355,7 @@ static int button_mask = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)rightMouseDown:(NSEvent *)event {
|
- (void)rightMouseDown:(NSEvent *)event {
|
||||||
|
_mouseDownEvent(event, BUTTON_RIGHT, BUTTON_MASK_RIGHT, true);
|
||||||
button_mask |= BUTTON_MASK_RIGHT;
|
|
||||||
|
|
||||||
Ref<InputEventMouseButton> mb;
|
|
||||||
mb.instance();
|
|
||||||
|
|
||||||
get_key_modifier_state([event modifierFlags], mb);
|
|
||||||
mb->set_button_index(BUTTON_RIGHT);
|
|
||||||
mb->set_pressed(true);
|
|
||||||
mb->set_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_global_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_button_mask(button_mask);
|
|
||||||
mb->set_doubleclick([event clickCount] == 2);
|
|
||||||
OS_OSX::singleton->push_input(mb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)rightMouseDragged:(NSEvent *)event {
|
- (void)rightMouseDragged:(NSEvent *)event {
|
||||||
|
@ -368,20 +363,7 @@ static int button_mask = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)rightMouseUp:(NSEvent *)event {
|
- (void)rightMouseUp:(NSEvent *)event {
|
||||||
|
_mouseDownEvent(event, BUTTON_RIGHT, BUTTON_MASK_RIGHT, false);
|
||||||
button_mask &= ~BUTTON_MASK_RIGHT;
|
|
||||||
|
|
||||||
Ref<InputEventMouseButton> mb;
|
|
||||||
mb.instance();
|
|
||||||
|
|
||||||
get_key_modifier_state([event modifierFlags], mb);
|
|
||||||
mb->set_button_index(BUTTON_RIGHT);
|
|
||||||
mb->set_pressed(false);
|
|
||||||
mb->set_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_global_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_button_mask(button_mask);
|
|
||||||
mb->set_doubleclick([event clickCount] == 2);
|
|
||||||
OS_OSX::singleton->push_input(mb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)otherMouseDown:(NSEvent *)event {
|
- (void)otherMouseDown:(NSEvent *)event {
|
||||||
|
@ -389,19 +371,7 @@ static int button_mask = 0;
|
||||||
if ((int)[event buttonNumber] != 2)
|
if ((int)[event buttonNumber] != 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
button_mask |= BUTTON_MASK_MIDDLE;
|
_mouseDownEvent(event, BUTTON_MIDDLE, BUTTON_MASK_MIDDLE, true);
|
||||||
|
|
||||||
Ref<InputEventMouseButton> mb;
|
|
||||||
mb.instance();
|
|
||||||
|
|
||||||
get_key_modifier_state([event modifierFlags], mb);
|
|
||||||
mb->set_button_index(BUTTON_MIDDLE);
|
|
||||||
mb->set_pressed(true);
|
|
||||||
mb->set_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_global_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_button_mask(button_mask);
|
|
||||||
mb->set_doubleclick([event clickCount] == 2);
|
|
||||||
OS_OSX::singleton->push_input(mb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)otherMouseDragged:(NSEvent *)event {
|
- (void)otherMouseDragged:(NSEvent *)event {
|
||||||
|
@ -413,19 +383,7 @@ static int button_mask = 0;
|
||||||
if ((int)[event buttonNumber] != 2)
|
if ((int)[event buttonNumber] != 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
button_mask &= ~BUTTON_MASK_MIDDLE;
|
_mouseDownEvent(event, BUTTON_MIDDLE, BUTTON_MASK_MIDDLE, false);
|
||||||
|
|
||||||
Ref<InputEventMouseButton> mb;
|
|
||||||
mb.instance();
|
|
||||||
|
|
||||||
get_key_modifier_state([event modifierFlags], mb);
|
|
||||||
mb->set_button_index(BUTTON_MIDDLE);
|
|
||||||
mb->set_pressed(false);
|
|
||||||
mb->set_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_global_position(Vector2(mouse_x, mouse_y));
|
|
||||||
mb->set_button_mask(button_mask);
|
|
||||||
mb->set_doubleclick([event clickCount] == 2);
|
|
||||||
OS_OSX::singleton->push_input(mb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseExited:(NSEvent *)event {
|
- (void)mouseExited:(NSEvent *)event {
|
||||||
|
|
Loading…
Reference in a new issue