ManaPlus
Public Member Functions | Protected Attributes
ExtendedListBox Class Reference

#include <extendedlistbox.h>

Inheritance diagram for ExtendedListBox:
ListBox Widget MouseListener KeyListener Widget2

Public Member Functions

 ExtendedListBox (const Widget2 *const widget, ListModel *const listModel, const std::string &skin, const unsigned int rowHeight)
 
 ~ExtendedListBox ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void adjustSize ()
 
int getSelectionByMouse (const int y) const
 
- Public Member Functions inherited from ListBox
 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)
 
void logic ()
 
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 Attributes

int mImagePadding
 
int mSpacing
 
int mHeight
 
std::vector< ExtendedListBoxItemmListItems
 
std::vector< ExtendedListBoxItemmSelectedItems
 
- Protected Attributes inherited from ListBox
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
 

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 Types inherited from ListBox
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 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 ()
 
- Static Protected Attributes inherited from ListBox
static float mAlpha = 1.0
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Definition at line 28 of file extendedlistbox.h.

Constructor & Destructor Documentation

◆ ExtendedListBox()

ExtendedListBox::ExtendedListBox ( const Widget2 *const  widget,
ListModel *const  listModel,
const std::string &  skin,
const unsigned int  rowHeight 
)

Constructor.

Definition at line 34 of file extendedlistbox.cpp.

37  :
38  ListBox(widget, listModel, skin),
39  mImagePadding(mSkin != nullptr ? mSkin->getOption("imagePadding") : 0),
40  mSpacing(mSkin != nullptr ? mSkin->getOption("spacing") : 0),
41  mHeight(0),
42  mListItems(),
44 {
45  if (rowHeight != 0U)
46  mRowHeight = rowHeight;
47 }
std::vector< ExtendedListBoxItem > mListItems
std::vector< ExtendedListBoxItem > mSelectedItems
ListBox(const Widget2 *const widget, ListModel *const listModel, const std::string &skin)
Definition: listbox.cpp:89
unsigned int mRowHeight
Definition: listbox.h:289
Skin * mSkin
Definition: listbox.h:291
int getOption(const std::string &name) const
Definition: skin.h:106

References ListBox::mRowHeight.

◆ ~ExtendedListBox()

ExtendedListBox::~ExtendedListBox ( )

Definition at line 49 of file extendedlistbox.cpp.

50 {
51 }

Member Function Documentation

◆ adjustSize()

void ExtendedListBox::adjustSize ( )
virtual

Reimplemented from ListBox.

Definition at line 226 of file extendedlistbox.cpp.

227 {
228  if (mHeight != 0)
229  setHeight(mHeight + 2 * mPadding);
230  else
232 }
virtual void adjustSize()
Definition: listbox.cpp:374
int mPadding
Definition: listbox.h:287
void setHeight(const int height)
Definition: widget.cpp:140

References ListBox::adjustSize(), mHeight, ListBox::mPadding, and Widget::setHeight().

◆ draw()

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

Draws the list box.

Implements Widget.

Definition at line 53 of file extendedlistbox.cpp.

