summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/core/graphics/gui/mouse.pngbin206 -> 449 bytes
-rw-r--r--src/graphic/graphic.cpp16
-rw-r--r--src/graphic/graphic.h3
-rw-r--r--src/gui/char_select.cpp6
-rw-r--r--src/gui/char_server.cpp6
-rw-r--r--src/gui/login.cpp6
-rw-r--r--src/main.cpp9
-rw-r--r--src/resources/image.cpp11
-rw-r--r--src/resources/image.h7
-rw-r--r--src/resources/resource.h3
-rw-r--r--src/resources/resourcemanager.cpp12
-rw-r--r--src/resources/resourcemanager.h6
12 files changed, 68 insertions, 17 deletions
diff --git a/data/core/graphics/gui/mouse.png b/data/core/graphics/gui/mouse.png
index 75afbb6f..e6a84021 100644
--- a/data/core/graphics/gui/mouse.png
+++ b/data/core/graphics/gui/mouse.png
Binary files differ
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index d39338de..a0786e59 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -150,9 +150,20 @@ int get_y_offset(Being *being) {
}
-Graphics::Graphics()
+Graphics::Graphics():
+ mouseCursor(NULL)
{
setTarget(SDL_GetVideoSurface());
+
+ // Load the mouse cursor
+ ResourceManager *resman = ResourceManager::getInstance();
+ mouseCursor = resman->getImage("core/graphics/gui/mouse.png", IMG_ALPHA);
+ if (!mouseCursor) {
+ error("Unable to load mouse cursor.");
+ }
+
+ // Hide the system mouse cursor
+ SDL_ShowCursor(SDL_DISABLE);
}
Graphics::~Graphics() {
@@ -210,6 +221,9 @@ void Graphics::drawImageRect(
void Graphics::updateScreen()
{
+ // Draw mouse before flipping
+ mouseCursor->draw(screen, mouseX - 5, mouseY - 2);
+
SDL_Flip(screen);
}
diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h
index 0bae4327..3e4bc168 100644
--- a/src/graphic/graphic.h
+++ b/src/graphic/graphic.h
@@ -152,6 +152,9 @@ class Graphics : public gcn::SDLGraphics {
* screen or swapping pages.
*/
void updateScreen();
+
+ private:
+ Image *mouseCursor;
};
/**
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 5032b196..128fbf7c 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -441,6 +441,12 @@ void charSelect()
case SDL_QUIT:
state = EXIT;
break;
+
+ case SDL_MOUSEMOTION:
+ // Update the known mouse position
+ mouseX = event.motion.x;
+ mouseY = event.motion.y;
+ break;
}
guiInput->pushInput(event);
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index c0f1c523..781f4a37 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -126,6 +126,12 @@ void char_server() {
case SDL_QUIT:
state = EXIT;
break;
+
+ case SDL_MOUSEMOTION:
+ // Update the known mouse position
+ mouseX = event.motion.x;
+ mouseY = event.motion.y;
+ break;
}
guiInput->pushInput(event);
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 5496c01b..d0cfa899 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -147,6 +147,12 @@ void login() {
state = EXIT;
}
break;
+
+ case SDL_MOUSEMOTION:
+ // Update the known mouse position
+ mouseX = event.motion.x;
+ mouseY = event.motion.y;
+ break;
}
guiInput->pushInput(event);
diff --git a/src/main.cpp b/src/main.cpp
index 8944387a..7e67bafd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -59,7 +59,7 @@ unsigned char state;
unsigned short x, y;
unsigned char direction;
//unsigned short job, hair, hair_color;
-unsigned char stretch_mode, screen_mode;
+unsigned char screen_mode;
char *dir;
Sound sound;
@@ -176,7 +176,6 @@ void init_engine() {
#else
config.setValue("chatlog", "chatlog.txt");
#endif
- config.setValue("stretch", 1);
config.setValue("remember", 1);
config.setValue("username", "Player");
@@ -310,6 +309,12 @@ int main(int argc, char *argv[]) {
case SDL_QUIT:
state = EXIT;
break;
+
+ case SDL_MOUSEMOTION:
+ // Update the known mouse position
+ mouseX = event.motion.x;
+ mouseY = event.motion.y;
+ break;
}
guiInput->pushInput(event);
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 15ef6708..f84826bb 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -26,6 +26,7 @@
#include <iostream>
#include <SDL_image.h>
#include "../graphic/graphic.h"
+#include "resourcemanager.h"
Image::Image(SDL_Surface *image):
image(image)
@@ -37,7 +38,7 @@ Image::~Image()
unload();
}
-Image* Image::load(const std::string &filePath)
+Image* Image::load(const std::string &filePath, int flags)
{
#ifdef __DEBUG
std::cout << "Image::load(" << filePath << ")\n";
@@ -46,7 +47,13 @@ Image* Image::load(const std::string &filePath)
SDL_Surface *tmpImage = IMG_Load(filePath.c_str());
SDL_SetColorKey(tmpImage, SDL_SRCCOLORKEY | SDL_RLEACCEL,
SDL_MapRGB(tmpImage->format, 255, 0, 255));
- SDL_Surface *image = SDL_DisplayFormat(tmpImage);
+ SDL_Surface *image = NULL;
+ if (flags & IMG_ALPHA) {
+ image = SDL_DisplayFormatAlpha(tmpImage);
+ }
+ else {
+ image = SDL_DisplayFormat(tmpImage);
+ }
SDL_FreeSurface(tmpImage);
// Check if the file was opened and return the appropriate value.
diff --git a/src/resources/image.h b/src/resources/image.h
index 1c2b58cf..bed75983 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -27,6 +27,11 @@
#include "resource.h"
#include <SDL.h>
+// This flag causes image alpha channel to be preserved, otherwise masking is
+// used.
+#define IMG_ALPHA 1
+
+
// Forward declarations
class SubImage;
class ScaledImage;
@@ -53,7 +58,7 @@ class Image : public Resource
* @return <code>true</code> if the image was loaded
* <code>false</code> otherwise.
*/
- static Image *load(const std::string &filePath);
+ static Image *load(const std::string &filePath, int flags);
/**
* Frees the resources created by SDL.
diff --git a/src/resources/resource.h b/src/resources/resource.h
index f1252c12..bd6bfcc5 100644
--- a/src/resources/resource.h
+++ b/src/resources/resource.h
@@ -24,9 +24,6 @@
#ifndef _TMW_RESOURCE_H
#define _TMW_RESOURCE_H
-#include <string>
-//#include <SDL/SDL.h>
-
/**
* A generic reference counted resource object.
*/
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 0d936836..1a2c7a5f 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -21,9 +21,8 @@
* $Id$
*/
-#include "../log.h"
-#include "image.h"
#include "resourcemanager.h"
+#include "../log.h"
#include <iostream>
#include <sstream>
@@ -71,7 +70,7 @@ ResourceManager::~ResourceManager()
}
Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
- const std::string &idPath)
+ const std::string &idPath, int flags)
{
// Check if the id exists, and return the value if it does.
std::map<std::string, ResourceEntry>::iterator resIter =
@@ -108,7 +107,8 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
break;
case IMAGE:
// Attempt to create and load our image object.
- resource = reinterpret_cast<Resource*>(Image::load(filePath));
+ resource =
+ reinterpret_cast<Resource*>(Image::load(filePath, flags));
break;
case SCRIPT:
warning("Script resource not supported.");
@@ -139,9 +139,9 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
return resource;
}
-Image *ResourceManager::getImage(const std::string &idPath)
+Image *ResourceManager::getImage(const std::string &idPath, int flags)
{
- return (Image*)get(IMAGE, idPath);
+ return (Image*)get(IMAGE, idPath, flags);
}
ResourceManager* ResourceManager::getInstance()
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 1b719b41..fe8b2a96 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -27,6 +27,7 @@
#include <map>
#include <string>
#include "resource.h"
+#include "image.h"
/**
* A resource entry descriptor.
@@ -80,12 +81,13 @@ class ResourceManager
*/
Resource *get(
const E_RESOURCE_TYPE &type,
- const std::string &idPath);
+ const std::string &idPath,
+ int flags = 0);
/**
* Convenience wrapper around ResourceManager::create.
*/
- Image *getImage(const std::string &idPath);
+ Image *getImage(const std::string &idPath, int flags = 0);
/**
* Returns an instance of the class, creating one if it does not