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

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2007-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef GUI_WIDGETS_SHORTCUTCONTAINER_H
24
#define GUI_WIDGETS_SHORTCUTCONTAINER_H
25
26
#include "gui/widgets/widget.h"
27
28
#include "listeners/mouselistener.h"
29
#include "listeners/widgetlistener.h"
30
31
class Image;
32
class ImageCollection;
33
34
/**
35
 * A generic shortcut container.
36
 *
37
 * \ingroup GUI
38
 */
39
class ShortcutContainer notfinal : public Widget,
40
                                   public WidgetListener,
41
                                   public MouseListener
42
{
43
    public:
44
        A_DELETE_COPY(ShortcutContainer)
45
46
        /**
47
         * Destructor.
48
         */
49
        virtual ~ShortcutContainer();
50
51
        /**
52
         * Invoked when a widget changes its size. This is used to determine
53
         * the new height of the container.
54
         */
55
        void widgetResized(const Event &event) override final;
56
57
        void widgetMoved(const Event& event) override final;
58
59
        /**
60
         * Handles mouse when dragged.
61
         */
62
        void mouseDragged(MouseEvent &event A_UNUSED) override
63
        {
64
        }
65
66
        /**
67
         * Handles mouse when pressed.
68
         */
69
        void mousePressed(MouseEvent &event A_UNUSED) override
70
        {
71
        }
72
73
        /**
74
         * Handles mouse release.
75
         */
76
        void mouseReleased(MouseEvent &event A_UNUSED) override
77
        {
78
        }
79
80
        int getMaxItems() const noexcept2 A_WARN_UNUSED
81
2
        { return mMaxItems; }
82
83
        int getBoxWidth() const noexcept2 A_WARN_UNUSED
84
        { return mBoxWidth; }
85
86
        int getBoxHeight() const noexcept2 A_WARN_UNUSED
87
2
        { return mBoxHeight; }
88
89
        void drawBackground(Graphics *const g) A_NONNULL(2);
90
91
        void safeDrawBackground(Graphics *const g) A_NONNULL(2);
92
93
    protected:
94
        /**
95
         * Constructor. Initializes the shortcut container.
96
         */
97
        explicit ShortcutContainer(Widget2 *const widget);
98
99
        /**
100
         * Gets the index from the grid provided the point is in an item box.
101
         *
102
         * @param pointX X coordinate of the point.
103
         * @param pointY Y coordinate of the point.
104
         * @return index on success, -1 on failure.
105
         */
106
        int getIndexFromGrid(const int pointX,
107
                             const int pointY) const A_WARN_UNUSED;
108
109
        Image *mBackgroundImg;
110
        static float mAlpha;
111
112
        unsigned mMaxItems;
113
        int mBoxWidth;
114
        int mBoxHeight;
115
        int mGridWidth;
116
        int mGridHeight;
117
        ImageCollection *mVertexes;
118
};
119
120
#endif  // GUI_WIDGETS_SHORTCUTCONTAINER_H