54 {
55  if (mListModel == nullptr)
56  return;
57 
58  BLOCK_START("ExtendedListBox::draw")
59  ExtendedListModel *const model = static_cast<ExtendedListModel *>(
60  mListModel);
61 
62  updateAlpha();
63  Font *const font = getFont();
64 
65  const int height = CAST_S32(mRowHeight);
66  const int pad2 = 2 + mPadding;
67  const int width = mDimension.width;
68  int textPos = (height - font->getHeight()) / 2 + mPadding;
69  if (textPos < 0)
70  textPos = 0;
71 
72  const int sz = mListModel->getNumberOfElements();
73  mListItems.clear();
75  int y = 0;
76  const int insideWidth = width - pad2;
77  for (int f = 0; f < sz; f ++)
78  {
79  int row = f;
80  bool useImage = true;
81  std::string str = mListModel->getElementAt(f);
82  int strWidth = font->getWidth(str) + 8;
83 
84  const Image *const image = model->getImageAt(row);
85  if (image != nullptr)
86  strWidth += image->getWidth() + mImagePadding;
87 
88  STD_VECTOR<ExtendedListBoxItem> &list =
90 
91  if (insideWidth < strWidth)
92  {
93  const size_t strSize = str.size();
94  size_t divPos = strSize / 2;
95  if (divPos > 0 && CAST_U8(
96  str[divPos - 1]) >= 0xc0)
97  {
98  divPos --;
99  }
100  for (size_t d = divPos; d > 10; d --)
101  {
102  if (str[d] == 32)
103  {
104  divPos = d + 1;
105  break;
106  }
107  }
108  list.push_back(ExtendedListBoxItem(row,
109  str.substr(0, divPos), useImage, y));
110  str = str.substr(divPos);
111  y += height;
112  useImage = false;
113  }
114  list.push_back(ExtendedListBoxItem(row, str, useImage, y));
115 
116  y += height;
117  }
118  mHeight = y + height;
119 
120  const size_t itemsSz = mListItems.size();
121  const size_t selSz = mSelectedItems.size();
122  int minY = -1;
123  int maxY = -1;
124  for (size_t f = 0; f < selSz; f ++)
125  {
126  const ExtendedListBoxItem &item = mSelectedItems[f];
127  const int y1 = item.y;
128  if (minY == -1)
129  minY = y1;
130  if (maxY < y1)
131  maxY = y1;
132  }
133 
134  if (minY != -1)
135  {
136  mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
137  graphics->setColor(mHighlightColor);
138  graphics->fillRectangle(Rect(mPadding, minY + mPadding,
139  width - pad2, maxY - minY + height));
140  }
141 
142  for (size_t f = 0; f < itemsSz; ++f)
143  {
144  const ExtendedListBoxItem &item = mListItems[f];
145  if (item.image)
146  {
147  const int row1 = item.row;
148  const Image *const image = model->getImageAt(row1);
149  if (image != nullptr)
150  {
151  graphics->drawImage(image,
153  item.y + (height - image->getHeight()) / 2 + mPadding);
154  }
155  }
156  }
157 
158  for (size_t f = 0; f < itemsSz; ++f)
159  {
160  const ExtendedListBoxItem &item = mListItems[f];
161  const int row1 = item.row;
162  const int y1 = item.y;
163  const Image *const image = model->getImageAt(row1);
164  if ((image == nullptr) || !item.image)
165  {
166  font->drawString(graphics,
168  item.text,
169  mPadding, y1 + textPos);
170  }
171  else
172  {
173  font->drawString(graphics,
175  item.text,
176  image->getWidth() + mImagePadding + mSpacing, y1 + textPos);
177  }
178  }
179 
180  for (size_t f = 0; f < selSz; ++f)
181  {
182  const ExtendedListBoxItem &item = mSelectedItems[f];
183  const int row1 = item.row;
184  const int y1 = item.y;
185  const Image *const image = model->getImageAt(row1);
186  if ((image == nullptr) || !item.image)
187  {
188  font->drawString(graphics,
190  item.text,
191  mPadding, y1 + textPos);
192  }
193  else
194  {
195  font->drawString(graphics,
197  item.text,
198  image->getWidth() + mImagePadding + mSpacing, y1 + textPos);
199  }
200  }
201 
202  for (size_t f = 0; f < selSz; ++f)
203  {
204  const ExtendedListBoxItem &item = mSelectedItems[f];
205  if (item.image)
206  {
207  const int row1 = item.row;
208  const Image *const image = model->getImageAt(row1);
209  if (image != nullptr)
210  {
211  graphics->drawImage(image,
213  item.y + (height - image->getHeight()) / 2 + mPadding);
214  }
215  }
216  }
217 
218  BLOCK_END("ExtendedListBox::draw")
219 }
#define CAST_S32
Definition: cast.h:30
#define CAST_U32
Definition: cast.h:31
#define CAST_U8
Definition: cast.h:27
unsigned int a
Definition: color.h:251
Definition: font.h:90
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
virtual void fillRectangle(const Rect &rectangle)=0
virtual void setColor(const Color &color)
Definition: graphics.h:320
int mSelected
Definition: listbox.h:256
Color mHighlightColor
Definition: listbox.h:283
void updateAlpha()
Definition: listbox.cpp:154
Color mForegroundSelectedColor2
Definition: listbox.h:285
ListModel * mListModel
Definition: listbox.h:261
static float mAlpha
Definition: listbox.h:292
Color mForegroundSelectedColor
Definition: listbox.h:284
virtual std::string getElementAt(int i)=0
Definition: rect.h:74
Color mForegroundColor2
Definition: widget2.h:113
Color mForegroundColor
Definition: widget.h:1086
Rect mDimension
Definition: widget.h:1101
Font * getFont() const
Definition: widget.cpp:331
int getHeight() const
Definition: widget.h:240
if(!vert) return
void clear()
Definition: playerinfo.cpp:452
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References Color::a, BLOCK_END, BLOCK_START, CAST_S32, CAST_U32, CAST_U8, Graphics::drawImage(), Font::drawString(), Graphics::fillRectangle(), ListModel::getElementAt(), Widget::getFont(), Font::getHeight(), ExtendedListModel::getImageAt(), ListModel::getNumberOfElements(), Font::getWidth(), ExtendedListBoxItem::image, ListBox::mAlpha, Widget::mDimension, Widget::mForegroundColor, Widget2::mForegroundColor2, ListBox::mForegroundSelectedColor, ListBox::mForegroundSelectedColor2, mHeight, ListBox::mHighlightColor, mImagePadding, mListItems, ListBox::mListModel, ListBox::mPadding, ListBox::mRowHeight, ListBox::mSelected, mSelectedItems, mSpacing, ExtendedListBoxItem::row, Graphics::setColor(), ExtendedListBoxItem::text, ListBox::updateAlpha(), Rect::width, ExtendedListBoxItem::y, and y.

