/*
* The Mana Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2012 The Mana Developers
* Copyright (C) 2009 Aethyra Development Team
*
* This file is part of The Mana Client.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "gui/widgets/popup.h"
#include "browserbox.h"
#include "graphics.h"
#include "log.h"
#include "textbox.h"
#include "gui/gui.h"
#include "gui/viewport.h"
#include "gui/widgets/label.h"
#include "gui/widgets/windowcontainer.h"
#include
Popup::Popup(const std::string &name, SkinType skinType)
: mPopupName(name)
, mMaxWidth(graphics->getWidth())
, mMaxHeight(graphics->getHeight())
, mSkinType(skinType)
{
Log::debug("Popup::Popup(\"%s\")", name.c_str());
if (!windowContainer)
throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set");
auto &skin = getSkin();
setFrameSize(skin.frameSize);
setPadding(skin.padding);
// Add this window to the window container
windowContainer->add(this);
// Popups are invisible by default
setVisible(false);
}
Popup::~Popup()
{
Log::debug("Popup::~Popup(\"%s\")", mPopupName.c_str());
}
void Popup::setWindowContainer(WindowContainer *wc)
{
windowContainer = wc;
}
void Popup::add(gcn::Widget *widget)
{
Container::add(widget);
widgetAdded(widget);
}
void Popup::add(gcn::Widget *widget, int x, int y)
{
Container::add(widget, x, y);
widgetAdded(widget);
}
void Popup::widgetAdded(gcn::Widget *widget) const
{
if (const int paletteId = getSkin().palette)
{
if (auto browserBox = dynamic_cast(widget))
{
browserBox->setPalette(paletteId);
}
else if (auto label = dynamic_cast