Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes

#include <label.h>

Inheritance diagram for Label:
Widget WidgetListener ToolTipListener Widget2 MouseListener

Public Member Functions

 Label (const Widget2 *const widget)
 Label (const Widget2 *const widget, const std::string &caption)
 ~Label ()
void init ()
void draw (Graphics *const graphics)
void safeDraw (Graphics *const graphics)
void adjustSize ()
void setForegroundColor (const Color &color)
void setForegroundColorAll (const Color &color1, const Color &color2)
void resizeTo (const int maxSize, const int minSize)
const std::string & getCaption () const
void setCaption (const std::string &caption)
void setAlignment (Graphics::Alignment alignment)
Graphics::Alignment getAlignment () const
void setParent (Widget *const widget)
void setWindow (Widget *const widget)
void widgetHidden (const Event &event)
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 ~Widget ()
virtual void drawFrame (Graphics *graphics)
virtual void safeDrawFrame (Graphics *graphics)
void setFrameSize (const unsigned int frameSize)
unsigned int getFrameSize () const
virtual void logic ()
WidgetgetParent () const
void setWidth (const int width)
int getWidth () const
void setHeight (const int height)
int getHeight () const
void setSize (const int width, const int height)
void setX (const int x)
int getX () const
void setY (const int y)
int getY () const
void setPosition (const int x, const int y)
void setDimension (const Rect &dimension)
const RectgetDimension () const
void setFocusable (const bool focusable)
bool isFocusable () const
virtual bool isFocused () const
void setEnabled (const bool enabled)
bool isEnabled () const
void setVisible (Visible visible)
bool isVisible () const
void setBaseColor (const Color &color)
const ColorgetBaseColor () const
void setForegroundColor (const Color &color)
const ColorgetForegroundColor () const
void setBackgroundColor (const Color &color)
const ColorgetBackgroundColor () const
virtual void requestFocus ()
virtual void requestMoveToTop ()
virtual void requestMoveToBottom ()
virtual void setFocusHandler (FocusHandler *const focusHandler)
FocusHandlergetFocusHandler ()
void addActionListener (ActionListener *const actionListener)
void removeActionListener (ActionListener *const actionListener)
void addDeathListener (WidgetDeathListener *const deathListener)
void removeDeathListener (WidgetDeathListener *const deathListener)
void addMouseListener (MouseListener *const mouseListener)
void removeMouseListener (MouseListener *const mouseListener)
void addKeyListener (KeyListener *const keyListener)
void removeKeyListener (KeyListener *const keyListener)
void addFocusListener (FocusListener *const focusListener)
void removeFocusListener (FocusListener *const focusListener)
void addWidgetListener (WidgetListener *const widgetListener)
void removeWidgetListener (WidgetListener *const widgetListener)
void setActionEventId (const std::string &actionEventId)
const std::string & getActionEventId () const
virtual void getAbsolutePosition (int &x, int &y) const
FontgetFont () const
void setFont (Font *const font)
virtual void fontChanged ()
bool isTabInEnabled () const
void setTabInEnabled (const bool enabled)
bool isTabOutEnabled () const
void setTabOutEnabled (const bool enabled)
void requestModalFocus ()
virtual void requestModalMouseInputFocus ()
virtual void releaseModalFocus ()
virtual void releaseModalMouseInputFocus ()
virtual bool isModalFocused () const
virtual bool isModalMouseInputFocused () const
virtual WidgetgetWidgetAt (int x, int y)
const std::list< MouseListener * > & getMouseListeners () const A_CONST
const std::list< KeyListener * > & getKeyListeners () const A_CONST
const std::list< FocusListener * > & getFocusListeners () const A_CONST
virtual Rect getChildrenArea ()
virtual FocusHandlergetInternalFocusHandler ()
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
virtual void moveToTop (Widget *widget)
virtual void moveToBottom (Widget *widget)
virtual void focusNext ()
virtual void focusPrevious ()
virtual void showWidgetPart (Widget *const widget, const Rect &area)
void setId (const std::string &id)
const std::string & getId () const
virtual void showPart (const Rect &rectangle)
bool isAllowLogic () const
void setMouseConsume (const bool b)
bool isMouseConsume () const
void setRedraw (const bool b)
virtual bool isSelectable () const
void setSelectable (const bool selectable)
void windowResized ()
virtual void postInit ()
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
virtual void setWidget2 (const Widget2 *const widget)
void setPalette (int palette)
void checkPalette ()
void setForegroundColor2 (const Color &color)
WidgetgetWindow () const
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
virtual void widgetResized (const Event &event)
virtual void widgetMoved (const Event &event)
virtual void widgetShown (const Event &event)
- Public Member Functions inherited from ToolTipListener
 ToolTipListener ()
