Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions phoenix/pico4-monado/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ sha256sums=(SKIP
'07e474ecbbb1e3a629735c123fe83cb1c9ca7c4dedf34392e1f99e06bdbf37c2'
'de4add87e8b087f7e1edfaa0212b052b435e94fde9cce0a28e8e410bcfeb6264'
'bb6561e792bdbcb7ec78eeb8b0a275fc138d930a3cde818ad34f2e56536a893d'
'00dd55716c855258ce2e3f6c247b7d80e3128d64a9fc466a5eb74e03dc028d0a'
'ebfa7c06a416438de1115a50a5f7808762212eaf6ff7bb6102745955216460fc'
'0fe74dbd8f72c6e0763952a3e602771aa4d3c4b9c84871909fb4355d9b3b3756'
'5cbe37ce8152ace06a53c6f0bec5b9fb6b639d9d2b86c6eb47864594112f87ab'
'6b0d8e8479f4282bcaaaa46d0090417fa5e1ca72a03600a9b2da95cdf71f28d5'
'aed57ba94e98f8d8d0862a72231ce2f81f1343a3376f7c38537be5ea16890dfd'
'8564f2babbd92aa89f26d448c6c6a9d2e9c7c07ac52c1fc9424f09fe11b226ed'
'82cb589128b7047e28c19267ab579abe4033e8003b0560841bbf7ea90bd79c8c'
'd3f62fedbea156a82c296430fdae6c89139f18de54c5228ab97bd4a0f37a39c0'
'27994274807cce849ebd2fbba7dc9b8894713dbf5047ae46f6821bad71e28df7'
'57b052998c5df61a691e163e4e43191e4f4994e610ea95a01ceb6a774b850be3'
'701f01563714bcd689e70a2af608d66fe331b073620513907f6ec0136690c113'
'cbe0e87ecdcaf2808b874c3b4ae2f05e0774d49563d6e1cffb2b76c755f3a4a5'
'80948b181cd55b1194842f7c4b284299ed4cf91c5ee9978fa31d1938e5c97501'
'5ba1862d71710d477172eabcad5f9dba055bb3c90c3e218a7187ded2da20cea2'
'4b58a623d5ebe53c2a30ed6710f25c66da8c96b2c014525fd08b479a8abbcd83'
'ccb6d333b26d172ac07fc2de3234883afccb2ae5ce0419cf3b067fe971d12372'
'7cc922f7215fd73bf1a1d7b209d2796299698ba9fe114343f3c56e97a770b25f'
'9785bd99b363cb9542801ef79ef2ceff49fa152954a8d513c9222466e4b5e5d3'
'374bd56d373143725b3a6db79f284a40350a1017eb631f63d4e8d3cd41ef20b2'
'88f2c74f8fb72878f7ba98d5c5007e6c639fe8ef7a078a546c1101e5b48c26ca'
'cc727edbad724f50656255313d81ebc56dc6c168bbe05f10f8c57cfecd3829a4'
Expand Down
24 changes: 18 additions & 6 deletions phoenix/pico4-monado/overpressure-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,10 @@ draw_about(cairo_t *c, const Frame &f, State &s, const Texts &t)
row_line(c, kColX + pad, ry, kColW - 2 * pad);
}
line_mid(c, row.label, kColX + pad, ry + rh / 2, 320, kBody, false, kText);
// The value at the right in a fixed-width face; what it is beside it, muted.
// The value at the right in a fixed-width face; what it is beside it, muted. Measured and
// drawn the right way round on a mirrored page, where it sits on the left.
cairo_save(c);
pico4_text::unmirror(c, 0, 0);
PangoLayout *layout = pango_cairo_create_layout(c);
PangoFontDescription *font = pango_font_description_from_string("Adwaita Mono, DejaVu Sans Mono, monospace");
pango_font_description_set_absolute_size(font, 23 * PANGO_SCALE);
Expand All @@ -799,10 +802,16 @@ draw_about(cairo_t *c, const Frame &f, State &s, const Texts &t)
pango_layout_set_text(layout, row.value.c_str(), -1);
int vw, vh;
pango_layout_get_pixel_size(layout, &vw, &vh);
cairo_restore(c);
const double vx = kColX + kColW - pad - 16 - vw;
set(c, kText);
cairo_save(c);
pico4_text::unmirror(c, vx, vw);
pango_cairo_update_layout(c, layout);
cairo_move_to(c, vx, ry + (rh - vh) / 2);
pango_cairo_show_layout(c, layout);
pico4_text::note(c, layout, vx, ry + (rh - vh) / 2, row.value);
cairo_restore(c);
pango_font_description_free(font);
g_object_unref(layout);
if (!row.note.empty()) {
Expand All @@ -823,7 +832,7 @@ draw_tab(cairo_surface_t *surface, State &s, const Texts &t, double now)
cairo_t *c = cairo_create(surface);
pico4_hits_clear(&s.hits);
Frame f{PICO4_SETTINGS_W, PICO4_SETTINGS_H, &s.hits, s.hover, s.pressed, now};
background(c, f);
background(c, f, t.rtl());
switch (s.page) {
case PICO4_SETTINGS_LENSES: draw_lenses(c, f, s, t); break;
case PICO4_SETTINGS_CONTROLLERS: draw_controllers(c, f, s, t); break;
Expand All @@ -842,7 +851,7 @@ draw_front(cairo_surface_t *surface, State &s, const Texts &t, double now)
cairo_t *c = cairo_create(surface);
pico4_hits_clear(&s.front_hits);
Frame f{PICO4_FRONT_W, PICO4_FRONT_H, &s.front_hits, s.front_hover, s.front_pressed, now};
background(c, f);
background(c, f, t.rtl());
pico4_pair_ui::Pairing p;
p.known = s.ctl.known;
p.left = s.ctl.left;
Expand Down Expand Up @@ -1153,7 +1162,8 @@ main(int argc, char **argv)
const double now = now_s();
vr::VREvent_t e;
while (overlay->PollNextOverlayEvent(tab, &e, sizeof(e))) {
const double x = e.data.mouse.x, y = PICO4_SETTINGS_H - e.data.mouse.y; // SteamVR's y points up
const double x = mirror_x(e.data.mouse.x, PICO4_SETTINGS_W, texts.rtl());
const double y = PICO4_SETTINGS_H - e.data.mouse.y; // SteamVR's y points up
switch (e.eventType) {
case vr::VREvent_MouseMove: {
const int at = pico4_hits_at(&s.hits, x, y);
Expand Down Expand Up @@ -1217,7 +1227,8 @@ main(int argc, char **argv)
}
const bool across = fabsf(dx) > fabsf(dy);
const int down = across ? 0 : -pico4_scroll_steps(&scroll_y, dy);
const int wider = across ? -pico4_scroll_steps(&scroll_x, dx) : 0;
// The knob follows the stick, on a mirrored page (its distance growing to the left) too.
const int wider = across ? (texts.rtl() ? 1 : -1) * pico4_scroll_steps(&scroll_x, dx) : 0;
if (s.page == PICO4_SETTINGS_ABOUT && down != 0) {
s.about.first = pico4_list_scroll(s.about.first, down, kAboutRows, 8);
tab_dirty = true;
Expand All @@ -1231,7 +1242,8 @@ main(int argc, char **argv)
}
}
while (overlay->PollNextOverlayEvent(front, &e, sizeof(e))) {
const double x = e.data.mouse.x, y = PICO4_FRONT_H - e.data.mouse.y;
const double x = mirror_x(e.data.mouse.x, PICO4_FRONT_W, texts.rtl());
const double y = PICO4_FRONT_H - e.data.mouse.y;
if (e.eventType == vr::VREvent_MouseMove) {
const int at = pico4_hits_at(&s.front_hits, x, y);
front_dirty = front_dirty || at != s.front_hover;
Expand Down
11 changes: 8 additions & 3 deletions phoenix/pico4-monado/pico4-onboarding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,15 @@ draw_wifi_step(cairo_t *c, const Frame &f, const State &s, const Texts &t)
}
const double tx = x + 24, tw = w - 48 - (name ? 0 : 56);
set(c, kText);
cairo_save(c);
pico4_text::unmirror(c, tx, tw); // the name or password reads left to right, as typed
const double drawn = shown.empty() ? 0 : pico4_text::field(c, shown, tx, fy + 20, tw, 28);
if (u.keyboard && std::fmod(f.now, 1.0) < 0.6) {
// The caret, blinking while the keyboard is up.
cairo_rectangle(c, tx + drawn + 3, fy + 18, 3, fh - 36);
cairo_fill(c);
}
cairo_restore(c);
if (!name) {
// Show the password: the eye in the field.
const bool hover = f.hover == kShowPassword || f.pressed == kShowPassword;
Expand Down Expand Up @@ -670,7 +673,7 @@ draw(cairo_surface_t *surface, State &s, const Texts &t, double now = 0)
cairo_t *c = cairo_create(surface);
pico4_hits_clear(&s.hits);
Frame f{PICO4_TOUR_W, PICO4_TOUR_H, &s.hits, s.hover, s.pressed, now};
background(c, f);
background(c, f, t.rtl());
draw_setup(c, f, s, t);
cairo_destroy(c);
cairo_surface_flush(surface);
Expand Down Expand Up @@ -1274,7 +1277,8 @@ main(int argc, char **argv)
if (!u.active) {
continue;
}
const double x = e.data.mouse.x, y = PICO4_TOUR_H - e.data.mouse.y; // SteamVR's y points up
const double x = mirror_x(e.data.mouse.x, PICO4_TOUR_W, texts.rtl());
const double y = PICO4_TOUR_H - e.data.mouse.y; // SteamVR's y points up
switch (e.eventType) {
case vr::VREvent_MouseMove: {
const int at = pico4_hits_at(&s.hits, x, y);
Expand Down Expand Up @@ -1321,7 +1325,8 @@ main(int argc, char **argv)
}
const bool across = fabsf(dx) > fabsf(dy);
const int down = across ? 0 : -pico4_scroll_steps(&scroll_y, dy);
const int wider = across ? -pico4_scroll_steps(&scroll_x, dx) : 0;
// The knob follows the stick, on a mirrored page (its distance growing to the left) too.
const int wider = across ? (texts.rtl() ? 1 : -1) * pico4_scroll_steps(&scroll_x, dx) : 0;
if (u.page == PICO4_SETUP_IPD && wider != 0) {
lens(wider);
} else if (down != 0 && list_count(u) > 0) {
Expand Down
3 changes: 3 additions & 0 deletions phoenix/pico4-monado/pico4_panels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ struct Texts
pico4_text::add_steam_fonts(steam);
}

//! Whether the language runs right to left, its pages mirrored (Steam's only one is Arabic).
bool rtl() const { return language == "arabic"; }

std::string our(const char *key) const
{
char out[1024];
Expand Down
77 changes: 65 additions & 12 deletions phoenix/pico4-monado/pico4_text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

namespace pico4_text {

enum Align
{
kStart, //!< left, or right in a right-to-left language
kCenter,
};

//! The fonts in order: the image's, then the Steam client's for every other script.
constexpr const char *kFamilies = "Adwaita Sans, Go Noto Kurrent-Regular, Go Noto Kurrent, Noto Sans, sans-serif";

Expand Down Expand Up @@ -47,6 +53,51 @@ add_steam_fonts(const std::string &steam)
return added;
}

/*!
* Whether @p c draws a mirrored page, a right-to-left language's: its x axis turned around, so that
* the pages lay out once, left to right, and read from the right in Arabic.
*/
inline bool
mirrored(cairo_t *c)
{
cairo_matrix_t m;
cairo_get_matrix(c, &m);
return m.xx < 0;
}

/*!
* On a mirrored page, turn the x axis back around inside the box from @p x, @p width wide: what is
* read or shows a real thing (a text, a picture) keeps its own orientation in the mirrored place.
*/
inline void
unmirror(cairo_t *c, double x, double width)
{
if (mirrored(c)) {
cairo_translate(c, 2 * x + width, 0);
cairo_scale(c, -1, 1);
}
}

/*!
* Lay @p layout (its text set) out from its start: on a mirrored page every line starts on the right, each
* paragraph in its own direction ("7.2.0-phoenix" keeps its order); elsewhere each paragraph in its own
* direction (@p natural, a right-to-left one from the right) or all from the left.
*/
inline void
start_side(PangoLayout *layout, bool rtl_page, bool natural, Align align)
{
pango_layout_set_auto_dir(layout, rtl_page || natural ? TRUE : FALSE);
if (align == kCenter) {
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
} else if (rtl_page) {
// Pango swaps left and right for a paragraph running against the layout's (left to right) base.
const bool rtl_text = pango_layout_get_direction(layout, 0) == PANGO_DIRECTION_RTL;
pango_layout_set_alignment(layout, rtl_text ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT);
} else {
pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
}
}

/*!
* Where the texts drawn while recording lie, in the surface's pixels: the renders check that no two
* overlap, as a long translation would make them.
Expand Down Expand Up @@ -118,12 +169,6 @@ overlaps(const char *page)
return n;
}

enum Align
{
kStart, //!< left, or right in a right-to-left language
kCenter,
};

/*!
* @p text at @p size px, wrapped to @p width, its first line's top at @p y; returns the height.
* @p measure only measures.
Expand All @@ -132,16 +177,18 @@ inline double
draw(cairo_t *c, const std::string &text, double x, double y, double width, double size, bool bold,
Align align = kStart, bool measure = false)
{
const bool rtl_page = mirrored(c);
cairo_save(c);
unmirror(c, x, width);
PangoLayout *layout = pango_cairo_create_layout(c);
PangoFontDescription *font = pango_font_description_from_string(kFamilies);
pango_font_description_set_absolute_size(font, size * PANGO_SCALE);
pango_font_description_set_weight(font, bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
pango_layout_set_font_description(layout, font);
pango_layout_set_width(layout, (int)(width * PANGO_SCALE));
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
pango_layout_set_alignment(layout, align == kCenter ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT);
pango_layout_set_auto_dir(layout, TRUE);
pango_layout_set_text(layout, text.c_str(), -1);
start_side(layout, rtl_page, true, align);
int w, h;
pango_layout_get_pixel_size(layout, &w, &h);
if (!measure) {
Expand All @@ -151,16 +198,20 @@ draw(cairo_t *c, const std::string &text, double x, double y, double width, doub
}
pango_font_description_free(font);
g_object_unref(layout);
cairo_restore(c);
return h;
}

/*!
* One line of @p text, cut with an ellipsis to @p width; with @p natural it starts on the right in a
* right-to-left language, else always on the left (rows of mixed scripts).
* One line of @p text, cut with an ellipsis to @p width; with @p natural a right-to-left text starts on
* the right, else on the left (rows of mixed scripts); on a mirrored page every line starts on the right.
*/
inline void
line(cairo_t *c, const std::string &text, double x, double y, double width, double size, bool bold, bool natural = true)
{
const bool rtl_page = mirrored(c);
cairo_save(c);
unmirror(c, x, width);
PangoLayout *layout = pango_cairo_create_layout(c);
PangoFontDescription *font = pango_font_description_from_string(kFamilies);
pango_font_description_set_absolute_size(font, size * PANGO_SCALE);
Expand All @@ -169,18 +220,20 @@ line(cairo_t *c, const std::string &text, double x, double y, double width, doub
pango_layout_set_width(layout, (int)(width * PANGO_SCALE));
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
pango_layout_set_single_paragraph_mode(layout, TRUE);
pango_layout_set_auto_dir(layout, natural ? TRUE : FALSE);
pango_layout_set_text(layout, text.c_str(), -1);
start_side(layout, rtl_page, natural, kStart);
cairo_move_to(c, x, y);
pango_cairo_show_layout(c, layout);
note(c, layout, x, y, text);
pango_font_description_free(font);
g_object_unref(layout);
cairo_restore(c);
}

/*!
* An input field's one line of @p text from the left, its end in view: what is wider than @p width
* leaves on the left, as a field scrolls while one types. Returns the width drawn, for the caret.
* leaves on the left, as a field scrolls while one types. Returns the width drawn, for the caret. A
* mirrored page unmirrors the field with its caret (a network's name and password read left to right).
*/
inline double
field(cairo_t *c, const std::string &text, double x, double y, double width, double size)
Expand Down
Loading