bsnes/hiro/extension/message-dialog.cpp
Tim Allen 0b923489dd Update to 20160106 OS X Preview for Developers release.
byuu says:

New update. Most of the work today went into eliminating hiro::Image
from all objects in all ports, replacing with nall::image. That took an
eternity.

Changelog:
- fixed crashing bug when loading games [thanks endrift!!]
- toggling "show status bar" option adjusts window geometry (not
  supposed to recenter the window, though)
- button sizes improved; icon-only button icons no longer being cut off
2016-01-07 19:17:15 +11:00

81 lines
2.3 KiB
C++

#if defined(Hiro_MessageDialog)
MessageDialog::MessageDialog(const string& text) {
state.text = text;
}
auto MessageDialog::error(const lstring& buttons) -> string {
state.buttons = buttons;
state.icon = Icon::Prompt::Error;
return _run();
}
auto MessageDialog::information(const lstring& buttons) -> string {
state.buttons = buttons;
state.icon = Icon::Prompt::Information;
return _run();
}
auto MessageDialog::question(const lstring& buttons) -> string {
state.buttons = buttons;
state.icon = Icon::Prompt::Question;
return _run();
}
auto MessageDialog::setParent(shared_pointer<mWindow> parent) -> type& {
state.parent = parent;
return *this;
}
auto MessageDialog::setText(const string& text) -> type& {
state.text = text;
return *this;
}
auto MessageDialog::setTitle(const string& title) -> type& {
state.title = title;
return *this;
}
auto MessageDialog::warning(const lstring& buttons) -> string {
state.buttons = buttons;
state.icon = Icon::Prompt::Warning;
return _run();
}
auto MessageDialog::_run() -> string {
Window window;
VerticalLayout layout{&window};
HorizontalLayout messageLayout{&layout, Size{~0, 0}, 5};
Canvas messageIcon{&messageLayout, Size{16, 16}, 5};
Label messageText{&messageLayout, Size{~0, 0}};
HorizontalLayout controlLayout{&layout, Size{~0, 0}};
Widget controlSpacer{&controlLayout, Size{~0, 0}};
layout.setMargin(5);
messageIcon.setIcon(state.icon);
messageText.setText(state.text);
for(auto n : range(state.buttons)) {
Button button{&controlLayout, Size{80, 0}, 5};
button.onActivate([&, n] { state.response = state.buttons[n]; window.setModal(false); });
button.setText(state.buttons[n]);
button.setFocused(); //the last button will have effective focus
}
signed widthMessage = 5 + 16 + 5 + Font().size(state.text).width() + 5;
signed widthButtons = 5 + state.buttons.size() * 85;
signed width = max(320, widthMessage, widthButtons);
window.onClose([&] { window.setModal(false); });
window.setTitle(state.title);
window.setResizable(false);
window.setSize({width, layout.minimumSize().height()});
window.setCentered(state.parent);
window.setVisible();
window.setModal();
window.setVisible(false);
return state.response;
}
#endif