2015-12-06 01:27:02 +00:00
|
|
|
#include "ViewManager.hpp"
|
2015-12-08 04:27:35 +00:00
|
|
|
#include "Specter/Control.hpp"
|
2015-12-12 00:37:32 +00:00
|
|
|
#include "Specter/Space.hpp"
|
2016-01-28 23:55:38 +00:00
|
|
|
#include "Specter/Menu.hpp"
|
2015-12-24 03:32:21 +00:00
|
|
|
#include "SplashScreen.hpp"
|
2015-12-31 03:20:52 +00:00
|
|
|
#include "locale/locale.hpp"
|
2016-01-07 00:40:27 +00:00
|
|
|
#include "ResourceBrowser.hpp"
|
2016-01-18 23:33:23 +00:00
|
|
|
#include "icons/icons.hpp"
|
2016-01-16 03:58:11 +00:00
|
|
|
#include <cstdio>
|
2015-12-06 01:27:02 +00:00
|
|
|
|
2015-12-11 02:37:54 +00:00
|
|
|
using YAMLNode = Athena::io::YAMLNode;
|
|
|
|
|
2016-01-05 09:53:16 +00:00
|
|
|
namespace URDE
|
2015-12-06 01:27:02 +00:00
|
|
|
{
|
|
|
|
|
2016-01-11 02:17:08 +00:00
|
|
|
Specter::View* ViewManager::BuildSpaceViews()
|
2015-12-12 00:37:32 +00:00
|
|
|
{
|
2016-01-11 02:17:08 +00:00
|
|
|
m_rootSpaceView = m_rootSpace->buildSpaceView(m_viewResources);
|
2016-01-05 00:01:02 +00:00
|
|
|
return m_rootSpaceView;
|
2015-12-12 00:37:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 00:01:02 +00:00
|
|
|
Specter::RootView* ViewManager::SetupRootView()
|
2015-12-06 01:27:02 +00:00
|
|
|
{
|
|
|
|
m_rootView.reset(new Specter::RootView(*this, m_viewResources, m_mainWindow.get()));
|
2015-12-13 02:27:34 +00:00
|
|
|
m_rootView->setBackground(Zeus::CColor::skBlack);
|
2016-01-05 00:01:02 +00:00
|
|
|
return m_rootView.get();
|
2015-12-13 02:27:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 00:01:02 +00:00
|
|
|
SplashScreen* ViewManager::SetupSplashView()
|
2015-12-13 02:27:34 +00:00
|
|
|
{
|
|
|
|
m_splash.reset(new SplashScreen(*this, m_viewResources));
|
2016-01-05 00:01:02 +00:00
|
|
|
if (!m_showSplash)
|
|
|
|
m_splash->close(true);
|
|
|
|
return m_splash.get();
|
2015-12-13 02:27:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 02:17:08 +00:00
|
|
|
void ViewManager::RootSpaceViewBuilt(Specter::View *view)
|
|
|
|
{
|
|
|
|
std::vector<Specter::View*>& cViews = m_rootView->accessContentViews();
|
|
|
|
cViews.clear();
|
|
|
|
cViews.push_back(view);
|
|
|
|
cViews.push_back(m_splash.get());
|
|
|
|
m_rootView->updateSize();
|
|
|
|
}
|
|
|
|
|
2015-12-13 02:27:34 +00:00
|
|
|
void ViewManager::SetupEditorView()
|
|
|
|
{
|
2016-01-10 06:42:58 +00:00
|
|
|
m_rootSpace.reset(new RootSpace(*this));
|
|
|
|
|
2016-01-11 02:17:08 +00:00
|
|
|
SplitSpace* split = new SplitSpace(*this, nullptr, Specter::SplitView::Axis::Horizontal);
|
2016-01-10 06:42:58 +00:00
|
|
|
m_rootSpace->setChild(std::unique_ptr<Space>(split));
|
|
|
|
split->setChildSlot(0, std::make_unique<ResourceBrowser>(*this, split));
|
|
|
|
split->setChildSlot(1, std::make_unique<ResourceBrowser>(*this, split));
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2016-01-11 02:17:08 +00:00
|
|
|
BuildSpaceViews();
|
2016-01-04 05:31:02 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 00:01:02 +00:00
|
|
|
void ViewManager::SetupEditorView(ConfigReader& r)
|
2016-01-04 05:31:02 +00:00
|
|
|
{
|
2016-01-10 06:42:58 +00:00
|
|
|
m_rootSpace.reset(Space::NewRootSpaceFromConfigStream(*this, r));
|
2016-01-11 02:17:08 +00:00
|
|
|
BuildSpaceViews();
|
2016-01-05 00:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewManager::SaveEditorView(ConfigWriter& w)
|
|
|
|
{
|
|
|
|
if (!m_rootSpace)
|
|
|
|
return;
|
|
|
|
m_rootSpace->saveState(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewManager::DismissSplash()
|
|
|
|
{
|
|
|
|
if (!m_showSplash)
|
|
|
|
return;
|
2016-01-04 05:31:02 +00:00
|
|
|
m_showSplash = false;
|
2016-01-05 00:01:02 +00:00
|
|
|
m_splash->close();
|
2015-12-06 01:27:02 +00:00
|
|
|
}
|
|
|
|
|
2015-12-13 02:27:34 +00:00
|
|
|
ViewManager::ViewManager(HECL::Runtime::FileStoreManager& fileMgr, HECL::CVarManager& cvarMgr)
|
2016-01-04 05:31:02 +00:00
|
|
|
: m_fileStoreManager(fileMgr), m_cvarManager(cvarMgr), m_projManager(*this),
|
2016-01-16 03:58:11 +00:00
|
|
|
m_fontCache(fileMgr), m_translator(URDE::SystemLocaleOrEnglish()),
|
|
|
|
m_recentProjectsPath(HECL::SysFormat(_S("%s/recent_projects.txt"), fileMgr.getStoreRoot().c_str())),
|
|
|
|
m_recentFilesPath(HECL::SysFormat(_S("%s/recent_files.txt"), fileMgr.getStoreRoot().c_str()))
|
|
|
|
{
|
2016-02-01 20:04:55 +00:00
|
|
|
Space::SpaceMenuNode::InitializeStrings(*this);
|
2016-01-16 03:58:11 +00:00
|
|
|
char path[2048];
|
|
|
|
HECL::Sstat theStat;
|
|
|
|
|
|
|
|
FILE* fp = HECL::Fopen(m_recentProjectsPath.c_str(), _S("r"), HECL::FileLockType::Read);
|
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
while (fgets(path, 2048, fp))
|
|
|
|
{
|
|
|
|
std::string pathStr(path);
|
|
|
|
pathStr.pop_back();
|
|
|
|
HECL::SystemStringView pathStrView(pathStr);
|
|
|
|
if (!HECL::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode))
|
|
|
|
m_recentProjects.push_back(pathStrView);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
fp = HECL::Fopen(m_recentFilesPath.c_str(), _S("r"), HECL::FileLockType::Read);
|
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
while (fgets(path, 2048, fp))
|
|
|
|
{
|
|
|
|
std::string pathStr(path);
|
|
|
|
pathStr.pop_back();
|
|
|
|
HECL::SystemStringView pathStrView(pathStr);
|
|
|
|
if (!HECL::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode))
|
|
|
|
m_recentFiles.push_back(pathStrView);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
2015-12-13 02:27:34 +00:00
|
|
|
|
|
|
|
ViewManager::~ViewManager() {}
|
|
|
|
|
2016-01-02 02:27:46 +00:00
|
|
|
void ViewManager::pushRecentProject(const HECL::SystemString& path)
|
|
|
|
{
|
2016-01-16 03:58:11 +00:00
|
|
|
for (HECL::SystemString& testPath : m_recentProjects)
|
|
|
|
{
|
|
|
|
if (path == testPath)
|
|
|
|
return;
|
|
|
|
}
|
2016-01-02 02:27:46 +00:00
|
|
|
m_recentProjects.push_back(path);
|
2016-01-16 03:58:11 +00:00
|
|
|
FILE* fp = HECL::Fopen(m_recentProjectsPath.c_str(), _S("w"), HECL::FileLockType::Write);
|
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
for (HECL::SystemString& pPath : m_recentProjects)
|
|
|
|
fprintf(fp, "%s\n", HECL::SystemUTF8View(pPath).c_str());
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2016-01-02 02:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewManager::pushRecentFile(const HECL::SystemString& path)
|
|
|
|
{
|
2016-01-16 03:58:11 +00:00
|
|
|
for (HECL::SystemString& testPath : m_recentFiles)
|
|
|
|
{
|
|
|
|
if (path == testPath)
|
|
|
|
return;
|
|
|
|
}
|
2016-01-02 02:27:46 +00:00
|
|
|
m_recentFiles.push_back(path);
|
2016-01-16 03:58:11 +00:00
|
|
|
FILE* fp = HECL::Fopen(m_recentFilesPath.c_str(), _S("w"), HECL::FileLockType::Write);
|
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
for (HECL::SystemString& pPath : m_recentFiles)
|
|
|
|
fprintf(fp, "%s\n", HECL::SystemUTF8View(pPath).c_str());
|
|
|
|
fclose(fp);
|
|
|
|
}}
|
2016-01-02 02:27:46 +00:00
|
|
|
|
2015-12-06 01:27:02 +00:00
|
|
|
void ViewManager::init(boo::IApplication* app)
|
|
|
|
{
|
2016-01-05 09:53:16 +00:00
|
|
|
m_mainWindow = std::unique_ptr<boo::IWindow>(app->newWindow(_S("URDE")));
|
2015-12-06 01:27:02 +00:00
|
|
|
m_mainWindow->showWindow();
|
|
|
|
m_mainWindow->setWaitCursor(true);
|
|
|
|
|
2015-12-13 02:27:34 +00:00
|
|
|
float pixelFactor = 1.0;
|
2015-12-06 01:27:02 +00:00
|
|
|
|
|
|
|
boo::IGraphicsDataFactory* gf = m_mainWindow->getMainContextDataFactory();
|
2016-01-10 06:42:58 +00:00
|
|
|
m_viewResources.init(gf, &m_fontCache, &m_themeData, pixelFactor);
|
2016-01-18 23:33:23 +00:00
|
|
|
m_iconsToken = InitializeIcons(m_viewResources);
|
2015-12-13 02:27:34 +00:00
|
|
|
m_viewResources.prepFontCacheAsync(m_mainWindow.get());
|
2016-01-05 00:01:02 +00:00
|
|
|
Specter::RootView* root = SetupRootView();
|
|
|
|
m_showSplash = true;
|
|
|
|
root->accessContentViews().push_back(SetupSplashView());
|
|
|
|
root->updateSize();
|
2015-12-06 01:27:02 +00:00
|
|
|
|
|
|
|
m_mainWindow->setWaitCursor(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewManager::proc()
|
|
|
|
{
|
|
|
|
boo::IGraphicsCommandQueue* gfxQ = m_mainWindow->getCommandQueue();
|
|
|
|
if (m_rootView->isDestroyed())
|
|
|
|
return false;
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2015-12-09 01:04:50 +00:00
|
|
|
if (m_updatePf)
|
|
|
|
{
|
|
|
|
m_viewResources.resetPixelFactor(m_reqPf);
|
2016-01-05 00:01:02 +00:00
|
|
|
Specter::RootView* root = SetupRootView();
|
|
|
|
if (m_rootSpace)
|
2016-01-11 02:17:08 +00:00
|
|
|
BuildSpaceViews();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<Specter::View*>& cViews = m_rootView->accessContentViews();
|
|
|
|
cViews.push_back(SetupSplashView());
|
|
|
|
}
|
2016-01-05 00:01:02 +00:00
|
|
|
root->updateSize();
|
2015-12-09 01:04:50 +00:00
|
|
|
m_updatePf = false;
|
|
|
|
}
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2015-12-06 01:27:02 +00:00
|
|
|
m_rootView->dispatchEvents();
|
2016-01-31 01:08:31 +00:00
|
|
|
m_rootView->internalThink();
|
2016-01-05 00:01:02 +00:00
|
|
|
if (m_rootSpace)
|
|
|
|
m_rootSpace->think();
|
|
|
|
if (m_splash)
|
2015-12-13 02:27:34 +00:00
|
|
|
m_splash->think();
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2016-01-11 02:17:08 +00:00
|
|
|
if (m_deferSplit)
|
|
|
|
{
|
2016-01-12 00:46:27 +00:00
|
|
|
SplitSpace* ss = static_cast<SplitSpace*>(m_deferSplit->spaceSplit(m_deferSplitAxis, m_deferSplitThisSlot));
|
|
|
|
m_rootView->startSplitDrag(ss->splitView(), m_deferSplitCoord);
|
2016-01-11 02:17:08 +00:00
|
|
|
m_deferSplit = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-05 00:01:02 +00:00
|
|
|
++m_editorFrames;
|
|
|
|
if (m_rootSpaceView && m_editorFrames <= 30)
|
|
|
|
m_rootSpaceView->setMultiplyColor(Zeus::CColor::lerp({1,1,1,0}, {1,1,1,1}, m_editorFrames / 30.0));
|
|
|
|
|
2015-12-06 01:27:02 +00:00
|
|
|
m_rootView->draw(gfxQ);
|
|
|
|
gfxQ->execute();
|
|
|
|
m_mainWindow->waitForRetrace();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewManager::stop()
|
|
|
|
{
|
|
|
|
m_mainWindow->getCommandQueue()->stopRenderer();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|