Represents a rectangular region that can handle messages directed to that region. More...
#include <HandlerChain_MessageWindow_Class.h>
Public Types | |
using | shared_ptr_t = std::shared_ptr< MessageWindow > |
Public Member Functions | |
bool | _PointInWindow (MessagePosition position) |
Determine if the specified point is in this MessageWindow's region. | |
bool | _PointInCloseBox (MessagePosition position) |
Determine if the specified point is in this MessageWindow's "close" region. | |
MessageWindow (int windowId, std::string title, int x, int y, int width, int height, HandlerChain *handlerChain) | |
Constructor. | |
int | ID () |
Returns the ID of the message handler. | |
bool | ProcessMessage (Message *message) |
Processes a message. | |
std::string | ToString () |
Convert this handler to a string. | |
Static Public Member Functions | |
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 instance to the given HandlerChain object. | |
static bool | _HandleButtonDownMessage (MessageWindow *window, Message *message) |
Helper method to handle the ButtonDown message. | |
static bool | _HandleButtonUpMessage (MessageWindow *window, Message *message) |
Helper method to handle the ButtonUp message. | |
static bool | _HandleCloseMessage (MessageWindow *window, Message *message) |
Helper method to handle the Close message. | |
Private Types | |
using | MessageHandler = bool(*)(MessageWindow *window, Message *message) |
Alias for the function that handles the messages. | |
Private Attributes | |
const int | CLOSE_WIDTH = 2 |
const int | CLOSE_HEIGHT = 2 |
std::map< MessageType, MessageHandler > | _messageHandlers |
Maps a message type to a handler method of type MessageHandler. | |
int | _windowId |
Unique ID of this window. | |
std::string | _title |
Title/Name of this window. | |
WindowRectangle | _windowBox |
Position of this window in global coordinates. | |
WindowRectangle | _closeBox |
Position of the close window within the window box, although the coordinates are also global coordinates to eliminate the need to convert between window and global coordinates. | |
bool | _selected |
Whether this window has been selected (a button click occurred within the window). | |
HandlerChain * | _handlerChain |
The HandlerChain to which this window belongs (as an IMessageHandler object). | |
Static Private Attributes | |
static int | _nextWindowId = 1 |
Used for assigning a unique ID to each created window. | |
Represents a rectangular region that can handle messages directed to that region.
Note: The IMessageHandler interface is an example of a Facade design pattern, where the complexity of the MessageWindow is exposed only through a few methods to a system that only needs to deal with those few methods.
Definition at line 117 of file HandlerChain_MessageWindow_Class.h.
|
private |
Alias for the function that handles the messages.
Definition at line 130 of file HandlerChain_MessageWindow_Class.h.
using shared_ptr_t = std::shared_ptr<MessageWindow> |
Definition at line 120 of file HandlerChain_MessageWindow_Class.h.
|
inline |
Constructor.
windowId | Unique ID of the window to use. |
title | Title of the window. |
x | Global x position of the upper left corner of the window's region. |
y | Global y position of the upper left corner of the window's region. |
width | Width of the window's region. |
height | Height of the window's region. |
handlerChain | A HandlerChain object that will be used for removal of this window when it is closed. |
Definition at line 231 of file HandlerChain_MessageWindow_Class.h.
References MessageWindow::_HandleButtonDownMessage(), MessageWindow::_HandleButtonUpMessage(), MessageWindow::_HandleCloseMessage(), MessageWindow::_messageHandlers, DesignPatternExamples_cpp::ButtonDown, DesignPatternExamples_cpp::ButtonUp, and DesignPatternExamples_cpp::Close.
|
static |
Helper method to handle the ButtonDown message.
window | The window that is handling the message |
message | A Message object describing the ButtonDown message. |
Definition at line 31 of file HandlerChain_MessageWindow_Class.cpp.
References MessageWindow::_PointInWindow(), MessageWindow::_selected, MessageWindow::_title, Helpers::formatstring(), and Message::Position.
Referenced by MessageWindow::MessageWindow().
|
static |
Helper method to handle the ButtonUp message.
window | The window that is handling the message |
message | A Message object describing the ButtonUp message. |
Definition at line 62 of file HandlerChain_MessageWindow_Class.cpp.
References MessageWindow::_handlerChain, MessageWindow::_PointInCloseBox(), MessageWindow::_PointInWindow(), MessageWindow::_selected, MessageWindow::_title, DesignPatternExamples_cpp::Close, Helpers::formatstring(), Message::Position, and HandlerChain::SendMessage().
Referenced by MessageWindow::MessageWindow().
|
static |
Helper method to handle the Close message.
window | The window that is handling the message |
message | A Message object describing the Close message. |
Definition at line 92 of file HandlerChain_MessageWindow_Class.cpp.
References MessageWindow::_handlerChain, MessageWindow::_selected, MessageWindow::_title, Helpers::formatstring(), and HandlerChain::RemoveHandler().
Referenced by MessageWindow::MessageWindow().
|
inline |
Determine if the specified point is in this MessageWindow's "close" region.
position | The point to examine. |
Definition at line 213 of file HandlerChain_MessageWindow_Class.h.
References MessageWindow::_closeBox, and WindowRectangle::PointInside().
Referenced by MessageWindow::_HandleButtonUpMessage().
|
inline |
Determine if the specified point is in this MessageWindow's region.
position | The global coordinate to examine. |
Definition at line 200 of file HandlerChain_MessageWindow_Class.h.
References MessageWindow::_windowBox, and WindowRectangle::PointInside().
Referenced by MessageWindow::_HandleButtonDownMessage(), and MessageWindow::_HandleButtonUpMessage().
|
static |
Creates an instance of the MessageWindow class with the specified attributes and adds the new instance to the given HandlerChain object.
title | Title of the MessageWindow. |
x | X position of the upper left corner of the window's region. |
y | Y position of the upper left corner of hte window's region. |
width | Width of the window's region. |
height | Height of the window's region. |
handlerChain | A HandlerChain object that will be given the window. |
Each MessageWindow instance is assigned a unique ID, which is required by the HandlerChain object.
Definition at line 15 of file HandlerChain_MessageWindow_Class.cpp.
References MessageWindow::_nextWindowId, and HandlerChain::AddHandler().
|
inlinevirtual |
Returns the ID of the message handler.
Implements IMessageHandler.
Definition at line 292 of file HandlerChain_MessageWindow_Class.h.
References MessageWindow::_windowId.
Referenced by MessageWindow::ToString().
|
inlinevirtual |
Processes a message.
message | The Message object to process. |
The message types are mapped to handlers in the MessageWindow constructor and stored in the _messageHandlers dictionary.
Implements IMessageHandler.
Definition at line 309 of file HandlerChain_MessageWindow_Class.h.
References MessageWindow::_messageHandlers, and Message::MessageType.
|
inlinevirtual |
Convert this handler to a string.
Implements IMessageHandler.
Definition at line 329 of file HandlerChain_MessageWindow_Class.h.
References MessageWindow::_selected, MessageWindow::_title, MessageWindow::_windowBox, Helpers::formatstring(), MessageWindow::ID(), and WindowRectangle::ToString().
|
private |
Position of the close window within the window box, although the coordinates are also global coordinates to eliminate the need to convert between window and global coordinates.
Definition at line 157 of file HandlerChain_MessageWindow_Class.h.
Referenced by MessageWindow::_PointInCloseBox().
|
private |
The HandlerChain to which this window belongs (as an IMessageHandler object).
Definition at line 168 of file HandlerChain_MessageWindow_Class.h.
Referenced by MessageWindow::_HandleButtonUpMessage(), and MessageWindow::_HandleCloseMessage().
|
private |
Maps a message type to a handler method of type MessageHandler.
Definition at line 135 of file HandlerChain_MessageWindow_Class.h.
Referenced by HandlerChain::AddHandler(), MessageWindow::MessageWindow(), MessageWindow::ProcessMessage(), HandlerChain::RemoveHandler(), HandlerChain::SendMessage(), and HandlerChain::ToString().
|
staticprivate |
Used for assigning a unique ID to each created window.
Definition at line 173 of file HandlerChain_MessageWindow_Class.h.
Referenced by MessageWindow::CreateWindow().
|
private |
Whether this window has been selected (a button click occurred within the window).
Definition at line 163 of file HandlerChain_MessageWindow_Class.h.
Referenced by MessageWindow::_HandleButtonDownMessage(), MessageWindow::_HandleButtonUpMessage(), MessageWindow::_HandleCloseMessage(), and MessageWindow::ToString().
|
private |
Title/Name of this window.
Definition at line 145 of file HandlerChain_MessageWindow_Class.h.
Referenced by MessageWindow::_HandleButtonDownMessage(), MessageWindow::_HandleButtonUpMessage(), MessageWindow::_HandleCloseMessage(), and MessageWindow::ToString().
|
private |
Position of this window in global coordinates.
Definition at line 150 of file HandlerChain_MessageWindow_Class.h.
Referenced by MessageWindow::_PointInWindow(), and MessageWindow::ToString().
|
private |
Unique ID of this window.
Definition at line 140 of file HandlerChain_MessageWindow_Class.h.
Referenced by MessageWindow::ID().
|
private |
Definition at line 125 of file HandlerChain_MessageWindow_Class.h.
|
private |
Definition at line 124 of file HandlerChain_MessageWindow_Class.h.