Add "Show Origin" and "Show Viewport" options to 2D Editor Viewport

(cherry picked from commit 934498d37a)
This commit is contained in:
Blazej Floch 2018-03-02 03:52:13 -05:00 committed by Hein-Pieter van Braam
parent 9cbcff4e91
commit 2c93def09d
2 changed files with 61 additions and 17 deletions

View File

@ -433,7 +433,6 @@ Dictionary CanvasItemEditor::get_state() const {
Dictionary state; Dictionary state;
state["zoom"] = zoom; state["zoom"] = zoom;
state["ofs"] = Point2(h_scroll->get_value(), v_scroll->get_value()); state["ofs"] = Point2(h_scroll->get_value(), v_scroll->get_value());
//state["ofs"]=-transform.get_origin();
state["grid_offset"] = grid_offset; state["grid_offset"] = grid_offset;
state["grid_step"] = grid_step; state["grid_step"] = grid_step;
state["snap_rotation_offset"] = snap_rotation_offset; state["snap_rotation_offset"] = snap_rotation_offset;
@ -446,6 +445,8 @@ Dictionary CanvasItemEditor::get_state() const {
state["snap_grid"] = snap_grid; state["snap_grid"] = snap_grid;
state["snap_guides"] = snap_guides; state["snap_guides"] = snap_guides;
state["show_grid"] = show_grid; state["show_grid"] = show_grid;
state["show_origin"] = show_origin;
state["show_viewport"] = show_viewport;
state["show_rulers"] = show_rulers; state["show_rulers"] = show_rulers;
state["show_guides"] = show_guides; state["show_guides"] = show_guides;
state["show_helpers"] = show_helpers; state["show_helpers"] = show_helpers;
@ -455,6 +456,7 @@ Dictionary CanvasItemEditor::get_state() const {
state["skeleton_show_bones"] = skeleton_show_bones; state["skeleton_show_bones"] = skeleton_show_bones;
return state; return state;
} }
void CanvasItemEditor::set_state(const Dictionary &p_state) { void CanvasItemEditor::set_state(const Dictionary &p_state) {
Dictionary state = p_state; Dictionary state = p_state;
@ -532,6 +534,18 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) {
view_menu->get_popup()->set_item_checked(idx, show_grid); view_menu->get_popup()->set_item_checked(idx, show_grid);
} }
if (state.has("show_origin")) {
show_origin = state["show_origin"];
int idx = view_menu->get_popup()->get_item_index(SHOW_ORIGIN);
view_menu->get_popup()->set_item_checked(idx, show_origin);
}
if (state.has("show_viewport")) {
show_viewport = state["show_viewport"];
int idx = view_menu->get_popup()->get_item_index(SHOW_VIEWPORT);
view_menu->get_popup()->set_item_checked(idx, show_viewport);
}
if (state.has("show_rulers")) { if (state.has("show_rulers")) {
show_rulers = state["show_rulers"]; show_rulers = state["show_rulers"];
int idx = view_menu->get_popup()->get_item_index(SHOW_RULERS); int idx = view_menu->get_popup()->get_item_index(SHOW_RULERS);
@ -2744,15 +2758,24 @@ void CanvasItemEditor::_draw_selection() {
} }
void CanvasItemEditor::_draw_axis() { void CanvasItemEditor::_draw_axis() {
if (show_origin) {
RID ci = viewport->get_canvas_item(); RID ci = viewport->get_canvas_item();
Point2 origin = transform.get_origin();
Color x_axis_color(1.0, 0.4, 0.4, 0.6); Color x_axis_color(1.0, 0.4, 0.4, 0.6);
Color y_axis_color(0.4, 1.0, 0.4, 0.6); Color y_axis_color(0.4, 1.0, 0.4, 0.6);
Color area_axis_color(0.4, 0.4, 1.0, 0.4);
Point2 origin = transform.get_origin();
VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(0, origin.y), Point2(viewport->get_size().x, origin.y), x_axis_color); VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(0, origin.y), Point2(viewport->get_size().x, origin.y), x_axis_color);
VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(origin.x, 0), Point2(origin.x, viewport->get_size().y), y_axis_color); VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(origin.x, 0), Point2(origin.x, viewport->get_size().y), y_axis_color);
}
if (show_viewport) {
RID ci = viewport->get_canvas_item();
Color area_axis_color(0.4, 0.4, 1.0, 0.4);
Size2 screen_size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")); Size2 screen_size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height"));
@ -2767,6 +2790,7 @@ void CanvasItemEditor::_draw_axis() {
VisualServer::get_singleton()->canvas_item_add_line(ci, screen_endpoints[i], screen_endpoints[(i + 1) % 4], area_axis_color); VisualServer::get_singleton()->canvas_item_add_line(ci, screen_endpoints[i], screen_endpoints[(i + 1) % 4], area_axis_color);
} }
} }
}
void CanvasItemEditor::_draw_bones() { void CanvasItemEditor::_draw_bones() {
RID ci = viewport->get_canvas_item(); RID ci = viewport->get_canvas_item();
@ -3384,6 +3408,18 @@ void CanvasItemEditor::_popup_callback(int p_op) {
viewport->update(); viewport->update();
viewport_base->update(); viewport_base->update();
} break; } break;
case SHOW_ORIGIN: {
show_origin = !show_origin;
int idx = view_menu->get_popup()->get_item_index(SHOW_ORIGIN);
view_menu->get_popup()->set_item_checked(idx, show_origin);
viewport->update();
} break;
case SHOW_VIEWPORT: {
show_viewport = !show_viewport;
int idx = view_menu->get_popup()->get_item_index(SHOW_VIEWPORT);
view_menu->get_popup()->set_item_checked(idx, show_viewport);
viewport->update();
} break;
case SNAP_USE_NODE_PARENT: { case SNAP_USE_NODE_PARENT: {
snap_node_parent = !snap_node_parent; snap_node_parent = !snap_node_parent;
int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_PARENT); int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_PARENT);
@ -4233,6 +4269,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_helpers", TTR("Show Helpers"), KEY_H), SHOW_HELPERS); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_helpers", TTR("Show Helpers"), KEY_H), SHOW_HELPERS);
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_rulers", TTR("Show Rulers"), KEY_R), SHOW_RULERS); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_rulers", TTR("Show Rulers"), KEY_R), SHOW_RULERS);
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_guides", TTR("Show Guides"), KEY_Y), SHOW_GUIDES); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_guides", TTR("Show Guides"), KEY_Y), SHOW_GUIDES);
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_origin", TTR("Show Origin")), SHOW_ORIGIN);
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_viewport", TTR("Show Viewport")), SHOW_VIEWPORT);
p->add_separator(); p->add_separator();
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION);
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_SHIFT | KEY_F), VIEW_FRAME_TO_SELECTION); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_SHIFT | KEY_F), VIEW_FRAME_TO_SELECTION);
@ -4324,6 +4362,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
edited_guide_index = -1; edited_guide_index = -1;
show_grid = false; show_grid = false;
show_origin = true;
show_viewport = true;
show_helpers = false; show_helpers = false;
show_rulers = true; show_rulers = true;
show_guides = true; show_guides = true;

View File

@ -97,6 +97,8 @@ class CanvasItemEditor : public VBoxContainer {
SHOW_HELPERS, SHOW_HELPERS,
SHOW_RULERS, SHOW_RULERS,
SHOW_GUIDES, SHOW_GUIDES,
SHOW_ORIGIN,
SHOW_VIEWPORT,
LOCK_SELECTED, LOCK_SELECTED,
UNLOCK_SELECTED, UNLOCK_SELECTED,
GROUP_SELECTED, GROUP_SELECTED,
@ -220,6 +222,8 @@ class CanvasItemEditor : public VBoxContainer {
bool show_grid; bool show_grid;
bool show_rulers; bool show_rulers;
bool show_guides; bool show_guides;
bool show_origin;
bool show_viewport;
bool show_helpers; bool show_helpers;
float zoom; float zoom;