I am constructing a small recreation in c++, and need to present popups.
I’ve some doubt of the right way to setup a popupmanager..mainly, I’ve this pseudo code:
class Popumanager {
createPopup(); //setup for popup
Render(); //reveals popup
string isInRect(); //returns which button the mouse cursor is in
}
I take advantage of this in a GUI
class like this:
GUI {
someGUIAction() {
popupManager.createPopup();
}
onMouseClick(mouse) {
activeButton = popupManager.isInRect(mouse);
//swap button and do stuff
if (activeButton == "OK") {
//do stuff
}
}
Render() {
popupManager.Render();
}
}
This method retains my popupmanager pretty easy, it is most important accountability is drawing some rectangles and textual content to the display, and checking if the mouse is inside the popup buttons.
I can see one other method, the place I move an eventBus
to the popupManager, so that it’s going to look considerably like this:
class Popumanager {
createPopup(OKEvent, CancelEvent); //setup for popup
Render(); //reveals popup
void isInRect(); //if mouse is detected on button, emit OKEvent / CancelEvent.
}
GUI {
createPopup(OKEvent{}, CancelEvent{});
handleOkEvent() {
//do stuff
}
}
Within the second state of affairs, all communication with the popupmanager will undergo occasions, which provides some dependencies to the popupManager, however any a part of the applying will be capable of react immediately to a sure Popup motion.
Which method makes probably the most sense, do you suppose? Some other state of affairs which may match higher?