MCPcopy Create free account
hub / github.com/Aloshi/EmulationStation / moveCursor

Method moveCursor

src/components/ComponentListComponent.cpp:198–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198void ComponentListComponent::moveCursor(Eigen::Vector2i dir)
199{
200 if(dir.x() != 0 && dir.y() != 0)
201 {
202 LOG(LogError) << "Invalid cursor move dir!";
203 return;
204 }
205
206 if(!cursorValid())
207 {
208 resetCursor();
209 if(!cursorValid())
210 return;
211 }
212
213 Eigen::Vector2i origCursor = mCursor;
214
215 Eigen::Vector2i searchAxis(dir.x() == 0, dir.y() == 0);
216
217 while(mCursor.x() >= 0 && mCursor.y() >= 0 && mCursor.x() < mGridSize.x() && mCursor.y() < mGridSize.y())
218 {
219 mCursor = mCursor + dir;
220
221 Eigen::Vector2i curDirPos = mCursor;
222
223 //spread out on search axis+
224 while(mCursor.x() < mGridSize.x() && mCursor.y() < mGridSize.y())
225 {
226 if(cursorValid() && getCell(mCursor.x(), mCursor.y())->canFocus)
227 return;
228
229 mCursor += searchAxis;
230 }
231
232 //now again on search axis-
233 mCursor = curDirPos;
234 while(mCursor.x() >= 0 && mCursor.y() >= 0)
235 {
236 if(cursorValid() && getCell(mCursor.x(), mCursor.y())->canFocus)
237 return;
238
239 mCursor -= searchAxis;
240 }
241
242 mCursor = curDirPos;
243 }
244
245 //failed to find another focusable element in this direction
246 mCursor = origCursor;
247}
248
249bool ComponentListComponent::cursorValid()
250{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected