Skip to content

Commit 0d75149

Browse files
committed
[debugger] Improve Sprite viewer selection
1 parent 437a637 commit 0d75149

1 file changed

Lines changed: 76 additions & 63 deletions

File tree

platforms/desktop-shared/gui_debug.cpp

Lines changed: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,9 @@ static void debug_window_vram_oam(void)
14811481

14821482
bool window_hovered = ImGui::IsWindowHovered();
14831483

1484+
static int selected_sprite = -1;
1485+
int hovered_sprite = -1;
1486+
14841487
for (int s = 0; s < 40; s++)
14851488
{
14861489
p[s] = ImGui::GetCursorScreenPos();
@@ -1490,7 +1493,16 @@ static void debug_window_vram_oam(void)
14901493
float mouse_x = io.MousePos.x - p[s].x;
14911494
float mouse_y = io.MousePos.y - p[s].y;
14921495

1493-
if (window_hovered && (mouse_x >= 0.0f) && (mouse_x < width) && (mouse_y >= 0.0f) && (mouse_y < (sprites_16 ? height_16 : height_8)))
1496+
bool is_hovered = window_hovered && (mouse_x >= 0.0f) && (mouse_x < width) && (mouse_y >= 0.0f) && (mouse_y < (sprites_16 ? height_16 : height_8));
1497+
1498+
if (is_hovered)
1499+
{
1500+
hovered_sprite = s;
1501+
if (ImGui::IsMouseClicked(0))
1502+
selected_sprite = (selected_sprite == s) ? -1 : s;
1503+
}
1504+
1505+
if (is_hovered || selected_sprite == s)
14941506
{
14951507
ImDrawList* draw_list = ImGui::GetWindowDrawList();
14961508
draw_list->AddRect(ImVec2(p[s].x, p[s].y), ImVec2(p[s].x + width, p[s].y + (sprites_16 ? height_16 : height_8)), ImColor(cyan), 2.0f, ImDrawFlags_RoundCornersAll, 3.0f);
@@ -1510,78 +1522,79 @@ static void debug_window_vram_oam(void)
15101522

15111523
ImGui::Image((ImTextureID)(intptr_t)renderer_emu_texture, ImVec2(GAMEBOY_WIDTH * screen_scale, GAMEBOY_HEIGHT * screen_scale));
15121524

1513-
for (int s = 0; s < 40; s++)
1514-
{
1515-
if ((p[s].x == 0) && (p[s].y == 0))
1516-
continue;
1525+
int display_sprite = (hovered_sprite >= 0) ? hovered_sprite : selected_sprite;
15171526

1518-
float mouse_x = io.MousePos.x - p[s].x;
1519-
float mouse_y = io.MousePos.y - p[s].y;
1520-
1521-
if (window_hovered && (mouse_x >= 0.0f) && (mouse_x < width) && (mouse_y >= 0.0f) && (mouse_y < (sprites_16 ? height_16 : height_8)))
1522-
{
1523-
u16 address = 0xFE00 + (4 * s);
1524-
1525-
u8 y = memory->Retrieve(address);
1526-
u8 x = memory->Retrieve(address + 1);
1527-
u8 tile = memory->Retrieve(address + 2);
1528-
u8 flags = memory->Retrieve(address + 3);
1529-
int palette = IsSetBit(flags, 4) ? 1 : 0;
1530-
bool xflip = IsSetBit(flags, 5);
1531-
bool yflip = IsSetBit(flags, 6);
1532-
bool priority = !IsSetBit(flags, 7);
1533-
bool cgb_bank = IsSetBit(flags, 3);
1534-
int cgb_pal = flags & 0x07;
1535-
1536-
float real_x = x - 8.0f;
1537-
float real_y = y - 16.0f;
1538-
float rectx_min = p_screen.x + (real_x * screen_scale);
1539-
float rectx_max = p_screen.x + ((real_x + 8.0f) * screen_scale);
1540-
float recty_min = p_screen.y + (real_y * screen_scale);
1541-
float recty_max = p_screen.y + ((real_y + (sprites_16 ? 16.0f : 8.0f)) * screen_scale);
1542-
1543-
rectx_min = fminf(fmaxf(rectx_min, p_screen.x), p_screen.x + (GAMEBOY_WIDTH * screen_scale));
1544-
rectx_max = fminf(fmaxf(rectx_max, p_screen.x), p_screen.x + (GAMEBOY_WIDTH * screen_scale));
1545-
recty_min = fminf(fmaxf(recty_min, p_screen.y), p_screen.y + (GAMEBOY_HEIGHT * screen_scale));
1546-
recty_max = fminf(fmaxf(recty_max, p_screen.y), p_screen.y + (GAMEBOY_HEIGHT * screen_scale));
1547-
1548-
ImDrawList* draw_list = ImGui::GetWindowDrawList();
1549-
draw_list->AddRect(ImVec2(rectx_min, recty_min), ImVec2(rectx_max, recty_max), ImColor(cyan), 2.0f, ImDrawFlags_RoundCornersAll, 2.0f);
1550-
1551-
ImGui::TextColored(magenta, "DETAILS:");
1552-
ImGui::TextColored(cyan, " X:"); ImGui::SameLine();
1553-
ImGui::Text("$%02X", x); ImGui::SameLine();
1554-
ImGui::TextColored(cyan, " Y:"); ImGui::SameLine();
1555-
ImGui::Text("$%02X", y); ImGui::SameLine();
1527+
if (display_sprite >= 0)
1528+
{
1529+
int s = display_sprite;
1530+
u16 address = 0xFE00 + (4 * s);
1531+
1532+
u8 y = memory->Retrieve(address);
1533+
u8 x = memory->Retrieve(address + 1);
1534+
u8 tile = memory->Retrieve(address + 2);
1535+
u8 flags = memory->Retrieve(address + 3);
1536+
int palette = IsSetBit(flags, 4) ? 1 : 0;
1537+
bool xflip = IsSetBit(flags, 5);
1538+
bool yflip = IsSetBit(flags, 6);
1539+
bool priority = !IsSetBit(flags, 7);
1540+
bool cgb_bank = IsSetBit(flags, 3);
1541+
int cgb_pal = flags & 0x07;
1542+
1543+
float real_x = x - 8.0f;
1544+
float real_y = y - 16.0f;
1545+
float rectx_min = p_screen.x + (real_x * screen_scale);
1546+
float rectx_max = p_screen.x + ((real_x + 8.0f) * screen_scale);
1547+
float recty_min = p_screen.y + (real_y * screen_scale);
1548+
float recty_max = p_screen.y + ((real_y + (sprites_16 ? 16.0f : 8.0f)) * screen_scale);
1549+
1550+
rectx_min = fminf(fmaxf(rectx_min, p_screen.x), p_screen.x + (GAMEBOY_WIDTH * screen_scale));
1551+
rectx_max = fminf(fmaxf(rectx_max, p_screen.x), p_screen.x + (GAMEBOY_WIDTH * screen_scale));
1552+
recty_min = fminf(fmaxf(recty_min, p_screen.y), p_screen.y + (GAMEBOY_HEIGHT * screen_scale));
1553+
recty_max = fminf(fmaxf(recty_max, p_screen.y), p_screen.y + (GAMEBOY_HEIGHT * screen_scale));
1554+
1555+
float t = (float)(0.5 + 0.5 * sin(ImGui::GetTime() * 4.0));
1556+
ImVec4 pulse_color = ImVec4(
1557+
red.x + (white.x - red.x) * t,
1558+
red.y + (white.y - red.y) * t,
1559+
red.z + (white.z - red.z) * t,
1560+
1.0f);
1561+
ImDrawList* draw_list = ImGui::GetWindowDrawList();
1562+
draw_list->AddRect(ImVec2(rectx_min, recty_min), ImVec2(rectx_max, recty_max), ImColor(pulse_color), 2.0f, ImDrawFlags_RoundCornersAll, 2.0f);
1563+
1564+
ImGui::NewLine();
1565+
1566+
ImGui::TextColored(magenta, "DETAILS:");
1567+
ImGui::TextColored(cyan, " X:"); ImGui::SameLine();
1568+
ImGui::Text("$%02X", x); ImGui::SameLine();
1569+
ImGui::TextColored(cyan, " Y:"); ImGui::SameLine();
1570+
ImGui::Text("$%02X", y); ImGui::SameLine();
15561571

1557-
ImGui::TextColored(cyan, " Tile:"); ImGui::SameLine();
1558-
ImGui::Text("$%02X", tile);
1572+
ImGui::TextColored(cyan, " Tile:"); ImGui::SameLine();
1573+
ImGui::Text("$%02X", tile);
15591574

1560-
ImGui::TextColored(cyan, " Tile Addr:"); ImGui::SameLine();
1561-
ImGui::Text("$%04X", 0x8000 + (tile * 16)); ImGui::SameLine();
1575+
ImGui::TextColored(cyan, " Tile Addr:"); ImGui::SameLine();
1576+
ImGui::Text("$%04X", 0x8000 + (tile * 16)); ImGui::SameLine();
15621577

1563-
ImGui::TextColored(cyan, " Bank:"); ImGui::SameLine();
1564-
ImGui::Text("%d", cgb_bank);
1578+
ImGui::TextColored(cyan, " Bank:"); ImGui::SameLine();
1579+
ImGui::Text("%d", cgb_bank);
15651580

1566-
ImGui::TextColored(cyan, " OAM Addr:"); ImGui::SameLine();
1567-
ImGui::Text("$%04X", address); ImGui::SameLine();
1581+
ImGui::TextColored(cyan, " OAM Addr:"); ImGui::SameLine();
1582+
ImGui::Text("$%04X", address); ImGui::SameLine();
15681583

1569-
1570-
ImGui::TextColored(cyan, " Flags:"); ImGui::SameLine();
1571-
ImGui::Text("$%02X", flags);
1584+
ImGui::TextColored(cyan, " Flags:"); ImGui::SameLine();
1585+
ImGui::Text("$%02X", flags);
15721586

1573-
ImGui::TextColored(cyan, " Priority:"); ImGui::SameLine();
1574-
priority ? ImGui::TextColored(green, "ON ") : ImGui::TextColored(gray, "OFF"); ImGui::SameLine();
1587+
ImGui::TextColored(cyan, " Priority:"); ImGui::SameLine();
1588+
priority ? ImGui::TextColored(green, "ON ") : ImGui::TextColored(gray, "OFF"); ImGui::SameLine();
15751589

1576-
ImGui::TextColored(cyan, " Palette:"); ImGui::SameLine();
1577-
ImGui::Text("%d", emu_is_cgb() ? cgb_pal : palette);
1590+
ImGui::TextColored(cyan, " Palette:"); ImGui::SameLine();
1591+
ImGui::Text("%d", emu_is_cgb() ? cgb_pal : palette);
15781592

1579-
ImGui::TextColored(cyan, " X-Flip:"); ImGui::SameLine();
1580-
xflip ? ImGui::TextColored(green, "ON ") : ImGui::TextColored(gray, "OFF"); ImGui::SameLine();
1593+
ImGui::TextColored(cyan, " X-Flip:"); ImGui::SameLine();
1594+
xflip ? ImGui::TextColored(green, "ON ") : ImGui::TextColored(gray, "OFF"); ImGui::SameLine();
15811595

1582-
ImGui::TextColored(cyan, " Y-Flip:"); ImGui::SameLine();
1583-
yflip ? ImGui::TextColored(green, "ON") : ImGui::TextColored(gray, "OFF");
1584-
}
1596+
ImGui::TextColored(cyan, " Y-Flip:"); ImGui::SameLine();
1597+
yflip ? ImGui::TextColored(green, "ON") : ImGui::TextColored(gray, "OFF");
15851598
}
15861599

15871600
ImGui::Columns(1);

0 commit comments

Comments
 (0)