Date:2011-05-10 02:43:15 (12 years 10 months ago)
Author:Maarten ter Huurne
Commit:bff04d241807d559ac21840439985bc48fa57c68
Message:ASFont: removed duplication of horizontal alignment code.

Files: src/asfont.cpp (4 diffs)
src/asfont.h (1 diff)

Change Details

src/asfont.cpp
173173    return getTextWidth(text.c_str());
174174}
175175
176void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) {
176void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign) {
177177    switch (halign) {
178178    case HAlignLeft:
179179        break;
...... 
184184        x -= getTextWidth(text);
185185        break;
186186    }
187    write(surface, text, x, y);
188}
187189
190void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) {
188191    switch (valign) {
189192    case VAlignTop:
190193        break;
...... 
195198        y -= getHeight();
196199        break;
197200    }
198
199    write(surface, text, x, y);
201    write(surface, text, x, y, halign);
200202}
203
201204void ASFont::write(SDL_Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign) {
202205    switch (valign) {
203206    case VAlignTop:
...... 
211214    }
212215
213216    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);
227218        y += getHeight();
228219    }
229220}
src/asfont.h
3535    void write(Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
3636
3737private:
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);
4138    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);
4243
4344    SDL_Surface *surface;
4445    std::vector<unsigned> charpos;

Archive Download the corresponding diff file



interactive