diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-08-24 12:32:19 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-08-24 12:32:19 +0000 |
commit | 2debd445c71e65265359b6471795cab2cb2c7086 (patch) | |
tree | 695f276a3ae343f2a182dd2d3bb75afa6254f899 /src/gui | |
parent | 15c9ca70fa37dc8bae6b9ebd63209f5d0f7b0756 (diff) | |
download | mana-2debd445c71e65265359b6471795cab2cb2c7086.tar.gz mana-2debd445c71e65265359b6471795cab2cb2c7086.tar.bz2 mana-2debd445c71e65265359b6471795cab2cb2c7086.tar.xz mana-2debd445c71e65265359b6471795cab2cb2c7086.zip |
Added trimming of name for new character creation and of chat messages
appearing above players. Also improved resize mouse cursor indication, removing
duplicated code and fixing indicator above resize grip.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/char_select.cpp | 12 | ||||
-rw-r--r-- | src/gui/char_select.h | 23 | ||||
-rw-r--r-- | src/gui/chat.cpp | 2 | ||||
-rw-r--r-- | src/gui/window.cpp | 133 | ||||
-rw-r--r-- | src/gui/window.h | 12 |
5 files changed, 88 insertions, 94 deletions
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 */ |