GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/tab.h Lines: 3 13 23.1 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008-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
/*      _______   __   __   __   ______   __   __   _______   __   __
25
 *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
26
 *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
27
 *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
28
 *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
29
 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
30
 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
31
 *
32
 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
33
 *
34
 *
35
 * Per Larsson a.k.a finalman
36
 * Olof Naessén a.k.a jansem/yakslem
37
 *
38
 * Visit: http://guichan.sourceforge.net
39
 *
40
 * License: (BSD)
41
 * Redistribution and use in source and binary forms, with or without
42
 * modification, are permitted provided that the following conditions
43
 * are met:
44
 * 1. Redistributions of source code must retain the above copyright
45
 *    notice, this list of conditions and the following disclaimer.
46
 * 2. Redistributions in binary form must reproduce the above copyright
47
 *    notice, this list of conditions and the following disclaimer in
48
 *    the documentation and/or other materials provided with the
49
 *    distribution.
50
 * 3. Neither the name of Guichan nor the names of its contributors may
51
 *    be used to endorse or promote products derived from this software
52
 *    without specific prior written permission.
53
 *
54
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
60
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
61
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
62
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
63
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65
 */
66
67
#ifndef GUI_WIDGETS_TABS_TAB_H
68
#define GUI_WIDGETS_TABS_TAB_H
69
70
#include "gui/widgets/basiccontainer.h"
71
72
#include "listeners/mouselistener.h"
73
#include "listeners/widgetlistener.h"
74
75
#include "localconsts.h"
76
77
class ImageCollection;
78
class Label;
79
class Skin;
80
class TabbedArea;
81
82
/**
83
 * A tab, the same as the Guichan tab in 0.8, but extended
84
 */
85
class Tab notfinal : public BasicContainer,
86
                     public MouseListener,
87
                     public WidgetListener
88
{
89
    public:
90
        explicit Tab(const Widget2 *const widget);
91
92
        A_DELETE_COPY(Tab)
93
94
        ~Tab() override;
95
96
        enum
97
        {
98
            TAB_STANDARD    = 0,
99
            TAB_HIGHLIGHTED = 1,
100
            TAB_SELECTED    = 2,
101
            TAB_UNUSED      = 3,
102
            TAB_COUNT       = 4  // Must be last
103
        };
104
105
        /**
106
         * Update the alpha value to the graphic components.
107
         */
108
        void updateAlpha();
109
110
        /**
111
         * Draw the tabbed area.
112
         */
113
        void draw(Graphics *const graphics) override final A_NONNULL(2);
114
115
        void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
116
117
        /**
118
         * Set the normal color for the tab's text.
119
         */
120
        void setTabColor(const Color *const color1,
121
                         const Color *const color2)
122
        {
123
            mTabColor = color1;
124
            mTabOutlineColor = color2;
125
            mRedraw = true;
126
        }
127
128
        /**
129
         * Set the highlighted color for the tab's text.
130
         */
131
        void setHighlightedTabColor(const Color *const color1,
132
                                    const Color *const color2)
133
        {
134
            mTabHighlightedColor = color1;
135
            mTabHighlightedOutlineColor = color2;
136
            mRedraw = true;
137
        }
138
139
        /**
140
         * Set the selected color for the tab's text.
141
         */
142
        void setSelectedTabColor(const Color *const color1,
143
                                 const Color *const color2)
144
        {
145
            mTabSelectedColor = color1;
146
            mTabSelectedOutlineColor = color2;
147
            mRedraw = true;
148
        }
149
150
        /**
151
         * Set the flash color for the tab's text.
152
         */
153
        void setFlashTabColor(const Color *const color1,
154
                              const Color *const color2)
155
        {
156
            mFlashColor = color1;
157
            mFlashOutlineColor = color2;
158
            mRedraw = true;
159
        }
160
161
        /**
162
         * Set the player flash color for the tab's text.
163
         */
164
        void setPlayerFlashTabColor(const Color *const color1,
165
                                    const Color *const color2)
166
        {
167
            mPlayerFlashColor = color1;
168
            mPlayerFlashOutlineColor = color2;
169
            mRedraw = true;
170
        }
171
172
        /**
173
         * Set tab flashing state
174
         */
175
        void setFlash(const int flash)
176
1
        { mFlash = flash; mRedraw = true; }
177
178
        int getFlash() const noexcept2 A_WARN_UNUSED
179
        { return mFlash; }
180
181
        void widgetResized(const Event &event) override final;
182
183
        void widgetMoved(const Event &event) override final;
184
185
        void setLabelFont(Font *const font);
186
187
        Label *getLabel() const noexcept2 A_WARN_UNUSED
188
        { return mLabel; }
189
190
        void adjustSize();
191
192
        void setTabbedArea(TabbedArea* tabbedArea);
193
194
        TabbedArea* getTabbedArea() const A_WARN_UNUSED;
195
196
        void setCaption(const std::string& caption);
197
198
        const std::string &getCaption() const A_WARN_UNUSED;
199
200
        void mouseEntered(MouseEvent &event) override final;
201
202
        void mouseExited(MouseEvent &event) override final;
203
204
        void setImage(Image *const image);
205
206
        static void finalCleanup();
207
208
    protected:
209
        friend class TabbedArea;
210
211
8
        virtual void setCurrent()
212
8
        { }
213
214
        Label* mLabel A_NONNULLPOINTER;
215
216
        TabbedArea* mTabbedArea;
217
218
    private:
219
        /** Load images if no other instances exist yet */
220
        void init();
221
222
        static Skin *tabImg[TAB_COUNT];  /**< Tab state graphics */
223
        static int mInstances;           /**< Number of tab instances */
224
        static float mAlpha;
225
226
        const Color *mTabColor;
227
        const Color *mTabOutlineColor;
228
        const Color *mTabHighlightedColor;
229
        const Color *mTabHighlightedOutlineColor;
230
        const Color *mTabSelectedColor;
231
        const Color *mTabSelectedOutlineColor;
232
        const Color *mFlashColor;
233
        const Color *mFlashOutlineColor;
234
        const Color *mPlayerFlashColor;
235
        const Color *mPlayerFlashOutlineColor;
236
        int mFlash;
237
        ImageCollection *mVertexes A_NONNULLPOINTER;
238
        Image *mImage;
239
        int mMode;
240
        int mLabelMode;
241
242
    protected:
243
        bool mHasMouse;
244
};
245
246
#endif  // GUI_WIDGETS_TABS_TAB_H