Skip to content

Commit

Permalink
draw the dimming overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
rraallvv committed Mar 10, 2018
1 parent eceba5a commit 4015212
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
35 changes: 28 additions & 7 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4572,26 +4572,37 @@ void EditorNode::_start_dimming(bool p_dimming) {
_dimming = p_dimming;
_dim_time = 0.0f;
_dim_timer->start();
if (_dimming) {
dim_overlay->set_visible(true);
}
}

void EditorNode::_dim_timeout() {

_dim_time += _dim_timer->get_wait_time();
float wait_time = EditorSettings::get_singleton()->get("interface/editor/dim_transition_time");

float c = 1.0f - (float)EditorSettings::get_singleton()->get("interface/editor/dim_amount");
float wait_time = _dimming ? (float)EditorSettings::get_singleton()->get("interface/editor/dim_transition_time") : 0;

Color base = _dimming ? Color(1, 1, 1) : Color(c, c, c);
Color final = _dimming ? Color(c, c, c) : Color(1, 1, 1);
Color base = _dimming ? Color(1, 1, 1, 0) : Color(1, 1, 1, 1);
Color final = _dimming ? Color(1, 1, 1, 1) : Color(1, 1, 1, 0);

if (_dim_time + _dim_timer->get_wait_time() >= wait_time) {
gui_base->set_modulate(final);
dim_overlay->set_modulate(final);
_dim_timer->stop();
if (!_dimming) {
dim_overlay->set_visible(false);
}
} else {
gui_base->set_modulate(base.linear_interpolate(final, _dim_time / wait_time));
dim_overlay->set_modulate(base.linear_interpolate(final, _dim_time / wait_time));
}
}

void EditorNode::_dim_draw() {
Size2 s = dim_overlay->get_size();
Rect2 r(0, 0, s.width, s.height);
Color c = EditorSettings::get_singleton()->get("interface/theme/dim_color");
dim_overlay->draw_rect(r, c);
}

void EditorNode::open_export_template_manager() {

export_template_manager->popup_manager();
Expand Down Expand Up @@ -4660,6 +4671,8 @@ void EditorNode::_bind_methods() {
ClassDB::bind_method("_dock_move_left", &EditorNode::_dock_move_left);
ClassDB::bind_method("_dock_move_right", &EditorNode::_dock_move_right);

ClassDB::bind_method("_dim_draw", &EditorNode::_dim_draw);

ClassDB::bind_method("_layout_menu_option", &EditorNode::_layout_menu_option);

ClassDB::bind_method("set_current_scene", &EditorNode::set_current_scene);
Expand Down Expand Up @@ -4863,6 +4876,14 @@ EditorNode::EditorNode() {
theme_base->add_child(gui_base);
gui_base->set_anchors_and_margins_preset(Control::PRESET_WIDE);

dim_overlay = memnew(Control);
dim_overlay->set_modulate(Color(0, 0, 0, 0));
dim_overlay->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
dim_overlay->set_anchors_and_margins_preset(Control::PRESET_WIDE);
dim_overlay->set_visible(false);
dim_overlay->connect("draw", this, "_dim_draw");
theme_base->add_child(dim_overlay);

Ref<Theme> theme = create_custom_theme();
theme_base->set_theme(theme);
gui_base->set_theme(theme);
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class EditorNode : public Node {
PanelContainer *scene_root_parent;
Control *theme_base;
Control *gui_base;
Control *dim_overlay;
VBoxContainer *main_vbox;
PanelContainer *play_button_panel;

Expand Down Expand Up @@ -555,6 +556,7 @@ class EditorNode : public Node {
void _reposition_active_tab(int idx_to);
void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
void _scene_tab_script_edited(int p_tab);
void _dim_draw();

Dictionary _get_main_scene_state();
void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("interface/editor/code_font", "");
hints["interface/editor/code_font"] = PropertyInfo(Variant::STRING, "interface/editor/code_font", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
_initial_set("interface/editor/dim_editor_on_dialog_popup", true);
_initial_set("interface/editor/dim_amount", 0.6f);
hints["interface/editor/dim_amount"] = PropertyInfo(Variant::REAL, "interface/editor/dim_amount", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT);
_initial_set("interface/editor/dim_transition_time", 0.08f);
hints["interface/editor/dim_transition_time"] = PropertyInfo(Variant::REAL, "interface/editor/dim_transition_time", PROPERTY_HINT_RANGE, "0,1,0.001", PROPERTY_USAGE_DEFAULT);

Expand All @@ -313,6 +311,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
hints["interface/theme/accent_color"] = PropertyInfo(Variant::COLOR, "interface/theme/accent_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
_initial_set("interface/theme/accent_color", Color::html("#699ce8"));
hints["interface/theme/base_color"] = PropertyInfo(Variant::COLOR, "interface/theme/base_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
_initial_set("interface/theme/dim_color", Color::html("#a0404040"));
hints["interface/theme/dim_color"] = PropertyInfo(Variant::COLOR, "interface/theme/dim_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
_initial_set("interface/theme/contrast", 0.25);
hints["interface/theme/contrast"] = PropertyInfo(Variant::REAL, "interface/theme/contrast", PROPERTY_HINT_RANGE, "0.01, 1, 0.01");
_initial_set("interface/theme/highlight_tabs", false);
Expand Down

0 comments on commit 4015212

Please sign in to comment.