1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-08 13:11:49 +00:00

daybreak: update for hid refactor (#1222)

This commit is contained in:
Adubbz 2020-12-02 21:21:05 +11:00 committed by SciresM
parent 41a53075e5
commit f3dbab4876

View file

@ -43,7 +43,6 @@ namespace dbk {
static constexpr float VerticalGap = 10.0f; static constexpr float VerticalGap = 10.0f;
u32 g_screen_width; u32 g_screen_width;
u32 g_screen_height; u32 g_screen_height;
@ -51,8 +50,10 @@ namespace dbk {
bool g_initialized = false; bool g_initialized = false;
bool g_exit_requested = false; bool g_exit_requested = false;
PadState g_pad;
u32 g_prev_touch_count = -1; u32 g_prev_touch_count = -1;
touchPosition g_start_touch_position; HidTouchScreenState g_start_touch;
bool g_started_touching = false; bool g_started_touching = false;
bool g_tapping = false; bool g_tapping = false;
bool g_touches_moving = false; bool g_touches_moving = false;
@ -67,15 +68,14 @@ namespace dbk {
constexpr u32 MaxTapMovement = 20; constexpr u32 MaxTapMovement = 20;
void UpdateInput() { void UpdateInput() {
/* Update the previous touch count. */
g_prev_touch_count = hidTouchCount();
/* Scan for input and update touch state. */ /* Scan for input and update touch state. */
hidScanInput(); padUpdate(&g_pad);
const u32 touch_count = hidTouchCount(); HidTouchScreenState current_touch;
hidGetTouchScreenStates(&current_touch, 1);
const u32 touch_count = current_touch.count;
if (g_prev_touch_count == 0 && touch_count > 0) { if (g_prev_touch_count == 0 && touch_count > 0) {
hidTouchRead(&g_start_touch_position, 0); hidGetTouchScreenStates(&g_start_touch, 1);
g_started_touching = true; g_started_touching = true;
g_tapping = true; g_tapping = true;
} else { } else {
@ -91,10 +91,7 @@ namespace dbk {
/* Check if currently moving. */ /* Check if currently moving. */
if (g_prev_touch_count > 0 && touch_count > 0) { if (g_prev_touch_count > 0 && touch_count > 0) {
touchPosition current_touch_position; if ((abs(current_touch.touches[0].x - g_start_touch.touches[0].x) > MaxTapMovement || abs(current_touch.touches[0].y - g_start_touch.touches[0].y) > MaxTapMovement)) {
hidTouchRead(&current_touch_position, 0);
if ((abs(current_touch_position.px - g_start_touch_position.px) > MaxTapMovement || abs(current_touch_position.py - g_start_touch_position.py) > MaxTapMovement)) {
g_touches_moving = true; g_touches_moving = true;
g_tapping = false; g_tapping = false;
} else { } else {
@ -103,6 +100,9 @@ namespace dbk {
} else { } else {
g_touches_moving = false; g_touches_moving = false;
} }
/* Update the previous touch count. */
g_prev_touch_count = current_touch.count;
} }
void ChangeMenu(std::shared_ptr<Menu> menu) { void ChangeMenu(std::shared_ptr<Menu> menu) {
@ -241,14 +241,13 @@ namespace dbk {
} }
Button *Menu::GetTouchedButton() { Button *Menu::GetTouchedButton() {
touchPosition touch; HidTouchScreenState current_touch;
const u32 touch_count = hidTouchCount(); hidGetTouchScreenStates(&current_touch, 1);
const u32 touch_count = current_touch.count;
for (u32 i = 0; i < touch_count && g_started_touching; i++) { for (u32 i = 0; i < touch_count && g_started_touching; i++) {
hidTouchRead(&touch, i);
for (auto &button : m_buttons) { for (auto &button : m_buttons) {
if (button && button->enabled && button->IsPositionInBounds(touch.px, touch.py)) { if (button && button->enabled && button->IsPositionInBounds(current_touch.touches[i].x, current_touch.touches[i].y)) {
return &(*button); return &(*button);
} }
} }
@ -264,9 +263,9 @@ namespace dbk {
return nullptr; return nullptr;
} }
const u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO); const u64 k_down = padGetButtonsDown(&g_pad);
if (k_down & KEY_A || this->GetTouchedButton() == selected_button) { if (k_down & HidNpadButton_A || this->GetTouchedButton() == selected_button) {
return selected_button; return selected_button;
} }
@ -274,16 +273,16 @@ namespace dbk {
} }
void Menu::UpdateButtons() { void Menu::UpdateButtons() {
const u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO); const u64 k_down = padGetButtonsDown(&g_pad);
Direction direction = Direction::Invalid; Direction direction = Direction::Invalid;
if (k_down & KEY_DOWN) { if (k_down & HidNpadButton_AnyDown) {
direction = Direction::Down; direction = Direction::Down;
} else if (k_down & KEY_UP) { } else if (k_down & HidNpadButton_AnyUp) {
direction = Direction::Up; direction = Direction::Up;
} else if (k_down & KEY_LEFT) { } else if (k_down & HidNpadButton_AnyLeft) {
direction = Direction::Left; direction = Direction::Left;
} else if (k_down & KEY_RIGHT) { } else if (k_down & HidNpadButton_AnyRight) {
direction = Direction::Right; direction = Direction::Right;
} }
@ -373,10 +372,10 @@ namespace dbk {
} }
void ErrorMenu::Update(u64 ns) { void ErrorMenu::Update(u64 ns) {
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO); u64 k_down = padGetButtonsDown(&g_pad);
/* Go back if B is pressed. */ /* Go back if B is pressed. */
if (k_down & KEY_B) { if (k_down & HidNpadButton_B) {
g_exit_requested = true; g_exit_requested = true;
return; return;
} }
@ -411,10 +410,10 @@ namespace dbk {
} }
void WarningMenu::Update(u64 ns) { void WarningMenu::Update(u64 ns) {
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO); u64 k_down = padGetButtonsDown(&g_pad);
/* Go back if B is pressed. */ /* Go back if B is pressed. */
if (k_down & KEY_B) { if (k_down & HidNpadButton_B) {
ReturnToPreviousMenu(); ReturnToPreviousMenu();
return; return;
} }
@ -449,9 +448,9 @@ namespace dbk {
} }
void MainMenu::Update(u64 ns) { void MainMenu::Update(u64 ns) {
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO); u64 k_down = padGetButtonsDown(&g_pad);
if (k_down & KEY_B) { if (k_down & HidNpadButton_B) {
g_exit_requested = true; g_exit_requested = true;
} }
@ -574,16 +573,16 @@ namespace dbk {
const float x = g_screen_width / 2.0f - WindowWidth / 2.0f; const float x = g_screen_width / 2.0f - WindowWidth / 2.0f;
const float y = g_screen_height / 2.0f - WindowHeight / 2.0f; const float y = g_screen_height / 2.0f - WindowHeight / 2.0f;
touchPosition current_pos; HidTouchScreenState current_touch;
hidTouchRead(&current_pos, 0); hidGetTouchScreenStates(&current_touch, 1);
/* Check if the tap is within the x bounds. */ /* Check if the tap is within the x bounds. */
if (current_pos.px >= x + TextBackgroundOffset + FileRowHorizontalInset && current_pos.px <= WindowWidth - (TextBackgroundOffset + FileRowHorizontalInset) * 2.0f) { if (current_touch.touches[0].x >= x + TextBackgroundOffset + FileRowHorizontalInset && current_touch.touches[0].x <= WindowWidth - (TextBackgroundOffset + FileRowHorizontalInset) * 2.0f) {
const float y_min = y + TitleGap + FileRowGap + i * (FileRowHeight + FileRowGap) - m_scroll_offset; const float y_min = y + TitleGap + FileRowGap + i * (FileRowHeight + FileRowGap) - m_scroll_offset;
const float y_max = y_min + FileRowHeight; const float y_max = y_min + FileRowHeight;
/* Check if the tap is within the y bounds. */ /* Check if the tap is within the y bounds. */
if (current_pos.py >= y_min && current_pos.py <= y_max) { if (current_touch.touches[0].y >= y_min && current_touch.touches[0].y <= y_max) {
return true; return true;
} }
} }
@ -604,10 +603,10 @@ namespace dbk {
/* Scroll based on touch movement. */ /* Scroll based on touch movement. */
if (g_touches_moving) { if (g_touches_moving) {
touchPosition current_pos; HidTouchScreenState current_touch;
hidTouchRead(&current_pos, 0); hidGetTouchScreenStates(&current_touch, 1);
const int dist_y = current_pos.py - g_start_touch_position.py; const int dist_y = current_touch.touches[0].y - g_start_touch.touches[0].y;
float new_scroll_offset = m_touch_start_scroll_offset - static_cast<float>(dist_y); float new_scroll_offset = m_touch_start_scroll_offset - static_cast<float>(dist_y);
float max_scroll = (FileRowHeight + FileRowGap) * static_cast<float>(m_file_entries.size()) - FileListHeight; float max_scroll = (FileRowHeight + FileRowGap) * static_cast<float>(m_file_entries.size()) - FileListHeight;
@ -688,16 +687,16 @@ namespace dbk {
} }
void FileMenu::Update(u64 ns) { void FileMenu::Update(u64 ns) {
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO); u64 k_down = padGetButtonsDown(&g_pad);
/* Go back if B is pressed. */ /* Go back if B is pressed. */
if (k_down & KEY_B) { if (k_down & HidNpadButton_B) {
ReturnToPreviousMenu(); ReturnToPreviousMenu();
return; return;
} }
/* Finalize selection on pressing A. */ /* Finalize selection on pressing A. */
if (k_down & KEY_A) { if (k_down & HidNpadButton_A) {
this->FinalizeSelection(); this->FinalizeSelection();
} }
@ -706,14 +705,14 @@ namespace dbk {
const u32 prev_index = m_current_index; const u32 prev_index = m_current_index;
if (k_down & KEY_DOWN) { if (k_down & HidNpadButton_AnyDown) {
/* Scroll down. */ /* Scroll down. */
if (m_current_index >= (m_file_entries.size() - 1)) { if (m_current_index >= (m_file_entries.size() - 1)) {
m_current_index = 0; m_current_index = 0;
} else { } else {
m_current_index++; m_current_index++;
} }
} else if (k_down & KEY_UP) { } else if (k_down & HidNpadButton_AnyUp) {
/* Scroll up. */ /* Scroll up. */
if (m_current_index == 0) { if (m_current_index == 0) {
m_current_index = m_file_entries.size() - 1; m_current_index = m_file_entries.size() - 1;
@ -859,10 +858,10 @@ namespace dbk {
this->ValidateUpdate(); this->ValidateUpdate();
} }
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO); u64 k_down = padGetButtonsDown(&g_pad);
/* Go back if B is pressed. */ /* Go back if B is pressed. */
if (k_down & KEY_B) { if (k_down & HidNpadButton_B) {
ReturnToPreviousMenu(); ReturnToPreviousMenu();
return; return;
} }
@ -923,10 +922,10 @@ namespace dbk {
} }
void ChooseResetMenu::Update(u64 ns) { void ChooseResetMenu::Update(u64 ns) {
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO); u64 k_down = padGetButtonsDown(&g_pad);
/* Go back if B is pressed. */ /* Go back if B is pressed. */
if (k_down & KEY_B) { if (k_down & HidNpadButton_B) {
ReturnToPreviousMenu(); ReturnToPreviousMenu();
return; return;
} }
@ -986,10 +985,10 @@ namespace dbk {
} }
void ChooseExfatMenu::Update(u64 ns) { void ChooseExfatMenu::Update(u64 ns) {
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO); u64 k_down = padGetButtonsDown(&g_pad);
/* Go back if B is pressed. */ /* Go back if B is pressed. */
if (k_down & KEY_B) { if (k_down & HidNpadButton_B) {
ReturnToPreviousMenu(); ReturnToPreviousMenu();
return; return;
} }
@ -1195,6 +1194,13 @@ namespace dbk {
void InitializeMenu(u32 screen_width, u32 screen_height) { void InitializeMenu(u32 screen_width, u32 screen_height) {
Result rc = 0; Result rc = 0;
/* Configure and initialize the gamepad. */
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
padInitializeDefault(&g_pad);
/* Initialize the touch screen. */
hidInitializeTouchScreen();
/* Set the screen width and height. */ /* Set the screen width and height. */
g_screen_width = screen_width; g_screen_width = screen_width;
g_screen_height = screen_height; g_screen_height = screen_height;