xoreos  0.0.5
okcancel.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/engines/aurora/gui.h"
26 
30 
32 
33 namespace Engines {
34 
35 namespace NWN {
36 
38  const Common::UString &ok, const Common::UString &cancel,
39  ::Engines::Console *console) : GUI(console),
40  _msg(msg), _ok(ok), _cancel(cancel) {
41 
42  load("okcancelpanel");
43 }
44 
46 }
47 
49  if (widget.getTag() == "MessageLabel") {
50  dynamic_cast<WidgetLabel &>(widget).setText(_msg);
51  return;
52  }
53 
54  if (widget.getTag() == "OkButton") {
55  if (!_ok.empty())
56  dynamic_cast<WidgetButton &>(widget).setText(_ok);
57  return;
58  }
59 
60  if (widget.getTag() == "CancelButton") {
61  if (!_cancel.empty())
62  dynamic_cast<WidgetButton &>(widget).setText(_cancel);
63  return;
64  }
65 }
66 
68  // Center the message
69  WidgetLabel &msg = *getLabel("MessageLabel", true);
70  WidgetPanel &pnl = *getPanel("PNL_OK" , true);
71 
72  float pX, pY, pZ;
73  pnl.getPosition(pX, pY, pZ);
74 
75  msg.setPosition(pX - msg.getWidth() / 2.0f, pY - msg.getHeight() / 2.0f, pZ - 1.0f);
76 
77  GUI::show();
78 }
79 
81  if (widget.getTag() == "OkButton") {
82  _returnCode = 1;
83  return;
84  }
85 
86  if (widget.getTag() == "CancelButton") {
87  _returnCode = 2;
88  return;
89  }
90 
91 }
92 
93 } // End of namespace NWN
94 
95 } // End of namespace Engines
A NWN panel widget.
Definition: panel.h:41
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: okcancel.cpp:80
A NWN button widget.
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
A class holding an UTF-8 string.
Definition: ustring.h:48
virtual void getPosition(float &x, float &y, float &z) const
Get the widget&#39;s position.
Definition: widget.cpp:140
OKCancelDialog(const Common::UString &msg, const Common::UString &ok="", const Common::UString &cancel="", ::Engines::Console *console=0)
Definition: okcancel.cpp:37
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Common::UString _msg
Definition: okcancel.h:52
void initWidget(Widget &widget)
Definition: okcancel.cpp:48
A GUI.
virtual void show()
Show the GUI.
Definition: gui.cpp:62
WidgetLabel * getLabel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:270
A NWN GUI.
Definition: gui.h:54
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
WidgetPanel * getPanel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:258
void load(const Common::UString &resref)
Definition: gui.cpp:77
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
Common::UString _cancel
Definition: okcancel.h:55
A NWN label widget.
Definition: label.h:41
float getHeight() const
Get the widget&#39;s height.
Definition: label.cpp:88
void show()
Show the GUI.
Definition: okcancel.cpp:67
A widget in a GUI.
Definition: widget.h:40
Common::UString _ok
Definition: okcancel.h:54
float getWidth() const
Get the widget&#39;s width.
Definition: label.cpp:84
The okay/cancel dialog.
A NWN panel widget.
A NWN label widget.
void setText(const Common::UString &text)
Definition: label.cpp:67