Submodule updates and initial locale files

This commit is contained in:
Jack Andersen 2015-12-05 15:27:02 -10:00
parent 4e9c51f4af
commit 1dca105792
11 changed files with 219 additions and 40 deletions

View File

@ -1,7 +1,11 @@
add_subdirectory(locale)
add_executable(rude WIN32
main.cpp)
main.cpp
ViewManager.hpp ViewManager.cpp)
target_link_libraries(rude
RudeLocales
RuntimeCommonCharacter
RuntimeCommonInput
RuntimeCommon

84
Editor/ViewManager.cpp Normal file
View File

@ -0,0 +1,84 @@
#include "ViewManager.hpp"
namespace RUDE
{
void ViewManager::SetupRootView()
{
m_rootView.reset(new Specter::RootView(*this, m_viewResources, m_mainWindow.get()));
Specter::SplitView* splitView = new Specter::SplitView(m_viewResources, *m_rootView, Specter::SplitView::Axis::Horizontal);
m_rootView->setContentView(std::unique_ptr<Specter::SplitView>(splitView));
m_test1 = m_cvarManager.newCVar("hello_button", "Help for Hello Button", false,
HECL::CVar::EFlags::Archive | HECL::CVar::EFlags::Editor);
Specter::Space* space1 = new Specter::Space(m_viewResources, *splitView, Specter::Toolbar::Position::Top);
space1->toolbar().push_back(std::make_unique<Specter::Button>(m_viewResources, space1->toolbar(),
std::make_unique<Specter::CVarControlBinding>(m_test1), "Hello Button"));
Specter::MultiLineTextView* textView1 = new Specter::MultiLineTextView(m_viewResources, *space1, m_viewResources.m_heading18);
space1->setContentView(std::unique_ptr<Specter::MultiLineTextView>(textView1));
m_test2 = m_cvarManager.newCVar("hello_button_jp", "Help for Japanese Hello Button", false,
HECL::CVar::EFlags::Archive | HECL::CVar::EFlags::Editor);
Specter::Space* space2 = new Specter::Space(m_viewResources, *splitView, Specter::Toolbar::Position::Bottom);
space2->toolbar().push_back(std::make_unique<Specter::Button>(m_viewResources, space2->toolbar(),
std::make_unique<Specter::CVarControlBinding>(m_test2), "こんにちはボタン"));
Specter::MultiLineTextView* textView2 = new Specter::MultiLineTextView(m_viewResources, *space2, m_viewResources.m_heading18);
space2->setContentView(std::unique_ptr<Specter::MultiLineTextView>(textView2));
splitView->setContentView(0, std::unique_ptr<Specter::Space>(space1));
splitView->setContentView(1, std::unique_ptr<Specter::Space>(space2));
textView1->typesetGlyphs("Hello, World!\n\n", m_viewResources.themeData().uiText());
textView2->typesetGlyphs("こんにちは世界!\n\n", m_viewResources.themeData().uiText());
textView1->setBackground(m_viewResources.themeData().viewportBackground());
textView2->setBackground(m_viewResources.themeData().viewportBackground());
m_rootView->setBackground(Zeus::CColor::skGrey);
}
void ViewManager::init(boo::IApplication* app)
{
m_mainWindow = std::unique_ptr<boo::IWindow>(app->newWindow(_S("RUDE")));
m_mainWindow->showWindow();
m_mainWindow->setWaitCursor(true);
unsigned dpi = m_mainWindow->getVirtualPixelFactor() * 72;
m_cvDPI = m_cvarManager.newCVar("ed_dpi", "User-selected UI DPI",
int(dpi), HECL::CVar::EFlags::Editor | HECL::CVar::EFlags::Archive);
boo::IGraphicsDataFactory* gf = m_mainWindow->getMainContextDataFactory();
m_viewResources.init(gf, &m_fontCache, Specter::ThemeData(), dpi);
SetupRootView();
m_mainWindow->setWaitCursor(false);
}
bool ViewManager::proc()
{
boo::IGraphicsCommandQueue* gfxQ = m_mainWindow->getCommandQueue();
if (m_rootView->isDestroyed())
return false;
if (m_cvDPI->isModified())
{
unsigned dpi = m_cvDPI->toInteger();
m_viewResources.resetDPI(dpi);
m_rootView->resetResources(m_viewResources);
m_cvDPI->clearModified();
}
m_rootView->dispatchEvents();
m_rootView->draw(gfxQ);
gfxQ->execute();
m_mainWindow->waitForRetrace();
return true;
}
void ViewManager::stop()
{
m_mainWindow->getCommandQueue()->stopRenderer();
}
}

34
Editor/ViewManager.hpp Normal file
View File

@ -0,0 +1,34 @@
#ifndef RUDE_VIEW_MANAGER_HPP
#define RUDE_VIEW_MANAGER_HPP
#include <Specter/Specter.hpp>
#include <HECL/CVarManager.hpp>
namespace RUDE
{
class ViewManager : Specter::IViewManager
{
HECL::CVarManager& m_cvarManager;
Specter::FontCache m_fontCache;
Specter::ViewResources m_viewResources;
std::unique_ptr<boo::IWindow> m_mainWindow;
std::unique_ptr<Specter::RootView> m_rootView;
HECL::CVar* m_cvDPI;
HECL::CVar* m_test1;
HECL::CVar* m_test2;
void SetupRootView();
public:
ViewManager(HECL::Runtime::FileStoreManager& fileMgr, HECL::CVarManager& cvarMgr)
: m_cvarManager(cvarMgr), m_fontCache(fileMgr) {}
void init(boo::IApplication* app);
bool proc();
void stop();
};
}
#endif // RUDE_VIEW_MANAGER_HPP

View File

@ -0,0 +1,6 @@
bintoc(en_US.c en_US.yaml L_en_US)
bintoc(en_GB.c en_GB.yaml L_en_GB)
add_library(RudeLocales
en_US.yaml en_US.c
en_GB.yaml en_GB.c
locale.hpp locale.cpp)

3
Editor/locale/en_GB.yaml Normal file
View File

@ -0,0 +1,3 @@
en_GB:
controls:
color: "Colour"

3
Editor/locale/en_US.yaml Normal file
View File

@ -0,0 +1,3 @@
en_US:
controls:
color: "Color"

58
Editor/locale/locale.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "locale.hpp"
#include <cstring>
extern "C" const uint8_t L_en_US[];
extern "C" size_t L_en_US_SZ;
extern "C" const uint8_t L_en_GB[];
extern "C" size_t L_en_GB_SZ;
namespace RUDE
{
static const Specter::Locale Locales[] =
{
{"en_US", "US English", L_en_US, L_en_US_SZ},
{"en_GB", "British English", L_en_GB, L_en_GB_SZ}
};
std::vector<std::pair<const std::string*, const std::string*>> ListLocales()
{
constexpr size_t localeCount = std::extent<decltype(Locales)>::value;
std::vector<std::pair<const std::string*, const std::string*>> ret;
ret.reserve(localeCount);
for (size_t i=0 ; i<localeCount ; ++i)
{
const Specter::Locale& l = Locales[i];
ret.emplace_back(&l.name(), &l.fullName());
}
return ret;
}
const Specter::Locale* LookupLocale(const std::string& name)
{
constexpr size_t localeCount = std::extent<decltype(Locales)>::value;
for (size_t i=0 ; i<localeCount ; ++i)
{
const Specter::Locale& l = Locales[i];
if (!name.compare(l.name()))
return &l;
}
return nullptr;
}
const Specter::Locale* SystemLocaleOrEnglish()
{
const char* sysLocale = std::setlocale(LC_ALL, nullptr);
size_t sysLocaleLen = std::strlen(sysLocale);
constexpr size_t localeCount = std::extent<decltype(Locales)>::value;
for (size_t i=0 ; i<localeCount ; ++i)
{
const Specter::Locale& l = Locales[i];
if (!l.name().compare(0, std::min(l.name().size(), sysLocaleLen), sysLocale))
return &l;
}
return Locales;
}
}

15
Editor/locale/locale.hpp Normal file
View File

@ -0,0 +1,15 @@
#ifndef RUDE_LOCALE_HPP
#define RUDE_LOCALE_HPP
#include <Specter/Translator.hpp>
namespace RUDE
{
std::vector<std::pair<const std::string*, const std::string*>> ListLocales();
const Specter::Locale* LookupLocale(const std::string& name);
const Specter::Locale* SystemLocaleOrEnglish();
}
#endif // RUDE_LOCALE_HPP

View File

@ -4,58 +4,32 @@
#include <HECL/CVarManager.hpp>
#include <Runtime/CGameAllocator.hpp>
#include <functional>
#include "ViewManager.hpp"
namespace RUDE
{
struct Application : boo::IApplicationCallback
{
HECL::Runtime::FileStoreManager m_fileMgr;
Specter::FontCache m_fontCache;
boo::IWindow* m_mainWindow;
Specter::ViewResources m_viewResources;
std::unique_ptr<Specter::RootView> m_rootView;
HECL::CVarManager m_cvarManager;
ViewManager m_viewManager;
bool m_running = true;
Application() :
m_fileMgr(_S("rude")),
m_fontCache(m_fileMgr),
m_cvarManager(m_fileMgr) {}
m_cvarManager(m_fileMgr),
m_viewManager(m_fileMgr, m_cvarManager) {}
int appMain(boo::IApplication* app)
{
m_mainWindow = app->newWindow(_S("RUDE"));
m_mainWindow->showWindow();
m_mainWindow->setWaitCursor(true);
unsigned dpi = m_mainWindow->getVirtualPixelFactor() * 72;
HECL::CVar* cvDPI = m_cvarManager.newCVar("ed_dpi", "User-selected UI DPI",
int(dpi), HECL::CVar::EFlags::Editor | HECL::CVar::EFlags::Archive);
boo::IGraphicsDataFactory* gf = m_mainWindow->getMainContextDataFactory();
m_viewResources.init(gf, &m_fontCache, Specter::ThemeData(), dpi);
m_rootView.reset(new Specter::RootView(m_viewResources, m_mainWindow));
m_mainWindow->setWaitCursor(false);
boo::IGraphicsCommandQueue* gfxQ = m_mainWindow->getCommandQueue();
m_viewManager.init(app);
while (m_running)
{
if (m_rootView->isDestroyed())
if (!m_viewManager.proc())
break;
if (cvDPI->isModified())
{
dpi = cvDPI->toInteger();
m_viewResources.resetDPI(dpi);
m_rootView->resetResources(m_viewResources);
cvDPI->clearModified();
}
m_rootView->dispatchEvents();
m_rootView->draw(gfxQ);
gfxQ->execute();
m_mainWindow->waitForRetrace();
}
gfxQ->stopRenderer();
m_viewManager.stop();
m_cvarManager.serialize();
return 0;
}
@ -67,8 +41,6 @@ struct Application : boo::IApplicationCallback
{
}
};
}
@ -81,7 +53,7 @@ int main(int argc, const boo::SystemChar** argv)
{
LogVisor::RegisterConsoleLogger();
RUDE::Application appCb;
int ret = ApplicationRun(boo::IApplication::EPlatformType::Auto,
int ret = boo::ApplicationRun(boo::IApplication::EPlatformType::Auto,
appCb, _S("rude"), _S("RUDE"), argc, argv, false);
printf("IM DYING!!\n");
return ret;

2
hecl

@ -1 +1 @@
Subproject commit 95406a7a05b215c4d8c369fc93d85997e7e54b5a
Subproject commit 1ab67752dfc85f610d26eda6160c474fcb892ead

@ -1 +1 @@
Subproject commit 49cebf59c89b74b83ade6c48d3212a0a8ff67e02
Subproject commit 1f555a7b83f35f208bf79b606f8441e0528fc6f3