| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_GUI_WIDGETS_CLICKLABEL_H |
| 23 |
#define FIFE_GUI_WIDGETS_CLICKLABEL_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
#include <string> |
| 27 |
|
| 28 |
// 3rd party library includes |
| 29 |
#include <fifechan.hpp> |
| 30 |
|
| 31 |
// FIFE includes |
| 32 |
// These includes are split up in two parts, separated by one empty line |
| 33 |
// First block: files included from the FIFE root src directory |
| 34 |
// Second block: files included from the same folder |
| 35 |
|
| 36 |
namespace FIFE { |
| 37 |
class GuiFont; |
| 38 |
} |
| 39 |
|
| 40 |
namespace fcn { |
| 41 |
|
| 42 |
/** |
| 43 |
* Implementation of a label capable of displaying a single or multiline caption. |
| 44 |
* |
| 45 |
* In case text wrapping is enabled, the labels width will be the same as the width from the parent. |
| 46 |
* Or as fallback the maximal size parameter is used. |
| 47 |
* If a label is clicked an action event will be sent to all action listener's of the label. |
| 48 |
*/ |
| 49 |
class ClickLabel : public Widget, public MouseListener, public KeyListener, public FocusListener, public WidgetListener { |
| 50 |
public: |
| 51 |
/** |
| 52 |
* Constructor. |
| 53 |
*/ |
| 54 |
ClickLabel(); |
| 55 |
|
| 56 |
/** |
| 57 |
* Constructor. The label will be automatically resized |
| 58 |
* to fit the caption. |
| 59 |
* |
| 60 |
* @param caption The caption of the label. |
| 61 |
*/ |
| 62 |
ClickLabel(const std::string& caption); |
| 63 |
|
| 64 |
virtual ~ClickLabel(); |
| 65 |
|
| 66 |
/** |
| 67 |
* Gets the caption of the label. |
| 68 |
* |
| 69 |
* @return The caption of the label. |
| 70 |
* @see setCaption |
| 71 |
*/ |
| 72 |
virtual const std::string& getCaption() const; |
| 73 |
|
| 74 |
/** |
| 75 |
* Sets the caption of the label. |
| 76 |
* |
| 77 |
* @param caption The caption of the label. |
| 78 |
* @see getCaption, adjustSize |
| 79 |
*/ |
| 80 |
virtual void setCaption(const std::string& caption); |
| 81 |
|
| 82 |
/** |
| 83 |
* Sets the alignment of the caption. The alignment is relative |
| 84 |
* to the center of the label. |
| 85 |
* |
| 86 |
* @param alignemnt The alignment of the caption of the label. |
| 87 |
* @see getAlignment, Graphics |
| 88 |
*/ |
| 89 |
virtual void setAlignment(Graphics::Alignment alignment); |
| 90 |
|
| 91 |
/** |
| 92 |
* Gets the alignment of the caption. The alignment is relative to |
| 93 |
* the center of the label. |
| 94 |
* |
| 95 |
* @return The alignment of caption of the label. |
| 96 |
* @see setAlignmentm Graphics |
| 97 |
*/ |
| 98 |
virtual Graphics::Alignment getAlignment() const; |
| 99 |
|
| 100 |
/** |
| 101 |
* Sets the opacity of the background. |
| 102 |
* |
| 103 |
* @param opaque True if opaque, false otherwise. |
| 104 |
*/ |
| 105 |
virtual void setOpaque(bool opaque); |
| 106 |
|
| 107 |
/** |
| 108 |
* @return Whether this background is opaque or not. |
| 109 |
*/ |
| 110 |
virtual bool isOpaque() const; |
| 111 |
|
| 112 |
/** |
| 113 |
* Sets the text wrapping of the caption. The text will be splitted |
| 114 |
* to the width of the label if enabled. |
| 115 |
* |
| 116 |
* @param textWrapping True if text wrapping is enabled, false otherwise. |
| 117 |
*/ |
| 118 |
virtual void setTextWrapping(bool textWrapping); |
| 119 |
|
| 120 |
/** |
| 121 |
* Gets the text wrapping of the caption. The text will be splitted |
| 122 |
* to the width of the label if it returns true. |
| 123 |
* |
| 124 |
* @return True if text wrapping is enabled, false otherwise. |
| 125 |
*/ |
| 126 |
virtual bool isTextWrapping() const; |
| 127 |
|
| 128 |
|
| 129 |
// Inherited from Widget |
| 130 |
|
| 131 |
virtual void setDimension(const Rectangle& dimension); |
| 132 |
virtual void resizeToContent(bool recursiv=true); |
| 133 |
virtual void adjustSize(); |
| 134 |
virtual void draw(Graphics* graphics); |
| 135 |
virtual void fontChanged(); |
| 136 |
|
| 137 |
|
| 138 |
// Inherited from FocusListener |
| 139 |
|
| 140 |
virtual void focusLost(const Event& event); |
| 141 |
|
| 142 |
|
| 143 |
// Inherited from MouseListener |
| 144 |
|
| 145 |
virtual void mousePressed(MouseEvent& mouseEvent); |
| 146 |
virtual void mouseReleased(MouseEvent& mouseEvent); |
| 147 |
virtual void mouseEntered(MouseEvent& mouseEvent); |
| 148 |
virtual void mouseExited(MouseEvent& mouseEvent); |
| 149 |
virtual void mouseDragged(MouseEvent& mouseEvent); |
| 150 |
|
| 151 |
|
| 152 |
// Inherited from KeyListener |
| 153 |
|
| 154 |
virtual void keyPressed(KeyEvent& keyEvent); |
| 155 |
virtual void keyReleased(KeyEvent& keyEvent); |
| 156 |
|
| 157 |
|
| 158 |
// Inherited from WidgetListener |
| 159 |
|
| 160 |
virtual void ancestorHidden(const Event& event); |
| 161 |
|
| 162 |
protected: |
| 163 |
virtual void wrapText(); |
| 164 |
|
| 165 |
/** |
| 166 |
* Holds the gui font. |
| 167 |
*/ |
| 168 |
FIFE::GuiFont* mGuiFont; |
| 169 |
|
| 170 |
/** |
| 171 |
* Holds the caption of the label. |
| 172 |
*/ |
| 173 |
std::string mCaption; |
| 174 |
|
| 175 |
/** |
| 176 |
* Holds the wrapped text of the label. |
| 177 |
*/ |
| 178 |
std::string mWrappedText; |
| 179 |
|
| 180 |
/** |
| 181 |
* Holds the alignment of the caption. |
| 182 |
*/ |
| 183 |
Graphics::Alignment mAlignment; |
| 184 |
|
| 185 |
/** |
| 186 |
* True if opaque, otherwise false. |
| 187 |
*/ |
| 188 |
bool mOpaque; |
| 189 |
|
| 190 |
/** |
| 191 |
* True if text wrapping is enabled, otherwise false. |
| 192 |
*/ |
| 193 |
bool mTextWrapping; |
| 194 |
|
| 195 |
/** |
| 196 |
* True if the mouse is ontop of the button, false otherwise. |
| 197 |
*/ |
| 198 |
bool mHasMouse; |
| 199 |
|
| 200 |
/** |
| 201 |
* True if a key has been pressed, false otherwise. |
| 202 |
*/ |
| 203 |
bool mKeyPressed; |
| 204 |
|
| 205 |
/** |
| 206 |
* True if a mouse has been pressed, false otherwise. |
| 207 |
*/ |
| 208 |
bool mMousePressed; |
| 209 |
}; |
| 210 |
} |
| 211 |
|
| 212 |
#endif |