~flosoft/s25rttr/trunk

« back to all changes in this revision

Viewing changes to src/ctrlPercent.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: ctrlPercent.cpp 7521 2011-09-08 20:45:55Z FloSoft $
 
1
// $Id: ctrlPercent.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
///////////////////////////////////////////////////////////////////////////////
36
36
 *
37
37
 *  @author OLiver
38
38
 */
39
 
ctrlPercent::ctrlPercent(Window *parent, 
40
 
                                                 unsigned int id,
41
 
                                                 unsigned short x,
42
 
                                                 unsigned short y,
43
 
                                                 unsigned short width,
44
 
                                                 unsigned short height, 
45
 
                                                 TextureColor tc, 
46
 
                                                 unsigned int text_color, 
47
 
                                                 glArchivItem_Font *font,
48
 
                                                 const unsigned short *percentage)
49
 
        : Window(x, y, id, parent, width, height),
50
 
        tc(tc), text_color(text_color), font(font), percentage(percentage)
 
39
ctrlPercent::ctrlPercent(Window* parent,
 
40
                         unsigned int id,
 
41
                         unsigned short x,
 
42
                         unsigned short y,
 
43
                         unsigned short width,
 
44
                         unsigned short height,
 
45
                         TextureColor tc,
 
46
                         unsigned int text_color,
 
47
                         glArchivItem_Font* font,
 
48
                         const unsigned short* percentage)
 
49
    : Window(x, y, id, parent, width, height),
 
50
      tc(tc), text_color(text_color), font(font), percentage(percentage)
51
51
{
52
52
}
53
53
 
61
61
 */
62
62
bool ctrlPercent::Draw_(void)
63
63
{
64
 
        // Wenn der Prozentsatzpointer = 0, dann wird 0 angezeigt und es soll nich abst�rzen!
65
 
        unsigned short percentage = (this->percentage ?  *this->percentage : 0);
66
 
 
67
 
        // Farbe herausfinden
68
 
        unsigned int color = 0xFFFF0000;
69
 
 
70
 
        if(percentage > 100)
71
 
                percentage = 100;
72
 
 
73
 
        // Farbe w�hlen je nachdem wie viel Prozent
74
 
        if(percentage >= 60)
75
 
                color = 0xFF00E000;
76
 
        else if(percentage >= 30)
77
 
                color = 0xFFFFFF00;
78
 
        else if(percentage >= 20)
79
 
                color = 0xFFFF8000;
80
 
 
81
 
        // Box zeichnen
82
 
        Draw3D(GetX(), GetY(), width, height, tc, 2);
83
 
 
84
 
        // Fortschritt zeichnen
85
 
        DrawRectangle(GetX()+4, GetY()+4, (width-8)*percentage/100, height-8, color);
86
 
 
87
 
        // Text zeichnen
88
 
        char caption[256];
89
 
        sprintf(caption,"%u%%",percentage);
90
 
        font->Draw(GetX() + width/2, GetY() + height/2, caption, glArchivItem_Font::DF_CENTER | glArchivItem_Font::DF_VCENTER, text_color);
91
 
 
92
 
        return true;
 
64
    // Wenn der Prozentsatzpointer = 0, dann wird 0 angezeigt und es soll nich abst�rzen!
 
65
    unsigned short percentage = (this->percentage ?  *this->percentage : 0);
 
66
 
 
67
    // Farbe herausfinden
 
68
    unsigned int color = 0xFFFF0000;
 
69
 
 
70
    if(percentage > 100)
 
71
        percentage = 100;
 
72
 
 
73
    // Farbe w�hlen je nachdem wie viel Prozent
 
74
    if(percentage >= 60)
 
75
        color = 0xFF00E000;
 
76
    else if(percentage >= 30)
 
77
        color = 0xFFFFFF00;
 
78
    else if(percentage >= 20)
 
79
        color = 0xFFFF8000;
 
80
 
 
81
    // Box zeichnen
 
82
    Draw3D(GetX(), GetY(), width, height, tc, 2);
 
83
 
 
84
    // Fortschritt zeichnen
 
85
    DrawRectangle(GetX() + 4, GetY() + 4, (width - 8)*percentage / 100, height - 8, color);
 
86
 
 
87
    // Text zeichnen
 
88
    char caption[256];
 
89
    sprintf(caption, "%u%%", percentage);
 
90
    font->Draw(GetX() + width / 2, GetY() + height / 2, caption, glArchivItem_Font::DF_CENTER | glArchivItem_Font::DF_VCENTER, text_color);
 
91
 
 
92
    return true;
93
93
}