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