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 finished(); } -ECommerceApplet::~ECommerceApplet() = default; - -DefaultECommerceApplet::~DefaultECommerceApplet() = default; - -void DefaultECommerceApplet::ShowApplicationInformation( - std::function<void()> finished, u64 title_id, std::optional<u128> user_id, - std::optional<bool> full_display, std::optional<std::string> extra_parameter) { - const auto value = user_id.value_or(u128{}); - LOG_INFO(Service_AM, - "Application requested frontend show application information for EShop, " - "title_id={:016X}, user_id={:016X}{:016X}, full_display={}, extra_parameter={}", - title_id, value[1], value[0], - full_display.has_value() ? fmt::format("{}", *full_display) : "null", - extra_parameter.value_or("null")); - finished(); -} - -void DefaultECommerceApplet::ShowAddOnContentList(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id, - std::optional<bool> full_display) { - const auto value = user_id.value_or(u128{}); - LOG_INFO(Service_AM, - "Application requested frontend show add on content list for EShop, " - "title_id={:016X}, user_id={:016X}{:016X}, full_display={}", - title_id, value[1], value[0], - full_display.has_value() ? fmt::format("{}", *full_display) : "null"); - finished(); -} - -void DefaultECommerceApplet::ShowSubscriptionList(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id) { - const auto value = user_id.value_or(u128{}); - LOG_INFO(Service_AM, - "Application requested frontend show subscription list for EShop, title_id={:016X}, " - "user_id={:016X}{:016X}", - title_id, value[1], value[0]); - finished(); -} - -void DefaultECommerceApplet::ShowConsumableItemList(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id) { - const auto value = user_id.value_or(u128{}); - LOG_INFO( - Service_AM, - "Application requested frontend show consumable item list for EShop, title_id={:016X}, " - "user_id={:016X}{:016X}", - title_id, value[1], value[0]); - finished(); -} - -void DefaultECommerceApplet::ShowShopHome(std::function<void()> finished, u128 user_id, - bool full_display) { - LOG_INFO(Service_AM, - "Application requested frontend show home menu for EShop, user_id={:016X}{:016X}, " - "full_display={}", - user_id[1], user_id[0], full_display); - finished(); -} - -void DefaultECommerceApplet::ShowSettings(std::function<void()> finished, u128 user_id, - bool full_display) { - LOG_INFO(Service_AM, - "Application requested frontend show settings menu for EShop, user_id={:016X}{:016X}, " - "full_display={}", - user_id[1], user_id[0], full_display); - finished(); -} - } // 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: void ShowAllPhotos(std::function<void()> finished) const override; }; -class ECommerceApplet { -public: - virtual ~ECommerceApplet(); - - // Shows a page with application icons, description, name, and price. - virtual void ShowApplicationInformation(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id = {}, - std::optional<bool> full_display = {}, - std::optional<std::string> extra_parameter = {}) = 0; - - // Shows a page with all of the add on content available for a game, with name, description, and - // price. - virtual void ShowAddOnContentList(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id = {}, - std::optional<bool> full_display = {}) = 0; - - // Shows a page with all of the subscriptions (recurring payments) for a game, with name, - // description, price, and renewal period. - virtual void ShowSubscriptionList(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id = {}) = 0; - - // Shows a page with a list of any additional game related purchasable items (DLC, - // subscriptions, etc) for a particular game, with name, description, type, and price. - virtual void ShowConsumableItemList(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id = {}) = 0; - - // Shows the home page of the shop. - virtual void ShowShopHome(std::function<void()> finished, u128 user_id, bool full_display) = 0; - - // Shows the user settings page of the shop. - virtual void ShowSettings(std::function<void()> finished, u128 user_id, bool full_display) = 0; -}; - -class DefaultECommerceApplet : public ECommerceApplet { -public: - ~DefaultECommerceApplet() override; - - void ShowApplicationInformation(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id, std::optional<bool> full_display, - std::optional<std::string> extra_parameter) override; - void ShowAddOnContentList(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id, - std::optional<bool> full_display) override; - void ShowSubscriptionList(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id) override; - void ShowConsumableItemList(std::function<void()> finished, u64 title_id, - std::optional<u128> user_id) override; - void ShowShopHome(std::function<void()> finished, u128 user_id, bool full_display) override; - void ShowSettings(std::function<void()> finished, u128 user_id, bool full_display) override; -}; - } // 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; DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default; -void DefaultWebBrowserApplet::OpenPageLocal(std::string_view filename, - std::function<void()> unpack_romfs_callback, - std::function<void()> finished_callback) { - LOG_INFO(Service_AM, - "(STUBBED) called - No suitable web browser implementation found to open website page " - "at '{}'!", - filename); - finished_callback(); +void DefaultWebBrowserApplet::OpenLocalWebPage( + std::string_view local_url, std::function<void()> extract_romfs_callback, + std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const { + LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open local web page at {}", + local_url); + + callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/"); +} + +void DefaultWebBrowserApplet::OpenExternalWebPage( + std::string_view external_url, + std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const { + LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open external web page at {}", + external_url); + + callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/"); } } // 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 @@ #include <functional> #include <string_view> +#include "core/hle/service/am/applets/web_types.h" + namespace Core::Frontend { class WebBrowserApplet { public: virtual ~WebBrowserApplet(); - virtual void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback, - std::function<void()> finished_callback) = 0; + virtual void OpenLocalWebPage( + std::string_view local_url, std::function<void()> extract_romfs_callback, + std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const = 0; + + virtual void OpenExternalWebPage( + std::string_view external_url, + std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const = 0; }; class DefaultWebBrowserApplet final : public WebBrowserApplet { public: ~DefaultWebBrowserApplet() override; - void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback, - std::function<void()> finished_callback) override; + void OpenLocalWebPage(std::string_view local_url, std::function<void()> extract_romfs_callback, + std::function<void(Service::AM::Applets::WebExitReason, std::string)> + callback) const override; + + void OpenExternalWebPage(std::string_view external_url, + std::function<void(Service::AM::Applets::WebExitReason, std::string)> + callback) const override; }; } // 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 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/core.h" +#include "core/frontend/input_interpreter.h" +#include "core/hle/service/hid/controllers/npad.h" +#include "core/hle/service/hid/hid.h" +#include "core/hle/service/sm/sm.h" + +InputInterpreter::InputInterpreter(Core::System& system) + : npad{system.ServiceManager() + .GetService<Service::HID::Hid>("hid") + ->GetAppletResource() + ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad)} {} + +InputInterpreter::~InputInterpreter() = default; + +void InputInterpreter::PollInput() { + const u32 button_state = npad.GetAndResetPressState(); + + previous_index = current_index; + current_index = (current_index + 1) % button_states.size(); + + button_states[current_index] = button_state; +} + +bool InputInterpreter::IsButtonPressedOnce(HIDButton button) const { + const bool current_press = + (button_states[current_index] & (1U << static_cast<u8>(button))) != 0; + const bool previous_press = + (button_states[previous_index] & (1U << static_cast<u8>(button))) != 0; + + return current_press && !previous_press; +} + +bool InputInterpreter::IsButtonHeld(HIDButton button) const { + u32 held_buttons{button_states[0]}; + + for (std::size_t i = 1; i < button_states.size(); ++i) { + held_buttons &= button_states[i]; + } + + return (held_buttons & (1U << static_cast<u8>(button))) != 0; +} 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 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <array> + +#include "common/common_types.h" + +namespace Core { +class System; +} + +namespace Service::HID { +class Controller_NPad; +} + +enum class HIDButton : u8 { + A, + B, + X, + Y, + LStick, + RStick, + L, + R, + ZL, + ZR, + Plus, + Minus, + + DLeft, + DUp, + DRight, + DDown, + + LStickLeft, + LStickUp, + LStickRight, + LStickDown, + + RStickLeft, + RStickUp, + RStickRight, + RStickDown, + + LeftSL, + LeftSR, + + RightSL, + RightSR, +}; + +/** + * The InputInterpreter class interfaces with HID to retrieve button press states. + * Input is intended to be polled every 50ms so that a button is considered to be + * held down after 400ms has elapsed since the initial button press and subsequent + * repeated presses occur every 50ms. + */ +class InputInterpreter { +public: + explicit InputInterpreter(Core::System& system); + virtual ~InputInterpreter(); + + /// Gets a button state from HID and inserts it into the array of button states. + void PollInput(); + + /** + * The specified button is considered to be pressed once + * if it is currently pressed and not pressed previously. + * + * @param button The button to check. + * + * @returns True when the button is pressed once. + */ + [[nodiscard]] bool IsButtonPressedOnce(HIDButton button) const; + + /** + * Checks whether any of the buttons in the parameter list is pressed once. + * + * @tparam HIDButton The buttons to check. + * + * @returns True when at least one of the buttons is pressed once. + */ + template <HIDButton... T> + [[nodiscard]] bool IsAnyButtonPressedOnce() { + return (IsButtonPressedOnce(T) || ...); + } + + /** + * The specified button is considered to be held down if it is pressed in all 9 button states. + * + * @param button The button to check. + * + * @returns True when the button is held down. + */ + [[nodiscard]] bool IsButtonHeld(HIDButton button) const; + + /** + * Checks whether any of the buttons in the parameter list is held down. + * + * @tparam HIDButton The buttons to check. + * + * @returns True when at least one of the buttons is held down. + */ + template <HIDButton... T> + [[nodiscard]] bool IsAnyButtonHeld() { + return (IsButtonHeld(T) || ...); + } + +private: + Service::HID::Controller_NPad& npad; + + /// Stores 9 consecutive button states polled from HID. + std::array<u32, 9> button_states{}; + + std::size_t previous_index{}; + std::size_t current_index{}; +}; |