Referenced by safeDraw().

◆ getSelectionByMouse()

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

Reimplemented from ListBox.

Definition at line 234 of file extendedlistbox.cpp.

235 {
236  if (mListItems.empty() && mSelectedItems.empty())
238 
239  const int height = CAST_S32(mRowHeight);
240  const size_t itemsSz = mListItems.size();
241  for (size_t f = 0; f < itemsSz; f ++)
242  {
243  const ExtendedListBoxItem &item = mListItems[f];
244  const int y2 = item.y + mPadding;
245  if (y2 <= y && y2 + height > y)
246  return item.row;
247  }
248 
249  const size_t selSz = mSelectedItems.size();
250  for (size_t f = 0; f < selSz; f ++)
251  {
252  const ExtendedListBoxItem &item = mSelectedItems[f];
253  const int y2 = item.y + mPadding;
254  if (y2 <= y && y2 + height > y)
255  return item.row;
256  }
257  return 0;
258 }
virtual int getSelectionByMouse(const int y) const
Definition: listbox.cpp:392

References CAST_S32, ListBox::getSelectionByMouse(), mListItems, ListBox::mPadding, ListBox::mRowHeight, mSelectedItems, ExtendedListBoxItem::row, ExtendedListBoxItem::y, and y.

◆ safeDraw()

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

Implements Widget.

Definition at line 221 of file extendedlistbox.cpp.

222 {
223  ExtendedListBox::draw(graphics);
224 }
void draw(Graphics *const graphics)

References draw().

Field Documentation

◆ mHeight

int ExtendedListBox::mHeight
protected

Definition at line 57 of file extendedlistbox.h.

Referenced by adjustSize(), and draw().

◆ mImagePadding

int ExtendedListBox::mImagePadding
protected

Definition at line 55 of file extendedlistbox.h.

Referenced by draw().

◆ mListItems

std::vector<ExtendedListBoxItem> ExtendedListBox::mListItems
protected

Definition at line 58 of file extendedlistbox.h.

Referenced by draw(), and getSelectionByMouse().

◆ mSelectedItems

std::vector<ExtendedListBoxItem> ExtendedListBox::mSelectedItems
protected

Definition at line 59 of file extendedlistbox.h.

Referenced by draw(), and getSelectionByMouse().

◆ mSpacing

int ExtendedListBox::mSpacing
protected

Definition at line 56 of file extendedlistbox.h.

Referenced by draw().


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