From 95e2ea11eb6a28dc7aff9b8c7fa382494c5da450 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Mon, 6 Jul 2015 23:03:24 -0700 Subject: [PATCH] Cleaning up paths a bit. Need to de-globalize. --- src/xenia/debug/ui/application.cc | 32 ----------- src/xenia/ui/elemental_control.cc | 94 ++++++++++++++++++++++++------- src/xenia/ui/elemental_control.h | 6 +- third_party/elemental-forms | 2 +- 4 files changed, 81 insertions(+), 53 deletions(-) diff --git a/src/xenia/debug/ui/application.cc b/src/xenia/debug/ui/application.cc index 8a0928ffb..62bf87e17 100644 --- a/src/xenia/debug/ui/application.cc +++ b/src/xenia/debug/ui/application.cc @@ -9,9 +9,6 @@ #include "xenia/debug/ui/application.h" -#include "el/message_handler.h" -#include "el/util/metrics.h" -#include "el/util/timer.h" #include "xenia/base/assert.h" #include "xenia/base/logging.h" #include "xenia/base/platform.h" @@ -78,32 +75,3 @@ void Application::Quit() { } // namespace ui } // namespace debug } // namespace xe - -// This doesn't really belong here (it belongs in tb_system_[linux/windows].cpp. -// This is here since the proper implementations has not yet been done. -void el::util::RescheduleTimer(uint64_t fire_time) { - if (fire_time == el::MessageHandler::kNotSoon) { - return; - } - - uint64_t now = el::util::GetTimeMS(); - uint64_t delay_millis = fire_time >= now ? fire_time - now : 0; - xe::debug::ui::Application::current()->loop()->PostDelayed([]() { - uint64_t next_fire_time = el::MessageHandler::GetNextMessageFireTime(); - uint64_t now = el::util::GetTimeMS(); - if (now < next_fire_time) { - // We timed out *before* we were supposed to (the OS is not playing nice). - // Calling ProcessMessages now won't achieve a thing so force a reschedule - // of the platform timer again with the same time. - // ReschedulePlatformTimer(next_fire_time, true); - return; - } - - el::MessageHandler::ProcessMessages(); - - // If we still have things to do (because we didn't process all messages, - // or because there are new messages), we need to rescedule, so call - // RescheduleTimer. - el::util::RescheduleTimer(el::MessageHandler::GetNextMessageFireTime()); - }, delay_millis); -} diff --git a/src/xenia/ui/elemental_control.cc b/src/xenia/ui/elemental_control.cc index 1033f956f..c17f350bd 100644 --- a/src/xenia/ui/elemental_control.cc +++ b/src/xenia/ui/elemental_control.cc @@ -11,7 +11,14 @@ #include "el/animation_manager.h" #include "el/elemental_forms.h" +#include "el/io/embedded_file_system.h" +#include "el/io/file_manager.h" +#include "el/io/posix_file_system.h" +#include "el/message_handler.h" #include "el/text/font_manager.h" +#include "el/util/metrics.h" +#include "el/util/string_table.h" +#include "el/util/timer.h" #include "xenia/base/assert.h" #include "xenia/base/clock.h" #include "xenia/base/logging.h" @@ -29,6 +36,8 @@ constexpr double kDoubleClickDistance = 5; constexpr int32_t kMouseWheelDetent = 120; +Loop* elemental_loop_ = nullptr; + class RootElement : public el::Element { public: RootElement(ElementalControl* owner) : owner_(owner) {} @@ -38,26 +47,39 @@ class RootElement : public el::Element { ElementalControl* owner_ = nullptr; }; -bool ElementalControl::InitializeElemental(el::graphics::Renderer* renderer) { +bool ElementalControl::InitializeElemental(Loop* loop, + el::graphics::Renderer* renderer) { static bool has_initialized = false; if (has_initialized) { return true; } has_initialized = true; - if (!el::Initialize( - renderer, - "third_party/turbobadger/resources/language/lng_en.tb.txt")) { + // Need to pass off the Loop we want Elemental to use. + // TODO(benvanik): give the callback to elemental instead. + elemental_loop_ = loop; + + if (!el::Initialize(renderer)) { XELOGE("Failed to initialize turbobadger core"); return false; } - // Load the default skin, and override skin that contains the graphics - // specific to the demo. - if (!el::Skin::get()->Load( - "third_party/elemental-forms/resources/default_skin/skin.tb.txt", - "third_party/elemental-forms/testbed/resources/skin/skin.tb.txt")) { - XELOGE("Failed to load turbobadger skin"); + el::io::FileManager::RegisterFileSystem( + std::make_unique( + "third_party/elemental-forms/resources/")); + el::io::FileManager::RegisterFileSystem( + std::make_unique( + "third_party/elemental-forms/testbed/resources/")); + auto embedded_file_system = std::make_unique(); + // TODO(benvanik): bin2c stuff. + el::io::FileManager::RegisterFileSystem(std::move(embedded_file_system)); + + // Load default translations. + el::util::StringTable::get()->Load("default_language/language_en.tb.txt"); + + // Load the default skin. Hosting controls may load additional skins later. + if (!LoadSkin("default_skin/skin.tb.txt")) { + XELOGE("Failed to load default skin"); return false; } @@ -78,14 +100,10 @@ bool ElementalControl::InitializeElemental(el::graphics::Renderer* renderer) { // Add fonts we can use to the font manager. #if defined(EL_FONT_RENDERER_STB) || defined(EL_FONT_RENDERER_FREETYPE) - font_manager->AddFontInfo("third_party/elemental-forms/resources/vera.ttf", - "Default"); + font_manager->AddFontInfo("fonts/vera.ttf", "Default"); #endif #ifdef EL_FONT_RENDERER_TBBF - font_manager->AddFontInfo( - "third_party/elemental-forms/resources/default_font/" - "segoe_white_with_shadow.tb.txt", - "Default"); + font_manager->AddFontInfo("fonts/segoe_white_with_shadow.tb.txt", "Default"); #endif // Set the default font description for elements to one of the fonts we just @@ -101,7 +119,8 @@ bool ElementalControl::InitializeElemental(el::graphics::Renderer* renderer) { return true; } -ElementalControl::ElementalControl(Loop* loop, uint32_t flags) : super(flags) {} +ElementalControl::ElementalControl(Loop* loop, uint32_t flags) + : super(flags), loop_(loop) {} ElementalControl::~ElementalControl() = default; @@ -115,8 +134,8 @@ bool ElementalControl::Create() { // Initialize elemental. // TODO(benvanik): once? Do we care about multiple controls? - if (!InitializeElemental(renderer_.get())) { - XELOGE("Unable to initialize turbobadger"); + if (!InitializeElemental(loop_, renderer_.get())) { + XELOGE("Unable to initialize elemental-forms"); return false; } @@ -137,6 +156,14 @@ bool ElementalControl::Create() { return true; } +bool ElementalControl::LoadLanguage(std::string filename) { + return el::util::StringTable::get()->Load(filename.c_str()); +} + +bool ElementalControl::LoadSkin(std::string filename) { + return el::Skin::get()->Load(filename.c_str()); +} + void ElementalControl::Destroy() { el::Shutdown(); super::Destroy(); @@ -476,3 +503,32 @@ void ElementalControl::OnMouseWheel(MouseEvent& e) { } // namespace ui } // namespace xe + +// This doesn't really belong here (it belongs in tb_system_[linux/windows].cpp. +// This is here since the proper implementations has not yet been done. +void el::util::RescheduleTimer(uint64_t fire_time) { + if (fire_time == el::MessageHandler::kNotSoon) { + return; + } + + uint64_t now = el::util::GetTimeMS(); + uint64_t delay_millis = fire_time >= now ? fire_time - now : 0; + xe::ui::elemental_loop_->PostDelayed([]() { + uint64_t next_fire_time = el::MessageHandler::GetNextMessageFireTime(); + uint64_t now = el::util::GetTimeMS(); + if (now < next_fire_time) { + // We timed out *before* we were supposed to (the OS is not playing nice). + // Calling ProcessMessages now won't achieve a thing so force a reschedule + // of the platform timer again with the same time. + // ReschedulePlatformTimer(next_fire_time, true); + return; + } + + el::MessageHandler::ProcessMessages(); + + // If we still have things to do (because we didn't process all messages, + // or because there are new messages), we need to rescedule, so call + // RescheduleTimer. + el::util::RescheduleTimer(el::MessageHandler::GetNextMessageFireTime()); + }, delay_millis); +} diff --git a/src/xenia/ui/elemental_control.h b/src/xenia/ui/elemental_control.h index f39fa2c12..f61569e0c 100644 --- a/src/xenia/ui/elemental_control.h +++ b/src/xenia/ui/elemental_control.h @@ -29,10 +29,13 @@ class ElementalControl : public PlatformControl { el::graphics::Renderer* renderer() const { return renderer_.get(); } el::Element* root_element() const { return root_element_.get(); } + bool LoadLanguage(std::string filename); + bool LoadSkin(std::string filename); + protected: using super = PlatformControl; - bool InitializeElemental(el::graphics::Renderer* renderer); + bool InitializeElemental(Loop* loop, el::graphics::Renderer* renderer); virtual std::unique_ptr CreateRenderer() = 0; bool Create() override; @@ -56,6 +59,7 @@ class ElementalControl : public PlatformControl { void OnMouseUp(MouseEvent& e) override; void OnMouseWheel(MouseEvent& e) override; + Loop* loop_ = nullptr; std::unique_ptr renderer_; std::unique_ptr root_element_; diff --git a/third_party/elemental-forms b/third_party/elemental-forms index b7322a960..17b41976c 160000 --- a/third_party/elemental-forms +++ b/third_party/elemental-forms @@ -1 +1 @@ -Subproject commit b7322a960063620938d76156c0ce4a4328788e71 +Subproject commit 17b41976c4277b702d8ec2f16e849d75d69cec71