mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-08-19 07:19:19 +03:00
Surface: Removed unused code and restricted access.
Removed all methods that are never called. Made methods that are only called by Surface itself private. One ugly thing remaining is outside access to the "raw" field.
This commit is contained in:
parent
b068aa04d4
commit
b6a5d89bc8
154
src/surface.cpp
154
src/surface.cpp
@ -58,38 +58,11 @@ Surface::Surface(const string &img, const string &skin, bool alpha) {
|
|||||||
halfH = raw->h/2;
|
halfH = raw->h/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::Surface(SDL_Surface *s, SDL_PixelFormat *fmt, Uint32 flags) {
|
|
||||||
dblbuffer = NULL;
|
|
||||||
this->operator =(s);
|
|
||||||
if (fmt!=NULL || flags!=0) {
|
|
||||||
if (fmt==NULL) fmt = s->format;
|
|
||||||
if (flags==0) flags = s->flags;
|
|
||||||
raw = SDL_ConvertSurface( s, fmt, flags );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Surface::Surface(Surface *s) {
|
Surface::Surface(Surface *s) {
|
||||||
dblbuffer = NULL;
|
dblbuffer = NULL;
|
||||||
this->operator =(s->raw);
|
raw = SDL_DisplayFormat(s->raw);
|
||||||
}
|
halfW = raw->w/2;
|
||||||
|
halfH = raw->h/2;
|
||||||
Surface::Surface(int w, int h, Uint32 flags) {
|
|
||||||
dblbuffer = NULL;
|
|
||||||
Uint32 rmask, gmask, bmask, amask;
|
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
||||||
rmask = 0xff000000;
|
|
||||||
gmask = 0x00ff0000;
|
|
||||||
bmask = 0x0000ff00;
|
|
||||||
amask = 0x000000ff;
|
|
||||||
#else
|
|
||||||
rmask = 0x000000ff;
|
|
||||||
gmask = 0x0000ff00;
|
|
||||||
bmask = 0x00ff0000;
|
|
||||||
amask = 0xff000000;
|
|
||||||
#endif
|
|
||||||
raw = SDL_CreateRGBSurface( flags, w, h, 16, rmask, gmask, bmask, amask );
|
|
||||||
halfW = w/2;
|
|
||||||
halfH = h/2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::~Surface() {
|
Surface::~Surface() {
|
||||||
@ -137,23 +110,6 @@ void Surface::load(const string &img, bool alpha, const string &skin) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Surface::lock() {
|
|
||||||
if ( SDL_MUSTLOCK(raw) && !locked ) {
|
|
||||||
if ( SDL_LockSurface(raw) < 0 ) {
|
|
||||||
ERROR("Can't lock surface: '%s'\n", SDL_GetError());
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
locked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::unlock() {
|
|
||||||
if ( SDL_MUSTLOCK(raw) && locked ) {
|
|
||||||
SDL_UnlockSurface(raw);
|
|
||||||
locked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::flip() {
|
void Surface::flip() {
|
||||||
if (dblbuffer!=NULL) {
|
if (dblbuffer!=NULL) {
|
||||||
this->blit(dblbuffer,0,0);
|
this->blit(dblbuffer,0,0);
|
||||||
@ -197,118 +153,25 @@ bool Surface::blitRight(Surface *destination, int x, int y, int w, int h, int a)
|
|||||||
return blitRight(destination->raw,x,y,w,h,a);
|
return blitRight(destination->raw,x,y,w,h,a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Surface::putPixel(int x, int y, SDL_Color color) {
|
|
||||||
putPixel(x,y, SDL_MapRGB( raw->format , color.r , color.g , color.b ));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::putPixel(int x, int y, Uint32 color) {
|
|
||||||
//determine position
|
|
||||||
char* pPosition = ( char* ) raw->pixels ;
|
|
||||||
//offset by y
|
|
||||||
pPosition += ( raw->pitch * y ) ;
|
|
||||||
//offset by x
|
|
||||||
pPosition += ( raw->format->BytesPerPixel * x ) ;
|
|
||||||
//copy pixel data
|
|
||||||
memcpy ( pPosition , &color , raw->format->BytesPerPixel ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Color Surface::pixelColor(int x, int y) {
|
|
||||||
SDL_Color color;
|
|
||||||
Uint32 col = pixel(x,y);
|
|
||||||
SDL_GetRGB( col, raw->format, &color.r, &color.g, &color.b );
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint32 Surface::pixel(int x, int y) {
|
|
||||||
//determine position
|
|
||||||
char* pPosition = ( char* ) raw->pixels ;
|
|
||||||
//offset by y
|
|
||||||
pPosition += ( raw->pitch * y ) ;
|
|
||||||
//offset by x
|
|
||||||
pPosition += ( raw->format->BytesPerPixel * x ) ;
|
|
||||||
//copy pixel data
|
|
||||||
Uint32 col = 0;
|
|
||||||
memcpy ( &col , pPosition , raw->format->BytesPerPixel ) ;
|
|
||||||
return col;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::blendAdd(Surface *target, int x, int y) {
|
|
||||||
SDL_Color targetcol, blendcol;
|
|
||||||
for (int iy=0; iy<raw->h; iy++)
|
|
||||||
if (iy+y >= 0 && iy+y < target->raw->h)
|
|
||||||
for (int ix=0; ix<raw->w; ix++) {
|
|
||||||
if (ix+x >= 0 && ix+x < target->raw->w) {
|
|
||||||
blendcol = pixelColor(ix,iy);
|
|
||||||
targetcol = target->pixelColor(ix+x,iy+y);
|
|
||||||
targetcol.r = min(targetcol.r+blendcol.r, 255);
|
|
||||||
targetcol.g = min(targetcol.g+blendcol.g, 255);
|
|
||||||
targetcol.b = min(targetcol.b+blendcol.b, 255);
|
|
||||||
target->putPixel(ix+x,iy+y,targetcol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Uint32 bcol, tcol;
|
|
||||||
char *pPos, *tpPos;
|
|
||||||
for (int iy=0; iy<raw->h; iy++)
|
|
||||||
if (iy+y >= 0 && iy+y < target->raw->h) {
|
|
||||||
pPos = (char*)raw->pixels + raw->pitch*iy;
|
|
||||||
tpPos = (char*)target->raw->pixels + target->raw->pitch*(iy+y);
|
|
||||||
|
|
||||||
for (int ix=0; ix<raw->w; ix++) {
|
|
||||||
memcpy(&bcol, pPos, raw->format->BytesPerPixel);
|
|
||||||
memcpy(&tcol, tpPos, target->raw->format->BytesPerPixel);
|
|
||||||
//memcpy(tpPos, &bcol, target->raw->format->BytesPerPixel);
|
|
||||||
pPos += raw->format->BytesPerPixel;
|
|
||||||
tpPos += target->raw->format->BytesPerPixel;
|
|
||||||
target->putPixel(ix+x,iy+y,bcol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::operator = (SDL_Surface *s) {
|
|
||||||
raw = SDL_DisplayFormat(s);
|
|
||||||
halfW = raw->w/2;
|
|
||||||
halfH = raw->h/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::operator = (Surface *s) {
|
|
||||||
this->operator =(s->raw);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
||||||
return boxRGBA(raw,x,y,x+w-1,y+h-1,r,g,b,a);
|
return boxRGBA(raw,x,y,x+w-1,y+h-1,r,g,b,a);
|
||||||
}
|
}
|
||||||
int Surface::box(SDL_Rect re, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
|
||||||
return boxRGBA(raw,re.x,re.y,re.x+re.w-1,re.y+re.h-1,r,g,b,a);
|
|
||||||
}
|
|
||||||
int Surface::box(SDL_Rect re, Uint8 r, Uint8 g, Uint8 b) {
|
|
||||||
return SDL_FillRect(raw, &re, SDL_MapRGBA(format(),r,g,b,255));
|
|
||||||
}
|
|
||||||
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b) {
|
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b) {
|
||||||
SDL_Rect re = {x,y,w,h};
|
SDL_Rect re = {x,y,w,h};
|
||||||
return box(re,r,g,b);
|
return SDL_FillRect(raw, &re, SDL_MapRGBA(format(),r,g,b,255));
|
||||||
}
|
}
|
||||||
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, RGBAColor c) {
|
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, RGBAColor c) {
|
||||||
return box(x,y,w,h,c.r,c.g,c.b,c.a);
|
return box(x,y,w,h,c.r,c.g,c.b,c.a);
|
||||||
}
|
}
|
||||||
int Surface::box(SDL_Rect re, RGBAColor c) {
|
int Surface::box(SDL_Rect re, RGBAColor c) {
|
||||||
return box(re,c.r,c.g,c.b,c.a);
|
return boxRGBA(
|
||||||
|
raw, re.x, re.y, re.x + re.w - 1, re.y + re.h - 1, c.r, c.g, c.b, c.a
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
||||||
return rectangleRGBA(raw,x,y,x+w-1,y+h-1,r,g,b,a);
|
return rectangleRGBA(raw,x,y,x+w-1,y+h-1,r,g,b,a);
|
||||||
}
|
}
|
||||||
int Surface::rectangle(SDL_Rect re, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
|
||||||
return rectangleRGBA(raw,re.x,re.y,re.x+re.w-1,re.y+re.h-1,r,g,b,a);
|
|
||||||
}
|
|
||||||
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b) {
|
|
||||||
return rectangleColor(raw, x,y,x+w-1,y+h-1, SDL_MapRGBA(format(),r,g,b,255));
|
|
||||||
}
|
|
||||||
int Surface::rectangle(SDL_Rect re, Uint8 r, Uint8 g, Uint8 b) {
|
|
||||||
return rectangleColor(raw, re.x,re.y,re.x+re.w-1,re.y+re.h-1, SDL_MapRGBA(format(),r,g,b,255));
|
|
||||||
}
|
|
||||||
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, RGBAColor c) {
|
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, RGBAColor c) {
|
||||||
return rectangle(x,y,w,h,c.r,c.g,c.b,c.a);
|
return rectangle(x,y,w,h,c.r,c.g,c.b,c.a);
|
||||||
}
|
}
|
||||||
@ -319,9 +182,6 @@ int Surface::rectangle(SDL_Rect re, RGBAColor c) {
|
|||||||
int Surface::hline(Sint16 x, Sint16 y, Sint16 w, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
int Surface::hline(Sint16 x, Sint16 y, Sint16 w, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
||||||
return hlineRGBA(raw,x,x+w-1,y,r,g,b,a);
|
return hlineRGBA(raw,x,x+w-1,y,r,g,b,a);
|
||||||
}
|
}
|
||||||
int Surface::hline(Sint16 x, Sint16 y, Sint16 w, RGBAColor c) {
|
|
||||||
return hline(x,y,w-1,c.r,c.g,c.b,c.a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::clearClipRect() {
|
void Surface::clearClipRect() {
|
||||||
SDL_SetClipRect(raw,NULL);
|
SDL_SetClipRect(raw,NULL);
|
||||||
|
@ -38,18 +38,11 @@ RGBAColor strtorgba(const string &strColor);
|
|||||||
@author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
|
@author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
|
||||||
*/
|
*/
|
||||||
class Surface {
|
class Surface {
|
||||||
private:
|
|
||||||
bool locked;
|
|
||||||
int halfW, halfH;
|
|
||||||
SDL_Surface *dblbuffer;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Surface();
|
Surface();
|
||||||
Surface(const string &img, const string &skin="", bool alpha=true);
|
Surface(const string &img, const string &skin="", bool alpha=true);
|
||||||
Surface(const string &img, bool alpha, const string &skin="");
|
Surface(const string &img, bool alpha, const string &skin="");
|
||||||
Surface(SDL_Surface *s, SDL_PixelFormat *fmt = NULL, Uint32 flags = 0);
|
|
||||||
Surface(Surface *s);
|
Surface(Surface *s);
|
||||||
Surface(int w, int h, Uint32 flags = SDL_HWSURFACE|SDL_SRCALPHA);
|
|
||||||
~Surface();
|
~Surface();
|
||||||
|
|
||||||
void enableVirtualDoubleBuffer(SDL_Surface *surface);
|
void enableVirtualDoubleBuffer(SDL_Surface *surface);
|
||||||
@ -57,18 +50,7 @@ public:
|
|||||||
SDL_Surface *raw;
|
SDL_Surface *raw;
|
||||||
|
|
||||||
void free();
|
void free();
|
||||||
void load(const string &img, bool alpha=true, const string &skin="");
|
|
||||||
void lock();
|
|
||||||
void unlock();
|
|
||||||
void flip();
|
void flip();
|
||||||
SDL_PixelFormat *format();
|
|
||||||
|
|
||||||
void putPixel(int,int,SDL_Color);
|
|
||||||
void putPixel(int,int,Uint32);
|
|
||||||
SDL_Color pixelColor(int,int);
|
|
||||||
Uint32 pixel(int,int);
|
|
||||||
|
|
||||||
void blendAdd(Surface*, int,int);
|
|
||||||
|
|
||||||
void clearClipRect();
|
void clearClipRect();
|
||||||
void setClipRect(int x, int y, int w, int h);
|
void setClipRect(int x, int y, int w, int h);
|
||||||
@ -76,11 +58,8 @@ public:
|
|||||||
|
|
||||||
bool blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
bool blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
||||||
bool blit(Surface *destination, SDL_Rect container, ASFont::HAlign halign = ASFont::HAlignLeft, ASFont::VAlign valign = ASFont::VAlignTop);
|
bool blit(Surface *destination, SDL_Rect container, ASFont::HAlign halign = ASFont::HAlignLeft, ASFont::VAlign valign = ASFont::VAlignTop);
|
||||||
bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
|
||||||
bool blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
bool blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
||||||
bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
|
||||||
bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
||||||
bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
|
||||||
|
|
||||||
void write(ASFont *font, const string &text, int x, int y, ASFont::HAlign halign = ASFont::HAlignLeft, ASFont::VAlign valign = ASFont::VAlignTop) {
|
void write(ASFont *font, const string &text, int x, int y, ASFont::HAlign halign = ASFont::HAlignLeft, ASFont::VAlign valign = ASFont::VAlignTop) {
|
||||||
font->write(this, text, x, y, halign, valign);
|
font->write(this, text, x, y, halign, valign);
|
||||||
@ -89,20 +68,22 @@ public:
|
|||||||
int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
||||||
int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8);
|
int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8);
|
||||||
int box(Sint16, Sint16, Sint16, Sint16, RGBAColor);
|
int box(Sint16, Sint16, Sint16, Sint16, RGBAColor);
|
||||||
int box(SDL_Rect, Uint8, Uint8, Uint8, Uint8);
|
|
||||||
int box(SDL_Rect, Uint8, Uint8, Uint8);
|
|
||||||
int box(SDL_Rect, RGBAColor);
|
int box(SDL_Rect, RGBAColor);
|
||||||
int rectangle(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
int rectangle(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
||||||
int rectangle(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8);
|
|
||||||
int rectangle(Sint16, Sint16, Sint16, Sint16, RGBAColor);
|
int rectangle(Sint16, Sint16, Sint16, Sint16, RGBAColor);
|
||||||
int rectangle(SDL_Rect, Uint8, Uint8, Uint8, Uint8);
|
|
||||||
int rectangle(SDL_Rect, Uint8, Uint8, Uint8);
|
|
||||||
int rectangle(SDL_Rect, RGBAColor);
|
int rectangle(SDL_Rect, RGBAColor);
|
||||||
int hline(Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
int hline(Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
||||||
int hline(Sint16, Sint16, Sint16, RGBAColor);
|
|
||||||
|
|
||||||
void operator = (SDL_Surface*);
|
private:
|
||||||
void operator = (Surface*);
|
SDL_PixelFormat *format();
|
||||||
|
void load(const string &img, bool alpha=true, const string &skin="");
|
||||||
|
bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
||||||
|
bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
||||||
|
bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
||||||
|
|
||||||
|
bool locked;
|
||||||
|
int halfW, halfH;
|
||||||
|
SDL_Surface *dblbuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user