ManaPlus
Public Member Functions | Protected Types | Protected Attributes | Static Protected Attributes
ListBox Class Reference

#include <listbox.h>

Inheritance diagram for ListBox:
Widget MouseListener KeyListener Widget2 AvatarListBox ColorPage ExtendedListBox ServersListBox ShopListBox SkillListBox

Public Member Functions

 ListBox (const Widget2 *const widget, ListModel *const listModel, const std::string &skin)
 
 ~ListBox ()
 
void postInit ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void updateAlpha ()
 
void keyPressed (KeyEvent &event)
 
void mouseWheelMovedUp (MouseEvent &event)
 
void mouseWheelMovedDown (MouseEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseReleased1 (const MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void refocus ()
 
void setDistributeMousePressed (const bool b)
 
virtual void adjustSize ()
 
void logic ()
 
virtual int getSelectionByMouse (const int y) const
 
void setCenter (const bool b)
 
int getPressedIndex () const
 
virtual unsigned int getRowHeight () const
 
void setRowHeight (unsigned int n)
 
int getSelected () const
 
void setSelected (const int selected)
 
void setListModel (ListModel *listModel)
 
ListModelgetListModel () const
 
bool isWrappingEnabled () const
 
void setWrappingEnabled (const bool wrappingEnabled)
 
void addSelectionListener (SelectionListener *const selectionListener)
 
void removeSelectionListener (SelectionListener *const selectionListener)
 
void distributeValueChangedEvent ()
 
- 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
 
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
 
virtual void setParent (Widget *parent)
 
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 ()
 
- 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
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseExited (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseMoved (MouseEvent &event)
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 

Protected Types

typedef std::list< SelectionListener * > SelectionListenerList
 
typedef SelectionListenerList::iterator SelectionListenerIterator
 
- 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 Attributes

int mSelected
 
ListModelmListModel
 
bool mWrappingEnabled
 
SelectionListenerList mSelectionListeners
 
Color mHighlightColor
 
Color mForegroundSelectedColor
 
Color mForegroundSelectedColor2
 
int mOldSelected
 
int mPadding
 
int mPressedIndex
 
unsigned int mRowHeight
 
int mItemPadding
 
SkinmSkin
 
bool mDistributeMousePressed
 
bool mCenterText
 
- 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
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
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
 
WidgetmWindow
 
Color mForegroundColor2
 

Static Protected Attributes

static float mAlpha = 1.0
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Additional Inherited Members

- 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)
 
- Data Fields inherited from Widget
Visible mVisible
 
- 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 MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 

Detailed Description

A list box, meant to be used inside a scroll area. Same as the Guichan list box except this one doesn't have a background, instead completely relying on the scroll area. It also adds selection listener functionality.

Definition at line 91 of file listbox.h.

Member Typedef Documentation

◆ SelectionListenerIterator

typedef SelectionListenerList::iterator ListBox::SelectionListenerIterator
protected

Typedef.

Definition at line 281 of file listbox.h.

◆ SelectionListenerList

typedef std::list<SelectionListener*> ListBox::SelectionListenerList
protected

Typdef.

Definition at line 271 of file listbox.h.

Constructor & Destructor Documentation

◆ ListBox()

ListBox::ListBox ( const Widget2 *const  widget,
ListModel *const  listModel,
const std::string &  skin 
)

Constructor.

Definition at line 89 of file listbox.cpp.

91  :
92  Widget(widget),
93  MouseListener(),
94  KeyListener(),
95  mSelected(-1),
96  mListModel(listModel),
97  mWrappingEnabled(false),
99  mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT, 255U)),
100  mForegroundSelectedColor(getThemeColor(ThemeColorId::LISTBOX_SELECTED,
101  255U)),
103  ThemeColorId::LISTBOX_SELECTED_OUTLINE, 255U)),
104  mOldSelected(-1),
105  mPadding(0),
106  mPressedIndex(-2),
107  mRowHeight(0),
108  mItemPadding(1),
109  mSkin(nullptr),
111  mCenterText(false)
112 {
113  setWidth(100);
114  setFocusable(true);
115  addMouseListener(this);
116  addKeyListener(this);
117 
118  mForegroundColor = getThemeColor(ThemeColorId::LISTBOX, 255U);
119  mForegroundColor2 = getThemeColor(ThemeColorId::LISTBOX_OUTLINE, 255U);
120 
121  if (theme != nullptr)
122  {
123  mSkin = theme->load(skin,
124  "listbox.xml",
125  true,
127  }
128 
129  if (mSkin != nullptr)
130  {
132  mItemPadding = mSkin->getOption("itemPadding");
133  }
134 
135  const Font *const font = getFont();
137  font->getHeight() + 2 * mItemPadding);
138 }
#define CAST_U32
Definition: cast.h:31
Definition: font.h:90
int getHeight() const
Definition: font.cpp:362
int mSelected
Definition: listbox.h:256
bool mWrappingEnabled
Definition: listbox.h:266
bool mCenterText
Definition: listbox.h:294
SelectionListenerList mSelectionListeners
Definition: listbox.h:276
Color mHighlightColor
Definition: listbox.h:283
unsigned int mRowHeight
Definition: listbox.h:289
int mPressedIndex
Definition: listbox.h:288
int mOldSelected
Definition: listbox.h:286
Color mForegroundSelectedColor2
Definition: listbox.h:285
ListModel * mListModel
Definition: listbox.h:261
int mItemPadding
Definition: listbox.h:290
int mPadding
Definition: listbox.h:287
Skin * mSkin
Definition: listbox.h:291
Color mForegroundSelectedColor
Definition: listbox.h:284
bool mDistributeMousePressed
Definition: listbox.h:293
int getOption(const std::string &name) const
Definition: skin.h:106
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
Color mForegroundColor2
Definition: widget2.h:113
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
Color mForegroundColor
Definition: widget.h:1086
void setFocusable(const bool focusable)
Definition: widget.cpp:192
void setWidth(const int width)
Definition: widget.cpp:133
Widget(const Widget2 *const widget)
Definition: widget.cpp:85
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
Font * getFont() const
Definition: widget.cpp:331
Theme * theme
Definition: theme.cpp:62

