~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/widgets/Quit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: Quit
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
// 
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
// 
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
 
22
//
 
23
#ifdef HAVE_CONFIG_H
 
24
#include "config.h"
 
25
#endif
 
26
 
 
27
#include "Quit.h"
 
28
// #include "../EmberOgre.h"
 
29
#include "main/Application.h"
 
30
#include <elements/CEGUIPushButton.h>
 
31
 
 
32
#include "framework/ConsoleBackend.h"
 
33
#include "../GUIManager.h"
 
34
#include "services/input/Input.h"
 
35
 
 
36
namespace EmberOgre {
 
37
namespace Gui {
 
38
 
 
39
Quit::Quit() : SoftQuit("softquit", this, "Display a quit confirmation window.")
 
40
{
 
41
}
 
42
 
 
43
 
 
44
Quit::~Quit()
 
45
{
 
46
}
 
47
 
 
48
void Quit::buildWidget()
 
49
{
 
50
        
 
51
        loadMainSheet("Quit.layout", "Quit/");
 
52
        
 
53
        Ember::Application::getSingleton().EventRequestQuit.connect(sigc::mem_fun(*this, &Quit::EmberOgre_RequestQuit));
 
54
        
 
55
        CEGUI::PushButton* yesButton = static_cast<CEGUI::PushButton*>(getWindow("YesButton"));
 
56
        CEGUI::PushButton* noButton = static_cast<CEGUI::PushButton*>(getWindow("NoButton"));
 
57
        
 
58
        if (yesButton) {
 
59
                BIND_CEGUI_EVENT(noButton, CEGUI::PushButton::EventClicked, Quit::No_Click );
 
60
        }
 
61
        if (noButton) {
 
62
                BIND_CEGUI_EVENT(yesButton, CEGUI::PushButton::EventClicked, Quit::Yes_Click );
 
63
        }
 
64
        
 
65
        registerConsoleVisibilityToggleCommand("quit");
 
66
        enableCloseButton();
 
67
        
 
68
        mMainWindow->setVisible(false);
 
69
}
 
70
 
 
71
bool Quit::Yes_Click(const CEGUI::EventArgs& args)
 
72
{
 
73
        Ember::Application::getSingleton().quit();
 
74
        return true;
 
75
}
 
76
 
 
77
bool Quit::No_Click(const CEGUI::EventArgs& args)
 
78
{
 
79
        mMainWindow->setVisible(false);
 
80
        return true;
 
81
}
 
82
 
 
83
 
 
84
void Quit::EmberOgre_RequestQuit(bool& handled) 
 
85
{
 
86
        handled = true;
 
87
        //if the window system twice requests a quit, do it
 
88
        if (mMainWindow->isVisible()) {
 
89
                Ember::Application::getSingleton().quit();
 
90
        } else {
 
91
                softquit();
 
92
        }
 
93
}
 
94
 
 
95
void Quit::softquit()
 
96
{
 
97
        mMainWindow->activate();
 
98
        mMainWindow->moveToFront();
 
99
        mMainWindow->setVisible(true);
 
100
        
 
101
        Ember::Input::getSingleton().setInputMode(Ember::Input::IM_GUI);
 
102
        //mMainWindow->setModalState(true);
 
103
}
 
104
 
 
105
void Quit::hide()
 
106
{
 
107
        //mMainWindow->setModalState(false);
 
108
}
 
109
 
 
110
 
 
111
void Quit::runCommand(const std::string &command, const std::string &args)
 
112
{
 
113
        if(SoftQuit == command)
 
114
        {
 
115
                softquit();
 
116
        } else {
 
117
                Widget::runCommand(command, args);
 
118
        }
 
119
 
 
120
}
 
121
}
 
122
};