summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/browserbox.h2
-rw-r--r--src/gui/widgets/button.h6
-rw-r--r--src/gui/widgets/channeltab.h3
-rw-r--r--src/gui/widgets/chattab.cpp14
-rw-r--r--src/gui/widgets/chattab.h8
-rw-r--r--src/gui/widgets/desktop.cpp8
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp2
-rw-r--r--src/gui/widgets/guildchattab.h3
-rw-r--r--src/gui/widgets/icon.h3
-rw-r--r--src/gui/widgets/layout.h4
-rw-r--r--src/gui/widgets/popup.h18
-rw-r--r--src/gui/widgets/progressbar.h6
-rw-r--r--src/gui/widgets/scrollarea.h3
-rw-r--r--src/gui/widgets/setupitem.cpp10
-rw-r--r--src/gui/widgets/setupitem.h4
-rw-r--r--src/gui/widgets/setuptabscroll.h2
-rw-r--r--src/gui/widgets/shoplistbox.h3
-rw-r--r--src/gui/widgets/tab.h4
-rw-r--r--src/gui/widgets/tabbedarea.h4
-rw-r--r--src/gui/widgets/textbox.h3
-rw-r--r--src/gui/widgets/textfield.cpp54
-rw-r--r--src/gui/widgets/textfield.h2
-rw-r--r--src/gui/widgets/vertcontainer.cpp7
-rw-r--r--src/gui/widgets/vertcontainer.h6
-rw-r--r--src/gui/widgets/window.cpp78
-rw-r--r--src/gui/widgets/window.h15
-rw-r--r--src/gui/widgets/windowcontainer.cpp12
-rw-r--r--src/gui/widgets/windowcontainer.h6
28 files changed, 171 insertions, 119 deletions
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index ab3049c0b..d82ebd758 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -187,7 +187,7 @@ class BrowserBox : public gcn::Widget,
TextRows &getRows()
{ return mTextRows; }
- bool hasRows()
+ bool hasRows() const
{ return !mTextRows.empty(); }
void setAlwaysUpdate(bool n)
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
index aed46bb55..560e46377 100644
--- a/src/gui/widgets/button.h
+++ b/src/gui/widgets/button.h
@@ -70,16 +70,16 @@ class Button : public gcn::Button, public gcn::WidgetListener
void setDescription(std::string text)
{ mDescription = text; }
- std::string getDescription()
+ std::string getDescription() const
{ return mDescription; }
- unsigned getClickCount()
+ unsigned getClickCount() const
{ return mClickCount; }
void setTag(int tag)
{ mTag = tag; }
- int getTag()
+ int getTag() const
{ return mTag; }
void widgetResized(const gcn::Event &event);
diff --git a/src/gui/widgets/channeltab.h b/src/gui/widgets/channeltab.h
index 4b56d2e05..39702a696 100644
--- a/src/gui/widgets/channeltab.h
+++ b/src/gui/widgets/channeltab.h
@@ -34,7 +34,8 @@ class ChannelTab : public ChatTab
{
public:
- Channel *getChannel() const { return mChannel; }
+ Channel *getChannel() const
+ { return mChannel; }
void showHelp();
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index aea367482..6d5dfc9dd 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -224,9 +224,17 @@ void ChatTab::chatLog(std::string line, Own own,
{
struct tm *timeInfo;
timeInfo = localtime(&t);
- line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(),
- timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(),
- tmp.text.c_str());
+ if (timeInfo)
+ {
+ line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(),
+ timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(),
+ tmp.text.c_str());
+ }
+ else
+ {
+ line = strprintf("%s %s%s", lineColor.c_str(),
+ tmp.nick.c_str(), tmp.text.c_str());
+ }
}
else
{
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index ddf10bf5e..912305a63 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -137,24 +137,24 @@ class ChatTab : public Tab
std::list<std::string> &getRows()
{ return mTextOutput->getRows(); }
- bool hasRows()
+ bool hasRows() const
{ return mTextOutput->hasRows(); }
void loadFromLogFile(std::string name);
- bool getAllowHighlight()
+ bool getAllowHighlight() const
{ return mAllowHightlight; }
void setAllowHighlight(bool n)
{ mAllowHightlight = n; }
- bool getRemoveNames()
+ bool getRemoveNames() const
{ return mRemoveNames; }
void setRemoveNames(bool n)
{ mRemoveNames = n; }
- bool getNoAway()
+ bool getNoAway() const
{ return mNoAway; }
void setNoAway(bool n)
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index beb232fb2..b40558c78 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -48,10 +48,14 @@ Desktop::Desktop() :
std::string appName = branding.getValue("appName", std::string(""));
if (appName.empty())
+ {
mVersionLabel = new Label(FULL_VERSION);
+ }
else
- mVersionLabel = new Label(strprintf("%s (Mana %s)", appName.c_str(),
- FULL_VERSION));
+ {
+ mVersionLabel = new Label(strprintf("%s (%s)", FULL_VERSION,
+ appName.c_str()));
+ }
mVersionLabel->setBackgroundColor(
Theme::getThemeColor(Theme::BACKGROUND, 128));
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index e8d7bb7e3..794357275 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -43,7 +43,7 @@
#include "debug.h"
-static const int MAX_ITEMS = 44;
+static const int MAX_ITEMS = 48;
EmoteShortcutContainer::EmoteShortcutContainer():
ShortcutContainer(),
diff --git a/src/gui/widgets/guildchattab.h b/src/gui/widgets/guildchattab.h
index bebdaa1f3..be6f4d034 100644
--- a/src/gui/widgets/guildchattab.h
+++ b/src/gui/widgets/guildchattab.h
@@ -41,7 +41,8 @@ class GuildChatTab : public ChatTab
void saveToLogFile(std::string &msg);
- int getType() const { return ChatTab::TAB_GUILD; }
+ int getType() const
+ { return ChatTab::TAB_GUILD; }
protected:
void handleInput(const std::string &msg);
diff --git a/src/gui/widgets/icon.h b/src/gui/widgets/icon.h
index 6f05da3f7..98fee314a 100644
--- a/src/gui/widgets/icon.h
+++ b/src/gui/widgets/icon.h
@@ -48,7 +48,8 @@ class Icon : public gcn::Widget
/**
* Gets the current Image.
*/
- Image *getImage() const { return mImage; }
+ Image *getImage() const
+ { return mImage; }
/**
* Sets the image to display.
diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h
index 02fed43b5..046d09b59 100644
--- a/src/gui/widgets/layout.h
+++ b/src/gui/widgets/layout.h
@@ -266,10 +266,10 @@ class LayoutCell
void setType(int t)
{ mType = t; }
- int getWidth()
+ int getWidth() const
{ return mExtent[0]; }
- int getHeight()
+ int getHeight() const
{ return mExtent[1]; }
void setWidth(int w)
diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h
index 8ff21149a..5572abd03 100644
--- a/src/gui/widgets/popup.h
+++ b/src/gui/widgets/popup.h
@@ -94,28 +94,32 @@ class Popup : public Container, public gcn::MouseListener,
*/
void setMinWidth(int width);
- int getMinWidth() const { return mMinWidth; }
+ int getMinWidth() const
+ { return mMinWidth; }
/**
* Sets the minimum height of the popup.
*/
void setMinHeight(int height);
- int getMinHeight() const { return mMinHeight; }
+ int getMinHeight() const
+ { return mMinHeight; }
/**
* Sets the maximum width of the popup.
*/
void setMaxWidth(int width);
- int getMaxWidth() const { return mMaxWidth; }
+ int getMaxWidth() const
+ { return mMaxWidth; }
/**
* Sets the minimum height of the popup.
*/
void setMaxHeight(int height);
- int getMaxHeight() const { return mMaxHeight; }
+ int getMaxHeight() const
+ { return mMaxHeight; }
/**
* Gets the padding of the popup. The padding is the distance between
@@ -124,9 +128,11 @@ class Popup : public Container, public gcn::MouseListener,
* @return The padding of the popup.
* @see setPadding
*/
- int getPadding() const { return mPadding; }
+ int getPadding() const
+ { return mPadding; }
- void setPadding(int padding) { mPadding = padding; }
+ void setPadding(int padding)
+ { mPadding = padding; }
/**
* Sets the name of the popup. This is only useful for debug purposes.
diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h
index 163310245..603df6157 100644
--- a/src/gui/widgets/progressbar.h
+++ b/src/gui/widgets/progressbar.h
@@ -73,7 +73,8 @@ class ProgressBar : public gcn::Widget, public gcn::WidgetListener
/**
* Returns the current progress.
*/
- float getProgress() const { return mProgress; }
+ float getProgress() const
+ { return mProgress; }
/**
* Change the ProgressPalette for this ProgressBar to follow or -1 to
@@ -89,7 +90,8 @@ class ProgressBar : public gcn::Widget, public gcn::WidgetListener
/**
* Returns the color of the progress bar.
*/
- const gcn::Color &getColor() const { return mColor; }
+ const gcn::Color &getColor() const
+ { return mColor; }
/**
* Sets the text shown on the progress bar.
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
index 86902b5c9..582033071 100644
--- a/src/gui/widgets/scrollarea.h
+++ b/src/gui/widgets/scrollarea.h
@@ -89,7 +89,8 @@ class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener
/**
* Returns whether the widget draws its background or not.
*/
- bool isOpaque() const { return mOpaque; }
+ bool isOpaque() const
+ { return mOpaque; }
/**
* Called when the mouse moves in the widget area.
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
index 92ff625c2..059b05ba2 100644
--- a/src/gui/widgets/setupitem.cpp
+++ b/src/gui/widgets/setupitem.cpp
@@ -192,7 +192,7 @@ void SetupItemCheckBox::createControls()
load();
mCheckBox = new CheckBox(mText, mValue != "0", mParent, mEventName);
mWidget = mCheckBox;
- mParent->getContainer()->add(mWidget);
+ mParent->getContainer()->add1(mWidget);
mParent->addControl(this);
mParent->addActionListener(this);
mWidget->addActionListener(this);
@@ -275,7 +275,7 @@ void SetupItemTextField::createControls()
mHorizont->add(mTextField);
mHorizont->add(mButton);
- mParent->getContainer()->add(mHorizont, true, 4);
+ mParent->getContainer()->add2(mHorizont, true, 4);
mParent->addControl(this);
mParent->addControl(this, mEventName + "_EDIT");
mParent->addControl(this, mEventName + "_EDIT_OK");
@@ -398,7 +398,7 @@ void SetupItemIntTextField::createControls()
mHorizont->add(mTextField);
mHorizont->add(mButton);
- mParent->getContainer()->add(mHorizont, true, 4);
+ mParent->getContainer()->add2(mHorizont, true, 4);
mParent->addControl(this);
mParent->addControl(this, mEventName + "_EDIT");
mParent->addControl(this, mEventName + "_EDIT_OK");
@@ -486,7 +486,7 @@ void SetupItemLabel::createControls()
}
mWidget = mLabel;
- mParent->getContainer()->add(mWidget);
+ mParent->getContainer()->add1(mWidget);
mParent->addControl(this);
mParent->addActionListener(this);
mWidget->addActionListener(this);
@@ -568,7 +568,7 @@ void SetupItemDropDown::createControls()
mHorizont->add(mLabel);
mHorizont->add(mDropDown);
- mParent->getContainer()->add(mHorizont, true, 4);
+ mParent->getContainer()->add2(mHorizont, true, 4);
mParent->addControl(this);
mParent->addActionListener(this);
mWidget->addActionListener(this);
diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h
index eb2680ede..71856d6e2 100644
--- a/src/gui/widgets/setupitem.h
+++ b/src/gui/widgets/setupitem.h
@@ -75,7 +75,7 @@ class SetupItem : public gcn::ActionListener
void setWidget(gcn::Widget *widget)
{ mWidget = widget; }
- gcn::Widget *getWidget()
+ gcn::Widget *getWidget() const
{ return mWidget; }
Configuration *getConfig();
@@ -93,7 +93,7 @@ class SetupItem : public gcn::ActionListener
virtual void externalUpdated(std::string eventName);
// virtual int add(ContainerPlacer &place, int x, int y, int width);
- bool isMainConfig()
+ bool isMainConfig() const
{ return mMainConfig; }
protected:
diff --git a/src/gui/widgets/setuptabscroll.h b/src/gui/widgets/setuptabscroll.h
index 4ad1f464b..d471ecfbc 100644
--- a/src/gui/widgets/setuptabscroll.h
+++ b/src/gui/widgets/setuptabscroll.h
@@ -43,7 +43,7 @@ class SetupTabScroll : public SetupTab
void addControl(SetupItem *widget, std::string event);
- VertContainer *getContainer()
+ VertContainer *getContainer() const
{ return mContainer; }
virtual void apply();
diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h
index 9b416d3a3..694fdb92e 100644
--- a/src/gui/widgets/shoplistbox.h
+++ b/src/gui/widgets/shoplistbox.h
@@ -56,7 +56,8 @@ class ShopListBox : public ListBox
/**
* Returns the height of a row.
*/
- unsigned int getRowHeight() const { return mRowHeight; }
+ unsigned int getRowHeight() const
+ { return mRowHeight; }
/**
* gives information about the current player's money
diff --git a/src/gui/widgets/tab.h b/src/gui/widgets/tab.h
index 40b46ede5..829689543 100644
--- a/src/gui/widgets/tab.h
+++ b/src/gui/widgets/tab.h
@@ -61,7 +61,7 @@ class Tab : public gcn::Tab, public gcn::WidgetListener
*/
void setFlash(int flash);
- int getFlash()
+ int getFlash() const
{ return mFlash; }
void widgetResized(const gcn::Event &event);
@@ -70,7 +70,7 @@ class Tab : public gcn::Tab, public gcn::WidgetListener
void setLabelFont(gcn::Font *font);
- gcn::Label *getLabel()
+ gcn::Label *getLabel() const
{ return mLabel; }
protected:
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index b202dfc9d..cceaf56b7 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -136,13 +136,13 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener
void setRightMargin(int n)
{ mRightMargin = n; }
- int getRightMargin()
+ int getRightMargin() const
{ return mRightMargin; }
void setFollowDownScroll(bool n)
{ mFollowDownScroll = n; }
- bool getFollowDownScroll()
+ bool getFollowDownScroll() const
{ return mFollowDownScroll; }
void fixSize()
diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h
index 6d2467b38..a052247c4 100644
--- a/src/gui/widgets/textbox.h
+++ b/src/gui/widgets/textbox.h
@@ -59,7 +59,8 @@ class TextBox : public gcn::TextBox
*/
inline void draw(gcn::Graphics *graphics)
{
- setForegroundColor(*mTextColor);
+ if (mTextColor)
+ setForegroundColor(*mTextColor);
gcn::TextBox::draw(graphics);
}
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 03fdb5378..4dba2eb57 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -183,7 +183,7 @@ int TextField::getValue() const
if (value < mMinimum)
return mMinimum;
- if (value > mMaximum)
+ if (value > (signed)mMaximum)
return mMaximum;
return value;
@@ -195,29 +195,43 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
if (val >= 32)
{
- int l;
- if (val < 128)
- l = 1; // 0xxxxxxx
- else if (val < 0x800)
- l = 2; // 110xxxxx 10xxxxxx
- else if (val < 0x10000)
- l = 3; // 1110xxxx 10xxxxxx 10xxxxxx
- else
- l = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-
- char buf[4];
- for (int i = 0; i < l; ++i)
+ if (mNumeric)
{
- buf[i] = static_cast<char>(val >> (6 * (l - i - 1)));
- if (i > 0)
- buf[i] = static_cast<char>((buf[i] & 63) | 128);
+ if ((val >= '0' && val <= '9') || (val == '-' && !mCaretPosition))
+ {
+ char buf[2];
+ buf[0] = val;
+ buf[1] = 0;
+ mText.insert(mCaretPosition, std::string(buf));
+ mCaretPosition += 1;
+ }
}
+ else if (!mMaximum || mText.size() < mMaximum)
+ {
+ int l;
+ if (val < 128)
+ l = 1; // 0xxxxxxx
+ else if (val < 0x800)
+ l = 2; // 110xxxxx 10xxxxxx
+ else if (val < 0x10000)
+ l = 3; // 1110xxxx 10xxxxxx 10xxxxxx
+ else
+ l = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+
+ char buf[4];
+ for (int i = 0; i < l; ++i)
+ {
+ buf[i] = static_cast<char>(val >> (6 * (l - i - 1)));
+ if (i > 0)
+ buf[i] = static_cast<char>((buf[i] & 63) | 128);
+ }
- if (l > 1)
- buf[0] |= static_cast<char>(255 << (8 - l));
+ if (l > 1)
+ buf[0] |= static_cast<char>(255 << (8 - l));
- mText.insert(mCaretPosition, std::string(buf, buf + l));
- mCaretPosition += l;
+ mText.insert(mCaretPosition, std::string(buf, buf + l));
+ mCaretPosition += l;
+ }
}
/* In UTF-8, 10xxxxxx is only used for inner parts of characters. So skip
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index bc1123f19..fef606526 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -114,7 +114,7 @@ class TextField : public gcn::TextField
static ImageRect skin;
bool mNumeric;
int mMinimum;
- int mMaximum;
+ unsigned mMaximum;
bool mLoseFocusOnTab;
int mLastEventPaste;
};
diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp
index 305343d1a..0eb59c8f9 100644
--- a/src/gui/widgets/vertcontainer.cpp
+++ b/src/gui/widgets/vertcontainer.cpp
@@ -35,12 +35,12 @@ VertContainer::VertContainer(int verticalItemSize, bool resizable,
addWidgetListener(this);
}
-void VertContainer::add(gcn::Widget *widget, int spacing)
+void VertContainer::add1(gcn::Widget *widget, int spacing)
{
- add(widget, mResizable, spacing);
+ add2(widget, mResizable, spacing);
}
-void VertContainer::add(gcn::Widget *widget, bool resizable, int spacing)
+void VertContainer::add2(gcn::Widget *widget, bool resizable, int spacing)
{
if (!widget)
return;
@@ -70,6 +70,7 @@ void VertContainer::clear()
mCount = 0;
mNextY = 0;
+ mResizableWidgets.clear();
}
void VertContainer::widgetResized(const gcn::Event &event A_UNUSED)
diff --git a/src/gui/widgets/vertcontainer.h b/src/gui/widgets/vertcontainer.h
index 6e1305a06..b4e43d31d 100644
--- a/src/gui/widgets/vertcontainer.h
+++ b/src/gui/widgets/vertcontainer.h
@@ -39,10 +39,10 @@ class VertContainer : public Container, public gcn::WidgetListener
VertContainer(int verticalItemSize, bool resizable = true,
int leftSpacing = 0);
- virtual void add(gcn::Widget *widget, bool resizable,
- int spacing = -1);
+ virtual void add2(gcn::Widget *widget, bool resizable,
+ int spacing = -1);
- virtual void add(gcn::Widget *widget, int spacing = -1);
+ virtual void add1(gcn::Widget *widget, int spacing = -1);
virtual void clear();
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 3858b0d81..6e6918694 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -433,7 +433,7 @@ void Window::setVisible(bool visible, bool forceSticky)
// Check if the window is off screen...
if (visible)
- checkIfIsOffScreen();
+ ensureOnScreen();
if (isStickyButtonLock())
gcn::Window::setVisible(visible);
@@ -713,7 +713,7 @@ void Window::loadWindowState()
}
// Check if the window is off screen...
- checkIfIsOffScreen();
+ ensureOnScreen();
if (viewport)
{
@@ -848,6 +848,22 @@ void Window::resetToDefaultSize()
saveWindowState();
}
+void Window::adjustPositionAfterResize(int oldScreenWidth, int oldScreenHeight)
+{
+ gcn::Rectangle dimension = getDimension();
+
+ // If window was aligned to the right or bottom, keep it there
+ const int rightMargin = oldScreenWidth - (getX() + getWidth());
+ const int bottomMargin = oldScreenHeight - (getY() + getHeight());
+ if (getX() > 0 && getX() > rightMargin)
+ dimension.x = mainGraphics->mWidth - rightMargin - getWidth();
+ if (getY() > 0 && getY() > bottomMargin)
+ dimension.y = mainGraphics->mHeight - bottomMargin - getHeight();
+
+ setDimension(dimension);
+ ensureOnScreen();
+}
+
int Window::getResizeHandles(gcn::MouseEvent &event)
{
if ((mStickyButtonLock && mSticky) || event.getX() < 0 || event.getY() < 0)
@@ -972,57 +988,27 @@ void Window::centerHorisontally()
setLocationHorisontallyRelativeTo(getParent());
}
-void Window::checkIfIsOffScreen(bool partially, bool entirely)
+void Window::ensureOnScreen()
{
- // Move the window onto screen if it has become off screen
- // For instance, because of resolution change...
-
- // First of all, don't deal when a window hasn't got
- // any size initialized yet...
+ // Skip when a window hasn't got any size initialized yet
if (getWidth() == 0 && getHeight() == 0)
return;
- // Made partially the default behaviour
- if (!partially && !entirely)
- partially = true;
-
- // Keep guichan window inside screen (supports resizing any side)
-
- gcn::Rectangle winDimension = getDimension();
-
- if (winDimension.x < 0)
- {
- winDimension.width += winDimension.x;
- winDimension.x = 0;
- }
- if (winDimension.y < 0)
- {
- winDimension.height += winDimension.y;
- winDimension.y = 0;
- }
-
- // Look if the window is partially off-screen limits...
- if (partially)
- {
- if (winDimension.x + winDimension.width > mainGraphics->mWidth)
- winDimension.x = mainGraphics->mWidth - winDimension.width;
-
- if (winDimension.y + winDimension.height > mainGraphics->mHeight)
- winDimension.y = mainGraphics->mHeight - winDimension.height;
+ gcn::Rectangle dimension = getDimension();
- setDimension(winDimension);
- return;
- }
+ // Check the left and bottom screen boundaries
+ if (dimension.x + dimension.width > mainGraphics->mWidth)
+ dimension.x = mainGraphics->mWidth - dimension.width;
+ if (dimension.y + dimension.height > mainGraphics->mHeight)
+ dimension.y = mainGraphics->mHeight - dimension.height;
- if (entirely)
- {
- if (winDimension.x > mainGraphics->mWidth)
- winDimension.x = mainGraphics->mWidth - winDimension.width;
+ // But never allow the windows to disappear in to the right and top
+ if (dimension.x < 0)
+ dimension.x = 0;
+ if (dimension.y < 0)
+ dimension.y = 0;
- if (winDimension.y > mainGraphics->mHeight)
- winDimension.y = mainGraphics->mHeight - winDimension.height;
- }
- setDimension(winDimension);
+ setDimension(dimension);
}
gcn::Rectangle Window::getWindowArea()
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index 65dbf196b..6fa47dedc 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -329,6 +329,13 @@ class Window : public gcn::Window, gcn::WidgetListener
virtual void resetToDefaultSize();
/**
+ * Adjusts the window position after the application window has been
+ * resized.
+ */
+ void adjustPositionAfterResize(int oldScreenWidth,
+ int oldScreenHeight);
+
+ /**
* Gets the layout handler for this window.
*/
Layout &getLayout();
@@ -406,11 +413,11 @@ class Window : public gcn::Window, gcn::WidgetListener
};
/**
- * Check if the window is off-screen and then move it to be visible
- * again. This is internally used by loadWindowState
- * and setVisible(true) members.
+ * Ensures the window is on the screen, moving it if necessary. This is
+ * used by loadWindowState and setVisible(true), and when the screen
+ * is resized.
*/
- void checkIfIsOffScreen(bool partially = true, bool entirely = true);
+ void ensureOnScreen();
/**
* Determines if the mouse is in a resize area and returns appropriate
diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp
index 43aaea8a4..9e698ffa6 100644
--- a/src/gui/widgets/windowcontainer.cpp
+++ b/src/gui/widgets/windowcontainer.cpp
@@ -22,6 +22,8 @@
#include "gui/widgets/windowcontainer.h"
+#include "gui/widgets/window.h"
+
#include "utils/dtor.h"
#include "debug.h"
@@ -41,3 +43,13 @@ void WindowContainer::scheduleDelete(gcn::Widget *widget)
if (widget)
mDeathList.push_back(widget);
}
+
+void WindowContainer::adjustAfterResize(int oldScreenWidth,
+ int oldScreenHeight)
+{
+ for (WidgetListIterator i = mWidgets.begin(); i != mWidgets.end(); ++i)
+ {
+ if (Window *window = dynamic_cast<Window*>(*i))
+ window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
+ }
+}
diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h
index 00ef04c19..1cec11861 100644
--- a/src/gui/widgets/windowcontainer.h
+++ b/src/gui/widgets/windowcontainer.h
@@ -48,6 +48,12 @@ class WindowContainer : public Container
*/
void scheduleDelete(gcn::Widget *widget);
+ /**
+ * Ensures that all visible windows are on the screen after the screen
+ * has been resized.
+ */
+ void adjustAfterResize(int oldScreenWidth, int oldScreenHeight);
+
private:
/**
* List of widgets that are scheduled to be deleted.