8#ifndef __HANDLECHAIN_MESSAGEWINDOW_CLASS_H__
9#define __HANDLECHAIN_MESSAGEWINDOW_CLASS_H__
16#include "helpers/formatstring.h"
78 bool isInside =
false;
192 static MessageWindow::shared_ptr_t
CreateWindow(std::string title,
int x,
int y,
int width,
int height,
HandlerChain* handlerChain);
311 bool messageProcessed =
false;
313 std::map<MessageType, MessageHandler>::const_iterator foundIter;
318 messageProcessed = handler (
this, message);
321 return messageProcessed;
Implementation of the HandlerChain class and declaration of the IMessageHandler interface used in the...
Implementation of the Message and MessagePosition structs used in the HandlerChain Pattern.
Represents a list of handlers that all implement the IMessageHandler interface. This list can be dyna...
Represents a rectangular region that can handle messages directed to that region.
WindowRectangle _closeBox
Position of the close window within the window box, although the coordinates are also global coordina...
static int _nextWindowId
Used for assigning a unique ID to each created window.
std::string _title
Title/Name of this window.
bool _PointInWindow(MessagePosition position)
Determine if the specified point is in this MessageWindow's region.
std::map< MessageType, MessageHandler > _messageHandlers
Maps a message type to a handler method of type MessageHandler.
bool ProcessMessage(Message *message)
Processes a message.
std::shared_ptr< MessageWindow > shared_ptr_t
std::string ToString()
Convert this handler to a string.
HandlerChain * _handlerChain
The HandlerChain to which this window belongs (as an IMessageHandler object).
bool _selected
Whether this window has been selected (a button click occurred within the window).
bool(*)(MessageWindow *window, Message *message) MessageHandler
Alias for the function that handles the messages.
int _windowId
Unique ID of this window.
WindowRectangle _windowBox
Position of this window in global coordinates.
static bool _HandleButtonDownMessage(MessageWindow *window, Message *message)
Helper method to handle the ButtonDown message.
static MessageWindow::shared_ptr_t CreateWindow(std::string title, int x, int y, int width, int height, HandlerChain *handlerChain)
Creates an instance of the MessageWindow class with the specified attributes and adds the new instanc...
MessageWindow(int windowId, std::string title, int x, int y, int width, int height, HandlerChain *handlerChain)
Constructor.
static bool _HandleButtonUpMessage(MessageWindow *window, Message *message)
Helper method to handle the ButtonUp message.
bool _PointInCloseBox(MessagePosition position)
Determine if the specified point is in this MessageWindow's "close" region.
int ID()
Returns the ID of the message handler.
static bool _HandleCloseMessage(MessageWindow *window, Message *message)
Helper method to handle the Close message.
Represents a rectangular region, with upper left and lower right coordinates.
WindowRectangle(int x, int y, int width, int height)
Constructor.
std::string ToString()
Convert this rectangle to a string.
const int MINIMUM_WIDTH
Minimum width of a window (to accommodate a close box).
const int MINIMUM_HEIGHT
Minimum height of a window (to accommodate a close box).
bool PointInside(MessagePosition point)
Determine if the given point is in the rectangle.
The namespace containing all Design Pattern Examples implemented in C++.
@ ButtonUp
Take an action on the currently selected window.
@ ButtonDown
Selects a window based on position.
@ Close
Window is asked to close itself, generally sent by the window itself in response to a button up in a ...
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....
Represents a handler in a chain of handlers. All objects that participate in the HandlerChain class m...
Represents a message sent to the windows. A message contains a type and a position.
enum MessageType MessageType
Value from the MessageType enumeration indicating the type of this message.
Position of the message in global coordinates (same scope of coordinates as windows)....