Mercurial > fife-parpg
comparison engine/core/video/image.h @ 430:ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 23 Feb 2010 19:25:59 +0000 |
parents | 3804348fe3fb |
children | 47b49b9b0c0a |
comparison
equal
deleted
inserted
replaced
429:be291458d9b5 | 430:ad1f09d954f9 |
---|---|
39 #include "util/structures/point.h" | 39 #include "util/structures/point.h" |
40 #include "util/structures/rect.h" | 40 #include "util/structures/rect.h" |
41 | 41 |
42 namespace FIFE { | 42 namespace FIFE { |
43 class Rect; | 43 class Rect; |
44 | 44 |
45 class AbstractImage { | 45 class AbstractImage { |
46 public: | 46 public: |
47 virtual ~AbstractImage() {} | 47 virtual ~AbstractImage() {} |
48 | 48 |
49 /** Get the surface used by this image | 49 /** Get the surface used by this image |
50 * @return pointer to used surface | 50 * @return pointer to used surface |
51 */ | 51 */ |
52 virtual SDL_Surface* getSurface() = 0; | 52 virtual SDL_Surface* getSurface() = 0; |
53 | 53 |
54 /** Returns the @b maximum width occupied by this image. | 54 /** Returns the @b maximum width occupied by this image. |
55 * This should return the maximum width that could be covered by the | 55 * This should return the maximum width that could be covered by the |
56 * image. | 56 * image. |
57 */ | 57 */ |
58 virtual unsigned int getWidth() const = 0; | 58 virtual unsigned int getWidth() const = 0; |
59 | 59 |
60 /** Returns the @b maximum height occupied by this image. | 60 /** Returns the @b maximum height occupied by this image. |
61 */ | 61 */ |
62 virtual unsigned int getHeight() const = 0; | 62 virtual unsigned int getHeight() const = 0; |
63 | 63 |
64 /** Gets the area of the image | 64 /** Gets the area of the image |
65 * @return Image area in rect | 65 * @return Image area in rect |
66 */ | 66 */ |
67 virtual const Rect& getArea() = 0; | 67 virtual const Rect& getArea() = 0; |
68 | 68 |
69 /** Writes pixel to given position. Returns true, if pixel was written (not out of bounds) | 69 /** Writes pixel to given position. Returns true, if pixel was written (not out of bounds) |
70 */ | 70 */ |
71 virtual bool putPixel(int x, int y, int r, int g, int b) = 0; | 71 virtual bool putPixel(int x, int y, int r, int g, int b) = 0; |
72 | 72 |
73 /** Draws line between given points with given RGBA | 73 /** Draws line between given points with given RGBA |
74 */ | 74 */ |
75 virtual void drawLine(const Point& p1, const Point& p2, int r, int g, int b) = 0; | 75 virtual void drawLine(const Point& p1, const Point& p2, int r, int g, int b) = 0; |
76 | 76 |
77 /** Draws quad between given points with given RGBA | 77 /** Draws quad between given points with given RGBA |
78 */ | 78 */ |
79 virtual void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b) = 0; | 79 virtual void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b) = 0; |
80 | 80 |
81 /** Draws a quad that represents a vertex with given RGBA | |
82 */ | |
83 virtual void drawVertex(const Point& p, const uint8_t size, int r, int g, int b) = 0; | |
84 | |
81 /** Returns pixel RGBA values from given position | 85 /** Returns pixel RGBA values from given position |
82 */ | 86 */ |
83 virtual void getPixelRGBA(int x, int y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) = 0; | 87 virtual void getPixelRGBA(int x, int y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) = 0; |
84 | 88 |
85 /** Pushes clip area to clip stack | 89 /** Pushes clip area to clip stack |
95 | 99 |
96 /** Gets the current clip area | 100 /** Gets the current clip area |
97 * @see pushClipArea | 101 * @see pushClipArea |
98 */ | 102 */ |
99 virtual const Rect& getClipArea() const = 0; | 103 virtual const Rect& getClipArea() const = 0; |
100 | 104 |
101 /** Saves the image using given filename | 105 /** Saves the image using given filename |
102 */ | 106 */ |
103 virtual void saveImage(const std::string& filename) = 0; | 107 virtual void saveImage(const std::string& filename) = 0; |
104 | 108 |
105 /** Enable or disable the alpha 'optimizing' code | 109 /** Enable or disable the alpha 'optimizing' code |
106 * | 110 * |
107 * @param optimize Wether the image shall be analysed for 'fake' alpha images. | 111 * @param optimize Wether the image shall be analysed for 'fake' alpha images. |
108 * Only implemented by and useful for the SDL backend at the moment. | 112 * Only implemented by and useful for the SDL backend at the moment. |
109 */ | 113 */ |
110 virtual void setAlphaOptimizerEnabled(bool enabled) = 0; | 114 virtual void setAlphaOptimizerEnabled(bool enabled) = 0; |
111 | 115 |
112 /** @see setAlphaOptimizerEnabled | 116 /** @see setAlphaOptimizerEnabled |
113 */ | 117 */ |
114 virtual bool isAlphaOptimizerEnabled() = 0; | 118 virtual bool isAlphaOptimizerEnabled() = 0; |
115 }; | 119 }; |
116 | 120 |
117 /** Base Class for Images. | 121 /** Base Class for Images. |
118 */ | 122 */ |
119 class Image : public ResourceClass, public AbstractImage { | 123 class Image : public ResourceClass, public AbstractImage { |
120 public: | 124 public: |
121 /** Constructor. | 125 /** Constructor. |
143 * Convenience function | 147 * Convenience function |
144 * @param rect The position and clipping where to draw this image to. | 148 * @param rect The position and clipping where to draw this image to. |
145 * @param alpha The alpha value, with which to draw self. | 149 * @param alpha The alpha value, with which to draw self. |
146 */ | 150 */ |
147 void render(const Rect& rect, unsigned char alpha = 255); | 151 void render(const Rect& rect, unsigned char alpha = 255); |
148 | 152 |
149 /** Removes underlying SDL_Surface from the image (if exists) and returns this | 153 /** Removes underlying SDL_Surface from the image (if exists) and returns this |
150 * @note this effectively causes SDL_Surface not to be freed on destruction | 154 * @note this effectively causes SDL_Surface not to be freed on destruction |
151 */ | 155 */ |
152 SDL_Surface* detachSurface(); | 156 SDL_Surface* detachSurface(); |
153 | 157 |
154 virtual ~Image(); | 158 virtual ~Image(); |
155 SDL_Surface* getSurface() { return m_surface; } | 159 SDL_Surface* getSurface() { return m_surface; } |
156 unsigned int getWidth() const; | 160 unsigned int getWidth() const; |
157 unsigned int getHeight() const; | 161 unsigned int getHeight() const; |
158 const Rect& getArea(); | 162 const Rect& getArea(); |
168 void pushClipArea(const Rect& cliparea, bool clear=true); | 172 void pushClipArea(const Rect& cliparea, bool clear=true); |
169 void popClipArea(); | 173 void popClipArea(); |
170 const Rect& getClipArea() const; | 174 const Rect& getClipArea() const; |
171 void setAlphaOptimizerEnabled(bool enabled) { m_isalphaoptimized = enabled; } | 175 void setAlphaOptimizerEnabled(bool enabled) { m_isalphaoptimized = enabled; } |
172 bool isAlphaOptimizerEnabled() { return m_isalphaoptimized; } | 176 bool isAlphaOptimizerEnabled() { return m_isalphaoptimized; } |
173 | 177 |
174 protected: | 178 protected: |
175 /** Sets given clip area into image | 179 /** Sets given clip area into image |
176 * @see pushClipArea | 180 * @see pushClipArea |
177 */ | 181 */ |
178 virtual void setClipArea(const Rect& cliparea, bool clear) = 0; | 182 virtual void setClipArea(const Rect& cliparea, bool clear) = 0; |
180 virtual void saveAsPng(const std::string& filename, SDL_Surface& surface); | 184 virtual void saveAsPng(const std::string& filename, SDL_Surface& surface); |
181 /** Clears any possible clip areas | 185 /** Clears any possible clip areas |
182 * @see pushClipArea | 186 * @see pushClipArea |
183 */ | 187 */ |
184 virtual void clearClipArea(); | 188 virtual void clearClipArea(); |
185 | 189 |
186 // The SDL Surface used. | 190 // The SDL Surface used. |
187 SDL_Surface* m_surface; | 191 SDL_Surface* m_surface; |
188 // The X shift of the Image | 192 // The X shift of the Image |
189 int m_xshift; | 193 int m_xshift; |
190 // The Y shift of the Image | 194 // The Y shift of the Image |
194 public: | 198 public: |
195 Rect r; | 199 Rect r; |
196 bool clearing; | 200 bool clearing; |
197 }; | 201 }; |
198 std::stack<ClipInfo> m_clipstack; | 202 std::stack<ClipInfo> m_clipstack; |
199 | 203 |
200 // image area | 204 // image area |
201 Rect m_area; | 205 Rect m_area; |
202 bool m_isalphaoptimized; | 206 bool m_isalphaoptimized; |
203 | 207 |
204 private: | 208 private: |
205 void reset(SDL_Surface* surface); | 209 void reset(SDL_Surface* surface); |
206 }; | 210 }; |
207 | 211 |
208 } | 212 } |