summaryrefslogtreecommitdiff
path: root/src/gui/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/window.cpp')
-rw-r--r--src/gui/window.cpp117
1 files changed, 23 insertions, 94 deletions
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 7629e2e7..75288eb5 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -106,7 +106,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
instances++;
- setBorderSize(0);
+ setFrameSize(0);
setPadding(3);
setTitleBarHeight(20);
@@ -121,6 +121,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
// Windows are invisible by default
setVisible(false);
+
+ addWidgetListener(this);
}
Window::~Window()
@@ -202,84 +204,12 @@ void Window::draw(gcn::Graphics *graphics)
drawChildren(graphics);
}
-void Window::setContentWidth(int width)
-{
- setWidth(width + 2 * getPadding());
-}
-
-void Window::setContentHeight(int height)
-{
- setHeight(height + getPadding() + getTitleBarHeight());
-}
-
void Window::setContentSize(int width, int height)
{
setSize(width + 2 * getPadding(),
height + getPadding() + getTitleBarHeight());
}
-void Window::setSize(int width, int height)
-{
- if (width == mDimension.width && height == mDimension.height) return;
-
- // No call to ancestor! Infinite loop otherwise.
- mDimension.width = width;
- mDimension.height = height;
-
- if (mGrip)
- {
- gcn::Rectangle const &area = getChildrenArea();
- mGrip->setPosition(width - mGrip->getWidth() - area.x,
- height - mGrip->getHeight() - area.y);
- }
-
- if (mLayout)
- {
- int w = width - 2 * getPadding(),
- h = height - getPadding() - getTitleBarHeight();
- mLayout->reflow(w, h);
- }
-
- fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED));
-}
-
-void Window::setWidth(int width)
-{
- setSize(width, mDimension.height);
-}
-
-void Window::setHeight(int height)
-{
- setSize(mDimension.width, height);
-}
-
-void Window::setPosition(int x, int y)
-{
- if (x == mDimension.x && y == mDimension.y) return;
-
- // No call to ancestor!
- mDimension.x = x;
- mDimension.y = y;
-
- fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED));
-}
-
-void Window::setDimension(const gcn::Rectangle &dimension)
-{
- setPosition(dimension.x, dimension.y);
- setSize(dimension.width, dimension.height);
-}
-
-void Window::setX(int x)
-{
- setPosition(x, mDimension.y);
-}
-
-void Window::setY(int y)
-{
- setPosition(mDimension.x, y);
-}
-
void Window::setLocationRelativeTo(gcn::Widget *widget)
{
int wx, wy;
@@ -331,6 +261,23 @@ void Window::setResizable(bool r)
}
}
+void Window::widgetResized(const gcn::Event &event)
+{
+ if (mGrip)
+ {
+ gcn::Rectangle const &area = getChildrenArea();
+ mGrip->setPosition(getWidth() - mGrip->getWidth() - area.x,
+ getHeight() - mGrip->getHeight() - area.y);
+ }
+
+ if (mLayout)
+ {
+ int w = getWidth() - 2 * getPadding();
+ int h = getHeight() - getPadding() - getTitleBarHeight();
+ mLayout->reflow(w, h);
+ }
+}
+
void Window::setCloseButton(bool flag)
{
mCloseButton = flag;
@@ -407,7 +354,7 @@ void Window::mouseReleased(gcn::MouseEvent &event)
}
// This should be the responsibility of Guichan (and is from 0.8.0 on)
- mIsMoving = false;
+ mMoved = false;
}
void Window::mouseExited(gcn::MouseEvent &event)
@@ -449,7 +396,7 @@ void Window::mouseDragged(gcn::MouseEvent &event)
gcn::Window::mouseDragged(event);
// Keep guichan window inside screen when it may be moved
- if (isMovable() && mIsMoving)
+ if (isMovable() && mMoved)
{
int newX = std::max(0, getX());
int newY = std::max(0, getY());
@@ -458,7 +405,7 @@ void Window::mouseDragged(gcn::MouseEvent &event)
setPosition(newX, newY);
}
- if (mouseResize && !mIsMoving)
+ if (mouseResize && !mMoved)
{
const int dx = event.getX() - mDragOffsetX;
const int dy = event.getY() - mDragOffsetY;
@@ -585,24 +532,6 @@ int Window::getResizeHandles(gcn::MouseEvent &event)
return resizeHandles;
}
-void Window::fireWindowEvent(const WindowEvent &event)
-{
- WindowListeners::iterator i_end = mListeners.end();
- WindowListeners::iterator i = mListeners.begin();
-
- switch (event.getType())
- {
- case WindowEvent::WINDOW_MOVED:
- for (; i != i_end; ++i)
- { (*i)->windowMoved(event); }
- break;
- case WindowEvent::WINDOW_RESIZED:
- for (; i != i_end; ++i)
- { (*i)->windowResized(event); }
- break;
- }
-}
-
Layout &Window::getLayout()
{
if (!mLayout) mLayout = new Layout;