-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
PushIn.h
78 lines (57 loc) · 2.06 KB
/
PushIn.h
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
#pragma once
#include <Swoosh/Segue.h>
#include <Swoosh/Ease.h>
using namespace swoosh;
/**
@class PushIn
@brief Pushes the new screen in while pushing the last screen out
@param direction. Compile-time constant. A cardinal direction to push from.
*/
template<types::direction direction>
class PushIn : public Segue {
sf::Texture next, last;
bool firstPass{ true };
public:
void onDraw(sf::RenderTexture& surface) override {
double elapsed = getElapsed().asMilliseconds();
double duration = getDuration().asMilliseconds();
double alpha = ease::linear(elapsed, duration, 1.0);
bool optimized = getController().getRequestedQuality() == quality::mobile;
sf::Texture temp, temp2;
if (firstPass || !optimized) {
surface.clear(this->getLastActivityBGColor());
this->drawLastActivity(surface);
surface.display(); // flip and ready the buffer
last = temp = sf::Texture(surface.getTexture()); // Make a copy of the source texture
}
else {
temp = last;
}
sf::Sprite left(temp);
int lr = 0;
int ud = 0;
if (direction == types::direction::left ) lr = -1;
if (direction == types::direction::right) lr = 1;
if (direction == types::direction::up ) ud = -1;
if (direction == types::direction::down ) ud = 1;
left.setPosition((float)(lr * alpha * left.getTexture()->getSize().x), (float)(ud * alpha * left.getTexture()->getSize().y));
surface.clear(this->getNextActivityBGColor());
if (firstPass || !optimized) {
this->drawNextActivity(surface);
surface.display(); // flip and ready the buffer
next = temp2 = sf::Texture(surface.getTexture());
}
else {
temp2 = next;
}
sf::Sprite right(temp2);
right.setPosition((float)(-lr * (1.0-alpha) * right.getTexture()->getSize().x), (float)(-ud * (1.0-alpha) * right.getTexture()->getSize().y));
surface.draw(left);
surface.draw(right);
firstPass = false;
}
PushIn(sf::Time duration, Activity* last, Activity* next) : Segue(duration, last, next) {
/* ... */
}
~PushIn() { }
};