mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Rename FocusDirection to FocusMove, make into enum class
This commit is contained in:
@@ -19,7 +19,7 @@ struct Point2D {
|
||||
}
|
||||
|
||||
/*
|
||||
FocusDirection directionTo(const Point &other) const {
|
||||
FocusMove directionTo(const Point &other) const {
|
||||
int angle = atan2f(other.y - y, other.x - x) / (2 * M_PI) - 0.125;
|
||||
|
||||
}*/
|
||||
|
||||
+10
-10
@@ -148,7 +148,7 @@ void LayoutViewHierarchy(const UIContext &dc, const UI::Margins &rootMargins, Vi
|
||||
root->Layout();
|
||||
}
|
||||
|
||||
static void MoveFocus(ViewGroup *root, FocusDirection direction) {
|
||||
static void MoveFocus(ViewGroup *root, FocusMove direction) {
|
||||
View *focusedView = GetFocusedView();
|
||||
if (!focusedView) {
|
||||
// Nothing was focused when we got in here. Focus the first non-group in the hierarchy.
|
||||
@@ -406,15 +406,15 @@ DialogResult UpdateViewHierarchy(ViewGroup *root) {
|
||||
} else {
|
||||
for (size_t i = 0; i < focusMoves.size(); i++) {
|
||||
switch (focusMoves[i]) {
|
||||
case NKCODE_DPAD_LEFT: MoveFocus(root, FOCUS_LEFT); break;
|
||||
case NKCODE_DPAD_RIGHT: MoveFocus(root, FOCUS_RIGHT); break;
|
||||
case NKCODE_DPAD_UP: MoveFocus(root, FOCUS_UP); break;
|
||||
case NKCODE_DPAD_DOWN: MoveFocus(root, FOCUS_DOWN); break;
|
||||
case NKCODE_PAGE_UP: MoveFocus(root, FOCUS_PREV_PAGE); break;
|
||||
case NKCODE_PAGE_DOWN: MoveFocus(root, FOCUS_NEXT_PAGE); break;
|
||||
case NKCODE_MOVE_HOME: MoveFocus(root, FOCUS_FIRST); break;
|
||||
case NKCODE_MOVE_END: MoveFocus(root, FOCUS_LAST); break;
|
||||
case NKCODE_TAB: MoveFocus(root, FOCUS_NEXT); break;
|
||||
case NKCODE_DPAD_LEFT: MoveFocus(root, FocusMove::LEFT); break;
|
||||
case NKCODE_DPAD_RIGHT: MoveFocus(root, FocusMove::RIGHT); break;
|
||||
case NKCODE_DPAD_UP: MoveFocus(root, FocusMove::UP); break;
|
||||
case NKCODE_DPAD_DOWN: MoveFocus(root, FocusMove::DOWN); break;
|
||||
case NKCODE_PAGE_UP: MoveFocus(root, FocusMove::PREV_PAGE); break;
|
||||
case NKCODE_PAGE_DOWN: MoveFocus(root, FocusMove::NEXT_PAGE); break;
|
||||
case NKCODE_MOVE_HOME: MoveFocus(root, FocusMove::FIRST); break;
|
||||
case NKCODE_MOVE_END: MoveFocus(root, FocusMove::LAST); break;
|
||||
case NKCODE_TAB: MoveFocus(root, FocusMove::NEXT); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ bool ScrollView::SubviewFocused(View *view) {
|
||||
return true;
|
||||
}
|
||||
|
||||
NeighborResult ScrollView::FindScrollNeighbor(View *view, const Point2D &target, FocusDirection direction, NeighborResult best) {
|
||||
NeighborResult ScrollView::FindScrollNeighbor(View *view, const Point2D &target, FocusMove direction, NeighborResult best) {
|
||||
if (ContainsSubview(view) && views_[0]->IsViewGroup()) {
|
||||
ViewGroup *vg = static_cast<ViewGroup *>(views_[0]);
|
||||
int found = -1;
|
||||
@@ -381,10 +381,10 @@ NeighborResult ScrollView::FindScrollNeighbor(View *view, const Point2D &target,
|
||||
if (found != -1) {
|
||||
float mult = 0.0f;
|
||||
switch (direction) {
|
||||
case FOCUS_PREV_PAGE:
|
||||
case FocusMove::PREV_PAGE:
|
||||
mult = -1.0f;
|
||||
break;
|
||||
case FOCUS_NEXT_PAGE:
|
||||
case FocusMove::NEXT_PAGE:
|
||||
mult = 1.0f;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
shadows_ = shadows;
|
||||
}
|
||||
|
||||
NeighborResult FindScrollNeighbor(View *view, const Point2D &target, FocusDirection direction, NeighborResult best) override;
|
||||
NeighborResult FindScrollNeighbor(View *view, const Point2D &target, FocusMove direction, NeighborResult best) override;
|
||||
|
||||
private:
|
||||
Margins GetMargins() const;
|
||||
|
||||
+8
-8
@@ -160,25 +160,25 @@ void View::PersistData(PersistStatus status, std::string anonId, PersistMap &sto
|
||||
}
|
||||
}
|
||||
|
||||
Point2D View::GetFocusPosition(FocusDirection dir) const {
|
||||
Point2D View::GetFocusPosition(FocusMove dir) const {
|
||||
// The +2/-2 is some extra fudge factor to cover for views sitting right next to each other.
|
||||
// Distance zero yields strange results otherwise.
|
||||
switch (dir) {
|
||||
case FOCUS_LEFT: return Point2D(bounds_.x + 2, bounds_.centerY());
|
||||
case FOCUS_RIGHT: return Point2D(bounds_.x2() - 2, bounds_.centerY());
|
||||
case FOCUS_UP: return Point2D(bounds_.centerX(), bounds_.y + 2);
|
||||
case FOCUS_DOWN: return Point2D(bounds_.centerX(), bounds_.y2() - 2);
|
||||
case FocusMove::LEFT: return Point2D(bounds_.x + 2, bounds_.centerY());
|
||||
case FocusMove::RIGHT: return Point2D(bounds_.x2() - 2, bounds_.centerY());
|
||||
case FocusMove::UP: return Point2D(bounds_.centerX(), bounds_.y + 2);
|
||||
case FocusMove::DOWN: return Point2D(bounds_.centerX(), bounds_.y2() - 2);
|
||||
|
||||
default:
|
||||
return bounds_.Center();
|
||||
}
|
||||
}
|
||||
|
||||
Point2D CollapsibleHeader::GetFocusPosition(FocusDirection dir) const {
|
||||
Point2D CollapsibleHeader::GetFocusPosition(FocusMove dir) const {
|
||||
// Bias the focus position to the left.
|
||||
switch (dir) {
|
||||
case FOCUS_UP: return Point2D(bounds_.x + 50, bounds_.y + 2);
|
||||
case FOCUS_DOWN: return Point2D(bounds_.x + 50, bounds_.y2() - 2);
|
||||
case FocusMove::UP: return Point2D(bounds_.x + 50, bounds_.y + 2);
|
||||
case FocusMove::DOWN: return Point2D(bounds_.x + 50, bounds_.y2() - 2);
|
||||
default:
|
||||
return View::GetFocusPosition(dir);
|
||||
}
|
||||
|
||||
+26
-26
@@ -118,17 +118,17 @@ struct Theme {
|
||||
};
|
||||
|
||||
// The four cardinal directions should be enough, plus Prev/Next in "element order".
|
||||
enum FocusDirection {
|
||||
FOCUS_UP,
|
||||
FOCUS_DOWN,
|
||||
FOCUS_LEFT,
|
||||
FOCUS_RIGHT,
|
||||
FOCUS_NEXT,
|
||||
FOCUS_PREV,
|
||||
FOCUS_FIRST,
|
||||
FOCUS_LAST,
|
||||
FOCUS_PREV_PAGE,
|
||||
FOCUS_NEXT_PAGE,
|
||||
enum class FocusMove {
|
||||
UP,
|
||||
DOWN,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
NEXT,
|
||||
PREV,
|
||||
FIRST,
|
||||
LAST,
|
||||
PREV_PAGE,
|
||||
NEXT_PAGE,
|
||||
};
|
||||
|
||||
typedef float Size; // can also be WRAP_CONTENT or FILL_PARENT.
|
||||
@@ -181,18 +181,18 @@ enum class BorderStyle {
|
||||
ITEM_DOWN_BG,
|
||||
};
|
||||
|
||||
inline FocusDirection Opposite(FocusDirection d) {
|
||||
inline FocusMove Opposite(FocusMove d) {
|
||||
switch (d) {
|
||||
case FOCUS_UP: return FOCUS_DOWN;
|
||||
case FOCUS_DOWN: return FOCUS_UP;
|
||||
case FOCUS_LEFT: return FOCUS_RIGHT;
|
||||
case FOCUS_RIGHT: return FOCUS_LEFT;
|
||||
case FOCUS_PREV: return FOCUS_NEXT;
|
||||
case FOCUS_NEXT: return FOCUS_PREV;
|
||||
case FOCUS_FIRST: return FOCUS_LAST;
|
||||
case FOCUS_LAST: return FOCUS_FIRST;
|
||||
case FOCUS_PREV_PAGE: return FOCUS_NEXT_PAGE;
|
||||
case FOCUS_NEXT_PAGE: return FOCUS_PREV_PAGE;
|
||||
case FocusMove::UP: return FocusMove::DOWN;
|
||||
case FocusMove::DOWN: return FocusMove::UP;
|
||||
case FocusMove::LEFT: return FocusMove::RIGHT;
|
||||
case FocusMove::RIGHT: return FocusMove::LEFT;
|
||||
case FocusMove::PREV: return FocusMove::NEXT;
|
||||
case FocusMove::NEXT: return FocusMove::PREV;
|
||||
case FocusMove::FIRST: return FocusMove::LAST;
|
||||
case FocusMove::LAST: return FocusMove::FIRST;
|
||||
case FocusMove::PREV_PAGE: return FocusMove::NEXT_PAGE;
|
||||
case FocusMove::NEXT_PAGE: return FocusMove::PREV_PAGE;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -414,7 +414,7 @@ public:
|
||||
|
||||
virtual bool CanBeFocused() const { return true; }
|
||||
virtual bool SubviewFocused(View *view) { return false; }
|
||||
virtual bool CanMoveFocus(FocusDirection dir) const { return true; }
|
||||
virtual bool CanMoveFocus(FocusMove dir) const { return true; }
|
||||
|
||||
void SetPopupStyle(bool popupStyle) { popupStyle_ = popupStyle; }
|
||||
|
||||
@@ -461,7 +461,7 @@ public:
|
||||
virtual bool IsViewGroup() const { return false; }
|
||||
virtual bool ContainsSubview(const View *view) const { return false; }
|
||||
|
||||
virtual Point2D GetFocusPosition(FocusDirection dir) const;
|
||||
virtual Point2D GetFocusPosition(FocusMove dir) const;
|
||||
|
||||
template <class T>
|
||||
T *AddTween(T *t) {
|
||||
@@ -944,7 +944,7 @@ public:
|
||||
void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override;
|
||||
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
||||
|
||||
Point2D GetFocusPosition(FocusDirection dir) const override;
|
||||
Point2D GetFocusPosition(FocusMove dir) const override;
|
||||
|
||||
void SetHasSubitems(bool hasSubItems) { hasSubItems_ = hasSubItems; }
|
||||
void SetOpenPtr(bool *open) {
|
||||
@@ -1117,7 +1117,7 @@ public:
|
||||
|
||||
void FocusChanged(int focusFlags) override;
|
||||
|
||||
bool CanMoveFocus(FocusDirection dir) const override { return dir != FocusDirection::FOCUS_LEFT && dir != FocusDirection::FOCUS_RIGHT; }
|
||||
bool CanMoveFocus(FocusMove dir) const override { return dir != FocusMove::LEFT && dir != FocusMove::RIGHT; }
|
||||
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
||||
void Draw(UIContext &dc) override;
|
||||
std::string DescribeText() const override;
|
||||
|
||||
+26
-29
@@ -314,7 +314,7 @@ static float VerticalOverlap(const Bounds &a, const Bounds &b) {
|
||||
return std::min(1.0f, overlap / minH);
|
||||
}
|
||||
|
||||
float GetTargetScore(const Point2D &originPos, int originIndex, const View *origin, const View *destination, FocusDirection direction) {
|
||||
float GetTargetScore(const Point2D &originPos, int originIndex, const View *origin, const View *destination, FocusMove direction) {
|
||||
// Skip labels and things like that.
|
||||
if (!destination->CanBeFocused())
|
||||
return 0.0f;
|
||||
@@ -328,10 +328,7 @@ float GetTargetScore(const Point2D &originPos, int originIndex, const View *orig
|
||||
float dx = destPos.x - originPos.x;
|
||||
float dy = destPos.y - originPos.y;
|
||||
|
||||
float distance = sqrtf(dx*dx + dy*dy);
|
||||
if (distance == 0.0f) {
|
||||
distance = 0.001f;
|
||||
}
|
||||
const float distance = std::max(sqrtf(dx*dx + dy*dy), 0.001f);
|
||||
float overlap = 0.0f;
|
||||
const float dirX = dx / distance;
|
||||
const float dirY = dy / distance;
|
||||
@@ -341,21 +338,21 @@ float GetTargetScore(const Point2D &originPos, int originIndex, const View *orig
|
||||
const float horizOverlap = HorizontalOverlap(origin->GetBounds(), destination->GetBounds());
|
||||
const float vertOverlap = VerticalOverlap(origin->GetBounds(), destination->GetBounds());
|
||||
if (horizOverlap == 1.0f && vertOverlap == 1.0f) {
|
||||
if (direction != FOCUS_PREV_PAGE && direction != FOCUS_NEXT_PAGE) {
|
||||
if (direction != FocusMove::PREV_PAGE && direction != FocusMove::NEXT_PAGE) {
|
||||
INFO_LOG(Log::UI, "Contain overlap: %s, %s", origin->Tag().c_str(), destination->Tag().c_str());
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
float originSize = 0.0f;
|
||||
switch (direction) {
|
||||
case FOCUS_LEFT:
|
||||
case FocusMove::LEFT:
|
||||
overlap = vertOverlap;
|
||||
originSize = origin->GetBounds().w;
|
||||
if (dirX > 0.0f) {
|
||||
wrongDirection = true;
|
||||
}
|
||||
break;
|
||||
case FOCUS_UP:
|
||||
case FocusMove::UP:
|
||||
overlap = horizOverlap;
|
||||
originSize = origin->GetBounds().h;
|
||||
if (dirY > 0.0f) {
|
||||
@@ -363,14 +360,14 @@ float GetTargetScore(const Point2D &originPos, int originIndex, const View *orig
|
||||
}
|
||||
vertical = true;
|
||||
break;
|
||||
case FOCUS_RIGHT:
|
||||
case FocusMove::RIGHT:
|
||||
overlap = vertOverlap;
|
||||
originSize = origin->GetBounds().w;
|
||||
if (dirX < 0.0f) {
|
||||
wrongDirection = true;
|
||||
}
|
||||
break;
|
||||
case FOCUS_DOWN:
|
||||
case FocusMove::DOWN:
|
||||
overlap = horizOverlap;
|
||||
originSize = origin->GetBounds().h;
|
||||
if (dirY < 0.0f) {
|
||||
@@ -378,27 +375,27 @@ float GetTargetScore(const Point2D &originPos, int originIndex, const View *orig
|
||||
}
|
||||
vertical = true;
|
||||
break;
|
||||
case FOCUS_FIRST:
|
||||
case FocusMove::FIRST:
|
||||
if (originIndex == -1)
|
||||
return 0.0f;
|
||||
if (dirX > 0.0f || dirY > 0.0f)
|
||||
return 0.0f;
|
||||
// More distance is good.
|
||||
return distance;
|
||||
case FOCUS_LAST:
|
||||
case FocusMove::LAST:
|
||||
if (originIndex == -1)
|
||||
return 0.0f;
|
||||
if (dirX < 0.0f || dirY < 0.0f)
|
||||
return 0.0f;
|
||||
// More distance is good.
|
||||
return distance;
|
||||
case FOCUS_PREV_PAGE:
|
||||
case FOCUS_NEXT_PAGE:
|
||||
case FocusMove::PREV_PAGE:
|
||||
case FocusMove::NEXT_PAGE:
|
||||
// Not always, but let's go with the bonus on height.
|
||||
vertical = true;
|
||||
break;
|
||||
case FOCUS_PREV:
|
||||
case FOCUS_NEXT:
|
||||
case FocusMove::PREV:
|
||||
case FocusMove::NEXT:
|
||||
ERROR_LOG(Log::UI, "Invalid focus direction");
|
||||
break;
|
||||
}
|
||||
@@ -414,12 +411,12 @@ float GetTargetScore(const Point2D &originPos, int originIndex, const View *orig
|
||||
}
|
||||
}
|
||||
|
||||
static float GetDirectionScore(int originIndex, const View *origin, View *destination, FocusDirection direction) {
|
||||
static float GetDirectionScore(int originIndex, const View *origin, View *destination, FocusMove direction) {
|
||||
Point2D originPos = origin->GetFocusPosition(direction);
|
||||
return GetTargetScore(originPos, originIndex, origin, destination, direction);
|
||||
}
|
||||
|
||||
NeighborResult ViewGroup::FindNeighbor(View *view, FocusDirection direction, NeighborResult result) {
|
||||
NeighborResult ViewGroup::FindNeighbor(View *view, FocusMove direction, NeighborResult result) {
|
||||
if (!IsEnabled()) {
|
||||
INFO_LOG(Log::UI, "Not enabled");
|
||||
return result;
|
||||
@@ -438,12 +435,12 @@ NeighborResult ViewGroup::FindNeighbor(View *view, FocusDirection direction, Nei
|
||||
}
|
||||
|
||||
switch (direction) {
|
||||
case FOCUS_UP:
|
||||
case FOCUS_LEFT:
|
||||
case FOCUS_RIGHT:
|
||||
case FOCUS_DOWN:
|
||||
case FOCUS_FIRST:
|
||||
case FOCUS_LAST:
|
||||
case FocusMove::UP:
|
||||
case FocusMove::LEFT:
|
||||
case FocusMove::RIGHT:
|
||||
case FocusMove::DOWN:
|
||||
case FocusMove::FIRST:
|
||||
case FocusMove::LAST:
|
||||
{
|
||||
// First, try the child views themselves as candidates
|
||||
for (size_t i = 0; i < views_.size(); i++) {
|
||||
@@ -472,15 +469,15 @@ NeighborResult ViewGroup::FindNeighbor(View *view, FocusDirection direction, Nei
|
||||
}
|
||||
return result;
|
||||
}
|
||||
case FOCUS_PREV_PAGE:
|
||||
case FOCUS_NEXT_PAGE:
|
||||
case FocusMove::PREV_PAGE:
|
||||
case FocusMove::NEXT_PAGE:
|
||||
return FindScrollNeighbor(view, Point2D(INFINITY, INFINITY), direction, result);
|
||||
case FOCUS_PREV:
|
||||
case FocusMove::PREV:
|
||||
// If view not found, no neighbor to find.
|
||||
if (num == -1)
|
||||
return NeighborResult(nullptr, 0.0f);
|
||||
return NeighborResult(views_[(num + views_.size() - 1) % views_.size()], 0.0f);
|
||||
case FOCUS_NEXT:
|
||||
case FocusMove::NEXT:
|
||||
// If view not found, no neighbor to find.
|
||||
if (num == -1)
|
||||
return NeighborResult(0, 0.0f);
|
||||
@@ -492,7 +489,7 @@ NeighborResult ViewGroup::FindNeighbor(View *view, FocusDirection direction, Nei
|
||||
}
|
||||
}
|
||||
|
||||
NeighborResult ViewGroup::FindScrollNeighbor(View *view, const Point2D &target, FocusDirection direction, NeighborResult best) {
|
||||
NeighborResult ViewGroup::FindScrollNeighbor(View *view, const Point2D &target, FocusMove direction, NeighborResult best) {
|
||||
if (!IsEnabled())
|
||||
return best;
|
||||
if (GetVisibility() != V_VISIBLE)
|
||||
|
||||
@@ -63,8 +63,8 @@ public:
|
||||
View *GetDefaultFocusView() { return defaultFocusView_; }
|
||||
|
||||
// Assumes that layout has taken place.
|
||||
NeighborResult FindNeighbor(View *view, FocusDirection direction, NeighborResult best);
|
||||
virtual NeighborResult FindScrollNeighbor(View *view, const Point2D &target, FocusDirection direction, NeighborResult best);
|
||||
NeighborResult FindNeighbor(View *view, FocusMove direction, NeighborResult best);
|
||||
virtual NeighborResult FindScrollNeighbor(View *view, const Point2D &target, FocusMove direction, NeighborResult best);
|
||||
|
||||
bool CanBeFocused() const override { return false; }
|
||||
bool IsViewGroup() const override { return true; }
|
||||
|
||||
Reference in New Issue
Block a user