~flosoft/s25rttr/trunk

« back to all changes in this revision

Viewing changes to src/ctrlProgress.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: ctrlProgress.cpp 8209 2012-09-10 14:55:39Z marcus $
 
1
// $Id: ctrlProgress.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
//
28
28
///////////////////////////////////////////////////////////////////////////////
29
29
// Makros / Defines
30
30
#if defined _WIN32 && defined _DEBUG && defined _MSC_VER
31
 
        #define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
32
 
        #undef THIS_FILE
33
 
        static char THIS_FILE[] = __FILE__;
 
31
#define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
 
32
#undef THIS_FILE
 
33
static char THIS_FILE[] = __FILE__;
34
34
#endif
35
35
 
36
36
///////////////////////////////////////////////////////////////////////////////
40
40
 *  @author Devil
41
41
 *  @author FloSoft
42
42
 */
43
 
ctrlProgress::ctrlProgress(Window *parent, 
44
 
                                                   const unsigned int id,
45
 
                                                   const unsigned short x, 
46
 
                                                   const unsigned short y, 
47
 
                                                   const unsigned short width,
48
 
                                                   const unsigned short height,
49
 
                                                   const TextureColor tc, 
50
 
                                                        unsigned short button_minus, 
51
 
                                                   unsigned short button_plus,  
52
 
                                                   const unsigned short maximum,
53
 
                                                   const unsigned short x_padding,
54
 
                                                   const unsigned short y_padding,
55
 
                                                   const unsigned int force_color,
56
 
                                                   const std::string& tooltip,
57
 
                                                   const std::string& button_minus_tooltip,
58
 
                                                   const std::string& button_plus_tooltip,
59
 
                                                   unsigned short * const write_val)
60
 
        : Window(x, y, id, parent, width, height, tooltip),
61
 
        tc(tc), position(0), maximum(maximum), x_padding(x_padding), y_padding(y_padding), force_color(force_color)
 
43
ctrlProgress::ctrlProgress(Window* parent,
 
44
                           const unsigned int id,
 
45
                           const unsigned short x,
 
46
                           const unsigned short y,
 
47
                           const unsigned short width,
 
48
                           const unsigned short height,
 
49
                           const TextureColor tc,
 
50
                           unsigned short button_minus,
 
51
                           unsigned short button_plus,
 
52
                           const unsigned short maximum,
 
53
                           const unsigned short x_padding,
 
54
                           const unsigned short y_padding,
 
55
                           const unsigned int force_color,
 
56
                           const std::string& tooltip,
 
57
                           const std::string& button_minus_tooltip,
 
58
                           const std::string& button_plus_tooltip,
 
59
                           unsigned short* const write_val)
 
60
    : Window(x, y, id, parent, width, height, tooltip),
 
61
      tc(tc), position(0), maximum(maximum), x_padding(x_padding), y_padding(y_padding), force_color(force_color)
62
62
{
63
 
        const char * str1 = "io", * str2 = "io";
64
 
        if(button_minus >= 1000)
65
 
        {
66
 
                str1 = "io_new";
67
 
                button_minus -= 1000;
68
 
        }
69
 
        if(button_plus >= 1000)
70
 
        {
71
 
                str2 = "io_new";
72
 
                button_plus -= 1000;
73
 
        }
74
 
        
75
 
        AddImageButton(0, 0,              0, height, height, tc, LOADER.GetImageN(str1, button_minus), (button_minus_tooltip.length() ? button_minus_tooltip : _("Less")) );
76
 
        AddImageButton(1, width - height, 0, height, height, tc, LOADER.GetImageN(str2, button_plus),  (button_plus_tooltip.length( ) ? button_plus_tooltip  : _("More")) );
 
63
    const char* str1 = "io", * str2 = "io";
 
64
    if(button_minus >= 1000)
 
65
    {
 
66
        str1 = "io_new";
 
67
        button_minus -= 1000;
 
68
    }
 
69
    if(button_plus >= 1000)
 
70
    {
 
71
        str2 = "io_new";
 
72
        button_plus -= 1000;
 
73
    }
 
74
 
 
75
    AddImageButton(0, 0,              0, height, height, tc, LOADER.GetImageN(str1, button_minus), (button_minus_tooltip.length() ? button_minus_tooltip : _("Less")) );
 
76
    AddImageButton(1, width - height, 0, height, height, tc, LOADER.GetImageN(str2, button_plus),  (button_plus_tooltip.length( ) ? button_plus_tooltip  : _("More")) );
77
77
}
78
78
 
