~flosoft/s25rttr/trunk

« back to all changes in this revision

Viewing changes to src/ctrlVarText.cpp

  • Committer: FloSoft
  • Date: 2014-04-25 15:35:50 UTC
  • Revision ID: flosoft@siedler25.org-20140425153550-9muu4vodhlqu58m0
committing subversion revision 9357 by FloSoft
astyle

modified:
s25client/trunk/
s25client/trunk/contrib/lua/lin32/include/
s25client/trunk/contrib/lua/lin64/include/
s25client/trunk/contrib/lua/mac/include/
s25client/trunk/contrib/lua/win32/include/
s25client/trunk/contrib/lua/win64/include/
s25client/trunk/driver/audio/SDL/src/
s25client/trunk/driver/src/
s25client/trunk/driver/video/GLFW/src/
s25client/trunk/driver/video/SDL/src/
s25client/trunk/driver/video/WinAPI/src/
s25client/trunk/src/
s25client/trunk/win32/
s25client/trunk/win32/prebuild-mutex/src/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: ctrlVarText.cpp 7521 2011-09-08 20:45:55Z FloSoft $
 
1
// $Id: ctrlVarText.cpp 9357 2014-04-25 15:35:25Z FloSoft $
2
2
//
3
3
// Copyright (c) 2005 - 2011 Settlers Freaks (sf-team at siedler25.org)
4
4
//
25
25
///////////////////////////////////////////////////////////////////////////////
26
26
// Makros / Defines
27
27
#if defined _WIN32 && defined _DEBUG && defined _MSC_VER
28
 
        #define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
29
 
        #undef THIS_FILE
30
 
        static char THIS_FILE[] = __FILE__;
 
28
#define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
 
29
#undef THIS_FILE
 
30
static char THIS_FILE[] = __FILE__;
31
31
#endif
32
32
 
33
33
///////////////////////////////////////////////////////////////////////////////
47
47
 *
48
48
 *  @author FloSoft
49
49
 */
50
 
ctrlVarText::ctrlVarText(Window *parent, 
51
 
                                                 unsigned int id, 
52
 
                                                 unsigned short x, 
53
 
                                                 unsigned short y, 
54
 
                                                 const std::string& formatstr, 
55
 
                                                 unsigned int color, 
56
 
                                                 unsigned int format, 
57
 
                                                 glArchivItem_Font *font,
58
 
                                                 unsigned int count,
59
 
                                                 va_list liste)
60
 
        : ctrlText(parent, id, x, y, formatstr, color, format, font)
 
50
ctrlVarText::ctrlVarText(Window* parent,
 
51
                         unsigned int id,
 
52
                         unsigned short x,
 
53
                         unsigned short y,
 
54
                         const std::string& formatstr,
 
55
                         unsigned int color,
 
56
                         unsigned int format,
 
57
                         glArchivItem_Font* font,
 
58
                         unsigned int count,
 
59
                         va_list liste)
 
60
    : ctrlText(parent, id, x, y, formatstr, color, format, font)
61
61
{
62
 
        // Pointerliste einlesen
63
 
        if(count > 0)
64
 
        {
65
 
                // Pointerliste anlegen
66
 
                vars = new void*[count];
 
62
    // Pointerliste einlesen
 
63
    if(count > 0)
 
64
    {
 
65
        // Pointerliste anlegen
 
66
        vars = new void*[count];
67
67
 
68
 
                // und zuweisen
69
 
                for(unsigned int i = 0; i < count; ++i)
70
 
                        vars[i] = va_arg(liste, void*);
71
 
        }
 
68
        // und zuweisen
 
69
        for(unsigned int i = 0; i < count; ++i)
 
70
            vars[i] = va_arg(liste, void*);
 
71
    }
72
72
}
73
73
 
74
74
///////////////////////////////////////////////////////////////////////////////
79
79
 */
