The Battle for Wesnoth  1.17.0-dev
message.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2021
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 /**
15  * @file
16  * This file contains the definitions for the @ref gui2::event::message class.
17  *
18  * The class is used in the @ref gui2::event::signal_message_function
19  */
20 
21 #pragma once
22 
23 #include "gui/widgets/helper.hpp"
24 #include "sdl/point.hpp"
25 
26 namespace gui2
27 {
28 
29 namespace event
30 {
31 
32 /**
33  * The message callbacks hold a reference to a message.
34  *
35  * The contents of the message differ per type. This class is a base with a
36  * virtual destructor, which makes it possible to use a dynamic_cast on the
37  * class received to make sure the proper message type is send.
38  *
39  * This means all messages used in the events need to be derived from this
40  * class. When a message needs no `content' it can send this class as message.
41  * This is done by:
42  * * @ref REQUEST_PLACEMENT
43  */
44 struct message
45 {
46  message() = default;
47 
48  // Disallow copying because constructing a copy loses the exact type.
49  message(const message&) = delete;
50 
51  virtual ~message()
52  {
53  }
54 };
55 
56 /** The message for MESSAGE_SHOW_TOOLTIP. */
58 {
59  message_show_tooltip(const std::string& message_, const point& location_, const SDL_Rect& source_rect_)
60  : message(message_), location(location_), source_rect(source_rect_)
61  {
62  }
63 
64  /** The message to show on the tooltip. */
65  const std::string message;
66 
67  /** The location where to show the tooltip. */
68  const point location;
69 
70  /** The size of the entity requesting to show a tooltip. */
71  const SDL_Rect source_rect;
72 };
73 
74 /** The message for MESSAGE_SHOW_HELPTIP. */
76 {
77  message_show_helptip(const std::string& message_, const point& location_, const SDL_Rect& source_rect_)
78  : message(message_), location(location_), source_rect(source_rect_)
79  {
80  }
81 
82  /** The message to show on the helptip. */
83  const std::string message;
84 
85  /** The location where to show the helptip. */
86  const point location;
87 
88  /** The size of the entity requesting to show a helptip. */
89  const SDL_Rect source_rect;
90 };
91 
92 } // namespace event
93 
94 } // namespace gui2
const std::string message
The message to show on the tooltip.
Definition: message.hpp:65
const std::string message
The message to show on the helptip.
Definition: message.hpp:83
const point location
The location where to show the tooltip.
Definition: message.hpp:68
The message for MESSAGE_SHOW_HELPTIP.
Definition: message.hpp:75
const SDL_Rect source_rect
The size of the entity requesting to show a tooltip.
Definition: message.hpp:71
const point location
The location where to show the helptip.
Definition: message.hpp:86
Generic file dialog.
Definition: field-fwd.hpp:22
The message callbacks hold a reference to a message.
Definition: message.hpp:44
const SDL_Rect source_rect
The size of the entity requesting to show a helptip.
Definition: message.hpp:89
message_show_helptip(const std::string &message_, const point &location_, const SDL_Rect &source_rect_)
Definition: message.hpp:77
message_show_tooltip(const std::string &message_, const point &location_, const SDL_Rect &source_rect_)
Definition: message.hpp:59
The message for MESSAGE_SHOW_TOOLTIP.
Definition: message.hpp:57
virtual ~message()
Definition: message.hpp:51
Holds a 2D point.
Definition: point.hpp:23