Skip to content

Commit

Permalink
Merge pull request #19729 from hrydgard/imgui-improvements
Browse files Browse the repository at this point in the history
ImGui improvements
  • Loading branch information
hrydgard authored Dec 13, 2024
2 parents 79c0f41 + 374c2e1 commit 0b4ca63
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Core/HLE/proAdhocServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ void spread_message(SceNetAdhocctlUserNode *user, const char *message)
}

// Chat Packet
SceNetAdhocctlChatPacketS2C packet;
SceNetAdhocctlChatPacketS2C packet{};

// Set Chat Opcode
packet.base.base.opcode = OPCODE_CHAT;
Expand Down
46 changes: 29 additions & 17 deletions UI/ImDebugger/ImDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ void ShowInWindowMenuItems(uint32_t addr, ImControl &control) {
}
}

void StatusBar(std::string_view status) {
ImGui::TextUnformatted(status.data(), status.data() + status.length());
ImGui::SameLine();
if (ImGui::SmallButton("Copy")) {
System_CopyStringToClipboard(status);
}
}

// TODO: Style it.
// Left click performs the preferred action, if any. Right click opens a menu for more.
void ImClickableAddress(uint32_t addr, ImControl &control, ImCmd cmd) {
Expand Down Expand Up @@ -1170,8 +1178,10 @@ void ImMemWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImControl &
memView_.gotoAddr(gotoAddr_);
}

ImVec2 size(0, -ImGui::GetFrameHeightWithSpacing());

// Main views - list of interesting addresses to the left, memory view to the right.
if (ImGui::BeginChild("addr_list", ImVec2(200.0f, 0.0))) {
if (ImGui::BeginChild("addr_list", ImVec2(200.0f, size.y), ImGuiChildFlags_ResizeX)) {
if (ImGui::Selectable("Scratch")) {
GotoAddr(0x00010000);
}
Expand All @@ -1182,18 +1192,19 @@ void ImMemWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImControl &
GotoAddr(0x08800000);
}
if (ImGui::Selectable("VRAM")) {
GotoAddr(0x08800000);
GotoAddr(0x04000000);
}
}
ImGui::EndChild();

ImGui::SameLine();
if (ImGui::BeginChild("memview", ImVec2(0, -ImGui::GetFrameHeightWithSpacing()))) {
if (ImGui::BeginChild("memview", size)) {
memView_.Draw(ImGui::GetWindowDrawList());
}
ImGui::EndChild();

ImGui::TextUnformatted(memView_.StatusMessage().c_str());
StatusBar(memView_.StatusMessage());

ImGui::End();
}

Expand All @@ -1206,7 +1217,7 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImContro
disasmView_.setDebugger(mipsDebug);

ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
if (!ImGui::Begin(Title(), &cfg.disasmOpen, ImGuiWindowFlags_NoNavInputs)) {
if (!ImGui::Begin(Title(), &cfg.disasmOpen)) {
ImGui::End();
return;
}
Expand Down Expand Up @@ -1273,10 +1284,11 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImContro
Core_RequestCPUStep(CPUStepType::Out, 0);
}

/*
ImGui::SameLine();
if (ImGui::SmallButton("Frame")) {
Core_RequestCPUStep(CPUStepType::Frame, 0);
}
}*/

ImGui::SameLine();
if (ImGui::SmallButton("Syscall")) {
Expand Down Expand Up @@ -1346,12 +1358,10 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImContro
disasmView_.scrollAddressIntoView();
}

