Skip to content

Commit

Permalink
Merge pull request #19614 from hrydgard/imgui-fixes
Browse files Browse the repository at this point in the history
More minor ImGui fixes
  • Loading branch information
hrydgard authored Nov 7, 2024
2 parents da9bfa6 + 80474fd commit da0168f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Core/MIPS/MIPSDebugInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ void MIPSDebugInterface::toggleBreakpoint(unsigned int address)


int MIPSDebugInterface::getColor(unsigned int address, bool darkMode) const {
int colors[6] = { 0xe0FFFF, 0xFFe0e0, 0xe8e8FF, 0xFFe0FF, 0xe0FFe0, 0xFFFFe0 };
int colorsDark[6] = { ~0xe0FFFF, ~0xFFe0e0, ~0xe8e8FF, ~0xFFe0FF, ~0xe0FFe0, ~0xFFFFe0 };
uint32_t colors[6] = { 0xFFe0FFFF, 0xFFFFe0e0, 0xFFe8e8FF, 0xFFFFe0FF, 0xFFe0FFe0, 0xFFFFFFe0 };
uint32_t colorsDark[6] = { 0xFF301010, 0xFF103030, 0xFF403010, 0xFF103000, 0xFF301030, 0xFF101030 };

int n = g_symbolMap->GetFunctionNum(address);
if (n == -1) {
Expand Down
5 changes: 5 additions & 0 deletions Core/MIPS/MIPSStackWalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ namespace MIPSStackWalk {

std::vector<StackFrame> Walk(u32 pc, u32 ra, u32 sp, u32 threadEntry, u32 threadStackTop) {
std::vector<StackFrame> frames;

if (!Memory::IsValidAddress(pc) || !Memory::IsValidAddress(sp) || !Memory::IsValidAddress(ra)) {
return frames;
}

StackFrame current;
current.pc = pc;
current.sp = sp;
Expand Down
4 changes: 2 additions & 2 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) {
if (UI::IsFocusMovementEnabled() || (imguiVisible_ && imguiInited_)) {
// Note: Allow some Vkeys through, so we can toggle the imgui for example (since we actually block the control mapper otherwise in imgui mode).
// We need to manually implement it here :/
if (imguiVisible_ && imguiInited_) {
if (imguiVisible_ && imguiInited_ && (key.flags & (KEY_UP | KEY_DOWN))) {
InputMapping mapping(key.deviceId, key.keyCode);
std::vector<int> pspButtons;
bool mappingFound = KeyMap::InputMappingToPspButton(mapping, &pspButtons);
Expand Down Expand Up @@ -1643,7 +1643,7 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
ImGui_ImplThin3d_Init(draw);
}

if (imguiVisible_ && imguiInited_) {
if (imguiVisible_ && imguiInited_ && PSP_IsInited()) {
_dbg_assert_(imDebugger_);

ImGui_ImplPlatform_NewFrame();
Expand Down
13 changes: 6 additions & 7 deletions UI/ImDebugger/ImDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void DrawRegisterView(MIPSDebugInterface *mipsDebug, bool *open) {

ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("FPR")) {
if (ImGui::BeginTabItem("FPU")) {
if (ImGui::BeginTable("fpr", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersH)) {
ImGui::TableSetupColumn("regname", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthFixed);
Expand All @@ -79,7 +79,7 @@ void DrawRegisterView(MIPSDebugInterface *mipsDebug, bool *open) {
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("VPR")) {
if (ImGui::BeginTabItem("VFPU")) {
ImGui::Text("TODO");
ImGui::EndTabItem();
}
Expand All @@ -93,10 +93,10 @@ static const char *ThreadStatusToString(u32 status) {
case THREADSTATUS_RUNNING: return "Running";
case THREADSTATUS_READY: return "Ready";
case THREADSTATUS_WAIT: return "Wait";
case THREADSTATUS_SUSPEND: return "Suspend";
case THREADSTATUS_SUSPEND: return "Suspended";
case THREADSTATUS_DORMANT: return "Dormant";
case THREADSTATUS_DEAD: return "Dead";
case THREADSTATUS_WAITSUSPEND: return "WaitSuspend";
case THREADSTATUS_WAITSUSPEND: return "WaitSuspended";
default:
break;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ void DrawCallStacks(MIPSDebugInterface *debug, bool *open) {
}

void DrawModules(MIPSDebugInterface *debug, bool *open) {
if (!ImGui::Begin("Modules", open)) {
if (!ImGui::Begin("Modules", open) || !g_symbolMap) {
ImGui::End();
return;
}
Expand Down Expand Up @@ -379,12 +379,11 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, bool *open, CoreState c
while (clipper.Step()) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
if (ImGui::Selectable(symCache_[i].name.c_str(), false)) {
disasmView_.setCurAddress(symCache_[i].address);
disasmView_.gotoAddr(symCache_[i].address);
disasmView_.scrollAddressIntoView();
}
}
}

clipper.End();
ImGui::EndListBox();
}
Expand Down
23 changes: 13 additions & 10 deletions UI/ImDebugger/ImDisasmView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ void ImDisasmView::Draw(ImDrawList *drawList) {
ImColor textColor = 0xFFFFFFFF;

if (isInInterval(address, line.totalSize, debugger->getPC())) {
backgroundColor = scaleColor(backgroundColor, 1.15f);
backgroundColor = scaleColor(backgroundColor, 1.3f);
}

if (address >= selectRangeStart_ && address < selectRangeEnd_ && searching_ == false) {
if (hasFocus_) {
backgroundColor = ImColor(address == curAddress_ ? 0xFFFF8822 : 0xFFFF9933);
textColor = ImColor(0xFF000000);
} else {
backgroundColor = ImColor(0xFFC0C0C0);
backgroundColor = ImColor(0xFF606060);
}
}

Expand All @@ -404,10 +404,12 @@ void ImDisasmView::Draw(ImDrawList *drawList) {
drawList->AddText(ImVec2(rect.left + pixelPositions_.addressStart, rect.top + rowY1 + 2), textColor, addressText);

if (isInInterval(address, line.totalSize, debugger->getPC())) {
// Show the current PC with a little square.
drawList->AddRectFilled(
ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - rowHeight_, canvas_p0.y + rowY1 + 2),
ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - 4, canvas_p0.y + rowY1 + rowHeight_ - 2), 0xFFFFFFFF);
// Show the current PC with a little triangle.
drawList->AddTriangleFilled(
ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - rowHeight_ * 0.7f, canvas_p0.y + rowY1 + 2),
ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - rowHeight_ * 0.7f, canvas_p0.y + rowY1 + rowHeight_ - 2),
ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - 4, canvas_p0.y + rowY1 + rowHeight_ * 0.5f),
0xFFFFFFFF);
}

// display whether the condition of a branch is met
Expand Down Expand Up @@ -498,7 +500,8 @@ void ImDisasmView::ScrollRelative(int amount) {
ScanVisibleFunctions();
}

void ImDisasmView::followBranch() {
// Follows branches and jumps.
void ImDisasmView::FollowBranch() {
DisassemblyLineInfo line;
manager.getLine(curAddress_, true, line);

Expand All @@ -507,7 +510,7 @@ void ImDisasmView::followBranch() {
jumpStack_.push_back(curAddress_);
gotoAddr(line.info.branchTarget);
} else if (line.info.hasRelevantAddress) {
// well, not exactly a branch, but we can do something anyway
// well, not exactly a branch, but we can do something anyway
// SendMessage(GetParent(wnd), WM_DEB_GOTOHEXEDIT, line.info.relevantAddress, 0);
// SetFocus(wnd);
}
Expand Down Expand Up @@ -644,7 +647,7 @@ void ImDisasmView::onKeyDown(ImGuiKey key) {
}
return;
case VK_RIGHT:
followBranch();
FollowBranch();
return;
case VK_TAB:
displaySymbols_ = !displaySymbols_;
Expand Down Expand Up @@ -797,7 +800,7 @@ void ImDisasmView::PopupMenu() {
debugger->setPC(curAddress_);
}
if (ImGui::MenuItem("Follow branch")) {
followBranch();
FollowBranch();
}
if (ImGui::MenuItem("Run to here")) {
// CBreakPoints::AddBreakPoint(pos, true);
Expand Down
2 changes: 1 addition & 1 deletion UI/ImDebugger/ImDisasmView.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ImDisasmView {
std::string disassembleRange(u32 start, u32 size);
void disassembleToFile();
void search(bool continueSearch);
void followBranch();
void FollowBranch();
void calculatePixelPositions();
bool getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels, bool showData);
void updateStatusBarText();
Expand Down
13 changes: 9 additions & 4 deletions ext/imgui/imgui_impl_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,26 @@ void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) {
default:
{
ImGuiKey keyCode = KeyCodeToImGui(key.keyCode);
if (keyCode == ImGuiKey_None) {
WARN_LOG(Log::System, "Unmapped ImGui keycode conversion from %d", key.keyCode);
} else {
if (keyCode != ImGuiKey_None) {
io.AddKeyEvent(keyCode, true);
} else {
WARN_LOG(Log::System, "KeyDown: Unmapped ImGui keycode conversion from %d", key.keyCode);
}
break;
}
}
}
if (key.flags & KEY_UP) {
ImGuiKey keyCode = KeyCodeToImGui(key.keyCode);
io.AddKeyEvent(keyCode, false);
if (keyCode != ImGuiKey_None) {
io.AddKeyEvent(keyCode, false);
} else {
WARN_LOG(Log::System, "KeyUp: Unmapped ImGui keycode conversion from %d", key.keyCode);
}
}
if (key.flags & KEY_CHAR) {
const int unichar = key.unicodeChar;

if (unichar >= 0x20) {
// Insert it! (todo: do it with a string insert)
char buf[16];
Expand Down

0 comments on commit da0168f

Please sign in to comment.