mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 10:04:05 +02:00
Use shared_ptr for layers
This allows transient layers to be deleted automatically when they are dismissed, while persistent layers will be kept alive by their other owner(s).
This commit is contained in:
parent
6d868a895a
commit
63029d85d7
@ -231,8 +231,6 @@ GMenu2X::GMenu2X()
|
|||||||
|
|
||||||
bg = NULL;
|
bg = NULL;
|
||||||
font = NULL;
|
font = NULL;
|
||||||
menu = NULL;
|
|
||||||
helpPopup = nullptr;
|
|
||||||
btnContextMenu = nullptr;
|
btnContextMenu = nullptr;
|
||||||
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
|
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
|
||||||
initMenu();
|
initMenu();
|
||||||
@ -256,7 +254,7 @@ GMenu2X::GMenu2X()
|
|||||||
DEBUG("Loading system input.conf file: %s.\n", input_file.c_str());
|
DEBUG("Loading system input.conf file: %s.\n", input_file.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
input.init(input_file, menu);
|
input.init(input_file, menu.get());
|
||||||
|
|
||||||
if (confInt["backlightTimeout"] > 0)
|
if (confInt["backlightTimeout"] > 0)
|
||||||
PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] );
|
PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] );
|
||||||
@ -279,8 +277,6 @@ GMenu2X::~GMenu2X() {
|
|||||||
delete Clock::getInstance();
|
delete Clock::getInstance();
|
||||||
quit();
|
quit();
|
||||||
|
|
||||||
delete menu;
|
|
||||||
delete helpPopup;
|
|
||||||
delete btnContextMenu;
|
delete btnContextMenu;
|
||||||
delete font;
|
delete font;
|
||||||
delete monitor;
|
delete monitor;
|
||||||
@ -372,7 +368,7 @@ void GMenu2X::initFont() {
|
|||||||
|
|
||||||
void GMenu2X::initMenu() {
|
void GMenu2X::initMenu() {
|
||||||
//Menu structure handler
|
//Menu structure handler
|
||||||
menu = new Menu(this, ts);
|
menu.reset(new Menu(this, ts));
|
||||||
for (uint i=0; i<menu->getSections().size(); i++) {
|
for (uint i=0; i<menu->getSections().size(); i++) {
|
||||||
//Add virtual links in the applications section
|
//Add virtual links in the applications section
|
||||||
if (menu->getSections()[i]=="applications") {
|
if (menu->getSections()[i]=="applications") {
|
||||||
@ -608,7 +604,7 @@ void GMenu2X::paint() {
|
|||||||
//Background
|
//Background
|
||||||
sc["bgmain"]->blit(s,0,0);
|
sc["bgmain"]->blit(s,0,0);
|
||||||
|
|
||||||
for (Layer *layer : layers) {
|
for (auto layer : layers) {
|
||||||
layer->paint(*s);
|
layer->paint(*s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,8 +675,7 @@ void GMenu2X::main() {
|
|||||||
if (!handled) {
|
if (!handled) {
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case InputManager::CANCEL:
|
case InputManager::CANCEL:
|
||||||
helpPopup = new HelpPopup(*this);
|
layers.push_back(make_shared<HelpPopup>(*this));
|
||||||
layers.push_back(helpPopup);
|
|
||||||
break;
|
break;
|
||||||
case InputManager::SETTINGS:
|
case InputManager::SETTINGS:
|
||||||
options();
|
options();
|
||||||
@ -694,13 +689,9 @@ void GMenu2X::main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto it = layers.begin(); it != layers.end(); ) {
|
for (auto it = layers.begin(); it != layers.end(); ) {
|
||||||
Layer *layer = *it;
|
auto layer = *it;
|
||||||
if (layer->wasDismissed()) {
|
if (layer->wasDismissed()) {
|
||||||
it = layers.erase(it);
|
it = layers.erase(it);
|
||||||
if (layer == helpPopup) {
|
|
||||||
delete helpPopup;
|
|
||||||
helpPopup = nullptr;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -67,12 +68,11 @@ typedef std::unordered_map<std::string, int, std::hash<std::string> > ConfIntHas
|
|||||||
class GMenu2X {
|
class GMenu2X {
|
||||||
private:
|
private:
|
||||||
Touchscreen ts;
|
Touchscreen ts;
|
||||||
Menu *menu;
|
std::shared_ptr<Menu> menu;
|
||||||
HelpPopup *helpPopup;
|
|
||||||
MediaMonitor *monitor;
|
MediaMonitor *monitor;
|
||||||
std::string batteryIcon;
|
std::string batteryIcon;
|
||||||
|
|
||||||
std::vector<Layer *> layers;
|
std::vector<std::shared_ptr<Layer>> layers;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Retrieves the free disk space on the sd
|
Retrieves the free disk space on the sd
|
||||||
|
Loading…
Reference in New Issue
Block a user