summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp127
-rw-r--r--src/gui/gui.h37
-rw-r--r--src/gui/setup.cpp44
-rw-r--r--src/gui/setup.h24
4 files changed, 163 insertions, 69 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 37e5daff..ce8f428b 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -30,6 +30,7 @@
#include "../engine.h"
#include "../game.h"
#include "../log.h"
+#include "../resources/resourcemanager.h"
extern Being* autoTarget;
@@ -46,7 +47,10 @@ gcn::ImageFont *hitYellowFont;
// Font used to display speech and player names
gcn::ImageFont *speechFont;
-Gui::Gui(Graphics *graphics)
+Gui::Gui(Graphics *graphics):
+ mHostImageLoader(NULL),
+ mMouseCursor(NULL),
+ mCustomCursor(false)
{
// Set graphics
guiGraphics = graphics;
@@ -59,18 +63,17 @@ Gui::Gui(Graphics *graphics)
// Set image loader
#ifdef USE_OPENGL
if (useOpenGL) {
- hostImageLoader = new gcn::SDLImageLoader();
- imageLoader = new gcn::OpenGLImageLoader(hostImageLoader);
+ mHostImageLoader = new gcn::SDLImageLoader();
+ mImageLoader = new gcn::OpenGLImageLoader(mHostImageLoader);
}
else {
- hostImageLoader = NULL;
- imageLoader = new gcn::SDLImageLoader();
+ mImageLoader = new gcn::SDLImageLoader();
}
#else
- imageLoader = new gcn::SDLImageLoader();
+ mImageLoader = new gcn::SDLImageLoader();
#endif
- gcn::Image::setImageLoader(imageLoader);
+ gcn::Image::setImageLoader(mImageLoader);
// Set focus handler
delete mFocusHandler;
@@ -86,7 +89,7 @@ Gui::Gui(Graphics *graphics)
// Set global font
try {
- guiFont = new gcn::ImageFont(
+ mGuiFont = new gcn::ImageFont(
TMW_DATADIR "data/graphics/gui/sansserif8.png",
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ["
"\\]^_`abcdefghijklmnopqrstuvwxyz{|}~|"
@@ -95,7 +98,7 @@ Gui::Gui(Graphics *graphics)
catch (gcn::Exception e)
{
try {
- guiFont = new gcn::ImageFont(
+ mGuiFont = new gcn::ImageFont(
"data/graphics/gui/sansserif8.png",
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVW"
"XYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~|"
@@ -130,7 +133,7 @@ Gui::Gui(Graphics *graphics)
}
}
- gcn::Widget::setGlobalFont(guiFont);
+ gcn::Widget::setGlobalFont(mGuiFont);
// Load hits' colourful fonts
try {
@@ -146,22 +149,26 @@ Gui::Gui(Graphics *graphics)
}
catch (gcn::Exception e)
{
- try {
- hitRedFont = new gcn::ImageFont(
- "data/graphics/gui/hits_red.png",
- "0123456789");
- hitBlueFont = new gcn::ImageFont(
- "data/graphics/gui/hits_blue.png",
- "0123456789");
- hitYellowFont = new gcn::ImageFont(
- "data/graphics/gui/hits_yellow.png",
- "mis");
- }
- catch (gcn::Exception e)
- {
- logger->error("Unable to load colored hits' fonts!");
- }
+ try {
+ hitRedFont = new gcn::ImageFont(
+ "data/graphics/gui/hits_red.png",
+ "0123456789");
+ hitBlueFont = new gcn::ImageFont(
+ "data/graphics/gui/hits_blue.png",
+ "0123456789");
+ hitYellowFont = new gcn::ImageFont(
+ "data/graphics/gui/hits_yellow.png",
+ "mis");
+ }
+ catch (gcn::Exception e)
+ {
+ logger->error("Unable to load colored hits' fonts!");
+ }
}
+
+ // Initialize mouse cursor and listen for changes to the option
+ setUseCustomCursor(config.getValue("customcursor", 1) == 1);
+ config.addListener("customcursor", this);
}
Gui::~Gui()
@@ -171,14 +178,18 @@ Gui::~Gui()
delete hitBlueFont;
delete hitYellowFont;
- delete guiFont;
+ if (mMouseCursor) {
+ mMouseCursor->decRef();
+ }
+
+ delete mGuiFont;
delete guiTop;
- delete imageLoader;
-#ifdef USE_OPENGL
- if (hostImageLoader) {
- delete hostImageLoader;
+ delete mImageLoader;
+
+ if (mHostImageLoader) {
+ delete mHostImageLoader;
}
-#endif
+
delete guiInput;
}
@@ -194,7 +205,18 @@ void Gui::logic()
void Gui::draw()
{
guiGraphics->pushClipArea(guiTop->getDimension());
+
guiTop->draw(guiGraphics);
+
+ int mouseX, mouseY;
+ Uint8 button = SDL_GetMouseState(&mouseX, &mouseY);
+
+ if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1))
+ && mCustomCursor)
+ {
+ mMouseCursor->draw(screen, mouseX - 5, mouseY - 2);
+ }
+
guiGraphics->popClipArea();
}
@@ -219,9 +241,48 @@ void Gui::mousePress(int mx, int my, int button)
}
}
-
gcn::ImageFont *Gui::getFont()
{
- return guiFont;
+ return mGuiFont;
+}
+
+void
+Gui::setUseCustomCursor(bool customCursor)
+{
+ if (customCursor != mCustomCursor)
+ {
+ mCustomCursor = customCursor;
+
+ if (mCustomCursor)
+ {
+ // Hide the SDL mouse cursor
+ SDL_ShowCursor(SDL_DISABLE);
+
+ // Load the mouse cursor
+ ResourceManager *resman = ResourceManager::getInstance();
+ mMouseCursor = resman->getImage("graphics/gui/mouse.png");
+ if (!mMouseCursor) {
+ logger->error("Unable to load mouse cursor.");
+ }
+ }
+ else
+ {
+ // Show the SDL mouse cursor
+ SDL_ShowCursor(SDL_ENABLE);
+
+ // Unload the mouse cursor
+ if (mMouseCursor) {
+ mMouseCursor->decRef();
+ mMouseCursor = NULL;
+ }
+ }
+ }
}
+void
+Gui::optionChanged(const std::string &name)
+{
+ if (name == "customcursor") {
+ setUseCustomCursor(config.getValue("customcursor", 1) == 1);
+ }
+}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index dfd72ec7..02ea7caa 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -28,6 +28,7 @@
#include <guichan/sdl.hpp>
#include "windowcontainer.h"
#include "../graphics.h"
+#include "../configuration.h"
/**
* \defgroup GUI Core GUI related classes (widgets)
@@ -42,7 +43,7 @@
*
* \ingroup GUI
*/
-class Gui : public gcn::Gui, public gcn::MouseListener
+class Gui : public gcn::Gui, public gcn::MouseListener, ConfigListener
{
public:
/**
@@ -58,30 +59,46 @@ class Gui : public gcn::Gui, public gcn::MouseListener
/**
* Works around Guichan bug
*/
- void logic();
+ void
+ logic();
/**
* Draws the whole Gui by calling draw functions down in the
* Gui hierarchy. It also draws the mouse pointer.
*/
- void draw();
+ void
+ draw();
/**
* Handles mouse press on map.
*/
- void mousePress(int mx, int my, int button);
+ void
+ mousePress(int mx, int my, int button);
/**
* Return game font
*/
- gcn::ImageFont *getFont();
+ gcn::ImageFont*
+ getFont();
+
+ /**
+ * Sets whether a custom cursor should be rendered.
+ */
+ void
+ setUseCustomCursor(bool customCursor);
+
+ /**
+ * ConfigListener method.
+ */
+ void
+ optionChanged(const std::string &name);
private:
-#ifdef USE_OPENGL
- gcn::ImageLoader *hostImageLoader; /**< For loading images in GL */
-#endif
- gcn::ImageLoader *imageLoader; /**< For loading images */
- gcn::ImageFont *guiFont; /**< The global GUI font */
+ gcn::ImageLoader *mHostImageLoader; /**< For loading images in GL */
+ gcn::ImageLoader *mImageLoader; /**< For loading images */
+ gcn::ImageFont *mGuiFont; /**< The global GUI font */
+ Image *mMouseCursor; /**< Mouse cursor image */
+ bool mCustomCursor; /**< Show custom cursor */
};
extern Gui *gui; /**< The GUI system */
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index a1c1f500..a9421874 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -88,6 +88,7 @@ Setup::Setup():
fsCheckBox = new CheckBox("Full screen", false);
openGlCheckBox = new CheckBox("OpenGL", false);
openGlCheckBox->setEnabled(false);
+ customCursorCheckBox = new CheckBox("Custom cursor");
alphaLabel = new gcn::Label("Gui opacity");
alphaSlider = new Slider(0.2, 1.0);
audioLabel = new gcn::Label("Audio settings");
@@ -105,28 +106,32 @@ Setup::Setup():
alphaSlider->setEventId("guialpha");
sfxSlider->setEventId("sfx");
musicSlider->setEventId("music");
+ customCursorCheckBox->setEventId("customcursor");
// Set dimensions/positions
- setContentSize(SETUP_WIDTH, 216);
+ setContentSize(SETUP_WIDTH, 226);
+
videoLabel->setPosition(SETUP_WIDTH - videoLabel->getWidth() - 5, 10);
scrollArea->setDimension(gcn::Rectangle(10, 30, 90, 50));
modeList->setDimension(gcn::Rectangle(0, 0, 60, 50));
fsCheckBox->setPosition(110, 30);
openGlCheckBox->setPosition(110, 50);
- alphaSlider->setDimension(gcn::Rectangle(10, 90, 100, 10));
- alphaLabel->setPosition(20 + alphaSlider->getWidth(), 87);
- audioLabel->setPosition(SETUP_WIDTH - videoLabel->getWidth() - 5, 110);
- soundCheckBox->setPosition(10, 130);
- sfxSlider->setDimension(gcn::Rectangle(10, 150, 100, 10));
- musicSlider->setDimension(gcn::Rectangle(10, 170, 100, 10));
- sfxLabel->setPosition(20 + sfxSlider->getWidth(), 147);
- musicLabel->setPosition(20 + musicSlider->getWidth(), 167);
+ customCursorCheckBox->setPosition(110, 70);
+ alphaSlider->setDimension(gcn::Rectangle(10, 100, 100, 10));
+ alphaLabel->setPosition(20 + alphaSlider->getWidth(), 97);
+
+ audioLabel->setPosition(SETUP_WIDTH - videoLabel->getWidth() - 5, 120);
+ soundCheckBox->setPosition(10, 140);
+ sfxSlider->setDimension(gcn::Rectangle(10, 160, 100, 10));
+ musicSlider->setDimension(gcn::Rectangle(10, 180, 100, 10));
+ sfxLabel->setPosition(20 + sfxSlider->getWidth(), 157);
+ musicLabel->setPosition(20 + musicSlider->getWidth(), 177);
cancelButton->setPosition(
SETUP_WIDTH - 5 - cancelButton->getWidth(),
- 216 - 5 - cancelButton->getHeight());
+ 226 - 5 - cancelButton->getHeight());
applyButton->setPosition(
cancelButton->getX() - 5 - applyButton->getWidth(),
- 216 - 5 - applyButton->getHeight());
+ 226 - 5 - applyButton->getHeight());
// Listen for actions
applyButton->addActionListener(this);
@@ -134,31 +139,33 @@ Setup::Setup():
alphaSlider->addActionListener(this);
sfxSlider->addActionListener(this);
musicSlider->addActionListener(this);
+ customCursorCheckBox->addActionListener(this);
// Assemble dialog
add(videoLabel);
add(scrollArea);
add(fsCheckBox);
add(openGlCheckBox);
+ add(customCursorCheckBox);
add(audioLabel);
add(soundCheckBox);
- add(applyButton);
- add(cancelButton);
add(alphaSlider);
add(alphaLabel);
add(sfxSlider);
add(musicSlider);
add(sfxLabel);
add(musicLabel);
+ add(applyButton);
+ add(cancelButton);
setLocationRelativeTo(getParent());
// Load default settings
modeList->setSelected(-1);
- if (config.getValue("screen", 0) == 1) {
- fsCheckBox->setMarked(true);
- }
+
+ fsCheckBox->setMarked(config.getValue("screen", 0));
soundCheckBox->setMarked(config.getValue("sound", 0));
+ customCursorCheckBox->setMarked(config.getValue("customcursor", 1));
alphaSlider->setValue(config.getValue("guialpha", 0.8));
sfxSlider->setValue(config.getValue("sfxVolume", 100));
musicSlider->setValue(config.getValue("musicVolume", 60));
@@ -198,6 +205,11 @@ void Setup::action(const std::string &eventId)
{
config.setValue("guialpha", alphaSlider->getValue());
}
+ else if (eventId == "customcursor")
+ {
+ config.setValue("customcursor",
+ customCursorCheckBox->isMarked() ? 1 : 0);
+ }
else if (eventId == "apply")
{
setVisible(false);
diff --git a/src/gui/setup.h b/src/gui/setup.h
index 30eda305..02eebae1 100644
--- a/src/gui/setup.h
+++ b/src/gui/setup.h
@@ -31,7 +31,8 @@
*
* \ingroup Interface
*/
-class ModeListModel : public gcn::ListModel {
+class ModeListModel : public gcn::ListModel
+{
public:
/**
* Constructor.
@@ -62,25 +63,27 @@ class ModeListModel : public gcn::ListModel {
*
* \ingroup GUI
*/
-class Setup : public Window, public gcn::ActionListener {
+class Setup : public Window, public gcn::ActionListener
+{
private:
+ ModeListModel *modeListModel;
+
// Dialog widgets
- gcn::Label *videoLabel, *audioLabel;
gcn::ListBox *modeList;
- ModeListModel *modeListModel;
gcn::ScrollArea *scrollArea;
+ gcn::Label *videoLabel, *audioLabel;
+ gcn::Label *alphaLabel;
+ gcn::Label *sfxLabel, *musicLabel;
gcn::CheckBox *fsCheckBox;
gcn::CheckBox *openGlCheckBox;
- gcn::Slider *alphaSlider;
- gcn::Label *alphaLabel;
gcn::CheckBox *soundCheckBox;
+ gcn::CheckBox *customCursorCheckBox;
+ gcn::Slider *alphaSlider;
gcn::Slider *sfxSlider, *musicSlider;
- gcn::Label *sfxLabel, *musicLabel;
gcn::Button *applyButton;
gcn::Button *cancelButton;
- public:
-
+ public:
/**
* Constructor.
*/
@@ -94,7 +97,8 @@ class Setup : public Window, public gcn::ActionListener {
/**
* Event handling method.
*/
- void action(const std::string& eventId);
+ void
+ action(const std::string& eventId);
};