src/asfont.cpp |
173 | 173 | return getTextWidth(text.c_str()); |
174 | 174 | } |
175 | 175 | |
176 | | void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) { |
| 176 | void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign) { |
177 | 177 | switch (halign) { |
178 | 178 | case HAlignLeft: |
179 | 179 | break; |
... | ... | |
184 | 184 | x -= getTextWidth(text); |
185 | 185 | break; |
186 | 186 | } |
| 187 | write(surface, text, x, y); |
| 188 | } |
187 | 189 | |
| 190 | void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) { |
188 | 191 | switch (valign) { |
189 | 192 | case VAlignTop: |
190 | 193 | break; |
... | ... | |
195 | 198 | y -= getHeight(); |
196 | 199 | break; |
197 | 200 | } |
198 | | |
199 | | write(surface, text, x, y); |
| 201 | write(surface, text, x, y, halign); |
200 | 202 | } |
| 203 | |
201 | 204 | void ASFont::write(SDL_Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign) { |
202 | 205 | switch (valign) { |
203 | 206 | case VAlignTop: |
... | ... | |
211 | 214 | } |
212 | 215 | |
213 | 216 | for (std::vector<std::string>::const_iterator it = text.begin(); it != text.end(); ++it) { |
214 | | int ix = x; |
215 | | switch (halign) { |
216 | | case HAlignLeft: |
217 | | break; |
218 | | case HAlignCenter: |
219 | | ix -= getTextWidth(*it) / 2; |
220 | | break; |
221 | | case HAlignRight: |
222 | | ix -= getTextWidth(*it); |
223 | | break; |
224 | | } |
225 | | |
226 | | write(surface, *it, ix, y); |
| 217 | write(surface, *it, x, y, halign); |
227 | 218 | y += getHeight(); |
228 | 219 | } |
229 | 220 | } |
src/asfont.h |
35 | 35 | void write(Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop); |
36 | 36 | |
37 | 37 | private: |
38 | | void write(SDL_Surface *s, const std::string &text, int x, int y); |
39 | | void write(SDL_Surface *surface, const std::string& text, int x, int y, HAlign halign, VAlign valign); |
40 | | void write(SDL_Surface *surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign); |
41 | 38 | Uint32 getPixel(Sint32 x, Sint32 y); |
| 39 | void write(SDL_Surface *surface, const std::string &text, int x, int y); |
| 40 | void write(SDL_Surface *surface, const std::string &text, int x, int y, HAlign halign); |
| 41 | void write(SDL_Surface *surface, const std::string &text, int x, int y, HAlign halign, VAlign valign); |
| 42 | void write(SDL_Surface *surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign); |
42 | 43 | |
43 | 44 | SDL_Surface *surface; |
44 | 45 | std::vector<unsigned> charpos; |