Skip to content

Commit

Permalink
made CopyWindow more flexible in terms of when it copies the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMaverickProgrammer committed Jun 11, 2020
1 parent 3d74cd6 commit 4bd51e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -28,6 +28,10 @@ extern/*
# Codelite
*.codelite

# VS Code
*.vscode/
*.vscode/*

# Build results
[Dd]ebug/
[Dd]ebugPublic/
Expand Down
27 changes: 21 additions & 6 deletions src/Swoosh/ActivityController.h
Expand Up @@ -531,27 +531,42 @@ namespace swoosh {
Example use case: a segue fading in an intro screen when there were no previous scenes at launch
This is best suited for all actions: push, pop, and replace.
@warning This is a costly operation in SFML and can cause your program to stall for a split second
depending on your computer. You should also be sure you don't clear your window content
until AFTER the AC's update loop
*/
class CopyWindow : public Activity {
sf::Texture framebuffer;
sf::Sprite drawable;
public:
CopyWindow(ActivityController& ac) : Activity(&ac) {
auto& window = ac.getWindow();
bool captured;

void copyWindowContents() {
if(captured) return;

auto& window = getController().getWindow();
sf::Vector2u windowSize = window.getSize();
framebuffer.create(windowSize.x, windowSize.y);
framebuffer.update(window);
drawable.setTexture(framebuffer, true);

captured = true;
}

public:
CopyWindow(ActivityController& ac) : Activity(&ac) {
captured = false;
}

virtual ~CopyWindow() { ; }

void onStart() override { };
void onLeave() override { };
void onStart() override { copyWindowContents(); };
void onLeave() override { copyWindowContents(); };
void onExit() override { };
void onEnter() override { };
void onEnter() override { copyWindowContents(); };
void onResume() override { };
void onEnd() override { };

void onUpdate(double elapsed) override { };

void onDraw(sf::RenderTexture& surface) override {
Expand Down
2 changes: 1 addition & 1 deletion src/Swoosh/Segue.h
Expand Up @@ -46,7 +46,7 @@ namespace swoosh {
void onUpdate (double elapsed) override final {
timer.update(elapsed);

if (last) last->onUpdate(elapsed);
last->onUpdate(elapsed);
next->onUpdate(elapsed);
}

Expand Down

0 comments on commit 4bd51e1

Please sign in to comment.