| 4640 | }); |
| 4641 | } |
| 4642 | void reshade::runtime::draw_code_editor(editor_instance &instance) |
| 4643 | { |
| 4644 | if (!instance.generated && |
| 4645 | (ImGui::Button(ICON_FK_FLOPPY " " + _("Save"), ImVec2(ImGui::GetContentRegionAvail().x, 0)) || |
| 4646 | (_input != nullptr && _input->is_key_pressed('S', true, false, false)))) |
| 4647 | { |
| 4648 | // Write current editor text to file |
| 4649 | if (FILE *const file = _wfsopen(instance.file_path.c_str(), L"wb", SH_DENYWR)) |
| 4650 | { |
| 4651 | const std::string text = instance.editor.get_text(); |
| 4652 | fwrite(text.data(), 1, text.size(), file); |
| 4653 | fclose(file); |
| 4654 | } |
| 4655 | |
| 4656 | if (!is_loading() && instance.effect_index < _effects.size()) |
| 4657 | { |
| 4658 | // Clear modified flag, so that errors are updated next frame (see 'update_effects') |
| 4659 | instance.editor.clear_modified(); |
| 4660 | |
| 4661 | reload_effect(instance.effect_index); |
| 4662 | |
| 4663 | // Reloading an effect file invalidates all textures, but the statistics window may already have drawn references to those, so need to reset it |
| 4664 | if (ImGuiWindow *const statistics_window = ImGui::FindWindowByName("###statistics")) |
| 4665 | statistics_window->DrawList->CmdBuffer.clear(); |
| 4666 | } |
| 4667 | } |
| 4668 | |
| 4669 | instance.editor.render("##editor", _editor_palette, false, _imgui_context->IO.Fonts->Fonts[_imgui_context->IO.Fonts->Fonts.Size - 1], _editor_font_size); |
| 4670 | |
| 4671 | // Disable keyboard shortcuts when the window is focused so they don't get triggered while editing text |
| 4672 | const bool is_focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows); |
| 4673 | _ignore_shortcuts |= is_focused; |
| 4674 | |
| 4675 | // Disable keyboard navigation starting with next frame when editor is focused so that the Alt key can be used without it switching focus to the menu bar |
| 4676 | if (is_focused) |
| 4677 | _imgui_context->IO.ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard; |
| 4678 | else // Enable navigation again if focus is lost |
| 4679 | _imgui_context->IO.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; |
| 4680 | } |
| 4681 | |
| 4682 | bool reshade::runtime::init_imgui_resources() |
| 4683 | { |
nothing calls this directly
no test coverage detected