| 18 | } |
| 19 | |
| 20 | int DisplayMessageBox(const char* title, const char* message, MsgBoxButtons buttons){ |
| 21 | int width = Graphics::GetTextLength(message) + 10; |
| 22 | if(width < 220) width = 220; |
| 23 | |
| 24 | Window* win = new Window(title, {width, 80}, 0, WindowType::GUI); |
| 25 | |
| 26 | Label* label = new Label(message, {10, 10, 180, 12}); |
| 27 | win->AddWidget(label); |
| 28 | |
| 29 | if(buttons == MsgButtonsOKCancel){ |
| 30 | Button* okBtn = new Button("OK", {-52, 2, 100, 24}); |
| 31 | win->AddWidget(okBtn); |
| 32 | okBtn->SetLayout(LayoutSize::Fixed, LayoutSize::Fixed, WAlignCentre, WAlignBottom); |
| 33 | okBtn->OnPress = OnMessageBoxOKPressed; |
| 34 | |
| 35 | Button* cancelBtn = new Button("Cancel", {52, 2, 100, 24}); |
| 36 | win->AddWidget(cancelBtn); |
| 37 | cancelBtn->SetLayout(LayoutSize::Fixed, LayoutSize::Fixed, WAlignCentre, WAlignBottom); |
| 38 | cancelBtn->OnPress = OnMessageBoxCancelPressed; |
| 39 | } else { |
| 40 | Button* okBtn = new Button("OK", {0, 5, 100, 24}); |
| 41 | win->AddWidget(okBtn); |
| 42 | okBtn->SetLayout(LayoutSize::Fixed, LayoutSize::Fixed, WAlignCentre, WAlignBottom); |
| 43 | okBtn->OnPress = OnMessageBoxOKPressed; |
| 44 | } |
| 45 | |
| 46 | bool paint = true; |
| 47 | |
| 48 | while(!win->closed){ |
| 49 | LemonEvent ev; |
| 50 | while(win->PollEvent(ev)){ |
| 51 | win->GUIHandleEvent(ev); |
| 52 | paint = true; |
| 53 | } |
| 54 | |
| 55 | if(paint){ |
| 56 | win->Paint(); |
| 57 | paint = false; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | delete win; |
| 62 | |
| 63 | return pressed; |
| 64 | } |
| 65 | } |
no test coverage detected