From 4df1759a3636108839f9533268c8ce1b7156e132 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 2 Oct 2005 13:38:27 +0000 Subject: Added check for pthread library (needed for FreeBSD, still needs to be checked on MacOS X) and some cleanups. --- src/Makefile.am | 2 +- src/gui/window.cpp | 75 ++++++++++++++++++++++----------------------- src/gui/window.h | 34 ++++++++++---------- src/map.cpp | 10 +++--- src/resources/buddylist.cpp | 6 ++-- src/resources/buddylist.h | 6 ++-- 6 files changed, 67 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 4506fde4..0cf92c0f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -184,5 +184,5 @@ INCLUDES = \ # the library search path. tmw_LDFLAGS = $(all_libraries) $(LIBSDL_RPATH) `pkg-config --libs libxml-2.0` tmw_CXXFLAGS = -Wall -Werror $(OPENGL_CFLAGS) $(LIBSDL_CFLAGS) `pkg-config --cflags libxml-2.0` $(CURL_CFLAGS) -tmw_LDADD = $(LIBSDL_LIBS) -lguichan_sdl -lguichan $(OPENGL_LIBS) $(CURL_LIBS) +tmw_LDADD = $(LIBSDL_LIBS) -lguichan_sdl $(OPENGL_LIBS) $(CURL_LIBS) tmw_TARGET = tmw diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 5b125bd2..2f288fff 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -130,14 +130,16 @@ Window::Window(const std::string& caption, bool modal, Window *parent): Window::~Window() { logger->log("Window::~Window(\"%s\")", getCaption().c_str()); + const std::string &name = mWindowName; // Saving X, Y and Width and Height for resizables in the config - config.setValue(std::string(getWindowName() + "WinX"), getX()); - config.setValue(std::string(getWindowName() + "WinY"), getY()); - if ( resizable ) + config.setValue(name + "WinX", getX()); + config.setValue(name + "WinY", getY()); + + if (resizable) { - config.setValue(std::string(getWindowName() + "WinWidth"), getWidth()); - config.setValue(std::string(getWindowName() + "WinHeight"), getHeight()); + config.setValue(name + "WinWidth", getWidth()); + config.setValue(name + "WinHeight", getHeight()); } instances--; @@ -212,9 +214,8 @@ void Window::setLocationRelativeTo(gcn::Widget* widget) widget->getAbsolutePosition(wx, wy); getAbsolutePosition(x, y); - setPosition( - getX() + (wx + (widget->getWidth() - getWidth()) / 2 - x), - getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); + setPosition(getX() + (wx + (widget->getWidth() - getWidth()) / 2 - x), + getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } void Window::setContentSize(int width, int height) @@ -281,15 +282,14 @@ void Window::mousePress(int x, int y, int button) // If the mouse is not inside the content, the press must have been on the // border, and is a candidate for a resize. if (isResizable() && button == 1 && - getGripDimension().isPointInRect(x, y) && - !getContentDimension().isPointInRect(x, y) && - hasMouse() && - !(mMouseDrag && y > (int)getPadding())) + getGripDimension().isPointInRect(x, y) && + !getContentDimension().isPointInRect(x, y) && + hasMouse() && + !(mMouseDrag && y > (int)getPadding())) { mMouseResize = true; mMouseXOffset = x; mMouseYOffset = y; - } } @@ -410,31 +410,26 @@ void Window::mouseRelease(int x, int y, int button) } } -gcn::Rectangle Window::getGripDimension () +gcn::Rectangle Window::getGripDimension() { - return gcn::Rectangle(getWidth() - resizeGrip->getWidth(), getHeight() - resizeGrip->getHeight(), getWidth(), + return gcn::Rectangle(getWidth() - resizeGrip->getWidth(), + getHeight() - resizeGrip->getHeight(), + getWidth(), getHeight()); } -void Window::setWindowName(std::string name) -{ - mWindowName = name; -} - -std::string Window::getWindowName() -{ - return mWindowName; -} - void Window::loadWindowState() { - setPosition((int)config.getValue(std::string(getWindowName() + "WinX"), getX()), - (int)config.getValue(std::string(getWindowName() + "WinY"), getY()) ); + const std::string &name = mWindowName; + + setPosition((int)config.getValue(name + "WinX", getX()), + (int)config.getValue(name + "WinY", getY())); - if ( resizable ) + if (resizable) { - setWidth((int)config.getValue(std::string(getWindowName() + "WinWidth"), getWidth()) ); - setHeight((int)config.getValue(std::string(getWindowName() + "WinHeight"), getHeight()) ); + setWidth((int)config.getValue(name + "WinWidth", getWidth())); + setHeight((int)config.getValue(name + "WinHeight", getHeight())); + if (mContent != NULL) { mContent->setDimension(getContentDimension()); @@ -442,21 +437,23 @@ void Window::loadWindowState() } } -void Window::setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight) +void Window::setDefaultSize(int defaultX, int defaultY, + int defaultWidth, int defaultHeight) { - this->defaultX = defaultX; - this->defaultY = defaultY; - this->defaultWidth = defaultWidth; - this->defaultHeight = defaultHeight; + mDefaultX = defaultX; + mDefaultY = defaultY; + mDefaultWidth = defaultWidth; + mDefaultHeight = defaultHeight; - setPosition(defaultX, defaultY); - setContentSize(defaultWidth, defaultHeight); + setPosition(mDefaultX, mDefaultY); + setContentSize(mDefaultWidth, mDefaultHeight); } void Window::resetToDefaultSize() { - setPosition(defaultX, defaultY); - setContentSize(defaultWidth, defaultHeight); + setPosition(mDefaultX, mDefaultY); + setContentSize(mDefaultWidth, mDefaultHeight); + if (mContent != NULL) { mContent->setDimension(getContentDimension()); diff --git a/src/gui/window.h b/src/gui/window.h index c1027518..66330350 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -147,31 +147,33 @@ class Window : public gcn::Window void scheduleDelete(); /** - * Window dragging and resizing mouse related. These methods also makes sure the - * window is not dragged/resized outside of the screen. + * Window dragging and resizing mouse related. These methods also makes + * sure the window is not dragged/resized outside of the screen. */ void mousePress(int x, int y, int button); void mouseMotion(int mx, int my); void mouseRelease(int x, int y, int button); /** - * The position of the resize grip + * Gets the position of the resize grip. */ gcn::Rectangle getGripDimension(); /** - * set Window internal name + * Sets the name of the window. This is not the window title. */ - void setWindowName(std::string name); + void + setWindowName(const std::string &name) { mWindowName = name; } /** - * Get window internal name + * Returns the name of the window. This is not the window title. */ - std::string getWindowName(); + const std::string& + getWindowName() { return mWindowName; } /** - * Read the X, Y, and Width and Height for resizables - * in the config based on its internal name. + * Read the x, y, and width and height for resizables in the config + * based on the name of the window. * That function let the values set with set{X, Y, Height, width}() * if no config value is found. * Don't forget to set these default values and resizable before @@ -184,7 +186,7 @@ class Window : public gcn::Window * (which can be different of the actual ones.) */ virtual void setDefaultSize(int defaultX, int defaultY, - int defaultWidth, int defaultHeight); + int defaultWidth, int defaultHeight); /** * Reset the win pos and size to default. @@ -195,20 +197,20 @@ class Window : public gcn::Window protected: gcn::Container *chrome; /**< Contained container */ Window *parent; /**< The parent window */ - std::string mWindowName; /**< Window internal name */ + std::string mWindowName; /**< Name of the window */ int snapSize; /**< Snap distance to window edge */ bool title; /**< Window has a title bar */ bool modal; /**< Window is modal */ bool resizable; /**< Window can be resized */ - bool mMouseResize; /**< Window is being resized */ - int minWinWidth; /**< Minimum window width */ int minWinHeight; /**< Minimum window height */ int maxWinWidth; /**< Maximum window width */ int maxWinHeight; /**< Maximum window height */ - int defaultX, defaultY; /**< Default Win Pos and size */ - int defaultWidth, defaultHeight; + int mDefaultX; /**< Default window X position */ + int mDefaultY; /**< Default window Y position */ + int mDefaultWidth; /**< Default window width */ + int mDefaultHeight; /**< Default window height */ /** The window container windows add themselves to. */ static WindowContainer* windowContainer; @@ -221,7 +223,7 @@ class Window : public gcn::Window static int instances; /**< Number of Window instances */ static ImageRect border; /**< The window border and background */ - static Image *resizeGrip; /**< The grip to resize window */ + static Image *resizeGrip; /**< The grip to resize window */ }; #endif diff --git a/src/map.cpp b/src/map.cpp index e74a3203..583a01be 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -25,6 +25,7 @@ #include "tileset.h" #include "being.h" #include "graphics.h" +#include "resources/image.h" #include @@ -103,7 +104,9 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer) { Image *img = getTile(x, y, layer); if (img) { - graphics->drawImage(img, x * 32 - scrollX, y * 32 - scrollY); + graphics->drawImage(img, + x * 32 - scrollX, + y * 32 - scrollY + 32 - img->getHeight()); } } } @@ -251,7 +254,7 @@ Map::findPath(int startX, int startY, int destX, int destY) // Declare open list, a list with open tiles sorted on F cost std::priority_queue openList; - // Return when destination not walkable + // Return empty path when destination not walkable if (!getWalk(destX, destY)) return path; // Reset starting tile's G cost to 0 @@ -266,8 +269,7 @@ Map::findPath(int startX, int startY, int destX, int destY) // Keep trying new open tiles until no more tiles to try or target found while (!openList.empty() && !foundPath) { - // Take the location with the lowest F cost from the open list, and - // add it to the closed list. + // Take the location with the lowest F cost from the open list. Location curr = openList.top(); openList.pop(); diff --git a/src/resources/buddylist.cpp b/src/resources/buddylist.cpp index 2e2cdea6..e41327a5 100644 --- a/src/resources/buddylist.cpp +++ b/src/resources/buddylist.cpp @@ -41,7 +41,7 @@ BuddyList::~BuddyList() delete filename; } -void BuddyList::loadFile(void) +void BuddyList::loadFile() { char *buddy; @@ -64,7 +64,7 @@ void BuddyList::loadFile(void) inputStream.close(); } -void BuddyList::saveFile(void) +void BuddyList::saveFile() { std::string str; @@ -121,7 +121,7 @@ bool BuddyList::removeBuddy(const std::string buddy) return false; } -int BuddyList::getNumberOfElements(void) +int BuddyList::getNumberOfElements() { return buddylist.size(); } diff --git a/src/resources/buddylist.h b/src/resources/buddylist.h index 33c85723..df5d6247 100644 --- a/src/resources/buddylist.h +++ b/src/resources/buddylist.h @@ -54,7 +54,7 @@ class BuddyList : public gcn::ListModel { /** * Returns the number of buddy on the list */ - int getNumberOfElements(void); + int getNumberOfElements(); /** * Returns the buddy of the number or null @@ -65,12 +65,12 @@ class BuddyList : public gcn::ListModel { /** * Save buddy to file */ - void saveFile(void); + void saveFile(); /** * Load buddy from file */ - void loadFile(void); + void loadFile(); std::list buddylist; /**< Buddy list */ std::list::iterator buddyit; /**< Iterator */ -- cgit v1.2.3-60-g2f50