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/LogDialog.h>
22 #include <dialogs/QuitDialog.h>
23 #include <GLW/GLWTextButton.h>
24 #include <GLW/GLWWindowManager.h>
25 #include <GLEXT/GLViewPort.h>
26 #include <graph/OptionsDisplay.h>
27 #include <common/Logger.h>
28 
29 LogDialog *LogDialog::instance_ = 0;
30 
instance()31 LogDialog *LogDialog::instance()
32 {
33 	if (!instance_)
34 	{
35 		instance_ = new LogDialog;
36 	}
37 	return instance_;
38 }
39 
LogDialog()40 LogDialog::LogDialog() :
41 	GLWWindow("Log", 10.0f, 10.0f, 300.0f, 240.0f, 0,
42 		"Log Window")
43 {
44 	needCentered_ = true;
45 	quit_ = (GLWTextButton *)
46 		addWidget(new GLWTextButton(LANG_RESOURCE("QUIT", "Quit"), 205, 10, 85, this,
47 		GLWButton::ButtonFlagCenterX));
48 	listView_ = (GLWListView *) addWidget(new GLWListView(10, 40, 280, 140, 100));
49 	serverName_ = (GLWLabel *) addWidget(new GLWLabel(5, 195, LANG_RESOURCE("LOCAL", "Local")));
50 
51 	// Add this class as a log handler
52 	Logger::addLogger(this);
53 }
54 
~LogDialog()55 LogDialog::~LogDialog()
56 {
57 }
58 
logMessage(LoggerInfo & info)59 void LogDialog::logMessage(LoggerInfo &info)
60 {
61 	listView_->addLine(info.getMessage());
62 	listView_->endPosition();
63 }
64 
draw()65 void LogDialog::draw()
66 {
67 	float wWidth = (float) GLViewPort::getWidth();
68 	float width = wWidth - 40.0f;
69 	if (width < 320) width = 320;
70 	if (width > 640) width = 640;
71 	setW(width - 20);
72 	listView_->setW(width - 40);
73 	quit_->setX(width - 115);
74 
75 	float wHeight = (float) GLViewPort::getHeight();
76 	float height = wHeight - 40.0f;
77 	if (height < 200) height = 200;
78 	if (height > 300) height = 300;
79 	serverName_->setY(height - 50);
80 	listView_->setH(height - 90);
81 	setH(height - 20);
82 
83 	GLWWindow::draw();
84 }
85 
buttonDown(unsigned int id)86 void LogDialog::buttonDown(unsigned int id)
87 {
88 	if (id == quit_->getId())
89 	{
90 		GLWWindowManager::instance()->
91 			showWindow(QuitDialog::instance()->getId());
92 	}
93 }
94