| 536 | } |
| 537 | |
| 538 | void update() |
| 539 | { |
| 540 | DisplayInfo display; |
| 541 | TFE_RenderBackend::getDisplayInfo(&display); |
| 542 | const u32 w = display.width; |
| 543 | const u32 h = display.height; |
| 544 | const f32 dt = (f32)TFE_System::getDeltaTime(); |
| 545 | |
| 546 | if (s_anim != 0.0f) |
| 547 | { |
| 548 | s_height += s_anim * 3.0f * dt; |
| 549 | if (s_height <= 0.0f) |
| 550 | { |
| 551 | s_height = 0.0f; |
| 552 | s_anim = 0.0f; |
| 553 | } |
| 554 | else if (s_height >= 1.0f) |
| 555 | { |
| 556 | s_height = 1.0f; |
| 557 | s_anim = 0.0f; |
| 558 | } |
| 559 | } |
| 560 | if (s_height <= 0.0f) { return; } |
| 561 | |
| 562 | const f32 consoleHeight = floorf(s_height * c_maxConsoleHeight * f32(h)); |
| 563 | ImGui::PushFont(s_consoleFont); |
| 564 | ImGui::OpenPopup("console"); |
| 565 | ImGui::SetNextWindowSize(ImVec2(f32(w), consoleHeight)); |
| 566 | ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f)); |
| 567 | ImGui::SetWindowFocus("##InputField"); |
| 568 | if (ImGui::BeginPopup("console", ImGuiWindowFlags_NoScrollbar)) |
| 569 | { |
| 570 | if (TFE_Input::bufferedKeyDown(KEY_PAGEUP)) |
| 571 | { |
| 572 | s_historyScroll++; |
| 573 | } |
| 574 | else if (TFE_Input::bufferedKeyDown(KEY_PAGEDOWN)) |
| 575 | { |
| 576 | s_historyScroll--; |
| 577 | } |
| 578 | |
| 579 | const s32 count = (s32)s_history.size(); |
| 580 | const s32 elementsPerPage = ((s32)consoleHeight - 16 - s_fontSize) / s_fontSize; |
| 581 | s_historyScroll = std::max(0, std::min(s_historyScroll, count - elementsPerPage)); |
| 582 | s32 start = count - 1 - s_historyScroll; |
| 583 | |
| 584 | s32 y = (s32)consoleHeight - 16 - 2*s_fontSize; |
| 585 | for (s32 i = start; i >= 0 && y > -s_fontSize; i--, y -= s_fontSize) |
| 586 | { |
| 587 | ImGui::SetCursorPosY(f32(y)); |
| 588 | ImGui::TextColored(ImVec4(s_history[i].color.x, s_history[i].color.y, s_history[i].color.z, s_history[i].color.w), "%s", s_history[i].text.c_str()); |
| 589 | } |
| 590 | |
| 591 | ImGui::SetKeyboardFocusHere(); |
| 592 | ImGui::SetNextItemWidth(f32(w - 16)); |
| 593 | ImGui::SetCursorPosY(consoleHeight - 12.0f - s_fontSize); |
| 594 | u32 flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_NoHorizontalScroll | |
| 595 | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; |
nothing calls this directly
no test coverage detected