metaforce/Editor/SplashScreen.cpp

264 lines
8.9 KiB
C++
Raw Normal View History

2015-12-12 18:27:34 -08:00
#include "SplashScreen.hpp"
2015-12-13 13:01:32 -08:00
#include "version.h"
2015-12-12 18:27:34 -08:00
2016-01-05 01:53:16 -08:00
namespace URDE
2015-12-12 18:27:34 -08:00
{
#define SPLASH_WIDTH 555
#define SPLASH_HEIGHT 300
#define WIRE_START 0
#define WIRE_FRAMES 60
#define SOLID_START 40
#define SOLID_FRAMES 40
#define TEXT_START 80
#define TEXT_FRAMES 40
2015-12-13 13:01:32 -08:00
#define LINE_WIDTH 2
2015-12-12 18:27:34 -08:00
#define TEXT_MARGIN 10
SplashScreen::SplashScreen(ViewManager& vm, Specter::ViewResources& res)
2015-12-20 11:20:07 -08:00
: ModalWindow(res, vm.rootView(),
Specter::RectangleConstraint(SPLASH_WIDTH * res.pixelFactor(),
SPLASH_HEIGHT * res.pixelFactor())),
m_vm(vm),
2015-12-12 18:27:34 -08:00
m_textColor(res.themeData().uiText()),
2015-12-15 13:56:40 -08:00
m_textColorClear(m_textColor),
2015-12-30 19:20:52 -08:00
m_buildInfoStr(HECL::Format("%s: %s\n%s: %s\n%s: %s",
vm.translateOr("branch", "Branch").c_str(), GIT_BRANCH,
vm.translateOr("commit", "Commit").c_str(), GIT_COMMIT_HASH,
vm.translateOr("date", "Date").c_str(), GIT_COMMIT_DATE)),
m_newString(m_vm.translateOr("new_project", "New Project")),
2015-12-15 13:56:40 -08:00
m_newProjBind(*this),
2015-12-30 19:20:52 -08:00
m_openString(m_vm.translateOr("open_project", "Open Project")),
2015-12-15 13:56:40 -08:00
m_openProjBind(*this),
2015-12-30 19:20:52 -08:00
m_extractString(m_vm.translateOr("extract_game", "Extract Game")),
2015-12-15 13:56:40 -08:00
m_extractProjBind(*this)
2015-12-12 18:27:34 -08:00
{
m_textColorClear[3] = 0.0;
commitResources(res);
}
2015-12-15 13:56:40 -08:00
void SplashScreen::think()
2015-12-12 18:27:34 -08:00
{
2015-12-15 13:56:40 -08:00
ModalWindow::think();
if (m_fileBrowser.m_view)
m_fileBrowser.m_view->think();
2016-01-07 21:54:00 -08:00
if (m_newProjBind.m_deferPath.size())
{
Log.report(LogVisor::Info, _S("Making project '%s'"), m_newProjBind.m_deferPath.c_str());
m_vm.projectManager().newProject(m_newProjBind.m_deferPath);
m_newProjBind.m_deferPath.clear();
}
else if (m_openProjBind.m_deferPath.size())
{
Log.report(LogVisor::Info, _S("Opening project '%s'"), m_openProjBind.m_deferPath.c_str());
m_vm.projectManager().openProject(m_openProjBind.m_deferPath);
m_openProjBind.m_deferPath.clear();
}
else if (m_extractProjBind.m_deferPath.size())
{
Log.report(LogVisor::Info, _S("Extracting game '%s'"), m_extractProjBind.m_deferPath.c_str());
m_vm.projectManager().extractGame(m_extractProjBind.m_deferPath);
m_extractProjBind.m_deferPath.clear();
}
2015-12-12 18:27:34 -08:00
}
2015-12-15 13:56:40 -08:00
void SplashScreen::updateContentOpacity(float opacity)
2015-12-12 18:27:34 -08:00
{
Specter::ViewResources& res = rootView().viewRes();
2015-12-15 13:56:40 -08:00
if (!m_title && res.fontCacheReady())
2015-12-30 19:20:52 -08:00
{
2015-12-12 18:27:34 -08:00
m_title.reset(new Specter::TextView(res, *this, res.m_titleFont));
Zeus::CColor clearColor = res.themeData().uiText();
clearColor[3] = 0.0;
2016-01-05 01:53:16 -08:00
m_title->typesetGlyphs("URDE", clearColor);
2015-12-13 13:01:32 -08:00
m_buildInfo.reset(new Specter::MultiLineTextView(res, *this, res.m_mainFont, Specter::TextView::Alignment::Right));
2015-12-30 19:20:52 -08:00
m_buildInfo->typesetGlyphs(m_buildInfoStr, clearColor);
2015-12-13 13:01:32 -08:00
2015-12-30 19:20:52 -08:00
m_newButt.m_view.reset(new Specter::Button(res, *this, &m_newProjBind, m_newString,
Specter::Button::Style::Text));
m_openButt.m_view.reset(new Specter::Button(res, *this, &m_openProjBind, m_openString,
Specter::Button::Style::Text));
m_extractButt.m_view.reset(new Specter::Button(res, *this, &m_extractProjBind, m_extractString,
Specter::Button::Style::Text));
2015-12-13 13:01:32 -08:00
2015-12-12 18:27:34 -08:00
updateSize();
}
2015-12-15 13:56:40 -08:00
Zeus::CColor clearColor = res.themeData().uiText();
clearColor[3] = 0.0;
Zeus::CColor color = Zeus::CColor::lerp(clearColor, res.themeData().uiText(), opacity);
m_title->colorGlyphs(color);
m_buildInfo->colorGlyphs(color);
m_newButt.m_view->colorGlyphs(color);
m_openButt.m_view->colorGlyphs(color);
m_extractButt.m_view->colorGlyphs(color);
2015-12-12 18:27:34 -08:00
}
2015-12-13 13:01:32 -08:00
void SplashScreen::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
2015-12-15 13:56:40 -08:00
if (skipBuildInAnimation())
return;
2015-12-22 16:26:30 -08:00
if (m_fileBrowser.m_view && !m_fileBrowser.m_view->closed())
2015-12-15 13:56:40 -08:00
m_fileBrowser.m_view->mouseDown(coord, button, mod);
else
{
m_newButt.mouseDown(coord, button, mod);
m_openButt.mouseDown(coord, button, mod);
m_extractButt.mouseDown(coord, button, mod);
}
2015-12-13 13:01:32 -08:00
}
void SplashScreen::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
2015-12-22 16:26:30 -08:00
if (m_fileBrowser.m_view && !m_fileBrowser.m_view->closed())
2015-12-15 13:56:40 -08:00
m_fileBrowser.m_view->mouseUp(coord, button, mod);
else
{
m_newButt.mouseUp(coord, button, mod);
m_openButt.mouseUp(coord, button, mod);
m_extractButt.mouseUp(coord, button, mod);
}
2015-12-13 13:01:32 -08:00
}
void SplashScreen::mouseMove(const boo::SWindowCoord& coord)
{
2015-12-22 16:26:30 -08:00
if (m_fileBrowser.m_view && !m_fileBrowser.m_view->closed())
2015-12-15 13:56:40 -08:00
m_fileBrowser.m_view->mouseMove(coord);
else
{
m_newButt.mouseMove(coord);
m_openButt.mouseMove(coord);
m_extractButt.mouseMove(coord);
}
2015-12-13 13:01:32 -08:00
}
void SplashScreen::mouseEnter(const boo::SWindowCoord& coord)
{
2015-12-22 16:26:30 -08:00
if (m_fileBrowser.m_view && !m_fileBrowser.m_view->closed())
2015-12-15 13:56:40 -08:00
m_fileBrowser.m_view->mouseEnter(coord);
else
{
m_newButt.mouseEnter(coord);
m_openButt.mouseEnter(coord);
m_extractButt.mouseEnter(coord);
}
2015-12-13 13:01:32 -08:00
}
void SplashScreen::mouseLeave(const boo::SWindowCoord& coord)
{
2015-12-22 16:26:30 -08:00
if (m_fileBrowser.m_view && !m_fileBrowser.m_view->closed())
2015-12-15 13:56:40 -08:00
m_fileBrowser.m_view->mouseLeave(coord);
else
{
m_newButt.mouseLeave(coord);
m_openButt.mouseLeave(coord);
m_extractButt.mouseLeave(coord);
}
2015-12-13 13:01:32 -08:00
}
2015-12-20 11:20:07 -08:00
void SplashScreen::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& scroll)
{
if (m_fileBrowser.m_view)
m_fileBrowser.m_view->scroll(coord, scroll);
}
void SplashScreen::touchDown(const boo::STouchCoord& coord, uintptr_t tid)
{
if (m_fileBrowser.m_view)
m_fileBrowser.m_view->touchDown(coord, tid);
}
void SplashScreen::touchUp(const boo::STouchCoord& coord, uintptr_t tid)
{
if (m_fileBrowser.m_view)
m_fileBrowser.m_view->touchUp(coord, tid);
}
void SplashScreen::touchMove(const boo::STouchCoord& coord, uintptr_t tid)
{
if (m_fileBrowser.m_view)
m_fileBrowser.m_view->touchMove(coord, tid);
}
void SplashScreen::charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat)
{
2016-01-01 18:27:46 -08:00
if (skipBuildInAnimation())
return;
if (m_fileBrowser.m_view)
m_fileBrowser.m_view->charKeyDown(charCode, mods, isRepeat);
}
void SplashScreen::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat)
{
if (skipBuildInAnimation())
return;
if (m_fileBrowser.m_view)
m_fileBrowser.m_view->specialKeyDown(key, mods, isRepeat);
2015-12-20 11:20:07 -08:00
}
2015-12-12 18:27:34 -08:00
void SplashScreen::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
{
2015-12-15 13:56:40 -08:00
ModalWindow::resized(root, sub);
2015-12-12 18:27:34 -08:00
float pf = rootView().viewRes().pixelFactor();
2015-12-15 13:56:40 -08:00
boo::SWindowRect centerRect = subRect();
2015-12-12 18:27:34 -08:00
centerRect.location[0] = root.size[0] / 2 - (SPLASH_WIDTH * pf / 2.0);
centerRect.location[1] = root.size[1] / 2 - (SPLASH_HEIGHT * pf / 2.0);
boo::SWindowRect textRect = centerRect;
textRect.location[0] += TEXT_MARGIN * pf;
textRect.location[1] += (SPLASH_HEIGHT - 36) * pf;
if (m_title)
2015-12-13 13:01:32 -08:00
{
2015-12-12 18:27:34 -08:00
m_title->resized(root, textRect);
2015-12-13 13:01:32 -08:00
textRect.location[0] = centerRect.location[0] + (SPLASH_WIDTH - TEXT_MARGIN) * pf;
textRect.location[1] -= 5 * pf;
m_buildInfo->resized(root, textRect);
2015-12-15 13:56:40 -08:00
textRect.size[0] = m_newButt.m_view->nominalWidth();
textRect.size[1] = m_newButt.m_view->nominalHeight();
2015-12-13 13:01:32 -08:00
textRect.location[1] = centerRect.location[1] + 20 * pf;
2015-12-15 13:56:40 -08:00
textRect.location[0] = centerRect.location[0] + SPLASH_WIDTH / 4 * pf - m_newButt.m_view->nominalWidth() / 2;
m_newButt.m_view->resized(root, textRect);
2015-12-13 13:01:32 -08:00
2015-12-15 13:56:40 -08:00
textRect.size[0] = m_openButt.m_view->nominalWidth();
textRect.size[1] = m_openButt.m_view->nominalHeight();
2015-12-13 13:01:32 -08:00
textRect.location[1] = centerRect.location[1] + 20 * pf;
2015-12-15 13:56:40 -08:00
textRect.location[0] = centerRect.location[0] + SPLASH_WIDTH * 2 / 4 * pf - m_openButt.m_view->nominalWidth() / 2;
m_openButt.m_view->resized(root, textRect);
2015-12-13 13:01:32 -08:00
2015-12-15 13:56:40 -08:00
textRect.size[0] = m_extractButt.m_view->nominalWidth();
textRect.size[1] = m_extractButt.m_view->nominalHeight();
2015-12-13 13:01:32 -08:00
textRect.location[1] = centerRect.location[1] + 20 * pf;
2015-12-15 13:56:40 -08:00
textRect.location[0] = centerRect.location[0] + SPLASH_WIDTH * 3 / 4 * pf - m_extractButt.m_view->nominalWidth() / 2;
m_extractButt.m_view->resized(root, textRect);
2015-12-13 13:01:32 -08:00
}
2015-12-15 13:56:40 -08:00
if (m_fileBrowser.m_view)
m_fileBrowser.m_view->resized(root, root);
2015-12-12 18:27:34 -08:00
}
void SplashScreen::draw(boo::IGraphicsCommandQueue* gfxQ)
{
2015-12-15 13:56:40 -08:00
ModalWindow::draw(gfxQ);
if (m_title)
2015-12-13 13:01:32 -08:00
{
2015-12-12 18:27:34 -08:00
m_title->draw(gfxQ);
2015-12-13 13:01:32 -08:00
m_buildInfo->draw(gfxQ);
2015-12-15 13:56:40 -08:00
m_newButt.m_view->draw(gfxQ);
m_openButt.m_view->draw(gfxQ);
m_extractButt.m_view->draw(gfxQ);
2015-12-13 13:01:32 -08:00
}
2015-12-12 18:27:34 -08:00
2015-12-15 13:56:40 -08:00
if (m_fileBrowser.m_view)
m_fileBrowser.m_view->draw(gfxQ);
2015-12-12 18:27:34 -08:00
}
}