Co-authored-by: Uri Tauber <uritaube@gmail.com>
This commit is contained in:
@@ -1,7 +1,18 @@
|
|||||||
#include "MappedInputManager.h"
|
#include "MappedInputManager.h"
|
||||||
|
|
||||||
|
#include <GfxRenderer.h>
|
||||||
|
|
||||||
#include "CrossPointSettings.h"
|
#include "CrossPointSettings.h"
|
||||||
|
|
||||||
|
bool MappedInputManager::isNavDirectionSwapped() const {
|
||||||
|
// Key the swap on the orientation the screen is *actually* rendered at, not the persisted reader
|
||||||
|
// setting. The reader (and its modal menus) render rotated, so navigation/labels flip there; the
|
||||||
|
// home and settings UI render in portrait, so they never flip even when a rotated reader is configured.
|
||||||
|
const auto orientation = renderer.getOrientation();
|
||||||
|
return SETTINGS.frontButtonFollowOrientation &&
|
||||||
|
(orientation == GfxRenderer::PortraitInverted || orientation == GfxRenderer::LandscapeCounterClockwise);
|
||||||
|
}
|
||||||
|
|
||||||
bool MappedInputManager::mapButton(const Button button, bool (HalGPIO::*fn)(uint8_t) const) const {
|
bool MappedInputManager::mapButton(const Button button, bool (HalGPIO::*fn)(uint8_t) const) const {
|
||||||
const auto sideLayout = SETTINGS.sideButtonLayout;
|
const auto sideLayout = SETTINGS.sideButtonLayout;
|
||||||
|
|
||||||
@@ -49,6 +60,15 @@ bool MappedInputManager::mapButton(const Button button, bool (HalGPIO::*fn)(uint
|
|||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
case Button::NavNext:
|
||||||
|
// Logical "next item" navigation: side Down + front Right, with the control axis flipped in
|
||||||
|
// INVERTED / LANDSCAPE_CCW (frontButtonFollowOrientation) so it matches the rotated hint labels.
|
||||||
|
return isNavDirectionSwapped() ? (mapButton(Button::Up, fn) || mapButton(Button::Left, fn))
|
||||||
|
: (mapButton(Button::Down, fn) || mapButton(Button::Right, fn));
|
||||||
|
case Button::NavPrevious:
|
||||||
|
// Logical "previous item" navigation: side Up + front Left, axis-flipped in the same orientations.
|
||||||
|
return isNavDirectionSwapped() ? (mapButton(Button::Down, fn) || mapButton(Button::Right, fn))
|
||||||
|
: (mapButton(Button::Up, fn) || mapButton(Button::Left, fn));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -69,9 +89,7 @@ unsigned long MappedInputManager::getHeldTime() const { return gpio.getHeldTime(
|
|||||||
MappedInputManager::Labels MappedInputManager::mapLabels(const char* back, const char* confirm, const char* previous,
|
MappedInputManager::Labels MappedInputManager::mapLabels(const char* back, const char* confirm, const char* previous,
|
||||||
const char* next) const {
|
const char* next) const {
|
||||||
// Swap previous/next labels to match the page turn direction swap in INVERTED and LANDSCAPE_CCW.
|
// Swap previous/next labels to match the page turn direction swap in INVERTED and LANDSCAPE_CCW.
|
||||||
const bool swapLabels =
|
const bool swapLabels = isNavDirectionSwapped();
|
||||||
SETTINGS.frontButtonFollowOrientation && (SETTINGS.orientation == CrossPointSettings::INVERTED ||
|
|
||||||
SETTINGS.orientation == CrossPointSettings::LANDSCAPE_CCW);
|
|
||||||
const char* leftLabel = swapLabels ? next : previous;
|
const char* leftLabel = swapLabels ? next : previous;
|
||||||
const char* rightLabel = swapLabels ? previous : next;
|
const char* rightLabel = swapLabels ? previous : next;
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
#include <HalGPIO.h>
|
#include <HalGPIO.h>
|
||||||
|
|
||||||
|
class GfxRenderer;
|
||||||
|
|
||||||
class MappedInputManager {
|
class MappedInputManager {
|
||||||
public:
|
public:
|
||||||
enum class Button { Back, Confirm, Left, Right, Up, Down, Power, PageBack, PageForward };
|
enum class Button { Back, Confirm, Left, Right, Up, Down, Power, PageBack, PageForward, NavNext, NavPrevious };
|
||||||
|
|
||||||
struct Labels {
|
struct Labels {
|
||||||
const char* btn1;
|
const char* btn1;
|
||||||
@@ -13,7 +15,7 @@ class MappedInputManager {
|
|||||||
const char* btn4;
|
const char* btn4;
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit MappedInputManager(HalGPIO& gpio) : gpio(gpio) {}
|
MappedInputManager(HalGPIO& gpio, const GfxRenderer& renderer) : gpio(gpio), renderer(renderer) {}
|
||||||
|
|
||||||
void update() const { gpio.update(); }
|
void update() const { gpio.update(); }
|
||||||
bool wasPressed(Button button) const;
|
bool wasPressed(Button button) const;
|
||||||
@@ -26,8 +28,20 @@ class MappedInputManager {
|
|||||||
// Returns the raw front button index that was pressed this frame (or -1 if none).
|
// Returns the raw front button index that was pressed this frame (or -1 if none).
|
||||||
int getPressedFrontButton() const;
|
int getPressedFrontButton() const;
|
||||||
|
|
||||||
|
// True when the control axis is flipped relative to the physical buttons: the user opted into
|
||||||
|
// orientation-following front buttons AND the screen is *currently rendered* rotated (INVERTED /
|
||||||
|
// LANDSCAPE_CCW). Keyed on the live renderer orientation rather than the persisted reader setting,
|
||||||
|
// so portrait UI (home, settings) never swaps while the reader and its menus do.
|
||||||
|
[[nodiscard]] bool isNavDirectionSwapped() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HalGPIO& gpio;
|
HalGPIO& gpio;
|
||||||
|
// Logical-to-physical button mapping depends on what the user is actually looking at: when the
|
||||||
|
// screen is rendered rotated, the directional buttons must flip to match. The renderer is the only
|
||||||
|
// authority on the *live* orientation (the reader rotates it and restores portrait on exit), so we
|
||||||
|
// read it here instead of CrossPointSettings.orientation, which is just the persisted reader
|
||||||
|
// preference and stays "rotated" even while portrait UI like home/settings is on screen.
|
||||||
|
const GfxRenderer& renderer;
|
||||||
|
|
||||||
bool mapButton(Button button, bool (HalGPIO::*fn)(uint8_t) const) const;
|
bool mapButton(Button button, bool (HalGPIO::*fn)(uint8_t) const) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,11 +43,8 @@ inline PageTurnResult detectPageTurn(const MappedInputManager& input) {
|
|||||||
const bool usePress = SETTINGS.longPressButtonBehavior == SETTINGS.OFF;
|
const bool usePress = SETTINGS.longPressButtonBehavior == SETTINGS.OFF;
|
||||||
const bool tiltNext = SETTINGS.tiltPageTurn && halTiltSensor.wasTiltedForward();
|
const bool tiltNext = SETTINGS.tiltPageTurn && halTiltSensor.wasTiltedForward();
|
||||||
const bool tiltPrev = SETTINGS.tiltPageTurn && halTiltSensor.wasTiltedBack();
|
const bool tiltPrev = SETTINGS.tiltPageTurn && halTiltSensor.wasTiltedBack();
|
||||||
const bool swapFront =
|
const auto prevButton = MappedInputManager::Button::NavPrevious;
|
||||||
SETTINGS.frontButtonFollowOrientation && (SETTINGS.orientation == CrossPointSettings::INVERTED ||
|
const auto nextButton = MappedInputManager::Button::NavNext;
|
||||||
SETTINGS.orientation == CrossPointSettings::LANDSCAPE_CCW);
|
|
||||||
const auto prevButton = swapFront ? MappedInputManager::Button::Right : MappedInputManager::Button::Left;
|
|
||||||
const auto nextButton = swapFront ? MappedInputManager::Button::Left : MappedInputManager::Button::Right;
|
|
||||||
const bool prev =
|
const bool prev =
|
||||||
tiltPrev ||
|
tiltPrev ||
|
||||||
(usePress ? (input.wasPressed(MappedInputManager::Button::PageBack) || input.wasPressed(prevButton))
|
(usePress ? (input.wasPressed(MappedInputManager::Button::PageBack) || input.wasPressed(prevButton))
|
||||||
|
|||||||
+1
-1
@@ -34,8 +34,8 @@
|
|||||||
#include "util/ButtonNavigator.h"
|
#include "util/ButtonNavigator.h"
|
||||||
#include "util/ScreenshotUtil.h"
|
#include "util/ScreenshotUtil.h"
|
||||||
|
|
||||||
MappedInputManager mappedInputManager(gpio);
|
|
||||||
GfxRenderer renderer(display);
|
GfxRenderer renderer(display);
|
||||||
|
MappedInputManager mappedInputManager(gpio, renderer);
|
||||||
ActivityManager activityManager(renderer, mappedInputManager);
|
ActivityManager activityManager(renderer, mappedInputManager);
|
||||||
FontDecompressor fontDecompressor;
|
FontDecompressor fontDecompressor;
|
||||||
SdCardFontSystem sdFontSystem;
|
SdCardFontSystem sdFontSystem;
|
||||||
|
|||||||
@@ -44,10 +44,8 @@ class ButtonNavigator final {
|
|||||||
[[nodiscard]] static int nextPageIndex(int currentIndex, int totalItems, int itemsPerPage);
|
[[nodiscard]] static int nextPageIndex(int currentIndex, int totalItems, int itemsPerPage);
|
||||||
[[nodiscard]] static int previousPageIndex(int currentIndex, int totalItems, int itemsPerPage);
|
[[nodiscard]] static int previousPageIndex(int currentIndex, int totalItems, int itemsPerPage);
|
||||||
|
|
||||||
[[nodiscard]] static Buttons getNextButtons() {
|
// Navigation uses the logical NavNext / NavPrevious buttons; MappedInputManager::mapButton resolves
|
||||||
return {MappedInputManager::Button::Down, MappedInputManager::Button::Right};
|
// them to physical buttons and applies any orientation-based direction swap, so this stays settings-free.
|
||||||
}
|
[[nodiscard]] static Buttons getNextButtons() { return {MappedInputManager::Button::NavNext}; }
|
||||||
[[nodiscard]] static Buttons getPreviousButtons() {
|
[[nodiscard]] static Buttons getPreviousButtons() { return {MappedInputManager::Button::NavPrevious}; }
|
||||||
return {MappedInputManager::Button::Up, MappedInputManager::Button::Left};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user