metaforce/specter/lib/MessageWindow.cpp

110 lines
3.6 KiB
C++
Raw Normal View History

2016-03-04 23:03:47 +00:00
#include "specter/MessageWindow.hpp"
#include "specter/ViewResources.hpp"
#include "specter/RootView.hpp"
#include "specter/Menu.hpp"
2016-01-02 23:07:40 +00:00
2016-03-04 23:03:47 +00:00
namespace specter
2016-01-02 23:07:40 +00:00
{
MessageWindow::MessageWindow(ViewResources& res, View& parentView,
2017-11-13 06:14:52 +00:00
Type type, std::string_view message,
2016-01-02 23:07:40 +00:00
std::function<void (bool)> func)
2016-01-03 02:42:52 +00:00
: ModalWindow(res, parentView, RectangleConstraint(),
2016-01-02 23:07:40 +00:00
type==Type::ErrorOk ? res.themeData().splashErrorBackground() : res.themeData().splashBackground()),
m_type(type), m_func(func),
m_okBind(*this, rootView().viewManager().translateOr("ok", "OK")),
m_cancelBind(*this, rootView().viewManager().translateOr("cancel", "Cancel"))
{
m_text.reset(new MultiLineTextView(res, *this, res.m_mainFont, TextView::Alignment::Center));
m_text->typesetGlyphs(message, res.themeData().uiText(), 380 * res.pixelFactor());
2016-01-03 02:42:52 +00:00
constraint() = RectangleConstraint(400 * res.pixelFactor(), 80 * res.pixelFactor() + m_text->nominalHeight());
2016-01-02 23:07:40 +00:00
2016-01-18 00:37:13 +00:00
m_ok.m_view.reset(new Button(res, *this, &m_okBind, m_okBind.m_name, nullptr,
2016-03-04 23:03:47 +00:00
Button::Style::Block, zeus::CColor::skWhite,
2016-01-18 23:32:16 +00:00
RectangleConstraint(150 * res.pixelFactor())));
2016-01-02 23:07:40 +00:00
if (type == Type::ConfirmOkCancel)
2016-01-18 00:37:13 +00:00
m_cancel.m_view.reset(new Button(res, *this, &m_cancelBind, m_cancelBind.m_name, nullptr,
2016-03-04 23:03:47 +00:00
Button::Style::Block, zeus::CColor::skWhite,
2016-01-18 23:32:16 +00:00
RectangleConstraint(150 * res.pixelFactor())));
2016-01-02 23:07:40 +00:00
updateContentOpacity(0.0);
}
void MessageWindow::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mods)
{
if (closed() || skipBuildInAnimation())
return;
m_ok.mouseDown(coord, button, mods);
m_cancel.mouseDown(coord, button, mods);
}
void MessageWindow::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mods)
{
if (closed())
return;
m_ok.mouseUp(coord, button, mods);
m_cancel.mouseUp(coord, button, mods);
}
void MessageWindow::mouseMove(const boo::SWindowCoord& coord)
{
if (closed())
return;
m_ok.mouseMove(coord);
m_cancel.mouseMove(coord);
}
void MessageWindow::mouseEnter(const boo::SWindowCoord& coord)
{
if (closed())
return;
m_ok.mouseEnter(coord);
m_cancel.mouseEnter(coord);
}
void MessageWindow::mouseLeave(const boo::SWindowCoord& coord)
{
if (closed())
return;
m_ok.mouseLeave(coord);
m_cancel.mouseLeave(coord);
}
void MessageWindow::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
{
ModalWindow::resized(root, sub);
boo::SWindowRect buttonRect = subRect();
float pf = rootView().viewRes().pixelFactor();
2016-01-03 02:42:52 +00:00
buttonRect.location[1] += 20 * pf;
2016-01-02 23:07:40 +00:00
buttonRect.size[0] = m_ok.m_view->nominalWidth();
buttonRect.size[1] = m_ok.m_view->nominalHeight();
if (m_type == Type::ConfirmOkCancel)
{
buttonRect.location[0] += 45 * pf;
m_ok.m_view->resized(root, buttonRect);
buttonRect.location[0] += 160 * pf;
m_cancel.m_view->resized(root, buttonRect);
}
else
{
buttonRect.location[0] += 125 * pf;
m_ok.m_view->resized(root, buttonRect);
}
boo::SWindowRect textRect = subRect();
textRect.location[0] += 200 * pf;
2016-01-03 02:42:52 +00:00
textRect.location[1] += 65 * pf;
2016-01-02 23:07:40 +00:00
m_text->resized(root, textRect);
}
void MessageWindow::draw(boo::IGraphicsCommandQueue* gfxQ)
{
ModalWindow::draw(gfxQ);
m_text->draw(gfxQ);
m_ok.m_view->draw(gfxQ);
if (m_type == Type::ConfirmOkCancel)
m_cancel.m_view->draw(gfxQ);
}
}