9 # error This is a userspace-only header, not allowed by the current build.
12 #include <sifteo/menu/types.h>
21 inline void Menu::detectNeighbors()
23 Neighborhood nbr(vid->cube());
28 if (nbr.hasCubeAt(i)) {
29 CubeID c(nbr.cubeAt(i));
30 n.neighborSide = Neighborhood(c).sideOf(vid->cube());
39 if (n != neighbors[i]) {
43 currentEvent.type = MENU_NEIGHBOR_REMOVE;
44 currentEvent.neighbor = neighbors[i];
51 neighbors[i].neighborSide =
NO_SIDE;
53 neighbors[i].masterSide =
NO_SIDE;
56 currentEvent.type = MENU_NEIGHBOR_ADD;
57 currentEvent.neighbor = n;
69 inline uint8_t Menu::computeSelected()
71 int s = (position + (kItemPixelWidth() / 2)) / kItemPixelWidth();
72 return clamp(s, 0, numItems - 1);
75 inline void Menu::checkForPress()
77 bool touch = vid->cube().isTouching();
79 if (touch && !prevTouch) {
80 currentEvent.type = MENU_ITEM_PRESS;
81 currentEvent.item = computeSelected();
89 inline void Menu::drawColumn(
int x)
92 Int2 topLeft = {
umod(x, kNumTilesX), 0 };
93 Int2 size = { 1, kIconTileHeight };
96 if (itemAtCol(x) < numItems) {
98 const AssetImage &img = *items[itemAtCol(x)].icon;
99 Int2 srcXY = { ((x % kItemTileWidth()) % img.tileWidth()), 0 };
100 vid->bg0.image(topLeft, size, img, srcXY);
102 if (assets->overflowIcon &&
umod(x,kIconTileWidth) < kItemTileWidth()) {
104 x =
umod(x, kItemTileWidth());
105 const AssetImage &img = *assets->overflowIcon;
106 Int2 srcXY = { ((x % kItemTileWidth()) % img.tileWidth()), 0 };
107 vid->bg0.image(topLeft, size, img, srcXY);
110 vid->bg0.fill(topLeft, size, *assets->background);
115 inline void Menu::drawFooter(
bool force)
117 if (numTips == 0)
return;
119 const AssetImage& footer = *assets->tips[currentTip];
120 const float kSecondsPerTip = 4.f;
126 currentTip = (currentTip+1) % numTips;
129 Int2 topLeft = { 0, kNumVisibleTilesY - footer.tileHeight() };
130 vid->bg1.image(topLeft, footer);
134 inline int Menu::stoppingPositionFor(
int selected)
136 return kItemPixelWidth() * selected;
139 inline float Menu::velocityMultiplier()
141 return abs(accel.x) > kAccelThresholdStep ? (1.f * kMaxSpeedMultiplier) : 1.f;
144 inline float Menu::maxVelocity()
146 const float kMaxNormalSpeed = 40.f;
147 return kMaxNormalSpeed *
149 (
abs(accel.x) / kOneG()) *
151 velocityMultiplier();
154 inline float Menu::lerp(
float min,
float max,
float u)
156 return min + u * (max - min);
159 inline void Menu::updateBG0()
161 int ut = computeCurrentTile();
163 while(prev_ut < ut) {
164 drawColumn(++prev_ut + kNumVisibleTilesX);
166 while(prev_ut > ut) {
167 drawColumn(--prev_ut);
171 Int2 vec = {(position - kEndCapPadding), kIconYOffset};
172 vid->bg0.setPanning(vec);
176 inline bool Menu::itemVisibleAtCol(uint8_t item,
int column)
178 ASSERT(item >= 0 && item < numItems);
179 if (column < 0)
return false;
181 return itemAtCol(column) == item;
184 inline uint8_t Menu::itemAtCol(
int column)
186 if (column < 0)
return numItems;
188 if (column % kItemTileWidth() < kIconTileWidth) {
189 return column < 0 ? numItems : column / kItemTileWidth();
194 inline int Menu::computeCurrentTile()
200 const int kPixelsPerTile = TILE;
201 const int kPositionAlignment = kEndCapPadding % kPixelsPerTile == 0
202 ? 0 : kPixelsPerTile - kEndCapPadding % kPixelsPerTile;
203 const int kTilePadding = kEndCapPadding / kPixelsPerTile;
205 int ui = position - kPositionAlignment;
206 int ut = (ui < 0 ? ui - kPixelsPerTile : ui) / kPixelsPerTile;