summaryrefslogtreecommitdiff
path: root/src/gui/gui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/gui.cpp')
-rw-r--r--src/gui/gui.cpp91
1 files changed, 53 insertions, 38 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index dc6306b4..1ef0219a 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -1,31 +1,30 @@
/*
* The Mana World
- * Copyright 2004 The Mana World Development Team
+ * Copyright (C) 2004 The Mana World Development Team
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
+ * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
- * The Mana World is distributed in the hope that it will be useful,
+ * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "gui.h"
-
#include <guichan/exception.hpp>
#include <guichan/image.hpp>
#include <guichan/imagefont.hpp>
#include "focushandler.h"
+#include "gui.h"
#include "sdlinput.h"
#include "truetypefont.h"
#include "viewport.h"
@@ -39,20 +38,21 @@
#include "../resources/image.h"
#include "../resources/imageset.h"
-#include "../resources/resourcemanager.h"
#include "../resources/imageloader.h"
+#include "../resources/resourcemanager.h"
// Guichan stuff
-Gui *gui;
-Viewport *viewport; /**< Viewport on the map. */
-SDLInput *guiInput;
+Gui *gui = 0;
+Viewport *viewport = 0; /**< Viewport on the map. */
+SDLInput *guiInput = 0;
// Fonts used in showing hits
-gcn::Font *hitRedFont;
-gcn::Font *hitBlueFont;
-gcn::Font *hitYellowFont;
-// Font used to display speech and player names
-gcn::Font *speechFont;
+gcn::Font *hitRedFont = 0;
+gcn::Font *hitBlueFont = 0;
+gcn::Font *hitYellowFont = 0;
+
+// Bolded font
+gcn::Font *boldFont = 0;
class GuiConfigListener : public ConfigListener
{
@@ -63,7 +63,8 @@ class GuiConfigListener : public ConfigListener
void optionChanged(const std::string &name)
{
- if (name == "customcursor") {
+ if (name == "customcursor")
+ {
bool bCustomCursor = config.getValue("customcursor", 1) == 1;
mGui->setUseCustomCursor(bCustomCursor);
}
@@ -96,7 +97,7 @@ Gui::Gui(Graphics *graphics):
mFocusHandler = new FocusHandler;
// Initialize top GUI widget
- WindowContainer *guiTop = new WindowContainer();
+ WindowContainer *guiTop = new WindowContainer;
guiTop->setDimension(gcn::Rectangle(0, 0,
graphics->getWidth(), graphics->getHeight()));
guiTop->setOpaque(false);
@@ -107,35 +108,48 @@ Gui::Gui(Graphics *graphics):
// Set global font
std::string path = resman->getPath(
- branding.getValue("guiFont","fonts/dejavusans.ttf"));
- if (!path.empty())
+ branding.getValue("font", "fonts/dejavusans.ttf"));
+ try
+ {
+ const int fontSize = (int)config.getValue("fontSize", 11);
+ mGuiFont = new TrueTypeFont(path, fontSize);
+ }
+ catch (gcn::Exception e)
{
- mGuiFont = new TrueTypeFont(path.c_str(), 11);
+ logger->error(std::string("Unable to load dejavusans.ttf: ")
+ + e.getMessage());
}
- // Set speech font
+ // Set bold font
path = resman->getPath(
- branding.getValue("speechFont","fonts/dejavusans.ttf"));
- if (!path.empty())
+ branding.getValue("boldFont", "fonts/dejavusans.ttf"));
+ try
{
- speechFont = new TrueTypeFont(path.c_str(), 11);
+ const int fontSize = (int)config.getValue("fontSize", 11);
+ boldFont = new TrueTypeFont(path, fontSize);
+ }
+ catch (gcn::Exception e)
+ {
+ logger->error(std::string("Unable to load dejavusans-bold.ttf: ")
+ + e.getMessage());
}
gcn::Widget::setGlobalFont(mGuiFont);
- // Load hits' colourful fonts
- try {
+ // Load hits' colorful fonts
+ try
+ {
hitRedFont = new gcn::ImageFont("graphics/gui/hits_red.png",
- "0123456789");
+ "0123456789crit! ");
hitBlueFont = new gcn::ImageFont("graphics/gui/hits_blue.png",
- "0123456789");
+ "0123456789crit! ");
hitYellowFont = new gcn::ImageFont("graphics/gui/hits_yellow.png",
"0123456789misxp ");
}
catch (gcn::Exception e)
{
- logger->log("Unable to load colored hits' fonts: %s", e.getMessage().c_str());
- throw;
+ logger->error(std::string("Unable to load colored hits' fonts: ")
+ + e.getMessage());
}
// Initialize mouse cursor and listen for changes to the option
@@ -144,7 +158,7 @@ Gui::Gui(Graphics *graphics):
config.addListener("customcursor", mConfigListener);
// Create the viewport
- viewport = new Viewport();
+ viewport = new Viewport;
viewport->setDimension(gcn::Rectangle(0, 0,
graphics->getWidth(), graphics->getHeight()));
guiTop->add(viewport);
@@ -164,7 +178,7 @@ Gui::~Gui()
mMouseCursors->decRef();
delete mGuiFont;
- delete speechFont;
+ delete boldFont;
delete viewport;
delete getTop();
@@ -174,12 +188,13 @@ Gui::~Gui()
void Gui::logic()
{
// Fade out mouse cursor after extended inactivity
- if (mMouseInactivityTimer < 100 * 15) {
+ if (mMouseInactivityTimer < 100 * 15)
+ {
++mMouseInactivityTimer;
mMouseCursorAlpha = std::min(1.0f, mMouseCursorAlpha + 0.05f);
- } else {
- mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f);
}
+ else
+ mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f);
gcn::Gui::logic();
}
@@ -224,9 +239,8 @@ void Gui::setUseCustomCursor(bool customCursor)
mMouseCursors =
resman->getImageSet("graphics/gui/mouse.png", 40, 40);
- if (!mMouseCursors) {
+ if (!mMouseCursors)
logger->error("Unable to load mouse cursors.");
- }
}
else
{
@@ -234,7 +248,8 @@ void Gui::setUseCustomCursor(bool customCursor)
SDL_ShowCursor(SDL_ENABLE);
// Unload the mouse cursor
- if (mMouseCursors) {
+ if (mMouseCursors)
+ {
mMouseCursors->decRef();
mMouseCursors = NULL;
}