1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #include <dialogs/MsgBoxDialog.h>
22 #include <GLW/GLWWindowManager.h>
23 
24 MsgBoxDialog *MsgBoxDialog::instance_ = 0;
25 
instance()26 MsgBoxDialog *MsgBoxDialog::instance()
27 {
28 	if (!instance_)
29 	{
30 		instance_ = new MsgBoxDialog;
31 	}
32 	return instance_;
33 }
34 
MsgBoxDialog()35 MsgBoxDialog::MsgBoxDialog() :
36 	GLWWindow("MsgBox", 210.0f, 150.0f, eHideName, "")
37 {
38 	GLWPanel *topPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
39 
40 	icon_ = new GLWIcon(0.0f, 0.0f, 32.0f, 32.0f);
41 	topPanel->addWidget(icon_, 0, SpaceLeft | SpaceTop | AlignTop, 10.0f);
42 
43 	message_ = new GLWLabel(0.0f, 0.0f, LANG_STRING(""), 8.0f, GLWLabel::eMultiLine);
44 	topPanel->addWidget(message_, 0, SpaceTop | SpaceLeft | SpaceRight | AlignCenterLeftRight, 10.0f);
45 
46 	topPanel->setLayout(GLWPanel::LayoutHorizontal);
47 	addWidget(topPanel);
48 
49 	okButton_ = (GLWTextButton *)
50 		addWidget(new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this,
51 		GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagOk |
52 		GLWButton::ButtonFlagCenterX), 0, SpaceAll | AlignRight, 10.0f);
53 	okButton_->setToolTip(new ToolTip(ToolTip::ToolTipHelp,
54 		LANG_RESOURCE("CANCEL", "Cancel"),
55 		LANG_RESOURCE("CANCEL_TOOLTIP", "Return to the game.")));
56 
57 	windowLevel_ = 1000;
58 
59 	setLayout(GLWPanel::LayoutVerticle);
60 	layout();
61 }
62 
~MsgBoxDialog()63 MsgBoxDialog::~MsgBoxDialog()
64 {
65 
66 }
67 
show(const LangString & message,ShowType type)68 void MsgBoxDialog::show(const LangString &message, ShowType type)
69 {
70 	if (type == eError)
71 	{
72 		instance()->icon_->setTextureImage(
73 			ImageID(S3D::eDataLocation,
74 			"data/images/exclaim.bmp",
75 			"data/images/mask.bmp"));
76 	}
77 	else
78 	{
79 		instance()->icon_->setTextureImage(
80 			ImageID(S3D::eDataLocation,
81 			"data/images/ok.bmp",
82 			"data/images/mask.bmp"));
83 	}
84 
85 	instance()->message_->setText(message);
86 	instance()->message_->calcWidth();
87 	instance()->layout();
88 
89 	GLWWindowManager::instance()->showWindow(instance()->getId());
90 }
91 
buttonDown(unsigned int id)92 void MsgBoxDialog::buttonDown(unsigned int id)
93 {
94 	if (id == okButton_->getId())
95 	{
96 		GLWWindowManager::instance()->hideWindow(id_);
97 	}
98 }
99 
mouseDown(int button,float x,float y,bool & skipRest)100 void MsgBoxDialog::mouseDown(int button, float x, float y, bool &skipRest)
101 {
102 	GLWWindow::mouseDown(button, x, y, skipRest);
103 	skipRest = true;
104 }
105 
mouseUp(int button,float x,float y,bool & skipRest)106 void MsgBoxDialog::mouseUp(int button, float x, float y, bool &skipRest)
107 {
108 	GLWWindow::mouseUp(button, x,y, skipRest);
109 	skipRest = true;
110 }
111 
keyDown(char * buffer,unsigned int keyState,KeyboardHistory::HistoryElement * history,int hisCount,bool & skipRest)112 void MsgBoxDialog::keyDown(char *buffer, unsigned int keyState,
113 		KeyboardHistory::HistoryElement *history, int hisCount,
114 		bool &skipRest)
115 {
116 	GLWWindow::keyDown(buffer, keyState, history, hisCount, skipRest);
117 	skipRest = true;
118 }
119 
mouseWheel(float x,float y,float z,bool & skipRest)120 void MsgBoxDialog::mouseWheel(float x, float y, float z, bool &skipRest)
121 {
122 	GLWWindow::mouseWheel(x, y, z, skipRest);
123 	skipRest = true;
124 }
125 
126