summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/game.cpp4
-rw-r--r--src/gui/box.h27
-rw-r--r--src/gui/buddywindow.cpp2
-rw-r--r--src/gui/buddywindow.h2
-rw-r--r--src/gui/buy.cpp2
-rw-r--r--src/gui/buy.h2
-rw-r--r--src/gui/buysell.cpp2
-rw-r--r--src/gui/buysell.h2
-rw-r--r--src/gui/char_select.cpp10
-rw-r--r--src/gui/char_select.h6
-rw-r--r--src/gui/chat.cpp27
-rw-r--r--src/gui/chat.h2
-rw-r--r--src/gui/confirm_dialog.cpp4
-rw-r--r--src/gui/confirm_dialog.h2
-rw-r--r--src/gui/connection.cpp2
-rw-r--r--src/gui/debugwindow.cpp2
-rw-r--r--src/gui/debugwindow.h2
-rw-r--r--src/gui/gui.cpp10
-rw-r--r--src/gui/help.cpp2
-rw-r--r--src/gui/help.h2
-rw-r--r--src/gui/inventorywindow.cpp7
-rw-r--r--src/gui/inventorywindow.h2
-rw-r--r--src/gui/item_amount.cpp2
-rw-r--r--src/gui/item_amount.h2
-rw-r--r--src/gui/login.cpp4
-rw-r--r--src/gui/login.h4
-rw-r--r--src/gui/menuwindow.cpp8
-rw-r--r--src/gui/ministatus.cpp2
-rw-r--r--src/gui/newskill.cpp2
-rw-r--r--src/gui/newskill.h2
-rw-r--r--src/gui/npc_text.cpp2
-rw-r--r--src/gui/npc_text.h2
-rw-r--r--src/gui/npclistdialog.cpp2
-rw-r--r--src/gui/npclistdialog.h2
-rw-r--r--src/gui/ok_dialog.cpp4
-rw-r--r--src/gui/ok_dialog.h2
-rw-r--r--src/gui/register.cpp2
-rw-r--r--src/gui/register.h2
-rw-r--r--src/gui/scrollarea.cpp37
-rw-r--r--src/gui/sell.cpp2
-rw-r--r--src/gui/sell.h2
-rw-r--r--src/gui/setup.cpp2
-rw-r--r--src/gui/setup.h2
-rw-r--r--src/gui/setup_audio.cpp2
-rw-r--r--src/gui/setup_audio.h2
-rw-r--r--src/gui/setup_joystick.cpp2
-rw-r--r--src/gui/setup_joystick.h2
-rw-r--r--src/gui/setup_video.cpp2
-rw-r--r--src/gui/setup_video.h2
-rw-r--r--src/gui/skill.cpp2
-rw-r--r--src/gui/skill.h2
-rw-r--r--src/gui/status.cpp2
-rw-r--r--src/gui/status.h2
-rw-r--r--src/gui/tabbedcontainer.cpp2
-rw-r--r--src/gui/tabbedcontainer.h4
-rw-r--r--src/gui/textfield.cpp2
-rw-r--r--src/gui/trade.cpp2
-rw-r--r--src/gui/trade.h2
-rw-r--r--src/gui/updatewindow.cpp6
-rw-r--r--src/gui/updatewindow.h2
-rw-r--r--src/gui/vbox.cpp18
-rw-r--r--src/gui/window.cpp34
-rw-r--r--src/main.cpp8
-rw-r--r--src/net/network.cpp11
-rw-r--r--src/net/playerhandler.cpp4
-rw-r--r--src/net/tradehandler.cpp2
-rw-r--r--src/openglgraphics.cpp28
-rw-r--r--src/resources/openglsdlimageloader.cpp34
-rw-r--r--src/resources/openglsdlimageloader.h37
-rw-r--r--src/resources/resourcemanager.cpp17
-rw-r--r--src/resources/resourcemanager.h8
-rw-r--r--src/resources/sdlimageloader.cpp53
-rw-r--r--src/resources/sdlimageloader.h4
-rw-r--r--src/sound.cpp2
75 files changed, 285 insertions, 231 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 1bb1d538..42e72829 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,8 +12,6 @@ tmw_SOURCES = graphic/imagerect.h \
gui/buysell.h \
gui/chargedialog.cpp \
gui/chargedialog.h \
- gui/char_server.cpp \
- gui/char_server.h \
gui/char_select.cpp \
gui/char_select.h \
gui/chat.cpp \
@@ -167,6 +165,8 @@ tmw_SOURCES = graphic/imagerect.h \
resources/mapreader.h \
resources/music.h \
resources/music.cpp \
+ resources/openglsdlimageloader.h \
+ resources/openglsdlimageloader.cpp \
resources/resource.cpp \
resources/resource.h \
resources/resourcemanager.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 51b541a6..fab88aa9 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -122,7 +122,7 @@ const int MAX_TIME = 10000;
*/
namespace {
struct ExitListener : public gcn::ActionListener {
- void action(const std::string &eventId) {
+ void action(const std::string &eventId, gcn::Widget *widget) {
if (eventId == "yes") {
done = true;
}
@@ -465,7 +465,7 @@ void Game::handleInput()
// Close the config window, cancelling changes if opened
else if (setupWindow->isVisible())
{
- setupWindow->action("cancel");
+ setupWindow->action("cancel", NULL);
}
// Else, open the chat edit box
else
diff --git a/src/gui/box.h b/src/gui/box.h
index dccbfc78..ed1a7163 100644
--- a/src/gui/box.h
+++ b/src/gui/box.h
@@ -31,27 +31,30 @@
class Box : public gcn::Container
{
+ public:
+ /**
+ * Returns padding.
+ */
+ unsigned int getPadding();
+
+ /**
+ * Sets padding between widgets.
+ */
+ void setPadding(unsigned int);
+
protected:
Box();
virtual ~Box();
- /*
- * Spacing between client widgets
+ /**
+ * Spacing between client widgets.
*/
unsigned int padding;
virtual void draw(gcn::Graphics *) = 0;
- public:
- /*
- * Returns padding
- */
- unsigned int getPadding();
-
- /*
- * Sets padding between widgets
- */
- void setPadding(unsigned int);
+ typedef std::list<gcn::Widget*> Widgets;
+ typedef Widgets::iterator WidgetIterator;
};
#endif
diff --git a/src/gui/buddywindow.cpp b/src/gui/buddywindow.cpp
index 19a2f1e0..145f0ad2 100644
--- a/src/gui/buddywindow.cpp
+++ b/src/gui/buddywindow.cpp
@@ -61,7 +61,7 @@ BuddyWindow::BuddyWindow():
add(cancel);
}
-void BuddyWindow::action(const std::string& eventId)
+void BuddyWindow::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "Talk") {
int selected = mListbox->getSelected();
diff --git a/src/gui/buddywindow.h b/src/gui/buddywindow.h
index 6eeb7999..8764d008 100644
--- a/src/gui/buddywindow.h
+++ b/src/gui/buddywindow.h
@@ -48,7 +48,7 @@ class BuddyWindow : public Window, public gcn::ActionListener
/**
* Performs action.
*/
- void action(const std::string &actionId);
+ void action(const std::string& eventId, gcn::Widget* widget);
private:
BuddyList *mBuddyList;
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index e96cc04f..e7bfef58 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -148,7 +148,7 @@ void BuyDialog::addItem(short id, int price)
mItemList->adjustSize();
}
-void BuyDialog::action(const std::string& eventId)
+void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
{
int selectedItem = mItemList->getSelected();
diff --git a/src/gui/buy.h b/src/gui/buy.h
index 0349be4a..b09b648b 100644
--- a/src/gui/buy.h
+++ b/src/gui/buy.h
@@ -71,7 +71,7 @@ class BuyDialog : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
/**
* Returns the number of items in the shop inventory.
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index 6e338f08..ac0dcc84 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -50,7 +50,7 @@ BuySellDialog::BuySellDialog():
setLocationRelativeTo(getParent());
}
-void BuySellDialog::action(const std::string& eventId)
+void BuySellDialog::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "Buy") {
current_npc->buy();
diff --git a/src/gui/buysell.h b/src/gui/buysell.h
index 2d3c7bd3..7a90a869 100644
--- a/src/gui/buysell.h
+++ b/src/gui/buysell.h
@@ -47,7 +47,7 @@ class BuySellDialog : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
};
#endif
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index e8aa84e0..934988f4 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -48,7 +48,7 @@ class CharDeleteConfirm : public ConfirmDialog
{
public:
CharDeleteConfirm(CharSelectDialog *master);
- void action(const std::string &eventId);
+ void action(const std::string &eventId, gcn::Widget *widget);
private:
CharSelectDialog *master;
};
@@ -60,13 +60,13 @@ CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m):
{
}
-void CharDeleteConfirm::action(const std::string &eventId)
+void CharDeleteConfirm::action(const std::string &eventId, gcn::Widget *widget)
{
//ConfirmDialog::action(eventId);
if (eventId == "yes") {
master->attemptCharDelete();
}
- ConfirmDialog::action(eventId);
+ ConfirmDialog::action(eventId, widget);
}
CharSelectDialog::CharSelectDialog(Network *network,
@@ -126,7 +126,7 @@ CharSelectDialog::CharSelectDialog(Network *network,
updatePlayerInfo();
}
-void CharSelectDialog::action(const std::string& eventId)
+void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "ok" && n_character > 0)
{
@@ -284,7 +284,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
setLocationRelativeTo(getParent());
}
-void CharCreateDialog::action(const std::string& eventId)
+void CharCreateDialog::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "create") {
if (getName().length() >= 4) {
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index 8fc7cd01..20105516 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -29,6 +29,8 @@
#include "../guichanfwd.h"
#include "../lockedarray.h"
+#include <guichan/actionlistener.hpp>
+
class LocalPlayer;
class Network;
class PlayerBox;
@@ -49,7 +51,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener
LockedArray<LocalPlayer*> *charInfo,
unsigned char sex);
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
void updatePlayerInfo();
@@ -101,7 +103,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener
CharCreateDialog(Window *parent, int slot, Network *network,
unsigned char sex);
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
std::string getName();
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 870582df..133e5e3a 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -85,18 +85,17 @@ ChatWindow::~ChatWindow()
void
ChatWindow::logic()
{
- mChatInput->setPosition(
- mChatInput->getBorderSize(),
- getContent()->getHeight() - mChatInput->getHeight() -
- mChatInput->getBorderSize());
- mChatInput->setWidth(
- getContent()->getWidth() - 2 * mChatInput->getBorderSize());
-
- mScrollArea->setWidth(
- getContent()->getWidth() - 2 * mScrollArea->getBorderSize());
- mScrollArea->setHeight(
- getContent()->getHeight() - 2 * mScrollArea->getBorderSize() -
- mChatInput->getHeight() - 5);
+ // todo: only do this when the size changes (updateWidgets?)
+
+ const gcn::Rectangle area = getChildrenArea();
+
+ mChatInput->setPosition(mChatInput->getBorderSize(),
+ area.height - mChatInput->getHeight() -
+ mChatInput->getBorderSize());
+ mChatInput->setWidth(area.width - 2 * mChatInput->getBorderSize());
+ mScrollArea->setWidth(area.width - 2 * mScrollArea->getBorderSize());
+ mScrollArea->setHeight(area.height - 2 * mScrollArea->getBorderSize() -
+ mChatInput->getHeight() - 5);
mScrollArea->logic();
}
@@ -189,7 +188,7 @@ ChatWindow::chatLog(CHATSKILL act)
}
void
-ChatWindow::action(const std::string& eventId)
+ChatWindow::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "chatinput")
{
@@ -246,7 +245,7 @@ ChatWindow::requestChatFocus()
bool
ChatWindow::isFocused()
{
- return mChatInput->hasFocus();
+ return mChatInput->isFocused();
}
void
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 80e57a84..addfb6b5 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -145,7 +145,7 @@ class ChatWindow : public Window, public gcn::ActionListener,
/**
* Performs action.
*/
- void action(const std::string &actionId);
+ void action(const std::string& actionId, gcn::Widget* widget);
/**
* Request focus for typing chat message.
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
index 2d574157..ed2f8680 100644
--- a/src/gui/confirm_dialog.cpp
+++ b/src/gui/confirm_dialog.cpp
@@ -64,13 +64,13 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
yesButton->requestFocus();
}
-void ConfirmDialog::action(const std::string &eventId)
+void ConfirmDialog::action(const std::string &eventId, gcn::Widget *widget)
{
// Proxy button events to our listeners
ActionListenerIterator i;
for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
{
- (*i)->action(eventId);
+ (*i)->action(eventId, widget);
}
// Can we receive anything else anyway?
diff --git a/src/gui/confirm_dialog.h b/src/gui/confirm_dialog.h
index 3a05494f..1c206b03 100644
--- a/src/gui/confirm_dialog.h
+++ b/src/gui/confirm_dialog.h
@@ -47,7 +47,7 @@ class ConfirmDialog : public Window, public gcn::ActionListener {
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
};
#endif
diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp
index 4bd619ea..f7fdaca6 100644
--- a/src/gui/connection.cpp
+++ b/src/gui/connection.cpp
@@ -35,7 +35,7 @@
namespace {
struct ConnectionActionListener : public gcn::ActionListener
{
- void action(const std::string& eventId) { state = EXIT_STATE; }
+ void action(const std::string &eventId, gcn::Widget *widget) { state = EXIT_STATE; }
} listener;
}
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index 66681a8b..d467d4d3 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -98,7 +98,7 @@ DebugWindow::logic()
}
void
-DebugWindow::action(const std::string& eventId)
+DebugWindow::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "close")
{
diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h
index 80524ffa..61ef44e6 100644
--- a/src/gui/debugwindow.h
+++ b/src/gui/debugwindow.h
@@ -53,7 +53,7 @@ class DebugWindow : public Window, public gcn::ActionListener
/**
* Performs action.
*/
- void action(const std::string &actionId);
+ void action(const std::string& eventId, gcn::Widget* widget);
private:
gcn::Label *mMusicFileLabel, *mMapFileLabel;
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index cb79e54b..c980389f 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -28,7 +28,7 @@
#include <guichan/imagefont.hpp>
#ifdef USE_OPENGL
-#include <guichan/opengl/openglimageloader.hpp>
+#include "../resources/openglsdlimageloader.h"
#endif
#include <guichan/sdl/sdlinput.hpp>
@@ -92,16 +92,14 @@ Gui::Gui(Graphics *graphics):
{
// Set graphics
setGraphics(graphics);
+
+ // Set image loader
#ifdef USE_OPENGL
if (config.getValue("opengl", 0)) {
-
- // Set image loader
- mHostImageLoader = new SDLImageLoader();
- mImageLoader = new gcn::OpenGLImageLoader(mHostImageLoader);
+ mImageLoader = new OpenGLSDLImageLoader();
} else
#endif
{
- // Set image loader
mImageLoader = new SDLImageLoader();
}
diff --git a/src/gui/help.cpp b/src/gui/help.cpp
index dfb814db..e7429b29 100644
--- a/src/gui/help.cpp
+++ b/src/gui/help.cpp
@@ -54,7 +54,7 @@ HelpWindow::HelpWindow():
setLocationRelativeTo(getParent());
}
-void HelpWindow::action(const std::string& eventId)
+void HelpWindow::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "close")
{
diff --git a/src/gui/help.h b/src/gui/help.h
index 44c3d6fc..539ab31b 100644
--- a/src/gui/help.h
+++ b/src/gui/help.h
@@ -48,7 +48,7 @@ class HelpWindow : public Window, public LinkHandler,
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
/**
* Handles link action.
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 8f672bc9..063e8836 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -95,7 +95,7 @@ void InventoryWindow::logic()
mWeightLabel->adjustSize();
}
-void InventoryWindow::action(const std::string &eventId)
+void InventoryWindow::action(const std::string &eventId, gcn::Widget *widget)
{
Item *item = mItems->getItem();
@@ -168,8 +168,9 @@ void InventoryWindow::mouseMotion(int mx, int my)
void InventoryWindow::updateWidgets()
{
- int width = getContent()->getWidth();
- int height = getContent()->getHeight();
+ gcn::Rectangle area = getChildrenArea();
+ int width = area.width;
+ int height = area.height;
int columns = width / 24;
if (columns < 1)
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 179e5314..da7a7ef2 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -54,7 +54,7 @@ class InventoryWindow : public Window, gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
void mouseClick(int x, int y, int button, int count);
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index b1b01c3f..30c899a8 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -94,7 +94,7 @@ void ItemAmountWindow::resetAmount()
mItemAmountTextBox->setInt(1);
}
-void ItemAmountWindow::action(const std::string& eventId)
+void ItemAmountWindow::action(const std::string &eventId, gcn::Widget *widget)
{
int amount = mItemAmountTextBox->getInt();
diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h
index ad1e18d6..a2a17575 100644
--- a/src/gui/item_amount.h
+++ b/src/gui/item_amount.h
@@ -54,7 +54,7 @@ class ItemAmountWindow : public Window, public gcn::ActionListener
/**
* Called when receiving actions from widget.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
/**
* Sets default amount value.
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index c0dd9245..2f646bd1 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -43,7 +43,7 @@ WrongDataNoticeListener::setTarget(gcn::TextField *textField)
}
void
-WrongDataNoticeListener::action(const std::string &eventId)
+WrongDataNoticeListener::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "ok")
{
@@ -128,7 +128,7 @@ LoginDialog::~LoginDialog()
}
void
-LoginDialog::action(const std::string& eventId)
+LoginDialog::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "ok")
{
diff --git a/src/gui/login.h b/src/gui/login.h
index 39548950..7218dca8 100644
--- a/src/gui/login.h
+++ b/src/gui/login.h
@@ -38,7 +38,7 @@ class LoginData;
class WrongDataNoticeListener : public gcn::ActionListener {
public:
void setTarget(gcn::TextField *textField);
- void action(const std::string &eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
private:
gcn::TextField *mTarget;
};
@@ -65,7 +65,7 @@ class LoginDialog : public Window, public gcn::ActionListener {
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
private:
gcn::TextField *mUserField;
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index 503f7ba8..a1b342f0 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -39,7 +39,7 @@ namespace {
/**
* Called when receiving actions from widget.
*/
- void action(const std::string& eventId);
+ void action(const std::string &eventId, gcn::Widget *widget);
} listener;
}
@@ -69,13 +69,13 @@ MenuWindow::MenuWindow():
setDefaultSize((windowContainer->getWidth() - x - 2), 0, x, (y + h));
}
-void MenuWindow::draw(gcn::Graphics *g)
+void MenuWindow::draw(gcn::Graphics *graphics)
{
- Window::drawContent(g);
+ drawChildren(graphics);
}
-void MenuWindowListener::action(const std::string& eventId)
+void MenuWindowListener::action(const std::string &eventId, gcn::Widget *widget)
{
Window *window = NULL;
if (eventId == "Status")
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp
index be089b68..53849550 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -96,5 +96,5 @@ void MiniStatusWindow::update()
void MiniStatusWindow::draw(gcn::Graphics *graphics)
{
update();
- Window::drawContent(graphics);
+ drawChildren(graphics);
}
diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp
index 498186ba..7f5de543 100644
--- a/src/gui/newskill.cpp
+++ b/src/gui/newskill.cpp
@@ -121,7 +121,7 @@ NewSkillDialog::NewSkillDialog():
setLocationRelativeTo(getParent());
}
-void NewSkillDialog::action(const std::string& eventId)
+void NewSkillDialog::action(const std::string &eventId, gcn::Widget *widget)
{
int osp = startPoint;
if (eventId == "close")
diff --git a/src/gui/newskill.h b/src/gui/newskill.h
index 764019f5..224574bd 100644
--- a/src/gui/newskill.h
+++ b/src/gui/newskill.h
@@ -55,7 +55,7 @@ class NewSkillDialog : public Window, public gcn::ActionListener
NewSkillDialog();
// action listener
- void action(const std::string&);
+ void action(const std::string& eventId, gcn::Widget* widget);
private:
void resetNSD(); // updates the values in the dialog box
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 1a6bb5ce..5b7ca439 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -67,7 +67,7 @@ NpcTextDialog::addText(const std::string &text)
}
void
-NpcTextDialog::action(const std::string& eventId)
+NpcTextDialog::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "ok")
{
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index a1d75aab..3ce1215d 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -49,7 +49,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener
* Called when receiving actions from the widgets.
*/
void
- action(const std::string &eventId);
+ action(const std::string& eventId, gcn::Widget* widget);
/**
* Sets the text shows in the dialog.
diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp
index 2d12986d..d1c3ddcb 100644
--- a/src/gui/npclistdialog.cpp
+++ b/src/gui/npclistdialog.cpp
@@ -91,7 +91,7 @@ NpcListDialog::reset()
}
void
-NpcListDialog::action(const std::string& eventId)
+NpcListDialog::action(const std::string &eventId, gcn::Widget *widget)
{
int choice = 0;
diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h
index 7d649450..03b76681 100644
--- a/src/gui/npclistdialog.h
+++ b/src/gui/npclistdialog.h
@@ -54,7 +54,7 @@ class NpcListDialog : public Window, public gcn::ActionListener,
* Called when receiving actions from the widgets.
*/
void
- action(const std::string& eventId);
+ action(const std::string& eventId, gcn::Widget* widget);
/**
* Returns the number of items in the choices list.
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index 2f3f21c5..906fd61f 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -54,13 +54,13 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
okButton->requestFocus();
}
-void OkDialog::action(const std::string &eventId)
+void OkDialog::action(const std::string &eventId, gcn::Widget *widget)
{
// Proxy button events to our listeners
ActionListenerIterator i;
for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
{
- (*i)->action(eventId);
+ (*i)->action(eventId, widget);
}
// Can we receive anything else anyway?
diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h
index eb0da2c0..06f703cc 100644
--- a/src/gui/ok_dialog.h
+++ b/src/gui/ok_dialog.h
@@ -46,7 +46,7 @@ class OkDialog : public Window, public gcn::ActionListener {
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
};
#endif
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index b99568a8..38136b87 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -116,7 +116,7 @@ RegisterDialog::~RegisterDialog()
}
void
-RegisterDialog::action(const std::string& eventId)
+RegisterDialog::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "cancel")
{
diff --git a/src/gui/register.h b/src/gui/register.h
index b46eb1ce..5d3f6cd5 100644
--- a/src/gui/register.h
+++ b/src/gui/register.h
@@ -56,7 +56,7 @@ class RegisterDialog : public Window, public gcn::ActionListener {
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
// Made them public to have the possibility to request focus
// from external functions.
diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp
index 3703ead8..18a1dfb4 100644
--- a/src/gui/scrollarea.cpp
+++ b/src/gui/scrollarea.cpp
@@ -55,7 +55,7 @@ ScrollArea::~ScrollArea()
{
// Garbage collection
if (mGC) {
- delete mContent;
+ delete getContent();
}
instances--;
@@ -144,20 +144,21 @@ void ScrollArea::init()
void ScrollArea::logic()
{
gcn::ScrollArea::logic();
+ gcn::Widget *content = getContent();
// When no scrollbar in a certain direction, adapt content size to match
// the content dimension exactly.
- if (mContent != NULL)
+ if (content != NULL)
{
if (getHorizontalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER)
{
- mContent->setWidth(getContentDimension().width -
- 2 * mContent->getBorderSize());
+ content->setWidth(getChildrenArea().width -
+ 2 * content->getBorderSize());
}
if (getVerticalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER)
{
- mContent->setHeight(getContentDimension().height -
- 2 * mContent->getBorderSize());
+ content->setHeight(getChildrenArea().height -
+ 2 * content->getBorderSize());
}
}
}
@@ -197,24 +198,26 @@ void ScrollArea::draw(gcn::Graphics *graphics)
mScrollbarWidth));
}
- if (mContent)
+ gcn::Widget *content = getContent();
+
+ if (content != NULL)
{
- graphics->pushClipArea(getContentDimension());
+ graphics->pushClipArea(getChildrenArea());
- if (mContent->getBorderSize() > 0)
+ if (content->getBorderSize() > 0)
{
- gcn::Rectangle rec = mContent->getDimension();
- rec.x -= mContent->getBorderSize();
- rec.y -= mContent->getBorderSize();
- rec.width += 2 * mContent->getBorderSize();
- rec.height += 2 * mContent->getBorderSize();
+ gcn::Rectangle rec = content->getDimension();
+ rec.x -= content->getBorderSize();
+ rec.y -= content->getBorderSize();
+ rec.width += 2 * content->getBorderSize();
+ rec.height += 2 * content->getBorderSize();
graphics->pushClipArea(rec);
- mContent->drawBorder(graphics);
+ content->drawBorder(graphics);
graphics->popClipArea();
}
- graphics->pushClipArea(mContent->getDimension());
- mContent->draw(graphics);
+ graphics->pushClipArea(content->getDimension());
+ content->draw(graphics);
graphics->popClipArea();
graphics->popClipArea();
}
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 0b7abf6f..e820d42f 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -152,7 +152,7 @@ void SellDialog::addItem(Item *item, int price)
mItemList->adjustSize();
}
-void SellDialog::action(const std::string& eventId)
+void SellDialog::action(const std::string &eventId, gcn::Widget *widget)
{
int selectedItem = mItemList->getSelected();
diff --git a/src/gui/sell.h b/src/gui/sell.h
index 59bc58c2..423fea26 100644
--- a/src/gui/sell.h
+++ b/src/gui/sell.h
@@ -68,7 +68,7 @@ class SellDialog : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
/**
* Mouse callback
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index e0e0e81b..6af9119b 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -85,7 +85,7 @@ Setup::~Setup()
for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs));
}
-void Setup::action(const std::string &event)
+void Setup::action(const std::string& event, gcn::Widget *widget)
{
if (event == "Apply")
{
diff --git a/src/gui/setup.h b/src/gui/setup.h
index 611633c5..6601ce3d 100644
--- a/src/gui/setup.h
+++ b/src/gui/setup.h
@@ -54,7 +54,7 @@ class Setup : public Window, public gcn::ActionListener
* Event handling method.
*/
void
- action(const std::string& eventId);
+ action(const std::string& eventId, gcn::Widget* widget);
private:
std::list<SetupTab*> mTabs;
diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp
index 6f884e2f..db88ff64 100644
--- a/src/gui/setup_audio.cpp
+++ b/src/gui/setup_audio.cpp
@@ -108,7 +108,7 @@ void Setup_Audio::cancel()
config.setValue("musicVolume", mMusicVolume);
}
-void Setup_Audio::action(const std::string &event)
+void Setup_Audio::action(const std::string& event, gcn::Widget *widget)
{
if (event == "sfx")
{
diff --git a/src/gui/setup_audio.h b/src/gui/setup_audio.h
index 706d6a50..f09f62da 100644
--- a/src/gui/setup_audio.h
+++ b/src/gui/setup_audio.h
@@ -38,7 +38,7 @@ class Setup_Audio : public SetupTab, public gcn::ActionListener
void apply();
void cancel();
- void action(const std::string&);
+ void action(const std::string& eventId, gcn::Widget* widget);
private:
int mMusicVolume, mSfxVolume;
diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp
index fdf50980..36b0ee20 100644
--- a/src/gui/setup_joystick.cpp
+++ b/src/gui/setup_joystick.cpp
@@ -44,7 +44,7 @@ Setup_Joystick::Setup_Joystick():
add(mCalibrateButton);
}
-void Setup_Joystick::action(const std::string &event)
+void Setup_Joystick::action(const std::string &event, gcn::Widget *widget)
{
if (!joystick) {
return;
diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h
index 2abe9678..da773c8f 100644
--- a/src/gui/setup_joystick.h
+++ b/src/gui/setup_joystick.h
@@ -38,7 +38,7 @@ class Setup_Joystick : public SetupTab, public gcn::ActionListener
void apply() {}
void cancel() {}
- void action(const std::string&);
+ void action(const std::string& eventId, gcn::Widget* widget);
private:
gcn::Label *mCalibrateLabel;
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index 05543092..9eb94520 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -237,7 +237,7 @@ void Setup_Video::cancel()
config.setValue("opengl", mOpenGLEnabled ? 1 : 0);
}
-void Setup_Video::action(const std::string &event)
+void Setup_Video::action(const std::string &event, gcn::Widget *widget)
{
if (event == "guialpha")
{
diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h
index b021ead4..d0a10925 100644
--- a/src/gui/setup_video.h
+++ b/src/gui/setup_video.h
@@ -41,7 +41,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
void apply();
void cancel();
- void action(const std::string&);
+ void action(const std::string &eventId, gcn::Widget *widget);
/** Called when key is pressed */
void keyPress(const gcn::Key& key);
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 604a19cc..4f552fd7 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -103,7 +103,7 @@ SkillDialog::~SkillDialog()
cleanList();
}
-void SkillDialog::action(const std::string& eventId)
+void SkillDialog::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "inc")
{
diff --git a/src/gui/skill.h b/src/gui/skill.h
index fe80347d..5555fec4 100644
--- a/src/gui/skill.h
+++ b/src/gui/skill.h
@@ -57,7 +57,7 @@ class SkillDialog : public Window, public gcn::ActionListener,
*/
~SkillDialog();
- void action(const std::string&);
+ void action(const std::string& eventId, gcn::Widget* widget);
void update();
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index 7d6cabac..bf109460 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -361,7 +361,7 @@ void StatusWindow::draw(gcn::Graphics *g)
Window::draw(g);
}
-void StatusWindow::action(const std::string& eventId)
+void StatusWindow::action(const std::string &eventId, gcn::Widget *widget)
{
// Stats Part
if (eventId.length() == 3)
diff --git a/src/gui/status.h b/src/gui/status.h
index 52ece323..6b963d24 100644
--- a/src/gui/status.h
+++ b/src/gui/status.h
@@ -51,7 +51,7 @@ class StatusWindow : public Window, public gcn::ActionListener {
/**
* Called when receiving actions from widget.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
/**
* Draw this window
diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp
index f1927c6f..e3d2527b 100644
--- a/src/gui/tabbedcontainer.cpp
+++ b/src/gui/tabbedcontainer.cpp
@@ -78,7 +78,7 @@ void TabbedContainer::logic()
Container::logic();
}
-void TabbedContainer::action(const std::string &event)
+void TabbedContainer::action(const std::string &event, gcn::Widget *widget)
{
std::stringstream ss(event);
int tabNo;
diff --git a/src/gui/tabbedcontainer.h b/src/gui/tabbedcontainer.h
index 24c8c425..453d8374 100644
--- a/src/gui/tabbedcontainer.h
+++ b/src/gui/tabbedcontainer.h
@@ -43,7 +43,7 @@ class TabbedContainer : public gcn::Container, public gcn::ActionListener
void logic();
- void action(const std::string &event);
+ void action(const std::string &event, gcn::Widget *widget);
void setOpaque(bool opaque);
@@ -53,7 +53,7 @@ class TabbedContainer : public gcn::Container, public gcn::ActionListener
Widgets mTabs; // The actual tabs at the top
Widgets mContents; // The contents of the tabs
- Widget *mActiveContent;
+ gcn::Widget *mActiveContent;
};
#endif
diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp
index aa9d04fd..2e083d5a 100644
--- a/src/gui/textfield.cpp
+++ b/src/gui/textfield.cpp
@@ -82,7 +82,7 @@ TextField::~TextField()
void TextField::draw(gcn::Graphics *graphics)
{
- if (hasFocus()) {
+ if (isFocused()) {
drawCaret(graphics,
getFont()->getWidth(mText.substr(0, mCaretPosition)) -
mXScroll);
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 4efdb06c..73193c88 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -258,7 +258,7 @@ void TradeWindow::mouseClick(int x, int y, int button, int count)
mItemDescriptionLabel->adjustSize();
}
-void TradeWindow::action(const std::string &eventId)
+void TradeWindow::action(const std::string &eventId, gcn::Widget *widget)
{
Item *item = inventoryWindow->getItem();
diff --git a/src/gui/trade.h b/src/gui/trade.h
index 8bf4b86d..eb3c0f97 100644
--- a/src/gui/trade.h
+++ b/src/gui/trade.h
@@ -110,7 +110,7 @@ class TradeWindow : public Window, gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
private:
Network *mNetwork;
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 3f5fe7bb..9188b6de 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -107,7 +107,7 @@ UpdaterWindow::~UpdaterWindow()
}
// Remove possibly leftover temporary download
- remove((mBasePath + "/updates/download.temp").c_str());
+ ::remove((mBasePath + "/updates/download.temp").c_str());
delete[] mCurlError;
}
@@ -129,7 +129,7 @@ void UpdaterWindow::enable()
mPlayButton->requestFocus();
}
-void UpdaterWindow::action(const std::string& eventId)
+void UpdaterWindow::action(const std::string &eventId, gcn::Widget *widget)
{
if (eventId == "cancel")
{
@@ -299,7 +299,7 @@ int UpdaterWindow::downloadThread(void *ptr)
// Any existing file with this name is deleted first, otherwise the
// rename will fail on Windows.
- remove(newName.c_str());
+ ::remove(newName.c_str());
rename(outFilename.c_str(), newName.c_str());
}
}
diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h
index 5f049e18..8a168be8 100644
--- a/src/gui/updatewindow.h
+++ b/src/gui/updatewindow.h
@@ -79,7 +79,7 @@ class UpdaterWindow : public Window, public gcn::ActionListener
*/
void loadNews();
- void action(const std::string& eventId);
+ void action(const std::string& eventId, gcn::Widget* widget);
/**
* Add a row to the message field.
diff --git a/src/gui/vbox.cpp b/src/gui/vbox.cpp
index d79fbba2..eb838ead 100644
--- a/src/gui/vbox.cpp
+++ b/src/gui/vbox.cpp
@@ -25,17 +25,21 @@
void VBox::draw(gcn::Graphics *graphics)
{
- int widgetCount = mWidgets.size();
- int childWidth = getWidth();
- if (widgetCount == 0)
- return;
- int childHeight = getHeight() / widgetCount;
+ if (mWidgets.size() == 0)
+ {
+ return;
+ }
+ int childWidth = getWidth();
+ int childHeight = getHeight() / mWidgets.size();
int i = 0;
- for (WidgetIterator w = mWidgets.begin(); w != mWidgets.end(); w++) {
- (*w)->setPosition(0, childHeight * i - padding);
+
+ for (WidgetIterator w = mWidgets.begin(); w != mWidgets.end(); w++)
+ {
+ (*w)->setPosition(0, childHeight * i - padding);
(*w)->setSize(childWidth, childHeight);
i++;
}
+
gcn::Container::draw(graphics);
}
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 974a1d73..9a07111f 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -105,7 +105,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
// Add chrome
mChrome = new GCContainer();
mChrome->setOpaque(false);
- setContent(mChrome);
+ gcn::Window::add(mChrome);
// Add this window to the window container
windowContainer->add(this);
@@ -180,7 +180,7 @@ void Window::draw(gcn::Graphics* graphics)
graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT);
}
- drawContent(graphics);
+ drawChildren(graphics);
}
void Window::setContentWidth(int width)
@@ -195,7 +195,7 @@ void Window::setContentHeight(int height)
resizeToContent();
}
-void Window::setLocationRelativeTo(gcn::Widget* widget)
+void Window::setLocationRelativeTo(gcn::Widget *widget)
{
int wx, wy;
int x, y;
@@ -267,7 +267,7 @@ void Window::mousePress(int x, int y, int button)
// border, and is a candidate for a resize.
if (isResizable() && button == 1 &&
getGripDimension().isPointInRect(x, y) &&
- !getContentDimension().isPointInRect(x, y) &&
+ !getChildrenArea().isPointInRect(x, y) &&
hasMouse() &&
!(mMouseDrag && y > (int)getPadding()))
{
@@ -374,11 +374,8 @@ void Window::mouseMotion(int x, int y)
// Set the new window and content dimensions
setDimension(newDim);
-
- if (mContent != NULL && mMouseResize)
- {
- mContent->setDimension(getContentDimension());
- }
+ const gcn::Rectangle area = getChildrenArea();
+ mChrome->setSize(area.width, area.height);
}
}
@@ -406,18 +403,16 @@ Window::loadWindowState()
{
const std::string &name = mWindowName;
- setPosition((int)config.getValue(name + "WinX", getX()),
- (int)config.getValue(name + "WinY", getY()));
+ setPosition((int) config.getValue(name + "WinX", getX()),
+ (int) config.getValue(name + "WinY", getY()));
if (mResizable)
{
- setWidth((int)config.getValue(name + "WinWidth", getWidth()));
- setHeight((int)config.getValue(name + "WinHeight", getHeight()));
+ setSize((int) config.getValue(name + "WinWidth", getWidth()),
+ (int) config.getValue(name + "WinHeight", getHeight()));
- if (mContent != NULL)
- {
- mContent->setDimension(getContentDimension());
- }
+ const gcn::Rectangle area = getChildrenArea();
+ mChrome->setSize(area.width, area.height);
}
}
@@ -437,9 +432,4 @@ void Window::resetToDefaultSize()
{
setPosition(mDefaultX, mDefaultY);
setContentSize(mDefaultWidth, mDefaultHeight);
-
- if (mContent != NULL)
- {
- mContent->setDimension(getContentDimension());
- }
}
diff --git a/src/main.cpp b/src/main.cpp
index 8cd6eeb6..1bec709f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -100,7 +100,7 @@ Logger *logger; /**< Log object */
namespace {
struct ErrorListener : public gcn::ActionListener
{
- void action(const std::string& eventId) { state = LOGIN_STATE; }
+ void action(const std::string &eventId, gcn::Widget *widget) { state = LOGIN_STATE; }
} errorListener;
}
@@ -606,7 +606,8 @@ int main(int argc, char *argv[])
oldstate = state;
- if (currentDialog && state != ACCOUNT_STATE && state != CHAR_CONNECT_STATE) {
+ if (currentDialog && state != ACCOUNT_STATE &&
+ state != CHAR_CONNECT_STATE) {
delete currentDialog;
currentDialog = NULL;
}
@@ -631,7 +632,8 @@ int main(int argc, char *argv[])
currentDialog = new CharSelectDialog(network, &charInfo,
1 - loginData.sex);
if (options.chooseDefault) {
- ((CharSelectDialog*)currentDialog)->action("ok");
+ ((CharSelectDialog*)currentDialog)->action("ok",
+ NULL);
}
break;
diff --git a/src/net/network.cpp b/src/net/network.cpp
index aa18e888..64cbf331 100644
--- a/src/net/network.cpp
+++ b/src/net/network.cpp
@@ -66,7 +66,7 @@ bool Network::connect(const std::string &address, short port)
mState = CONNECTING;
- mClient = enet_host_create (0, 1, 0, 0);
+ mClient = enet_host_create(0, 1, 0, 0);
if (!mClient)
{
@@ -160,8 +160,10 @@ void Network::dispatchMessages()
void Network::flush()
{
+ logger->log("Network::flush()");
if (mState == IDLE || mState == NET_ERROR)
{
+ logger->log("Idle or error, returning");
return;
}
@@ -173,20 +175,25 @@ void Network::flush()
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
+ logger->log("Connected.");
mState = CONNECTED;
// Store any relevant server information here.
event.peer->data = 0;
break;
case ENET_EVENT_TYPE_RECEIVE:
+ logger->log("Incoming data...");
mIncomingPackets.push(event.packet);
break;
case ENET_EVENT_TYPE_DISCONNECT:
mState = IDLE;
- printf("Disconnected\n");
+ logger->log("Disconnected.");
// Reset the server information.
event.peer->data = 0;
break;
+ case ENET_EVENT_TYPE_NONE:
+ logger->log("No event during 10 milliseconds.");
+ break;
default:
logger->log("Unhandled enet event.");
break;
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index 5453eae4..c70eada3 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -46,7 +46,7 @@ OkDialog *deathNotice = NULL;
namespace {
struct WeightListener : public gcn::ActionListener
{
- void action(const std::string &eventId) { weightNotice = NULL; }
+ void action(const std::string &eventId, gcn::Widget *widget) { weightNotice = NULL; }
} weightListener;
}
@@ -56,7 +56,7 @@ namespace {
// TODO Move somewhere else
namespace {
struct DeathListener : public gcn::ActionListener {
- void action(const std::string &eventId) {
+ void action(const std::string &eventId, gcn::Widget *widget) {
player_node->revive();
deathNotice = NULL;
}
diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp
index 0f5bdcdc..b0baa5ea 100644
--- a/src/net/tradehandler.cpp
+++ b/src/net/tradehandler.cpp
@@ -41,7 +41,7 @@ std::string tradePartnerName;
namespace {
struct RequestTradeListener : public gcn::ActionListener
{
- void action(const std::string& eventId)
+ void action(const std::string &eventId, gcn::Widget *widget)
{
player_node->tradeReply(eventId == "yes");
};
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index dc14b6c6..2a6c931d 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -31,7 +31,9 @@
#include <OpenGL/OpenGL.h>
#endif
+#include <guichan/exception.hpp>
#include <guichan/image.hpp>
+#include <guichan/opengl/openglimage.hpp>
#include "log.h"
@@ -227,28 +229,24 @@ void OpenGLGraphics::drawImage(const gcn::Image* image,
int dstX, int dstY,
int width, int height)
{
- // The following code finds the real width and height of the texture.
- // OpenGL only supports texture sizes that are powers of two
- int realImageWidth = 1;
- int realImageHeight = 1;
- while (realImageWidth < image->getWidth())
- {
- realImageWidth *= 2;
- }
- while (realImageHeight < image->getHeight())
+ const gcn::OpenGLImage* srcImage =
+ dynamic_cast<const gcn::OpenGLImage*>(image);
+
+ if (srcImage == NULL)
{
- realImageHeight *= 2;
+ throw GCN_EXCEPTION("Trying to draw an image of unknown format, "
+ "must be an SDLImage.");
}
// Find OpenGL texture coordinates
- float texX1 = srcX / (float)realImageWidth;
- float texY1 = srcY / (float)realImageHeight;
- float texX2 = (srcX + width) / (float)realImageWidth;
- float texY2 = (srcY + height) / (float)realImageHeight;
+ float texX1 = srcX / (float)srcImage->getTextureWidth();
+ float texY1 = srcY / (float)srcImage->getTextureHeight();
+ float texX2 = (srcX + width) / (float)srcImage->getTextureWidth();
+ float texY2 = (srcY + height) / (float)srcImage->getTextureHeight();
// Please dont look too closely at the next line, it is not pretty.
// It uses the image data as a pointer to a GLuint
- glBindTexture(GL_TEXTURE_2D, *((GLuint *)(image->_getData())));
+ glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle());
drawTexedQuad(dstX, dstY, width, height, texX1, texY1, texX2, texY2);
}
diff --git a/src/resources/openglsdlimageloader.cpp b/src/resources/openglsdlimageloader.cpp
new file mode 100644
index 00000000..f3ddbd84
--- /dev/null
+++ b/src/resources/openglsdlimageloader.cpp
@@ -0,0 +1,34 @@
+/*
+ * The Mana World
+ * Copyright 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
+ * 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,
+ * 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
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: sdlimageloader.cpp 2121 2006-01-31 02:55:26Z der_doener $
+ */
+
+#include "openglsdlimageloader.h"
+
+#include <string>
+
+#include "resourcemanager.h"
+
+SDL_Surface* OpenGLSDLImageLoader::loadSDLSurface(const std::string& filename)
+{
+ ResourceManager *resman = ResourceManager::getInstance();
+ return resman->loadSDLSurface(filename);
+}
diff --git a/src/resources/openglsdlimageloader.h b/src/resources/openglsdlimageloader.h
new file mode 100644
index 00000000..29be294c
--- /dev/null
+++ b/src/resources/openglsdlimageloader.h
@@ -0,0 +1,37 @@
+/*
+ * The Mana World
+ * Copyright 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
+ * 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,
+ * 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
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: sdlimageloader.h 1724 2005-09-12 22:15:35Z der_doener $
+ */
+
+#ifndef _TMW_OPENGLSDLIMAGELOADER_H
+#define _TMW_OPENGLSDLIMAGELOADER_H
+
+#include <iosfwd>
+
+#include <guichan/opengl/openglsdlimageloader.hpp>
+
+class OpenGLSDLImageLoader : public gcn::OpenGLSDLImageLoader
+{
+ protected:
+ SDL_Surface* loadSDLSurface(const std::string& filename);
+};
+
+#endif
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 6353afac..23a73497 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -26,6 +26,7 @@
#include <cassert>
#include <sstream>
#include <physfs.h>
+#include <SDL_image.h>
#include "image.h"
#include "music.h"
@@ -300,3 +301,19 @@ ResourceManager::loadTextFile(const std::string &fileName)
free(fileContents);
return lines;
}
+
+SDL_Surface*
+ResourceManager::loadSDLSurface(const std::string& filename)
+{
+ int fileSize;
+ void *buffer = loadFile(filename, fileSize);
+ SDL_Surface *tmp = NULL;
+
+ if (buffer) {
+ SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize);
+ tmp = IMG_Load_RW(rw, 1);
+ ::free(buffer);
+ }
+
+ return tmp;
+}
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index f254a8b4..0086b167 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -27,6 +27,7 @@
#include <iosfwd>
#include <map>
#include <vector>
+#include <SDL.h>
class Resource;
class Image;
@@ -164,6 +165,13 @@ class ResourceManager
loadTextFile(const std::string &fileName);
/**
+ * Loads the given filename as an SDL surface. The returned surface is
+ * expected to be freed by the caller using SDL_FreeSurface.
+ */
+ SDL_Surface*
+ loadSDLSurface(const std::string& filename);
+
+ /**
* Returns an instance of the class, creating one if it does not
* already exist.
*/
diff --git a/src/resources/sdlimageloader.cpp b/src/resources/sdlimageloader.cpp
index 88c4143e..ae4f4dcb 100644
--- a/src/resources/sdlimageloader.cpp
+++ b/src/resources/sdlimageloader.cpp
@@ -24,60 +24,11 @@
#include "sdlimageloader.h"
#include <string>
-#include <SDL_image.h>
-
-#include <guichan/exception.hpp>
#include "resourcemanager.h"
-void SDLImageLoader::prepare(const std::string &filename)
+SDL_Surface* SDLImageLoader::loadSDLSurface(const std::string& filename)
{
- if (mCurrentImage)
- {
- throw GCN_EXCEPTION("Function called before finalizing or discarding last loaded image.");
- }
-
ResourceManager *resman = ResourceManager::getInstance();
-
- int fileSize;
- void *buffer = resman->loadFile(filename, fileSize);
-
- SDL_Surface *tmp = NULL;
- if (buffer) {
- SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize);
- tmp = IMG_Load_RW(rw, 1);
- ::free(buffer);
- }
-
- if (!tmp)
- {
- throw GCN_EXCEPTION(std::string("Unable to load image file: ")+filename);
- }
-
- Uint32 rmask, gmask, bmask, amask;
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
-#else
- rmask = 0x000000ff;
- gmask = 0x0000ff00;
- bmask = 0x00ff0000;
- amask = 0xff000000;
-#endif
-
- mCurrentImage = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32,
- rmask, gmask, bmask, amask);
-
- if (!mCurrentImage)
- {
- throw GCN_EXCEPTION(std::string("Not enough memory to load: ")+filename);
- }
-
- SDL_Surface* tmp2 = SDL_ConvertSurface(tmp, mCurrentImage->format, SDL_SWSURFACE);
- SDL_FreeSurface(tmp);
- SDL_FreeSurface(mCurrentImage);
-
- mCurrentImage = tmp2;
+ return resman->loadSDLSurface(filename);
}
diff --git a/src/resources/sdlimageloader.h b/src/resources/sdlimageloader.h
index b34b98fe..50b1d4f1 100644
--- a/src/resources/sdlimageloader.h
+++ b/src/resources/sdlimageloader.h
@@ -30,8 +30,8 @@
class SDLImageLoader : public gcn::SDLImageLoader
{
- public:
- void prepare(const std::string &filename);
+ protected:
+ SDL_Surface* loadSDLSurface(const std::string& filename);
};
#endif
diff --git a/src/sound.cpp b/src/sound.cpp
index 8b012176..182be3d6 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -208,6 +208,6 @@ void Sound::close()
stopMusic();
mInstalled = false;
- Mix_CloseAudio();
logger->log("Sound::close() Shutting down sound...");
+ Mix_CloseAudio();
}