Preserve 16:9 tile aspect on resize
This commit is contained in:
@@ -37,6 +37,7 @@ constexpr uint32_t TEXTURE_WIDTH = 512;
|
||||
constexpr uint32_t TEXTURE_HEIGHT = 288;
|
||||
constexpr uint32_t VERTICES_PER_QUAD = 6;
|
||||
constexpr float TILE_GAP_PIXELS = 8.0f;
|
||||
constexpr float TILE_ASPECT = 16.0f / 9.0f;
|
||||
|
||||
static std::atomic<bool> g_running{true};
|
||||
|
||||
@@ -465,32 +466,23 @@ static void drawTileLabels(
|
||||
ImDrawList* drawList = ImGui::GetForegroundDrawList();
|
||||
const ImVec2 displaySize = ImGui::GetIO().DisplaySize;
|
||||
|
||||
const float gapX =
|
||||
std::min(TILE_GAP_PIXELS, displaySize.x * 0.1f);
|
||||
const float gapY =
|
||||
std::min(TILE_GAP_PIXELS, displaySize.y * 0.1f);
|
||||
const float tileW =
|
||||
(displaySize.x -
|
||||
gapX * static_cast<float>(gridCols - 1)) /
|
||||
static_cast<float>(gridCols);
|
||||
const float tileH =
|
||||
(displaySize.y -
|
||||
gapY * static_cast<float>(gridRows - 1)) /
|
||||
static_cast<float>(gridRows);
|
||||
const std::vector<TileRect> tileRects =
|
||||
makeGridTileRects(
|
||||
gridCols,
|
||||
gridRows,
|
||||
displaySize.x,
|
||||
displaySize.y,
|
||||
TILE_GAP_PIXELS,
|
||||
TILE_ASPECT
|
||||
);
|
||||
const float labelH =
|
||||
std::max(24.0f, ImGui::GetFontSize() + 10.0f);
|
||||
|
||||
for (uint32_t i = 0; i < feeds.size(); ++i)
|
||||
for (uint32_t i = 0;
|
||||
i < feeds.size() && i < tileRects.size();
|
||||
++i)
|
||||
{
|
||||
const uint32_t col = i % gridCols;
|
||||
const uint32_t row = i / gridCols;
|
||||
|
||||
const float x0 =
|
||||
static_cast<float>(col) * (tileW + gapX);
|
||||
const float y0 =
|
||||
static_cast<float>(row) * (tileH + gapY);
|
||||
const float x1 = x0 + tileW;
|
||||
const float y1 = y0 + tileH;
|
||||
const TileRect& tileRect = tileRects[i];
|
||||
|
||||
const FeedRuntimeStatus status =
|
||||
feeds[i]->status();
|
||||
@@ -503,9 +495,15 @@ static void drawTileLabels(
|
||||
? feedRuntimeStatusDisplayName(status)
|
||||
: sourceInfo);
|
||||
|
||||
const ImVec2 labelMin(x0, y1 - labelH);
|
||||
const ImVec2 labelMax(x1, y1);
|
||||
const ImVec2 textPos(x0 + 10.0f, y1 - labelH + 5.0f);
|
||||
const ImVec2 labelMin(
|
||||
tileRect.x0,
|
||||
tileRect.y1 - labelH
|
||||
);
|
||||
const ImVec2 labelMax(tileRect.x1, tileRect.y1);
|
||||
const ImVec2 textPos(
|
||||
tileRect.x0 + 10.0f,
|
||||
tileRect.y1 - labelH + 5.0f
|
||||
);
|
||||
|
||||
drawList->AddRectFilled(
|
||||
labelMin,
|
||||
@@ -630,19 +628,14 @@ int main(int argc, char* argv[])
|
||||
// Vertex buffer (quad tiles)
|
||||
// ----------------------------------------
|
||||
|
||||
const float initialGapX =
|
||||
2.0f * TILE_GAP_PIXELS /
|
||||
static_cast<float>(winWidth);
|
||||
const float initialGapY =
|
||||
2.0f * TILE_GAP_PIXELS /
|
||||
static_cast<float>(winHeight);
|
||||
|
||||
std::vector<Vertex> quadVertices =
|
||||
makeGridLayout(
|
||||
config.gridCols,
|
||||
config.gridRows,
|
||||
initialGapX,
|
||||
initialGapY);
|
||||
static_cast<float>(winWidth),
|
||||
static_cast<float>(winHeight),
|
||||
TILE_GAP_PIXELS,
|
||||
TILE_ASPECT);
|
||||
|
||||
VkDeviceSize vbSize =
|
||||
sizeof(quadVertices[0]) * quadVertices.size();
|
||||
@@ -1680,34 +1673,16 @@ int main(int argc, char* argv[])
|
||||
SDL_GetPerformanceCounter();
|
||||
|
||||
VkExtent2D swapExtent = swapchain.extent();
|
||||
const float gapX =
|
||||
2.0f * TILE_GAP_PIXELS /
|
||||
static_cast<float>(swapExtent.width);
|
||||
const float gapY =
|
||||
2.0f * TILE_GAP_PIXELS /
|
||||
static_cast<float>(swapExtent.height);
|
||||
|
||||
updateGridLayout(
|
||||
quadVertices.data(),
|
||||
config.gridCols,
|
||||
config.gridRows,
|
||||
gapX,
|
||||
gapY
|
||||
static_cast<float>(swapExtent.width),
|
||||
static_cast<float>(swapExtent.height),
|
||||
TILE_GAP_PIXELS,
|
||||
TILE_ASPECT
|
||||
);
|
||||
|
||||
const float tileWidthPx =
|
||||
(static_cast<float>(swapExtent.width) -
|
||||
TILE_GAP_PIXELS *
|
||||
static_cast<float>(config.gridCols - 1)) /
|
||||
static_cast<float>(config.gridCols);
|
||||
const float tileHeightPx =
|
||||
(static_cast<float>(swapExtent.height) -
|
||||
TILE_GAP_PIXELS *
|
||||
static_cast<float>(config.gridRows - 1)) /
|
||||
static_cast<float>(config.gridRows);
|
||||
const float tileAspect =
|
||||
tileWidthPx / tileHeightPx;
|
||||
|
||||
for (uint32_t i = 0; i < feedCount; ++i)
|
||||
{
|
||||
float srcAspect = feeds[i]->srcAspectRatio();
|
||||
@@ -1716,7 +1691,7 @@ int main(int argc, char* argv[])
|
||||
quadVertices.data(),
|
||||
i,
|
||||
srcAspect,
|
||||
tileAspect);
|
||||
TILE_ASPECT);
|
||||
}
|
||||
|
||||
std::memcpy(
|
||||
|
||||
Reference in New Issue
Block a user