UI: Prevent race condition during emulator startup.

This commit is contained in:
Parker Lamb 2017-07-01 14:36:16 -05:00
parent 0c20f1c0fc
commit fc27b34304
6 changed files with 47 additions and 0 deletions

View File

@ -266,6 +266,8 @@ bool EmulatorWindow::Initialize() {
window_->Resize(1280, 720); window_->Resize(1280, 720);
window_->DisableMainMenu();
return true; return true;
} }

View File

@ -178,6 +178,9 @@ int xenia_main(const std::vector<std::wstring>& args) {
evt->Set(); evt->Set();
}); });
// Enable the main menu now that the emulator is properly loaded
emulator_window->window()->EnableMainMenu();
// Grab path from the flag or unnamed argument. // Grab path from the flag or unnamed argument.
std::wstring path; std::wstring path;
if (!FLAGS_target.empty() || args.size() >= 2) { if (!FLAGS_target.empty() || args.size() >= 2) {

View File

@ -19,6 +19,8 @@
namespace xe { namespace xe {
namespace ui { namespace ui {
class Window;
class MenuItem { class MenuItem {
public: public:
typedef std::unique_ptr<MenuItem, void (*)(MenuItem*)> MenuItemPtr; typedef std::unique_ptr<MenuItem, void (*)(MenuItem*)> MenuItemPtr;
@ -51,6 +53,9 @@ class MenuItem {
void RemoveChild(MenuItem* child_item); void RemoveChild(MenuItem* child_item);
MenuItem* child(size_t index); MenuItem* child(size_t index);
virtual void EnableMenuItem(Window& window) = 0;
virtual void DisableMenuItem(Window& window) = 0;
protected: protected:
MenuItem(Type type, const std::wstring& text, const std::wstring& hotkey, MenuItem(Type type, const std::wstring& text, const std::wstring& hotkey,
std::function<void()> callback); std::function<void()> callback);

View File

@ -44,6 +44,9 @@ class Window {
OnMainMenuChange(); OnMainMenuChange();
} }
virtual void EnableMainMenu() = 0;
virtual void DisableMainMenu() = 0;
const std::wstring& title() const { return title_; } const std::wstring& title() const { return title_; }
virtual bool set_title(const std::wstring& title) { virtual bool set_title(const std::wstring& title) {
if (title == title_) { if (title == title_) {

View File

@ -163,6 +163,18 @@ void Win32Window::OnClose() {
super::OnClose(); super::OnClose();
} }
void Win32Window::EnableMainMenu() {
if (main_menu_) {
main_menu_->EnableMenuItem(*this);
}
}
void Win32Window::DisableMainMenu() {
if (main_menu_) {
main_menu_->DisableMenuItem(*this);
}
}
bool Win32Window::set_title(const std::wstring& title) { bool Win32Window::set_title(const std::wstring& title) {
if (!super::set_title(title)) { if (!super::set_title(title)) {
return false; return false;
@ -628,6 +640,22 @@ Win32MenuItem::~Win32MenuItem() {
} }
} }
void Win32MenuItem::EnableMenuItem(Window& window) {
int i = 0;
for (auto iter = children_.begin(); iter != children_.end(); ++iter, i++) {
::EnableMenuItem(handle_, i, MF_BYPOSITION | MF_ENABLED);
}
DrawMenuBar((HWND)window.native_handle());
}
void Win32MenuItem::DisableMenuItem(Window& window) {
int i = 0;
for (auto iter = children_.begin(); iter != children_.end(); ++iter, i++) {
::EnableMenuItem(handle_, i, MF_BYPOSITION | MF_GRAYED);
}
DrawMenuBar((HWND)window.native_handle());
}
void Win32MenuItem::OnChildAdded(MenuItem* generic_child_item) { void Win32MenuItem::OnChildAdded(MenuItem* generic_child_item) {
auto child_item = static_cast<Win32MenuItem*>(generic_child_item); auto child_item = static_cast<Win32MenuItem*>(generic_child_item);

View File

@ -30,6 +30,9 @@ class Win32Window : public Window {
NativeWindowHandle native_handle() const override { return hwnd_; } NativeWindowHandle native_handle() const override { return hwnd_; }
HWND hwnd() const { return hwnd_; } HWND hwnd() const { return hwnd_; }
void EnableMainMenu() override;
void DisableMainMenu() override;
bool set_title(const std::wstring& title) override; bool set_title(const std::wstring& title) override;
bool SetIcon(const void* buffer, size_t size) override; bool SetIcon(const void* buffer, size_t size) override;
@ -87,6 +90,9 @@ class Win32MenuItem : public MenuItem {
HMENU handle() { return handle_; } HMENU handle() { return handle_; }
void EnableMenuItem(Window& window) override;
void DisableMenuItem(Window& window) override;
using MenuItem::OnSelected; using MenuItem::OnSelected;
protected: protected: