1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-07-02 18:54:31 +03:00

Isolate all PNG loading in a separate source/header.

This is in preparation of replacing SDL_image with direct use of libpng.
This commit is contained in:
Maarten ter Huurne 2011-03-30 03:21:31 +02:00
parent c22cc4d663
commit e6be835038
7 changed files with 34 additions and 11 deletions

View File

@ -11,7 +11,8 @@ gmenu2x_SOURCES = asfont.cpp button.cpp cpu.cpp dirdialog.cpp filedialog.cpp \
settingsdialog.cpp sfontplus.cpp surfacecollection.cpp surface.cpp \
textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \
utilities.cpp wallpaperdialog.cpp \
browsedialog.cpp buttonbox.cpp dialog.cpp
browsedialog.cpp buttonbox.cpp dialog.cpp \
imageio.cpp
noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \
filedialog.h filelister.h gmenu2x.h gp2x.h iconbutton.h imagedialog.h \
@ -23,7 +24,8 @@ noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \
messagebox.h selector.h settingsdialog.h \
sfontplus.h surfacecollection.h surface.h textdialog.h textmanualdialog.h \
touchscreen.h translator.h utilities.h wallpaperdialog.h \
browsedialog.h buttonbox.h dialog.h
browsedialog.h buttonbox.h dialog.h \
imageio.h
AM_CFLAGS= @CFLAGS@ @SDL_CFLAGS@

8
src/imageio.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "imageio.h"
#include <SDL_image.h>
SDL_Surface *loadPNG(const std::string &path)
{
return IMG_Load(path.c_str());
}

10
src/imageio.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef IMAGEIO_H
#define IMAGEIO_H
#include <string>
struct SDL_Surface;
SDL_Surface *loadPNG(const std::string &path);
#endif

View File

@ -1,7 +1,8 @@
#include "sfontplus.h"
#include "imageio.h"
#include <cassert>
#include <SDL_image.h>
#include <iostream>
using namespace std;
@ -63,7 +64,7 @@ bool SFontPlus::utf8Code(unsigned char c) {
}
void SFontPlus::initFont(const string &font, const string &characters) {
SDL_Surface *buf = IMG_Load(font.c_str());
SDL_Surface *buf = loadPNG(font);
if (buf!=NULL) {
initFont( SDL_DisplayFormatAlpha(buf), characters );
SDL_FreeSurface(buf);

View File

@ -18,15 +18,16 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "surface.h"
#include "imageio.h"
#include "utilities.h"
#include "debug.h"
#include <SDL_gfxPrimitives.h>
#include <iostream>
using namespace std;
#include "surface.h"
#include "utilities.h"
#include "debug.h"
RGBAColor strtorgba(const string &strColor) {
RGBAColor c = {0,0,0,255};
c.r = constrain( strtol( strColor.substr(0,2).c_str(), NULL, 16 ), 0, 255 );
@ -124,7 +125,7 @@ void Surface::load(const string &img, bool alpha, const string &skin) {
skinpath = img;
}
SDL_Surface *buf = IMG_Load(skinpath.c_str());
SDL_Surface *buf = loadPNG(skinpath);
if (buf!=NULL) {
if (alpha)
raw = SDL_DisplayFormatAlpha(buf);

View File

@ -20,9 +20,8 @@
#ifndef SURFACE_H
#define SURFACE_H
#include <iostream>
#include <SDL.h>
#include <SDL_image.h>
#include <string>
#include "asfont.h"

View File

@ -23,6 +23,8 @@
#include "utilities.h"
#include "debug.h"
#include <iostream>
using std::endl;
using std::string;