From 8b5cb2fa6e2de299b055b5d51845de899cf83086 Mon Sep 17 00:00:00 2001 From: Xenolphthalein <21215869+Xenolphthalein@users.noreply.github.com> Date: Thu, 3 Dec 2026 11:54:05 +0100 Subject: [PATCH] feat(pico4-monado): the setup and Overpressure Settings are mirrored in Arabic In a right-to-left language each page is drawn mirrored and the laser's x mirrored to match, so the pages lay out once: rows, the top bar's way back and its breadcrumb, tick boxes, sliders, buttons and lists read from the right. Texts, the headset's picture and the icons that show a thing keep their orientation; only the arrows that point a way turn. Every line starts on the right, each paragraph in its own direction ("7.2.0-phoenix" keeps its order); a network's name and password read left to right as typed. The thumbstick moves the lens slider's knob the way it is pushed. Left-to-right languages render byte for byte as before. For overpressure/phoenix#180 --- phoenix/pico4-monado/PKGBUILD | 10 +-- .../pico4-monado/overpressure-settings.cpp | 24 ++++-- phoenix/pico4-monado/pico4-onboarding.cpp | 11 ++- phoenix/pico4-monado/pico4_panels.hpp | 3 + phoenix/pico4-monado/pico4_text.hpp | 77 ++++++++++++++++--- phoenix/pico4-monado/pico4_ui.hpp | 35 ++++++++- 6 files changed, 131 insertions(+), 29 deletions(-) diff --git a/phoenix/pico4-monado/PKGBUILD b/phoenix/pico4-monado/PKGBUILD index 71839b7..796259a 100644 --- a/phoenix/pico4-monado/PKGBUILD +++ b/phoenix/pico4-monado/PKGBUILD @@ -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' diff --git a/phoenix/pico4-monado/overpressure-settings.cpp b/phoenix/pico4-monado/overpressure-settings.cpp index 388e8ed..2069dff 100644 --- a/phoenix/pico4-monado/overpressure-settings.cpp +++ b/phoenix/pico4-monado/overpressure-settings.cpp @@ -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); @@ -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()) { @@ -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; @@ -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; @@ -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); @@ -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; @@ -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; diff --git a/phoenix/pico4-monado/pico4-onboarding.cpp b/phoenix/pico4-monado/pico4-onboarding.cpp index 8032bea..c072d09 100644 --- a/phoenix/pico4-monado/pico4-onboarding.cpp +++ b/phoenix/pico4-monado/pico4-onboarding.cpp @@ -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; @@ -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); @@ -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); @@ -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) { diff --git a/phoenix/pico4-monado/pico4_panels.hpp b/phoenix/pico4-monado/pico4_panels.hpp index 61e6e64..c966a9c 100644 --- a/phoenix/pico4-monado/pico4_panels.hpp +++ b/phoenix/pico4-monado/pico4_panels.hpp @@ -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]; diff --git a/phoenix/pico4-monado/pico4_text.hpp b/phoenix/pico4-monado/pico4_text.hpp index 21662fc..7f40d8f 100644 --- a/phoenix/pico4-monado/pico4_text.hpp +++ b/phoenix/pico4-monado/pico4_text.hpp @@ -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"; @@ -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. @@ -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. @@ -132,6 +177,9 @@ 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); @@ -139,9 +187,8 @@ draw(cairo_t *c, const std::string &text, double x, double y, double width, doub 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) { @@ -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); @@ -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) diff --git a/phoenix/pico4-monado/pico4_ui.hpp b/phoenix/pico4-monado/pico4_ui.hpp index d146862..1e1bb0e 100644 --- a/phoenix/pico4-monado/pico4_ui.hpp +++ b/phoenix/pico4-monado/pico4_ui.hpp @@ -260,12 +260,18 @@ path(cairo_t *c, const char *d) } } -//! Icon @p i, @p size px square, its top left at (@p x, @p y), in @p colour. +/*! + * Icon @p i, @p size px square, its top left at (@p x, @p y), in @p colour. A mirrored page turns only + * the arrows that point a way (back, on); the others show things and keep their side. + */ inline void icon(cairo_t *c, Icon i, double x, double y, double size, Rgb colour) { cairo_save(c); cairo_new_path(c); + if (i != kRight && i != kLeft) { + pico4_text::unmirror(c, x, size); + } cairo_translate(c, x, y); cairo_scale(c, size / 24.0, size / 24.0); path(c, icon_path(i)); @@ -284,6 +290,8 @@ icon(cairo_t *c, Icon i, double x, double y, double size, Rgb colour) inline double text_width(cairo_t *c, const std::string &text, double size, bool bold) { + cairo_save(c); + pico4_text::unmirror(c, 0, 0); // measured as drawn, the right way round PangoLayout *layout = pango_cairo_create_layout(c); PangoFontDescription *font = pango_font_description_from_string(pico4_text::kFamilies); pango_font_description_set_absolute_size(font, size * PANGO_SCALE); @@ -294,6 +302,7 @@ text_width(cairo_t *c, const std::string &text, double size, bool bold) pango_layout_get_pixel_size(layout, &w, &h); pango_font_description_free(font); g_object_unref(layout); + cairo_restore(c); return w; } @@ -321,10 +330,12 @@ constexpr double kPanelR = 32; /*! * The panel's background, its corners round: outside them the panel is clear (SteamVR blends the - * texture's alpha), and all that is drawn after stays inside (the clip stays until the end). + * texture's alpha), and all that is drawn after stays inside (the clip stays until the end). With + * @p rtl (a right-to-left language) all that is drawn after is mirrored: the pages lay out once, and + * the laser's x is mirrored as well (mirror_x). */ inline void -background(cairo_t *c, const Frame &f) +background(cairo_t *c, const Frame &f, bool rtl = false) { cairo_set_operator(c, CAIRO_OPERATOR_CLEAR); cairo_paint(c); @@ -333,6 +344,17 @@ background(cairo_t *c, const Frame &f) cairo_clip(c); set(c, kBg); cairo_paint(c); + if (rtl) { + cairo_translate(c, f.w, 0); + cairo_scale(c, -1, 1); + } +} + +//! The laser's @p x on a panel @p w wide, where the page laid out left to right has it. +inline double +mirror_x(double x, double w, bool rtl) +{ + return rtl ? w - x : x; } /*! @@ -491,6 +513,9 @@ group_label(cairo_t *c, const std::string &text, double x, double y, double w) upper = u; g_free(u); set(c, kMuted); + const bool rtl_page = pico4_text::mirrored(c); + cairo_save(c); + pico4_text::unmirror(c, x, w); PangoLayout *layout = pango_cairo_create_layout(c); PangoFontDescription *font = pango_font_description_from_string(pico4_text::kFamilies); pango_font_description_set_absolute_size(font, kLabel * PANGO_SCALE); @@ -502,11 +527,14 @@ group_label(cairo_t *c, const std::string &text, double x, double y, double w) pango_attr_list_insert(attrs, pango_attr_letter_spacing_new((int)(kLabel * 0.06 * PANGO_SCALE))); pango_layout_set_attributes(layout, attrs); pango_layout_set_text(layout, upper.c_str(), -1); + pico4_text::start_side(layout, rtl_page, true, pico4_text::kStart); cairo_move_to(c, x, y); pango_cairo_show_layout(c, layout); + pico4_text::note(c, layout, x, y, upper); pango_attr_list_unref(attrs); pango_font_description_free(font); g_object_unref(layout); + cairo_restore(c); return kLabel * 1.4 + 8; } @@ -641,6 +669,7 @@ headset_art(cairo_t *c, double x, double y, double size) cairo_save(c); pico4_overlay::rounded(c, x, y, size, size, size * 0.23); cairo_clip(c); + pico4_text::unmirror(c, x, size); // the headset as it is if (art != nullptr) { RsvgRectangle box = {x, y, size, size}; rsvg_handle_render_document(art, c, &box, nullptr);