mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 01:50:16 +02:00
Removed most uses of naked Surface pointers
However, SurfaceCollection remains a very important user.
This commit is contained in:
parent
4bd1c799bd
commit
60183e539d
@ -230,7 +230,7 @@ void BrowseDialog::paint()
|
|||||||
unsigned int firstElement, lastElement;
|
unsigned int firstElement, lastElement;
|
||||||
unsigned int offsetY;
|
unsigned int offsetY;
|
||||||
|
|
||||||
OffscreenSurface bg(gmenu2x->bg);
|
OffscreenSurface bg(*gmenu2x->bg);
|
||||||
drawTitleIcon(bg, "icons/explorer.png", true);
|
drawTitleIcon(bg, "icons/explorer.png", true);
|
||||||
writeTitle(bg, title);
|
writeTitle(bg, title);
|
||||||
writeSubTitle(bg, subtitle);
|
writeSubTitle(bg, subtitle);
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
class OffscreenSurface;
|
||||||
class Touchscreen;
|
class Touchscreen;
|
||||||
|
|
||||||
class BrowseDialog : protected Dialog {
|
class BrowseDialog : protected Dialog {
|
||||||
@ -72,9 +73,9 @@ private:
|
|||||||
|
|
||||||
bool ts_pressed;
|
bool ts_pressed;
|
||||||
|
|
||||||
Surface *iconGoUp;
|
OffscreenSurface *iconGoUp;
|
||||||
Surface *iconFolder;
|
OffscreenSurface *iconFolder;
|
||||||
Surface *iconFile;
|
OffscreenSurface *iconFile;
|
||||||
|
|
||||||
ButtonBox buttonBox;
|
ButtonBox buttonBox;
|
||||||
|
|
||||||
|
@ -313,9 +313,9 @@ GMenu2X::~GMenu2X() {
|
|||||||
|
|
||||||
void GMenu2X::initBG() {
|
void GMenu2X::initBG() {
|
||||||
sc.del("bgmain");
|
sc.del("bgmain");
|
||||||
|
bg.reset();
|
||||||
|
|
||||||
// Load wallpaper.
|
// Load wallpaper.
|
||||||
delete bg;
|
|
||||||
bg = OffscreenSurface::loadImage(confStr["wallpaper"]);
|
bg = OffscreenSurface::loadImage(confStr["wallpaper"]);
|
||||||
if (!bg) {
|
if (!bg) {
|
||||||
bg = OffscreenSurface::emptySurface(resX, resY);
|
bg = OffscreenSurface::emptySurface(resX, resY);
|
||||||
@ -326,20 +326,22 @@ void GMenu2X::initBG() {
|
|||||||
|
|
||||||
OffscreenSurface *bgmain = sc.add(*bg, "bgmain");
|
OffscreenSurface *bgmain = sc.add(*bg, "bgmain");
|
||||||
|
|
||||||
Surface *sd = OffscreenSurface::loadImage("imgs/sd.png", confStr["skin"]);
|
{
|
||||||
|
auto sd = OffscreenSurface::loadImage("imgs/sd.png", confStr["skin"]);
|
||||||
if (sd) sd->blit(*bgmain, 3, bottomBarIconY);
|
if (sd) sd->blit(*bgmain, 3, bottomBarIconY);
|
||||||
|
}
|
||||||
|
|
||||||
string df = getDiskFree(getHome().c_str());
|
string df = getDiskFree(getHome().c_str());
|
||||||
font->write(*bgmain, df, 22, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle);
|
font->write(*bgmain, df, 22, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle);
|
||||||
delete sd;
|
|
||||||
|
|
||||||
cpuX = font->getTextWidth(df)+32;
|
cpuX = font->getTextWidth(df) + 32;
|
||||||
#ifdef ENABLE_CPUFREQ
|
#ifdef ENABLE_CPUFREQ
|
||||||
Surface *cpu = OffscreenSurface::loadImage("imgs/cpu.png", confStr["skin"]);
|
{
|
||||||
|
auto cpu = OffscreenSurface::loadImage("imgs/cpu.png", confStr["skin"]);
|
||||||
if (cpu) cpu->blit(bgmain, cpuX, bottomBarIconY);
|
if (cpu) cpu->blit(bgmain, cpuX, bottomBarIconY);
|
||||||
|
}
|
||||||
cpuX += 19;
|
cpuX += 19;
|
||||||
manualX = cpuX+font->getTextWidth("300MHz")+5;
|
manualX = cpuX + font->getTextWidth("300MHz") + 5;
|
||||||
delete cpu;
|
|
||||||
#else
|
#else
|
||||||
manualX = cpuX;
|
manualX = cpuX;
|
||||||
#endif
|
#endif
|
||||||
@ -347,24 +349,22 @@ void GMenu2X::initBG() {
|
|||||||
int serviceX = resX-38;
|
int serviceX = resX-38;
|
||||||
if (usbnet) {
|
if (usbnet) {
|
||||||
if (web) {
|
if (web) {
|
||||||
Surface *webserver = OffscreenSurface::loadImage(
|
auto webserver = OffscreenSurface::loadImage(
|
||||||
"imgs/webserver.png", confStr["skin"]);
|
"imgs/webserver.png", confStr["skin"]);
|
||||||
if (webserver) webserver->blit(*bgmain, serviceX, bottomBarIconY);
|
if (webserver) webserver->blit(*bgmain, serviceX, bottomBarIconY);
|
||||||
serviceX -= 19;
|
serviceX -= 19;
|
||||||
delete webserver;
|
|
||||||
}
|
}
|
||||||
if (samba) {
|
if (samba) {
|
||||||
Surface *sambaS = OffscreenSurface::loadImage(
|
auto sambaS = OffscreenSurface::loadImage(
|
||||||
"imgs/samba.png", confStr["skin"]);
|
"imgs/samba.png", confStr["skin"]);
|
||||||
if (sambaS) sambaS->blit(*bgmain, serviceX, bottomBarIconY);
|
if (sambaS) sambaS->blit(*bgmain, serviceX, bottomBarIconY);
|
||||||
serviceX -= 19;
|
serviceX -= 19;
|
||||||
delete sambaS;
|
|
||||||
}
|
}
|
||||||
if (inet) {
|
if (inet) {
|
||||||
Surface *inetS = OffscreenSurface::loadImage("imgs/inet.png", confStr["skin"]);
|
auto inetS = OffscreenSurface::loadImage(
|
||||||
|
"imgs/inet.png", confStr["skin"]);
|
||||||
if (inetS) inetS->blit(*bgmain, serviceX, bottomBarIconY);
|
if (inetS) inetS->blit(*bgmain, serviceX, bottomBarIconY);
|
||||||
serviceX -= 19;
|
serviceX -= 19;
|
||||||
delete inetS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,6 @@ class Launcher;
|
|||||||
class Layer;
|
class Layer;
|
||||||
class MediaMonitor;
|
class MediaMonitor;
|
||||||
class Menu;
|
class Menu;
|
||||||
class OutputSurface;
|
|
||||||
class Surface;
|
|
||||||
|
|
||||||
#ifndef GMENU2X_SYSTEM_DIR
|
#ifndef GMENU2X_SYSTEM_DIR
|
||||||
#define GMENU2X_SYSTEM_DIR "/usr/share/gmenu2x"
|
#define GMENU2X_SYSTEM_DIR "/usr/share/gmenu2x"
|
||||||
@ -160,7 +158,7 @@ public:
|
|||||||
SurfaceCollection sc;
|
SurfaceCollection sc;
|
||||||
Translator tr;
|
Translator tr;
|
||||||
std::unique_ptr<OutputSurface> s;
|
std::unique_ptr<OutputSurface> s;
|
||||||
Surface *bg;
|
std::unique_ptr<OffscreenSurface> bg;
|
||||||
std::unique_ptr<Font> font;
|
std::unique_ptr<Font> font;
|
||||||
|
|
||||||
//Status functions
|
//Status functions
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
class OffscreenSurface;
|
||||||
class Surface;
|
class Surface;
|
||||||
class Touchscreen;
|
class Touchscreen;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ private:
|
|||||||
function_t action;
|
function_t action;
|
||||||
|
|
||||||
SDL_Rect rect, iconRect, labelRect;
|
SDL_Rect rect, iconRect, labelRect;
|
||||||
Surface *iconSurface;
|
OffscreenSurface *iconSurface;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -149,7 +149,7 @@ bool InputDialog::exec() {
|
|||||||
Uint32 caretTick = 0, curTick;
|
Uint32 caretTick = 0, curTick;
|
||||||
bool caretOn = true;
|
bool caretOn = true;
|
||||||
|
|
||||||
OffscreenSurface bg(gmenu2x->bg);
|
OffscreenSurface bg(*gmenu2x->bg);
|
||||||
drawTitleIcon(bg, icon, false);
|
drawTitleIcon(bg, icon, false);
|
||||||
writeTitle(bg, title);
|
writeTitle(bg, title);
|
||||||
writeSubTitle(bg, text);
|
writeSubTitle(bg, text);
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class GMenu2X;
|
class GMenu2X;
|
||||||
class Surface;
|
class OffscreenSurface;
|
||||||
class Touchscreen;
|
class Touchscreen;
|
||||||
|
|
||||||
|
|
||||||
@ -68,8 +68,7 @@ protected:
|
|||||||
bool edited;
|
bool edited;
|
||||||
std::string title, description, launchMsg, icon, iconPath;
|
std::string title, description, launchMsg, icon, iconPath;
|
||||||
|
|
||||||
Surface *iconSurface;
|
OffscreenSurface *iconSurface;
|
||||||
Surface *icon_hover;
|
|
||||||
|
|
||||||
virtual const std::string &searchIcon();
|
virtual const std::string &searchIcon();
|
||||||
void setIconPath(const std::string &icon);
|
void setIconPath(const std::string &icon);
|
||||||
|
@ -433,11 +433,11 @@ void LinkApp::showManual() {
|
|||||||
gmenu2x->setSafeMaxClock();
|
gmenu2x->setSafeMaxClock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OffscreenSurface *pngman = OffscreenSurface::loadImage(manual);
|
auto pngman = OffscreenSurface::loadImage(manual);
|
||||||
if (!pngman) {
|
if (!pngman) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
OffscreenSurface *bg = OffscreenSurface::loadImage(gmenu2x->confStr["wallpaper"]);
|
auto bg = OffscreenSurface::loadImage(gmenu2x->confStr["wallpaper"]);
|
||||||
if (!bg) {
|
if (!bg) {
|
||||||
bg = OffscreenSurface::emptySurface(gmenu2x->s->width(), gmenu2x->s->height());
|
bg = OffscreenSurface::emptySurface(gmenu2x->s->width(), gmenu2x->s->height());
|
||||||
}
|
}
|
||||||
@ -502,7 +502,6 @@ void LinkApp::showManual() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete bg;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
class GMenu2X;
|
class GMenu2X;
|
||||||
class Launcher;
|
class Launcher;
|
||||||
|
class Surface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Parses links files.
|
Parses links files.
|
||||||
|
@ -59,7 +59,7 @@ int Selector::exec(int startSelection) {
|
|||||||
fl.setFilter(link->getSelectorFilter());
|
fl.setFilter(link->getSelectorFilter());
|
||||||
fl.browse();
|
fl.browse();
|
||||||
|
|
||||||
OffscreenSurface bg(gmenu2x->bg);
|
OffscreenSurface bg(*gmenu2x->bg);
|
||||||
drawTitleIcon(bg, link->getIconPath(), true);
|
drawTitleIcon(bg, link->getIconPath(), true);
|
||||||
writeTitle(bg, link->getTitle());
|
writeTitle(bg, link->getTitle());
|
||||||
writeSubTitle(bg, link->getDescription());
|
writeSubTitle(bg, link->getDescription());
|
||||||
|
@ -50,7 +50,7 @@ SettingsDialog::~SettingsDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SettingsDialog::exec() {
|
bool SettingsDialog::exec() {
|
||||||
OffscreenSurface bg(gmenu2x->bg);
|
OffscreenSurface bg(*gmenu2x->bg);
|
||||||
bg.convertToDisplayFormat();
|
bg.convertToDisplayFormat();
|
||||||
|
|
||||||
bool close = false, ts_pressed = false;
|
bool close = false, ts_pressed = false;
|
||||||
|
@ -281,17 +281,18 @@ void Surface::fillRectAlpha(SDL_Rect rect, RGBAColor c) {
|
|||||||
|
|
||||||
// OffscreenSurface:
|
// OffscreenSurface:
|
||||||
|
|
||||||
OffscreenSurface *OffscreenSurface::emptySurface(int width, int height)
|
unique_ptr<OffscreenSurface> OffscreenSurface::emptySurface(
|
||||||
|
int width, int height)
|
||||||
{
|
{
|
||||||
SDL_Surface *raw = SDL_CreateRGBSurface(
|
SDL_Surface *raw = SDL_CreateRGBSurface(
|
||||||
SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0);
|
SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0);
|
||||||
if (!raw) return nullptr;
|
if (!raw) return unique_ptr<OffscreenSurface>();
|
||||||
SDL_FillRect(raw, nullptr, SDL_MapRGB(raw->format, 0, 0, 0));
|
SDL_FillRect(raw, nullptr, SDL_MapRGB(raw->format, 0, 0, 0));
|
||||||
return new OffscreenSurface(raw);
|
return unique_ptr<OffscreenSurface>(new OffscreenSurface(raw));
|
||||||
}
|
}
|
||||||
|
|
||||||
OffscreenSurface *OffscreenSurface::loadImage(
|
unique_ptr<OffscreenSurface> OffscreenSurface::loadImage(
|
||||||
const string &img, const string &skin, bool loadAlpha)
|
string const& img,string const& skin, bool loadAlpha)
|
||||||
{
|
{
|
||||||
string skinpath;
|
string skinpath;
|
||||||
if (!skin.empty() && !img.empty() && img[0]!='/')
|
if (!skin.empty() && !img.empty() && img[0]!='/')
|
||||||
@ -302,10 +303,10 @@ OffscreenSurface *OffscreenSurface::loadImage(
|
|||||||
SDL_Surface *raw = loadPNG(skinpath, loadAlpha);
|
SDL_Surface *raw = loadPNG(skinpath, loadAlpha);
|
||||||
if (!raw) {
|
if (!raw) {
|
||||||
ERROR("Couldn't load surface '%s'\n", img.c_str());
|
ERROR("Couldn't load surface '%s'\n", img.c_str());
|
||||||
return nullptr;
|
return unique_ptr<OffscreenSurface>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new OffscreenSurface(raw);
|
return unique_ptr<OffscreenSurface>(new OffscreenSurface(raw));
|
||||||
}
|
}
|
||||||
|
|
||||||
OffscreenSurface::OffscreenSurface(OffscreenSurface&& other)
|
OffscreenSurface::OffscreenSurface(OffscreenSurface&& other)
|
||||||
|
@ -107,14 +107,14 @@ private:
|
|||||||
*/
|
*/
|
||||||
class OffscreenSurface: public Surface {
|
class OffscreenSurface: public Surface {
|
||||||
public:
|
public:
|
||||||
static OffscreenSurface *emptySurface(int width, int height);
|
static std::unique_ptr<OffscreenSurface> emptySurface(
|
||||||
static OffscreenSurface *loadImage(const std::string &img,
|
int width, int height);
|
||||||
const std::string &skin="", bool loadAlpha=true);
|
static std::unique_ptr<OffscreenSurface> loadImage(
|
||||||
|
std::string const& img, std::string const& skin = "",
|
||||||
// TODO: Remove this once naked Surface pointers are no longer in use.
|
bool loadAlpha = true);
|
||||||
OffscreenSurface(Surface *other) : Surface(*other) {}
|
|
||||||
|
|
||||||
OffscreenSurface(Surface const& other) : Surface(other) {}
|
OffscreenSurface(Surface const& other) : Surface(other) {}
|
||||||
|
OffscreenSurface(OffscreenSurface const& other) : Surface(other) {}
|
||||||
OffscreenSurface(OffscreenSurface&& other);
|
OffscreenSurface(OffscreenSurface&& other);
|
||||||
~OffscreenSurface();
|
~OffscreenSurface();
|
||||||
OffscreenSurface& operator=(OffscreenSurface other);
|
OffscreenSurface& operator=(OffscreenSurface other);
|
||||||
|
@ -120,7 +120,8 @@ OffscreenSurface *SurfaceCollection::add(const string &path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("Adding surface: '%s'\n", path.c_str());
|
DEBUG("Adding surface: '%s'\n", path.c_str());
|
||||||
auto s = OffscreenSurface::loadImage(filePath, "", defaultAlpha);
|
// TODO: Be safe.
|
||||||
|
auto s = OffscreenSurface::loadImage(filePath, "", defaultAlpha).release();
|
||||||
if (s) {
|
if (s) {
|
||||||
surfaces[path] = s;
|
surfaces[path] = s;
|
||||||
}
|
}
|
||||||
@ -136,7 +137,8 @@ OffscreenSurface *SurfaceCollection::addSkinRes(const string &path, bool useDefa
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
DEBUG("Adding skin surface: '%s'\n", path.c_str());
|
DEBUG("Adding skin surface: '%s'\n", path.c_str());
|
||||||
auto s = OffscreenSurface::loadImage(skinpath);
|
// TODO: Be safe.
|
||||||
|
auto s = OffscreenSurface::loadImage(skinpath).release();
|
||||||
if (s) {
|
if (s) {
|
||||||
surfaces[path] = s;
|
surfaces[path] = s;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ void TextDialog::drawText(const vector<string> &text, unsigned int y,
|
|||||||
void TextDialog::exec() {
|
void TextDialog::exec() {
|
||||||
bool close = false;
|
bool close = false;
|
||||||
|
|
||||||
OffscreenSurface bg(gmenu2x->bg);
|
OffscreenSurface bg(*gmenu2x->bg);
|
||||||
|
|
||||||
//link icon
|
//link icon
|
||||||
if (!fileExists(icon))
|
if (!fileExists(icon))
|
||||||
|
@ -68,7 +68,7 @@ TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextManualDialog::exec() {
|
void TextManualDialog::exec() {
|
||||||
OffscreenSurface bg(gmenu2x->bg);
|
OffscreenSurface bg(*gmenu2x->bg);
|
||||||
|
|
||||||
//link icon
|
//link icon
|
||||||
if (!fileExists(icon))
|
if (!fileExists(icon))
|
||||||
|
Loading…
Reference in New Issue
Block a user