-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomLayoutManager.cpp
45 lines (31 loc) · 1.34 KB
/
RandomLayoutManager.cpp
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
///////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: RandomLayoutManager.cpp
//
// Author: David Borland
//
// Description: Lays out images randomly
//
///////////////////////////////////////////////////////////////////////////////////////////////
#include "RandomLayoutManager.h"
#include "CollageGraphics.h"
RandomLayoutManager::RandomLayoutManager(CollageGraphics* collageGraphics)
: CollageLayoutManager(collageGraphics) {
}
RandomLayoutManager::~RandomLayoutManager() {
}
void RandomLayoutManager::Layout(unsigned int start) {
std::cout << "RandomLayoutManager::Layout() : doing layout" << std::endl;
std::vector<CollageImage*> images = collageGraphics->GetImages();
float w = collageGraphics->GetViewWidth();
float h = collageGraphics->GetViewHeight();
float scale = w * h / (float)images.size();
for (int i = 0; i < (int)images.size(); i++) {
images[i]->SetScale(scale);
}
for (int i = start; i < (int)images.size(); i++) {
float x = (float)rand() / (float)RAND_MAX * (w - images[i]->GetWidth()) + images[i]->GetWidth() * 0.5;
float y = (float)rand() / (float)RAND_MAX * (h - images[i]->GetHeight()) + images[i]->GetHeight() * 0.5;
images[i]->SetPosition(Vec2(x, y));
}
}