~flosoft/s25rttr/trunk

« back to all changes in this revision

Viewing changes to src/iwMsgbox.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: iwMsgbox.cpp 8865 2013-08-24 21:56:19Z marcus $
 
1
// $Id: iwMsgbox.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
//
30
30
///////////////////////////////////////////////////////////////////////////////
31
31
// Makros / Defines
32
32
#if defined _WIN32 && defined _DEBUG && defined _MSC_VER
33
 
        #define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
34
 
        #undef THIS_FILE
35
 
        static char THIS_FILE[] = __FILE__;
 
33
#define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
 
34
#undef THIS_FILE
 
35
static char THIS_FILE[] = __FILE__;
36
36
#endif
37
37
 
38
38
///////////////////////////////////////////////////////////////////////////////
41
41
 *
42
42
 *  @author OLiver
43
43
 */
44
 
iwMsgbox::iwMsgbox(const std::string& title, const std::string& text, Window *parent, MsgboxButton button, unsigned short icon, unsigned int msgboxid)
45
 
        : IngameWindow(CGI_MSGBOX, 0xFFFF, 0xFFFF, 420, 140, title, LOADER.GetImageN("resource", 41), true), parent(parent), button(button), msgboxid(msgboxid), text(text)
 
44
iwMsgbox::iwMsgbox(const std::string& title, const std::string& text, Window* parent, MsgboxButton button, unsigned short icon, unsigned int msgboxid)
 
45
    : IngameWindow(CGI_MSGBOX, 0xFFFF, 0xFFFF, 420, 140, title, LOADER.GetImageN("resource", 41), true), parent(parent), button(button), msgboxid(msgboxid), text(text)
46
46
{
47
 
        AddImage(0, 42, 42, LOADER.GetImageN("io", icon));
48
 
        //ctrlMultiline *multiline = AddMultiline(1, 77, 34, 400, 90, TC_GREEN2, NormalFont);
49
 
        //multiline->AddText(text, COLOR_YELLOW);
50
 
        /*AddText(1, 80, 30, text, COLOR_YELLOW, 0, NormalFont);*/
51
 
 
52
 
        // Umbrechungsinformationen vom Text holen
53
 
        glArchivItem_Font::WrapInfo wi;
54
 
        NormalFont->GetWrapInfo(text,330,330,wi);
55
 
        // Einzelne Zeilen-Strings erzeugen
56
 
        strings = new std::string[wi.positions.size()];
57
 
        wi.CreateSingleStrings(text,strings);
58
 
        lines_count = wi.positions.size();
59
 
 
60
 
        // Buttons erstellen
61
 
        switch(button)
62
 
        {
63
 
        case MSB_OK:
64
 
                {
65
 
                        AddButton(0, width / 2 - 45, _("OK"), TC_GREEN2);
66
 
                        VideoDriverWrapper::inst().SetMousePos(GetX() + width / 2, GetY() + 110);
67
 
                } break;
68
 
 
69
 
        case MSB_OKCANCEL:
70
 
                {
71
 
                        AddButton(0, width / 2 - 3 - 90, _("OK"), TC_GREEN2);
72
 
                        AddButton(1, width / 2 + 3, _("Cancel"), TC_RED1);
73
 
                        VideoDriverWrapper::inst().SetMousePos(GetX() + width / 2 + 3 + 45, GetY() + 110);
74
 
                } break;
75
 
 
76
 
        case MSB_YESNO:
77
 
                {
78
 
                        AddButton(0, width / 2 - 3 - 90, _("Yes"), TC_GREEN2);
79
 
                        AddButton(1, width / 2 + 3, _("No"), TC_RED1);
80
 
                        VideoDriverWrapper::inst().SetMousePos(GetX() + width / 2 + 3 + 45, GetY() + 110);
81
 
                } break;
82
 
 
83
 
        case MSB_YESNOCANCEL:
84
 
                {
85
 
                        AddButton(0, width / 2 - 45 - 6 - 90, _("Yes"), TC_GREEN2);
86
 
                        AddButton(1, width / 2 - 45, _("No"), TC_RED1);
87
 
                        AddButton(2, width / 2 + 45 + 6, _("Cancel"), TC_GREY);
88
 
                        VideoDriverWrapper::inst().SetMousePos(GetX() + width / 2 + 6 + 90, GetY() + 110);
89
 
                } break;
90
 
        }
 
47
    AddImage(0, 42, 42, LOADER.GetImageN("io", icon));
 
48
    //ctrlMultiline *multiline = AddMultiline(1, 77, 34, 400, 90, TC_GREEN2, NormalFont);
 
49
    //multiline->AddText(text, COLOR_YELLOW);
 
50
    /*AddText(1, 80, 30, text, COLOR_YELLOW, 0, NormalFont);*/
 
51
 
 
52
    // Umbrechungsinformationen vom Text holen
 
53
    glArchivItem_Font::WrapInfo wi;
 
54
    NormalFont->GetWrapInfo(text, 330, 330, wi);
 
55
    // Einzelne Zeilen-Strings erzeugen
 
56
    strings = new std::string[wi.positions.size()];
 
57
    wi.CreateSingleStrings(text, strings);
 
58
    lines_count = wi.positions.size();
 
59
 
 
60
    // Buttons erstellen
 
61
    switch(button)
 
62
    {
 
63
        case MSB_OK:
 
64
        {
 
65
            AddButton(0, width / 2 - 45, _("OK"), TC_GREEN2);
 
66
            VideoDriverWrapper::inst().SetMousePos(GetX() + width / 2, GetY() + 110);
 
67
        } break;
 
68
 
 
69
        case MSB_OKCANCEL:
 
70
        {
 
71
            AddButton(0, width / 2 - 3 - 90, _("OK"), TC_GREEN2);
 
72
            AddButton(1, width / 2 + 3, _("Cancel"), TC_RED1);
 
73
            VideoDriverWrapper::inst().SetMousePos(GetX() + width / 2 + 3 + 45, GetY() + 110);
 
74
        } break;
 
75
 
 
76
        case MSB_YESNO:
 
77
        {
 
78
            AddButton(0, width / 2 - 3 - 90, _("Yes"), TC_GREEN2);
 
79
            AddButton(1, width / 2 + 3, _("No"), TC_RED1);
 
80
            VideoDriverWrapper::inst().SetMousePos(GetX() + width / 2 + 3 + 45, GetY() + 110);
 
81
        } break;
 
82
 
 
83
        case MSB_YESNOCANCEL:
 
84
        {
 
85
            AddButton(0, width / 2 - 45 - 6 - 90, _("Yes"), TC_GREEN2);
 
86
            AddButton(1, width / 2 - 45, _("No"), TC_RED1);
 
87
            AddButton(2, width / 2 + 45 + 6, _("Cancel"), TC_GREY);
 
88
            VideoDriverWrapper::inst().SetMousePos(GetX() + width / 2 + 6 + 90, GetY() + 110);
 
89
        } break;
 
90
    }
91
91
}
92
92
 