80
80
ctrlVarText::~ctrlVarText()
81
81
{
82
 
        // Pointerliste aufr�umen
83
 
        delete[] vars;
 
82
    // Pointerliste aufr�umen
 
83
    delete[] vars;
84
84
}
85
85
 
86
86
///////////////////////////////////////////////////////////////////////////////
93
93
 */
94
94
bool ctrlVarText::Draw_(void)
95
95
{
96
 
        char buffer[1025];
97
 
 
98
 
        for(unsigned int i = 0, j = 0, k = 0; i < text.length() && j < 1024; ++i)
99
 
        {
100
 
                if(text[i] == '%')
101
 
                {
102
 
                        ++i;
103
 
                        char temp[1025];
104
 
                        switch(text[i])
105
 
                        {
106
 
                        case 'd':
107
 
                        case 'u':
108
 
                                {
109
 
                                        snprintf(temp, 1024, (text[i]=='d') ? "%d" : "%u", *(int*)vars[k++]);
110
 
                                        for(unsigned int x = 0; x < strlen(temp); ++x)
111
 
                                                buffer[j++] = temp[x];
112
 
                                } break;
113
 
                        case 's':
114
 
                                {
115
 
                                        snprintf(temp, 1024, "%s", (char*)vars[k++]);
116
 
                                        for(unsigned int x = 0; x < strlen(temp); ++x)
117
 
                                                buffer[j++] = temp[x];
118
 
                                } break;
119
 
                        default:
120
 
                                {
121
 
                                        buffer[j++] = text[i-1];
122
 
                                        buffer[j++] = text[i];
123
 
                                } break;
124
 
                        }
125
 
                }
126
 
                else
127
 
                        buffer[j++] = text[i];
128
 
                buffer[j] = '\0';
129
 
        }
130
 
        // variablen Inhalt erzeugen
131
 
        //vsnprintf(buffer, 1024, text, *(va_list*)&vars);
132
 
 
133
 
        // letzte byte nullen (safety, vsnprintf schreibt bei zu gro�em string kein null-terminator)
134
 
        buffer[1024] = '\0';
135
 
 
136
 
        // und zeichnen
137
 
        font->Draw( GetX(), GetY(), buffer, format, color);
138
 
 
139
 
        return true;
 
96
    char buffer[1025];
 
97
 
 
98
    for(unsigned int i = 0, j = 0, k = 0; i < text.length() && j < 1024; ++i)
 
99
    {
 
100
        if(text[i] == '%')
 
101
        {
 
102
            ++i;
 
103
            char temp[1025];
 
104
            switch(text[i])
 
105
            {
 
106
                case 'd':
 
107
                case 'u':
 
108
                {
 
109
                    snprintf(temp, 1024, (text[i] == 'd') ? "%d" : "%u", *(int*)vars[k++]);
 
110
                    for(unsigned int x = 0; x < strlen(temp); ++x)
 
111
                        buffer[j++] = temp[x];
 
112
                } break;
 
113
                case 's':
 
114
                {
 
115
                    snprintf(temp, 1024, "%s", (char*)vars[k++]);
 
116
                    for(unsigned int x = 0; x < strlen(temp); ++x)
 
117
                        buffer[j++] = temp[x];
 
118
                } break;
 
119
                default:
 
120
                {
 
121
                    buffer[j++] = text[i - 1];
 
122
                    buffer[j++] = text[i];
 
123
                } break;
 
124
            }
 
125
        }
 
126
        else
 
127
            buffer[j++] = text[i];
 
128
        buffer[j] = '\0';
 
129
    }
 
130
    // variablen Inhalt erzeugen
 
131
    //vsnprintf(buffer, 1024, text, *(va_list*)&vars);
 
132
 
 
133
    // letzte byte nullen (safety, vsnprintf schreibt bei zu gro�em string kein null-terminator)
 
134
    buffer[1024] = '\0';
 
135
 
 
136
    // und zeichnen
 
137
    font->Draw( GetX(), GetY(), buffer, format, color);
 
138
 
 
139
    return true;
140
140
}