2019-09-02 12:15:51 +00:00
|
|
|
// Copyright 2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief SDL2 functions to drive the GUI.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup gui
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "gui_common.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
struct gui_scene_manager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<gui_scene *> scenes = {};
|
|
|
|
std::vector<gui_scene *> del = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" void
|
2019-10-09 15:22:34 +00:00
|
|
|
gui_scene_push_front(struct gui_program *p, struct gui_scene *me)
|
2019-09-02 12:15:51 +00:00
|
|
|
{
|
|
|
|
auto &gsm = *p->gsm;
|
|
|
|
|
|
|
|
// Need to remove the scene if it is already on the list.
|
|
|
|
auto index = gsm.scenes.begin();
|
|
|
|
for (auto scene : gsm.scenes) {
|
|
|
|
if (scene != me) {
|
|
|
|
index++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsm.scenes.erase(index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now push it to the front.
|
|
|
|
gsm.scenes.push_back(me);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
2019-10-09 15:22:34 +00:00
|
|
|
gui_scene_delete_me(struct gui_program *p, struct gui_scene *me)
|
2019-09-02 12:15:51 +00:00
|
|
|
{
|
|
|
|
auto &gsm = *p->gsm;
|
|
|
|
|
|
|
|
auto index = gsm.scenes.begin();
|
|
|
|
for (auto scene : gsm.scenes) {
|
|
|
|
if (scene != me) {
|
|
|
|
index++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsm.scenes.erase(index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsm.del.push_back(me);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
2019-10-09 15:22:34 +00:00
|
|
|
gui_scene_manager_render(struct gui_program *p)
|
2019-09-02 12:15:51 +00:00
|
|
|
{
|
|
|
|
auto &gsm = *p->gsm;
|
|
|
|
auto copy = gsm.scenes;
|
|
|
|
|
|
|
|
for (auto scene : copy) {
|
|
|
|
scene->render(scene, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
copy = gsm.del;
|
|
|
|
gsm.del.clear();
|
|
|
|
for (auto scene : copy) {
|
2019-09-21 17:20:11 +00:00
|
|
|
scene->destroy(scene, p);
|
2019-09-02 12:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no scenes left stop the program.
|
2019-12-03 16:28:29 +00:00
|
|
|
if (gsm.scenes.empty()) {
|
2019-09-02 12:15:51 +00:00
|
|
|
p->stopped = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
2019-10-09 15:22:34 +00:00
|
|
|
gui_scene_manager_init(struct gui_program *p)
|
2019-09-02 12:15:51 +00:00
|
|
|
{
|
|
|
|
p->gsm = new gui_scene_manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
2019-10-09 15:22:34 +00:00
|
|
|
gui_scene_manager_destroy(struct gui_program *p)
|
2019-09-02 12:15:51 +00:00
|
|
|
{
|
2019-11-13 20:53:16 +00:00
|
|
|
for (auto scene : p->gsm->scenes) {
|
|
|
|
scene->destroy(scene, p);
|
|
|
|
}
|
|
|
|
|
2019-09-02 12:15:51 +00:00
|
|
|
delete p->gsm;
|
|
|
|
p->gsm = NULL;
|
|
|
|
}
|