mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-30 01:33:45 +01:00
Add a simple screen manager (kind of like activity stack)
This commit is contained in:
1 parent
5819c79463
commit
c762d1c0a5
6 files changed
+157
-5
No files matched your search
+5
-5
@@ -234,13 +234,11 @@ int main(int argc, char *argv[]) {
|
||||
bool nextFrameMD = 0;
|
||||
float t = 0;
|
||||
while (true) {
|
||||
SDL_Event event;
|
||||
|
||||
input_state.accelerometer_valid = false;
|
||||
input_state.mouse_valid = true;
|
||||
int quitRequested = 0;
|
||||
|
||||
// input_state.mouse_down[1] = nextFrameMD;
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
float mx = event.motion.x * dp_xscale;
|
||||
float my = event.motion.y * dp_yscale;
|
||||
@@ -289,7 +287,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
|
||||
// Simple framerate limiting
|
||||
// Simple frame rate limiting
|
||||
while (time_now() < t + 1.0f/60.0f) {
|
||||
sleep_ms(0);
|
||||
time_update();
|
||||
@@ -299,7 +297,8 @@ int main(int argc, char *argv[]) {
|
||||
framecount++;
|
||||
}
|
||||
// Faster exit, thanks to the OS. Remove this if you want to debug shutdown
|
||||
exit(0);
|
||||
// The speed difference is only really noticable on Linux. On Windows you do notice it though
|
||||
// exit(0);
|
||||
|
||||
NativeShutdownGraphics();
|
||||
SDL_PauseAudio(1);
|
||||
@@ -307,5 +306,6 @@ int main(int argc, char *argv[]) {
|
||||
SDL_CloseAudio();
|
||||
SDL_Quit();
|
||||
net::Shutdown();
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
@@ -148,6 +148,7 @@
|
||||
<ClInclude Include="net\http_client.h" />
|
||||
<ClInclude Include="net\resolve.h" />
|
||||
<ClInclude Include="profiler\profiler.h" />
|
||||
<ClInclude Include="ui\screen.h" />
|
||||
<ClInclude Include="ui\ui.h" />
|
||||
<ClInclude Include="util\bits\bits.h" />
|
||||
</ItemGroup>
|
||||
@@ -211,6 +212,7 @@
|
||||
<ClCompile Include="net\http_client.cpp" />
|
||||
<ClCompile Include="net\resolve.cpp" />
|
||||
<ClCompile Include="profiler\profiler.cpp" />
|
||||
<ClCompile Include="ui\screen.cpp" />
|
||||
<ClCompile Include="ui\ui.cpp" />
|
||||
<ClCompile Include="util\bits\bits.cpp" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -181,6 +181,9 @@
|
||||
<ClInclude Include="android\native-audio-so.h">
|
||||
<Filter>android</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ui\screen.h">
|
||||
<Filter>ui</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="gfx\gl_debug_log.cpp">
|
||||
@@ -330,6 +333,9 @@
|
||||
<ClCompile Include="android\native-audio-so.cpp">
|
||||
<Filter>android</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui\screen.cpp">
|
||||
<Filter>ui</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="gfx">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
set(SRCS
|
||||
ui.cpp
|
||||
screen.cpp
|
||||
)
|
||||
|
||||
set(SRCS ${SRCS})
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
#include "base/logging.h"
|
||||
#include "input/input_state.h"
|
||||
#include "ui/screen.h"
|
||||
|
||||
ScreenManager screenManager;
|
||||
|
||||
Screen::Screen() { }
|
||||
Screen::~Screen() { }
|
||||
|
||||
ScreenManager::ScreenManager() {
|
||||
currentScreen_=0;
|
||||
nextScreen_=0;
|
||||
}
|
||||
|
||||
ScreenManager::~ScreenManager() {
|
||||
delete currentScreen_;
|
||||
}
|
||||
|
||||
void ScreenManager::switchScreen(Screen *screen) {
|
||||
// Note that if a dialog is found, this will be a silent background switch that
|
||||
// will only become apparent if the dialog is closed. The previous screen will stick around
|
||||
// until that switch.
|
||||
if (nextScreen_ != 0) {
|
||||
FLOG("WTF? Already had nextScreen_");
|
||||
}
|
||||
nextScreen_ = screen;
|
||||
}
|
||||
|
||||
void ScreenManager::update(const InputState &input) {
|
||||
if (dialog_.size()) {
|
||||
dialog_.back()->update(input);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextScreen_) {
|
||||
Screen *temp = currentScreen_;
|
||||
currentScreen_ = nextScreen_;
|
||||
delete temp;
|
||||
temp = 0;
|
||||
nextScreen_ = 0;
|
||||
}
|
||||
if (currentScreen_) {
|
||||
currentScreen_->update(input);
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenManager::render() {
|
||||
if (dialog_.size()) {
|
||||
dialog_.back()->render();
|
||||
}
|
||||
if (currentScreen_) {
|
||||
currentScreen_->render();
|
||||
}
|
||||
else {
|
||||
ELOG("No current screen!");
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenManager::shutdown() {
|
||||
if (nextScreen_) {
|
||||
delete nextScreen_;
|
||||
nextScreen_ = 0;
|
||||
}
|
||||
if (currentScreen_) {
|
||||
delete currentScreen_;
|
||||
currentScreen_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenManager::push(Screen *screen) {
|
||||
dialog_.push_back(screen);
|
||||
}
|
||||
|
||||
void ScreenManager::pop() {
|
||||
if (dialog_.size()) {
|
||||
delete dialog_.back();
|
||||
dialog_.pop_back();
|
||||
} else {
|
||||
ELOG("Can't push when no dialog is shown");
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// Super basic screen manager. Let's you, well, switch between screens. Can also be used
|
||||
// to pop one screen in front for a bit while keeping another one running, it's basically
|
||||
// a native "activity stack". Well actually that part is still a TODO.
|
||||
//
|
||||
// Semantics
|
||||
//
|
||||
// switchScreen: When you call this, on a newed screen, the ScreenManager takes ownership.
|
||||
// On the next update, it switches to the new screen and deletes the previous screen.
|
||||
//
|
||||
// TODO: A way to do smooth transitions between screens. Will probably involve screenshotting
|
||||
// the previous screen and then animating it on top of the current screen with transparency
|
||||
// and/or other similar effects.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include "base/display.h"
|
||||
|
||||
struct InputState;
|
||||
|
||||
class Screen {
|
||||
public:
|
||||
Screen();
|
||||
virtual ~Screen();
|
||||
virtual void update(const InputState &input) = 0;
|
||||
virtual void render() {}
|
||||
virtual void dialogFinished(const Screen &dialog) {}
|
||||
};
|
||||
|
||||
class Transition {
|
||||
public:
|
||||
Transition() {}
|
||||
};
|
||||
|
||||
class ScreenManager {
|
||||
public:
|
||||
ScreenManager();
|
||||
virtual ~ScreenManager();
|
||||
|
||||
void switchScreen(Screen *screen);
|
||||
void update(const InputState &input);
|
||||
void render();
|
||||
void shutdown();
|
||||
|
||||
// Push a dialog box in front. Currently 1-level only.
|
||||
void push(Screen *screen);
|
||||
|
||||
// Pops the dialog away.
|
||||
void pop();
|
||||
|
||||
private:
|
||||
// Base screen. These don't "stack" and you can move in any order between them.
|
||||
Screen *currentScreen_;
|
||||
Screen *nextScreen_;
|
||||
|
||||
// Dialog stack. These are shown "on top" of base screens and back works as expected.
|
||||
// Used for options, in-game menus and other things you expect to be able to back out from onto something.
|
||||
std::list<Screen *> dialog_;
|
||||
};
|
||||
|
||||
// Yeah, an old school non enforced singleton. Good enough.
|
||||
extern ScreenManager screenManager;
|
||||
Reference in new issue
Block a user