28 # error This is a userspace-only header, not allowed by the current build.
31 #include <sifteo/menu/types.h>
40 inline void Menu::detectNeighbors()
42 Neighborhood nbr(vid->cube());
47 if (nbr.hasCubeAt(i)) {
48 CubeID c(nbr.cubeAt(i));
49 n.neighborSide = Neighborhood(c).sideOf(vid->cube());
58 if (n != neighbors[i]) {
62 currentEvent.type = MENU_NEIGHBOR_REMOVE;
63 currentEvent.neighbor = neighbors[i];
70 neighbors[i].neighborSide =
NO_SIDE;
72 neighbors[i].masterSide =
NO_SIDE;
75 currentEvent.type = MENU_NEIGHBOR_ADD;
76 currentEvent.neighbor = n;
88 inline uint8_t Menu::computeSelected()
90 int s = (position + (kItemPixelWidth() / 2)) / kItemPixelWidth();
91 return clamp(s, 0, numItems - 1);
94 inline void Menu::checkForPress()
96 bool touch = vid->cube().isTouching();
98 if (touch && !prevTouch) {
99 currentEvent.type = MENU_ITEM_PRESS;
100 currentEvent.item = computeSelected();
108 inline void Menu::drawColumn(
int x)
111 Int2 topLeft = {
umod(x, kNumTilesX), 0 };
112 Int2 size = { 1, kIconTileHeight };
115 if (itemAtCol(x) < numItems) {
117 const AssetImage &img = *items[itemAtCol(x)].icon;
118 Int2 srcXY = { ((x % kItemTileWidth()) % img.tileWidth()), 0 };
119 vid->bg0.image(topLeft, size, img, srcXY);
121 if (assets->overflowIcon &&
umod(x,kIconTileWidth) < kItemTileWidth()) {
123 x =
umod(x, kItemTileWidth());
124 const AssetImage &img = *assets->overflowIcon;
125 Int2 srcXY = { ((x % kItemTileWidth()) % img.tileWidth()), 0 };
126 vid->bg0.image(topLeft, size, img, srcXY);
129 vid->bg0.fill(topLeft, size, *assets->background);
134 inline void Menu::drawFooter(
bool force)
136 if (numTips == 0)
return;
138 const AssetImage& footer = *assets->tips[currentTip];
139 const float kSecondsPerTip = 4.f;
145 currentTip = (currentTip+1) % numTips;
148 Int2 topLeft = { 0, kNumVisibleTilesY - footer.tileHeight() };
149 vid->bg1.image(topLeft, footer);
153 inline int Menu::stoppingPositionFor(
int selected)
155 return kItemPixelWidth() * selected;
158 inline float Menu::velocityMultiplier()
160 return abs(accel.x) > kAccelThresholdStep ? (1.f * kMaxSpeedMultiplier) : 1.f;
163 inline float Menu::maxVelocity()
165 const float kMaxNormalSpeed = 40.f;
166 return kMaxNormalSpeed *
168 (
abs(accel.x) / kOneG()) *
170 velocityMultiplier();
173 inline float Menu::lerp(
float min,
float max,
float u)
175 return min + u * (max - min);
178 inline void Menu::updateBG0()
180 int ut = computeCurrentTile();
182 while(prev_ut < ut) {
183 drawColumn(++prev_ut + kNumVisibleTilesX);
185 while(prev_ut > ut) {
186 drawColumn(--prev_ut);
190 Int2 vec = {(position - kEndCapPadding), kIconYOffset};
191 vid->bg0.setPanning(vec);
195 inline bool Menu::itemVisibleAtCol(uint8_t item,
int column)
197 ASSERT(item >= 0 && item < numItems);
198 if (column < 0)
return false;
200 return itemAtCol(column) == item;
203 inline uint8_t Menu::itemAtCol(
int column)
205 if (column < 0)
return numItems;
207 if (column % kItemTileWidth() < kIconTileWidth) {
208 return column < 0 ? numItems : column / kItemTileWidth();
213 inline int Menu::computeCurrentTile()
219 const int kPixelsPerTile = TILE;
220 const int kPositionAlignment = kEndCapPadding % kPixelsPerTile == 0
221 ? 0 : kPixelsPerTile - kEndCapPadding % kPixelsPerTile;
222 const int kTilePadding = kEndCapPadding / kPixelsPerTile;
224 int ui = position - kPositionAlignment;
225 int ut = (ui < 0 ? ui - kPixelsPerTile : ui) / kPixelsPerTile;
static SystemTime now()
Returns a new SystemTime representing the current system clock value.
Definition: time.h:269
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
Side
An enumeration which names the four sides of a Sifteo cube.
Definition: cube.h:54
Vector2< int > Int2
Typedef for a 2-vector of ints.
Definition: math.h:641
T abs(const T &value)
For any type, return the absolute value.
Definition: math.h:90
Nil value (-1)
Definition: cube.h:60
unsigned umod(int a, int b)
Compute the unsigned remainder from dividing two signed integers.
Definition: math.h:208
Total number of sides (4)
Definition: cube.h:59
T clamp(const T &value, const T &low, const T &high)
For any type, clamp a value to the extremes 'low' and 'high'.
Definition: math.h:72
static const _SYSCubeID UNDEFINED
A reserved ID, used to mark undefined CubeIDs.
Definition: cube.h:92
Vector2< T > vec(T x, T y)
Create a Vector2, from a set of (x,y) coordinates.
Definition: math.h:658