UI: Prevent race condition during emulator startup.
This commit is contained in:
parent
0c20f1c0fc
commit
fc27b34304
|
@ -266,6 +266,8 @@ bool EmulatorWindow::Initialize() {
|
|||
|
||||
window_->Resize(1280, 720);
|
||||
|
||||
window_->DisableMainMenu();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -178,6 +178,9 @@ int xenia_main(const std::vector<std::wstring>& args) {
|
|||
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.
|
||||
std::wstring path;
|
||||
if (!FLAGS_target.empty() || args.size() >= 2) {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
class Window;
|
||||
|
||||
class MenuItem {
|
||||
public:
|
||||
typedef std::unique_ptr<MenuItem, void (*)(MenuItem*)> MenuItemPtr;
|
||||
|
@ -51,6 +53,9 @@ class MenuItem {
|
|||
void RemoveChild(MenuItem* child_item);
|
||||
MenuItem* child(size_t index);
|
||||
|
||||
virtual void EnableMenuItem(Window& window) = 0;
|
||||
virtual void DisableMenuItem(Window& window) = 0;
|
||||
|
||||
protected:
|
||||
MenuItem(Type type, const std::wstring& text, const std::wstring& hotkey,
|
||||
std::function<void()> callback);
|
||||
|
|
|
@ -44,6 +44,9 @@ class Window {
|
|||
OnMainMenuChange();
|
||||
}
|
||||
|
||||
virtual void EnableMainMenu() = 0;
|
||||
virtual void DisableMainMenu() = 0;
|
||||
|
||||
const std::wstring& title() const { return title_; }
|
||||
virtual bool set_title(const std::wstring& title) {
|
||||
if (title == title_) {
|
||||
|
|
|
@ -163,6 +163,18 @@ void Win32Window::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) {
|
||||
if (!super::set_title(title)) {
|
||||
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) {
|
||||
auto child_item = static_cast<Win32MenuItem*>(generic_child_item);
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@ class Win32Window : public Window {
|
|||
NativeWindowHandle native_handle() const override { return hwnd_; }
|
||||
HWND hwnd() const { return hwnd_; }
|
||||
|
||||
void EnableMainMenu() override;
|
||||
void DisableMainMenu() override;
|
||||
|
||||
bool set_title(const std::wstring& title) override;
|
||||
|
||||
bool SetIcon(const void* buffer, size_t size) override;
|
||||
|
@ -87,6 +90,9 @@ class Win32MenuItem : public MenuItem {
|
|||
|
||||
HMENU handle() { return handle_; }
|
||||
|
||||
void EnableMenuItem(Window& window) override;
|
||||
void DisableMenuItem(Window& window) override;
|
||||
|
||||
using MenuItem::OnSelected;
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue