Path: blob/master/scene/debugger/runtime_node_select.h
20934 views
/**************************************************************************/1/* runtime_node_select.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#ifdef DEBUG_ENABLED3334#include "scene/gui/view_panner.h"35#ifndef _3D_DISABLED36#include "scene/resources/mesh.h"37#endif // _3D_DISABLED3839class Node;40class PopupMenu;4142class RuntimeNodeSelect : public Object {43GDCLASS(RuntimeNodeSelect, Object);4445public:46enum NodeType {47NODE_TYPE_NONE,48NODE_TYPE_2D,49NODE_TYPE_3D,50NODE_TYPE_MAX,51};5253enum SelectMode {54SELECT_MODE_SINGLE,55SELECT_MODE_LIST,56SELECT_MODE_MAX,57};5859private:60friend class SceneDebugger;6162NodeType node_select_type = NODE_TYPE_2D;63SelectMode node_select_mode = SELECT_MODE_SINGLE;6465struct SelectResult {66Node *item = nullptr;67real_t order = 0;68_FORCE_INLINE_ bool operator<(const SelectResult &p_rr) const { return p_rr.order < order; }69};7071const int SELECTION_MIN_AREA = 8 * 8;72enum SelectionDragState {73SELECTION_DRAG_NONE,74SELECTION_DRAG_MOVE,75SELECTION_DRAG_END,76};77SelectionDragState selection_drag_state = SELECTION_DRAG_NONE;7879bool has_selection = false;80int max_selection = 1;81Point2 selection_position = Point2(Math::INF, Math::INF);82Rect2 selection_drag_area;83PopupMenu *selection_list = nullptr;84Color selection_area_fill;85Color selection_area_outline;86bool selection_visible = true;87bool selection_update_queued = false;8889bool avoid_locked_nodes = false;90bool prefer_group_selection = false;9192bool multi_shortcut_pressed = false;93bool list_shortcut_pressed = false;94RID draw_canvas;95RID sel_drag_ci;9697bool camera_override = false;98bool camera_first_override = true;99100// Values taken from EditorZoomWidget.101const float VIEW_2D_MIN_ZOOM = 1.0 / 128;102const float VIEW_2D_MAX_ZOOM = 128;103104Ref<ViewPanner> panner;105Vector2 view_2d_offset;106real_t view_2d_zoom = 1.0;107bool warped_panning = false;108109LocalVector<ObjectID> selected_ci_nodes;110real_t sel_2d_grab_dist = 0;111int sel_2d_scale = 1;112113RID sbox_2d_ci;114115#ifndef _3D_DISABLED116struct Cursor {117Vector3 pos;118real_t x_rot, y_rot, distance, fov_scale;119Vector3 eye_pos; // Used in freelook mode.120121Cursor() {122// These rotations place the camera in +X +Y +Z, aka south east, facing north west.123x_rot = 0.5;124y_rot = -0.5;125distance = 4;126fov_scale = 1.0;127}128};129Cursor cursor;130131// Values taken from Node3DEditor.132const float VIEW_3D_MIN_ZOOM = 0.01;133#ifdef REAL_T_IS_DOUBLE134const double VIEW_3D_MAX_ZOOM = 1'000'000'000'000;135#else136const float VIEW_3D_MAX_ZOOM = 10'000;137#endif // REAL_T_IS_DOUBLE138139const float CAMERA_MIN_FOV_SCALE = 0.1;140const float CAMERA_MAX_FOV_SCALE = 2.5;141142bool camera_freelook = false;143144real_t camera_fov = 0;145real_t camera_znear = 0;146real_t camera_zfar = 0;147148bool invert_x_axis = false;149bool invert_y_axis = false;150bool warped_mouse_panning_3d = false;151152real_t freelook_base_speed = 0;153real_t freelook_sensitivity = 0;154real_t orbit_sensitivity = 0;155real_t translation_sensitivity = 0;156157Vector2 previous_mouse_position;158159struct SelectionBox3D : public RefCounted {160RID instance;161RID instance_ofs;162RID instance_xray;163RID instance_xray_ofs;164165Transform3D transform;166AABB bounds;167168~SelectionBox3D() {169if (instance.is_valid()) {170RS::get_singleton()->free_rid(instance);171RS::get_singleton()->free_rid(instance_ofs);172RS::get_singleton()->free_rid(instance_xray);173RS::get_singleton()->free_rid(instance_xray_ofs);174}175}176};177HashMap<ObjectID, Ref<SelectionBox3D>> selected_3d_nodes;178179Color sbox_3d_color;180Ref<ArrayMesh> sbox_3d_mesh;181Ref<ArrayMesh> sbox_3d_mesh_xray;182RID sbox_3d;183RID sbox_3d_ofs;184RID sbox_3d_xray;185RID sbox_3d_xray_ofs;186#endif // _3D_DISABLED187188void _setup(const Dictionary &p_settings);189190void _node_set_type(NodeType p_type);191void _select_set_mode(SelectMode p_mode);192193void _set_camera_override_enabled(bool p_enabled);194195void _root_window_input(const Ref<InputEvent> &p_event);196void _items_popup_index_pressed(int p_index, PopupMenu *p_popup);197void _update_input_state();198199void _process_frame();200void _physics_frame();201202void _send_ids(const Vector<Node *> &p_picked_nodes, bool p_invert_new_selections = true);203void _set_selected_nodes(const Vector<Node *> &p_nodes);204void _queue_selection_update();205void _update_selection();206void _clear_selection();207void _update_selection_drag(const Point2 &p_end_pos = Point2());208void _set_selection_visible(bool p_visible);209void _set_avoid_locked(bool p_enabled);210void _set_prefer_group(bool p_enabled);211212void _open_selection_list(const Vector<SelectResult> &p_items, const Point2 &p_pos);213void _close_selection_list();214215void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<SelectResult> &r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());216void _find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_node, Vector<SelectResult> &r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());217void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);218void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);219void _reset_camera_2d();220void _update_view_2d();221222#ifndef _3D_DISABLED223void _find_3d_items_at_pos(const Point2 &p_pos, Vector<SelectResult> &r_items);224void _find_3d_items_at_rect(const Rect2 &p_rect, Vector<SelectResult> &r_items);225Vector3 _get_screen_to_space(const Vector3 &p_vector3);226227bool _handle_3d_input(const Ref<InputEvent> &p_event);228void _set_camera_freelook_enabled(bool p_enabled);229void _cursor_scale_distance(real_t p_scale);230void _scale_freelook_speed(real_t p_scale);231void _cursor_look(Ref<InputEventWithModifiers> p_event);232void _cursor_pan(Ref<InputEventWithModifiers> p_event);233void _cursor_orbit(Ref<InputEventWithModifiers> p_event);234Point2 _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_event, Rect2 p_border) const;235Transform3D _get_cursor_transform();236void _reset_camera_3d();237#endif // _3D_DISABLED238239RuntimeNodeSelect() { singleton = this; }240241inline static RuntimeNodeSelect *singleton = nullptr;242243public:244static RuntimeNodeSelect *get_singleton();245246~RuntimeNodeSelect();247};248#endif // DEBUG_ENABLED249250251