if (ImGui::BeginTable("main", 2)) {
ImGui::TableSetupColumn("left", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("right", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImVec2 avail = ImGui::GetContentRegionAvail();
avail.y -= ImGui::GetTextLineHeightWithSpacing();

if (ImGui::BeginChild("left", ImVec2(150.0f, avail.y), ImGuiChildFlags_ResizeX)) {
if (symCache_.empty() || symsDirty_) {
symCache_ = g_symbolMap->GetAllSymbols(SymbolType::ST_FUNCTION);
symsDirty_ = false;
Expand All @@ -1369,8 +1379,7 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImContro
}
}

ImVec2 sz = ImGui::GetContentRegionAvail();
if (ImGui::BeginListBox("##symbols", ImVec2(150.0, sz.y - ImGui::GetTextLineHeightWithSpacing() * 2))) {
if (ImGui::BeginListBox("##symbols", ImGui::GetContentRegionAvail())) {
ImGuiListClipper clipper;
clipper.Begin((int)symCache_.size(), -1);
while (clipper.Step()) {
Expand All @@ -1386,13 +1395,16 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImContro
clipper.End();
ImGui::EndListBox();
}
}
ImGui::EndChild();

ImGui::TableSetColumnIndex(1);
ImGui::SameLine();
if (ImGui::BeginChild("right", ImVec2(0.0f, avail.y))) {
disasmView_.Draw(ImGui::GetWindowDrawList(), control);
ImGui::EndTable();

ImGui::TextUnformatted(disasmView_.StatusBarText().c_str());
}
ImGui::EndChild();

StatusBar(disasmView_.StatusBarText());
ImGui::End();
}

Expand Down
3 changes: 3 additions & 0 deletions UI/ImDebugger/ImDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class ImMemWindow {
symsDirty_ = true;
}
void GotoAddr(u32 addr) {
gotoAddr_ = addr;
memView_.gotoAddr(addr);
}
static const char *Title(int index);
Expand Down Expand Up @@ -122,6 +123,7 @@ struct ImConfig {
bool geDebuggerOpen;
bool geStateOpen;
bool schedulerOpen;
bool watchOpen;
bool memViewOpen[4];

// HLE explorer settings
Expand Down Expand Up @@ -195,3 +197,4 @@ class ImDebugger {
void ImClickableAddress(uint32_t addr, ImControl &control, ImCmd cmd);
void ShowInWindowMenuItems(uint32_t addr, ImControl &control);
void ShowInMemoryViewerMenuItem(uint32_t addr, ImControl &control);
void StatusBar(std::string_view str);
6 changes: 1 addition & 5 deletions UI/ImDebugger/ImDisasmView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ void ImDisasmView::Draw(ImDrawList *drawList, ImControl &control) {

ImVec2 canvas_p0 = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
ImVec2 canvas_sz = ImGui::GetContentRegionAvail(); // Resize canvas to what's available
if (canvas_sz.x < 50.0f) canvas_sz.x = 50.0f;
if (canvas_sz.y < 50.0f) canvas_sz.y = 50.0f;
canvas_sz.y -= rowHeight_ * 2.0f; // space for status bar
const ImVec2 canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);

// This will catch our interactions
bool pressed = ImGui::InvisibleButton("canvas", canvas_sz, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
Expand All @@ -323,8 +321,6 @@ void ImDisasmView::Draw(ImDrawList *drawList, ImControl &control) {
}
ImGui::SetItemKeyOwner(ImGuiKey_MouseWheelY);

const ImVec2 canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);

drawList->PushClipRect(canvas_p0, canvas_p1, true);
drawList->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(25, 25, 25, 255));
if (is_active) {
Expand Down
34 changes: 18 additions & 16 deletions UI/ImDebugger/ImGe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,23 +426,25 @@ void ImGeDebuggerWindow::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterfa

ImGui::BeginChild("left pane", ImVec2(400, 0), ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeX);

for (auto index : gpuDebug->GetDisplayListQueue()) {
const auto &list = gpuDebug->GetDisplayList(index);
char title[64];
snprintf(title, sizeof(title), "List %d", list.id);
if (ImGui::CollapsingHeader(title)) {
ImGui::Text("State: %s", DLStateToString(list.state));
ImGui::TextUnformatted("PC:");
ImGui::SameLine();
ImClickableAddress(list.pc, control, ImCmd::SHOW_IN_GE_DISASM);
ImGui::Text("StartPC:");
ImGui::SameLine();
ImClickableAddress(list.startpc, control, ImCmd::SHOW_IN_GE_DISASM);
if (list.pendingInterrupt) {
ImGui::TextUnformatted("(Pending interrupt)");
if (ImGui::CollapsingHeader("Display lists")) {
for (auto index : gpuDebug->GetDisplayListQueue()) {
const auto &list = gpuDebug->GetDisplayList(index);
char title[64];
snprintf(title, sizeof(title), "List %d", list.id);
if (ImGui::CollapsingHeader(title)) {
ImGui::Text("State: %s", DLStateToString(list.state));
ImGui::TextUnformatted("PC:");
ImGui::SameLine();
ImClickableAddress(list.pc, control, ImCmd::SHOW_IN_GE_DISASM);
ImGui::Text("StartPC:");
ImGui::SameLine();
ImClickableAddress(list.startpc, control, ImCmd::SHOW_IN_GE_DISASM);
if (list.pendingInterrupt) {
ImGui::TextUnformatted("(Pending interrupt)");
}
ImGui::Text("Stack depth: %d", (int)list.stackptr);
ImGui::Text("BBOX result: %d", (int)list.bboxResult);
}
ImGui::Text("Stack depth: %d", (int)list.stackptr);
ImGui::Text("BBOX result: %d", (int)list.bboxResult);
}
}

Expand Down
23 changes: 7 additions & 16 deletions UI/ImDebugger/ImMemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ ImMemView::ImMemView() {

ImMemView::~ImMemView() {}

/*
LRESULT CALLBACK ImMemView::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) {
ccp->ScrollWindow(-3, GotoModeFromModifiers(false));
} else if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) {
ccp->ScrollWindow(3, GotoModeFromModifiers(false));
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
*/

static uint32_t pickTagColor(std::string_view tag) {
uint32_t colors[6] = { 0xFF301010, 0xFF103030, 0xFF403010, 0xFF103000, 0xFF301030, 0xFF101030 };
int which = XXH3_64bits(tag.data(), tag.length()) % ARRAY_SIZE(colors);
Expand Down Expand Up @@ -107,7 +96,7 @@ void ImMemView::Draw(ImDrawList *drawList) {

char temp[32];
uint32_t address = windowStart_ + i * rowSize_;
snprintf(temp, sizeof(temp), "%08X", address);
snprintf(temp, sizeof(temp), "%08x", address);
drawList->AddText(ImVec2(canvas_p0.x + addressStartX_, canvas_p0.y + rowY), IM_COL32(0xE0, 0xE0, 0xE0, 0xFF), temp);

union {
Expand Down Expand Up @@ -136,7 +125,7 @@ void ImMemView::Draw(ImDrawList *drawList) {

char c;
if (valid) {
snprintf(temp, sizeof(temp), "%02X ", memory.bytes[j]);
snprintf(temp, sizeof(temp), "%02x ", memory.bytes[j]);
c = (char)memory.bytes[j];
if (memory.bytes[j] < 32 || memory.bytes[j] >= 128)
c = '.';
Expand Down Expand Up @@ -188,16 +177,18 @@ void ImMemView::Draw(ImDrawList *drawList) {
if (bg != 0) {
int bgWidth = 2; // continueRect ? 3 : 2;
drawList->AddRectFilled(ImVec2(canvas_p0.x + hexX - 1, canvas_p0.y + rowY), ImVec2(canvas_p0.x + hexX + charWidth_ * bgWidth, canvas_p0.y + rowY + charHeight_), bg);
drawList->AddText(ImVec2(canvas_p0.x + hexX, canvas_p0.y + rowY), fg, &temp[0], &temp[2]);
}
drawList->AddText(ImVec2(canvas_p0.x + hexX, canvas_p0.y + rowY), fg, &temp[0], &temp[2]);
if (underline >= 0) {
float x = canvas_p0.x + hexX + underline * charWidth_;
drawList->AddRectFilled(ImVec2(x, canvas_p0.y + rowY + charHeight_ - 2), ImVec2(x + charWidth_, canvas_p0.y + rowY + charHeight_), IM_COL32(0xFF, 0xFF, 0xFF, 0xFF));
}

fg = asciiTextCol;
bg = asciiBGCol;
drawList->AddRectFilled(ImVec2(canvas_p0.x + asciiX, canvas_p0.y + rowY), ImVec2(canvas_p0.x + asciiX + charWidth_, canvas_p0.y + rowY + charHeight_), bg);
if (bg) {
drawList->AddRectFilled(ImVec2(canvas_p0.x + asciiX, canvas_p0.y + rowY), ImVec2(canvas_p0.x + asciiX + charWidth_, canvas_p0.y + rowY + charHeight_), bg);
}
drawList->AddText(ImVec2(canvas_p0.x + asciiX, canvas_p0.y + rowY), fg, &c, &c + 1);
}
}
Expand Down Expand Up @@ -533,7 +524,7 @@ void ImMemView::updateStatusBarText() {
snprintf(text, sizeof(text), "%08x", curAddress_);
// There should only be one.
for (MemBlockInfo info : memRangeInfo) {
snprintf(text, sizeof(text), "%08x - %s %08x-%08x (alloc'd at PC %08x / %lld ticks)", curAddress_, info.tag.c_str(), info.start, info.start + info.size, info.pc, info.ticks);
snprintf(text, sizeof(text), "%08x - %s %08x-%08x (PC %08x / %lld ticks)", curAddress_, info.tag.c_str(), info.start, info.start + info.size, info.pc, info.ticks);
}
statusMessage_ = text;
}
Expand Down
26 changes: 26 additions & 0 deletions Windows/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "Common/Input/KeyCodes.h"
#include "Common/Thread/ThreadUtil.h"
#include "Common/Data/Encoding/Utf8.h"
#include "ext/imgui/imgui_impl_platform.h"

#include "Core/Core.h"
#include "Core/Config.h"
Expand Down Expand Up @@ -611,6 +612,31 @@ namespace MainWindow
case WM_SETFOCUS:
break;

case WM_SETCURSOR:
if ((lParam & 0xFFFF) == HTCLIENT && g_Config.bShowImDebugger) {
LPTSTR win32_cursor = 0;
switch (ImGui_ImplPlatform_GetCursor()) {
case ImGuiMouseCursor_Arrow: win32_cursor = IDC_ARROW; break;
case ImGuiMouseCursor_TextInput: win32_cursor = IDC_IBEAM; break;
case ImGuiMouseCursor_ResizeAll: win32_cursor = IDC_SIZEALL; break;
case ImGuiMouseCursor_ResizeEW: win32_cursor = IDC_SIZEWE; break;
case ImGuiMouseCursor_ResizeNS: win32_cursor = IDC_SIZENS; break;
case ImGuiMouseCursor_ResizeNESW: win32_cursor = IDC_SIZENESW; break;
case ImGuiMouseCursor_ResizeNWSE: win32_cursor = IDC_SIZENWSE; break;
case ImGuiMouseCursor_Hand: win32_cursor = IDC_HAND; break;
case ImGuiMouseCursor_NotAllowed: win32_cursor = IDC_NO; break;
}
if (win32_cursor) {
SetCursor(::LoadCursor(nullptr, win32_cursor));
} else {
SetCursor(nullptr);
}
return TRUE;
} else {
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;

case WM_ERASEBKGND:
if (firstErase) {
firstErase = false;
Expand Down
7 changes: 7 additions & 0 deletions ext/imgui/imgui_impl_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "imgui_impl_platform.h"

static ImGuiMouseCursor g_cursor = ImGuiMouseCursor_Arrow;

void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) {
ImGuiIO &io = ImGui::GetIO();

Expand Down Expand Up @@ -94,6 +96,7 @@ void ImGui_ImplPlatform_NewFrame() {

double now = time_now_d();

g_cursor = ImGui::GetMouseCursor();
ImGuiIO &io = ImGui::GetIO();
io.DisplaySize = ImVec2(g_display.pixel_xres, g_display.pixel_yres);
io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
Expand All @@ -102,6 +105,10 @@ void ImGui_ImplPlatform_NewFrame() {
lastTime = now;
}

ImGuiMouseCursor ImGui_ImplPlatform_GetCursor() {
return g_cursor;
}

// Written by chatgpt
ImGuiKey KeyCodeToImGui(InputKeyCode keyCode) {
switch (keyCode) {
Expand Down
2 changes: 2 additions & 0 deletions ext/imgui/imgui_impl_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ void ImGui_ImplPlatform_NewFrame();
void ImGui_ImplPlatform_KeyEvent(const KeyInput &key);
void ImGui_ImplPlatform_TouchEvent(const TouchInput &touch);
void ImGui_ImplPlatform_AxisEvent(const AxisInput &axis);

ImGuiMouseCursor ImGui_ImplPlatform_GetCursor();

0 comments on commit 0b4ca63

Please sign in to comment.