summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--src/gui/char_select.cpp12
-rw-r--r--src/gui/char_select.h23
-rw-r--r--src/gui/chat.cpp2
-rw-r--r--src/gui/window.cpp133
-rw-r--r--src/gui/window.h12
-rw-r--r--src/net/chathandler.cpp2
-rw-r--r--src/utils/trim.h7
8 files changed, 103 insertions, 95 deletions
diff --git a/ChangeLog b/ChangeLog
index 3cfeef3c..c2359fc7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,13 @@
instance so there is no point in supporting a shared resource.
* src/gui/window.cpp, src/gui/gui.h: Removed unnecessary
Gui::isCustomCursor method.
+ * src/gui/char_select.h, src/gui/char_select.cpp, src/utils/trim.h:
+ Added trimming of name for new character creation.
+ * src/net/chathandler.cpp: Added trimming of chat messages appearing
+ above players.
+ * src/gui/window.cpp, src/gui/window.h: Improved resize mouse cursor
+ indication, removing duplicated code and fixing indicator above resize
+ grip.
2007-08-23 Bjørn Lindeijer <bjorn@lindeijer.nl>
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index fc6be59f..fe260561 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -41,6 +41,7 @@
#include "../net/messageout.h"
#include "../utils/tostring.h"
+#include "../utils/trim.h"
// Defined in main.cpp, used here for setting the char create dialog
extern CharServerHandler charServerHandler;
@@ -249,11 +250,6 @@ bool CharSelectDialog::selectByName(const std::string &name)
return false;
}
-std::string CharSelectDialog::getName()
-{
- return mNameLabel->getCaption();
-}
-
CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
unsigned char sex):
Window("Create Character", true, parent), mNetwork(network), mSlot(slot)
@@ -357,10 +353,12 @@ CharCreateDialog::action(const gcn::ActionEvent &event)
}
}
-const std::string&
+std::string
CharCreateDialog::getName()
{
- return mNameField->getText();
+ std::string name = mNameField->getText();
+ trim(name);
+ return name;
}
void
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index 754362c3..00b1c51d 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -60,11 +60,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener
bool selectByName(const std::string &name);
- /**
- * Returns name of selected player
- */
- std::string getName();
-
private:
Network *mNetwork;
LockedArray<LocalPlayer*> *mCharInfo;
@@ -119,9 +114,6 @@ class CharCreateDialog : public Window, public gcn::ActionListener
void
action(const gcn::ActionEvent &event);
- const std::string&
- getName();
-
/**
* Unlocks the dialog, enabling the create character button again.
*/
@@ -129,6 +121,16 @@ class CharCreateDialog : public Window, public gcn::ActionListener
unlock();
private:
+ /**
+ * Returns the name of the character to create.
+ */
+ std::string getName();
+
+ /**
+ * Communicate character creation to the server.
+ */
+ void attemptCharCreate();
+
Network *mNetwork;
gcn::TextField *mNameField;
gcn::Label *mNameLabel;
@@ -145,11 +147,6 @@ class CharCreateDialog : public Window, public gcn::ActionListener
PlayerBox *mPlayerBox;
int mSlot;
-
- /**
- * Communicate character creation to the server.
- */
- void attemptCharCreate();
};
#endif
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index d760f18d..0eb250e7 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -97,7 +97,7 @@ void
ChatWindow::chatLog(std::string line, int own)
{
// Delete overhead from the end of the list
- while ((int)mChatlog.size() > mItemsKeep) {
+ while ((int) mChatlog.size() > mItemsKeep) {
mChatlog.pop_back();
}
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 7df5e3ac..8cacd23e 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -345,63 +345,46 @@ void Window::mousePressed(gcn::MouseEvent &event)
// Let Guichan move window to top and figure out title bar drag
gcn::Window::mousePressed(event);
- const int x = event.getX();
- const int y = event.getY();
- mouseResize = 0;
-
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- // Close Button Handler
+ const int x = event.getX();
+ const int y = event.getY();
+
+ // Handle close button
if (mCloseButton)
{
- gcn::Rectangle tCloseButtonRect(
+ gcn::Rectangle closeButtonRect(
getWidth() - closeImage->getWidth() - getPadding(),
getPadding(),
closeImage->getWidth(),
- closeImage->getHeight()
- );
- if (tCloseButtonRect.isPointInRect(x, y))
+ closeImage->getHeight());
+
+ if (closeButtonRect.isPointInRect(x, y))
{
setVisible(false);
- return;
}
}
- // Resize Window Handler
- if (mResizable &&
- event.getSource() == this &&
- !getChildrenArea().isPointInRect(x, y))
- {
- mouseResize |= (x > getWidth() - resizeBorderWidth) ? RIGHT :
- (x < resizeBorderWidth) ? LEFT : 0;
- mouseResize |= (y > getHeight() - resizeBorderWidth) ? BOTTOM :
- (y < resizeBorderWidth) ? TOP : 0;
- return;
- }
- if (event.getSource() == mGrip &&
- event.getButton() == gcn::MouseEvent::LEFT)
- {
- mDragOffsetX = x;
- mDragOffsetY = y;
- mouseResize |= BOTTOM | RIGHT;
- mIsMoving = false;
- }
+
+ // Handle window resizing
+ mouseResize = getResizeHandles(event);
}
}
void Window::mouseReleased(gcn::MouseEvent &event)
{
- if (mResizable &&
- mouseResize)
+ if (mResizable && mouseResize)
{
mouseResize = 0;
gui->setCursorType(Gui::CURSOR_POINTER);
}
+
+ // This should be the responsibility of Guichan (and is from 0.8.0 on)
+ mIsMoving = false;
}
void Window::mouseExited(gcn::MouseEvent &event)
{
- if (mResizable &&
- !mouseResize)
+ if (mResizable && !mouseResize)
{
gui->setCursorType(Gui::CURSOR_POINTER);
}
@@ -409,47 +392,26 @@ void Window::mouseExited(gcn::MouseEvent &event)
void Window::mouseMoved(gcn::MouseEvent &event)
{
- const int x = event.getX();
- const int y = event.getY();
+ int resizeHandles = getResizeHandles(event);
- // changes the custom mouse cursor based on it's current position.
- if (mResizable &&
- !mouseResize)
+ // Changes the custom mouse cursor based on it's current position.
+ switch (resizeHandles)
{
- gcn::Rectangle tContainerRect(
- getPadding(),
- getPadding(),
- getWidth()-(getPadding() * 2),
- getHeight()-(getPadding() * 2)
- );
- if (!tContainerRect.isPointInRect(x, y))
- {
- int tMouseResize = 0;
- tMouseResize |= (x > getWidth() - resizeBorderWidth) ? RIGHT :
- (x < resizeBorderWidth) ? LEFT : 0;
- tMouseResize |= (y > getHeight() - resizeBorderWidth) ? BOTTOM :
- (y < resizeBorderWidth) ? TOP : 0;
- switch (tMouseResize)
- {
- case BOTTOM | RIGHT:
- gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_RIGHT);
- break;
- case BOTTOM | LEFT:
- gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_LEFT);
- break;
- case BOTTOM:
- gui->setCursorType(Gui::CURSOR_RESIZE_DOWN);
- break;
- case RIGHT:
- case LEFT:
- gui->setCursorType(Gui::CURSOR_RESIZE_ACROSS);
- break;
- }
- }
- else
- {
+ case BOTTOM | RIGHT:
+ gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_RIGHT);
+ break;
+ case BOTTOM | LEFT:
+ gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_LEFT);
+ break;
+ case BOTTOM:
+ gui->setCursorType(Gui::CURSOR_RESIZE_DOWN);
+ break;
+ case RIGHT:
+ case LEFT:
+ gui->setCursorType(Gui::CURSOR_RESIZE_ACROSS);
+ break;
+ default:
gui->setCursorType(Gui::CURSOR_POINTER);
- }
}
}
@@ -570,3 +532,32 @@ void Window::resetToDefaultSize()
setPosition(mDefaultX, mDefaultY);
setContentSize(mDefaultWidth, mDefaultHeight);
}
+
+int Window::getResizeHandles(gcn::MouseEvent &event)
+{
+ int resizeHandles = 0;
+ const int y = event.getY();
+
+ if (mResizable && y > (int) mTitleBarHeight)
+ {
+ const int x = event.getX();
+
+ if (!getChildrenArea().isPointInRect(x, y) &&
+ event.getSource() == this)
+ {
+ resizeHandles |= (x > getWidth() - resizeBorderWidth) ? RIGHT :
+ (x < resizeBorderWidth) ? LEFT : 0;
+ resizeHandles |= (y > getHeight() - resizeBorderWidth) ? BOTTOM :
+ (y < resizeBorderWidth) ? TOP : 0;
+ }
+
+ if (event.getSource() == mGrip)
+ {
+ mDragOffsetX = x;
+ mDragOffsetY = y;
+ resizeHandles |= BOTTOM | RIGHT;
+ }
+ }
+
+ return resizeHandles;
+}
diff --git a/src/gui/window.h b/src/gui/window.h
index 5e8d8010..625d7541 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -175,7 +175,6 @@ class Window : public gcn::Window
* Overloads window setVisible by Guichan to allow sticky window
* handling.
*/
-
void setVisible(bool visible);
/**
@@ -265,6 +264,15 @@ class Window : public gcn::Window
};
protected:
+ /**
+ * Determines if the mouse is in a resize area and returns appropriate
+ * resize handles. Also initializes drag offset in case the resize
+ * grip is used.
+ *
+ * @see ResizeHandles
+ */
+ int getResizeHandles(gcn::MouseEvent &event);
+
GCContainer *mChrome; /**< Contained container */
ResizeGrip *mGrip; /**< Resize grip */
Window *mParent; /**< The parent window */
@@ -291,8 +299,8 @@ class Window : public gcn::Window
*/
static ConfigListener *windowConfigListener;
+ static int mouseResize; /**< Active resize handles */
static int instances; /**< Number of Window instances */
- static int mouseResize; /**< Window is being resized */
static ImageRect border; /**< The window border and background */
static Image *closeImage; /**< Close Button Image */
diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp
index 9095a4e1..c8f52e2b 100644
--- a/src/net/chathandler.cpp
+++ b/src/net/chathandler.cpp
@@ -36,6 +36,7 @@
#include "../gui/chat.h"
#include "../utils/tostring.h"
+#include "../utils/trim.h"
extern Being *player_node;
@@ -73,6 +74,7 @@ void ChatHandler::handleMessage(MessageIn *msg)
chatMsg = msg->readString(chatMsgLength);
chatWindow->chatLog(chatMsg, BY_OTHER);
chatMsg.erase(0, chatMsg.find(" : ", 0) + 3);
+ trim(chatMsg);
being->setSpeech(chatMsg, SPEECH_TIME);
break;
diff --git a/src/utils/trim.h b/src/utils/trim.h
index 19d37909..1b5311e6 100644
--- a/src/utils/trim.h
+++ b/src/utils/trim.h
@@ -21,6 +21,9 @@
* $Id$
*/
+#ifndef _TMW_UTILS_TRIM_H_
+#define _TMW_UTILS_TRIM_H_
+
#include <string>
/**
@@ -28,7 +31,7 @@
*
* @param str the string to trim spaces off
*/
-void trim(std::string &str)
+static void trim(std::string &str)
{
std::string::size_type pos = str.find_last_not_of(' ');
if (pos != std::string::npos)
@@ -46,3 +49,5 @@ void trim(std::string &str)
str.clear();
}
}
+
+#endif