mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-29 04:18:49 -04:00
Triforce v0.8.5
A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
This commit is contained in:
393
tests/test_menu_page_slider.py
Normal file
393
tests/test_menu_page_slider.py
Normal file
@@ -0,0 +1,393 @@
|
||||
"""The options' page slider under the mouse: the scroll bar beside a list (gpu/vk/vk_menu.cpp scroll_bar; the dark track with
|
||||
the gold thumb at the left of a tab's rows, of the Controls page, of the teleport list and of the Mods cards, and at the right
|
||||
of a mod's description) only showed how far the list was scrolled. (Triforce) The owner: "I want you to make that accessible
|
||||
for mouse. So when a player clicks that, it should be able to move up or down. How a normal touch slider should work."
|
||||
|
||||
The arithmetic is gpu/vk/vk_menu_hit.h's Bar, with no ImGui and no Vulkan, compiled here alone; with it are compiled, cut
|
||||
out of vk_menu.cpp by their text: scroll_rows (where a rows' list stands), what scroll_bar records of the bar it draws,
|
||||
bar_scroll (where each list keeps its place) and bar_mouse (the press, the hold and the letting go). No game. Checked:
|
||||
|
||||
- the bar that is recorded is the bar that is drawn: its thumb's top and bottom are the picture's, at any place of the list;
|
||||
- it is taken hold of a little either side of the thin track and past its ends, not beside a list that fits its view, and
|
||||
a control drawn after it (a card whose edge it reaches) keeps its own hit;
|
||||
- a press on the thumb moves nothing; held, the list follows the cursor in proportion, between two rows too and without
|
||||
easing (the thumb stays under the cursor), to the list's ends and no further, wherever the cursor goes, off the bar too;
|
||||
- let go, a rows' list comes to whole rows; the selection has not moved, and the next move of it by the keys or the pad
|
||||
brings it into view exactly as it does after the wheel;
|
||||
- a press on the track off the thumb brings the thumb's middle under the cursor, the list with it, and is held the same
|
||||
way; a click shorter than a tick still takes the list there;
|
||||
- a short thumb (a long list of cards) is taken hold of a little either side of itself without the list moving;
|
||||
- the cards' lists stop following the choice, as after the wheel, and the description's follows too;
|
||||
- the bar the cursor is on, or holds, is the one drawn brighter; a list no longer drawn lets go;
|
||||
- none of it is a sound: nothing the sounds are told of changes (menu_sound_events.h sound_of), as with the wheel.
|
||||
|
||||
And the source is read for the rest: every scroll bar drawn has its list's number, every page that draws one gives its
|
||||
mouse to bar_mouse first and leaves the wheel, the rows and the cards alone while one is held, and a bar held is let go
|
||||
with the button on any page and when the menu shuts.
|
||||
|
||||
python -I -B tests/test_menu_page_slider.py [--cxx g++]
|
||||
"""
|
||||
import argparse
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent)) # (python -I leaves the check's own folder off the path)
|
||||
from srccut import between, block # noqa: E402
|
||||
|
||||
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
MENU = ROOT / "gpu" / "vk" / "vk_menu.cpp"
|
||||
|
||||
|
||||
def check(ok, why):
|
||||
if not ok:
|
||||
raise SystemExit("FAIL: " + why)
|
||||
|
||||
|
||||
FIXTURE = r'''#include "@ROOT@/gpu/vk/vk_menu_hit.h"
|
||||
#include "@ROOT@/gpu/vk/menu_sound_events.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <utility>
|
||||
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); std::exit(1); } } while (0)
|
||||
|
||||
// ---- what the menu's own lines stand on, here: the pointer, the units, the lists' places ----
|
||||
enum { HOS_MOUSE_LEFT = 1, HOS_MOUSE_RIGHT = 2 };
|
||||
struct MkwVkPointer { int x, y, width, height; unsigned held, pressed; int wheel; };
|
||||
typedef unsigned ImU32;
|
||||
namespace ui {
|
||||
struct Ctx { float s; bool over_game; };
|
||||
inline float lu(const Ctx& c, float units) { return units * c.s / 3; }
|
||||
}
|
||||
namespace mkwvk {
|
||||
enum { kSlots = 10 };
|
||||
menu_hit::Map hits;
|
||||
float scroll_at[kSlots], scroll_want[kSlots];
|
||||
int wheel_rows[kSlots], scrolled_to[kSlots] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
||||
float teleport_scroll_px = 0, teleport_want_px = 0, mods_scroll_px = 0, mods_want_px = 0, mods_desc_px = 0;
|
||||
bool teleport_follow = true, mods_follow = true;
|
||||
int inventory_page = 0, names_shown = 0; // ((Triforce, 11-26) the paged pages' page, a step of their sliders)
|
||||
void names_slider_to(int page) { names_shown = page; }
|
||||
@STATE@
|
||||
float ease_step = 1;
|
||||
@SCROLL_ROWS@
|
||||
@BAR_SCROLL@
|
||||
@BAR_MOUSE@
|
||||
/// (scroll_bar's own lines, from its track to the bar it records; the picture's thumb given back)
|
||||
void record_bar(ui::Ctx& c, float x, float top, float bottom, int n, int shown, float first, int id, float* thumb0, float* thumb1) {
|
||||
@BAR_RECORD@
|
||||
(void)w;
|
||||
*thumb0 = y0, *thumb1 = y1;
|
||||
}
|
||||
} // namespace mkwvk
|
||||
using namespace mkwvk;
|
||||
|
||||
static bool near(float a, float b, float tol = 0.001f) { return std::fabs(a - b) <= tol; }
|
||||
static ui::Ctx ctx{2, false}; // (a 1440-high window: 2 pixels a point, a unit two thirds of a pixel)
|
||||
static const float kX = 58, kTop = 653, kBottom = 861; // (the bar's middle line and its list's span: its track 653 to 861)
|
||||
static float thumb0, thumb1;
|
||||
/// A drawing of a tab's rows: where scroll_rows has them (8 fit), and their bar recorded as scroll_bar records it
|
||||
static float draw_rows(int slot, int n, int sel) {
|
||||
int shown = 0;
|
||||
const float first = scroll_rows(slot, n, sel, 0, 800, 100, &shown);
|
||||
CHECK(shown == 8);
|
||||
hits.clear(0, 0, 2560, 1440);
|
||||
record_bar(ctx, kX, kTop, kBottom, n, shown, first, slot, &thumb0, &thumb1);
|
||||
hits.add(138, 200, 1354, 280, menu_hit::kRow, 0); // (a row, right of the bar: drawn after it)
|
||||
return first;
|
||||
}
|
||||
/// A tick of the mouse: the buttons, the cursor; what bar_mouse says, and whether it asked for another drawing
|
||||
static bool redraw;
|
||||
static bool tick(unsigned held, unsigned pressed, float x, float y) {
|
||||
MkwVkPointer ptr{};
|
||||
ptr.held = held, ptr.pressed = pressed;
|
||||
redraw = false;
|
||||
return bar_mouse(ptr, (int)y, hits.at(x, y), redraw);
|
||||
}
|
||||
|
||||
int main() {
|
||||
using menu_hit::Bar;
|
||||
// ---- the arithmetic alone: a track 600 to 808 beside 26 rows of which 8 show: 8 pixels a row, a thumb of 64 ----
|
||||
{
|
||||
Bar b{3, 600, 808, 26, 8, 9, 0};
|
||||
CHECK(b.scrolls() && near(b.most(), 18) && near(b.length(), 64));
|
||||
CHECK(near(b.thumb(0), 600) && near(b.thumb(9), 672) && near(b.thumb(18) + b.length(), 808));
|
||||
CHECK(near(b.first_at(672), 9) && near(b.first_at(676), 9.5f));
|
||||
CHECK(near(b.first_at(-1000), 0) && near(b.first_at(5000), 18)); // (held to the list's ends)
|
||||
// (on the thumb, 672 to 736: held where the cursor is, and the press alone moves nothing)
|
||||
CHECK(near(b.grab(700), 28) && near(b.drag(700, b.grab(700)), 9));
|
||||
CHECK(near(b.grab(672), 0) && near(b.grab(735.5f), 63.5f));
|
||||
CHECK(near(b.drag(716, 28), 11) && near(b.drag(684, 28), 7)); // (16 pixels down or up: two rows)
|
||||
CHECK(near(b.drag(-50, 28), 0) && near(b.drag(3000, 28), 18));
|
||||
// (off the thumb: its middle comes under the cursor)
|
||||
CHECK(near(b.grab(650), 32) && near(b.grab(736), 32) && near(b.grab(671.9f), 32));
|
||||
const float f = b.drag(650, b.grab(650));
|
||||
CHECK(near(f, 2.25f) && near(b.thumb(f) + b.length() / 2, 650));
|
||||
CHECK(near(b.drag(604, 32), 0) && near(b.drag(806, 32), 18)); // (near an end: the end)
|
||||
// (a list that fits its view, or a track without a length: nowhere to scroll to)
|
||||
Bar fits{3, 600, 808, 8, 8, 0, 0}, flat{3, 600, 600, 26, 8, 0, 0};
|
||||
CHECK(!fits.scrolls() && fits.most() == 0 && fits.first_at(700) == 0 && fits.drag(700, 10) == 0);
|
||||
CHECK(!flat.scrolls() && flat.first_at(700) == 0);
|
||||
// (a long list of cards in pixels: the thumb under 7 pixels; taken hold of 16 either side of its middle, nothing moved)
|
||||
Bar cards{101, 600, 808, 30000, 1000, 12000, 16};
|
||||
CHECK(near(cards.thumb(12000), 683.2f) && cards.length() < 7);
|
||||
const float mid = cards.thumb(12000) + cards.length() / 2;
|
||||
CHECK(near(cards.drag(mid + 12, cards.grab(mid + 12)), 12000, 0.5f) && near(cards.drag(mid - 15, cards.grab(mid - 15)), 12000, 0.5f));
|
||||
CHECK(near(cards.grab(mid + 20), cards.length() / 2)); // (further off: the thumb comes to the cursor)
|
||||
CHECK(near(cards.drag(mid + 20, cards.grab(mid + 20)), 12000 + 20 * 30000 / 208.0f, 1));
|
||||
}
|
||||
// ---- the record: the bar as drawn, its box, what is drawn after it ----
|
||||
{
|
||||
menu_hit::Map m;
|
||||
m.clear(0, 0, 2560, 1440);
|
||||
m.add_bar(34, 82, Bar{2, 653, 861, 26, 8, 0, 16}, 8);
|
||||
m.add(82, 690, 600, 760, menu_hit::kListLine, 7); // (a card whose left edge the bar's box reaches)
|
||||
CHECK(m.bars == 1 && m.bar_of(2) && m.bar_of(2)->y1 == 861 && !m.bar_of(3));
|
||||
menu_hit::Hit h = m.at(58, 700);
|
||||
CHECK(h.part == menu_hit::kScroll && h.index == 2);
|
||||
CHECK(m.at(34, 700).part == menu_hit::kScroll && m.at(81.5f, 700).part == menu_hit::kScroll); // (either side of the thin track)
|
||||
CHECK(m.at(33, 700).part == menu_hit::kNone && m.at(82, 500).part == menu_hit::kNone);
|
||||
CHECK(m.at(58, 646).part == menu_hit::kScroll && m.at(58, 868).part == menu_hit::kScroll); // (a little past its ends)
|
||||
CHECK(m.at(58, 644).part == menu_hit::kNone && m.at(58, 870).part == menu_hit::kNone);
|
||||
CHECK(m.at(82, 700).part == menu_hit::kListLine && m.at(81.5f, 700).part == menu_hit::kScroll); // (the card keeps its own)
|
||||
m.add(40, 690, 70, 710, menu_hit::kButton, 1); // (drawn after it, over it: on top)
|
||||
CHECK(m.at(58, 700).part == menu_hit::kButton && m.at(58, 720).part == menu_hit::kScroll);
|
||||
// (no hit: a list that fits its view, a bar without a number; no more than kBars; gone with the next drawing)
|
||||
const int boxes = m.n;
|
||||
m.add_bar(34, 82, Bar{4, 653, 861, 8, 8, 0, 16}, 8);
|
||||
m.add_bar(34, 82, Bar{-1, 653, 861, 26, 8, 0, 16}, 8);
|
||||
CHECK(m.bars == 1 && m.n == boxes && !m.bar_of(4) && !m.bar_of(-1));
|
||||
for (int i = 0; i < menu_hit::Map::kBars + 3; i++) m.add_bar(900, 940, Bar{10 + i, 100, 200, 26, 8, 0, 16}, 8);
|
||||
CHECK(m.bars == menu_hit::Map::kBars && m.n == boxes + menu_hit::Map::kBars - 1);
|
||||
m.clear(0, 0, 2560, 1440);
|
||||
CHECK(m.bars == 0 && !m.bar_of(2) && m.at(58, 700).part == menu_hit::kNone);
|
||||
}
|
||||
// ---- a tab's rows: 26 of which 8 fit, the bar's track 653 to 861 (scroll_bar's own: 312 units about its list's middle) ----
|
||||
const int slot = 2, n = 26;
|
||||
ease_step = 0.25f; // (a quarter of the way a drawing, as at 60 a second)
|
||||
CHECK(draw_rows(slot, n, 0) == 0);
|
||||
CHECK(hits.bars == 1 && hits.bar_of(slot) && near(hits.bar_of(slot)->y0, 653) && near(hits.bar_of(slot)->y1, 861));
|
||||
CHECK(near(thumb0, 653) && near(thumb1, 717));
|
||||
for (float first : {0.0f, 3.0f, 5.5f, 18.0f}) { // (the bar recorded is the bar drawn: its thumb the picture's)
|
||||
float t0 = 0, t1 = 0;
|
||||
hits.clear(0, 0, 2560, 1440);
|
||||
record_bar(ctx, kX, kTop, kBottom, n, 8, first, slot, &t0, &t1);
|
||||
const Bar* b = hits.bar_of(slot);
|
||||
CHECK(b && near(b->thumb(b->first), t0) && near(b->thumb(b->first) + b->length(), t1) && near(b->first, first));
|
||||
CHECK(near(b->reach, 16));
|
||||
}
|
||||
{ // (taken hold of 36 units either side of its middle line, 24 pixels here, and 12 units past its ends)
|
||||
CHECK(draw_rows(slot, n, 0) == 0);
|
||||
CHECK(hits.at(kX - 24, 700).part == menu_hit::kScroll && hits.at(kX + 23.5f, 700).part == menu_hit::kScroll);
|
||||
CHECK(hits.at(kX - 25, 700).part == menu_hit::kNone && hits.at(kX + 24, 700).part == menu_hit::kNone);
|
||||
CHECK(hits.at(kX, 645).part == menu_hit::kScroll && hits.at(kX, 868.5f).part == menu_hit::kScroll);
|
||||
CHECK(hits.at(kX, 644).part == menu_hit::kNone);
|
||||
// (a list that fits: no bar to take; over the game's own list it is drawn whole, and still none to take)
|
||||
float t0, t1;
|
||||
hits.clear(0, 0, 2560, 1440);
|
||||
ui::Ctx over{2, true};
|
||||
record_bar(over, kX, kTop, kBottom, 1, 1, 0, slot, &t0, &t1);
|
||||
CHECK(hits.bars == 0 && hits.at(kX, 700).part == menu_hit::kNone && near(t0, 653) && near(t1, 861));
|
||||
}
|
||||
// (the cursor on it: lit, and drawn again for that; off it: not)
|
||||
CHECK(draw_rows(slot, n, 0) == 0);
|
||||
CHECK(!tick(0, 0, 500, 240) && bar_hover == -1 && !redraw);
|
||||
CHECK(!tick(0, 0, kX, 700) && bar_hover == slot && redraw && bar_held == -1);
|
||||
CHECK(!tick(0, 0, kX, 701) && bar_hover == slot && !redraw);
|
||||
CHECK(!tick(0, 0, 500, 240) && bar_hover == -1 && redraw);
|
||||
// (a press on the thumb: held, and nothing moves)
|
||||
CHECK(tick(1, 1, kX, 700) && bar_held == slot && bar_hover == slot && near(bar_grab, 47) && redraw);
|
||||
CHECK(scroll_want[slot] == 0 && draw_rows(slot, n, 0) == 0);
|
||||
CHECK(tick(1, 0, kX, 700) && !redraw); // (held still: nothing to draw again)
|
||||
// (40 pixels down: 5 rows, at once though the easing is a quarter a drawing; 4 more: between two rows)
|
||||
CHECK(tick(1, 0, kX, 740) && redraw && near(draw_rows(slot, n, 0), 5) && near(thumb0, 693));
|
||||
CHECK(tick(1, 0, kX, 744) && near(draw_rows(slot, n, 0), 5.5f) && near(thumb0, 697));
|
||||
CHECK(scrolled_to[slot] == 0); // (the selection: not moved, not asked into view)
|
||||
// (the cursor far off the bar, over a row, off the menu: still held, to the list's end and no further)
|
||||
CHECK(hits.at(700, 240).part == menu_hit::kRow);
|
||||
CHECK(tick(1, 0, 700, 240) && near(draw_rows(slot, n, 0), 0));
|
||||
CHECK(tick(1, 0, 5000, 5000) && near(draw_rows(slot, n, 0), 18) && near(thumb1, 861));
|
||||
CHECK(tick(1, 0, kX, 744) && near(draw_rows(slot, n, 0), 5.5f));
|
||||
// (let go: whole rows, eased there; the bar still lit under the cursor)
|
||||
CHECK(!tick(0, 0, kX, 744) && bar_held == -1 && bar_hover == slot && redraw);
|
||||
float at = draw_rows(slot, n, 0);
|
||||
CHECK(at > 5.5f && at < 6 && scroll_want[slot] == 6);
|
||||
ease_step = 1;
|
||||
CHECK(draw_rows(slot, n, 0) == 6);
|
||||
// (the selection is where it was, out of view above; Down then brings the next row into view, with its row of context)
|
||||
CHECK(draw_rows(slot, n, 1) == 0);
|
||||
{ // (...which is what the wheel does: six notches from the same place, then Down)
|
||||
const int other = 4;
|
||||
CHECK(draw_rows(other, n, 0) == 0 && draw_rows(other, n, 0) == 0);
|
||||
wheel_rows[other] -= 6;
|
||||
CHECK(draw_rows(other, n, 0) == 6 && draw_rows(other, n, 1) == 0);
|
||||
}
|
||||
// (the selection moved by the keys while the bar is held: the rows stay with the cursor, and it comes into view after)
|
||||
CHECK(draw_rows(slot, n, 1) == 0);
|
||||
CHECK(tick(1, 1, kX, 700) && tick(1, 0, kX, 780) && near(draw_rows(slot, n, 1), 10));
|
||||
CHECK(near(draw_rows(slot, n, 20), 10) && tick(1, 0, kX, 781) && near(draw_rows(slot, n, 20), 10.125f));
|
||||
CHECK(!tick(0, 0, kX, 781) && draw_rows(slot, n, 20) == 14); // (20 and its row of context: 14 to 21 in view)
|
||||
// ---- a press on the track off the thumb: the thumb's middle under the cursor, the rows with it; held the same way ----
|
||||
CHECK(draw_rows(slot, n, 0) == 0 && near(thumb1, 717));
|
||||
CHECK(tick(1, 1, kX, 801) && bar_held == slot && near(bar_grab, 32));
|
||||
CHECK(near(draw_rows(slot, n, 0), 14.5f) && near((thumb0 + thumb1) / 2, 801));
|
||||
CHECK(tick(1, 0, kX, 793) && near(draw_rows(slot, n, 0), 13.5f)); // (and drawn along from there)
|
||||
CHECK(!tick(0, 0, kX, 793) && draw_rows(slot, n, 0) == 14);
|
||||
CHECK(tick(1, 1, kX, 660) && near(draw_rows(slot, n, 0), 0)); // (above it, near the track's top: the list's top)
|
||||
CHECK(!tick(0, 0, kX, 660) && draw_rows(slot, n, 0) == 0);
|
||||
CHECK(tick(1, 1, kX, 866) && near(draw_rows(slot, n, 0), 18)); // (just past the track's foot: the list's end)
|
||||
CHECK(!tick(0, 0, kX, 866) && draw_rows(slot, n, 0) == 18);
|
||||
// (a click shorter than a tick, pressed and let go between two reads: the list goes there all the same)
|
||||
CHECK(tick(0, 1, kX, 757) && bar_held == slot);
|
||||
CHECK(near(draw_rows(slot, n, 0), 9)); // (the track's middle: the list's)
|
||||
CHECK(!tick(0, 0, kX, 757) && bar_held == -1 && draw_rows(slot, n, 0) == 9);
|
||||
// (a press off the bar takes nothing; nor the right button on it)
|
||||
CHECK(!tick(1, 1, 700, 240) && bar_held == -1 && draw_rows(slot, n, 0) == 9);
|
||||
CHECK(!tick(2, 2, kX, 700) && bar_held == -1 && draw_rows(slot, n, 0) == 9);
|
||||
// (held, and its list no longer drawn, another tab's in its place: let go, the other not moved)
|
||||
CHECK(tick(1, 1, kX, 700) && bar_held == slot);
|
||||
scroll_want[5] = scroll_at[5] = 0;
|
||||
CHECK(draw_rows(5, n, 0) == 0);
|
||||
CHECK(!tick(1, 0, kX, 800) && bar_held == -1 && draw_rows(5, n, 0) == 0);
|
||||
CHECK(!tick(1, 0, kX, 800) && bar_held == -1); // (the button still down from before: no press of this bar)
|
||||
// ---- the cards' lists, in pixels: at once, and the cards no longer follow the choice, as after the wheel ----
|
||||
{
|
||||
float t0, t1;
|
||||
auto draw = [&](int id, float total, float view, float at) {
|
||||
hits.clear(0, 0, 2560, 1440);
|
||||
record_bar(ctx, kX, kTop, kBottom, (int)total, (int)view, at, id, &t0, &t1);
|
||||
};
|
||||
CHECK(!tick(0, 0, 500, 240));
|
||||
const float rows_want = scroll_want[slot], other_want = scroll_want[5];
|
||||
draw(kBarTeleport, 3000, 1000, 0); // (thumb 653 to 722.3)
|
||||
CHECK(hits.at(kX, 700).part == menu_hit::kScroll && hits.at(kX, 700).index == kBarTeleport);
|
||||
CHECK(tick(1, 1, kX, 700) && bar_held == kBarTeleport && teleport_scroll_px == 0 && !teleport_follow);
|
||||
CHECK(tick(1, 0, kX, 752) && near(teleport_scroll_px, 750, 0.01f) && teleport_want_px == teleport_scroll_px);
|
||||
draw(kBarTeleport, 3000, 1000, teleport_scroll_px);
|
||||
CHECK(near(t0, 705));
|
||||
CHECK(tick(1, 0, kX, 2000) && near(teleport_scroll_px, 2000, 0.01f));
|
||||
CHECK(!tick(0, 0, kX, 2000) && near(teleport_scroll_px, 2000, 0.01f));
|
||||
CHECK(scroll_want[slot] == rows_want && scroll_want[5] == other_want); // (no rows' list touched)
|
||||
draw(kBarMods, 30000, 1000, 0);
|
||||
float d0, d1;
|
||||
record_bar(ctx, 2400, 900, 1300, 2000, 400, 0, kBarModsDesc, &d0, &d1); // (the Mods screen's second: the description's)
|
||||
CHECK(hits.bars == 2 && hits.at(kX, 757).index == kBarMods && hits.at(2400, 1100).index == kBarModsDesc);
|
||||
CHECK(tick(1, 1, kX, 757) && bar_held == kBarMods && !mods_follow && near(mods_scroll_px, 14500, 1) && mods_want_px == mods_scroll_px);
|
||||
CHECK(mods_desc_px == 0 && !tick(0, 0, kX, 757));
|
||||
CHECK(tick(1, 1, 2400, 1150) && bar_held == kBarModsDesc && mods_desc_px > 0 && near(mods_scroll_px, 14500, 1));
|
||||
CHECK(!tick(0, 0, 2400, 1150) && bar_held == -1);
|
||||
}
|
||||
// ---- no sound: nothing the sounds are told of changes by it, as with the wheel; and it is not a row's slider drawn along ----
|
||||
{
|
||||
menu_sound::State s;
|
||||
s.open = true, s.tab = 2, s.cursor = 3, s.value = 50;
|
||||
menu_sound::Input press, hold, none;
|
||||
press.click = true;
|
||||
CHECK(menu_sound::sound_of(s, s, press) == menu_sound::kNone);
|
||||
CHECK(menu_sound::sound_of(s, s, hold) == menu_sound::kNone && menu_sound::sound_of(s, s, none) == menu_sound::kNone);
|
||||
}
|
||||
std::printf("PASS: the page slider: the bar drawn is the bar taken, held and drawn along, its track clicked\n");
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def fixture(menu):
|
||||
state = re.search(r"constexpr int kBarTeleport = [^\n]*\nint bar_held = -1;[^\n]*\nfloat bar_grab = 0;[^\n]*\nint bar_hover = -1;[^\n]*\n", menu)
|
||||
check(state, "the page sliders' state (kBarTeleport, bar_held, bar_grab, bar_hover) is not where the check cuts it")
|
||||
bar = block(menu, "void scroll_bar(")
|
||||
record = between(bar, " const float mid = ", " const bool live")
|
||||
check("hits.add_bar(" in record and "const float y0 = " in record and "const menu_hit::Bar bar{id, " in record,
|
||||
"scroll_bar does not record the bar from the numbers it draws the thumb with")
|
||||
parts = {"@ROOT@": ROOT.as_posix(), "@STATE@": state.group(0), "@SCROLL_ROWS@": block(menu, "float scroll_rows("),
|
||||
"@BAR_SCROLL@": block(menu, "void bar_scroll("), "@BAR_MOUSE@": block(menu, "bool bar_mouse("), "@BAR_RECORD@": record}
|
||||
text = FIXTURE
|
||||
for mark, part in parts.items():
|
||||
text = text.replace(mark, part)
|
||||
return text
|
||||
|
||||
|
||||
def sources(menu):
|
||||
hit = (ROOT / "gpu" / "vk" / "vk_menu_hit.h").read_text(encoding="utf-8")
|
||||
check("#include" not in hit, "vk_menu_hit.h includes something: it is plain arithmetic, and this check compiles it alone")
|
||||
# (every scroll bar drawn has its list's number: one drawn without is a bar the mouse cannot take)
|
||||
calls = re.findall(r"^[^/\n]*\bscroll_bar\(c, [^;]*\);", menu, re.M)
|
||||
calls = [c for c in calls if not c.lstrip().startswith("void ")]
|
||||
numbers = [re.search(r", (\w+)\);$", c).group(1) for c in calls]
|
||||
# ((Triforce, 11-26) and the Debug tab's paged pages': the Inventory's, a name page's (and its empty page's, still)
|
||||
check(sorted(numbers) == ["cur_tab", "kBarInventory", "kBarMods", "kBarModsDesc", "kBarNames", "kBarNames", "kBarTeleport", "kControlsSlot"],
|
||||
"the scroll bars drawn and their lists' numbers: %s" % numbers)
|
||||
check("scroll_rows(cur_tab, listed, sel_at, top, bottom, pitch, &shown)" in menu and
|
||||
"scroll_rows(kControlsSlot, n, csel, top, bottom, pitch, &shown)" in menu,
|
||||
"a rows' list's bar no longer has the number of its slot of scroll_at")
|
||||
bar = block(menu, "void scroll_bar(")
|
||||
check("live && id == bar_held ?" in bar and "live && id == bar_hover ?" in bar and bar.count("lit") >= 3,
|
||||
"the bar under the cursor, or held, is not drawn brighter")
|
||||
# (a rows' list while its bar is held: where the cursor has it; the wheel's lines as they were)
|
||||
rows = block(menu, "float scroll_rows(")
|
||||
check("else if (bar_held == slot) {" in rows and "return at = want;" in rows, "scroll_rows eases or rounds a list whose bar is held")
|
||||
check("want -= (float)wheel;" in rows and "want = std::round(std::clamp(want, 0.0f, (float)(n - fit)));" in rows,
|
||||
"scroll_rows: the wheel's and the selection's scrolling changed")
|
||||
# (each page that draws one: bar_mouse first, and while it holds one the rest of the mouse is nothing's)
|
||||
tick = menu[menu.index("void menu_tick() {"):]
|
||||
check("if (drag_row < 0 && bar_mouse(ptr, my, hit, changed)) hit = menu_hit::Hit{}, ptr.wheel = 0;" in tick,
|
||||
"the tabs' rows do not give the mouse to their page slider (or give it while a row's slider is held)")
|
||||
check(tick.index("bar_mouse(ptr, my, hit, changed)) hit = menu_hit::Hit{}, ptr.wheel = 0;\n const int ht =") <
|
||||
tick.index("} else if (on_row && (moved || ptr.pressed) && hit.index != sel) {"),
|
||||
"the tabs' rows: a row is chosen under the cursor before the page slider has the mouse")
|
||||
controls = between(tick, "} else if (open_now.load() && page == 1) {", "} else if (open_now.load() && page == 4) {",
|
||||
unique=False)
|
||||
check("if (bar_mouse(ptr, my, hit, changed)) hit = menu_hit::Hit{}, ptr.wheel = 0;\n const bool option =" in controls,
|
||||
"the Controls page does not give the mouse to its page slider first")
|
||||
teleport = block(menu, "void teleport_mouse(")
|
||||
check("const bool bar = bar_mouse(ptr, my, hit, changed);\n if (bar) hit = menu_hit::Hit{};" in teleport and
|
||||
"if (ptr.wheel && !bar) teleport_wheel += ptr.wheel" in teleport, "the teleport list does not give the mouse to its page slider first")
|
||||
mods = block(menu, "void mods_tick(")
|
||||
check("const bool bar = !dialog && !mods_kbd && bar_mouse(ptr, my, hit, changed);\n if (bar) hit = menu_hit::Hit{};" in mods and
|
||||
"if (ptr.wheel && !bar) (mx >= mods_desc_x0 ? mods_desc_wheel : mods_wheel) += ptr.wheel" in mods,
|
||||
"the Mods screen does not give the mouse to its page sliders first, or gives it under a dialog")
|
||||
# ((Triforce, 11-26) the Inventory and the name pages' sliders, a page a step, take the mouse first as the teleport list's)
|
||||
for head in ("void inventory_mouse(", "void names_mouse("):
|
||||
page = block(menu, head)
|
||||
check("const bool bar = bar_mouse(ptr, my, hit, changed);\n if (bar) hit = menu_hit::Hit{};" in page and "if (ptr.wheel && !bar)" in page,
|
||||
head + " does not give the mouse to its page slider first")
|
||||
bars = block(menu, "void bar_scroll(")
|
||||
check("else if (id == kBarInventory) inventory_page = std::max(0, (int)std::lround(first));" in bars and
|
||||
"else if (id == kBarNames) names_slider_to(std::max(0, (int)std::lround(first)));" in bars,
|
||||
"a paged page's slider does not turn its pages")
|
||||
check(menu.count("bar_mouse(ptr, my, hit, changed)") == 6, "a page's bar_mouse added or gone: this check names six")
|
||||
# (let go with the button wherever the menu is by then, and when it shuts)
|
||||
check("if (bar_held >= 0 && !(ptr.held & HOS_MOUSE_LEFT)) bar_held = -1, changed = true;" in tick,
|
||||
"a page slider held is not let go with the button on every page")
|
||||
check(tick.index("if (bar_held >= 0 && !(ptr.held & HOS_MOUSE_LEFT)) bar_held = -1") < tick.index("if (reshade_menu::comparing()) {"),
|
||||
"a page slider is let go only after the pages have had the tick")
|
||||
shut = between(tick, "if (!now_open) {", "if (now_open != told && app_window()) {")
|
||||
check("bar_held = bar_hover = -1;" in shut, "a page slider held as the menu shuts stays held")
|
||||
# (not a sound: the sounds' input is told of a row's slider alone, and their state has no list's place in it)
|
||||
check("in.click = (ptr.pressed & HOS_MOUSE_LEFT) != 0, in.drag = drag_row >= 0;" in tick, "the sounds are told of the page slider's hold")
|
||||
state = block(menu, "static menu_sound::State sound_state() {")
|
||||
check(not re.search(r"scroll|bar_held|bar_hover", state), "a list's place is part of what the sounds are told of")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cxx", default="g++")
|
||||
args = parser.parse_args()
|
||||
menu = MENU.read_text(encoding="utf-8")
|
||||
sources(menu)
|
||||
with tempfile.TemporaryDirectory(prefix="menu-page-slider-") as tmp:
|
||||
src, exe = Path(tmp) / "fixture.cpp", Path(tmp) / "fixture"
|
||||
src.write_text(fixture(menu), encoding="utf-8")
|
||||
subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", str(src), "-o", str(exe)], check=True)
|
||||
subprocess.run([str(exe)], check=True)
|
||||
print("PASS: the options' page slider under the mouse")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user