79
79
///////////////////////////////////////////////////////////////////////////////
85
85
 */
86
86
void ctrlProgress::SetPosition(unsigned short position)
87
87
{
88
 
        this->position = (position > maximum ? maximum : position);
 
88
    this->position = (position > maximum ? maximum : position);
89
89
}
90
90
 
91
91
///////////////////////////////////////////////////////////////////////////////
98
98
 */
99
99
bool ctrlProgress::Draw_(void)
100
100
{
101
 
        Draw3D(GetX() + height - 2 + x_padding, GetY() + y_padding, width - (height*2) + 4 - 2*x_padding, height - 2*y_padding, tc, 2);
102
 
 
103
 
        // Buttons
104
 
        DrawControls();
105
 
 
106
 
        unsigned int percentage = position * 100 / maximum;
107
 
        unsigned int progress = (width - height*2 - 4 - 2*x_padding) * position / maximum;
108
 
 
109
 
        // Farbe herausfinden
110
 
        unsigned int color = 0xFFFF0000;
111
 
 
112
 
        // Feste Farbe?
113
 
        if(force_color)
114
 
                color = force_color;
115
 
        else
116
 
        {
117
 
                // Farbe w�hlen je nachdem wie viel Prozent
118
 
                if(percentage >= 60)
119
 
                        color = 0xFF00E000;
120
 
                else if(percentage >= 30)
121
 
                        color = 0xFFFFFF00;
122
 
                else if(percentage >= 20)
123
 
                        color = 0xFFFF8000;
124
 
        }
125
 
 
126
 
        // Leiste
127
 
        DrawRectangle(GetX() + height + 2 + x_padding, GetY() + 4 + y_padding, progress, height -8 - 2*y_padding, color);
128
 
 
129
 
        // Prozentzahlen zeichnen
130
 
        std::stringstream percent;
131
 
        percent << percentage << "%";
132
 
        SmallFont->Draw(GetX() + (width / 2), GetY() + height / 2, percent.str(), glArchivItem_Font::DF_VCENTER|glArchivItem_Font::DF_CENTER, COLOR_YELLOW);
133
 
 
134
 
        return true;
 
101
    Draw3D(GetX() + height - 2 + x_padding, GetY() + y_padding, width - (height * 2) + 4 - 2 * x_padding, height - 2 * y_padding, tc, 2);
 
102
 
 
103
    // Buttons
 
104
    DrawControls();
 
105
 
 
106
    unsigned int percentage = position * 100 / maximum;
 
107
    unsigned int progress = (width - height * 2 - 4 - 2 * x_padding) * position / maximum;
 
108
 
 
109
    // Farbe herausfinden
 
110
    unsigned int color = 0xFFFF0000;
 
111
 
 
112
    // Feste Farbe?
 
113
    if(force_color)
 
114
        color = force_color;
 
115
    else
 
116
    {
 
117
        // Farbe w�hlen je nachdem wie viel Prozent
 
118
        if(percentage >= 60)
 
119
            color = 0xFF00E000;
 
120
        else if(percentage >= 30)
 
121
            color = 0xFFFFFF00;
 
122
        else if(percentage >= 20)
 
123
            color = 0xFFFF8000;
 
124
    }
 
125
 
 
126
    // Leiste
 
127
    DrawRectangle(GetX() + height + 2 + x_padding, GetY() + 4 + y_padding, progress, height - 8 - 2 * y_padding, color);
 
128
 
 
129
    // Prozentzahlen zeichnen
 
130
    std::stringstream percent;
 
131
    percent << percentage << "%";
 
132
    SmallFont->Draw(GetX() + (width / 2), GetY() + height / 2, percent.str(), glArchivItem_Font::DF_VCENTER | glArchivItem_Font::DF_CENTER, COLOR_YELLOW);
 
133
 
 
134
    return true;
135
135
}
136
136
 
