Date: | 2011-06-02 04:29:19 (12 years 9 months ago) |
---|---|
Author: | Maarten ter Huurne |
Commit: | b2896d6bac3d8f0180ba8c0febdbb0bbf8554458 |
Message: | ASFont: Refactored string drawing methods. Renamed methods that draw a single line from write() to writeLine(). There is now only one write() method left: the public method. Pass surface to draw on as wrapped Surface instead of SDL_Surface. At the end of the call chain we still use SDL directly though. |
Files: |
src/asfont.cpp (6 diffs) src/asfont.h (1 diff) |
Change Details
src/asfont.cpp | ||
---|---|---|
100 | 100 | //return c>=194; |
101 | 101 | } |
102 | 102 | |
103 | void ASFont::write(SDL_Surface *s, const std::string &text, int x, int y) { | |
103 | void ASFont::writeLine(Surface *s, const std::string &text, int x, int y) { | |
104 | 104 | if (text.empty()) return; |
105 | 105 | |
106 | 106 | std::string::size_type pos; |
... | ... | |
129 | 129 | srcrect.w = charpos[pos+2] - charpos[pos]; |
130 | 130 | dstrect.x = x - charpos[pos+1] + charpos[pos]; |
131 | 131 | |
132 | SDL_BlitSurface(surface, &srcrect, s, &dstrect); | |
132 | SDL_BlitSurface(surface, &srcrect, s->raw, &dstrect); | |
133 | 133 | |
134 | 134 | x += charpos[pos+2] - charpos[pos+1]; |
135 | 135 | } |
... | ... | |
165 | 165 | return getTextWidth(text.c_str()); |
166 | 166 | } |
167 | 167 | |
168 | void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign) { | |
168 | void ASFont::writeLine(Surface* surface, const std::string& text, int x, int y, HAlign halign) { | |
169 | 169 | switch (halign) { |
170 | 170 | case HAlignLeft: |
171 | 171 | break; |
... | ... | |
176 | 176 | x -= getTextWidth(text); |
177 | 177 | break; |
178 | 178 | } |
179 | write(surface, text, x, y); | |
179 | writeLine(surface, text, x, y); | |
180 | 180 | } |
181 | 181 | |
182 | void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) { | |
182 | void ASFont::writeLine(Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) { | |
183 | 183 | switch (valign) { |
184 | 184 | case VAlignTop: |
185 | 185 | break; |
... | ... | |
190 | 190 | y -= getHeight(); |
191 | 191 | break; |
192 | 192 | } |
193 | write(surface, text, x, y, halign); | |
193 | writeLine(surface, text, x, y, halign); | |
194 | 194 | } |
195 | 195 | |
196 | void ASFont::write(SDL_Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign) { | |
196 | void ASFont::writeLine(Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign) { | |
197 | 197 | switch (valign) { |
198 | 198 | case VAlignTop: |
199 | 199 | break; |
... | ... | |
215 | 215 | if (text.find("\n", 0) != std::string::npos) { |
216 | 216 | std::vector<std::string> textArr; |
217 | 217 | split(textArr, text, "\n"); |
218 | write(surface->raw, textArr, x, y, halign, valign); | |
218 | writeLine(surface, textArr, x, y, halign, valign); | |
219 | 219 | } else |
220 | write(surface->raw, text, x, y, halign, valign); | |
220 | writeLine(surface, text, x, y, halign, valign); | |
221 | 221 | } |
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 *surface, const std::string &text, int x, int y); | |
39 | void write(SDL_Surface *surface, const std::string &text, int x, int y, HAlign halign); | |
40 | void write(SDL_Surface *surface, const std::string &text, int x, int y, HAlign halign, VAlign valign); | |
41 | void write(SDL_Surface *surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign); | |
38 | void writeLine(Surface *surface, const std::string &text, int x, int y); | |
39 | void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign); | |
40 | void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign, VAlign valign); | |
41 | void writeLine(Surface *surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign); | |
42 | 42 | |
43 | 43 | SDL_Surface *surface; |
44 | 44 | std::vector<unsigned> charpos; |
Branches:
install_locations
master
opkrun
packages