void setToolTip (const std::string &str)
std::string getToolTip () const
void mouseMoved (MouseEvent &event)
void mouseExited (MouseEvent &event)
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
virtual void mouseEntered (MouseEvent &event)
virtual void mousePressed (MouseEvent &event)
virtual void mouseReleased (MouseEvent &event)
virtual void mouseClicked (MouseEvent &event)
virtual void mouseWheelMovedUp (MouseEvent &event)
virtual void mouseWheelMovedDown (MouseEvent &event)
virtual void mouseDragged (MouseEvent &event)

Static Public Member Functions

static void finalCleanup ()
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
static FontgetGloablFont ()
static void cleanGlobalFont ()
static bool widgetExists (const Widget *const widget)
static void distributeWindowResizeEvent ()
static WidgetcallPostInit (Widget *const widget)

Static Public Attributes

static SkinmSkin = 0
static int mInstances = 0

Private Attributes

std::string mCaption
TextChunk mTextChunk
Graphics::Alignment mAlignment
int mPadding
bool mTextChanged

Additional Inherited Members

- Data Fields inherited from Widget
Visible mVisible
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
typedef MouseListenerList::iterator MouseListenerIterator
typedef std::list< KeyListener * > KeyListenerList
typedef KeyListenerList::iterator KeyListenerIterator
typedef std::list< ActionListener * > ActionListenerList
typedef ActionListenerList::iterator ActionListenerIterator
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
typedef std::list< FocusListener * > FocusListenerList
typedef FocusListenerList::iterator FocusListenerIterator
typedef std::list< WidgetListener * > WidgetListenerList
typedef WidgetListenerList::iterator WidgetListenerIterator
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
void distributeResizedEvent ()
void distributeMovedEvent ()
void distributeHiddenEvent ()
void distributeShownEvent ()
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
- Protected Member Functions inherited from MouseListener
 MouseListener ()
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
KeyListenerList mKeyListeners
ActionListenerList mActionListeners
WidgetDeathListenerList mDeathListeners
FocusListenerList mFocusListeners
WidgetListenerList mWidgetListeners
Color mForegroundColor
Color mBackgroundColor
Color mBaseColor
Rect mDimension
std::string mActionEventId
std::string mId
unsigned int mFrameSize
bool mFocusable
bool mTabIn
bool mTabOut
bool mEnabled
bool mAllowLogic
bool mMouseConsume
bool mRedraw
bool mSelectable
- Protected Attributes inherited from Widget2
int mPaletteOffset
Color mForegroundColor2
- Protected Attributes inherited from ToolTipListener
std::string mToolTip
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0

Detailed Description

Label widget. Same as the Guichan label but modified to use the palette system.

Definition at line 88 of file label.h.

Constructor & Destructor Documentation

◆ Label() [1/2]

Label::Label ( const Widget2 *const  widget)


Definition at line 78 of file label.cpp.

78  :
79  Widget(widget),
82  mCaption(),
83  mTextChunk(),
85  mPadding(0),
86  mTextChanged(true)
87 {
88  init();
89 }
bool mTextChanged
Definition: label.h:193
void init()
Definition: label.cpp:126
int mPadding
Definition: label.h:191
Graphics::Alignment mAlignment
Definition: label.h:189
TextChunk mTextChunk
Definition: label.h:184
std::string mCaption
Definition: label.h:182
Widget(const Widget2 *const widget)
Definition: widget.cpp:85

References init().

◆ Label() [2/2]