137
137
///////////////////////////////////////////////////////////////////////////////
138
138
/**
139
 
 *  
 
139
 *
140
140
 *
141
141
 *  @author OLiver
142
142
 */
143
143
void ctrlProgress::Msg_ButtonClick(const unsigned int ctrl_id)
144
144
{
145
 
        switch(ctrl_id)
 
145
    switch(ctrl_id)
146
146
    {
147
 
        case 0: // Minus
148
 
                {
149
 
                        if(position)
150
 
                                --position;
151
 
                        if(parent)
152
 
                                parent->Msg_ProgressChange(GetID(), position);
153
 
                } break;
154
 
        case 1: // Plus
155
 
                {
156
 
                        if(position < maximum)
157
 
                                ++position;
158
 
                        if(parent)
159
 
                                parent->Msg_ProgressChange(GetID(), position);
160
 
                } break;
161
 
        }
 
147
        case 0: // Minus
 
148
        {
 
149
            if(position)
 
150
                --position;
 
151
            if(parent)
 
152
                parent->Msg_ProgressChange(GetID(), position);
 
153
        } break;
 
154
        case 1: // Plus
 
155
        {
 
156
            if(position < maximum)
 
157
                ++position;
 
158
            if(parent)
 
159
                parent->Msg_ProgressChange(GetID(), position);
 
160
        } break;
 
161
    }
162
162
}
163
163
 
164
164
///////////////////////////////////////////////////////////////////////////////
165
165
/**
166
 
 *  
 
166
 *
167
167
 *
168
168
 *  @author OLiver
169
169
 */
170
170
bool ctrlProgress::Msg_LeftDown(const MouseCoords& mc)
171
171
{
172
 
        // Test if clicked on progress bar
173
 
        if(Coll(mc.x, mc.y, 
174
 
                GetX() + height + 2 + x_padding, GetY() + 4 + y_padding, 
175
 
                width - height*2 - 4 - 2*x_padding, height - 8 - 2*y_padding))
176
 
        {
177
 
                // The additional check for (position > maximum) is
178
 
                // mathematically redundant here; if there was more code than 
179
 
                // it in SetPosition() we had to call it here instead of simply:
180
 
                position = ( mc.x - (GetX() + height + 2 + x_padding) 
181
 
                             + /*rounding:*/ (width - height*2 - 4 - 2*x_padding) / maximum / 2)
182
 
                           * maximum / (width - height*2 - 4 - 2*x_padding);
 
172
    // Test if clicked on progress bar
 
173
    if(Coll(mc.x, mc.y,
 
174
            GetX() + height + 2 + x_padding, GetY() + 4 + y_padding,
 
175
            width - height * 2 - 4 - 2 * x_padding, height - 8 - 2 * y_padding))
 
176
    {
 
177
        // The additional check for (position > maximum) is
 
178
        // mathematically redundant here; if there was more code than
 
179
        // it in SetPosition() we had to call it here instead of simply:
 
180
        position = ( mc.x - (GetX() + height + 2 + x_padding)
 
181
                     + /*rounding:*/ (width - height * 2 - 4 - 2 * x_padding) / maximum / 2)
 
182
                   * maximum / (width - height * 2 - 4 - 2 * x_padding);
183
183
 
184
 
                if(parent) parent->Msg_ProgressChange(GetID(), position);
185
 
                return true;
186
 
        }
187
 
        else
188
 
                return RelayMouseMessage(&Window::Msg_LeftDown, mc);
 
184
        if(parent) parent->Msg_ProgressChange(GetID(), position);
 
185
        return true;
 
186
    }
 
187
    else
 
188
        return RelayMouseMessage(&Window::Msg_LeftDown, mc);
189
189
}
190
190
 
191
191
///////////////////////////////////////////////////////////////////////////////
192
192
/**
193
 
 *  
 
193
 *
194
194
 *
195
195
 *  @author OLiver
196
196
 */
197
197
bool ctrlProgress::Msg_LeftUp(const MouseCoords& mc)
198
198
{
199
 
        return RelayMouseMessage(&Window::Msg_LeftUp, mc);
 
199
    return RelayMouseMessage(&Window::Msg_LeftUp, mc);
200
200
}
201
201
 
202
202
///////////////////////////////////////////////////////////////////////////////
203
203
/**
204
 
 *  
 
204
 *
205
205
 *
206
206
 *  @author Divan
207
207
 */
208
208
bool ctrlProgress::Msg_WheelUp(const MouseCoords& mc)
209
209
{
210
 
        // If mouse is over the controls, simulate button click
211
 
        if(Coll(mc.x,mc.y,GetX(),GetY(), width, height))
212
 
        {
213
 
                Msg_ButtonClick(1);
214
 
                return true;
215
 
        }
216
 
        return false;
 
210
    // If mouse is over the controls, simulate button click
 
211
    if(Coll(mc.x, mc.y, GetX(), GetY(), width, height))
 
212
    {
 
213
        Msg_ButtonClick(1);
 
214
        return true;
 
215
    }
 
216
    return false;
217
217
}
218
218
 
219
219
///////////////////////////////////////////////////////////////////////////////
220
220
/**
221
 
 *  
 
221
 *
222
222
 *
223
223
 *  @author Divan
224
224
 */
225
225
bool ctrlProgress::Msg_WheelDown(const MouseCoords& mc)
226
226
{
227
 
        // If mouse is over the controls, simulate button click
228
 
        if(Coll(mc.x,mc.y,GetX(),GetY(), width, height))
229
 
        {
230
 
                Msg_ButtonClick(0);
231
 
                return true;
232
 
        }
233
 
        return false;
 
227
    // If mouse is over the controls, simulate button click
 
228
    if(Coll(mc.x, mc.y, GetX(), GetY(), width, height))
 
229
    {
 
230
        Msg_ButtonClick(0);
 
231
        return true;
 
232
    }
 
233
    return false;
234
234
}
235
235
 
236
236
///////////////////////////////////////////////////////////////////////////////
237
237
/**
238
 
 *  
 
238
 *
239
239
 *
240
240
 *  @author OLiver
241
241
 */
242
242
bool ctrlProgress::Msg_MouseMove(const MouseCoords& mc)
243
243
{
244
 
        // an Buttons weiterleiten
245
 
        RelayMouseMessage(&Window::Msg_MouseMove, mc);
 
244
    // an Buttons weiterleiten
 
245
    RelayMouseMessage(&Window::Msg_MouseMove, mc);
246
246
 
247
 
        if(Coll(mc.x, mc.y, GetX() + height + x_padding, GetY(), width - height*2 - x_padding*2, height))
248
 
        {
249
 
                WindowManager::inst().SetToolTip(this, tooltip);
250
 
                return true;
251
 
        }
252
 
        else
253
 
        {
254
 
                WindowManager::inst().SetToolTip(this, "");
255
 
                return false;
256
 
        }
 
247
    if(Coll(mc.x, mc.y, GetX() + height + x_padding, GetY(), width - height * 2 - x_padding * 2, height))
 
248
    {
 
249
        WindowManager::inst().SetToolTip(this, tooltip);
 
250
        return true;
 
251
    }
 
252
    else
 
253
    {
 
254
        WindowManager::inst().SetToolTip(this, "");
 
255
        return false;
 
256
    }
257
257
}