FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
clicklabel.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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 
49  class ClickLabel : public Widget, public MouseListener, public KeyListener, public FocusListener, public WidgetListener {
50  public:
54  ClickLabel();
55 
62  ClickLabel(const std::string& caption);
63 
64  virtual ~ClickLabel();
65 
72  virtual const std::string& getCaption() const;
73 
80  virtual void setCaption(const std::string& caption);
81 
89  virtual void setAlignment(Graphics::Alignment alignment);
90 
98  virtual Graphics::Alignment getAlignment() const;
99 
105  virtual void setOpaque(bool opaque);
106 
110  virtual bool isOpaque() const;
111 
118  virtual void setTextWrapping(bool textWrapping);
119 
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 
169 
173  std::string mCaption;
174 
178  std::string mWrappedText;
179 
183  Graphics::Alignment mAlignment;
184 
188  bool mOpaque;
189 
194 
198  bool mHasMouse;
199 
204 
209  };
210 }
211 
212 #endif
Implementation of a label capable of displaying a single or multiline caption.
Definition: clicklabel.h:49
virtual void fontChanged()
Definition: clicklabel.cpp:208
virtual void keyReleased(KeyEvent &keyEvent)
Definition: clicklabel.cpp:253
virtual void ancestorHidden(const Event &event)
Definition: clicklabel.cpp:269
bool mMousePressed
True if a mouse has been pressed, false otherwise.
Definition: clicklabel.h:208
virtual ~ClickLabel()
Definition: clicklabel.cpp:72
virtual void setTextWrapping(bool textWrapping)
Sets the text wrapping of the caption.
Definition: clicklabel.cpp:101
virtual void mouseExited(MouseEvent &mouseEvent)
Definition: clicklabel.cpp:221
virtual void mouseEntered(MouseEvent &mouseEvent)
Definition: clicklabel.cpp:225
virtual void setOpaque(bool opaque)
Sets the opacity of the background.
Definition: clicklabel.cpp:93
bool mHasMouse
True if the mouse is ontop of the button, false otherwise.
Definition: clicklabel.h:198
FIFE::GuiFont * mGuiFont
Holds the gui font.
Definition: clicklabel.h:168
std::string mCaption
Holds the caption of the label.
Definition: clicklabel.h:173
virtual void wrapText()
Definition: clicklabel.cpp:113
std::string mWrappedText
Holds the wrapped text of the label.
Definition: clicklabel.h:178
virtual void setDimension(const Rectangle &dimension)
Definition: clicklabel.cpp:120
virtual void adjustSize()
Definition: clicklabel.cpp:132
virtual const std::string & getCaption() const
Gets the caption of the label.
Definition: clicklabel.cpp:81
bool mTextWrapping
True if text wrapping is enabled, otherwise false.
Definition: clicklabel.h:193
virtual Graphics::Alignment getAlignment() const
Gets the alignment of the caption.
Definition: clicklabel.cpp:89
virtual void resizeToContent(bool recursiv=true)
Definition: clicklabel.cpp:128
virtual void mouseReleased(MouseEvent &mouseEvent)
Definition: clicklabel.cpp:229
virtual void mousePressed(MouseEvent &mouseEvent)
Definition: clicklabel.cpp:214
bool mOpaque
True if opaque, otherwise false.
Definition: clicklabel.h:188
virtual void mouseDragged(MouseEvent &mouseEvent)
Definition: clicklabel.cpp:240
virtual void setAlignment(Graphics::Alignment alignment)
Sets the alignment of the caption.
Definition: clicklabel.cpp:85
ClickLabel()
Constructor.
Definition: clicklabel.cpp:38
Graphics::Alignment mAlignment
Holds the alignment of the caption.
Definition: clicklabel.h:183
virtual bool isOpaque() const
Definition: clicklabel.cpp:97
virtual bool isTextWrapping() const
Gets the text wrapping of the caption.
Definition: clicklabel.cpp:109
virtual void draw(Graphics *graphics)
Definition: clicklabel.cpp:161
bool mKeyPressed
True if a key has been pressed, false otherwise.
Definition: clicklabel.h:203
virtual void focusLost(const Event &event)
Definition: clicklabel.cpp:263
virtual void keyPressed(KeyEvent &keyEvent)
Definition: clicklabel.cpp:244
virtual void setCaption(const std::string &caption)
Sets the caption of the label.
Definition: clicklabel.cpp:75