2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
2011-10-23 17:43:56 +03:00
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
2010-02-04 13:33:47 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
2011-10-23 17:43:56 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
#ifndef SURFACE_H
|
|
|
|
#define SURFACE_H
|
|
|
|
|
2013-08-03 23:30:12 +03:00
|
|
|
#include "font.h"
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-10-23 17:43:56 +03:00
|
|
|
#include <SDL.h>
|
|
|
|
#include <string>
|
2014-07-17 20:22:48 +03:00
|
|
|
#include <cstdint>
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
struct RGBAColor {
|
2014-07-17 20:22:48 +03:00
|
|
|
uint8_t r, g, b, a;
|
2014-07-17 20:27:39 +03:00
|
|
|
static RGBAColor fromString(std::string const& strColor);
|
2014-07-17 21:11:06 +03:00
|
|
|
RGBAColor() : r(0), g(0), b(0), a(0) {}
|
|
|
|
RGBAColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
|
|
|
|
: r(r), g(g), b(b), a(a) {}
|
2014-07-17 23:15:50 +03:00
|
|
|
Uint32 pixelValue(SDL_PixelFormat *fmt) {
|
|
|
|
return SDL_MapRGBA(fmt, r, g, b, a);
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wrapper around SDL_Surface
|
|
|
|
@author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
|
|
|
|
*/
|
|
|
|
class Surface {
|
|
|
|
public:
|
2011-06-02 18:59:26 +03:00
|
|
|
static Surface *openOutputSurface(int width, int height, int bitsperpixel);
|
2011-06-03 12:46:36 +03:00
|
|
|
static Surface *emptySurface(int width, int height);
|
2011-10-23 17:43:56 +03:00
|
|
|
static Surface *loadImage(const std::string &img,
|
2014-07-13 23:47:45 +03:00
|
|
|
const std::string &skin="", bool loadAlpha=true);
|
2011-06-02 18:59:26 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
Surface(Surface *s);
|
|
|
|
~Surface();
|
|
|
|
|
2011-06-03 12:46:36 +03:00
|
|
|
/** Converts the underlying surface to the same pixel format as the frame
|
|
|
|
* buffer, for faster blitting. This removes the alpha channel if the
|
|
|
|
* image has done.
|
|
|
|
*/
|
|
|
|
void convertToDisplayFormat();
|
|
|
|
|
2013-08-09 18:47:34 +03:00
|
|
|
int width() const { return raw->w; }
|
|
|
|
int height() const { return raw->h; }
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
void flip();
|
|
|
|
|
|
|
|
void clearClipRect();
|
|
|
|
void setClipRect(int x, int y, int w, int h);
|
|
|
|
void setClipRect(SDL_Rect rect);
|
|
|
|
|
2014-07-17 19:41:11 +03:00
|
|
|
void blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
|
|
|
|
void blit(Surface *destination, SDL_Rect container, Font::HAlign halign = Font::HAlignLeft, Font::VAlign valign = Font::VAlignTop) const;
|
|
|
|
void blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
|
|
|
|
void blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2013-08-03 23:30:12 +03:00
|
|
|
void write(Font *font, const std::string &text, int x, int y,
|
|
|
|
Font::HAlign halign = Font::HAlignLeft,
|
|
|
|
Font::VAlign valign = Font::VAlignTop) {
|
2011-05-09 06:17:25 +03:00
|
|
|
font->write(this, text, x, y, halign, valign);
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-07-17 23:15:50 +03:00
|
|
|
void box(SDL_Rect re, RGBAColor c);
|
|
|
|
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
|
|
|
|
box((SDL_Rect){ x, y, w, h }, c);
|
|
|
|
}
|
|
|
|
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
|
|
|
box((SDL_Rect){ x, y, w, h }, RGBAColor(r, g, b, a));
|
|
|
|
}
|
|
|
|
void rectangle(SDL_Rect re, RGBAColor c);
|
|
|
|
void rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
|
|
|
|
rectangle((SDL_Rect){ x, y, w, h }, c);
|
|
|
|
}
|
|
|
|
void rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
|
|
|
rectangle((SDL_Rect){ x, y, w, h }, RGBAColor(r, g, b, a));
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-06-02 04:39:34 +03:00
|
|
|
private:
|
2011-06-02 18:59:26 +03:00
|
|
|
Surface(SDL_Surface *raw, bool freeWhenDone);
|
2014-07-17 19:41:11 +03:00
|
|
|
void blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
|
|
|
|
void blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
|
|
|
|
void blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
|
2011-06-02 04:39:34 +03:00
|
|
|
|
2011-06-02 23:44:04 +03:00
|
|
|
SDL_Surface *raw;
|
2011-06-02 18:59:26 +03:00
|
|
|
bool freeWhenDone;
|
2011-06-02 04:39:34 +03:00
|
|
|
int halfW, halfH;
|
2011-06-02 23:44:04 +03:00
|
|
|
|
|
|
|
// For direct access to "raw".
|
2013-08-03 23:30:12 +03:00
|
|
|
friend class Font;
|
2010-02-04 13:33:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|