References Widget::addKeyListener(), Widget::addMouseListener(), CAST_U32, Widget::getFont(), Font::getHeight(), Skin::getOption(), Skin::getPadding(), Widget2::getThemeColor(), Theme::getThemePath(), Theme::load(), Widget::mForegroundColor, Widget2::mForegroundColor2, mItemPadding, mPadding, mRowHeight, mSkin, Widget::setFocusable(), Widget::setWidth(), and theme.

◆ ~ListBox()

ListBox::~ListBox ( )

Definition at line 145 of file listbox.cpp.

146 {
147  if (gui != nullptr)
148  gui->removeDragged(this);
149 
150  if (theme != nullptr)
151  theme->unload(mSkin);
152 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
void unload(Skin *const skin)
Definition: theme.cpp:250
Gui * gui
Definition: gui.cpp:111

References gui, mSkin, Gui::removeDragged(), theme, and Theme::unload().

Member Function Documentation

◆ addSelectionListener()

void ListBox::addSelectionListener ( SelectionListener *const  selectionListener)

Adds a selection listener to the list box. When the selection changes an event will be sent to all selection listeners of the list box.

If you delete your selection listener, be sure to also remove it using removeSelectionListener().

Parameters
selectionListenerThe selection listener to add.

Definition at line 435 of file listbox.cpp.

436 {
437  mSelectionListeners.push_back(selectionListener);
438 }

References mSelectionListeners.

Referenced by BuyDialog::init(), SellDialog::postInit(), TextSelectDialog::postInit(), ServerDialog::ServerDialog(), Setup_Colors::Setup_Colors(), and ShopWindow::ShopWindow().

◆ adjustSize()

void ListBox::adjustSize ( )
virtual

Reimplemented in ShopListBox, ExtendedListBox, and ColorPage.

Definition at line 374 of file listbox.cpp.

375 {
376  BLOCK_START("ListBox::adjustSize")
377  if (mListModel != nullptr)
378  {
381  }
382  BLOCK_END("ListBox::adjustSize")
383 }
#define CAST_S32
Definition: cast.h:30
virtual unsigned int getRowHeight() const
Definition: listbox.h:156
virtual int getNumberOfElements()=0
void setHeight(const int height)
Definition: widget.cpp:140
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References BLOCK_END, BLOCK_START, CAST_S32, ListModel::getNumberOfElements(), getRowHeight(), mListModel, mPadding, and Widget::setHeight().

Referenced by ExtendedListBox::adjustSize(), PopupList::adjustSize(), logic(), postInit(), and setListModel().

◆ distributeValueChangedEvent()

void ListBox::distributeValueChangedEvent ( )

Distributes a value changed event to all selection listeners of the list box.

Definition at line 446 of file listbox.cpp.

447 {
449  {
450  SelectionEvent event(this);
451  (*iter)->valueChanged(event);
452  }
453 }
SelectionListenerList::iterator SelectionListenerIterator
Definition: listbox.h:281
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

References FOR_EACH, and mSelectionListeners.

Referenced by setSelected().

◆ draw()

void ListBox::draw ( Graphics *const  graphics)
virtual

Draws the list box.

Implements Widget.

Reimplemented in SkillListBox, ShopListBox, and ServersListBox.

Definition at line 163 of file listbox.cpp.

164 {
165  if (mListModel == nullptr)
166  return;
167 
168  BLOCK_START("ListBox::draw")
169  updateAlpha();
170 
171  mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
172  graphics->setColor(mHighlightColor);
173  Font *const font = getFont();
174  const int rowHeight = CAST_S32(getRowHeight());
175  const int width = mDimension.width;
176 
177  if (mCenterText)
178  {
179  // Draw filled rectangle around the selected list element
180  if (mSelected >= 0)
181  {
182  graphics->fillRectangle(Rect(mPadding,
183  rowHeight * mSelected + mPadding,
184  mDimension.width - 2 * mPadding, rowHeight));
185 
186  const std::string str = mListModel->getElementAt(mSelected);
187  font->drawString(graphics,
190  str,
191  (width - font->getWidth(str)) / 2,
192  mSelected * rowHeight + mPadding + mItemPadding);
193  }
194  // Draw the list elements
195  const int sz = mListModel->getNumberOfElements();
196  for (int i = 0, y = mPadding + mItemPadding;
197  i < sz; ++i, y += rowHeight)
198  {
199  if (i != mSelected)
200  {
201  const std::string str = mListModel->getElementAt(i);
202  font->drawString(graphics,
205  str,
206  (width - font->getWidth(str)) / 2, y);
207  }
208  }
209  }
210  else
211  {
212  // Draw filled rectangle around the selected list element
213  if (mSelected >= 0)
214  {
215  graphics->fillRectangle(Rect(mPadding,
216  rowHeight * mSelected + mPadding,
217  mDimension.width - 2 * mPadding, rowHeight));
218 
219  const std::string str = mListModel->getElementAt(mSelected);
220  font->drawString(graphics,
223  str,
224  mPadding,
225  mSelected * rowHeight + mPadding + mItemPadding);
226  }
227  // Draw the list elements
228  const int sz = mListModel->getNumberOfElements();
229  for (int i = 0, y = mPadding + mItemPadding; i < sz;
230  ++i, y += rowHeight)
231  {
232  if (i != mSelected)
233  {
234  const std::string str = mListModel->getElementAt(i);
235  font->drawString(graphics,
238  str,
239  mPadding, y);
240  }
241  }
242  }
243  BLOCK_END("ListBox::draw")
244 }
virtual void fillRectangle(const Rect &rectangle)=0
void updateAlpha()
Definition: listbox.cpp:154
static float mAlpha
Definition: listbox.h:292
virtual std::string getElementAt(int i)=0
Definition: rect.h:74
int width
Definition: rect.h:219
Rect mDimension
Definition: widget.h:1101
void setColor(const Color &restrict color) override final

References Color::a, BLOCK_END, BLOCK_START, CAST_S32, CAST_U32, Font::drawString(), Graphics::fillRectangle(), ListModel::getElementAt(), Widget::getFont(), ListModel::getNumberOfElements(), getRowHeight(), Font::getWidth(), mAlpha, mCenterText, Widget::mDimension, Widget::mForegroundColor, Widget2::mForegroundColor2, mForegroundSelectedColor, mForegroundSelectedColor2, mHighlightColor, mItemPadding, mListModel, mPadding, mSelected, Graphics::setColor(), updateAlpha(), Rect::width, and y.

Referenced by safeDraw().

◆ getListModel()

ListModel* ListBox::getListModel ( ) const
inline

Gets the list model used.

Returns
the list model used.
See also
setListModel

Definition at line 194 of file listbox.h.

195  { return mListModel; }

References mListModel.

Referenced by keyPressed().

◆ getPressedIndex()

int ListBox::getPressedIndex ( ) const
inline

Definition at line 153 of file listbox.h.

154  { return mPressedIndex; }

References mPressedIndex.

◆ getRowHeight()

virtual unsigned int ListBox::getRowHeight ( ) const
inlinevirtual

◆ getSelected()

int ListBox::getSelected ( ) const
inline

◆ getSelectionByMouse()

int ListBox::getSelectionByMouse ( const int  y) const
virtual

◆ isWrappingEnabled()

bool ListBox::isWrappingEnabled ( ) const
inline

Checks whether the list box wraps when selecting items with a keyboard.

Wrapping means that the selection of items will be wrapped. That is, if the first item is selected and up is pressed, the last item will get selected. If the last item is selected and down is pressed, the first item will get selected.

Returns
true if wrapping is enabled, fasle otherwise.
See also
setWrappingEnabled

Definition at line 209 of file listbox.h.

210  { return mWrappingEnabled; }

References mWrappingEnabled.

◆ keyPressed()

void ListBox::keyPressed ( KeyEvent event)
virtual

Called if a key is pressed when the widget has keyboard focus. If a key is held down the widget will generate multiple key presses.

Parameters
eventDiscribes the event.

Reimplemented from KeyListener.

Definition at line 246 of file listbox.cpp.

247 {
248  const InputActionT action = event.getActionId();
249  if (action == InputAction::GUI_SELECT)
250  {
252  event.consume();
253  }
254  else if (action == InputAction::GUI_UP)
255  {
256  if (mSelected > 0)
257  {
258  setSelected(mSelected - 1);
259  }
260  else if (mSelected == 0 &&
262  getListModel() != nullptr)
263  {
264  setSelected(getListModel()->getNumberOfElements() - 1);
265  }
266  event.consume();
267  }
268  else if (action == InputAction::GUI_DOWN)
269  {
270  const int num = getListModel()->getNumberOfElements() - 1;
271  if (mSelected < num)
272  setSelected(mSelected + 1);
273  else if (mSelected == num && mWrappingEnabled)
274  setSelected(0);
275  event.consume();
276  }
277  else if (action == InputAction::GUI_HOME)
278  {
279  setSelected(0);
280  event.consume();
281  }
282  else if (action == InputAction::GUI_END && (getListModel() != nullptr))
283  {
284  setSelected(getListModel()->getNumberOfElements() - 1);
285  event.consume();
286  }
287 }
void setSelected(const int selected)
Definition: listbox.cpp:399
ListModel * getListModel() const
Definition: listbox.h:194
void distributeActionEvent()
Definition: widget.cpp:493
InputAction ::T InputActionT
Definition: inputaction.h:717

References Widget::distributeActionEvent(), getListModel(), ListModel::getNumberOfElements(), InputAction::GUI_DOWN, InputAction::GUI_END, InputAction::GUI_HOME, InputAction::GUI_SELECT, InputAction::GUI_UP, mSelected, mWrappingEnabled, and setSelected().

Referenced by ServerDialog::keyPressed().

◆ logic()

void ListBox::logic ( )
virtual

Called for all widgets in the gui each time Gui::logic is called. You can do logic stuff here like playing an animation.

See also
Gui::logic

Reimplemented from Widget.

Definition at line 385 of file listbox.cpp.

386 {
387  BLOCK_START("ListBox::logic")
388  adjustSize();
390 }
void logic()
Definition: listbox.cpp:385
virtual void adjustSize()
Definition: listbox.cpp:374

References adjustSize(), BLOCK_END, and BLOCK_START.

◆ mouseDragged()

void ListBox::mouseDragged ( MouseEvent event)
virtual

Called when the mouse has moved and the mouse has previously been pressed on the widget.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Reimplemented in SkillListBox.

Definition at line 355 of file listbox.cpp.

356 {
357  if (event.getButton() != MouseButton::LEFT || getRowHeight() == 0)
358  return;
359 
360  // Make list selection update on drag, but guard against negative y
361  if (getRowHeight() != 0U)
362  setSelected(std::max(0, getSelectionByMouse(event.getY())));
363 }
virtual int getSelectionByMouse(const int y) const
Definition: listbox.cpp:392
MouseButtonT getButton() const
Definition: mouseevent.h:116
int getY() const
Definition: mouseevent.h:138

References MouseEvent::getButton(), getRowHeight(), getSelectionByMouse(), MouseEvent::getY(), MouseButton::LEFT, and setSelected().

Referenced by SkillListBox::mouseDragged(), and mouseReleased().

◆ mousePressed()

void ListBox::mousePressed ( MouseEvent event)
virtual

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Reimplemented in SkillListBox.

Definition at line 304 of file listbox.cpp.

305 {
307  if (mMouseConsume && mPressedIndex != -1)
308  event.consume();
309 }
bool mMouseConsume
Definition: widget.h:1162

References getSelectionByMouse(), MouseEvent::getY(), Widget::mMouseConsume, and mPressedIndex.

Referenced by SkillListBox::mousePressed().

◆ mouseReleased()

void ListBox::mouseReleased ( MouseEvent event)
virtual

Called when a mouse button has been released on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Reimplemented in SkillListBox, and ShopListBox.

Definition at line 311 of file listbox.cpp.

312 {
313  if (mPressedIndex != getSelectionByMouse(event.getY()))
314  return;
315 
317  {
318  mouseReleased1(event);
319  }
320  else
321  {
322  switch (event.getClickCount())
323  {
324  case 1:
325  mouseDragged(event);
327  break;
328  case 2:
329  if (gui != nullptr)
330  gui->resetClickCount();
331  if (mOldSelected == mSelected)
332  mouseReleased1(event);
333  else
334  mouseDragged(event);
336  break;
337  default:
338  mouseDragged(event);
340  break;
341  }
342  }
343  mPressedIndex = -2;
344 }
void resetClickCount()
Definition: gui.cpp:980
void mouseReleased1(const MouseEvent &event)
Definition: listbox.cpp:346
void mouseDragged(MouseEvent &event)
Definition: listbox.cpp:355
int getClickCount() const
Definition: mouseevent.h:147

References MouseEvent::getClickCount(), getSelectionByMouse(), MouseEvent::getY(), gui, mDistributeMousePressed, mOldSelected, mouseDragged(), mouseReleased1(), mPressedIndex, mSelected, and Gui::resetClickCount().

Referenced by ShopListBox::mouseReleased(), and SkillListBox::mouseReleased().

◆ mouseReleased1()

void ListBox::mouseReleased1 ( const MouseEvent event)

Definition at line 346 of file listbox.cpp.

347 {
348  if (event.getButton() == MouseButton::LEFT)
349  {
350  setSelected(std::max(0, getSelectionByMouse(event.getY())));
352  }
353 }

References Widget::distributeActionEvent(), MouseEvent::getButton(), getSelectionByMouse(), MouseEvent::getY(), MouseButton::LEFT, and setSelected().

Referenced by mouseReleased().

◆ mouseWheelMovedDown()

void ListBox::mouseWheelMovedDown ( MouseEvent event)
virtual

Called when the mouse wheel has moved down on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 300 of file listbox.cpp.

301 {
302 }

◆ mouseWheelMovedUp()

void ListBox::mouseWheelMovedUp ( MouseEvent event)
virtual

Called when the mouse wheel has moved up on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 296 of file listbox.cpp.

297 {
298 }

◆ postInit()

void ListBox::postInit ( )
virtual

Reimplemented from Widget.

Definition at line 140 of file listbox.cpp.

141 {
142  adjustSize();
143 }

References adjustSize().

◆ refocus()

void ListBox::refocus ( )

Definition at line 365 of file listbox.cpp.

366 {
367  if (mFocusHandler == nullptr)
368  return;
369 
370  if (isFocusable())
372 }
void requestFocus(const Widget *const widget)
FocusHandler * mFocusHandler
Definition: widget.h:1116
bool isFocusable() const
Definition: widget.cpp:199

References Widget::isFocusable(), Widget::mFocusHandler, and FocusHandler::requestFocus().

Referenced by NpcDialog::refocus().

◆ removeSelectionListener()

void ListBox::removeSelectionListener ( SelectionListener *const  selectionListener)

Removes a selection listener from the list box.

Parameters
selectionListenerThe selection listener to remove.

Definition at line 440 of file listbox.cpp.

442 {
443  mSelectionListeners.remove(selectionListener);
444 }

References mSelectionListeners.

◆ safeDraw()

void ListBox::safeDraw ( Graphics *const  graphics)
virtual

Implements Widget.

Reimplemented in SkillListBox, ShopListBox, and ServersListBox.

Definition at line 289 of file listbox.cpp.

290 {
291  ListBox::draw(graphics);
292 }
void draw(Graphics *const graphics)
Definition: listbox.cpp:163

References draw().

◆ setCenter()

void ListBox::setCenter ( const bool  b)
inline

Definition at line 150 of file listbox.h.

151  { mCenterText = b; }

References mCenterText.

Referenced by EmoteWindow::postInit().

◆ setDistributeMousePressed()

void ListBox::setDistributeMousePressed ( const bool  b)
inline

◆ setListModel()

void ListBox::setListModel ( ListModel listModel)

Sets the list model to use.

Parameters
listModelthe list model to use.
See also
getListModel

Definition at line 428 of file listbox.cpp.

429 {
430  mSelected = -1;
431  mListModel = listModel;
432  adjustSize();
433 }

References adjustSize(), mListModel, and mSelected.

Referenced by PopupList::setListModel().

◆ setRowHeight()

void ListBox::setRowHeight ( unsigned int  n)
inline

Definition at line 159 of file listbox.h.

160  { mRowHeight = n; }

References mRowHeight.

Referenced by NpcDialog::NpcDialog(), and QuestsWindow::QuestsWindow().

◆ setSelected()

void ListBox::setSelected ( const int  selected)

Sets the selected item. The selected item is represented by an index from the list model.

Parameters
selectedthe selected item as an index from the list model.
See also
getSelected

Definition at line 399 of file listbox.cpp.

400 {
401  if (mListModel == nullptr)
402  {
403  mSelected = -1;
404  }
405  else
406  {
407  if (selected < 0)
408  mSelected = -1;
409  else if (selected >= mListModel->getNumberOfElements())
411  else
412  mSelected = selected;
413  }
414 
415  Rect scroll;
416 
417  if (mSelected < 0)
418  scroll.y = 0;
419  else
420  scroll.y = CAST_S32(getRowHeight()) * mSelected;
421 
422  scroll.height = CAST_S32(getRowHeight());
423  showPart(scroll);
424 
426 }
void distributeValueChangedEvent()
Definition: listbox.cpp:446
int y
Definition: rect.h:214
int height
Definition: rect.h:224
virtual void showPart(const Rect &rectangle)
Definition: widget.cpp:511

References CAST_S32, distributeValueChangedEvent(), ListModel::getNumberOfElements(), getRowHeight(), Rect::height, mListModel, mSelected, Widget::showPart(), and Rect::y.

Referenced by Setup_Input::action(), ServerDialog::action(), NpcDialog::buildLayout(), Setup_Video::cancel(), MailWindow::clear(), EmoteWindow::clearFont(), EmoteWindow::clearText(), keyPressed(), ServerDialog::keyPressed(), ServerDialog::loadServers(), mouseDragged(), AvatarListBox::mousePressed(), ShopListBox::mouseReleased(), mouseReleased1(), NpcDialog::move(), NpcDialog::parseListItems(), ServerDialog::postInit(), QuestsWindow::rebuild(), SellDialog::reset(), BuyDialog::reset(), ColorPage::resetAction(), QuestsWindow::selectQuest(), NpcSellDialog::sellOneItem(), PopupList::setSelected(), Setup_Video::Setup_Video(), MailWindow::viewNext(), MailWindow::viewPrev(), and WorldSelectDialog::WorldSelectDialog().

◆ setWrappingEnabled()

void ListBox::setWrappingEnabled ( const bool  wrappingEnabled)
inline

Sets the list box to wrap or not when selecting items with a keyboard.

Wrapping means that the selection of items will be wrapped. That is, if the first item is selected and up is pressed, the last item will get selected. If the last item is selected and down is pressed, the first item will get selected.

See also
isWrappingEnabled

Definition at line 223 of file listbox.h.

224  { mWrappingEnabled = wrappingEnabled; }

References mWrappingEnabled.

Referenced by NpcDialog::NpcDialog().

◆ updateAlpha()

void ListBox::updateAlpha ( )

Update the alpha value to the graphic components.

Definition at line 154 of file listbox.cpp.

155 {
156  const float alpha = std::max(settings.guiAlpha,
158 
159  if (mAlpha != alpha)
160  mAlpha = alpha;
161 }
float guiAlpha
Definition: settings.h:131
float getMinimumOpacity() const
Definition: theme.h:124
Settings settings
Definition: settings.cpp:32

References Theme::getMinimumOpacity(), Settings::guiAlpha, mAlpha, settings, and theme.

Referenced by ColorPage::draw(), ExtendedListBox::draw(), draw(), ServersListBox::draw(), SkillListBox::draw(), AvatarListBox::draw(), and AvatarListBox::safeDraw().

Field Documentation

◆ mAlpha

float ListBox::mAlpha = 1.0
staticprotected

◆ mCenterText

bool ListBox::mCenterText
protected

Definition at line 294 of file listbox.h.

Referenced by draw(), and setCenter().

◆ mDistributeMousePressed

bool ListBox::mDistributeMousePressed
protected

Definition at line 293 of file listbox.h.

Referenced by mouseReleased(), and setDistributeMousePressed().

◆ mForegroundSelectedColor

Color ListBox::mForegroundSelectedColor
protected

Definition at line 284 of file listbox.h.

Referenced by ExtendedListBox::draw(), draw(), ServersListBox::draw(), and ShopListBox::draw().

◆ mForegroundSelectedColor2

Color ListBox::mForegroundSelectedColor2
protected

Definition at line 285 of file listbox.h.

Referenced by ExtendedListBox::draw(), draw(), ServersListBox::draw(), and ShopListBox::draw().

◆ mHighlightColor

Color ListBox::mHighlightColor
protected

◆ mItemPadding

int ListBox::mItemPadding
protected

Definition at line 290 of file listbox.h.

Referenced by ColorPage::ColorPage(), draw(), and ListBox().

◆ mListModel

ListModel* ListBox::mListModel
protected

◆ mOldSelected

int ListBox::mOldSelected
protected

Definition at line 286 of file listbox.h.

Referenced by mouseReleased().

◆ mPadding

int ListBox::mPadding
protected

◆ mPressedIndex

int ListBox::mPressedIndex
protected

Definition at line 288 of file listbox.h.

Referenced by getPressedIndex(), mousePressed(), and mouseReleased().

◆ mRowHeight

unsigned int ListBox::mRowHeight
protected

◆ mSelected

int ListBox::mSelected
protected

◆ mSelectionListeners

SelectionListenerList ListBox::mSelectionListeners
protected

The selection listeners of the list box.

Definition at line 276 of file listbox.h.

Referenced by addSelectionListener(), distributeValueChangedEvent(), and removeSelectionListener().

◆ mSkin

Skin* ListBox::mSkin
protected

Definition at line 291 of file listbox.h.

Referenced by ColorPage::ColorPage(), ListBox(), and ~ListBox().

◆ mWrappingEnabled

bool ListBox::mWrappingEnabled
protected

True if wrapping is enabled, false otherwise.

Definition at line 266 of file listbox.h.

Referenced by isWrappingEnabled(), keyPressed(), and setWrappingEnabled().


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