mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-23 23:31:11 +01:00
daybreak: update for hid refactor (#1222)
This commit is contained in:
parent
b69bf07d9c
commit
3b18db914c
@ -43,7 +43,6 @@ namespace dbk {
|
||||
|
||||
static constexpr float VerticalGap = 10.0f;
|
||||
|
||||
|
||||
u32 g_screen_width;
|
||||
u32 g_screen_height;
|
||||
|
||||
@ -51,8 +50,10 @@ namespace dbk {
|
||||
bool g_initialized = false;
|
||||
bool g_exit_requested = false;
|
||||
|
||||
PadState g_pad;
|
||||
|
||||
u32 g_prev_touch_count = -1;
|
||||
touchPosition g_start_touch_position;
|
||||
HidTouchScreenState g_start_touch;
|
||||
bool g_started_touching = false;
|
||||
bool g_tapping = false;
|
||||
bool g_touches_moving = false;
|
||||
@ -67,15 +68,14 @@ namespace dbk {
|
||||
constexpr u32 MaxTapMovement = 20;
|
||||
|
||||
void UpdateInput() {
|
||||
/* Update the previous touch count. */
|
||||
g_prev_touch_count = hidTouchCount();
|
||||
|
||||
/* Scan for input and update touch state. */
|
||||
hidScanInput();
|
||||
const u32 touch_count = hidTouchCount();
|
||||
padUpdate(&g_pad);
|
||||
HidTouchScreenState current_touch;
|
||||
hidGetTouchScreenStates(¤t_touch, 1);
|
||||
const u32 touch_count = current_touch.count;
|
||||
|
||||
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_tapping = true;
|
||||
} else {
|
||||
@ -91,10 +91,7 @@ namespace dbk {
|
||||
|
||||
/* Check if currently moving. */
|
||||
if (g_prev_touch_count > 0 && touch_count > 0) {
|
||||
touchPosition current_touch_position;
|
||||
hidTouchRead(¤t_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)) {
|
||||
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)) {
|
||||
g_touches_moving = true;
|
||||
g_tapping = false;
|
||||
} else {
|
||||
@ -103,6 +100,9 @@ namespace dbk {
|
||||
} else {
|
||||
g_touches_moving = false;
|
||||
}
|
||||
|
||||
/* Update the previous touch count. */
|
||||
g_prev_touch_count = current_touch.count;
|
||||
}
|
||||
|
||||
void ChangeMenu(std::shared_ptr<Menu> menu) {
|
||||
@ -241,14 +241,13 @@ namespace dbk {
|
||||
}
|
||||
|
||||
Button *Menu::GetTouchedButton() {
|
||||
touchPosition touch;
|
||||
const u32 touch_count = hidTouchCount();
|
||||
HidTouchScreenState current_touch;
|
||||
hidGetTouchScreenStates(¤t_touch, 1);
|
||||
const u32 touch_count = current_touch.count;
|
||||
|
||||
for (u32 i = 0; i < touch_count && g_started_touching; i++) {
|
||||
hidTouchRead(&touch, i);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -264,9 +263,9 @@ namespace dbk {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -274,16 +273,16 @@ namespace dbk {
|
||||
}
|
||||
|
||||
void Menu::UpdateButtons() {
|
||||
const u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
const u64 k_down = padGetButtonsDown(&g_pad);
|
||||
Direction direction = Direction::Invalid;
|
||||
|
||||
if (k_down & KEY_DOWN) {
|
||||
if (k_down & HidNpadButton_AnyDown) {
|
||||
direction = Direction::Down;
|
||||
} else if (k_down & KEY_UP) {
|
||||
} else if (k_down & HidNpadButton_AnyUp) {
|
||||
direction = Direction::Up;
|
||||
} else if (k_down & KEY_LEFT) {
|
||||
} else if (k_down & HidNpadButton_AnyLeft) {
|
||||
direction = Direction::Left;
|
||||
} else if (k_down & KEY_RIGHT) {
|
||||
} else if (k_down & HidNpadButton_AnyRight) {
|
||||
direction = Direction::Right;
|
||||
}
|
||||
|
||||
@ -373,10 +372,10 @@ namespace dbk {
|
||||
}
|
||||
|
||||
void ErrorMenu::Update(u64 ns) {
|
||||
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
u64 k_down = padGetButtonsDown(&g_pad);
|
||||
|
||||
/* Go back if B is pressed. */
|
||||
if (k_down & KEY_B) {
|
||||
if (k_down & HidNpadButton_B) {
|
||||
g_exit_requested = true;
|
||||
return;
|
||||
}
|
||||
@ -411,10 +410,10 @@ namespace dbk {
|
||||
}
|
||||
|
||||
void WarningMenu::Update(u64 ns) {
|
||||
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
u64 k_down = padGetButtonsDown(&g_pad);
|
||||
|
||||
/* Go back if B is pressed. */
|
||||
if (k_down & KEY_B) {
|
||||
if (k_down & HidNpadButton_B) {
|
||||
ReturnToPreviousMenu();
|
||||
return;
|
||||
}
|
||||
@ -449,9 +448,9 @@ namespace dbk {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -574,16 +573,16 @@ namespace dbk {
|
||||
const float x = g_screen_width / 2.0f - WindowWidth / 2.0f;
|
||||
const float y = g_screen_height / 2.0f - WindowHeight / 2.0f;
|
||||
|
||||
touchPosition current_pos;
|
||||
hidTouchRead(¤t_pos, 0);
|
||||
HidTouchScreenState current_touch;
|
||||
hidGetTouchScreenStates(¤t_touch, 1);
|
||||
|
||||
/* 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_max = y_min + FileRowHeight;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
@ -604,10 +603,10 @@ namespace dbk {
|
||||
|
||||
/* Scroll based on touch movement. */
|
||||
if (g_touches_moving) {
|
||||
touchPosition current_pos;
|
||||
hidTouchRead(¤t_pos, 0);
|
||||
HidTouchScreenState current_touch;
|
||||
hidGetTouchScreenStates(¤t_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 max_scroll = (FileRowHeight + FileRowGap) * static_cast<float>(m_file_entries.size()) - FileListHeight;
|
||||
|
||||
@ -688,16 +687,16 @@ namespace dbk {
|
||||
}
|
||||
|
||||
void FileMenu::Update(u64 ns) {
|
||||
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
u64 k_down = padGetButtonsDown(&g_pad);
|
||||
|
||||
/* Go back if B is pressed. */
|
||||
if (k_down & KEY_B) {
|
||||
if (k_down & HidNpadButton_B) {
|
||||
ReturnToPreviousMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Finalize selection on pressing A. */
|
||||
if (k_down & KEY_A) {
|
||||
if (k_down & HidNpadButton_A) {
|
||||
this->FinalizeSelection();
|
||||
}
|
||||
|
||||
@ -706,14 +705,14 @@ namespace dbk {
|
||||
|
||||
const u32 prev_index = m_current_index;
|
||||
|
||||
if (k_down & KEY_DOWN) {
|
||||
if (k_down & HidNpadButton_AnyDown) {
|
||||
/* Scroll down. */
|
||||
if (m_current_index >= (m_file_entries.size() - 1)) {
|
||||
m_current_index = 0;
|
||||
} else {
|
||||
m_current_index++;
|
||||
}
|
||||
} else if (k_down & KEY_UP) {
|
||||
} else if (k_down & HidNpadButton_AnyUp) {
|
||||
/* Scroll up. */
|
||||
if (m_current_index == 0) {
|
||||
m_current_index = m_file_entries.size() - 1;
|
||||
@ -859,10 +858,10 @@ namespace dbk {
|
||||
this->ValidateUpdate();
|
||||
}
|
||||
|
||||
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
u64 k_down = padGetButtonsDown(&g_pad);
|
||||
|
||||
/* Go back if B is pressed. */
|
||||
if (k_down & KEY_B) {
|
||||
if (k_down & HidNpadButton_B) {
|
||||
ReturnToPreviousMenu();
|
||||
return;
|
||||
}
|
||||
@ -923,10 +922,10 @@ namespace dbk {
|
||||
}
|
||||
|
||||
void ChooseResetMenu::Update(u64 ns) {
|
||||
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
u64 k_down = padGetButtonsDown(&g_pad);
|
||||
|
||||
/* Go back if B is pressed. */
|
||||
if (k_down & KEY_B) {
|
||||
if (k_down & HidNpadButton_B) {
|
||||
ReturnToPreviousMenu();
|
||||
return;
|
||||
}
|
||||
@ -986,10 +985,10 @@ namespace dbk {
|
||||
}
|
||||
|
||||
void ChooseExfatMenu::Update(u64 ns) {
|
||||
u64 k_down = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
u64 k_down = padGetButtonsDown(&g_pad);
|
||||
|
||||
/* Go back if B is pressed. */
|
||||
if (k_down & KEY_B) {
|
||||
if (k_down & HidNpadButton_B) {
|
||||
ReturnToPreviousMenu();
|
||||
return;
|
||||
}
|
||||
@ -1195,6 +1194,13 @@ namespace dbk {
|
||||
void InitializeMenu(u32 screen_width, u32 screen_height) {
|
||||
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. */
|
||||
g_screen_width = screen_width;
|
||||
g_screen_height = screen_height;
|
||||
|
Loading…
Reference in New Issue
Block a user