[ad_1]
I’m constructing a small sport in c++, and wish to present popups.
I’ve some doubt of how you can setup a popupmanager..mainly, I’ve this pseudo code:
class Popumanager {
createPopup(); //setup for popup
Render(); //exhibits popup
string isInRect(); //returns which button the mouse cursor is in
}
I exploit this in a GUI class like this:
GUI {
someGUIAction() {
popupManager.createPopup();
}
onMouseClick(mouse) {
activeButton = popupManager.isInRect(mouse);
//change button and do stuff
if (activeButton == "OK") {
//do stuff
}
}
Render() {
popupManager.Render();
}
}
This strategy retains my popupmanager pretty easy, it is primary 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 strategy, the place I go an eventBus to the popupManager, so that it’s going to look considerably like this:
class Popumanager {
createPopup(OKEvent, CancelEvent); //setup for popup
Render(); //exhibits popup
void isInRect(); //if mouse is detected on button, emit OKEvent / CancelEvent.
}
GUI {
createPopup(OKEvent{}, CancelEvent{});
handleOkEvent() {
//do stuff
}
}
In the second situation, 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 to react immediately to a sure Popup motion.
Which approach makes essentially the most sense, do you assume? Any different situation that may match higher?
[ad_2]