From 032431ce6a9d7a24c6170f37bbb8f60d7188741a Mon Sep 17 00:00:00 2001 From: seaweeduk <2912658+seaweeduk@users.noreply.github.com> Date: Sun, 22 Nov 2026 19:57:17 +0000 Subject: [PATCH] Refactor 1/6: groundwork for the restructure --- src/app_dirs.h | 13 ++ src/cairo_canvas.cpp | 11 +- src/cairo_canvas.h | 3 + src/control_map.h | 230 ++++++++++++++++++++++++++++++++++++ src/controls.cpp | 6 - src/controls.h | 223 +--------------------------------- src/density_map.h | 2 +- src/diagnostics.cpp | 1 + src/eye_state.h | 26 ++++ src/first_run.cpp | 2 +- src/flat_screen.h | 9 +- src/focus_controller.cpp | 21 ---- src/focus_controller.h | 8 -- src/focus_target.h | 2 +- src/folder_listing.cpp | 6 - src/folder_listing.h | 1 - src/foveation.h | 17 +-- src/foveation_level.h | 18 +++ src/frame_reuse.h | 2 +- src/gpu_context.cpp | 2 +- src/library.cpp | 2 +- src/library_index.cpp | 2 +- src/main.cpp | 2 +- src/media_server.cpp | 6 - src/media_server.h | 3 - src/menu.cpp | 52 ++++++-- src/menu.h | 225 ++++------------------------------- src/menu_hints.cpp | 2 +- src/menu_list_parts.cpp | 2 +- src/menu_parts.cpp | 31 ----- src/menu_setup.cpp | 14 +-- src/menu_setup.h | 4 +- src/menu_stash.cpp | 2 +- src/menu_stash_lists.cpp | 2 +- src/menu_video_settings.cpp | 2 +- src/menu_view.h | 209 ++++++++++++++++++++++++++++++++ src/notices.cpp | 1 + src/notices.h | 4 +- src/offline.cpp | 2 +- src/places.cpp | 2 +- src/places.h | 2 + src/playback_state.h | 45 +++++++ src/presets.cpp | 1 + src/remote.cpp | 2 +- src/screen_control.h | 4 +- src/script_player.h | 3 +- src/seek_preview.h | 1 - src/settings.cpp | 2 + src/settings.h | 17 +-- src/sftp.cpp | 2 +- src/stash.cpp | 2 +- src/stash_images.cpp | 19 --- src/stash_images.h | 7 -- src/stash_store.cpp | 2 +- src/strings.cpp | 7 -- src/strings.h | 8 +- src/strings_de.cpp | 12 -- src/strings_es.cpp | 12 -- src/strings_fr.cpp | 12 -- src/strings_ja.cpp | 12 -- src/strings_pt_br.cpp | 12 -- src/strings_zh_cn.cpp | 12 -- src/thumbnailer.cpp | 2 +- src/value_ranges.h | 28 +++-- src/video_memory.cpp | 2 +- src/video_memory.h | 7 +- src/video_player.h | 39 +----- src/vr_input.h | 2 +- src/xr_context.h | 26 +--- 69 files changed, 699 insertions(+), 775 deletions(-) create mode 100644 src/app_dirs.h create mode 100644 src/control_map.h create mode 100644 src/eye_state.h create mode 100644 src/foveation_level.h create mode 100644 src/menu_view.h create mode 100644 src/playback_state.h diff --git a/src/app_dirs.h b/src/app_dirs.h new file mode 100644 index 0000000..ff90992 --- /dev/null +++ b/src/app_dirs.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +// Where the player keeps its files: ~/.config/videoframevr (or under +// $XDG_CONFIG_HOME). A folder from the former name "vrplayer" is moved there. +std::filesystem::path configDir(); +// Where it keeps what it collects (the media library): ~/.local/share/videoframevr +// (or under $XDG_DATA_HOME). +std::filesystem::path dataDir(); +// Where it keeps what can be fetched again (Stash's images): ~/.cache/videoframevr +// (or under $XDG_CACHE_HOME). +std::filesystem::path cacheDir(); diff --git a/src/cairo_canvas.cpp b/src/cairo_canvas.cpp index a575b12..af0fd1a 100644 --- a/src/cairo_canvas.cpp +++ b/src/cairo_canvas.cpp @@ -45,8 +45,7 @@ CairoCanvas::~CairoCanvas() { if (spare_.image) uploader_->gpu().retire(spare_); } -bool CairoCanvas::init(Uploader& uploader, int width, int height, float scale, bool scrolls) { - uploader_ = &uploader; +bool CairoCanvas::init(int width, int height, float scale) { width_ = width; height_ = height; scale_ = scale; @@ -56,6 +55,12 @@ bool CairoCanvas::init(Uploader& uploader, int width, int height, float scale, b if (cairo_surface_status(surface_) != CAIRO_STATUS_SUCCESS) return false; cairo_surface_set_device_scale(surface_, scale, scale); cr_ = cairo_create(surface_); + return true; +} + +bool CairoCanvas::init(Uploader& uploader, int width, int height, float scale, bool scrolls) { + uploader_ = &uploader; + if (!init(width, height, scale)) return false; // Down to an eighth of the size at scale 1, a sixteenth at 2. const uint32_t full = @@ -90,6 +95,7 @@ void CairoCanvas::clear(int firstRow, int endRow) { } void CairoCanvas::upload(int firstRow, int endRow, int firstColumn, int endColumn) { + if (!uploader_) return; if (endRow < 0) endRow = height_; if (endColumn < 0) endColumn = width_; // In the surface's pixels. @@ -135,6 +141,7 @@ void CairoCanvas::finishUpdate() { } void CairoCanvas::shiftUp(int x0, int y0, int x1, int y1, double dy) { + if (!uploader_) return; if (!spare_.image) { std::fprintf(stderr, "CairoCanvas: shiftUp() on a canvas made without scrolling\n"); return; diff --git a/src/cairo_canvas.h b/src/cairo_canvas.h index 9c33493..7cf6b2d 100644 --- a/src/cairo_canvas.h +++ b/src/cairo_canvas.h @@ -30,6 +30,9 @@ class CairoCanvas { // pixels per unit (sharper text for the same drawing). scrolls: shiftUp() // is used, which needs a spare image of the same size. bool init(Uploader& uploader, int width, int height, float scale = 1.0f, bool scrolls = false); + // The surface alone, without an image: uploads and shifts are dropped and + // texture() has nothing (drawing and measuring without a GPU). + bool init(int width, int height, float scale = 1.0f); cairo_t* cr() const { return cr_; } cairo_surface_t* surface() const { return surface_; } diff --git a/src/control_map.h b/src/control_map.h new file mode 100644 index 0000000..a312390 --- /dev/null +++ b/src/control_map.h @@ -0,0 +1,230 @@ +#pragma once + +// The controllers' buttons, the jobs they can do and the gestures, and what +// the user chose for each controller type (ControlMap, GestureMap), as the +// settings keep them. The rest is in controls.h. + +#include +#include +#include +#include + +// The buttons OpenXR is asked for, one boolean action each, on both hands. +// The thumbstick (a vector) and the pointer's pose are read on their own. +enum class Control : uint8_t { + Trigger, Bumper, Grip, A, B, X, Y, Menu, View, DpadUp, DpadDown, DpadLeft, DpadRight, StickClick, + Count +}; +constexpr int kControls = static_cast(Control::Count); +constexpr uint32_t controlBit(Control c) { return 1u << static_cast(c); } + +// What a button can do, in the order the chooser shows them. +enum class Job : uint8_t { + None, + Menu, Recenter, Choose, + PlayPause, Stop, SkipBack, SkipForward, BigSkipBack, BigSkipForward, FrameBack, FrameForward, + PreviousChapter, NextChapter, FromStart, Scripts, + PreviousVideo, NextVideo, AfterVideo, RatingUp, RatingDown, DeleteVideo, + VolumeUp, VolumeDown, Mute, NextAudioTrack, Subtitles, + Passthrough, PeekRoom, SeeThrough, MatchRoom, RemoveBackground, ToneLook, TvGamma, Motion, ZoomIn, ZoomOut, + StereoFocus, ShowFocusTarget, ResetScreen, ResetPicture, + Count +}; +constexpr int kJobs = static_cast(Job::Count); + +// The controller types with a layout of their own, by OpenXR interaction +// profile. Others reach the app through SteamVR's remapping onto one of +// them. +enum class ControllerType : uint8_t { Frame, Index, Touch, Simple, Count }; +constexpr int kControllerTypes = static_cast(ControllerType::Count); + +// A changeable control of a type, alone or with grip held, as a menu +// command carries it (MenuCommand::option). +struct ControlSlot { + ControllerType type = ControllerType::Count; + int hand = 0; + Control control = Control::Count; + bool grip = false; + int pack() const { + return static_cast(type) << 6 | grip << 5 | hand << 4 | static_cast(control); + } + static ControlSlot unpack(int packed) { + return {static_cast(packed >> 6 & 7), packed >> 4 & 1, + static_cast(packed & 15), (packed >> 5 & 1) != 0}; + } + bool operator==(const ControlSlot& o) const { + return type == o.type && hand == o.hand && control == o.control && grip == o.grip; + } +}; + +// What each controller type's buttons do: the user's choices, else the +// layout's defaults. Kept in the settings as each type's changes. With +// that hand's grip held, a button does its grip job if it has one (none by +// default; Nothing is one), else its own. +class ControlMap { + public: + ControlMap(); + // Job::None for a control the type hasn't on that hand; on an unknown + // type, the trigger chooses and nothing else does anything. + Job job(ControllerType type, int hand, Control control) const; + // A changeable control's job; false if it is fixed or not there. + bool set(ControllerType type, int hand, Control control, Job job); + // How many of the type's controls do it. + int count(ControllerType type, Job job) const; + // A change Menu allows: it always keeps a button (one of them fixed, or + // the last one left). + bool allowed(ControllerType type, int hand, Control control, Job job) const; + // A grip job of its own (Nothing too), and which: Job::None without + // one. A stick's click (with grip held it clears a rating) and a button + // that chooses (with grip held it gives volume, as the trigger does) take + // none; a button's grip job goes when it is set to choose. + bool hasGrip(ControllerType type, int hand, Control control) const; + Job gripJob(ControllerType type, int hand, Control control) const; + bool takesGrip(ControllerType type, int hand, Control control) const; + bool setGrip(ControllerType type, int hand, Control control, Job job); + // Back to doing with grip held what it does alone. + bool clearGrip(ControllerType type, int hand, Control control); + // What a press does, with that hand's grip held or not. + Job pressJob(ControllerType type, int hand, Control control, bool gripHeld) const { + return gripHeld && hasGrip(type, hand, control) ? gripJob(type, hand, control) + : job(type, hand, control); + } + // A change of a slot's job, alone or with grip held. + bool set(const ControlSlot& s, Job job) { + return s.grip ? setGrip(s.type, s.hand, s.control, job) : set(s.type, s.hand, s.control, job); + } + // A button's jobs alone and with grip held (none of its own: -1) as one + // number, and those put back: an Undo's. + int button(ControllerType type, int hand, Control control) const; + bool restore(ControllerType type, int hand, Control control, int button); + // Every button alone and with grip held back to its default. + void reset(ControllerType type); + // The changes from the defaults as one line ("right_b_button:none,...", + // grip jobs as "grip_left_x_button:stop"), and such a line read: unknown + // controls and jobs are left out, so they keep their defaults. + std::string line(ControllerType type) const; + void read(ControllerType type, const std::string& line); + bool operator==(const ControlMap& o) const; + bool operator!=(const ControlMap& o) const { return !(*this == o); } + + private: + static constexpr uint8_t kDefault = 0xff; + uint8_t chosen_[kControllerTypes][2][kControls]; // a Job, or kDefault + uint8_t grip_[kControllerTypes][2][kControls]; // a Job, or kDefault: none + // Menu always keeps a button: a type's read without one gets the layout's. + void keepMenu(ControllerType type); +}; + +// How a gesture's hand moves while its buttons are held: only the wrist's +// twist for now. Saved by id, so others can be added. +enum class Movement : uint8_t { Twist, Count }; +constexpr int kMovements = static_cast(Movement::Count); +const char* movementId(Movement movement); + +// What a gesture changes: a value the menu also sets, in the chooser's +// order. +enum class GestureValue : uint8_t { + Volume, + Opacity, MatchBrightness, MatchColour, KeyStrength, KeyEdges, KeySpill, KeyShrink, + Brightness, Contrast, Saturation, Warmth, Tint, Exposure, Sharpen, Zoom, + Viewpoint, ScreenDistance, ScreenHeight, ScreenCurve, + Scrub, Rating, + ScriptTiming, + SubtitleSize, SubtitleRaise, SubtitleDistance, + Count +}; +constexpr int kGestureValues = static_cast(GestureValue::Count); + +// A gesture: one button, or two on one controller, held, and the hand's +// movement changes a value. The trigger is only ever the second; the +// trigger alone isn't one (it chooses and drags). +struct Gesture { + uint8_t hands = 0; // a bit per hand that does it: 1 left, 2 right, 3 either + Control first = Control::Count; + Control second = Control::Count; // Count: one button + Movement movement = Movement::Twist; + GestureValue value = GestureValue::Count; + + bool has(Control c) const { return c != Control::Count && (first == c || second == c); } + int controls() const { return second == Control::Count ? 1 : 2; } + // Its buttons as bits (controlBit()). + uint32_t bits() const { + return controlBit(first) | (second == Control::Count ? 0u : controlBit(second)); + } + // The same buttons and movement on a hand of both: one replaces the other. + bool sameHold(const Gesture& o) const { + return (hands & o.hands) != 0 && bits() == o.bits() && movement == o.movement; + } + // As a menu command carries it (MenuCommand::option, with the type). + int pack() const { + return static_cast(value) << 12 | static_cast(movement) << 10 | + static_cast(second) << 6 | static_cast(first) << 2 | hands; + } + static Gesture unpack(int packed) { + Gesture g; + g.hands = static_cast(packed & 3); + g.first = static_cast(packed >> 2 & 15); + g.second = static_cast(packed >> 6 & 15); + g.movement = static_cast(packed >> 10 & 3); + g.value = static_cast(packed >> 12 & 31); + return g; + } + bool operator==(const Gesture& o) const { + return hands == o.hands && first == o.first && second == o.second && movement == o.movement && + value == o.value; + } + bool operator!=(const Gesture& o) const { return !(*this == o); } +}; +constexpr int kMaxGestures = 12; // a controller type's + +// Each controller type's gestures: the user's, else the layout's defaults. +// Kept in the settings as a type's whole list once it differs from them. +// Each type's list is shared between copies until one of them changes, so +// the menu's copy each frame costs no more than a pointer's. +class GestureMap { + public: + GestureMap(); + const std::vector& list(ControllerType type) const; + static const std::vector& defaults(ControllerType type); + // Whether the type can have it: a known value and movement, its buttons + // on each of its hands and changeable or the grip, the trigger only + // second, not one button twice. + static bool valid(ControllerType type, const Gesture& g); + // A new one, in place of any with the same hold (those go into + // `replaced`, for Undo; one of either hand's stays on the hand `g` leaves + // it); false if it isn't valid, or that would be more than kMaxGestures or + // than its column has room for. + bool add(ControllerType type, const Gesture& g, std::vector* replaced = nullptr); + // The index-th changed into `g` (another value, or other buttons), also in + // place of any other with its hold, as add() does; `replaced` gets the old + // one first. + bool replace(ControllerType type, size_t index, const Gesture& g, + std::vector* replaced = nullptr); + bool remove(ControllerType type, size_t index); + // A list put back (Undo); those not valid are left out. + void restore(ControllerType type, const std::vector& gestures); + void reset(ControllerType type); // the defaults again + bool full(ControllerType type) const { return list(type).size() >= kMaxGestures; } + // The gesture of exactly these buttons on that hand (b: Count for one), or null. + const Gesture* find(ControllerType type, int hand, Control a, Control b = Control::Count, + Movement movement = Movement::Twist) const; + // A press of `control` on that hand waits to do its job until it is let go + // (and does it only if no gesture got under way meanwhile): it is a + // gesture's button, with the grip only while that is held (`held`: + // controlBit()s). Never the trigger's. + bool tapOnRelease(ControllerType type, int hand, Control control, uint32_t held) const; + // The list as one line ("right:y_button:twist:opacity,either:grip+trigger: + // twist:volume"); "none" without any. line() is empty while it is the + // defaults. A line read: entries with unknown ids, or not valid, are left + // out; an empty one is the defaults. + std::string line(ControllerType type) const; + std::string listLine(ControllerType type) const; + void read(ControllerType type, const std::string& line); + bool operator==(const GestureMap& o) const; + bool operator!=(const GestureMap& o) const { return !(*this == o); } + + private: + using List = std::shared_ptr>; + static const List& defaultList(ControllerType type); + List lists_[kControllerTypes]; +}; diff --git a/src/controls.cpp b/src/controls.cpp index e51cf6c..538f655 100644 --- a/src/controls.cpp +++ b/src/controls.cpp @@ -938,12 +938,6 @@ void GestureMap::reset(ControllerType type) { if (type != ControllerType::Count) lists_[static_cast(type)] = defaultList(type); } -bool GestureMap::hasGesture(ControllerType type, int hand, Control control) const { - for (const Gesture& g : list(type)) - if ((g.hands >> hand & 1) && g.has(control)) return true; - return false; -} - const Gesture* GestureMap::find(ControllerType type, int hand, Control a, Control b, Movement movement) const { const uint32_t bits = controlBit(a) | (b == Control::Count ? 0u : controlBit(b)); diff --git a/src/controls.h b/src/controls.h index 9abdfa0..2f08a8a 100644 --- a/src/controls.h +++ b/src/controls.h @@ -11,47 +11,24 @@ // control: a Control, its entry in kControlTable and its paths in the // layouts that have it. +#include "control_map.h" #include "controller_guide.h" #include "controller_state.h" #include "menu_command.h" #include "value_ranges.h" #include -#include #include #include struct Strings; -// The buttons OpenXR is asked for, one boolean action each, on both hands. -// The thumbstick (a vector) and the pointer's pose are read on their own. -enum class Control : uint8_t { - Trigger, Bumper, Grip, A, B, X, Y, Menu, View, DpadUp, DpadDown, DpadLeft, DpadRight, StickClick, - Count -}; -constexpr int kControls = static_cast(Control::Count); -constexpr uint32_t controlBit(Control c) { return 1u << static_cast(c); } - struct ControlInfo { const char* id; // the OpenXR action's name, and the saved bindings' const char* name; // the action's localized name }; const ControlInfo& controlInfo(Control control); -// What a button can do, in the order the chooser shows them. -enum class Job : uint8_t { - None, - Menu, Recenter, Choose, - PlayPause, Stop, SkipBack, SkipForward, BigSkipBack, BigSkipForward, FrameBack, FrameForward, - PreviousChapter, NextChapter, FromStart, Scripts, - PreviousVideo, NextVideo, AfterVideo, RatingUp, RatingDown, DeleteVideo, - VolumeUp, VolumeDown, Mute, NextAudioTrack, Subtitles, - Passthrough, PeekRoom, SeeThrough, MatchRoom, RemoveBackground, ToneLook, TvGamma, Motion, ZoomIn, ZoomOut, - StereoFocus, ShowFocusTarget, ResetScreen, ResetPicture, - Count -}; -constexpr int kJobs = static_cast(Job::Count); - // The chooser's sections (Nothing is in none). enum class JobSection : uint8_t { None, General, Playback, Videos, Sound, Picture }; // What a job needs to do anything: nothing, a file open (a video or a @@ -82,12 +59,6 @@ std::string skipLength(int seconds, const Strings& t); const char* jobTip(Job job, const Strings& t); const char* jobSectionTitle(JobSection section, const Strings& t); -// The controller types with a layout of their own, by OpenXR interaction -// profile. Others reach the app through SteamVR's remapping onto one of -// them. -enum class ControllerType : uint8_t { Frame, Index, Touch, Simple, Count }; -constexpr int kControllerTypes = static_cast(ControllerType::Count); - struct LayoutControl { Control control; int hand; // 0 left, 1 right @@ -109,103 +80,6 @@ ControllerType controllerTypeById(const std::string& id); // them and their glyphs (loadControllerArt()). ControllerBindings layoutSources(ControllerType type); -// A changeable control of a type, alone or with grip held, as a menu -// command carries it (MenuCommand::option). -struct ControlSlot { - ControllerType type = ControllerType::Count; - int hand = 0; - Control control = Control::Count; - bool grip = false; - int pack() const { - return static_cast(type) << 6 | grip << 5 | hand << 4 | static_cast(control); - } - static ControlSlot unpack(int packed) { - return {static_cast(packed >> 6 & 7), packed >> 4 & 1, - static_cast(packed & 15), (packed >> 5 & 1) != 0}; - } - bool operator==(const ControlSlot& o) const { - return type == o.type && hand == o.hand && control == o.control && grip == o.grip; - } -}; - -// What each controller type's buttons do: the user's choices, else the -// layout's defaults. Kept in the settings as each type's changes. With -// that hand's grip held, a button does its grip job if it has one (none by -// default; Nothing is one), else its own. -class ControlMap { - public: - ControlMap(); - // Job::None for a control the type hasn't on that hand; on an unknown - // type, the trigger chooses and nothing else does anything. - Job job(ControllerType type, int hand, Control control) const; - // A changeable control's job; false if it is fixed or not there. - bool set(ControllerType type, int hand, Control control, Job job); - // How many of the type's controls do it. - int count(ControllerType type, Job job) const; - // A change Menu allows: it always keeps a button (one of them fixed, or - // the last one left). - bool allowed(ControllerType type, int hand, Control control, Job job) const; - // A grip job of its own (Nothing too), and which: Job::None without - // one. A stick's click (with grip held it clears a rating) and a button - // that chooses (with grip held it gives volume, as the trigger does) take - // none; a button's grip job goes when it is set to choose. - bool hasGrip(ControllerType type, int hand, Control control) const; - Job gripJob(ControllerType type, int hand, Control control) const; - bool takesGrip(ControllerType type, int hand, Control control) const; - bool setGrip(ControllerType type, int hand, Control control, Job job); - // Back to doing with grip held what it does alone. - bool clearGrip(ControllerType type, int hand, Control control); - // What a press does, with that hand's grip held or not. - Job pressJob(ControllerType type, int hand, Control control, bool gripHeld) const { - return gripHeld && hasGrip(type, hand, control) ? gripJob(type, hand, control) - : job(type, hand, control); - } - // A change of a slot's job, alone or with grip held. - bool set(const ControlSlot& s, Job job) { - return s.grip ? setGrip(s.type, s.hand, s.control, job) : set(s.type, s.hand, s.control, job); - } - // A button's jobs alone and with grip held (none of its own: -1) as one - // number, and those put back: an Undo's. - int button(ControllerType type, int hand, Control control) const; - bool restore(ControllerType type, int hand, Control control, int button); - // Every button alone and with grip held back to its default. - void reset(ControllerType type); - // The changes from the defaults as one line ("right_b_button:none,...", - // grip jobs as "grip_left_x_button:stop"), and such a line read: unknown - // controls and jobs are left out, so they keep their defaults. - std::string line(ControllerType type) const; - void read(ControllerType type, const std::string& line); - bool operator==(const ControlMap& o) const; - bool operator!=(const ControlMap& o) const { return !(*this == o); } - - private: - static constexpr uint8_t kDefault = 0xff; - uint8_t chosen_[kControllerTypes][2][kControls]; // a Job, or kDefault - uint8_t grip_[kControllerTypes][2][kControls]; // a Job, or kDefault: none - // Menu always keeps a button: a type's read without one gets the layout's. - void keepMenu(ControllerType type); -}; - -// How a gesture's hand moves while its buttons are held: only the wrist's -// twist for now. Saved by id, so others can be added. -enum class Movement : uint8_t { Twist, Count }; -constexpr int kMovements = static_cast(Movement::Count); -const char* movementId(Movement movement); - -// What a gesture changes: a value the menu also sets, in the chooser's -// order. -enum class GestureValue : uint8_t { - Volume, - Opacity, MatchBrightness, MatchColour, KeyStrength, KeyEdges, KeySpill, KeyShrink, - Brightness, Contrast, Saturation, Warmth, Tint, Exposure, Sharpen, Zoom, - Viewpoint, ScreenDistance, ScreenHeight, ScreenCurve, - Scrub, Rating, - ScriptTiming, - SubtitleSize, SubtitleRaise, SubtitleDistance, - Count -}; -constexpr int kGestureValues = static_cast(GestureValue::Count); - // The value chooser's sections. enum class GestureSection : uint8_t { Sound, Room, Picture, Place, Playback, Funscripts, Subtitles, Count }; // Where a value can be changed: anywhere, with a video or photo open, a @@ -246,47 +120,6 @@ std::string gestureValueLabel(GestureValue value, const Strings& t); // and Rating's are drawn otherwise. std::string gestureValueText(GestureValue value, double number); -// A gesture: one button, or two on one controller, held, and the hand's -// movement changes a value. The trigger is only ever the second; the -// trigger alone isn't one (it chooses and drags). -struct Gesture { - uint8_t hands = 0; // a bit per hand that does it: 1 left, 2 right, 3 either - Control first = Control::Count; - Control second = Control::Count; // Count: one button - Movement movement = Movement::Twist; - GestureValue value = GestureValue::Count; - - bool has(Control c) const { return c != Control::Count && (first == c || second == c); } - int controls() const { return second == Control::Count ? 1 : 2; } - // Its buttons as bits (controlBit()). - uint32_t bits() const { - return controlBit(first) | (second == Control::Count ? 0u : controlBit(second)); - } - // The same buttons and movement on a hand of both: one replaces the other. - bool sameHold(const Gesture& o) const { - return (hands & o.hands) != 0 && bits() == o.bits() && movement == o.movement; - } - // As a menu command carries it (MenuCommand::option, with the type). - int pack() const { - return static_cast(value) << 12 | static_cast(movement) << 10 | - static_cast(second) << 6 | static_cast(first) << 2 | hands; - } - static Gesture unpack(int packed) { - Gesture g; - g.hands = static_cast(packed & 3); - g.first = static_cast(packed >> 2 & 15); - g.second = static_cast(packed >> 6 & 15); - g.movement = static_cast(packed >> 10 & 3); - g.value = static_cast(packed >> 12 & 31); - return g; - } - bool operator==(const Gesture& o) const { - return hands == o.hands && first == o.first && second == o.second && movement == o.movement && - value == o.value; - } - bool operator!=(const Gesture& o) const { return !(*this == o); } -}; -constexpr int kMaxGestures = 12; // a controller type's // Settings' Controls lists a type's gestures in three columns of // kGestureRows rows: the left controller's (0), either's (1) and the right // one's (2). Either's starts with the gestures that can't be changed and @@ -295,60 +128,6 @@ constexpr int kGestureRows = 11; int gestureColumn(const Gesture& g); int gestureColumnRoom(ControllerType type, int column); -// Each controller type's gestures: the user's, else the layout's defaults. -// Kept in the settings as a type's whole list once it differs from them. -// Each type's list is shared between copies until one of them changes, so -// the menu's copy each frame costs no more than a pointer's. -class GestureMap { - public: - GestureMap(); - const std::vector& list(ControllerType type) const; - static const std::vector& defaults(ControllerType type); - // Whether the type can have it: a known value and movement, its buttons - // on each of its hands and changeable or the grip, the trigger only - // second, not one button twice. - static bool valid(ControllerType type, const Gesture& g); - // A new one, in place of any with the same hold (those go into - // `replaced`, for Undo; one of either hand's stays on the hand `g` leaves - // it); false if it isn't valid, or that would be more than kMaxGestures or - // than its column has room for. - bool add(ControllerType type, const Gesture& g, std::vector* replaced = nullptr); - // The index-th changed into `g` (another value, or other buttons), also in - // place of any other with its hold, as add() does; `replaced` gets the old - // one first. - bool replace(ControllerType type, size_t index, const Gesture& g, - std::vector* replaced = nullptr); - bool remove(ControllerType type, size_t index); - // A list put back (Undo); those not valid are left out. - void restore(ControllerType type, const std::vector& gestures); - void reset(ControllerType type); // the defaults again - bool full(ControllerType type) const { return list(type).size() >= kMaxGestures; } - // A button that is one of a gesture's on that hand (the Controls page marks it). - bool hasGesture(ControllerType type, int hand, Control control) const; - // The gesture of exactly these buttons on that hand (b: Count for one), or null. - const Gesture* find(ControllerType type, int hand, Control a, Control b = Control::Count, - Movement movement = Movement::Twist) const; - // A press of `control` on that hand waits to do its job until it is let go - // (and does it only if no gesture got under way meanwhile): it is a - // gesture's button, with the grip only while that is held (`held`: - // controlBit()s). Never the trigger's. - bool tapOnRelease(ControllerType type, int hand, Control control, uint32_t held) const; - // The list as one line ("right:y_button:twist:opacity,either:grip+trigger: - // twist:volume"); "none" without any. line() is empty while it is the - // defaults. A line read: entries with unknown ids, or not valid, are left - // out; an empty one is the defaults. - std::string line(ControllerType type) const; - std::string listLine(ControllerType type) const; - void read(ControllerType type, const std::string& line); - bool operator==(const GestureMap& o) const; - bool operator!=(const GestureMap& o) const { return !(*this == o); } - - private: - using List = std::shared_ptr>; - static const List& defaultList(ControllerType type); - List lists_[kControllerTypes]; -}; - // A button of the gesture that chooses on that hand (with grip held where // the gesture has the grip), the trigger aside, else Control::Count. It // selects as it goes down, as the trigger does, so the gesture doesn't run diff --git a/src/density_map.h b/src/density_map.h index 61bc77f..36e90f6 100644 --- a/src/density_map.h +++ b/src/density_map.h @@ -1,6 +1,6 @@ #pragma once -#include "foveation.h" +#include "foveation_level.h" #include "tile_grid.h" #include diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index ab9e9c7..60b489c 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -3,6 +3,7 @@ #include "media_server.h" #include "platform.h" #include "run_log.h" +#include "app_dirs.h" #include "settings.h" #include diff --git a/src/eye_state.h b/src/eye_state.h new file mode 100644 index 0000000..bcf309d --- /dev/null +++ b/src/eye_state.h @@ -0,0 +1,26 @@ +#pragma once + +#include "xmath.h" + +struct EyeMatrices { + Mat4 projection; + Mat4 view; + // The same view as raw orientation + field-of-view tangents, for shaders + // that compute a view ray per pixel. + Quat orientation; + Vec3 position; + float tanLeft = 0, tanRight = 0, tanUp = 0, tanDown = 0; +}; + +// Eye gaze from XR_EXT_eye_gaze_interaction (Steam Frame), updated by beginFrame(). +struct GazeState { + bool available = false; // the runtime offers it and the system supports it + bool active = false; // the input is bound and delivering (permission, tracker on) + bool valid = false; // a pose this frame + bool tracked = false; // ... measured, not estimated + Vec3 origin; // local space + Quat orientation; // the gaze looks along -Z of this orientation + bool ageKnown = false; + double ageSeconds = 0; // sample time before the frame's display time (negative: predicted) + double sampleSeconds = 0; // the sample time itself (XrTime in seconds) +}; diff --git a/src/first_run.cpp b/src/first_run.cpp index 84437a9..b7d27ad 100644 --- a/src/first_run.cpp +++ b/src/first_run.cpp @@ -1,7 +1,7 @@ #include "first_run.h" #include "file_util.h" -#include "settings.h" +#include "app_dirs.h" #include #include diff --git a/src/flat_screen.h b/src/flat_screen.h index 0d06d2e..6b2a576 100644 --- a/src/flat_screen.h +++ b/src/flat_screen.h @@ -1,5 +1,6 @@ #pragma once +#include "value_ranges.h" #include "xmath.h" #include @@ -10,9 +11,11 @@ // Screen distance, height and curve, with their defaults and limits. // The width follows from the picture's shape. struct ScreenSize { - static constexpr float kMinDistance = 0.1f, kMaxDistance = 11.0f; // meters - static constexpr float kMinHeight = 0.1f, kMaxHeight = 11.0f; // meters - static constexpr float kMaxCurve = 1.0f; + static constexpr float kMinDistance = value_range::kMinScreenDistance, + kMaxDistance = value_range::kMaxScreenDistance; // meters + static constexpr float kMinHeight = value_range::kMinScreenHeight, + kMaxHeight = value_range::kMaxScreenHeight; // meters + static constexpr float kMaxCurve = value_range::kMaxScreenCurve; float distance = 3.0f; // meters from the viewer to the screen's centre float height = 3.0f; // meters diff --git a/src/focus_controller.cpp b/src/focus_controller.cpp index 31952d0..6f4970a 100644 --- a/src/focus_controller.cpp +++ b/src/focus_controller.cpp @@ -13,35 +13,17 @@ constexpr float kRate = 4.0f; // per second at transition speed 1 constexpr float kPursuit = 0.01f, kMaxPursuitGain = 4.0f; constexpr float kMinDistance = 0.01f; -FocusReason reasonOf(DepthStatus s) { - switch (s) { - case DepthStatus::Ok: return FocusReason::None; - case DepthStatus::Blank: return FocusReason::Blank; - case DepthStatus::Ambiguous: return FocusReason::Ambiguous; - case DepthStatus::Mismatch: return FocusReason::Mismatch; - case DepthStatus::Edge: return FocusReason::Edge; - case DepthStatus::Clear: return FocusReason::Clear; - } - return FocusReason::Mismatch; -} - } // namespace void FocusController::clearProbes() { probes_[0] = probes_[1] = probes_[2] = 0; phase_ = 0; phaseStep_ = 1; - state_.locked = false; } void FocusController::submit(const DepthEstimate& e, int phase) { const bool ok = e.status == DepthStatus::Ok; probes_[std::clamp(phase, -1, 1) + 1] = ok ? e.angle : 0.0f; - if (phase == 0) { - state_.reason = reasonOf(e.status); - state_.measured = ok ? e.distance : 0.0f; - state_.confidence = e.confidence; - } if (phase_ == 1) phaseStep_ = -1; if (phase_ == -1) phaseStep_ = 1; phase_ += phaseStep_; @@ -57,9 +39,6 @@ void FocusController::submit(const DepthEstimate& e, int phase) { if (d < kAgreement && (minus <= 0 || std::abs(minus - accepted_) > d) && (plus <= 0 || std::abs(plus - accepted_) > d)) { accepted_ = center; - state_.locked = true; - } else if (phase == 0 && ok && d >= kAgreement) { - state_.reason = FocusReason::Disagree; } } diff --git a/src/focus_controller.h b/src/focus_controller.h index 43a486a..6f02609 100644 --- a/src/focus_controller.h +++ b/src/focus_controller.h @@ -3,9 +3,6 @@ #include "depth_estimator.h" #include "focus_settings.h" -// Why the last measurement did not change the focus (None: it could). -enum class FocusReason { None, Blank, Ambiguous, Mismatch, Edge, Clear, Disagree, OutOfRange }; - // Focus selection (docs/autofocus.md): // measurements come from three probes taken in turn (+1, 0, -1, 0, ...; the // probe directions are spread apart, less so the higher the sensitivity). @@ -18,11 +15,7 @@ enum class FocusReason { None, Blank, Ambiguous, Mismatch, Edge, Clear, Disagree class FocusController { public: struct State { - bool locked = false; // an angle was accepted since the probes were cleared bool holding = false; // the accepted depth is nearer than the range: the focus holds - FocusReason reason = FocusReason::None; - float measured = 0; // meters, the last probe's depth (0 = none) - float confidence = 0; float distance = 0; // meters, what the correction uses now }; @@ -35,7 +28,6 @@ class FocusController { // Advances the filter to `now`; returns the distance to correct at (meters). // eyes: aimed by the eyes, small changes are followed faster. float advance(const FocusSettings& s, double now, bool eyes); - const State& state() const { return state_; } // The half-convergence angle (radians) the focus holds to, DepthRequest::held: // the accepted one, or the shown one while an accepted one nearer than the // range is not followed. diff --git a/src/focus_target.h b/src/focus_target.h index 87ee698..3637723 100644 --- a/src/focus_target.h +++ b/src/focus_target.h @@ -1,9 +1,9 @@ #pragma once #include "autofocus.h" +#include "eye_state.h" #include "gaze_correction.h" #include "xmath.h" -#include "xr_context.h" // What the automatic focus is aimed by, as the menu tells it. enum class TargetStatus { diff --git a/src/folder_listing.cpp b/src/folder_listing.cpp index 73befc7..b394409 100644 --- a/src/folder_listing.cpp +++ b/src/folder_listing.cpp @@ -243,9 +243,3 @@ bool FolderListing::matches(const Entry& entry, const std::string& query) { } return true; } - -int FolderListing::matchCount(const std::string& query) const { - int n = 0; - for (const Entry& entry : entries_) n += matches(entry, query); - return n; -} diff --git a/src/folder_listing.h b/src/folder_listing.h index 1f173b5..698997f 100644 --- a/src/folder_listing.h +++ b/src/folder_listing.h @@ -56,7 +56,6 @@ class FolderListing { // Whether the entry's name holds all words of `query`, ignoring case, // punctuation and a file's extension. An empty query matches everything. static bool matches(const Entry& entry, const std::string& query); - int matchCount(const std::string& query) const; private: struct Pending; diff --git a/src/foveation.h b/src/foveation.h index 2392175..a9059f1 100644 --- a/src/foveation.h +++ b/src/foveation.h @@ -1,5 +1,7 @@ #pragma once +#include "foveation_level.h" + #include #include @@ -9,21 +11,6 @@ class XrContext; struct GazeFit; struct Quat; -// How much the eye images are foveated on the Steam Frame -// (docs/vulkan-renderer.md, 5): full detail where you look, coarser shading -// further out. Persisted by name (settings.cpp). -enum class FoveationLevel { Off, Low, Medium, High, Custom }; - -constexpr int kDefaultSharpBins = 1; -constexpr bool kDefaultFoveationRing = true; - -const char* foveationLevelName(FoveationLevel level); -bool parseFoveationLevel(const std::string& name, FoveationLevel& level); -void foveationPreset(FoveationLevel level, int& sharpBins, bool& ring, int& outside); -FoveationLevel foveationLevel(bool enabled, int sharpBins, bool ring, int outside); -// Off, followed by the eight combinations of sharp area, ring and outside. -int foveationMapIndex(bool enabled, int sharpBins, bool ring, int outside); - // Where the sharp area goes: where SteamVR's eye tracking puts it, straight // ahead, or a fixed point (NDC, +y down) for repeatable headset runs // (--foveation-gaze). diff --git a/src/foveation_level.h b/src/foveation_level.h new file mode 100644 index 0000000..1c0ca41 --- /dev/null +++ b/src/foveation_level.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +// How much the eye images are foveated on the Steam Frame +// (docs/vulkan-renderer.md, 5): full detail where you look, coarser shading +// further out. Persisted by name (settings.cpp). +enum class FoveationLevel { Off, Low, Medium, High, Custom }; + +constexpr int kDefaultSharpBins = 1; +constexpr bool kDefaultFoveationRing = true; + +const char* foveationLevelName(FoveationLevel level); +bool parseFoveationLevel(const std::string& name, FoveationLevel& level); +void foveationPreset(FoveationLevel level, int& sharpBins, bool& ring, int& outside); +FoveationLevel foveationLevel(bool enabled, int sharpBins, bool ring, int outside); +// Off, followed by the eight combinations of sharp area, ring and outside. +int foveationMapIndex(bool enabled, int sharpBins, bool ring, int outside); diff --git a/src/frame_reuse.h b/src/frame_reuse.h index fdc06b3..c09e28e 100644 --- a/src/frame_reuse.h +++ b/src/frame_reuse.h @@ -1,7 +1,7 @@ #pragma once +#include "eye_state.h" #include "scene_renderer.h" -#include "xr_context.h" #include diff --git a/src/gpu_context.cpp b/src/gpu_context.cpp index 357c90c..d5b7048 100644 --- a/src/gpu_context.cpp +++ b/src/gpu_context.cpp @@ -1,6 +1,6 @@ #include "gpu_context.h" -#include "settings.h" +#include "app_dirs.h" #include diff --git a/src/library.cpp b/src/library.cpp index bff0e6a..0a39bcd 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -4,7 +4,7 @@ #include "file_util.h" #include "library_schema.h" // kLibrarySchema, made from library_schema.sql at build time #include "oshash.h" -#include "settings.h" // dataDir +#include "app_dirs.h" #include #include diff --git a/src/library_index.cpp b/src/library_index.cpp index f15db9b..76898f1 100644 --- a/src/library_index.cpp +++ b/src/library_index.cpp @@ -1,7 +1,7 @@ #include "library_index.h" #include "file_util.h" -#include "settings.h" // dataDir +#include "app_dirs.h" #include "remote.h" #include "stash_catalog.h" diff --git a/src/main.cpp b/src/main.cpp index 552782a..d1cf2c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "anti_shimmer.h" +#include "app_dirs.h" #include "autofocus.h" #include "bluray.h" #include "direct_depth.h" @@ -4397,7 +4398,6 @@ int run(Options opts) { view.resolutionOverride = overrideScale > 0 ? static_cast(std::floor(resolutionBase * overrideScale)) : 0; view.resolutionBase = resolutionBase; - view.panelBase = kPanelWidth > 0; view.foveationAvailable = foveation.active(); view.foveation = foveation.level(); view.showFoveation = showFoveation; diff --git a/src/media_server.cpp b/src/media_server.cpp index 286f761..39bb0e5 100644 --- a/src/media_server.cpp +++ b/src/media_server.cpp @@ -25,12 +25,6 @@ const MediaServer& mediaServer(ServerKind kind) { return *mediaServers().front(); } -ServerKind serverKindOf(std::string_view id) { - for (const MediaServer* server : mediaServers()) - if (id == server->id()) return server->kind(); - return mediaServers().front()->kind(); -} - std::string mediaServerNames(const std::string& between) { std::string names; for (const MediaServer* server : mediaServers()) { diff --git a/src/media_server.h b/src/media_server.h index c15c54a..40ad6d4 100644 --- a/src/media_server.h +++ b/src/media_server.h @@ -102,9 +102,6 @@ std::string serverIdentity(ServerKind kind, const std::string& server); bool originalKind(ServerKind kind); // Every kind, in the order an address is tried as each (findServer()). const std::vector& mediaServers(); -// The kind with this id(); Stash's for any other, as settings from before -// there were kinds have none. -ServerKind serverKindOf(std::string_view id); // Every kind's name, "Stash / XBVR": Settings' name for its servers' // section. In a sentence they are named with the language's "or" between // (StashSetupStrings::orKind), as no server is set up yet. diff --git a/src/menu.cpp b/src/menu.cpp index 262d8aa..b0b2145 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -54,10 +54,46 @@ Menu::~Menu() { bool Menu::init(Uploader& uploader) { uploader_ = &uploader; + return init(); +} + +bool Menu::init() { refreshPlaces(); - return canvases_[kMain].init(uploader, kMainWidth, kMainHeight, menu_geometry::kRasterScale) && - canvases_[kBrowser].init(uploader, kBrowserWidth, kBrowserHeight, - menu_geometry::kRasterScale, true); + return initCanvas(canvases_[kMain], kMainWidth, kMainHeight, menu_geometry::kRasterScale) && + initCanvas(canvases_[kBrowser], kBrowserWidth, kBrowserHeight, menu_geometry::kRasterScale, true); +} + +bool Menu::initCanvas(CairoCanvas& canvas, int width, int height, float scale, bool scrolls) { + return uploader_ ? canvas.init(*uploader_, width, height, scale, scrolls) : canvas.init(width, height, scale); +} + +void Menu::draw(PanelId panel, cairo_t* cr) { + if (panel == kSetup) + SetupPages::draw(*this, cr); + else if (panel == kMain) + drawMain(cr); + else + drawBrowser(cr); +} + +const std::vector& Menu::layOut() { + if (setup_) + SetupPages::layout(*this); + else + layout(true); + return buttons_; +} + +bool Menu::working() const { + if (!places_.ready() || places_.looking() || listing_.reading() || discovery_.scanning()) return true; + if ((controls_ && controls_->loading.running()) || (hints_ && hints_->loading.running())) return true; + if (!setup_) return false; + if (setup_->controls.loading.running()) return true; + if (!setup_->folders) return false; + if (setup_->folders->finding.running()) return true; + for (const auto& [path, folder] : setup_->folders->folders) + if (folder.reading.running()) return true; + return false; } bool Menu::hoverRect(PanelId panel, float rect[4], float& radius, bool& danger, float clip[4]) const { @@ -124,15 +160,6 @@ bool Menu::pointedButton() const { buttons_[hovered_].ratingPath.empty(); } -std::array Menu::linearAccent(const AccentColours& accent) { - std::array rgb; - for (int i = 0; i < 3; ++i) { - const double c = accent.fill[i]; - rgb[i] = static_cast(c <= 0.04045 ? c / 12.92 : std::pow((c + 0.055) / 1.055, 2.4)); - } - return rgb; -} - void Menu::languageChanged() { dirty_ = true; if (setup_) setup_->cuesDrawn = false; @@ -302,7 +329,6 @@ void Menu::update(const MenuView& view) { if (view.appFps != view_.appFps) stripDirty_ = true; if (accent != view_.accent) { accent_ = accentColours(accent); - accentLinear_ = linearAccent(accent_); finishes_.setAccent(accent_); } view_ = view; diff --git a/src/menu.h b/src/menu.h index 51060a5..492b483 100644 --- a/src/menu.h +++ b/src/menu.h @@ -19,6 +19,7 @@ #include "menu_finish.h" #include "menu_command.h" #include "menu_geometry.h" +#include "menu_view.h" #include "settings.h" #include "remote.h" #include "sftp.h" @@ -27,7 +28,6 @@ #include "strings.h" #include "video_format.h" #include "video_memory.h" -#include "video_player.h" #include "whats_new.h" #include @@ -74,192 +74,9 @@ struct CurvedPanel; struct Palette; -// Match the room's switch (room_light.h): not offered, the room not shown, -// ready, reading, or a reading that just failed. -enum class RoomMatch { Hidden, Off, Ready, Reading, Failed }; - -// A message's icon (notices.h), from the menu's set. -enum class NoticeIcon { None, Recenter, Viewpoint, Passthrough, Card, Usb, Drive, Warning }; - -// A gesture's value as its notice shows it (Menu::drawRingNotice()): a ring -// in the pill's round start, a knob's travel of 270° open at the bottom, -// filled clockwise to the value, and its name and number beside it. -struct RingNotice { - // A value; a rating in ten half-star steps; a place in the video. - enum class Kind : uint8_t { Value, Stars, Position }; - Kind kind = Kind::Value; - // Along the ring, 0..1: the value, where its fill starts (0, or the - // middle's for a value centred on 0, which gets a tick), its default - // (-1: none), and Position's chapters. - double at = 0, from = 0, mark = -1; - bool centred = false; - bool limit = false; // at an end: the end brighter - std::vector ticks; - int halves = 0; // Stars: the rating - // Its name, then its number in the semibold, then dim what follows it - // ("Volume" "64 %"; Position: "12:40" "/ 48:10"). - std::string name, number, after; - // Equal as drawn: the fill to a 300th of the ring. - bool operator==(const RingNotice& o) const { - const auto step = [](double x) { return std::lround(x * 300); }; - return kind == o.kind && step(at) == step(o.at) && step(from) == step(o.from) && - step(mark) == step(o.mark) && centred == o.centred && limit == o.limit && - ticks == o.ticks && halves == o.halves && name == o.name && number == o.number && - after == o.after; - } - bool operator!=(const RingNotice& o) const { return !(*this == o); } -}; - // An audio or subtitle track as the menu names it: "English (eng)", "eng" or "Track 2". std::string trackName(const Track& track, const Strings& t); -// The flat screen's size (ScreenSize) as the menu shows it. -struct ScreenView { - int distanceCm = 0, heightCm = 0, curvePercent = 0; - - static ScreenView of(const ScreenSize& size) { - return {static_cast(std::lround(size.distance * 100)), - static_cast(std::lround(size.height * 100)), - static_cast(std::lround(size.curve * 100))}; - } - bool operator==(const ScreenView& o) const { - return distanceCm == o.distanceCm && heightCm == o.heightCm && - curvePercent == o.curvePercent; - } - bool operator!=(const ScreenView& o) const { return !(*this == o); } -}; - -// Why a press while picking the background key's colour took none: the -// patch pointed at isn't one colour, or the picture can't be read. -enum class KeyPickNote { None, Uneven, Unreadable }; - -// Settings' Controls (menu_controls.cpp): the controller type it shows, -// what the buttons do, its gestures, and how far Skip and Big skip go. -struct ControlsView { - ControllerType type = ControllerType::Touch; - ControlMap map; - GestureMap gestures; - int skipSeconds = 10, bigSkipSeconds = 60; - bool operator==(const ControlsView& o) const { - return type == o.type && map == o.map && gestures == o.gestures && skipSeconds == o.skipSeconds && - bigSkipSeconds == o.bigSkipSeconds; - } - bool operator!=(const ControlsView& o) const { return !(*this == o); } -}; - -// Everything the menu shows about the app. -struct MenuView { - PlaybackState playback; - VideoFormat format; - bool halfPacked = false; // flat 3D shown with half-squeezed eyes (chosen by hand) - ScreenView screen; - bool passthrough = false; - GreenScreen greenScreen; // of the running video - bool colourKey = false; // ... its key is a colour key (VideoSettings::colourKeyed()) ... - KeyColour keyColour; // ... on this colour - bool fillChecked = false; // ... and the video was checked for a flat background - bool fillChecking = false; // ... or is being, and hasn't answered yet - bool greenScreenFound = false; // ... and its green screen check found one - bool keyPicking = false; // a colour for it is being picked: the strip asks to point at it - KeyPickNote keyPickNote = KeyPickNote::None; // ... and why the last press took none - bool packedAlpha = false; // the running video brings its own mask (no keying needed) - bool maskFormat = false; // its format is the one a packed mask comes in (maskFormat()) - bool maskLayers = false; // its mask has a second layer (VideoSettings::maskLayersFound) - bool secondLayerHidden = false; // ... hidden by hand - int opacity = 100; // of the running video, percent - bool opacityApplies = false; // the runtime blends the video over the room - std::string currentFile; - bool playbackFailed = false; // the current video couldn't be played - bool discEncrypted = false; // ... because it is an encrypted disc image - bool decoderBusy = false; // ... because the decoder is busy (decoder_holders.h) - Accent accent; - bool floatingSubtitles = false; - bool hardwareAv1 = false; // the headset's decoder takes AV1 (SteamOS 0.5.10) - bool streaming = false; // the current video is a link, not a file - int videoWidth = 0, videoHeight = 0; - bool background = true; // night sky around the flat screen - bool autoPassthrough = false; // passthrough switches itself on for videos made for it - bool keyGreen = false; // a PC whose runtime doesn't blend: passthrough draws the room green - bool passthroughAvailable = false; // the runtime blends, or keyGreen is on in its place - int subtitleSize = 100, subtitleRaise = 0, subtitleDistance = 150; // see Settings - bool photo = false; // the current file is a photo - int slideshowSeconds = 0; // 0 = no slideshow - AfterVideo afterVideo = AfterVideo::Next; // what happens when a video ends - // Picture settings of the running video. - int brightness = 0, contrast = 0, saturation = 0; - ColourBalance balance; // the video's, or Match the room's while it is on and applies - RoomMatch roomMatch = RoomMatch::Hidden; - bool roomMatched = false; // Match the room is on (applied only while the room is shown) - int matchColour = 70, matchBrightness = 60; // percent (Settings::matchColour) - float zoom = 1.0f; - int originForward = 0; // surround viewpoint: percent of the sphere's radius toward the picture - bool tvGamma = false; // SDR video converted for a TV's gamma (darker shadows) - bool videoMipmaps = true; // global: video sampled through mipmaps - AntiShimmer antiShimmer = AntiShimmer::On; // this run's: without them (anti_shimmer.h) - int sharpen = 0; // global: video sharpening in percent, 0 = off - bool toneLook = false; // global: tone curve and vignette - // Global eye size: the choice (pixels with stops, otherwise percent), - // and the requested and allowed scales in percent. - int videoResolution = 100, videoResolutionActive = 100, videoResolutionEffective = 100; - const std::vector* resolutionStops = nullptr; // Frame; owned by the run - int resolutionOverride = 0; // eye image pixels across this run asks for from the command line, else 0 - int resolutionBase = 0; // eye image pixels across at 100 % - bool panelBase = false; // resolutionBase is the headset's panel, else SteamVR's recommendation - bool resolutionNotice = false; // 1× has changed meaning; show the migrated size - // The Frame's foveation (FoveationLevel), where the eye images have it. - bool foveationAvailable = false; - FoveationLevel foveation = FoveationLevel::High; - bool showFoveation = false; - bool foveationLearned = false; - int sharpBins = kDefaultSharpBins; - bool foveationRing = kDefaultFoveationRing; - int foveationOutside = 4; - bool frameReuse = true; // Frame: repeated frames not drawn, this run's (frame_reuse.h) - bool advancedSettings = false; - int refreshRate = 0; // Frame: Hz, SteamVR's for this app (refresh_rate.h); 0: not changeable - // What the resolution, foveation, mipmaps, anti-shimmer and sharpening - // match (presets.h), else Custom. - PerformancePreset performancePreset = PerformancePreset::High; - // The user's named presets as last listed (ListUserPresets), owned by the - // run; userPresetsListed counts the listings. The one shown as chosen - // (-1: a performance preset, or Custom), and this device's presets. - const std::vector* userPresets = nullptr; - int userPresetsListed = 0; - int userPresetShown = -1; - const Presets* presets = nullptr; - std::array foveationMaps{{0, 1, 2, 3, 4, 5, 6, 7, 8}}; - std::array sharpDegrees{}; - FocusView focus; // stereo focus of the running video - bool motionEmulation = true; // global: head translation emulation (motion.h) - int motionDistance = 200; // ... cm - bool resume = true; // videos start where they were left - bool freeDecoder = false; // Frame: the decoder is freed from Steam without asking - bool seekPreview = true; // the seek bar shows the frame where the pointer is - bool seekPreviewAvailable = true; // ... can at all (not on the Steam Frame) - bool showPerformance = false; // the performance readout, this run's (--show-performance) - bool vibration = true; // controllers buzz on clicks, seeks and grabs - bool thumbnails = true; // file browser and library: thumbnails, else a video icon - StashSettings stash; // the media server's setup in use (its pages show only while it is on) - unsigned serversSetUp = 0; // a bit per ServerKind with a server set up, in use or not - bool setupBanner = false; // the Library's "You're all set" after setup (DismissSetupBanner) - bool showWhatsNew = true; // What's new opens after updates (Settings::showWhatsNew) - int appFps = 0; // frames the app drew in the last second (0 = not known yet) - ReleaseUpdate::State releaseUpdate = ReleaseUpdate::State::Disabled; - std::string releaseVersion; - DiagnosticsExport::State diagnostics = DiagnosticsExport::State::Idle; - std::string diagnosticsFile; // Saved: the zip's name - bool crashedLastRun = false; // until its diagnostics are saved - bool softwareDecoding = false; // the video plays without hardware decoding - ScriptSettings scripts; // funscripts on a device (script_player.h) - ScriptStatus scriptStatus; // ... how far the way to one has got, and whether the video has a script - std::string downloadsTo; // Settings::downloadsTo - // The strip's delete button (docs/alpha/delete-file.md): not shown - // (nothing open, a link), shown, or shown disabled for a scene played - // from Stash's stream: Send to Stash off, or Stash not answering. - enum class Deletable : uint8_t { No, Yes, NeedsSendToStash, StashDown } deletable = Deletable::No; - ControlsView controls; -}; - // The delete dialog's (docs/alpha/delete-file.md): the file playing, and // what the app found out about it in the background. Until `ready`, only // Cancel can be pressed. @@ -323,6 +140,9 @@ class Menu { Menu(); ~Menu(); bool init(Uploader& uploader); + // Without a GPU: the panels are drawn into surfaces that are never + // uploaded, so texture() has nothing. draw() draws them elsewhere. + bool init(); // Source of the file browser's thumbnails (optional, not owned). Before // its start(): this sets the sizes they are made at. void setThumbnailer(Thumbnailer* thumbnailer); @@ -585,6 +405,12 @@ class Menu { void shownColumns(int panel, int& first, int& end) const; // Panel texture (sRGB, premultiplied alpha), redrawn first if needed. const Texture* texture(PanelId panel); + // All of a panel as it is laid out now, drawn into `cr` (layout pixels). + void draw(PanelId panel, cairo_t* cr); + // Background work the menu started (places, a folder's listing, servers + // looked for, controller drawings, setup's drives and folders) that may + // still change what it shows. + bool working() const; // The button under the pointer on this panel, in layout pixels // (x0, y0, x1, y1), with its corner radius and whether it is destructive // (highlighted red), for the shader, and the edges of the list it scrolls @@ -593,8 +419,6 @@ class Menu { // Whether the pointer is on such a button that is not a rating (its stars // are pointed at one by one, and on a tile the whole tile lights up). bool pointedButton() const; - // The accent's fill (chosen buttons, the panels' edge) in linear light. - const std::array& accentLinear() const { return accentLinear_; } // The colours with the chosen accent (menu_style.h). Palette palette() const; // How the panel shader draws the control under the pointer on this panel: @@ -638,6 +462,7 @@ class Menu { // Stash's section in the navigation: its mark (three // layers), scenes (a film frame), performers, studios Layers, Film, People, Building }; + public: enum class Dialog { None, ConfirmDelete, Deleting, Error, Deleted, ConfirmQuit, SaveTo, NoRoom, RemoveDownload, // offline downloads' (menu_offline.cpp) Update, // a newer release (menu_settings.cpp) @@ -655,6 +480,8 @@ class Menu { // password as its key was refused, its key changed, and // Forget for a key login (and with the server not answering). KeyRefused, HostKeyChanged, ForgetServer, ForgetOffline }; + + private: // Small choice menus opened by their button. enum class Dropdown { None, Slideshow, AfterVideo, Audio, Subtitles, Chapters, Sort, Language, Presets, // the user's own presets (menu_presets.cpp) @@ -662,6 +489,8 @@ class Menu { DownloadsTo }; // the drive offline downloads go to // File browser order (folders always come first). using SortMode = FolderListing::Order; + + public: struct Button { int panel = kMain; double x = 0, y = 0, w = 0, h = 0; @@ -771,6 +600,11 @@ class Menu { bool dialog = false; // a dialog's button (DialogLayout): its icon and label centred int controlPart = -1; // drawn by drawControlPart() instead (menu_controls.cpp): its part }; + // Lays the panels out as a redraw does (setup's while it runs): their + // buttons, in layout pixels. + const std::vector