Root/
Source at commit 86ee995 created 9 years 8 months ago. By Maarten ter Huurne, Removed dedicated horizontal line routine | |
---|---|
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 | |
21 | #ifndef SURFACE_H |
22 | #define SURFACE_H |
23 | |
24 | #include "font.h" |
25 | |
26 | #include <SDL.h> |
27 | #include <string> |
28 | |
29 | struct RGBAColor { |
30 | unsigned short r,g,b,a; |
31 | }; |
32 | |
33 | RGBAColor strtorgba(const std::string &strColor); |
34 | |
35 | /** |
36 | Wrapper around SDL_Surface |
37 | @author Massimiliano Torromeo <massimiliano.torromeo@gmail.com> |
38 | */ |
39 | class Surface { |
40 | public: |
41 | static Surface *openOutputSurface(int width, int height, int bitsperpixel); |
42 | static Surface *emptySurface(int width, int height); |
43 | static Surface *loadImage(const std::string &img, |
44 | const std::string &skin="", bool loadAlpha=true); |
45 | |
46 | Surface(Surface *s); |
47 | ~Surface(); |
48 | |
49 | /** Converts the underlying surface to the same pixel format as the frame |
50 | * buffer, for faster blitting. This removes the alpha channel if the |
51 | * image has done. |
52 | */ |
53 | void convertToDisplayFormat(); |
54 | |
55 | int width() const { return raw->w; } |
56 | int height() const { return raw->h; } |
57 | |
58 | void flip(); |
59 | |
60 | void clearClipRect(); |
61 | void setClipRect(int x, int y, int w, int h); |
62 | void setClipRect(SDL_Rect rect); |
63 | |
64 | bool blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; |
65 | bool blit(Surface *destination, SDL_Rect container, Font::HAlign halign = Font::HAlignLeft, Font::VAlign valign = Font::VAlignTop) const; |
66 | bool blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; |
67 | bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; |
68 | |
69 | void write(Font *font, const std::string &text, int x, int y, |
70 | Font::HAlign halign = Font::HAlignLeft, |
71 | Font::VAlign valign = Font::VAlignTop) { |
72 | font->write(this, text, x, y, halign, valign); |
73 | } |
74 | |
75 | int box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a); |
76 | int box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b); |
77 | int box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor); |
78 | int box(SDL_Rect, RGBAColor); |
79 | int rectangle(Sint16, Sint16, Uint16, Uint16, Uint8 r, Uint8 g, Uint8 b, Uint8 a); |
80 | int rectangle(Sint16, Sint16, Uint16, Uint16, RGBAColor); |
81 | int rectangle(SDL_Rect, RGBAColor); |
82 | |
83 | private: |
84 | Surface(SDL_Surface *raw, bool freeWhenDone); |
85 | bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; |
86 | bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; |
87 | bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; |
88 | |
89 | SDL_Surface *raw; |
90 | bool freeWhenDone; |
91 | int halfW, halfH; |
92 | |
93 | // For direct access to "raw". |
94 | friend class Font; |
95 | }; |
96 | |
97 | #endif |
98 |
Branches:
install_locations
master
opkrun
packages