Root/src/surface.h

1/***************************************************************************
2 * Copyright (C) 2006 by Massimiliano Torromeo *
3 * massimiliano.torromeo@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20#ifndef SURFACE_H
21#define SURFACE_H
22
23#include <SDL.h>
24#include <string>
25
26#include "asfont.h"
27
28using std::string;
29
30struct RGBAColor {
31    unsigned short r,g,b,a;
32};
33
34RGBAColor strtorgba(const string &strColor);
35
36/**
37    Wrapper around SDL_Surface
38    @author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
39*/
40class Surface {
41public:
42    Surface();
43    Surface(Surface *s);
44    Surface(const string &img, const string &skin="");
45    ~Surface();
46
47    void enableVirtualDoubleBuffer(SDL_Surface *surface);
48
49    SDL_Surface *raw;
50
51    void free();
52    void flip();
53
54    void clearClipRect();
55    void setClipRect(int x, int y, int w, int h);
56    void setClipRect(SDL_Rect rect);
57
58    bool blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
59    bool blit(Surface *destination, SDL_Rect container, ASFont::HAlign halign = ASFont::HAlignLeft, ASFont::VAlign valign = ASFont::VAlignTop);
60    bool blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
61    bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
62
63    void write(ASFont *font, const string &text, int x, int y, ASFont::HAlign halign = ASFont::HAlignLeft, ASFont::VAlign valign = ASFont::VAlignTop) {
64        font->write(this, text, x, y, halign, valign);
65    }
66
67    int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
68    int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8);
69    int box(Sint16, Sint16, Sint16, Sint16, RGBAColor);
70    int box(SDL_Rect, RGBAColor);
71    int rectangle(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
72    int rectangle(Sint16, Sint16, Sint16, Sint16, RGBAColor);
73    int rectangle(SDL_Rect, RGBAColor);
74    int hline(Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
75
76private:
77    SDL_PixelFormat *format();
78    void load(const string &img, const string &skin);
79    bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
80    bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
81    bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
82
83    bool locked;
84    int halfW, halfH;
85    SDL_Surface *dblbuffer;
86};
87
88#endif
89

Archive Download this file



interactive