forked from Aloshi/EmulationStation
-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathImageGridComponent.h
More file actions
725 lines (574 loc) · 19.7 KB
/
ImageGridComponent.h
File metadata and controls
725 lines (574 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
#pragma once
#ifndef ES_CORE_COMPONENTS_IMAGE_GRID_COMPONENT_H
#define ES_CORE_COMPONENTS_IMAGE_GRID_COMPONENT_H
#include "Log.h"
#include "animations/LambdaAnimation.h"
#include "components/IList.h"
#include "resources/TextureResource.h"
#include "GridTileComponent.h"
#define EXTRAITEMS 2
enum ScrollDirection
{
SCROLL_VERTICALLY,
SCROLL_HORIZONTALLY
};
enum ImageSource
{
THUMBNAIL,
IMAGE,
MARQUEE
};
struct ImageGridData
{
std::string texturePath;
};
template<typename T>
class ImageGridComponent : public IList<ImageGridData, T>
{
protected:
using IList<ImageGridData, T>::mEntries;
using IList<ImageGridData, T>::mScrollTier;
using IList<ImageGridData, T>::listUpdate;
using IList<ImageGridData, T>::listInput;
using IList<ImageGridData, T>::listRenderTitleOverlay;
using IList<ImageGridData, T>::getTransform;
using IList<ImageGridData, T>::mSize;
using IList<ImageGridData, T>::mCursor;
using IList<ImageGridData, T>::Entry;
using IList<ImageGridData, T>::mWindow;
public:
using IList<ImageGridData, T>::size;
using IList<ImageGridData, T>::isScrolling;
using IList<ImageGridData, T>::stopScrolling;
ImageGridComponent(Window* window);
void add(const std::string& name, const std::string& imagePath, const T& obj);
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
void onSizeChanged() override;
inline void setCursorChangedCallback(const std::function<void(CursorState state)>& func) { mCursorChangedCallback = func; }
ImageSource getImageSource() { return mImageSource; };
protected:
virtual void onCursorChanged(const CursorState& state) override;
private:
// TILES
void buildTiles();
void updateTiles(bool ascending = true, bool allowAnimation = true, bool updateSelectedState = true);
void updateTileAtPos(int tilePos, int imgPos, bool allowAnimation, bool updateSelectedState);
void calcGridDimension();
bool isScrollLoop();
bool isVertical() { return mScrollDirection == SCROLL_VERTICALLY; };
// IMAGES & ENTRIES
bool mEntriesDirty;
int mLastCursor;
std::string mDefaultGameTexture;
std::string mDefaultFolderTexture;
// TILES
bool mLastRowPartial;
Vector2f mAutoLayout;
float mAutoLayoutZoom;
int mLastScrollTier;
Vector4f mPadding;
Vector2f mMargin;
Vector2f mTileSize;
Vector2i mGridDimension;
std::shared_ptr<ThemeData> mTheme;
std::vector< std::shared_ptr<GridTileComponent> > mTiles;
int mStartPosition;
float mCamera;
float mCameraDirection;
// MISCELLANEOUS
bool mAnimate;
bool mCenterSelection;
bool mScrollLoop;
ScrollDirection mScrollDirection;
ImageSource mImageSource;
std::function<void(CursorState state)> mCursorChangedCallback;
};
template<typename T>
ImageGridComponent<T>::ImageGridComponent(Window* window) : IList<ImageGridData, T>(window)
{
Vector2f screen = Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
mCamera = 0.0;
mCameraDirection = 1.0;
mAutoLayout = Vector2f::Zero();
mAutoLayoutZoom = 1.0;
mLastScrollTier = 0;
mStartPosition = 0;
mEntriesDirty = true;
mLastCursor = 0;
mDefaultGameTexture = ":/cartridge.svg";
mDefaultFolderTexture = ":/folder.svg";
mSize = screen * 0.80f;
mMargin = screen * 0.07f;
mPadding = Vector4f::Zero();
mTileSize = GridTileComponent::getDefaultTileSize();
mAnimate = true;
mCenterSelection = false;
mScrollLoop = false;
mScrollDirection = SCROLL_VERTICALLY;
mImageSource = THUMBNAIL;
}
template<typename T>
void ImageGridComponent<T>::add(const std::string& name, const std::string& imagePath, const T& obj)
{
typename IList<ImageGridData, T>::Entry entry;
entry.name = name;
entry.object = obj;
entry.data.texturePath = imagePath;
static_cast<IList< ImageGridData, T >*>(this)->add(entry);
mEntriesDirty = true;
}
template<typename T>
bool ImageGridComponent<T>::input(InputConfig* config, Input input)
{
if(input.value != 0)
{
int idx = isVertical() ? 0 : 1;
Vector2i dir = Vector2i::Zero();
if(config->isMappedLike("up", input))
dir[1 ^ idx] = -1;
else if(config->isMappedLike("down", input))
dir[1 ^ idx] = 1;
else if(config->isMappedLike("left", input))
dir[0 ^ idx] = -1;
else if(config->isMappedLike("right", input))
dir[0 ^ idx] = 1;
if(dir != Vector2i::Zero())
{
if (isVertical())
listInput(dir.x() + dir.y() * mGridDimension.x());
else
listInput(dir.x() + dir.y() * mGridDimension.y());
return true;
}
}else{
if(config->isMappedLike("up", input) || config->isMappedLike("down", input) || config->isMappedLike("left", input) || config->isMappedLike("right", input))
{
stopScrolling();
}
}
return GuiComponent::input(config, input);
}
template<typename T>
void ImageGridComponent<T>::update(int deltaTime)
{
GuiComponent::update(deltaTime);
listUpdate(deltaTime);
for(auto it = mTiles.begin(); it != mTiles.end(); it++)
(*it)->update(deltaTime);
}
template<typename T>
void ImageGridComponent<T>::render(const Transform4x4f& parentTrans)
{
Transform4x4f trans = getTransform() * parentTrans;
Transform4x4f tileTrans = trans;
float offsetX = isVertical() ? 0.0f : mCamera * mCameraDirection * (mTileSize.x() + mMargin.x());
float offsetY = isVertical() ? mCamera * mCameraDirection * (mTileSize.y() + mMargin.y()) : 0.0f;
tileTrans.translate(Vector3f(offsetX, offsetY, 0.0));
if(mEntriesDirty)
{
updateTiles();
mEntriesDirty = false;
}
// Create a clipRect to hide tiles used to buffer texture loading
float scaleX = trans.r0().x();
float scaleY = trans.r1().y();
Vector2i pos((int)Math::round(trans.translation()[0]), (int)Math::round(trans.translation()[1]));
Vector2i size((int)Math::round(mSize.x() * scaleX), (int)Math::round(mSize.y() * scaleY));
Renderer::pushClipRect(pos, size);
// Render all the tiles but the selected one
std::shared_ptr<GridTileComponent> selectedTile = NULL;
for(auto it = mTiles.begin(); it != mTiles.end(); it++)
{
std::shared_ptr<GridTileComponent> tile = (*it);
// If it's the selected image, keep it for later, otherwise render it now
if(tile->isSelected())
selectedTile = tile;
else
tile->render(tileTrans);
}
Renderer::popClipRect();
// Render the selected image on top of the others
if (selectedTile != NULL)
selectedTile->render(tileTrans);
listRenderTitleOverlay(trans);
GuiComponent::renderChildren(trans);
}
template<typename T>
void ImageGridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties)
{
// Apply theme to GuiComponent but not size property, which will be applied at the end of this function
GuiComponent::applyTheme(theme, view, element, properties ^ ThemeFlags::SIZE);
// Keep the theme pointer to apply it on the tiles later on
mTheme = theme;
Vector2f screen = Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "imagegrid");
if (elem)
{
if (elem->has("margin"))
mMargin = elem->get<Vector2f>("margin") * screen;
if (elem->has("padding"))
mPadding = elem->get<Vector4f>("padding") * Vector4f(screen.x(), screen.y(), screen.x(), screen.y());
if (elem->has("autoLayout"))
mAutoLayout = elem->get<Vector2f>("autoLayout");
if (elem->has("autoLayoutSelectedZoom"))
mAutoLayoutZoom = elem->get<float>("autoLayoutSelectedZoom");
if (elem->has("imageSource"))
{
auto direction = elem->get<std::string>("imageSource");
if (direction == "image")
mImageSource = IMAGE;
else if (direction == "marquee")
mImageSource = MARQUEE;
else
mImageSource = THUMBNAIL;
}
else
mImageSource = THUMBNAIL;
if (elem->has("scrollDirection"))
mScrollDirection = (ScrollDirection)(elem->get<std::string>("scrollDirection") == "horizontal");
if (elem->has("centerSelection"))
{
mCenterSelection = (elem->get<bool>("centerSelection"));
if (elem->has("scrollLoop"))
mScrollLoop = (elem->get<bool>("scrollLoop"));
}
if (elem->has("animate"))
mAnimate = (elem->get<bool>("animate"));
else
mAnimate = true;
if (elem->has("gameImage"))
{
std::string path = elem->get<std::string>("gameImage");
if (!ResourceManager::getInstance()->fileExists(path))
LOG(LogWarning) << "Could not replace default game image, check path: " << path;
else
{
std::string oldDefaultGameTexture = mDefaultGameTexture;
mDefaultGameTexture = path;
// mEntries are already loaded at this point,
// so we need to update them with new game image texture
for (auto it = mEntries.begin(); it != mEntries.end(); it++)
{
if ((*it).data.texturePath == oldDefaultGameTexture)
(*it).data.texturePath = mDefaultGameTexture;
}
}
}
if (elem->has("folderImage"))
{
std::string path = elem->get<std::string>("folderImage");
if (!ResourceManager::getInstance()->fileExists(path))
LOG(LogWarning) << "Could not replace default folder image, check path: " << path;
else
{
std::string oldDefaultFolderTexture = mDefaultFolderTexture;
mDefaultFolderTexture = path;
// mEntries are already loaded at this point,
// so we need to update them with new folder image texture
for (auto it = mEntries.begin(); it != mEntries.end(); it++)
{
if ((*it).data.texturePath == oldDefaultFolderTexture)
(*it).data.texturePath = mDefaultFolderTexture;
}
}
}
}
// We still need to manually get the grid tile size here,
// so we can recalculate the new grid dimension, and THEN (re)build the tiles
elem = theme->getElement(view, "default", "gridtile");
mTileSize = elem && elem->has("size") ?
elem->get<Vector2f>("size") * screen :
GridTileComponent::getDefaultTileSize();
// Apply size property, will trigger a call to onSizeChanged() which will build the tiles
GuiComponent::applyTheme(theme, view, element, ThemeFlags::SIZE);
// Trigger the call manually if the theme have no "imagegrid" element
if (!elem)
buildTiles();
}
template<typename T>
void ImageGridComponent<T>::onSizeChanged()
{
buildTiles();
updateTiles();
}
template<typename T>
void ImageGridComponent<T>::onCursorChanged(const CursorState& state)
{
if (mLastCursor == mCursor)
{
if (state == CURSOR_STOPPED && mCursorChangedCallback)
mCursorChangedCallback(state);
return;
}
bool direction = mCursor >= mLastCursor;
int diff = direction ? mCursor - mLastCursor : mLastCursor - mCursor;
if (isScrollLoop() && diff == mEntries.size() - 1)
{
direction = !direction;
}
int oldStart = mStartPosition;
int dimScrollable = (isVertical() ? mGridDimension.y() : mGridDimension.x()) - 2 * EXTRAITEMS;
int dimOpposite = isVertical() ? mGridDimension.x() : mGridDimension.y();
int centralCol = (int)(dimScrollable - 0.5) / 2;
int maxCentralCol = dimScrollable / 2;
int oldCol = (mLastCursor / dimOpposite);
int col = (mCursor / dimOpposite);
int lastCol = ((mEntries.size() - 1) / dimOpposite);
int lastScroll = std::max(0, (lastCol + 1 - dimScrollable));
float startPos = 0;
float endPos = 1;
if (((GuiComponent*)this)->isAnimationPlaying(2))
{
startPos = 0;
((GuiComponent*)this)->cancelAnimation(2);
updateTiles(direction, false, false);
}
if (mAnimate) {
std::shared_ptr<GridTileComponent> oldTile = nullptr;
std::shared_ptr<GridTileComponent> newTile = nullptr;
int oldIdx = mLastCursor - mStartPosition + (dimOpposite * EXTRAITEMS);
if (oldIdx >= 0 && oldIdx < mTiles.size())
oldTile = mTiles[oldIdx];
int newIdx = mCursor - mStartPosition + (dimOpposite * EXTRAITEMS);
if (isScrollLoop()) {
if (newIdx < 0)
newIdx += mEntries.size();
else if (newIdx >= mTiles.size())
newIdx -= mEntries.size();
}
if (newIdx >= 0 && newIdx < mTiles.size())
newTile = mTiles[newIdx];
for (auto it = mTiles.begin(); it != mTiles.end(); it++) {
if ((*it)->isSelected() && *it != oldTile && *it != newTile) {
startPos = 0;
(*it)->setSelected(false, false, nullptr);
}
}
Vector3f oldPos = Vector3f::Zero();
if (oldTile != nullptr && oldTile != newTile) {
oldPos = oldTile->getBackgroundPosition();
oldTile->setSelected(false, true, nullptr, true);
}
if (newTile != nullptr)
newTile->setSelected(true, true, oldPos == Vector3f::Zero() ? nullptr : &oldPos, true);
}
int firstVisibleCol = mStartPosition / dimOpposite;
if ((col < centralCol || (col == 0 && col == centralCol)) && !mCenterSelection)
mStartPosition = 0;
else if ((col - centralCol) > lastScroll && !mCenterSelection && !isScrollLoop())
mStartPosition = lastScroll * dimOpposite;
else if ((maxCentralCol != centralCol && col == firstVisibleCol + maxCentralCol) || col == firstVisibleCol + centralCol)
{
if (col == firstVisibleCol + maxCentralCol)
mStartPosition = (col - maxCentralCol) * dimOpposite;
else
mStartPosition = (col - centralCol) * dimOpposite;
}
else
{
if (oldCol == firstVisibleCol + maxCentralCol)
mStartPosition = (col - maxCentralCol) * dimOpposite;
else
mStartPosition = (col - centralCol) * dimOpposite;
}
auto lastCursor = mLastCursor;
mLastCursor = mCursor;
mCameraDirection = direction ? -1.0f : 1.0f;
mCamera = 0;
if (lastCursor < 0 || !mAnimate)
{
updateTiles(direction, mAnimate && (lastCursor >= 0 || isScrollLoop()));
if (mCursorChangedCallback)
mCursorChangedCallback(state);
return;
}
if (mCursorChangedCallback)
mCursorChangedCallback(state);
bool moveCamera = (oldStart != mStartPosition);
auto func = [this, startPos, endPos, moveCamera](float t)
{
if (!moveCamera)
return;
t -= 1; // cubic ease out
float pct = Math::lerp(0, 1, t*t*t + 1);
t = startPos * (1.0f - pct) + endPos * pct;
mCamera = t;
};
((GuiComponent*)this)->setAnimation(new LambdaAnimation(func, 250), 0, [this, direction] {
mCamera = 0;
updateTiles(direction, false);
}, false, 2);
}
// Create and position tiles (mTiles)
template<typename T>
void ImageGridComponent<T>::buildTiles()
{
mStartPosition = 0;
mTiles.clear();
calcGridDimension();
if (mCenterSelection)
{
int dimScrollable = (isVertical() ? mGridDimension.y() : mGridDimension.x()) - 2 * EXTRAITEMS;
mStartPosition -= (int) Math::floorf(dimScrollable / 2.0f);
}
Vector2f tileDistance = mTileSize + mMargin;
if (mAutoLayout.x() != 0 && mAutoLayout.y() != 0)
{
auto x = (mSize.x() - (mMargin.x() * (mAutoLayout.x() - 1)) - mPadding.x() - mPadding.z()) / (int) mAutoLayout.x();
auto y = (mSize.y() - (mMargin.y() * (mAutoLayout.y() - 1)) - mPadding.y() - mPadding.w()) / (int) mAutoLayout.y();
mTileSize = Vector2f(x, y);
tileDistance = mTileSize + mMargin;
}
bool vert = isVertical();
Vector2f startPosition = mTileSize / 2;
startPosition += mPadding.v2();
int X, Y;
// Layout tile size and position
for (int y = 0; y < (vert ? mGridDimension.y() : mGridDimension.x()); y++)
{
for (int x = 0; x < (vert ? mGridDimension.x() : mGridDimension.y()); x++)
{
// Create tiles
auto tile = std::make_shared<GridTileComponent>(mWindow);
// In Vertical mod, tiles are ordered from left to right, then from top to bottom
// In Horizontal mod, tiles are ordered from top to bottom, then from left to right
X = vert ? x : y - EXTRAITEMS;
Y = vert ? y - EXTRAITEMS : x;
tile->setPosition(X * tileDistance.x() + startPosition.x(), Y * tileDistance.y() + startPosition.y());
tile->setOrigin(0.5f, 0.5f);
tile->setImage("");
if (mTheme)
tile->applyTheme(mTheme, "grid", "gridtile", ThemeFlags::ALL);
if (mAutoLayout.x() != 0 && mAutoLayout.y() != 0)
tile->forceSize(mTileSize, mAutoLayoutZoom);
mTiles.push_back(tile);
}
}
}
template<typename T>
void ImageGridComponent<T>::updateTiles(bool ascending, bool allowAnimation, bool updateSelectedState)
{
if (!mTiles.size())
return;
if (mScrollTier == 3)
{
// Stop updating the tiles at highest scroll speed
if (mLastScrollTier != 3)
{
for (int ti = 0; ti < (int) mTiles.size(); ti++)
{
std::shared_ptr<GridTileComponent> tile = mTiles.at(ti);
tile->setSelected(false);
tile->setImage(mDefaultGameTexture);
tile->setVisible(false);
}
}
mLastScrollTier = mScrollTier;
return;
}
mLastScrollTier = mScrollTier;
// Temporary store previous texture so they can't be unloaded
std::vector<std::shared_ptr<TextureResource>> previousTextures;
for (int ti = 0; ti < (int)mTiles.size(); ti++)
{
std::shared_ptr<GridTileComponent> tile = mTiles.at(ti);
previousTextures.push_back(tile->getTexture());
}
// If going down, update from top to bottom
// If going up, update from bottom to top
int scrollDirection = ascending ? 1 : -1;
int ti = ascending ? 0 : (int)mTiles.size() - 1;
int end = ascending ? (int)mTiles.size() : -1;
int img = mStartPosition + ti;
img -= EXTRAITEMS * (isVertical() ? mGridDimension.x() : mGridDimension.y());
// Update the tiles
while (ti != end)
{
updateTileAtPos(ti, img, allowAnimation, updateSelectedState);
ti += scrollDirection;
img += scrollDirection;
}
if (updateSelectedState)
mLastCursor = mCursor;
mLastCursor = mCursor;
}
template<typename T>
void ImageGridComponent<T>::updateTileAtPos(int tilePos, int imgPos, bool allowAnimation, bool updateSelectedState)
{
std::shared_ptr<GridTileComponent> tile = mTiles.at(tilePos);
if(isScrollLoop())
{
if (imgPos < 0)
imgPos += mEntries.size();
else if (imgPos >= size())
imgPos -= mEntries.size();
}
// If we have more tiles than we have to display images on screen, hide them
if(imgPos < 0 || imgPos >= size() || tilePos < 0 || tilePos >= (int) mTiles.size()) // Same for tiles out of the buffer
{
if (updateSelectedState)
tile->setSelected(false, allowAnimation);
tile->reset();
tile->setVisible(false);
}
else
{
tile->setVisible(true);
std::string imagePath = mEntries.at(imgPos).data.texturePath;
if (ResourceManager::getInstance()->fileExists(imagePath))
tile->setImage(imagePath);
else if (mEntries.at(imgPos).object->getType() == 2)
tile->setImage(mDefaultFolderTexture);
else
tile->setImage(mDefaultGameTexture);
if (updateSelectedState)
{
if (imgPos == mCursor && mCursor != mLastCursor)
{
int dif = mCursor - tilePos;
int idx = mLastCursor - dif;
if (idx < 0 || idx >= mTiles.size())
idx = 0;
Vector3f pos = mTiles.at(idx)->getBackgroundPosition();
tile->setSelected(true, allowAnimation, &pos);
}
else
tile->setSelected(imgPos == mCursor, allowAnimation);
}
}
}
// Calculate how much tiles of size mTileSize we can fit in a grid of size mSize using a margin of size mMargin
template<typename T>
void ImageGridComponent<T>::calcGridDimension()
{
// GRID_SIZE = COLUMNS * TILE_SIZE + (COLUMNS - 1) * MARGIN
// <=> COLUMNS = (GRID_SIZE + MARGIN) / (TILE_SIZE + MARGIN)
Vector2f gridDimension = (mSize + mMargin) / (mTileSize + mMargin);
if (mAutoLayout.x() != 0 && mAutoLayout.y() != 0)
gridDimension = mAutoLayout;
mLastRowPartial = Math::floorf(gridDimension.y()) != gridDimension.y();
// Ceil y dim so we can display partial last row
mGridDimension = Vector2i(gridDimension.x(), Math::ceilf(gridDimension.y()));
// Grid dimension validation
if (mGridDimension.x() < 1)
LOG(LogError) << "Theme defined grid X dimension below 1";
if (mGridDimension.y() < 1)
LOG(LogError) << "Theme defined grid Y dimension below 1";
// Add extra tiles to both sides : Add EXTRAITEMS before, EXTRAITEMS after
if (isVertical())
mGridDimension.y() += 2 * EXTRAITEMS;
else
mGridDimension.x() += 2 * EXTRAITEMS;
}
template<typename T>
bool ImageGridComponent<T>::isScrollLoop() {
if (!mScrollLoop)
return false;
if (isVertical())
return (mGridDimension.x() * (mGridDimension.y() - 2 * EXTRAITEMS)) <= mEntries.size();
return (mGridDimension.y() * (mGridDimension.x() - 2 * EXTRAITEMS)) <= mEntries.size();
};
#endif // ES_CORE_COMPONENTS_IMAGE_GRID_COMPONENT_H