From 4bd51e1ce9e4d316a96b146ae5464d9936693ff9 Mon Sep 17 00:00:00 2001 From: TheMaverickProgrammer Date: Wed, 10 Jun 2020 21:04:01 -0500 Subject: [PATCH] made CopyWindow more flexible in terms of when it copies the screen --- .gitignore | 4 ++++ src/Swoosh/ActivityController.h | 27 +++++++++++++++++++++------ src/Swoosh/Segue.h | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index dabbf08..609258f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,10 @@ extern/* # Codelite *.codelite +# VS Code +*.vscode/ +*.vscode/* + # Build results [Dd]ebug/ [Dd]ebugPublic/ diff --git a/src/Swoosh/ActivityController.h b/src/Swoosh/ActivityController.h index cb27753..114c15d 100644 --- a/src/Swoosh/ActivityController.h +++ b/src/Swoosh/ActivityController.h @@ -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 { diff --git a/src/Swoosh/Segue.h b/src/Swoosh/Segue.h index 4573978..3fe8c1f 100644 --- a/src/Swoosh/Segue.h +++ b/src/Swoosh/Segue.h @@ -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); }