diff options
Diffstat (limited to 'src/gui/widgets/window.cpp')
-rw-r--r-- | src/gui/widgets/window.cpp | 116 |
1 files changed, 63 insertions, 53 deletions
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 4435496a7..c52bf744e 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -47,7 +47,7 @@ int Window::instances = 0; int Window::mouseResize = 0; Window::Window(const std::string &caption, bool modal, Window *parent, - const std::string &skin): + std::string skin): gcn::Window(caption), mGrip(0), mParent(parent), @@ -63,8 +63,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent, mStickyButtonLock(false), mMinWinWidth(100), mMinWinHeight(40), - mMaxWinWidth(graphics->mWidth), - mMaxWinHeight(graphics->mHeight), + mMaxWinWidth(mainGraphics->mWidth), + mMaxWinHeight(mainGraphics->mHeight), mVertexes(new GraphicsVertexes()), mRedraw(true) { @@ -79,8 +79,20 @@ Window::Window(const std::string &caption, bool modal, Window *parent, setPadding(3); setTitleBarHeight(20); + if (skin == "") + skin = "window.xml"; + // Loads the skin - mSkin = Theme::instance()->load(skin); + if (Theme::instance()) + { + mSkin = Theme::instance()->load(skin); + if (mSkin) + setPadding(mSkin->getPadding()); + } + else + { + mSkin = 0; + } // Add this window to the window container windowContainer->add(this); @@ -113,8 +125,6 @@ Window::~Window() mWidgets.clear(); -// need mWidgets.clean ? - removeWidgetListener(this); delete mVertexes; mVertexes = 0; @@ -122,7 +132,11 @@ Window::~Window() instances--; if (mSkin) - mSkin->instances--; + { + if (Theme::instance()) + Theme::instance()->unload(mSkin); + mSkin = 0; + } } void Window::setWindowContainer(WindowContainer *wc) @@ -244,39 +258,39 @@ void Window::setLocationRelativeTo(ImageRect::ImagePosition position, } else if (position == ImageRect::UPPER_CENTER) { - offsetX += (graphics->mWidth - getWidth()) / 2; + offsetX += (mainGraphics->mWidth - getWidth()) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - offsetX += graphics->mWidth - getWidth(); + offsetX += mainGraphics->mWidth - getWidth(); } else if (position == ImageRect::LEFT) { - offsetY += (graphics->mHeight - getHeight()) / 2; + offsetY += (mainGraphics->mHeight - getHeight()) / 2; } else if (position == ImageRect::CENTER) { - offsetX += (graphics->mWidth - getWidth()) / 2; - offsetY += (graphics->mHeight - getHeight()) / 2; + offsetX += (mainGraphics->mWidth - getWidth()) / 2; + offsetY += (mainGraphics->mHeight - getHeight()) / 2; } else if (position == ImageRect::RIGHT) { - offsetX += graphics->mWidth - getWidth(); - offsetY += (graphics->mHeight - getHeight()) / 2; + offsetX += mainGraphics->mWidth - getWidth(); + offsetY += (mainGraphics->mHeight - getHeight()) / 2; } else if (position == ImageRect::LOWER_LEFT) { - offsetY += graphics->mHeight - getHeight(); + offsetY += mainGraphics->mHeight - getHeight(); } else if (position == ImageRect::LOWER_CENTER) { - offsetX += (graphics->mWidth - getWidth()) / 2; - offsetY += graphics->mHeight - getHeight(); + offsetX += (mainGraphics->mWidth - getWidth()) / 2; + offsetY += mainGraphics->mHeight - getHeight(); } else if (position == ImageRect::LOWER_RIGHT) { - offsetX += graphics->mWidth - getWidth(); - offsetY += graphics->mHeight - getHeight(); + offsetX += mainGraphics->mWidth - getWidth(); + offsetY += mainGraphics->mHeight - getHeight(); } setPosition(offsetX, offsetY); @@ -373,7 +387,7 @@ void Window::widgetHidden(const gcn::Event &event A_UNUSED) if (!mFocusHandler) return; - for (it = mWidgets.begin(); it != mWidgets.end(); it++) + for (it = mWidgets.begin(); it != mWidgets.end(); ++ it) { if (mFocusHandler->isFocused(*it)) mFocusHandler->focusNone(); @@ -443,7 +457,7 @@ void Window::mousePressed(gcn::MouseEvent &event) const int y = event.getY(); // Handle close button - if (mCloseButton) + if (mCloseButton && mSkin) { Image *img = mSkin->getCloseImage(); if (img) @@ -464,7 +478,7 @@ void Window::mousePressed(gcn::MouseEvent &event) } // Handle sticky button - if (mStickyButton) + if (mStickyButton && mSkin) { Image *button = mSkin->getStickyImage(mSticky); if (button) @@ -579,8 +593,8 @@ void Window::mouseDragged(gcn::MouseEvent &event) { int newX = std::max(0, getX()); int newY = std::max(0, getY()); - newX = std::min(graphics->mWidth - getWidth(), newX); - newY = std::min(graphics->mHeight - getHeight(), newY); + newX = std::min(mainGraphics->mWidth - getWidth(), newX); + newY = std::min(mainGraphics->mHeight - getHeight(), newY); setPosition(newX, newY); } @@ -621,14 +635,10 @@ void Window::mouseDragged(gcn::MouseEvent &event) newDim.height += newDim.y; newDim.y = 0; } - if (newDim.x + newDim.width > graphics->mWidth) - { - newDim.width = graphics->mWidth - newDim.x; - } - if (newDim.y + newDim.height > graphics->mHeight) - { - newDim.height = graphics->mHeight - newDim.y; - } + if (newDim.x + newDim.width > mainGraphics->mWidth) + newDim.width = mainGraphics->mWidth - newDim.x; + if (newDim.y + newDim.height > mainGraphics->mHeight) + newDim.height = mainGraphics->mHeight - newDim.y; // Update mouse offset when dragging bottom or right border if (mouseResize & BOTTOM) @@ -790,39 +800,39 @@ void Window::setDefaultSize(int defaultWidth, int defaultHeight, } else if (position == ImageRect::UPPER_CENTER) { - x = (graphics->mWidth - defaultWidth) / 2; + x = (mainGraphics->mWidth - defaultWidth) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - x = graphics->mWidth - defaultWidth; + x = mainGraphics->mWidth - defaultWidth; } else if (position == ImageRect::LEFT) { - y = (graphics->mHeight - defaultHeight) / 2; + y = (mainGraphics->mHeight - defaultHeight) / 2; } else if (position == ImageRect::CENTER) { - x = (graphics->mWidth - defaultWidth) / 2; - y = (graphics->mHeight - defaultHeight) / 2; + x = (mainGraphics->mWidth - defaultWidth) / 2; + y = (mainGraphics->mHeight - defaultHeight) / 2; } else if (position == ImageRect::RIGHT) { - x = graphics->mWidth - defaultWidth; - y = (graphics->mHeight - defaultHeight) / 2; + x = mainGraphics->mWidth - defaultWidth; + y = (mainGraphics->mHeight - defaultHeight) / 2; } else if (position == ImageRect::LOWER_LEFT) { - y = graphics->mHeight - defaultHeight; + y = mainGraphics->mHeight - defaultHeight; } else if (position == ImageRect::LOWER_CENTER) { - x = (graphics->mWidth - defaultWidth) / 2; - y = graphics->mHeight - defaultHeight; + x = (mainGraphics->mWidth - defaultWidth) / 2; + y = mainGraphics->mHeight - defaultHeight; } else if (position == ImageRect::LOWER_RIGHT) { - x = graphics->mWidth - defaultWidth; - y = graphics->mHeight - defaultHeight; + x = mainGraphics->mWidth - defaultWidth; + y = mainGraphics->mHeight - defaultHeight; } mDefaultX = x - offsetX; @@ -994,11 +1004,11 @@ void Window::checkIfIsOffScreen(bool partially, bool entirely) // Look if the window is partially off-screen limits... if (partially) { - if (winDimension.x + winDimension.width > graphics->mWidth) - winDimension.x = graphics->mWidth - winDimension.width; + if (winDimension.x + winDimension.width > mainGraphics->mWidth) + winDimension.x = mainGraphics->mWidth - winDimension.width; - if (winDimension.y + winDimension.height > graphics->mHeight) - winDimension.y = graphics->mHeight - winDimension.height; + if (winDimension.y + winDimension.height > mainGraphics->mHeight) + winDimension.y = mainGraphics->mHeight - winDimension.height; setDimension(winDimension); return; @@ -1006,11 +1016,11 @@ void Window::checkIfIsOffScreen(bool partially, bool entirely) if (entirely) { - if (winDimension.x > graphics->mWidth) - winDimension.x = graphics->mWidth - winDimension.width; + if (winDimension.x > mainGraphics->mWidth) + winDimension.x = mainGraphics->mWidth - winDimension.width; - if (winDimension.y > graphics->mHeight) - winDimension.y = graphics->mHeight - winDimension.height; + if (winDimension.y > mainGraphics->mHeight) + winDimension.y = mainGraphics->mHeight - winDimension.height; } setDimension(winDimension); } @@ -1021,4 +1031,4 @@ gcn::Rectangle Window::getWindowArea() getPadding(), getWidth() - getPadding() * 2, getHeight() - getPadding() * 2); -}
\ No newline at end of file +} |