93
93
iwMsgbox::~iwMsgbox()
94
94
{
95
 
        delete [] strings;
 
95
    delete [] strings;
96
96
}
97
97
 
98
98
 
99
99
const MsgboxResult RET_IDS[4][3] =
100
100
{
101
 
        {MSR_OK,  MSR_NOTHING, MSR_NOTHING},
102
 
        {MSR_OK,  MSR_CANCEL,  MSR_NOTHING},
103
 
        {MSR_YES, MSR_NO,      MSR_NOTHING},
104
 
        {MSR_YES, MSR_NO,      MSR_CANCEL}
 
101
    {MSR_OK,  MSR_NOTHING, MSR_NOTHING},
 
102
    {MSR_OK,  MSR_CANCEL,  MSR_NOTHING},
 
103
    {MSR_YES, MSR_NO,      MSR_NOTHING},
 
104
    {MSR_YES, MSR_NO,      MSR_CANCEL}
105
105
};
106
106
 
107
107
void iwMsgbox::Msg_ButtonClick(const unsigned int ctrl_id)
108
108
{
109
 
        if(parent)
110
 
                parent->Msg_MsgBoxResult(msgboxid,RET_IDS[button][ctrl_id-2]);
111
 
        Close();
 
109
    if(parent)
 
110
        parent->Msg_MsgBoxResult(msgboxid, RET_IDS[button][ctrl_id - 2]);
 
111
    Close();
112
112
}
113
113
 
114
114
void iwMsgbox::Msg_PaintAfter()
115
115
{
116
 
        // Text zeichnen
117
 
        for(unsigned i = 0;i<lines_count;++i)
118
 
                NormalFont->Draw(GetX()+80,GetY()+30+NormalFont->getHeight()*i,strings[i],glArchivItem_Font::DF_LEFT,0xFFFFFF00);
 
116
    // Text zeichnen
 
117
    for(unsigned i = 0; i < lines_count; ++i)
 
118
        NormalFont->Draw(GetX() + 80, GetY() + 30 + NormalFont->getHeight()*i, strings[i], glArchivItem_Font::DF_LEFT, 0xFFFFFF00);
119
119
}
120
120
 
121
121
void iwMsgbox::AddButton(unsigned short id, int x, const std::string& text, const TextureColor tc)
122
122
{
123
 
        Window::AddTextButton(2 + id, x, 100, 90, 20, tc, text,NormalFont);
 
123
    Window::AddTextButton(2 + id, x, 100, 90, 20, tc, text, NormalFont);
124
124
}