48 addMouseListener(
this);
50 addFocusListener(
this);
51 addWidgetListener(
this);
66 addMouseListener(
this);
68 addFocusListener(
this);
69 addWidgetListener(
this);
104 if (wrappingEnabled) {
115 int32_t w = getWidth() - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight();
121 int32_t w = getWidth();
122 Widget::setDimension(dimension);
134 int32_t w = getWidth();
138 w = getParent()->getChildrenArea().width;
140 int32_t textW = w - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight();
141 int32_t maxW = isFixedSize() ? getFixedSize().getWidth() : getMaxSize().getWidth();
144 textW = w - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight();
145 }
else if (w > maxW) {
146 w = std::min(w, maxW);
147 textW = w - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight();
152 w = image->
getWidth() + 2 * getBorderSize() + getPaddingLeft() + getPaddingRight();
156 h = 2 * getBorderSize() + getPaddingTop() + getPaddingBottom() + image->
getHeight();
162 bool active = isFocused();
163 Rectangle offsetRec(getBorderSize(), getBorderSize(), 2 * getBorderSize(), 2 * getBorderSize());
166 Color faceColor = getBackgroundColor();
167 if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) {
168 faceColor = getSelectionColor();
170 graphics->setColor(faceColor);
171 graphics->fillRectangle(offsetRec.x, offsetRec.y, getWidth() - offsetRec.width, getHeight() - offsetRec.height);
174 if (getBorderSize() > 0) {
175 if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) {
176 drawSelectionFrame(graphics);
178 drawBorder(graphics);
183 graphics->setColor(getForegroundColor());
188 int32_t textY = offsetRec.y + getPaddingTop() + (getHeight() - offsetRec.height - getPaddingTop() - getPaddingBottom() - image->
getHeight()) / 2;
192 textX = offsetRec.x + getPaddingLeft();
194 case Graphics::Center:
195 textX = offsetRec.x + getPaddingLeft() + (getWidth() - offsetRec.width - getPaddingLeft() - getPaddingRight() - image->
getWidth()) / 2;
197 case Graphics::Right:
198 textX = getWidth() - offsetRec.x - getPaddingRight() - image->
getWidth();
201 throw FCN_EXCEPTION(
"Unknown alignment.");
215 if (mouseEvent.getButton() == MouseEvent::Left) {
217 mouseEvent.consume();
232 distributeActionEvent();
233 mouseEvent.consume();
234 }
else if (mouseEvent.getButton() == MouseEvent::Left) {
236 mouseEvent.consume();
241 mouseEvent.consume();
245 Key key = keyEvent.getKey();
247 if (key.getValue() == Key::Enter || key.getValue() == Key::Space) {
254 Key key = keyEvent.getKey();
256 if ((key.getValue() == Key::Enter || key.getValue() == Key::Space) &&
mKeyPressed) {
258 distributeActionEvent();
std::string splitTextToWidth(const std::string &text, int32_t render_width)
virtual void fontChanged()
virtual void keyReleased(KeyEvent &keyEvent)
virtual void ancestorHidden(const Event &event)
bool mMousePressed
True if a mouse has been pressed, false otherwise.
virtual Graphics::Alignment getAlignment() const
Gets the alignment of the caption.
virtual void setTextWrapping(bool textWrapping)
Sets the text wrapping of the caption.
virtual void mouseExited(MouseEvent &mouseEvent)
virtual void mouseEntered(MouseEvent &mouseEvent)
virtual void setOpaque(bool opaque)
Sets the opacity of the background.
bool mHasMouse
True if the mouse is ontop of the button, false otherwise.
virtual bool isTextWrapping() const
Gets the text wrapping of the caption.
FIFE::GuiFont * mGuiFont
Holds the gui font.
std::string mCaption
Holds the caption of the label.
virtual bool isOpaque() const
void drawMultiLineString(fcn::Graphics *graphics, const std::string &text, int32_t x, int32_t y)
Image * getAsImageMultiline(const std::string &text)
Gets given text as Image.
std::string mWrappedText
Holds the wrapped text of the label.
virtual const std::string & getCaption() const
Gets the caption of the label.
uint32_t getHeight() const
virtual void setDimension(const Rectangle &dimension)
virtual void adjustSize()
bool mTextWrapping
True if text wrapping is enabled, otherwise false.
virtual void resizeToContent(bool recursiv=true)
virtual void mouseReleased(MouseEvent &mouseEvent)
virtual void mousePressed(MouseEvent &mouseEvent)
bool mOpaque
True if opaque, otherwise false.
virtual void mouseDragged(MouseEvent &mouseEvent)
virtual void setAlignment(Graphics::Alignment alignment)
Sets the alignment of the caption.
Graphics::Alignment mAlignment
Holds the alignment of the caption.
virtual void draw(Graphics *graphics)
bool mKeyPressed
True if a key has been pressed, false otherwise.
virtual void focusLost(const Event &event)
virtual void keyPressed(KeyEvent &keyEvent)
uint32_t getWidth() const
virtual void setCaption(const std::string &caption)
Sets the caption of the label.