GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/popup.h Lines: 2 4 50.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *  Copyright (C) 2009  Aethyra Development Team
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#ifndef GUI_WIDGETS_POPUP_H
25
#define GUI_WIDGETS_POPUP_H
26
27
#include "gui/widgets/container.h"
28
29
#include "listeners/mouselistener.h"
30
#include "listeners/widgetlistener.h"
31
32
class ImageCollection;
33
class Skin;
34
class WindowContainer;
35
36
/**
37
 * A light version of the Window class. Particularly suited for popup type
38
 * functionality that doesn't need to be resized or moved around by the mouse
39
 * once created, but only needs to display some simple content, like a static
40
 * message.
41
 *
42
 * Popups, in general, shouldn't also need to update their content once
43
 * created, although this is not an explicit requirement to use the popup
44
 * class.
45
 *
46
 * \ingroup GUI
47
 */
48
class Popup notfinal : public Container,
49
                       public MouseListener,
50
                       public WidgetListener
51
{
52
    public:
53
        /**
54
         * Constructor. Initializes the title to the given text and hooks
55
         * itself into the popup container.
56
         *
57
         * @param name    A human readable name for the popup. Only useful for
58
         *                debugging purposes.
59
         * @param skin    The location where the Popup's skin XML can be found.
60
         */
61
        explicit Popup(const std::string &name = "",
62
                       std::string skin = "");
63
64
        A_DELETE_COPY(Popup)
65
66
        /**
67
         * Destructor. Deletes all the added widgets.
68
         */
69
        virtual ~Popup();
70
71
        /**
72
         * Sets the window container to be used by new popups.
73
         */
74
        static void setWindowContainer(WindowContainer *const windowContainer);
75
76
        /**
77
         * Draws the popup.
78
         */
79
        void draw(Graphics *const graphics) override A_NONNULL(2);
80
81
        void safeDraw(Graphics *const graphics) override A_NONNULL(2);
82
83
        /**
84
         * Sets the size of this popup.
85
         */
86
        void setContentSize(int width, int height);
87
88
        /**
89
         * Sets the location relative to the given widget.
90
         */
91
        void setLocationRelativeTo(const Widget *const widget);
92
93
        void mouseMoved(MouseEvent &event) override;
94
95
        /**
96
         * Sets the minimum width of the popup.
97
         */
98
        void setMinWidth(const int width);
99
100
        int getMinWidth() const noexcept2 A_WARN_UNUSED
101
        { return mMinWidth; }
102
103
        /**
104
         * Sets the minimum height of the popup.
105
         */
106
        void setMinHeight(const int height);
107
108
        int getMinHeight() const noexcept2 A_WARN_UNUSED
109
        { return mMinHeight; }
110
111
        /**
112
         * Sets the maximum width of the popup.
113
         */
114
        void setMaxWidth(const int width);
115
116
        int getMaxWidth() const noexcept2 A_WARN_UNUSED
117
        { return mMaxWidth; }
118
119
        /**
120
         * Sets the minimum height of the popup.
121
         */
122
        void setMaxHeight(const int height);
123
124
        int getMaxHeight() const noexcept2 A_WARN_UNUSED
125
        { return mMaxHeight; }
126
127
        /**
128
         * Gets the padding of the popup. The padding is the distance between
129
         * the popup border and the content.
130
         *
131
         * @return The padding of the popup.
132
         * @see setPadding
133
         */
134
        int getPadding() const noexcept2 A_WARN_UNUSED
135
        { return mPadding; }
136
137
        void setPadding(int padding) noexcept2
138
222
        { mPadding = padding; }
139
140
        /**
141
         * Sets the name of the popup. This is only useful for debug purposes.
142
         */
143
        void setPopupName(const std::string &name) noexcept2
144
        { mPopupName = name; }
145
146
        const std::string &getPopupName() const noexcept2
147
        { return mPopupName; }
148
149
        /**
150
         * Schedule this popup for deletion. It will be deleted at the start
151
         * of the next logic update.
152
         */
153
        void scheduleDelete();
154
155
        // Inherited from BasicContainer
156
157
        Rect getChildrenArea() override;
158
159
        /**
160
         * Sets the location to display the popup. Tries to horizontally center
161
         * the popup and provide a vertical buffer between the given point and
162
         * the popup. Prevents the popup from extending off-screen, if
163
         * possible.
164
         */
165
        void position(const int x, const int y);
166
167
        void hide();
168
169
        void widgetResized(const Event &event) override;
170
171
        void widgetMoved(const Event &event) override final;
172
173
        bool isPopupVisible() const noexcept2
174
        { return mVisible == Visible_true; }
175
176
        void postInit() override
177
222
        { mInit = true; }
178
179
    protected:
180
        int mPadding;                 /**< Holds the padding of the popup. */
181
        Skin *mSkin;                  /**< Skin in use by this popup */
182
183
    private:
184
        std::string mPopupName;       /**< Name of the popup */
185
        ImageCollection *mVertexes A_NONNULLPOINTER;
186
        int mMinWidth;                /**< Minimum popup width */
187
        int mMinHeight;               /**< Minimum popup height */
188
        int mMaxWidth;                /**< Maximum popup width */
189
        int mMaxHeight;               /**< Maximum popup height */
190
        bool mInit;
191
};
192
193
#endif  // GUI_WIDGETS_POPUP_H