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-2019  The ManaPlus Developers  | 
    
    
    6  | 
     | 
     | 
     *  Copyright (C) 2019-2021  Andrei Karas  | 
    
    
    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_SHORTCUTCONTAINER_H  | 
    
    
    25  | 
     | 
     | 
    #define GUI_WIDGETS_SHORTCUTCONTAINER_H  | 
    
    
    26  | 
     | 
     | 
     | 
    
    
    27  | 
     | 
     | 
    #include "gui/widgets/widget.h"  | 
    
    
    28  | 
     | 
     | 
     | 
    
    
    29  | 
     | 
     | 
    #include "listeners/mouselistener.h"  | 
    
    
    30  | 
     | 
     | 
    #include "listeners/widgetlistener.h"  | 
    
    
    31  | 
     | 
     | 
     | 
    
    
    32  | 
     | 
     | 
    class Image;  | 
    
    
    33  | 
     | 
     | 
    class ImageCollection;  | 
    
    
    34  | 
     | 
     | 
    class Skin;  | 
    
    
    35  | 
     | 
     | 
     | 
    
    
    36  | 
     | 
     | 
    /**  | 
    
    
    37  | 
     | 
     | 
     * A generic shortcut container.  | 
    
    
    38  | 
     | 
     | 
     *  | 
    
    
    39  | 
     | 
     | 
     * \ingroup GUI  | 
    
    
    40  | 
     | 
     | 
     */  | 
    
    
    41  | 
     | 
     | 
    class ShortcutContainer notfinal : public Widget,  | 
    
    
    42  | 
     | 
     | 
                                       public WidgetListener,  | 
    
    
    43  | 
     | 
     | 
                                       public MouseListener  | 
    
    
    44  | 
     | 
     | 
    { | 
    
    
    45  | 
     | 
     | 
        public:  | 
    
    
    46  | 
     | 
     | 
            A_DELETE_COPY(ShortcutContainer)  | 
    
    
    47  | 
     | 
     | 
     | 
    
    
    48  | 
     | 
     | 
            /**  | 
    
    
    49  | 
     | 
     | 
             * Destructor.  | 
    
    
    50  | 
     | 
     | 
             */  | 
    
    
    51  | 
     | 
     | 
            ~ShortcutContainer() override;  | 
    
    
    52  | 
     | 
     | 
     | 
    
    
    53  | 
     | 
     | 
            /**  | 
    
    
    54  | 
     | 
     | 
             * Invoked when a widget changes its size. This is used to determine  | 
    
    
    55  | 
     | 
     | 
             * the new height of the container.  | 
    
    
    56  | 
     | 
     | 
             */  | 
    
    
    57  | 
     | 
     | 
            void widgetResized(const Event &event) override final;  | 
    
    
    58  | 
     | 
     | 
     | 
    
    
    59  | 
     | 
     | 
            void widgetMoved(const Event& event) override final;  | 
    
    
    60  | 
     | 
     | 
     | 
    
    
    61  | 
     | 
     | 
            /**  | 
    
    
    62  | 
     | 
     | 
             * Handles mouse when dragged.  | 
    
    
    63  | 
     | 
     | 
             */  | 
    
    
    64  | 
     | 
     | 
            void mouseDragged(MouseEvent &event A_UNUSED) override  | 
    
    
    65  | 
     | 
     | 
            { | 
    
    
    66  | 
     | 
     | 
            }  | 
    
    
    67  | 
     | 
     | 
     | 
    
    
    68  | 
     | 
     | 
            /**  | 
    
    
    69  | 
     | 
     | 
             * Handles mouse when pressed.  | 
    
    
    70  | 
     | 
     | 
             */  | 
    
    
    71  | 
     | 
     | 
            void mousePressed(MouseEvent &event A_UNUSED) override  | 
    
    
    72  | 
     | 
     | 
            { | 
    
    
    73  | 
     | 
     | 
            }  | 
    
    
    74  | 
     | 
     | 
     | 
    
    
    75  | 
     | 
     | 
            /**  | 
    
    
    76  | 
     | 
     | 
             * Handles mouse release.  | 
    
    
    77  | 
     | 
     | 
             */  | 
    
    
    78  | 
     | 
     | 
            void mouseReleased(MouseEvent &event A_UNUSED) override  | 
    
    
    79  | 
     | 
     | 
            { | 
    
    
    80  | 
     | 
     | 
            }  | 
    
    
    81  | 
     | 
     | 
     | 
    
    
    82  | 
     | 
     | 
            int getMaxItems() const noexcept2 A_WARN_UNUSED  | 
    
    
    83  | 
     | 
    1  | 
            { return mMaxItems; } | 
    
    
    84  | 
     | 
     | 
     | 
    
    
    85  | 
     | 
     | 
            int getBoxWidth() const noexcept2 A_WARN_UNUSED  | 
    
    
    86  | 
     | 
    1  | 
            { return mBoxWidth; } | 
    
    
    87  | 
     | 
     | 
     | 
    
    
    88  | 
     | 
     | 
            int getBoxHeight() const noexcept2 A_WARN_UNUSED  | 
    
    
    89  | 
     | 
    1  | 
            { return mBoxHeight; } | 
    
    
    90  | 
     | 
     | 
     | 
    
    
    91  | 
     | 
     | 
            void drawBackground(Graphics *const g) A_NONNULL(2);  | 
    
    
    92  | 
     | 
     | 
     | 
    
    
    93  | 
     | 
     | 
            void safeDrawBackground(Graphics *const g) A_NONNULL(2);  | 
    
    
    94  | 
     | 
     | 
     | 
    
    
    95  | 
     | 
     | 
            virtual void setSkin(const Widget2 *const widget,  | 
    
    
    96  | 
     | 
     | 
                                 Skin *const skin);  | 
    
    
    97  | 
     | 
     | 
     | 
    
    
    98  | 
     | 
     | 
        protected:  | 
    
    
    99  | 
     | 
     | 
            /**  | 
    
    
    100  | 
     | 
     | 
             * Constructor. Initializes the shortcut container.  | 
    
    
    101  | 
     | 
     | 
             */  | 
    
    
    102  | 
     | 
     | 
            explicit ShortcutContainer(Widget2 *const widget);  | 
    
    
    103  | 
     | 
     | 
     | 
    
    
    104  | 
     | 
     | 
            /**  | 
    
    
    105  | 
     | 
     | 
             * Gets the index from the grid provided the point is in an item box.  | 
    
    
    106  | 
     | 
     | 
             *  | 
    
    
    107  | 
     | 
     | 
             * @param pointX X coordinate of the point.  | 
    
    
    108  | 
     | 
     | 
             * @param pointY Y coordinate of the point.  | 
    
    
    109  | 
     | 
     | 
             * @return index on success, -1 on failure.  | 
    
    
    110  | 
     | 
     | 
             */  | 
    
    
    111  | 
     | 
     | 
            int getIndexFromGrid(const int pointX,  | 
    
    
    112  | 
     | 
     | 
                                 const int pointY) const A_WARN_UNUSED;  | 
    
    
    113  | 
     | 
     | 
     | 
    
    
    114  | 
     | 
     | 
            Image *mBackgroundImg;  | 
    
    
    115  | 
     | 
     | 
            Skin *mSkin;  | 
    
    
    116  | 
     | 
     | 
            static float mAlpha;  | 
    
    
    117  | 
     | 
     | 
     | 
    
    
    118  | 
     | 
     | 
            unsigned mMaxItems;  | 
    
    
    119  | 
     | 
     | 
            int mBoxWidth;  | 
    
    
    120  | 
     | 
     | 
            int mBoxHeight;  | 
    
    
    121  | 
     | 
     | 
            int mGridWidth;  | 
    
    
    122  | 
     | 
     | 
            int mGridHeight;  | 
    
    
    123  | 
     | 
     | 
            int mImageOffsetX;  | 
    
    
    124  | 
     | 
     | 
            int mImageOffsetY;  | 
    
    
    125  | 
     | 
     | 
            int mTextOffsetX;  | 
    
    
    126  | 
     | 
     | 
            int mTextOffsetY;  | 
    
    
    127  | 
     | 
     | 
            ImageCollection *mVertexes;  | 
    
    
    128  | 
     | 
     | 
    };  | 
    
    
    129  | 
     | 
     | 
     | 
    
    
    130  | 
     | 
     | 
    #endif  // GUI_WIDGETS_SHORTCUTCONTAINER_H  |