mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 02:10:38 +02:00
Made Font ownership explicit using unique_ptr
This commit is contained in:
parent
902145b698
commit
e32964bb50
@ -14,9 +14,9 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
Font *Font::defaultFont()
|
||||
unique_ptr<Font> Font::defaultFont()
|
||||
{
|
||||
return new Font(TTF_FONT, TTF_FONT_SIZE);
|
||||
return unique_ptr<Font>(new Font(TTF_FONT, TTF_FONT_SIZE));
|
||||
}
|
||||
|
||||
Font::Font(const std::string &path, unsigned int size)
|
||||
|
12
src/font.h
12
src/font.h
@ -5,20 +5,26 @@
|
||||
#define FONT_H
|
||||
|
||||
#include <SDL_ttf.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class Surface;
|
||||
|
||||
/**
|
||||
* Wrapper around a TrueType or other FreeType-supported font.
|
||||
* The wrapper is valid even if the font couldn't be loaded, but in that case
|
||||
* nothing will be drawn.
|
||||
*/
|
||||
class Font {
|
||||
public:
|
||||
enum HAlign { HAlignLeft, HAlignRight, HAlignCenter };
|
||||
enum VAlign { VAlignTop, VAlignBottom, VAlignMiddle };
|
||||
|
||||
/**
|
||||
* Returns a newly created Font object for the default font,
|
||||
* or nullptr if there was a problem creating it.
|
||||
* Returns a newly created Font object for the default font.
|
||||
*/
|
||||
static Font *defaultFont();
|
||||
static std::unique_ptr<Font> defaultFont();
|
||||
|
||||
Font(const std::string &path, unsigned int size);
|
||||
~Font();
|
||||
|
||||
|
@ -278,7 +278,6 @@ GMenu2X::~GMenu2X() {
|
||||
delete PowerSaver::getInstance();
|
||||
quit();
|
||||
|
||||
delete font;
|
||||
#ifdef ENABLE_INOTIFY
|
||||
delete monitor;
|
||||
#endif
|
||||
@ -355,11 +354,6 @@ void GMenu2X::initBG() {
|
||||
}
|
||||
|
||||
void GMenu2X::initFont() {
|
||||
if (font) {
|
||||
delete font;
|
||||
font = NULL;
|
||||
}
|
||||
|
||||
string path = skinConfStr["font"];
|
||||
if (!path.empty()) {
|
||||
unsigned int size = skinConfInt["fontsize"];
|
||||
@ -367,16 +361,10 @@ void GMenu2X::initFont() {
|
||||
size = 12;
|
||||
if (path.substr(0,5)=="skin:")
|
||||
path = sc.getSkinFilePath(path.substr(5, path.length()));
|
||||
font = new Font(path, size);
|
||||
font.reset(new Font(path, size));
|
||||
} else {
|
||||
font = Font::defaultFont();
|
||||
}
|
||||
|
||||
if (!font) {
|
||||
ERROR("Cannot function without font; aborting...\n");
|
||||
quit();
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void GMenu2X::initMenu() {
|
||||
|
@ -159,7 +159,7 @@ public:
|
||||
SurfaceCollection sc;
|
||||
Translator tr;
|
||||
Surface *s, *bg;
|
||||
Font *font;
|
||||
std::unique_ptr<Font> font;
|
||||
|
||||
//Status functions
|
||||
void main();
|
||||
|
Loading…
Reference in New Issue
Block a user