mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 10:11:57 +03:00
Merge pull request #73692 from m4gr3d/update_touchscreen_editor_settings_3x
[3.x] Enable granular control of touchscreen related settings
This commit is contained in:
@@ -343,7 +343,7 @@ bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_e
|
||||
if (mb->get_button_index() == BUTTON_LEFT) {
|
||||
if (mb->is_pressed()) {
|
||||
for (int i = 0; i < handles.size(); i++) {
|
||||
if (xform.xform(handles[i]).distance_to(gpoint) < 8) {
|
||||
if (xform.xform(handles[i]).distance_to(gpoint) < grab_threshold) {
|
||||
edit_handle = i;
|
||||
|
||||
break;
|
||||
@@ -557,6 +557,10 @@ void CollisionShape2DEditor::_notification(int p_what) {
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
get_tree()->disconnect("node_removed", this, "_node_removed");
|
||||
} break;
|
||||
|
||||
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
||||
grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius");
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,6 +598,7 @@ CollisionShape2DEditor::CollisionShape2DEditor(EditorNode *p_editor) {
|
||||
|
||||
edit_handle = -1;
|
||||
pressed = false;
|
||||
grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius");
|
||||
}
|
||||
|
||||
void CollisionShape2DEditorPlugin::edit(Object *p_obj) {
|
||||
|
||||
@@ -75,6 +75,7 @@ class CollisionShape2DEditor : public Control {
|
||||
int shape_type;
|
||||
int edit_handle;
|
||||
bool pressed;
|
||||
real_t grab_threshold = 8;
|
||||
Variant original;
|
||||
Transform2D original_transform;
|
||||
Point2 last_point;
|
||||
|
||||
@@ -44,6 +44,7 @@ CurveEditor::CurveEditor() {
|
||||
_tangents_length = 40;
|
||||
_dragging = false;
|
||||
_has_undo_data = false;
|
||||
_gizmo_handle_scale = EDITOR_GET("interface/touchscreen/scale_gizmo_handles");
|
||||
|
||||
set_focus_mode(FOCUS_ALL);
|
||||
set_clip_contents(true);
|
||||
@@ -96,8 +97,13 @@ Size2 CurveEditor::get_minimum_size() const {
|
||||
}
|
||||
|
||||
void CurveEditor::_notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
_draw();
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_DRAW: {
|
||||
_draw();
|
||||
} break;
|
||||
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
||||
_gizmo_handle_scale = EDITOR_GET("interface/touchscreen/scale_gizmo_handles");
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,7 +397,7 @@ int CurveEditor::get_point_at(Vector2 pos) const {
|
||||
}
|
||||
const Curve &curve = **_curve_ref;
|
||||
|
||||
const float true_hover_radius = Math::round(_hover_radius * EDSCALE);
|
||||
const float true_hover_radius = Math::round(_hover_radius * _gizmo_handle_scale * EDSCALE);
|
||||
const float r = true_hover_radius * true_hover_radius;
|
||||
|
||||
for (int i = 0; i < curve.get_point_count(); ++i) {
|
||||
@@ -411,14 +417,14 @@ CurveEditor::TangentIndex CurveEditor::get_tangent_at(Vector2 pos) const {
|
||||
|
||||
if (_selected_point != 0) {
|
||||
Vector2 control_pos = get_tangent_view_pos(_selected_point, TANGENT_LEFT);
|
||||
if (control_pos.distance_to(pos) < _hover_radius) {
|
||||
if (control_pos.distance_to(pos) < _hover_radius * _gizmo_handle_scale) {
|
||||
return TANGENT_LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
if (_selected_point != _curve_ref->get_point_count() - 1) {
|
||||
Vector2 control_pos = get_tangent_view_pos(_selected_point, TANGENT_RIGHT);
|
||||
if (control_pos.distance_to(pos) < _hover_radius) {
|
||||
if (control_pos.distance_to(pos) < _hover_radius * _gizmo_handle_scale) {
|
||||
return TANGENT_RIGHT;
|
||||
}
|
||||
}
|
||||
@@ -555,7 +561,7 @@ Vector2 CurveEditor::get_tangent_view_pos(int i, TangentIndex tangent) const {
|
||||
Vector2 point_pos = get_view_pos(_curve_ref->get_point_position(i));
|
||||
Vector2 control_pos = get_view_pos(_curve_ref->get_point_position(i) + dir);
|
||||
|
||||
return point_pos + Math::round(_tangents_length * EDSCALE) * (control_pos - point_pos).normalized();
|
||||
return point_pos + Math::round(_tangents_length * _gizmo_handle_scale * EDSCALE) * (control_pos - point_pos).normalized();
|
||||
}
|
||||
|
||||
Vector2 CurveEditor::get_view_pos(Vector2 world_pos) const {
|
||||
@@ -699,13 +705,13 @@ void CurveEditor::_draw() {
|
||||
if (i != 0) {
|
||||
Vector2 control_pos = get_tangent_view_pos(i, TANGENT_LEFT);
|
||||
draw_line(get_view_pos(pos), control_pos, tangent_color, Math::round(EDSCALE), true);
|
||||
draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(Math::round(2 * EDSCALE)), tangent_color);
|
||||
draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(Math::round(2 * _gizmo_handle_scale * EDSCALE)), tangent_color);
|
||||
}
|
||||
|
||||
if (i != curve.get_point_count() - 1) {
|
||||
Vector2 control_pos = get_tangent_view_pos(i, TANGENT_RIGHT);
|
||||
draw_line(get_view_pos(pos), control_pos, tangent_color, Math::round(EDSCALE), true);
|
||||
draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(Math::round(2 * EDSCALE)), tangent_color);
|
||||
draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(Math::round(2 * _gizmo_handle_scale * EDSCALE)), tangent_color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -728,7 +734,7 @@ void CurveEditor::_draw() {
|
||||
|
||||
for (int i = 0; i < curve.get_point_count(); ++i) {
|
||||
Vector2 pos = curve.get_point_position(i);
|
||||
draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(Math::round(3 * EDSCALE)), i == _selected_point ? selected_point_color : point_color);
|
||||
draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(Math::round(3 * _gizmo_handle_scale * EDSCALE)), i == _selected_point ? selected_point_color : point_color);
|
||||
// TODO Circles are prettier. Needs a fix! Or a texture
|
||||
//draw_circle(pos, 2, point_color);
|
||||
}
|
||||
@@ -738,7 +744,7 @@ void CurveEditor::_draw() {
|
||||
if (_hover_point != -1) {
|
||||
const Color hover_color = line_color;
|
||||
Vector2 pos = curve.get_point_position(_hover_point);
|
||||
draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(Math::round(_hover_radius * EDSCALE)), hover_color, false, Math::round(EDSCALE));
|
||||
draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(Math::round(_hover_radius * _gizmo_handle_scale * EDSCALE)), hover_color, false, Math::round(EDSCALE));
|
||||
}
|
||||
|
||||
// Help text
|
||||
|
||||
@@ -117,6 +117,7 @@ private:
|
||||
// Constant
|
||||
float _hover_radius;
|
||||
float _tangents_length;
|
||||
float _gizmo_handle_scale = 1.0;
|
||||
};
|
||||
|
||||
class EditorInspectorPluginCurve : public EditorInspectorPlugin {
|
||||
|
||||
Reference in New Issue
Block a user