Label::Label ( const Widget2 *const  widget,
const std::string &  caption 

Constructor. This version of the constructor sets the label with an inintialization string.

Definition at line 91 of file label.cpp.

92  :
93  Widget(widget),
96  mCaption(caption),
97  mTextChunk(),
99  mPadding(0),
100  mTextChanged(true)
101 {
102  const Font *const font = getFont();
103  setWidth(font->getWidth(caption));
104  setHeight(font->getHeight());
105  init();
106 }
Definition: font.h:90
int getHeight() const
Definition: font.cpp:362
int getWidth(const std::string &text) const
Definition: font.cpp:334
void setWidth(const int width)
Definition: widget.cpp:133
void setHeight(const int height)
Definition: widget.cpp:140
Font * getFont() const
Definition: widget.cpp:331

References Widget::getFont(), Font::getHeight(), Font::getWidth(), init(), Widget::setHeight(), and Widget::setWidth().

◆ ~Label()

Label::~Label ( )

Definition at line 108 of file label.cpp.

109 {
110  if (mWindow != nullptr)
113  if (gui != nullptr)
114  gui->removeDragged(this);
116  mInstances --;
117  if (mInstances == 0)
118  {
119  if (theme != nullptr)
120  theme->unload(mSkin);
121  }
122  removeMouseListener(this);
124 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
static Skin * mSkin
Definition: label.h:172
static int mInstances
Definition: label.h:174
void deleteImage()
Definition: textchunk.cpp:193
void unload(Skin *const skin)
Definition: theme.cpp:250
Widget * mWindow
Definition: widget2.h:112
void removeMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:297
void removeWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:307
Gui * gui
Definition: gui.cpp:111
Theme * theme
Definition: theme.cpp:62

References TextChunk::deleteImage(), gui, mInstances, mSkin, mTextChunk, Widget2::mWindow, Gui::removeDragged(), Widget::removeMouseListener(), Widget::removeWidgetListener(), theme, and Theme::unload().

Member Function Documentation

◆ adjustSize()

void Label::adjustSize ( )

◆ draw()

void Label::draw ( Graphics *const  graphics)

Draws the label.

Implements Widget.

Definition at line 151 of file label.cpp.

152 {
153  BLOCK_START("Label::draw")
154  int textX;
155  const Rect &rect = mDimension;
156  Font *const font = getFont();
158  switch (mAlignment)
159  {
160  case Graphics::LEFT:
161  default:
162  textX = mPadding;
163  break;
164  case Graphics::CENTER:
165  textX = (rect.width - font->getWidth(mCaption)) / 2;
166  break;
167  case Graphics::RIGHT:
168  if (rect.width > mPadding)
169  textX = rect.width - mPadding - font->getWidth(mCaption);
170  else
171  textX = 0;
172  break;
173  }
175  if (mTextChanged)
176  {
177  mTextChunk.textFont = font;
182  font->generate(mTextChunk);
183  mTextChanged = false;
184  }
186  const Image *const image = mTextChunk.img;
187  if (image != nullptr)
188  {
189  const int textY = rect.height / 2 - font->getHeight() / 2;
190  graphics->drawImage(image, textX, textY);
191  }
192  BLOCK_END("Label::draw")
193 }
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: graphics.h:132
Definition: rect.h:74
Font * textFont
Definition: textchunk.h:64
Image * img
Definition: textchunk.h:63
Color color
Definition: textchunk.h:66
Color color2
Definition: textchunk.h:67
std::string text
Definition: textchunk.h:65
Color mForegroundColor2
Definition: widget2.h:113
Color mForegroundColor
Definition: widget.h:1086
Rect mDimension
Definition: widget.h:1101
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References BLOCK_END, BLOCK_START, Graphics::CENTER, TextChunk::color, TextChunk::color2, TextChunk::deleteImage(), Graphics::drawImage(), Font::generate(), Widget::getFont(), Font::getHeight(), Font::getWidth(), Rect::height, TextChunk::img, Graphics::LEFT, mAlignment, mCaption, Widget::mDimension, Widget::mForegroundColor, Widget2::mForegroundColor2, mPadding, mTextChanged, mTextChunk, Graphics::RIGHT, TextChunk::text, TextChunk::textFont, and Rect::width.

Referenced by safeDraw().

◆ finalCleanup()

void Label::finalCleanup ( )

Definition at line 297 of file label.cpp.

298 {
299  mSkin = nullptr;
300 }

References mSkin.

Referenced by Gui::~Gui().

◆ getAlignment()

Graphics::Alignment Label::getAlignment ( ) const

Gets the alignment of the caption. The alignment is relative to the center of the label.

The alignment of caption of the label.
See also
setAlignmentm Graphics

Definition at line 163 of file label.h.

164  { return mAlignment; }

References mAlignment.

◆ getCaption()

const std::string& Label::getCaption ( ) const

Gets the caption of the label.

The caption of the label.
See also

Definition at line 133 of file label.h.

134  { return mCaption; }

References mCaption.

Referenced by Tab::getCaption(), AttrDisplay::getValue(), UpdaterWindow::logic(), CharacterDisplay::mouseMoved(), SpellPopup::setItem(), and BeingPopup::show().

◆ init()

void Label::init ( )

Definition at line 126 of file label.cpp.

127 {
128  addMouseListener(this);
129  mAllowLogic = false;
131  mForegroundColor2 = getThemeColor(ThemeColorId::LABEL_OUTLINE, 255U);
132  if (mInstances == 0)
133  {
134  if (theme != nullptr)
135  {
136  mSkin = theme->load("label.xml",
137  "",
138  true,
140  }
141  }
142  mInstances ++;
144  if (mSkin != nullptr)
146  else
147  mPadding = 0;
148  setSelectable(false);
149 }
int getPadding() const
Definition: skin.h:100
static std::string getThemePath()
Definition: theme.h:67
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:179
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
bool mAllowLogic
Definition: widget.h:1160
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void setSelectable(const bool selectable)
Definition: widget.h:948

References Widget::addMouseListener(), Skin::getPadding(), Widget2::getThemeColor(), Theme::getThemePath(), GradientType::LABEL, Theme::load(), Widget::mAllowLogic, Widget::mForegroundColor, Widget2::mForegroundColor2, mInstances, mPadding, mSkin, Widget::setSelectable(), and theme.

Referenced by Label().

◆ resizeTo()

void Label::resizeTo ( const int  maxSize,
const int  minSize 

Definition at line 227 of file label.cpp.

228 {
229  const Font *const font = getFont();
230  const int pad2 = 2 * mPadding;
231  setHeight(font->getHeight() + pad2);
233  if (font->getWidth(mCaption) + pad2 > maxSize)
234  {
235  const int dots = font->getWidth("...");
236  if (dots > maxSize)
237  {
238  setWidth(maxSize);
239  return;
240  }
241  const size_t szChars = mCaption.size();
242  for (size_t f = 1; f < szChars - 1; f ++)
243  {
244  const std::string text = mCaption.substr(0, szChars - f);
245  const int width = font->getWidth(text) + dots + pad2;
246  if (width <= maxSize)
247  {
248  setCaption(text + "...");
249  setWidth(width);
250  return;
251  }
252  }
253  setWidth(maxSize);
254  }
255  else
256  {
257  int sz = font->getWidth(mCaption) + pad2;
258  if (sz < minSize)
259  sz = minSize;
260  setWidth(sz);
261  }
262 }
void setCaption(const std::string &caption)
Definition: label.cpp:264

References Widget::getFont(), Font::getHeight(), Font::getWidth(), mCaption, mPadding, setCaption(), Widget::setHeight(), and Widget::setWidth().

Referenced by CharacterDisplay::update(), CharCreateDialog::updateHair(), and CharCreateDialog::updateLook().

◆ safeDraw()

void Label::safeDraw ( Graphics *const  graphics)

Implements Widget.

Definition at line 195 of file label.cpp.

196 {
197  Label::draw(graphics);
198 }
void draw(Graphics *const graphics)
Definition: label.cpp:151

References draw().

◆ setAlignment()

void Label::setAlignment ( Graphics::Alignment  alignment)

Sets the alignment of the caption. The alignment is relative to the center of the label.

alignmentThe alignment of the caption of the label.
See also
getAlignment, Graphics

Definition at line 153 of file label.h.

154  { mAlignment = alignment; }

References mAlignment.

Referenced by AttrDisplay::AttrDisplay(), CharacterDisplay::CharacterDisplay(), BuyDialog::init(), OutfitWindow::OutfitWindow(), and SellDialog::postInit().

◆ setCaption()

void Label::setCaption ( const std::string &  caption)

Sets the caption of the label. It's advisable to call adjustSize after setting of the caption to adjust the label's size to fit the caption.

captionThe caption of the label.
See also
getCaption, adjustSize

Definition at line 264 of file label.cpp.

265 {
266  if (caption != mCaption)
267  mTextChanged = true;
268  mCaption = caption;
269 }

References mCaption, and mTextChanged.

Referenced by Setup_Joystick::action(), Setup_Video::action(), KillStats::action(), StatsPageBasic::attributeChanged(), KillStats::attributeChanged(), StatusWindow::attributeChanged(), BankWindow::bankMoneyChanged(), Setup_Video::cancel(), CharacterViewSmall::CharacterViewSmall(), KillStats::gainXp(), MapDebugTab::logic(), NetDebugTab::logic(), StatDebugTab::logic(), TargetDebugTab::logic(), ServerDialog::logic(), UpdaterWindow::logic(), MailViewWindow::removeMoney(), InfoClanTab::resetClan(), resizeTo(), Tab::setCaption(), SpeechBubble::setCaption(), ItemPopup::setItem(), SpellPopup::setItem(), StatusPopup::setLabelText(), TradeWindow::setMoney(), Setup_Colors::Setup_Colors(), Setup_Video::Setup_Video(), CharacterViewSmall::show(), BeingPopup::show(), TextPopup::show(), SkillPopup::show(), OutfitWindow::showCurrentOutfit(), StatsPageBasic::StatsPageBasic(), StatusWindow::StatusWindow(), SetupQuickItem::toWidget(), AttrDisplay::update(), ChangeDisplay::update(), CharacterDisplay::update(), KillStats::update(), SkillDialog::update(), SellDialog::updateButtonsAndLabels(), BuyDialog::updateButtonsAndLabels(), InfoClanTab::updateClan(), SocialWindow::updateCounter(), Setup_Colors::updateGradType(), CharCreateDialog::updateHair(), SetupItemSlider2::updateLabel(), SliderList::updateLabel(), StatusWindow::updateLevelLabel(), CharCreateDialog::updateLook(), CharCreateDialog::updateSliders(), and Setup_Colors::valueChanged().

◆ setForegroundColor()

void Label::setForegroundColor ( const Color color)

Definition at line 208 of file label.cpp.

209 {
210  if (mForegroundColor != color || mForegroundColor2 != color)
211  mTextChanged = true;
212 // logger->log("Label::setForegroundColor: " + mCaption);
213  mForegroundColor = color;
214  mForegroundColor2 = color;
215 }

References Widget::mForegroundColor, Widget2::mForegroundColor2, and mTextChanged.

◆ setForegroundColorAll()

void Label::setForegroundColorAll ( const Color color1,
const Color color2 

◆ setParent()

void Label::setParent ( Widget *const  parent)

Sets the parent of the widget. A parent must be a BasicContainer.

WARNING: This function is used internally and should not be called or overloaded unless you know what you are doing.

parentThe parent of the widget.
See also

Reimplemented from Widget.

Definition at line 271 of file label.cpp.

272 {
273  if (mWindow != nullptr)
274  mWindow->addWidgetListener(this);
275  Widget::setParent(widget);
276 }
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302
virtual void setParent(Widget *parent)
Definition: widget.h:626

References Widget::addWidgetListener(), Widget2::mWindow, and Widget::setParent().

◆ setWindow()

void Label::setWindow ( Widget *const  widget)

Reimplemented from Widget2.

Definition at line 278 of file label.cpp.

279 {
280  if ((widget == nullptr) && (mWindow != nullptr))
281  {
283  mWindow = nullptr;
284  }
285  else
286  {
287  Widget2::setWindow(widget);
288  }
289 }
virtual void setWindow(Widget *const window)
Definition: widget2.h:97

References Widget2::mWindow, Widget::removeWidgetListener(), and Widget2::setWindow().

◆ widgetHidden()

void Label::widgetHidden ( const Event event)

Invoked when a widget is hidden, i.e it's set to be not visible.

eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 291 of file label.cpp.

292 {
293  mTextChanged = true;
295 }

References TextChunk::deleteImage(), mTextChanged, and mTextChunk.

Field Documentation

◆ mAlignment

Graphics::Alignment Label::mAlignment

Holds the alignment of the caption.

Definition at line 189 of file label.h.

Referenced by draw(), getAlignment(), and setAlignment().

◆ mCaption

std::string Label::mCaption

Holds the caption of the label.

Definition at line 182 of file label.h.

Referenced by adjustSize(), draw(), getCaption(), resizeTo(), and setCaption().

◆ mInstances

int Label::mInstances = 0

Definition at line 174 of file label.h.

Referenced by init(), and ~Label().

◆ mPadding

int Label::mPadding

Definition at line 191 of file label.h.

Referenced by adjustSize(), draw(), init(), and resizeTo().

◆ mSkin

Skin * Label::mSkin = 0

Definition at line 172 of file label.h.

Referenced by finalCleanup(), init(), and ~Label().

◆ mTextChanged

bool Label::mTextChanged

Definition at line 193 of file label.h.

Referenced by draw(), setCaption(), setForegroundColor(), setForegroundColorAll(), and widgetHidden().

◆ mTextChunk

TextChunk Label::mTextChunk

Definition at line 184 of file label.h.

Referenced by draw(), widgetHidden(), and ~Label().

The documentation for this class was generated from the following files: