diff options
-rw-r--r-- | core/math/a_star.cpp | 8 | ||||
-rw-r--r-- | doc/base/classes.xml | 1 | ||||
-rw-r--r-- | editor/editor_themes.cpp | 5 | ||||
-rw-r--r-- | editor/plugins/path_2d_editor_plugin.cpp | 138 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 284 | ||||
-rw-r--r-- | scene/3d/vehicle_body.cpp | 18 | ||||
-rw-r--r-- | scene/3d/vehicle_body.h | 5 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 2 |
8 files changed, 231 insertions, 230 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 7e061359fc..320990cc50 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -43,6 +43,7 @@ int AStar::get_available_point_id() const { void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) { ERR_FAIL_COND(p_id < 0); + ERR_FAIL_COND(p_weight_scale < 1); if (!points.has(p_id)) { Point *pt = memnew(Point); pt->id = p_id; @@ -192,8 +193,7 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { Point *n = begin_point->neighbours[i]; n->prev_point = begin_point; - n->distance = _compute_cost(n->id, begin_point->id); - n->distance *= n->weight_scale; + n->distance = _compute_cost(begin_point->id, n->id) * n->weight_scale; n->last_pass = pass; open_list.add(&n->list); @@ -221,7 +221,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { real_t cost = p->distance; cost += _estimate_cost(p->id, end_point->id); - cost *= p->weight_scale; if (cost < least_cost) { @@ -238,8 +237,7 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { Point *e = p->neighbours[i]; - real_t distance = _compute_cost(p->id, e->id) + p->distance; - distance *= e->weight_scale; + real_t distance = _compute_cost(p->id, e->id) * e->weight_scale + p->distance; if (e->last_pass == pass) { //oh this was visited already, can we win the cost? diff --git a/doc/base/classes.xml b/doc/base/classes.xml index a04890d4fd..da614e14d3 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -1991,6 +1991,7 @@ <argument index="1" name="pos" type="Vector3"> </argument> <argument index="2" name="weight_scale" type="float" default="1"> + Weight scale has to be 1 or larger. </argument> <description> </description> diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index c7a41e4441..b88474e2c3 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -413,6 +413,11 @@ Ref<Theme> create_editor_theme() { theme->set_stylebox("comment", "GraphNode", graphsbcomment); theme->set_stylebox("commentfocus", "GraphNode", graphsbcommentselected); + // FileDialog + Color disable_color = light_color_2; + disable_color.a = 0.7; + theme->set_color("files_disabled", "FileDialog", disable_color); + return theme; } diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 38a2a0c462..f8d250334c 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -59,7 +59,6 @@ void Path2DEditor::_node_removed(Node *p_node) { } bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - if (!node) return false; @@ -76,11 +75,12 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = mb->get_pos(); - Vector2 cpoint = !mb->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); - //first check if a point is to be added (segment split) - real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + Vector2 cpoint = + !mb->get_alt() ? + canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : + node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); - // Test move point!! + real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); if (mb->is_pressed() && action == ACTION_NONE) { @@ -88,23 +88,43 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { for (int i = 0; i < curve->get_point_count(); i++) { - bool pointunder = false; - real_t dist_to_p = gpoint.distance_to(xform.xform(curve->get_point_pos(i))); real_t dist_to_p_out = gpoint.distance_to(xform.xform(curve->get_point_pos(i) + curve->get_point_out(i))); real_t dist_to_p_in = gpoint.distance_to(xform.xform(curve->get_point_pos(i) + curve->get_point_in(i))); - if (mb->get_button_index() == BUTTON_LEFT && !mb->get_shift() && mode == MODE_EDIT) { - if (dist_to_p < grab_threshold) { + // Check for point movement start (for point + in/out controls). + if (mb->get_button_index() == BUTTON_LEFT) { + if (!mb->get_shift() && mode == MODE_EDIT) { + // Point can only be moved in edit mode. + if (dist_to_p < grab_threshold) { - action = ACTION_MOVING_POINT; - action_point = i; - moving_from = curve->get_point_pos(i); - moving_screen_from = gpoint; - return true; + action = ACTION_MOVING_POINT; + action_point = i; + moving_from = curve->get_point_pos(i); + moving_screen_from = gpoint; + return true; + } + } else if (mode == MODE_EDIT || mode == MODE_EDIT_CURVE) { + // In/out controls can be moved in multiple modes. + if (dist_to_p_out < grab_threshold && i < (curve->get_point_count() - 1)) { + + action = ACTION_MOVING_OUT; + action_point = i; + moving_from = curve->get_point_out(i); + moving_screen_from = gpoint; + return true; + } else if (dist_to_p_in < grab_threshold && i > 0) { + + action = ACTION_MOVING_IN; + action_point = i; + moving_from = curve->get_point_in(i); + moving_screen_from = gpoint; + return true; + } } } + // Check for point deletion. if ((mb->get_button_index() == BUTTON_RIGHT && mode == MODE_EDIT) || (mb->get_button_index() == BUTTON_LEFT && mode == MODE_DELETE)) { if (dist_to_p < grab_threshold) { @@ -135,65 +155,10 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return true; } } - - if (dist_to_p < grab_threshold) - pointunder = true; - - if (mb->get_button_index() == BUTTON_LEFT && i < (curve->get_point_count() - 1)) { - if (dist_to_p_out < grab_threshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) { - - action_point = i; - moving_from = curve->get_point_pos(i); - moving_screen_from = gpoint; - return true; - } else if ((mb->get_button_index() == BUTTON_RIGHT && mode == MODE_EDIT) || (mb->get_button_index() == BUTTON_LEFT && mode == MODE_DELETE)) { - - undo_redo->create_action(TTR("Remove Point from Curve")); - undo_redo->add_do_method(curve.ptr(), "remove_point", i); - undo_redo->add_undo_method(curve.ptr(), "add_point", curve->get_point_pos(i), curve->get_point_in(i), curve->get_point_out(i), i); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - return true; - } else - pointunder = true; - } - - if (pointunder) - return true; } -#if 0 -I think i broke this, was this not suposed to go somewhere? - if (mb->get_button_index() == BUTTON_LEFT && i < (curve->get_point_count() - 1)) { - Point2 p = xform.xform(curve->get_point_pos(i) + curve->get_point_out(i)); - if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) { - action = ACTION_MOVING_OUT; - action_point = i; - moving_from = curve->get_point_out(i); - moving_screen_from = gpoint; - return true; - } - } - - if (mb->get_button_index() == BUTTON_LEFT && i > 0) { - Point2 p = xform.xform(curve->get_point_pos(i) + curve->get_point_in(i)); - if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) { - - action = ACTION_MOVING_IN; - action_point = i; - moving_from = curve->get_point_in(i); - moving_screen_from = gpoint; - return true; - } - } - - if (pointunder) - return true; -#endif } - // Test add point in empty space! - + // Check for point creation. if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && ((mb->get_command() && mode == MODE_EDIT) || mode == MODE_CREATE)) { Ref<Curve2D> curve = node->get_curve(); @@ -215,6 +180,7 @@ I think i broke this, was this not suposed to go somewhere? return true; } + // Check for point movement completion. if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && action != ACTION_NONE) { Ref<Curve2D> curve = node->get_curve(); @@ -222,6 +188,10 @@ I think i broke this, was this not suposed to go somewhere? Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); switch (action) { + case ACTION_NONE: + // N/A, handled in above condition. + break; + case ACTION_MOVING_POINT: { undo_redo->create_action(TTR("Move Point in Curve")); @@ -232,6 +202,7 @@ I think i broke this, was this not suposed to go somewhere? undo_redo->commit_action(); } break; + case ACTION_MOVING_IN: { undo_redo->create_action(TTR("Move In-Control in Curve")); @@ -242,6 +213,7 @@ I think i broke this, was this not suposed to go somewhere? undo_redo->commit_action(); } break; + case ACTION_MOVING_OUT: { undo_redo->create_action(TTR("Move Out-Control in Curve")); @@ -278,9 +250,6 @@ I think i broke this, was this not suposed to go somewhere? edited_point=1; return true; } else { - if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_threshold) { - //wip closed - _wip_close(); if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_treshold) { //wip closed _wip_close(); @@ -301,8 +270,6 @@ I think i broke this, was this not suposed to go somewhere? _wip_close(); } - - } break; case MODE_EDIT: { @@ -454,11 +421,8 @@ I think i broke this, was this not suposed to go somewhere? } - - } break; } - #endif } @@ -467,10 +431,13 @@ I think i broke this, was this not suposed to go somewhere? if (mm.is_valid()) { if (action != ACTION_NONE) { - + // Handle point/control movement. Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = mm->get_pos(); - Vector2 cpoint = !mm->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); + Vector2 cpoint = + !mm->get_alt() ? + canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : + node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); Ref<Curve2D> curve = node->get_curve(); @@ -478,19 +445,20 @@ I think i broke this, was this not suposed to go somewhere? switch (action) { - case ACTION_MOVING_POINT: { + case ACTION_NONE: + // N/A, handled in above condition. + break; + case ACTION_MOVING_POINT: { curve->set_point_pos(action_point, cpoint); } break; - case ACTION_MOVING_IN: { + case ACTION_MOVING_IN: { curve->set_point_in(action_point, new_pos); - } break; - case ACTION_MOVING_OUT: { + case ACTION_MOVING_OUT: { curve->set_point_out(action_point, new_pos); - } break; } diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 462a926674..d13486b490 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -63,15 +63,12 @@ static NSRect convertRectToBacking(NSRect contentRect) { return contentRect; } -static InputModifierState translateFlags(NSUInteger flags) { - InputModifierState mod; +static void get_key_modifier_state(unsigned int p_osx_state, Ref<InputEventWithModifiers> state) { - mod.shift = (flags & NSShiftKeyMask); - mod.control = (flags & NSControlKeyMask); - mod.alt = (flags & NSAlternateKeyMask); - mod.meta = (flags & NSCommandKeyMask); - - return mod; + state->set_shift((p_osx_state & NSShiftKeyMask)); + state->set_control((p_osx_state & NSControlKeyMask)); + state->set_alt((p_osx_state & NSAlternateKeyMask)); + state->set_metakey((p_osx_state & NSCommandKeyMask)); } static int mouse_x = 0; @@ -286,20 +283,19 @@ static int button_mask = 0; - (void)mouseDown:(NSEvent *)event { - //print_line("mouse down:"); button_mask |= BUTTON_MASK_LEFT; - Ref<InputEvent> ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev->get_button_index() = BUTTON_LEFT; - ev->is_pressed() = true; - ev->get_pos().x = mouse_x; - ev->get_pos().y = mouse_y; - ev.mouse_button.global_x = mouse_x; - ev.mouse_button.global_y = mouse_y; - ev->get_button_mask() = button_mask; - ev.mouse_button.doubleclick = [event clickCount] == 2; - ev.mouse_button.mod = translateFlags([event modifierFlags]); - OS_OSX::singleton->push_input(ev); + + Ref<InputEventMouseButton> mb; + mb.instance(); + + get_key_modifier_state([event modifierFlags], mb); + mb->set_button_index(BUTTON_LEFT); + mb->set_pressed(true); + mb->set_pos(Vector2(mouse_x, mouse_y)); + mb->set_global_pos(Vector2(mouse_x, mouse_y)); + mb->set_button_mask(button_mask); + mb->set_doubleclick([event clickCount] == 2); + OS_OSX::singleton->push_input(mb); } - (void)mouseDragged:(NSEvent *)event { @@ -309,56 +305,58 @@ static int button_mask = 0; - (void)mouseUp:(NSEvent *)event { button_mask &= ~BUTTON_MASK_LEFT; - Ref<InputEvent> ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev->get_button_index() = BUTTON_LEFT; - ev->is_pressed() = false; - ev->get_pos().x = mouse_x; - ev->get_pos().y = mouse_y; - ev.mouse_button.global_x = mouse_x; - ev.mouse_button.global_y = mouse_y; - ev->get_button_mask() = button_mask; - ev.mouse_button.mod = translateFlags([event modifierFlags]); - OS_OSX::singleton->push_input(ev); + Ref<InputEventMouseButton> mb; + mb.instance(); + + get_key_modifier_state([event modifierFlags], mb); + mb->set_button_index(BUTTON_LEFT); + mb->set_pressed(false); + mb->set_pos(Vector2(mouse_x, mouse_y)); + mb->set_global_pos(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 { - Ref<InputEvent> ev; - ev.type = InputEvent::MOUSE_MOTION; - ev->get_button_mask() = button_mask; + Ref<InputEventMouseMotion> mm; + mm.instance(); + + mm->set_button_mask(button_mask); prev_mouse_x = mouse_x; prev_mouse_y = mouse_y; const NSRect contentRect = [OS_OSX::singleton->window_view frame]; const NSPoint p = [event locationInWindow]; mouse_x = p.x * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); mouse_y = (contentRect.size.height - p.y) * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); - ev.mouse_motion.x = mouse_x; - ev.mouse_motion.y = mouse_y; - ev.mouse_motion.global_x = mouse_x; - ev.mouse_motion.global_y = mouse_y; - ev->get_relative().x = [event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); - ev->get_relative().y = [event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); - ev.mouse_motion.mod = translateFlags([event modifierFlags]); + mm->set_pos(Vector2(mouse_x, mouse_y)); + mm->set_global_pos(Vector2(mouse_x, mouse_y)); + Vector2 relativeMotion = Vector2(); + relativeMotion.x = [event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); + relativeMotion.y = [event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); + mm->set_relative(relativeMotion); + get_key_modifier_state([event modifierFlags], mm); OS_OSX::singleton->input->set_mouse_position(Point2(mouse_x, mouse_y)); - OS_OSX::singleton->push_input(ev); + OS_OSX::singleton->push_input(mm); } - (void)rightMouseDown:(NSEvent *)event { button_mask |= BUTTON_MASK_RIGHT; - Ref<InputEvent> ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev->get_button_index() = BUTTON_RIGHT; - ev->is_pressed() = true; - ev->get_pos().x = mouse_x; - ev->get_pos().y = mouse_y; - ev.mouse_button.global_x = mouse_x; - ev.mouse_button.global_y = mouse_y; - ev->get_button_mask() = button_mask; - ev.mouse_button.mod = translateFlags([event modifierFlags]); - OS_OSX::singleton->push_input(ev); + + Ref<InputEventMouseButton> mb; + mb.instance(); + + get_key_modifier_state([event modifierFlags], mb); + mb->set_button_index(BUTTON_RIGHT); + mb->set_pressed(true); + mb->set_pos(Vector2(mouse_x, mouse_y)); + mb->set_global_pos(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 { @@ -367,18 +365,19 @@ static int button_mask = 0; - (void)rightMouseUp:(NSEvent *)event { - button_mask &= ~BUTTON_MASK_RIGHT; - Ref<InputEvent> ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev->get_button_index() = BUTTON_RIGHT; - ev->is_pressed() = false; - ev->get_pos().x = mouse_x; - ev->get_pos().y = mouse_y; - ev.mouse_button.global_x = mouse_x; - ev.mouse_button.global_y = mouse_y; - ev->get_button_mask() = button_mask; - ev.mouse_button.mod = translateFlags([event modifierFlags]); - OS_OSX::singleton->push_input(ev); + 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_pos(Vector2(mouse_x, mouse_y)); + mb->set_global_pos(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 { @@ -387,17 +386,18 @@ static int button_mask = 0; return; button_mask |= BUTTON_MASK_MIDDLE; - Ref<InputEvent> ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev->get_button_index() = BUTTON_MIDDLE; - ev->is_pressed() = true; - ev->get_pos().x = mouse_x; - ev->get_pos().y = mouse_y; - ev.mouse_button.global_x = mouse_x; - ev.mouse_button.global_y = mouse_y; - ev->get_button_mask() = button_mask; - ev.mouse_button.mod = translateFlags([event modifierFlags]); - OS_OSX::singleton->push_input(ev); + + Ref<InputEventMouseButton> mb; + mb.instance(); + + get_key_modifier_state([event modifierFlags], mb); + mb->set_button_index(BUTTON_MIDDLE); + mb->set_pressed(true); + mb->set_pos(Vector2(mouse_x, mouse_y)); + mb->set_global_pos(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 { @@ -409,18 +409,19 @@ static int button_mask = 0; if ((int)[event buttonNumber] != 2) return; - button_mask &= ~BUTTON_MASK_MIDDLE; - Ref<InputEvent> ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev->get_button_index() = BUTTON_MIDDLE; - ev->is_pressed() = false; - ev->get_pos().x = mouse_x; - ev->get_pos().y = mouse_y; - ev.mouse_button.global_x = mouse_x; - ev.mouse_button.global_y = mouse_y; - ev->get_button_mask() = button_mask; - ev.mouse_button.mod = translateFlags([event modifierFlags]); - OS_OSX::singleton->push_input(ev); + button_mask |= BUTTON_MASK_MIDDLE; + + Ref<InputEventMouseButton> mb; + mb.instance(); + + get_key_modifier_state([event modifierFlags], mb); + mb->set_button_index(BUTTON_MIDDLE); + mb->set_pressed(true); + mb->set_pos(Vector2(mouse_x, mouse_y)); + mb->set_global_pos(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 { @@ -610,96 +611,102 @@ static int translateKey(unsigned int key) { } - (void)keyDown:(NSEvent *)event { - Ref<InputEvent> ev; - ev.type = InputEvent::KEY; - ev->is_pressed() = true; - ev.key.mod = translateFlags([event modifierFlags]); - ev->get_scancode() = latin_keyboard_keycode_convert(translateKey([event keyCode])); - ev->is_echo() = [event isARepeat]; + + Ref<InputEventKey> k; + k.instance(); + + get_key_modifier_state([event modifierFlags], k); + k->set_pressed(true); + k->set_scancode(latin_keyboard_keycode_convert(translateKey([event keyCode]))); + k->set_echo([event isARepeat]); NSString *characters = [event characters]; NSUInteger i, length = [characters length]; - if (length > 0 && keycode_has_unicode(ev->get_scancode())) { + if (length > 0 && keycode_has_unicode(k->get_scancode())) { for (i = 0; i < length; i++) { - ev.key.unicode = [characters characterAtIndex:i]; - OS_OSX::singleton->push_input(ev); - ev->get_scancode() = 0; + k->set_unicode([characters characterAtIndex:i]); + OS_OSX::singleton->push_input(k); + k->set_scancode(0); } } else { - OS_OSX::singleton->push_input(ev); + OS_OSX::singleton->push_input(k); } } - (void)flagsChanged:(NSEvent *)event { - Ref<InputEvent> ev; + Ref<InputEventKey> k; + k.instance(); + int key = [event keyCode]; int mod = [event modifierFlags]; - ev.type = InputEvent::KEY; - if (key == 0x36 || key == 0x37) { if (mod & NSCommandKeyMask) { mod &= ~NSCommandKeyMask; - ev->is_pressed() = true; + k->set_pressed(true); } else { - ev->is_pressed() = false; + k->set_pressed(false); } } else if (key == 0x38 || key == 0x3c) { if (mod & NSShiftKeyMask) { mod &= ~NSShiftKeyMask; - ev->is_pressed() = true; + k->set_pressed(true); } else { - ev->is_pressed() = false; + k->set_pressed(false); } } else if (key == 0x3a || key == 0x3d) { if (mod & NSAlternateKeyMask) { mod &= ~NSAlternateKeyMask; - ev->is_pressed() = true; + k->set_pressed(true); } else { - ev->is_pressed() = false; + k->set_pressed(false); } } else if (key == 0x3b || key == 0x3e) { if (mod & NSControlKeyMask) { mod &= ~NSControlKeyMask; - ev->is_pressed() = true; + k->set_pressed(true); } else { - ev->is_pressed() = false; + k->set_pressed(false); } } else { return; } - ev.key.mod = translateFlags(mod); - ev->get_scancode() = latin_keyboard_keycode_convert(translateKey(key)); + get_key_modifier_state(mod, k); + k->set_scancode(latin_keyboard_keycode_convert(translateKey(key))); - OS_OSX::singleton->push_input(ev); + OS_OSX::singleton->push_input(k); } - (void)keyUp:(NSEvent *)event { - Ref<InputEvent> ev; - ev.type = InputEvent::KEY; - ev->is_pressed() = false; - ev.key.mod = translateFlags([event modifierFlags]); - ev->get_scancode() = latin_keyboard_keycode_convert(translateKey([event keyCode])); - OS_OSX::singleton->push_input(ev); -} - -inline void sendScrollEvent(int button, double factor) { - Ref<InputEvent> ev; - ev.type = Ref<InputEvent>::MOUSE_BUTTON; - ev->get_button_index() = button; - ev.mouse_button->get_factor() = factor; - ev->is_pressed() = true; - ev->get_pos().x = mouse_x; - ev->get_pos().y = mouse_y; - ev.mouse_button.global_x = mouse_x; - ev.mouse_button.global_y = mouse_y; - ev->get_button_mask() = button_mask; - OS_OSX::singleton->push_input(ev); - ev->is_pressed() = false; - OS_OSX::singleton->push_input(ev); + Ref<InputEventKey> k; + k.instance(); + + get_key_modifier_state([event modifierFlags], k); + k->set_pressed(false); + k->set_scancode(latin_keyboard_keycode_convert(translateKey([event keyCode]))); + + OS_OSX::singleton->push_input(k); +} + +inline void sendScrollEvent(int button, double factor, int modifierFlags) { + + Ref<InputEventMouseButton> sc; + sc.instance(); + + get_key_modifier_state(modifierFlags, sc); + sc->set_button_index(button); + sc->set_factor(factor); + sc->set_pressed(true); + Vector2 mouse_pos = Vector2(mouse_x, mouse_y); + sc->set_pos(mouse_pos); + sc->set_global_pos(mouse_pos); + sc->set_button_mask(button_mask); + OS_OSX::singleton->push_input(sc); + sc->set_pressed(false); + OS_OSX::singleton->push_input(sc); } - (void)scrollWheel:(NSEvent *)event { @@ -720,12 +727,11 @@ inline void sendScrollEvent(int button, double factor) { deltaX = [event deltaX]; deltaY = [event deltaY]; } - if (fabs(deltaX)) { - sendScrollEvent(0 > deltaX ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_LEFT, fabs(deltaX * 0.3)); + sendScrollEvent(0 > deltaX ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_LEFT, fabs(deltaX * 0.3), [event modifierFlags]); } if (fabs(deltaY)) { - sendScrollEvent(0 < deltaY ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN, fabs(deltaY * 0.3)); + sendScrollEvent(0 < deltaY ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN, fabs(deltaY * 0.3), [event modifierFlags]); } } diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body.cpp index 38e1ba1cd5..8d927e529e 100644 --- a/scene/3d/vehicle_body.cpp +++ b/scene/3d/vehicle_body.cpp @@ -214,6 +214,18 @@ float VehicleWheel::get_friction_slip() const { return m_frictionSlip; } +void VehicleWheel::set_roll_influence(float p_value) { + m_rollInfluence = p_value; +} + +float VehicleWheel::get_roll_influence() const { + return m_rollInfluence; +} + +bool VehicleWheel::is_in_contact() const { + return m_raycastInfo.m_isInContact; +} + void VehicleWheel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_radius", "length"), &VehicleWheel::set_radius); @@ -246,9 +258,15 @@ void VehicleWheel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_friction_slip", "length"), &VehicleWheel::set_friction_slip); ClassDB::bind_method(D_METHOD("get_friction_slip"), &VehicleWheel::get_friction_slip); + ClassDB::bind_method(D_METHOD("is_in_contact"), &VehicleWheel::is_in_contact); + + ClassDB::bind_method(D_METHOD("set_roll_influence", "roll_influence"), &VehicleWheel::set_roll_influence); + ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel::get_roll_influence); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_traction"), "set_use_as_traction", "is_used_as_traction"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_steering"), "set_use_as_steering", "is_used_as_steering"); ADD_GROUP("Wheel", "wheel_"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_roll_influence"), "set_roll_influence", "get_roll_influence"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_radius"), "set_radius", "get_radius"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_rest_length"), "set_suspension_rest_length", "get_suspension_rest_length"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_friction_slip"), "set_friction_slip", "get_friction_slip"); diff --git a/scene/3d/vehicle_body.h b/scene/3d/vehicle_body.h index cdb2ebc0be..7ed9bce730 100644 --- a/scene/3d/vehicle_body.h +++ b/scene/3d/vehicle_body.h @@ -126,6 +126,11 @@ public: void set_use_as_steering(bool p_enabled); bool is_used_as_steering() const; + bool is_in_contact() const; + + void set_roll_influence(float p_value); + float get_roll_influence() const; + VehicleWheel(); }; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 67d440ca67..662ce63946 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -361,7 +361,7 @@ void ColorPicker::_w_input(const Ref<InputEvent> &ev) { if (!changing_color) return; - float y = CLAMP((float)bev->get_pos().y, 0, 256); + float y = CLAMP((float)mev->get_pos().y, 0, 256); h = 1.0 - y / 256.0; color.set_hsv(h, s, v, color.a); last_hsv = color; |