summaryrefslogtreecommitdiff
path: root/src/gui/window.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-20 12:50:26 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-20 12:50:26 +0000
commit90e5ce7e958418f0d39d38112d33d3190a78baea (patch)
tree012150b22e971e44d0f7e795ef48384e15392940 /src/gui/window.cpp
parent9ca202ae89bbe60f2cd1c8e3249a4fe3f8972a2b (diff)
downloadmana-client-90e5ce7e958418f0d39d38112d33d3190a78baea.tar.gz
mana-client-90e5ce7e958418f0d39d38112d33d3190a78baea.tar.bz2
mana-client-90e5ce7e958418f0d39d38112d33d3190a78baea.tar.xz
mana-client-90e5ce7e958418f0d39d38112d33d3190a78baea.zip
TMW now uses latest Guichan CVS, and doesn't work with Guichan 0.2.0 anymore!
Also fixed a crash on clicking wallpaper in login phase.
Diffstat (limited to 'src/gui/window.cpp')
-rw-r--r--src/gui/window.cpp125
1 files changed, 34 insertions, 91 deletions
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 13f0cc9a..0d8ce5ff 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -28,24 +28,16 @@
WindowContainer *Window::windowContainer = NULL;
-Window::Window(const std::string& text, bool modal, Window *parent):
+Window::Window(const std::string& caption, bool modal, Window *parent):
+ gcn::Window(caption),
parent(parent),
- caption(text),
- mousePX(0),
- mousePY(0),
snapSize(8),
- mouseDown(false),
- modal(modal),
- titlebarHeight(20),
- padding(3)
+ modal(modal)
{
log("Window::Window(\"%s\")", caption.c_str());
- titlebarColor.r = 203;
- titlebarColor.g = 203;
- titlebarColor.b = 203;
-
- setBaseColor(gcn::Color(255, 255, 255));
+ setBorderSize(0);
+ setPadding(3);
// Load dialog title bar image
ResourceManager *resman = ResourceManager::getInstance();
@@ -62,14 +54,10 @@ Window::Window(const std::string& text, bool modal, Window *parent):
border.grid[7] = dBorders->getSubImage(4, 15, 3, 4);
border.grid[8] = dBorders->getSubImage(7, 15, 4, 4);
- // Register mouse listener
- addMouseListener(this);
-
// Add chrome
chrome = new gcn::Container();
chrome->setOpaque(false);
- chrome->setPosition(padding, titlebarHeight + padding);
- gcn::Container::add(chrome);
+ setContent(chrome);
// Add this window to the window container
if (windowContainer) {
@@ -85,7 +73,7 @@ Window::Window(const std::string& text, bool modal, Window *parent):
Window::~Window()
{
- log("Window::~Window(\"%s\")", caption.c_str());
+ log("Window::~Window(\"%s\")", getCaption().c_str());
// Free dialog bitmaps
//release_bitmap(dLeft);
@@ -113,37 +101,29 @@ void Window::draw(gcn::Graphics* graphics)
// Draw title
graphics->setFont(getFont());
- graphics->drawText(caption, 7, 5, gcn::Graphics::LEFT);
-
- drawChildren(graphics);
-}
-
-void Window::setTitle(const std::string& text)
-{
- caption = std::string(text);
-}
+ graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT);
-void Window::setDimension(const gcn::Rectangle &dimension)
-{
- gcn::Container::setDimension(gcn::Rectangle(
- dimension.x,
- dimension.y - titlebarHeight,
- dimension.width,
- dimension.height + titlebarHeight));
- chrome->setDimension(gcn::Rectangle(0, titlebarHeight,
- dimension.width, dimension.height));
+ if (mContent != NULL)
+ {
+ graphics->pushClipArea(getContentDimension());
+ graphics->pushClipArea(gcn::Rectangle(
+ 0, 0, mContent->getWidth(), mContent->getHeight()));
+ mContent->draw(graphics);
+ graphics->popClipArea();
+ graphics->popClipArea();
+ }
}
-void Window::setWidth(int width)
+void Window::setContentWidth(int width)
{
- gcn::Container::setWidth(width + 2 * padding);
chrome->setWidth(width);
+ resizeToContent();
}
-void Window::setHeight(int height)
+void Window::setContentHeight(int height)
{
- gcn::Container::setHeight(height + titlebarHeight + 2 * padding);
chrome->setHeight(height);
+ resizeToContent();
}
void Window::setLocationRelativeTo(gcn::Widget* widget)
@@ -159,10 +139,10 @@ void Window::setLocationRelativeTo(gcn::Widget* widget)
getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y));
}
-void Window::setSize(int width, int height)
+void Window::setContentSize(int width, int height)
{
- setWidth(width);
- setHeight(height);
+ setContentWidth(width);
+ setContentHeight(height);
}
Window *Window::getParentWindow()
@@ -185,62 +165,25 @@ void Window::add(gcn::Widget *w, int x, int y)
chrome->add(w, x, y);
}
-void Window::mousePress(int mx, int my, int button)
-{
- mouseDown = true;
-
- mousePX = mx;
- mousePY = my;
-}
-
-void Window::mouseRelease(int mx, int my, int button)
-{
- mouseDown = false;
-}
-
void Window::mouseMotion(int mx, int my)
{
- if (mouseDown)
+ if (mMouseDrag && isMovable())
{
- int winWidth = this->getDimension().width;
- int winHeight = this->getDimension().height;
- int x = this->getDimension().x;
- int y = this->getDimension().y;
-
- x = x - (mousePX - mx);
- y = y - (mousePY - my);
+ int x = mx - mMouseXOffset + getX();
+ int y = my - mMouseYOffset + getY();
// Keep guichan window inside window
if (x < 0) x = 0;
if (y < 0) y = 0;
- if (x + winWidth > screen->w) x = screen->w - winWidth;
- if (y + winHeight > screen->h) y = screen->h - winHeight;
+ if (x + getWidth() > screen->w) x = screen->w - getWidth();
+ if (y + getHeight() > screen->h) y = screen->h - getHeight();
// Snap window to edges
- /*
- if (x < snapSize) x = 0;
- if (y < snapSize) y = 0;
- if (x + winWidth + snapSize > screen->w) x = screen->w - winWidth;
- if (y + winHeight + snapSize > screen->h) y = screen->h - winHeight;
- */
-
- this->setPosition(x, y);
- }
-}
+ //if (x < snapSize) x = 0;
+ //if (y < snapSize) y = 0;
+ //if (x + winWidth + snapSize > screen->w) x = screen->w - winWidth;
+ //if (y + winHeight + snapSize > screen->h) y = screen->h - winHeight;
-void Window::mouseOut()
-{
- mouseDown = false;
-}
-
-void Window::_mouseInputMessage(const gcn::MouseInput &mouseInput)
-{
- if (mouseInput.getType() == gcn::MouseInput::MOTION && mouseDown) {
- // It's a window drag event
- gcn::Widget::_mouseInputMessage(mouseInput);
- }
- else {
- // It's something else
- gcn::Container::_mouseInputMessage(mouseInput);
+ setPosition(x, y);
}
}