ManaPlus
Public Member Functions | Private Attributes
ServersListBox Class Reference

#include <serverslistbox.h>

Inheritance diagram for ServersListBox:
ListBox Widget MouseListener KeyListener Widget2

Public Member Functions

 ServersListBox (const Widget2 *const widget, ServersListModel *const model)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
unsigned int getRowHeight () const
 
- Public Member Functions inherited from ListBox
 ListBox (const Widget2 *const widget, ListModel *const listModel, const std::string &skin)
 
 ~ListBox ()
 
void postInit ()
 
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
 
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)
 

Private Attributes

Color mNotSupportedColor
 
Color mNotSupportedColor2
 

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 ()
 
- 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
 
- 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 33 of file serverslistbox.h.

Constructor & Destructor Documentation

◆ ServersListBox()

ServersListBox::ServersListBox ( const Widget2 *const  widget,
ServersListModel *const  model 
)
inline

Definition at line 36 of file serverslistbox.h.

37  :
38  ListBox(widget, model, "serverslistbox.xml"),
40  ThemeColorId::SERVER_VERSION_NOT_SUPPORTED, 255U)),
42  ThemeColorId::SERVER_VERSION_NOT_SUPPORTED_OUTLINE, 255U))
43  {
44  mHighlightColor = getThemeColor(ThemeColorId::HIGHLIGHT, 255U);
45  }
ListBox(const Widget2 *const widget, ListModel *const listModel, const std::string &skin)
Definition: listbox.cpp:89
Color mHighlightColor
Definition: listbox.h:283
Color mNotSupportedColor
Color mNotSupportedColor2
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45

References Widget2::getThemeColor(), and ListBox::mHighlightColor.

Member Function Documentation

◆ draw()

void ServersListBox::draw ( Graphics *const  graphics)
inlinevirtual

Draws the list box.

Reimplemented from ListBox.

Definition at line 49 of file serverslistbox.h.

50  {
51  if (mListModel == nullptr)
52  return;
53 
54  ServersListModel *const model
55  = static_cast<ServersListModel *>(mListModel);
56 
57  updateAlpha();
58 
59  mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
60  graphics->setColor(mHighlightColor);
61 
62  const int height = getRowHeight();
63  mNotSupportedColor.a = CAST_S32(mAlpha * 255.0F);
64 
65  // Draw filled rectangle around the selected list element
66  if (mSelected >= 0)
67  {
68  graphics->fillRectangle(Rect(mPadding,
69  height * mSelected + mPadding,
70  getWidth() - 2 * mPadding,
71  height));
72  }
73 
74  Font *const font1 = boldFont;
75  Font *const font2 = getFont();
76  const int fontHeight = font1->getHeight();
77  const int pad1 = fontHeight + mPadding;
78  const int pad2 = height / 4 + mPadding;
79  const int width = getWidth();
80  // Draw the list elements
81  for (int i = 0, y = 0; i < model->getNumberOfElements();
82  ++i, y += height)
83  {
84  const ServerInfo &info = model->getServer(i);
85 
86  const Color *color1;
87  const Color *color2;
88  if (mSelected == i)
89  {
90  color1 = &mForegroundSelectedColor;
91  color2 = &mForegroundSelectedColor2;
92  }
93  else
94  {
95  color1 = &mForegroundColor;
96  color2 = &mForegroundColor2;
97  }
98 
99  int top;
100  int x = mPadding;
101 
102  if (!info.name.empty())
103  {
104  x += font1->getWidth(info.name) + 15;
105  font1->drawString(graphics,
106  *color1,
107  *color2,
108  info.name,
109  mPadding,
110  y + mPadding);
111  top = y + pad1;
112  }
113  else
114  {
115  top = y + pad2;
116  }
117 
118  if (!info.description.empty())
119  {
120  font2->drawString(graphics,
121  *color1,
122  *color2,
123  info.description,
124  x,
125  y + mPadding);
126  }
127  font2->drawString(graphics,
128  *color1,
129  *color2,
130  model->getElementAt(i),
131  mPadding,
132  top);
133 
134  if (info.version.first > 0)
135  {
136  font2->drawString(graphics,
139  info.version.second,
140  width - info.version.first - mPadding,
141  top);
142  }
143  }
144  }
#define CAST_S32
Definition: cast.h:30
Definition: color.h:76
unsigned int a
Definition: color.h:251
Definition: font.h:90
int getHeight() const
Definition: font.cpp:362
int getWidth(const std::string &text) const
Definition: font.cpp:334
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:254
virtual void fillRectangle(const Rect &rectangle)=0
virtual void setColor(const Color &color)
Definition: graphics.h:320
int mSelected
Definition: listbox.h:256
void updateAlpha()
Definition: listbox.cpp:154
Color mForegroundSelectedColor2
Definition: listbox.h:285
ListModel * mListModel
Definition: listbox.h:261
int mPadding
Definition: listbox.h:287
static float mAlpha
Definition: listbox.h:292
Color mForegroundSelectedColor
Definition: listbox.h:284
Definition: rect.h:74
unsigned int getRowHeight() const
const ServerInfo & getServer(const int elementIndex) const
std::string getElementAt(int elementIndex)
Color mForegroundColor2
Definition: widget2.h:113
Color mForegroundColor
Definition: widget.h:1086
Font * getFont() const
Definition: widget.cpp:331
int getWidth() const
Definition: widget.h:221
const Image *restrict const top
Font * boldFont
Definition: gui.cpp:112
bool info(InputEvent &event)
Definition: commands.cpp:57

References Color::a, boldFont, CAST_S32, Font::drawString(), ServersListModel::getElementAt(), Widget::getFont(), Font::getHeight(), ServersListModel::getNumberOfElements(), getRowHeight(), ServersListModel::getServer(), Widget::getWidth(), Font::getWidth(), Actions::info(), ListBox::mAlpha, Widget::mForegroundColor, Widget2::mForegroundColor2, ListBox::mForegroundSelectedColor, ListBox::mForegroundSelectedColor2, ListBox::mHighlightColor, ListBox::mListModel, mNotSupportedColor, mNotSupportedColor2, ListBox::mPadding, ListBox::mSelected, top, ListBox::updateAlpha(), x, and y.

Referenced by safeDraw().

◆ getRowHeight()

unsigned int ServersListBox::getRowHeight ( ) const
inlinevirtual

Reimplemented from ListBox.

Definition at line 151 of file serverslistbox.h.

152  {
153  return 2 * getFont()->getHeight() + 5;
154  }

References Widget::getFont(), and Font::getHeight().

Referenced by draw().

◆ safeDraw()

void ServersListBox::safeDraw ( Graphics *const  graphics)
inlinevirtual

Reimplemented from ListBox.

Definition at line 146 of file serverslistbox.h.

147  {
148  ServersListBox::draw(graphics);
149  }
void draw(Graphics *const graphics)

References draw().

Field Documentation

◆ mNotSupportedColor

Color ServersListBox::mNotSupportedColor
private

Definition at line 156 of file serverslistbox.h.

Referenced by draw().

◆ mNotSupportedColor2

Color ServersListBox::mNotSupportedColor2
private

Definition at line 157 of file serverslistbox.h.

Referenced by draw().


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