// (Triforce) The title's tabs: Mods and Save Select at the picture's top left, each with its button's prompt under it. The // owner: "I want you to move the mod tab and the save select tab to the top left of the screen. I want there to be a button // prompt below the tabs ... optimize those placements for every aspect ratio" (they were entries under the title's list, // where Quit Game is now). // // Where they are: from the picture's own top left corner (game_grid.h Place: the picture as the present shows it, between // bars or not), in the game's layout units (2160 down the picture), so that they keep their size against the title's own // words in every window and are in the corner of what is seen in every shape: a 4:3 or 16:10 picture (the layouts squeezed // across, and the tabs with them), 16:9, 21:9 and 32:9 (the corner of the wide picture, not of its 16:9 middle), and a // picture between bars (never in the bars). // // The arithmetic alone, in the pixels of the column the entry is drawn on (vk_menu.cpp grid_ctx: 16:9 of the grid's height, // from 0; put on the window by game_grid::Map after): no ImGui and no Vulkan, tests/test_title_tabs.py compiles it alone. #pragma once #include #include "game_grid.h" namespace mkwvk::title_tabs { constexpr int kTabs = 2; // (Mods, Save Select) constexpr float kLeft = 112; // (the first label's left edge from the picture's left edge, units) constexpr float kTop = 108; // (the labels' middle under the picture's top edge) constexpr float kText = 52; // (the labels' size: the title's own entries', vk_menu.cpp kTitleText) constexpr float kBetween = 104; // (from a tab's widest part to the next one's) constexpr float kIcon = 84; // (the prompt's icon: the game's guides have theirs at 102 beside 48-unit labels) constexpr float kIconDrop = 92; // (the icon's middle under the label's) constexpr float kPadX = 34, kPadY = 26; // (the hit box past the label and the icon) /// One tab in the column's pixels: its label's middle, its icon's middle, and the box a click or the mouse over it counts in struct Tab { float label_x = 0, label_y = 0; float icon_x = 0, icon_y = 0; float x0 = 0, y0 = 0, x1 = 0, y1 = 0; }; struct Layout { Tab tab[kTabs]; int n = 0; }; /// The picture's left and top edges in the pixels of the column drawn on (m: where that column goes in the window). With no /// picture known yet the grid is the window's own column: its edges inline float picture_left(const game_grid::Place& g, const game_grid::Map& m) { return m.back_x(g.picture ? g.pic_x : g.x); } inline float picture_top(const game_grid::Place& g, const game_grid::Map& m) { return m.back_y(g.picture ? g.pic_y : g.y); } /// The whole picture in the pixels of the column drawn on: the clip rectangle the tabs are drawn in. ((Triforce) the lab's /// first run of them, the owner's 3416 x 1440 picture: the tabs were not drawn at all. On a picture wider than 16:9 its /// left edge is left of the column (x under 0 in its pixels), and ImGui leaves out the glyphs of text outside the clip /// rectangle as it adds them, which was the window's own in the column's pixels) inline void picture_clip(const game_grid::Place& g, const game_grid::Map& m, float* x0, float* y0, float* x1, float* y1) { const float px = g.picture ? g.pic_x : g.x, py = g.picture ? g.pic_y : g.y; const float pw = g.picture ? g.pic_w : g.w, ph = g.picture ? g.pic_h : g.h; *x0 = m.back_x(px), *y0 = m.back_y(py), *x1 = m.back_x(px + pw), *y1 = m.back_y(py + ph); } /// n tabs from the picture's top left (left, top: picture_left, picture_top). unit: pixels a layout unit (the column's height /// over 2160); label_w, icon_w: each label's and each icon's width in the column's pixels; icons: the prompts are drawn (a /// controller's: the hit box reaches under them) inline Layout place(float left, float top, float unit, const float* label_w, const float* icon_w, int n, bool icons) { Layout l; l.n = std::clamp(n, 0, kTabs); float x = left + kLeft * unit; for (int i = 0; i < l.n; i++) { const float w = std::max(label_w[i], icons ? icon_w[i] : 0.0f); // (the icon is centred under the label) Tab& t = l.tab[i]; t.label_x = x + w * 0.5f, t.label_y = top + kTop * unit; t.icon_x = t.label_x, t.icon_y = t.label_y + kIconDrop * unit; t.x0 = x - kPadX * unit, t.x1 = x + w + kPadX * unit; t.y0 = t.label_y - (kText * 0.5f + kPadY) * unit; t.y1 = (icons ? t.icon_y + kIcon * 0.5f * unit : t.label_y + kText * 0.5f * unit) + kPadY * unit; x += w + kBetween * unit; } return l; } /// The tab at a point of the column's pixels, -1 none inline int at(const Layout& l, float x, float y) { for (int i = 0; i < l.n; i++) if (x >= l.tab[i].x0 && x < l.tab[i].x1 && y >= l.tab[i].y0 && y < l.tab[i].y1) return i; return -1; } } // namespace mkwvk::title_tabs