diff options
Diffstat (limited to 'src/core/frontend')
| -rw-r--r-- | src/core/frontend/applets/general_frontend.cpp | 68 | ||||
| -rw-r--r-- | src/core/frontend/applets/general_frontend.h | 51 | ||||
| -rw-r--r-- | src/core/frontend/applets/web_browser.cpp | 24 | ||||
| -rw-r--r-- | src/core/frontend/applets/web_browser.h | 20 | ||||
| -rw-r--r-- | src/core/frontend/input_interpreter.cpp | 45 | ||||
| -rw-r--r-- | src/core/frontend/input_interpreter.h | 120 |
6 files changed, 197 insertions, 131 deletions
diff --git a/src/core/frontend/applets/general_frontend.cpp b/src/core/frontend/applets/general_frontend.cpp index c30b36de7..7483ffb76 100644 --- a/src/core/frontend/applets/general_frontend.cpp +++ b/src/core/frontend/applets/general_frontend.cpp | |||
| @@ -53,72 +53,4 @@ void DefaultPhotoViewerApplet::ShowAllPhotos(std::function<void()> finished) con | |||
| 53 | finished(); | 53 | finished(); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | ECommerceApplet::~ECommerceApplet() = default; | ||
| 57 | |||
| 58 | DefaultECommerceApplet::~DefaultECommerceApplet() = default; | ||
| 59 | |||
| 60 | void DefaultECommerceApplet::ShowApplicationInformation( | ||
| 61 | std::function<void()> finished, u64 title_id, std::optional<u128> user_id, | ||
| 62 | std::optional<bool> full_display, std::optional<std::string> extra_parameter) { | ||
| 63 | const auto value = user_id.value_or(u128{}); | ||
| 64 | LOG_INFO(Service_AM, | ||
| 65 | "Application requested frontend show application information for EShop, " | ||
| 66 | "title_id={:016X}, user_id={:016X}{:016X}, full_display={}, extra_parameter={}", | ||
| 67 | title_id, value[1], value[0], | ||
| 68 | full_display.has_value() ? fmt::format("{}", *full_display) : "null", | ||
| 69 | extra_parameter.value_or("null")); | ||
| 70 | finished(); | ||
| 71 | } | ||
| 72 | |||
| 73 | void DefaultECommerceApplet::ShowAddOnContentList(std::function<void()> finished, u64 title_id, | ||
| 74 | std::optional<u128> user_id, | ||
| 75 | std::optional<bool> full_display) { | ||
| 76 | const auto value = user_id.value_or(u128{}); | ||
| 77 | LOG_INFO(Service_AM, | ||
| 78 | "Application requested frontend show add on content list for EShop, " | ||
| 79 | "title_id={:016X}, user_id={:016X}{:016X}, full_display={}", | ||
| 80 | title_id, value[1], value[0], | ||
| 81 | full_display.has_value() ? fmt::format("{}", *full_display) : "null"); | ||
| 82 | finished(); | ||
| 83 | } | ||
| 84 | |||
| 85 | void DefaultECommerceApplet::ShowSubscriptionList(std::function<void()> finished, u64 title_id, | ||
| 86 | std::optional<u128> user_id) { | ||
| 87 | const auto value = user_id.value_or(u128{}); | ||
| 88 | LOG_INFO(Service_AM, | ||
| 89 | "Application requested frontend show subscription list for EShop, title_id={:016X}, " | ||
| 90 | "user_id={:016X}{:016X}", | ||
| 91 | title_id, value[1], value[0]); | ||
| 92 | finished(); | ||
| 93 | } | ||
| 94 | |||
| 95 | void DefaultECommerceApplet::ShowConsumableItemList(std::function<void()> finished, u64 title_id, | ||
| 96 | std::optional<u128> user_id) { | ||
| 97 | const auto value = user_id.value_or(u128{}); | ||
| 98 | LOG_INFO( | ||
| 99 | Service_AM, | ||
| 100 | "Application requested frontend show consumable item list for EShop, title_id={:016X}, " | ||
| 101 | "user_id={:016X}{:016X}", | ||
| 102 | title_id, value[1], value[0]); | ||
| 103 | finished(); | ||
| 104 | } | ||
| 105 | |||
| 106 | void DefaultECommerceApplet::ShowShopHome(std::function<void()> finished, u128 user_id, | ||
| 107 | bool full_display) { | ||
| 108 | LOG_INFO(Service_AM, | ||
| 109 | "Application requested frontend show home menu for EShop, user_id={:016X}{:016X}, " | ||
| 110 | "full_display={}", | ||
| 111 | user_id[1], user_id[0], full_display); | ||
| 112 | finished(); | ||
| 113 | } | ||
| 114 | |||
| 115 | void DefaultECommerceApplet::ShowSettings(std::function<void()> finished, u128 user_id, | ||
| 116 | bool full_display) { | ||
| 117 | LOG_INFO(Service_AM, | ||
| 118 | "Application requested frontend show settings menu for EShop, user_id={:016X}{:016X}, " | ||
| 119 | "full_display={}", | ||
| 120 | user_id[1], user_id[0], full_display); | ||
| 121 | finished(); | ||
| 122 | } | ||
| 123 | |||
| 124 | } // namespace Core::Frontend | 56 | } // namespace Core::Frontend |
diff --git a/src/core/frontend/applets/general_frontend.h b/src/core/frontend/applets/general_frontend.h index 4b63f828e..b713b14ee 100644 --- a/src/core/frontend/applets/general_frontend.h +++ b/src/core/frontend/applets/general_frontend.h | |||
| @@ -58,55 +58,4 @@ public: | |||
| 58 | void ShowAllPhotos(std::function<void()> finished) const override; | 58 | void ShowAllPhotos(std::function<void()> finished) const override; |
| 59 | }; | 59 | }; |
| 60 | 60 | ||
| 61 | class ECommerceApplet { | ||
| 62 | public: | ||
| 63 | virtual ~ECommerceApplet(); | ||
| 64 | |||
| 65 | // Shows a page with application icons, description, name, and price. | ||
| 66 | virtual void ShowApplicationInformation(std::function<void()> finished, u64 title_id, | ||
| 67 | std::optional<u128> user_id = {}, | ||
| 68 | std::optional<bool> full_display = {}, | ||
| 69 | std::optional<std::string> extra_parameter = {}) = 0; | ||
| 70 | |||
| 71 | // Shows a page with all of the add on content available for a game, with name, description, and | ||
| 72 | // price. | ||
| 73 | virtual void ShowAddOnContentList(std::function<void()> finished, u64 title_id, | ||
| 74 | std::optional<u128> user_id = {}, | ||
| 75 | std::optional<bool> full_display = {}) = 0; | ||
| 76 | |||
| 77 | // Shows a page with all of the subscriptions (recurring payments) for a game, with name, | ||
| 78 | // description, price, and renewal period. | ||
| 79 | virtual void ShowSubscriptionList(std::function<void()> finished, u64 title_id, | ||
| 80 | std::optional<u128> user_id = {}) = 0; | ||
| 81 | |||
| 82 | // Shows a page with a list of any additional game related purchasable items (DLC, | ||
| 83 | // subscriptions, etc) for a particular game, with name, description, type, and price. | ||
| 84 | virtual void ShowConsumableItemList(std::function<void()> finished, u64 title_id, | ||
| 85 | std::optional<u128> user_id = {}) = 0; | ||
| 86 | |||
| 87 | // Shows the home page of the shop. | ||
| 88 | virtual void ShowShopHome(std::function<void()> finished, u128 user_id, bool full_display) = 0; | ||
| 89 | |||
| 90 | // Shows the user settings page of the shop. | ||
| 91 | virtual void ShowSettings(std::function<void()> finished, u128 user_id, bool full_display) = 0; | ||
| 92 | }; | ||
| 93 | |||
| 94 | class DefaultECommerceApplet : public ECommerceApplet { | ||
| 95 | public: | ||
| 96 | ~DefaultECommerceApplet() override; | ||
| 97 | |||
| 98 | void ShowApplicationInformation(std::function<void()> finished, u64 title_id, | ||
| 99 | std::optional<u128> user_id, std::optional<bool> full_display, | ||
| 100 | std::optional<std::string> extra_parameter) override; | ||
| 101 | void ShowAddOnContentList(std::function<void()> finished, u64 title_id, | ||
| 102 | std::optional<u128> user_id, | ||
| 103 | std::optional<bool> full_display) override; | ||
| 104 | void ShowSubscriptionList(std::function<void()> finished, u64 title_id, | ||
| 105 | std::optional<u128> user_id) override; | ||
| 106 | void ShowConsumableItemList(std::function<void()> finished, u64 title_id, | ||
| 107 | std::optional<u128> user_id) override; | ||
| 108 | void ShowShopHome(std::function<void()> finished, u128 user_id, bool full_display) override; | ||
| 109 | void ShowSettings(std::function<void()> finished, u128 user_id, bool full_display) override; | ||
| 110 | }; | ||
| 111 | |||
| 112 | } // namespace Core::Frontend | 61 | } // namespace Core::Frontend |
diff --git a/src/core/frontend/applets/web_browser.cpp b/src/core/frontend/applets/web_browser.cpp index 528295ffc..50db6a654 100644 --- a/src/core/frontend/applets/web_browser.cpp +++ b/src/core/frontend/applets/web_browser.cpp | |||
| @@ -11,14 +11,22 @@ WebBrowserApplet::~WebBrowserApplet() = default; | |||
| 11 | 11 | ||
| 12 | DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default; | 12 | DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default; |
| 13 | 13 | ||
| 14 | void DefaultWebBrowserApplet::OpenPageLocal(std::string_view filename, | 14 | void DefaultWebBrowserApplet::OpenLocalWebPage( |
| 15 | std::function<void()> unpack_romfs_callback, | 15 | std::string_view local_url, std::function<void()> extract_romfs_callback, |
| 16 | std::function<void()> finished_callback) { | 16 | std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const { |
| 17 | LOG_INFO(Service_AM, | 17 | LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open local web page at {}", |
| 18 | "(STUBBED) called - No suitable web browser implementation found to open website page " | 18 | local_url); |
| 19 | "at '{}'!", | 19 | |
| 20 | filename); | 20 | callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/"); |
| 21 | finished_callback(); | 21 | } |
| 22 | |||
| 23 | void DefaultWebBrowserApplet::OpenExternalWebPage( | ||
| 24 | std::string_view external_url, | ||
| 25 | std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const { | ||
| 26 | LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open external web page at {}", | ||
| 27 | external_url); | ||
| 28 | |||
| 29 | callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/"); | ||
| 22 | } | 30 | } |
| 23 | 31 | ||
| 24 | } // namespace Core::Frontend | 32 | } // namespace Core::Frontend |
diff --git a/src/core/frontend/applets/web_browser.h b/src/core/frontend/applets/web_browser.h index 110e33bc4..1c5ef19a9 100644 --- a/src/core/frontend/applets/web_browser.h +++ b/src/core/frontend/applets/web_browser.h | |||
| @@ -7,22 +7,34 @@ | |||
| 7 | #include <functional> | 7 | #include <functional> |
| 8 | #include <string_view> | 8 | #include <string_view> |
| 9 | 9 | ||
| 10 | #include "core/hle/service/am/applets/web_types.h" | ||
| 11 | |||
| 10 | namespace Core::Frontend { | 12 | namespace Core::Frontend { |
| 11 | 13 | ||
| 12 | class WebBrowserApplet { | 14 | class WebBrowserApplet { |
| 13 | public: | 15 | public: |
| 14 | virtual ~WebBrowserApplet(); | 16 | virtual ~WebBrowserApplet(); |
| 15 | 17 | ||
| 16 | virtual void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback, | 18 | virtual void OpenLocalWebPage( |
| 17 | std::function<void()> finished_callback) = 0; | 19 | std::string_view local_url, std::function<void()> extract_romfs_callback, |
| 20 | std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const = 0; | ||
| 21 | |||
| 22 | virtual void OpenExternalWebPage( | ||
| 23 | std::string_view external_url, | ||
| 24 | std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const = 0; | ||
| 18 | }; | 25 | }; |
| 19 | 26 | ||
| 20 | class DefaultWebBrowserApplet final : public WebBrowserApplet { | 27 | class DefaultWebBrowserApplet final : public WebBrowserApplet { |
| 21 | public: | 28 | public: |
| 22 | ~DefaultWebBrowserApplet() override; | 29 | ~DefaultWebBrowserApplet() override; |
| 23 | 30 | ||
| 24 | void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback, | 31 | void OpenLocalWebPage(std::string_view local_url, std::function<void()> extract_romfs_callback, |
| 25 | std::function<void()> finished_callback) override; | 32 | std::function<void(Service::AM::Applets::WebExitReason, std::string)> |
| 33 | callback) const override; | ||
| 34 | |||
| 35 | void OpenExternalWebPage(std::string_view external_url, | ||
| 36 | std::function<void(Service::AM::Applets::WebExitReason, std::string)> | ||
| 37 | callback) const override; | ||
| 26 | }; | 38 | }; |
| 27 | 39 | ||
| 28 | } // namespace Core::Frontend | 40 | } // namespace Core::Frontend |
diff --git a/src/core/frontend/input_interpreter.cpp b/src/core/frontend/input_interpreter.cpp new file mode 100644 index 000000000..66ae506cd --- /dev/null +++ b/src/core/frontend/input_interpreter.cpp | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "core/core.h" | ||
| 6 | #include "core/frontend/input_interpreter.h" | ||
| 7 | #include "core/hle/service/hid/controllers/npad.h" | ||
| 8 | #include "core/hle/service/hid/hid.h" | ||
| 9 | #include "core/hle/service/sm/sm.h" | ||
| 10 | |||
| 11 | InputInterpreter::InputInterpreter(Core::System& system) | ||
| 12 | : npad{system.ServiceManager() | ||
| 13 | .GetService<Service::HID::Hid>("hid") | ||
| 14 | ->GetAppletResource() | ||
| 15 | ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad)} {} | ||
| 16 | |||
| 17 | InputInterpreter::~InputInterpreter() = default; | ||
| 18 | |||
| 19 | void InputInterpreter::PollInput() { | ||
| 20 | const u32 button_state = npad.GetAndResetPressState(); | ||
| 21 | |||
| 22 | previous_index = current_index; | ||
| 23 | current_index = (current_index + 1) % button_states.size(); | ||
| 24 | |||
| 25 | button_states[current_index] = button_state; | ||
| 26 | } | ||
| 27 | |||
| 28 | bool InputInterpreter::IsButtonPressedOnce(HIDButton button) const { | ||
| 29 | const bool current_press = | ||
| 30 | (button_states[current_index] & (1U << static_cast<u8>(button))) != 0; | ||
| 31 | const bool previous_press = | ||
| 32 | (button_states[previous_index] & (1U << static_cast<u8>(button))) != 0; | ||
| 33 | |||
| 34 | return current_press && !previous_press; | ||
| 35 | } | ||
| 36 | |||
| 37 | bool InputInterpreter::IsButtonHeld(HIDButton button) const { | ||
| 38 | u32 held_buttons{button_states[0]}; | ||
| 39 | |||
| 40 | for (std::size_t i = 1; i < button_states.size(); ++i) { | ||
| 41 | held_buttons &= button_states[i]; | ||
| 42 | } | ||
| 43 | |||
| 44 | return (held_buttons & (1U << static_cast<u8>(button))) != 0; | ||
| 45 | } | ||
diff --git a/src/core/frontend/input_interpreter.h b/src/core/frontend/input_interpreter.h new file mode 100644 index 000000000..fea9aebe6 --- /dev/null +++ b/src/core/frontend/input_interpreter.h | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | |||
| 9 | #include "common/common_types.h" | ||
| 10 | |||
| 11 | namespace Core { | ||
| 12 | class System; | ||
| 13 | } | ||
| 14 | |||
| 15 | namespace Service::HID { | ||
| 16 | class Controller_NPad; | ||
| 17 | } | ||
| 18 | |||
| 19 | enum class HIDButton : u8 { | ||
| 20 | A, | ||
| 21 | B, | ||
| 22 | X, | ||
| 23 | Y, | ||
| 24 | LStick, | ||
| 25 | RStick, | ||
| 26 | L, | ||
| 27 | R, | ||
| 28 | ZL, | ||
| 29 | ZR, | ||
| 30 | Plus, | ||
| 31 | Minus, | ||
| 32 | |||
| 33 | DLeft, | ||
| 34 | DUp, | ||
| 35 | DRight, | ||
| 36 | DDown, | ||
| 37 | |||
| 38 | LStickLeft, | ||
| 39 | LStickUp, | ||
| 40 | LStickRight, | ||
| 41 | LStickDown, | ||
| 42 | |||
| 43 | RStickLeft, | ||
| 44 | RStickUp, | ||
| 45 | RStickRight, | ||
| 46 | RStickDown, | ||
| 47 | |||
| 48 | LeftSL, | ||
| 49 | LeftSR, | ||
| 50 | |||
| 51 | RightSL, | ||
| 52 | RightSR, | ||
| 53 | }; | ||
| 54 | |||
| 55 | /** | ||
| 56 | * The InputInterpreter class interfaces with HID to retrieve button press states. | ||
| 57 | * Input is intended to be polled every 50ms so that a button is considered to be | ||
| 58 | * held down after 400ms has elapsed since the initial button press and subsequent | ||
| 59 | * repeated presses occur every 50ms. | ||
| 60 | */ | ||
| 61 | class InputInterpreter { | ||
| 62 | public: | ||
| 63 | explicit InputInterpreter(Core::System& system); | ||
| 64 | virtual ~InputInterpreter(); | ||
| 65 | |||
| 66 | /// Gets a button state from HID and inserts it into the array of button states. | ||
| 67 | void PollInput(); | ||
| 68 | |||
| 69 | /** | ||
| 70 | * The specified button is considered to be pressed once | ||
| 71 | * if it is currently pressed and not pressed previously. | ||
| 72 | * | ||
| 73 | * @param button The button to check. | ||
| 74 | * | ||
| 75 | * @returns True when the button is pressed once. | ||
| 76 | */ | ||
| 77 | [[nodiscard]] bool IsButtonPressedOnce(HIDButton button) const; | ||
| 78 | |||
| 79 | /** | ||
| 80 | * Checks whether any of the buttons in the parameter list is pressed once. | ||
| 81 | * | ||
| 82 | * @tparam HIDButton The buttons to check. | ||
| 83 | * | ||
| 84 | * @returns True when at least one of the buttons is pressed once. | ||
| 85 | */ | ||
| 86 | template <HIDButton... T> | ||
| 87 | [[nodiscard]] bool IsAnyButtonPressedOnce() { | ||
| 88 | return (IsButtonPressedOnce(T) || ...); | ||
| 89 | } | ||
| 90 | |||
| 91 | /** | ||
| 92 | * The specified button is considered to be held down if it is pressed in all 9 button states. | ||
| 93 | * | ||
| 94 | * @param button The button to check. | ||
| 95 | * | ||
| 96 | * @returns True when the button is held down. | ||
| 97 | */ | ||
| 98 | [[nodiscard]] bool IsButtonHeld(HIDButton button) const; | ||
| 99 | |||
| 100 | /** | ||
| 101 | * Checks whether any of the buttons in the parameter list is held down. | ||
| 102 | * | ||
| 103 | * @tparam HIDButton The buttons to check. | ||
| 104 | * | ||
| 105 | * @returns True when at least one of the buttons is held down. | ||
| 106 | */ | ||
| 107 | template <HIDButton... T> | ||
| 108 | [[nodiscard]] bool IsAnyButtonHeld() { | ||
| 109 | return (IsButtonHeld(T) || ...); | ||
| 110 | } | ||
| 111 | |||
| 112 | private: | ||
| 113 | Service::HID::Controller_NPad& npad; | ||
| 114 | |||
| 115 | /// Stores 9 consecutive button states polled from HID. | ||
| 116 | std::array<u32, 9> button_states{}; | ||
| 117 | |||
| 118 | std::size_t previous_index{}; | ||
| 119 | std::size_t current_index{}; | ||
| 120 | }; | ||