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

#include <dropdown.h>

Inheritance diagram for DropDown:
ActionListener BasicContainer KeyListener MouseListener FocusListener SelectionListener Widget WidgetDeathListener Widget2

Public Member Functions

 DropDown (const Widget2 *const widget, ListModel *const listModel, const bool extended, const Modal modal, ActionListener *const listener, const std::string &eventId)
 
 ~DropDown ()
 
void updateAlpha ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void drawFrame (Graphics *const graphics)
 
void safeDrawFrame (Graphics *const graphics)
 
void keyPressed (KeyEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseWheelMovedUp (MouseEvent &event)
 
void mouseWheelMovedDown (MouseEvent &event)
 
void setSelectedString (const std::string &str)
 
std::string getSelectedString () const
 
void valueChanged (const SelectionEvent &event)
 
void updateSelection ()
 
void adjustHeight ()
 
void dropDown ()
 
void foldUp ()
 
void hideDrop (bool event)
 
int getSelected () const
 
void setSelected (int selected)
 
void setListModel (ListModel *const listModel)
 
ListModelgetListModel ()
 
void addSelectionListener (SelectionListener *listener)
 
void removeSelectionListener (SelectionListener *selectionListener)
 
Rect getChildrenArea ()
 
void action (const ActionEvent &actionEvent)
 
void distributeValueChangedEvent ()
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget * > &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
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 ()
 
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
 
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 FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
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
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 
- 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 FocusListener
virtual ~FocusListener ()
 
virtual void focusGained (const Event &event)
 
virtual void focusLost (const Event &event)
 
- Public Member Functions inherited from SelectionListener
virtual ~SelectionListener ()
 

Protected Types

typedef std::list< SelectionListener * > SelectionListenerList
 
typedef SelectionListenerList::iterator SelectionListenerIterator
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- 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

void drawButton (Graphics *const graphics)
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- 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 WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from FocusListener
 FocusListener ()
 
- Protected Member Functions inherited from SelectionListener
 SelectionListener ()
 

Protected Attributes

PopupListmPopup
 
Color mShadowColor
 
Color mHighlightColor
 
int mPadding
 
int mImagePadding
 
int mSpacing
 
int mFoldedUpHeight
 
SelectionListenerList mSelectionListeners
 
bool mExtended
 
bool mDroppedDown
 
bool mPushed
 
bool mIsDragged
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- 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 int instances = 0
 
static Imagebuttons [2][2]
 
static ImageRect skinRect
 
static float mAlpha = 1.0
 
static SkinmSkin = 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
 

Detailed Description

A drop down box from which you can select different values.

A ListModel provides the contents of the drop down. To be able to use DropDown you must give DropDown an implemented ListModel which represents your list.

Definition at line 51 of file dropdown.h.

Member Typedef Documentation

◆ SelectionListenerIterator

typedef SelectionListenerList::iterator DropDown::SelectionListenerIterator
protected

Definition at line 152 of file dropdown.h.

◆ SelectionListenerList

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

Definition at line 150 of file dropdown.h.

Constructor & Destructor Documentation

◆ DropDown()

DropDown::DropDown ( const Widget2 *const  widget,
ListModel *const  listModel,
const bool  extended,
const Modal  modal,
ActionListener *const  listener,
const std::string &  eventId 
)

Definition at line 56 of file dropdown.cpp.

61  :
63  BasicContainer(widget),
64  KeyListener(),
65  MouseListener(),
66  FocusListener(),
68  mPopup(CREATEWIDGETR(PopupList, this, listModel, isExtended, modal)),
69  mShadowColor(getThemeColor(ThemeColorId::DROPDOWN_SHADOW, 255U)),
70  mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT, 255U)),
71  mPadding(1),
72  mImagePadding(2),
73  mSpacing(0),
74  mFoldedUpHeight(0),
76  mExtended(isExtended),
77  mDroppedDown(false),
78  mPushed(false),
79  mIsDragged(false)
80 {
81  mAllowLogic = false;
82  mFrameSize = 2;
83  mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE, 255U);
84 
85  mPopup->setHeight(100);
86 
87  // Initialize graphics
88  if (instances == 0 && (theme != nullptr))
89  {
90  // Load the background skin
91  for (int i = 0; i < 2; i ++)
92  {
93  Skin *const skin = theme->load(dropdownFiles[i],
94  "dropdown.xml",
95  true,
97  if (skin != nullptr)
98  {
99  if (i == 0)
100  mSkin = skin;
101  const ImageRect &rect = skin->getBorder();
102  for (int f = 0; f < 2; f ++)
103  {
104  if (rect.grid[f] != nullptr)
105  {
106  rect.grid[f]->incRef();
107  buttons[f][i] = rect.grid[f];
108  buttons[f][i]->setAlpha(mAlpha);
109  }
110  else
111  {
112  buttons[f][i] = nullptr;
113  }
114  }
115  if (i != 0)
116  theme->unload(skin);
117  }
118  else
119  {
120  for (int f = 0; f < 2; f ++)
121  buttons[f][i] = nullptr;
122  }
123  }
124 
125  // get the border skin
126  theme->loadRect(skinRect, "dropdown_background.xml", "", 0, 8);
127  }
128 
129  instances++;
130 
131  setWidth(100);
132  setFocusable(true);
133  setListModel(listModel);
134 
135  if (mPopup->getSelected() < 0)
136  mPopup->setSelected(0);
137 
138  addMouseListener(this);
139  addKeyListener(this);
140  addFocusListener(this);
141 
142  adjustHeight();
143 // mPopup->setForegroundColorAll(getThemeColor(ThemeColorId::DROPDOWN,
144 // 255U),
145 // getThemeColor(ThemeColorId::DROPDOWN_OUTLINE, 255U));
146  mForegroundColor = getThemeColor(ThemeColorId::DROPDOWN, 255U);
147  mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE, 255U);
148 
149  if (!eventId.empty())
150  setActionEventId(eventId);
151 
152  if (listener != nullptr)
154 
155  mPopup->adjustSize();
156 
157  if (mSkin != nullptr)
158  {
159  mSpacing = mSkin->getOption("spacing");
160  mFrameSize = CAST_U32(mSkin->getOption("frameSize"));
162  mImagePadding = mSkin->getOption("imagePadding");
163  }
164  adjustHeight();
165 }
#define CAST_U32
Definition: cast.h:31
static Skin * mSkin
Definition: dropdown.h:164
bool mExtended
Definition: dropdown.h:154
static int instances
Definition: dropdown.h:160
bool mDroppedDown
Definition: dropdown.h:155
bool mPushed
Definition: dropdown.h:156
void adjustHeight()
Definition: dropdown.cpp:470
int mSpacing
Definition: dropdown.h:147
Color mShadowColor
Definition: dropdown.h:143
PopupList * mPopup
Definition: dropdown.h:142
int mImagePadding
Definition: dropdown.h:146
static ImageRect skinRect
Definition: dropdown.h:162
static float mAlpha
Definition: dropdown.h:163
Color mHighlightColor
Definition: dropdown.h:144
bool mIsDragged
Definition: dropdown.h:157
static Image * buttons[2][2]
Definition: dropdown.h:161
SelectionListenerList mSelectionListeners
Definition: dropdown.h:151
int mPadding
Definition: dropdown.h:145
int mFoldedUpHeight
Definition: dropdown.h:148
void setListModel(ListModel *const listModel)
Definition: dropdown.cpp:520
Image * grid[9]
Definition: imagerect.h:42
void setSelected(const int selected)
Definition: popuplist.cpp:107
int getSelected() const
Definition: popuplist.cpp:115
void adjustSize()
Definition: popuplist.cpp:130
Definition: skin.h:37
int getOption(const std::string &name) const
Definition: skin.h:106
const ImageRect & getBorder() const
Definition: skin.h:68
int getPadding() const
Definition: skin.h:100
void unload(Skin *const skin)
Definition: theme.cpp:250
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
void loadRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:883
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
unsigned int mFrameSize
Definition: widget.h:1138
bool mAllowLogic
Definition: widget.h:1160
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void setHeight(const int height)
Definition: widget.cpp:140
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
friend class BasicContainer
Definition: widget.h:101
void addFocusListener(FocusListener *const focusListener)
Definition: widget.cpp:282
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
static std::string const dropdownFiles[2]
Definition: dropdown.cpp:50
Theme * theme
Definition: theme.cpp:62

References Widget::addActionListener(), Widget::addFocusListener(), Widget::addKeyListener(), Widget::addMouseListener(), adjustHeight(), PopupList::adjustSize(), buttons, CAST_U32, dropdownFiles, Skin::getBorder(), Skin::getOption(), Skin::getPadding(), PopupList::getSelected(), Widget2::getThemeColor(), Theme::getThemePath(), ImageRect::grid, instances, anonymous_namespace{itemlinkhandler.cpp}::listener, Theme::load(), Theme::loadRect(), Widget::mAllowLogic, mAlpha, Widget::mForegroundColor, Widget2::mForegroundColor2, Widget::mFrameSize, mImagePadding, mPadding, mPopup, mSkin, mSpacing, Widget::setActionEventId(), Widget::setFocusable(), Widget::setHeight(), setListModel(), PopupList::setSelected(), Widget::setWidth(), skinRect, theme, and Theme::unload().

◆ ~DropDown()

DropDown::~DropDown ( )

Definition at line 167 of file dropdown.cpp.

168 {
169  if (gui != nullptr)
170  gui->removeDragged(this);
171 
172  instances--;
173  if (instances == 0)
174  {
175  for (int f = 0; f < 2; f ++)
176  {
177  for (int i = 0; i < 2; i ++)
178  {
179  if (buttons[f][i] != nullptr)
180  buttons[f][i]->decRef();
181  }
182  }
183  if (theme != nullptr)
184  {
185  theme->unload(mSkin);
187  }
188  }
189 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:915
Gui * gui
Definition: gui.cpp:111

References buttons, gui, instances, mSkin, Gui::removeDragged(), skinRect, theme, Theme::unload(), and Theme::unloadRect().

Member Function Documentation

◆ action()

void DropDown::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Implements ActionListener.

Definition at line 535 of file dropdown.cpp.

536 {
537  foldUp();
539 }
void foldUp()
Definition: dropdown.cpp:500
void distributeActionEvent()
Definition: widget.cpp:493

References Widget::distributeActionEvent(), and foldUp().

◆ addSelectionListener()

void DropDown::addSelectionListener ( SelectionListener listener)

Definition at line 565 of file dropdown.cpp.

566 {
567  mSelectionListeners.push_back(selectionListener);
568 }

References mSelectionListeners.

◆ adjustHeight()

void DropDown::adjustHeight ( )

◆ distributeValueChangedEvent()

void DropDown::distributeValueChangedEvent ( )

Definition at line 575 of file dropdown.cpp.

576 {
578  iter != mSelectionListeners.end();
579  ++iter)
580  {
581  SelectionEvent event(this);
582  (*iter)->valueChanged(event);
583  }
584 }
SelectionListenerList::iterator SelectionListenerIterator
Definition: dropdown.h:152

References mSelectionListeners.

Referenced by updateSelection().

◆ draw()

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

Draws the widget. It is called by the parent widget when it is time for the widget to draw itself. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension.

Parameters
graphicsaA graphics object to draw with.

Implements Widget.

Definition at line 217 of file dropdown.cpp.

218 {
219  BLOCK_START("DropDown::draw")
220  int h;
221 
222  if (mDroppedDown)
223  h = mFoldedUpHeight;
224  else
225  h = mDimension.height;
226 
227  updateAlpha();
228 
229  const unsigned int alpha = CAST_U32(mAlpha * 255.0F);
230  mHighlightColor.a = alpha;
231  mShadowColor.a = alpha;
232 
233  ListModel *const model = mPopup->getListModel();
234  if ((model != nullptr) && mPopup->getSelected() >= 0)
235  {
236  Font *const font = getFont();
237  if (mExtended)
238  {
239  const int sel = mPopup->getSelected();
240  ExtendedListModel *const model2
241  = static_cast<ExtendedListModel *>(model);
242  const Image *const image = model2->getImageAt(sel);
243  if (image == nullptr)
244  {
245  font->drawString(graphics,
248  model->getElementAt(sel),
249  mPadding, mPadding);
250  }
251  else
252  {
253  graphics->drawImage(image,
255  (mDimension.height - image->getHeight()) / 2 + mPadding);
256  font->drawString(graphics,
259  model->getElementAt(sel),
260  image->getWidth() + mImagePadding + mSpacing, mPadding);
261  }
262  }
263  else
264  {
265  font->drawString(graphics,
268  model->getElementAt(mPopup->getSelected()),
269  mPadding, mPadding);
270  }
271  }
272 
273  if (isFocused())
274  {
275  const int pad = 2 * mPadding;
276  graphics->setColor(mHighlightColor);
277  graphics->drawRectangle(Rect(mPadding, mPadding,
278  mDimension.width - h - pad, h - pad));
279  }
280 
281  drawButton(graphics);
282 
283  if (mDroppedDown)
284  {
285  // Draw two lines separating the ListBox with selected
286  // element view.
287  const int w = mDimension.width;
288  graphics->setColor(mHighlightColor);
289  graphics->drawLine(0, h, w, h);
290  graphics->setColor(mShadowColor);
291  graphics->drawLine(0, h + 1, w, h + 1);
292  }
293  BLOCK_END("DropDown::draw")
294 }
int getSelected() const
Definition: dropdown.cpp:509
void updateAlpha()
Definition: dropdown.cpp:191
ListModel * getListModel()
Definition: dropdown.cpp:530
void drawButton(Graphics *const graphics)
Definition: dropdown.cpp:323
virtual const Image * getImageAt(int i)=0
Definition: font.h:90
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 drawImage(const Image *const image, int dstX, int dstY)=0
virtual void setColor(const Color &color)
Definition: graphics.h:320
virtual void drawRectangle(const Rect &rectangle)=0
virtual void drawLine(int x1, int y1, int x2, int y2)=0
Definition: rect.h:74
int width
Definition: rect.h:219
int height
Definition: rect.h:224
Rect mDimension
Definition: widget.h:1101
virtual bool isFocused() const
Definition: widget.cpp:184
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References Color::a, BLOCK_END, BLOCK_START, CAST_U32, drawButton(), Graphics::drawImage(), Graphics::drawLine(), Graphics::drawRectangle(), Font::drawString(), ListModel::getElementAt(), Widget::getFont(), ExtendedListModel::getImageAt(), PopupList::getListModel(), PopupList::getSelected(), Rect::height, Widget::isFocused(), mAlpha, Widget::mDimension, mDroppedDown, mExtended, mFoldedUpHeight, Widget::mForegroundColor, Widget2::mForegroundColor2, mHighlightColor, mImagePadding, mPadding, mPopup, mShadowColor, mSpacing, Graphics::setColor(), updateAlpha(), and Rect::width.

Referenced by safeDraw().

◆ drawButton()

void DropDown::drawButton ( Graphics *const  graphics)
protected

Draws the button with the little down arrow.

Parameters
graphicsa Graphics object to draw with.

Definition at line 323 of file dropdown.cpp.

324 {
325  Image *const image = buttons[mDroppedDown][mPushed];
326  if (image != nullptr)
327  {
328  const int height = mDroppedDown ? mFoldedUpHeight : mDimension.height;
329  graphics->drawImage(image,
330  mDimension.width - image->getWidth() - mImagePadding,
331  (height - image->getHeight()) / 2);
332  }
333 }

References buttons, Graphics::drawImage(), Rect::height, Widget::mDimension, mDroppedDown, mFoldedUpHeight, mImagePadding, mPushed, and Rect::width.

Referenced by draw().

◆ drawFrame()

void DropDown::drawFrame ( Graphics *const  graphics)
virtual

Called when a widget is given a chance to draw a frame around itself. The frame is not considered a part of the widget, it only allows a frame to be drawn around the widget, thus a frame will never be included when calculating if a widget should receive events from user input. Also a widget's frame will never be included when calculating a widget's position.

The size of the frame is calculated using the widget's frame size. If a widget has a frame size of 10 pixels than the area the drawFrame function can draw to will be the size of the widget with an additional extension of 10 pixels in each direction.

An example when drawFrame is a useful function is if a widget needs a glow around itself.

Parameters
graphicsA graphics object to draw with.
See also
setFrameSize, getFrameSize

Reimplemented from Widget.

Definition at line 301 of file dropdown.cpp.

302 {
303  BLOCK_START("DropDown::drawFrame")
304  const int bs2 = CAST_S32(getFrameSize());
305  const Rect &rect = mDimension;
306  graphics->drawImageRect(0, 0,
307  rect.width + bs2, rect.height + bs2,
308  skinRect);
310 }
#define CAST_S32
Definition: cast.h:30
void drawFrame(Graphics *const graphics)
Definition: dropdown.cpp:301
unsigned int getFrameSize() const
Definition: widget.h:184
void drawImageRect(int x, int y, int w, int h, const ImageRect &restrict imgRect) restrict2 override final

References BLOCK_END, BLOCK_START, CAST_S32, Graphics::drawImageRect(), Widget::getFrameSize(), Rect::height, Widget::mDimension, skinRect, and Rect::width.

◆ dropDown()

void DropDown::dropDown ( )

Definition at line 475 of file dropdown.cpp.

476 {
477  if (!mDroppedDown)
478  {
479  if (mParent == nullptr)
480  return;
481  mDroppedDown = true;
483  adjustHeight();
484 
485  int x = 0;
486  int y = 0;
488  const int frame = CAST_S32(mParent->getFrameSize());
489  const int pad = mPopup->getPadding();
490  const int pad2 = pad * 2;
491 
492  // here width should be adjusted on some other parameters
493  mPopup->setWidth(mDimension.width - pad2 + 8);
494  mPopup->show(x - mPadding - frame - 1, y + mDimension.height);
496  mPopup->requestFocus();
497  }
498 }
void show(int x, int y)
Definition: popuplist.cpp:82
int getPadding() const
Definition: popup.h:135
virtual void getAbsolutePosition(int &x, int &y) const
Definition: widget.cpp:312
virtual void requestMoveToTop()
Definition: widget.cpp:213
Widget * mParent
Definition: widget.h:1128
virtual void requestFocus()
Definition: widget.cpp:204

References adjustHeight(), CAST_S32, Widget::getAbsolutePosition(), Widget::getFrameSize(), Widget::getHeight(), Popup::getPadding(), Rect::height, Widget::mDimension, mDroppedDown, mFoldedUpHeight, mPadding, Widget::mParent, mPopup, Widget::requestFocus(), Widget::requestMoveToTop(), Widget::setWidth(), PopupList::show(), Rect::width, x, and y.

Referenced by keyPressed(), and mousePressed().

◆ foldUp()

void DropDown::foldUp ( )

Definition at line 500 of file dropdown.cpp.

501 {
502  if (mDroppedDown)
503  {
504  mDroppedDown = false;
505  adjustHeight();
506  }
507 }

References adjustHeight(), and mDroppedDown.

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

◆ getChildrenArea()

Rect DropDown::getChildrenArea ( )
virtual

Gets the area of the widget occupied by the widget's children. By default this method returns an empty rectangle as not all widgets are containers. If you want to make a container this method should return the area where the children resides. This method is used when drawing children of a widget when computing clip rectangles for the children.

An example of a widget that overloads this method is ScrollArea. A ScrollArea has a view of its contant and that view is the children area. The size of a ScrollArea's children area might vary depending on if the scroll bars of the ScrollArea is shown or not.

Returns
The area of the widget occupied by the widget's children.
See also
BasicContainer
BasicContainer::getChildrenArea
BasicContainer::drawChildren

Reimplemented from BasicContainer.

Definition at line 541 of file dropdown.cpp.

542 {
543  if (mDroppedDown)
544  {
545  // Calculate the children area (with the one pixel border in mind)
546  return Rect(1, mFoldedUpHeight + 1,
548  }
549 
550  return Rect();
551 }

References Rect::height, Widget::mDimension, mDroppedDown, mFoldedUpHeight, and Rect::width.

◆ getListModel()

ListModel * DropDown::getListModel ( )

Definition at line 530 of file dropdown.cpp.

531 {
532  return mPopup->getListModel();
533 }
ListModel * getListModel() const
Definition: popuplist.h:63

References PopupList::getListModel(), and mPopup.

◆ getSelected()

int DropDown::getSelected ( ) const

◆ getSelectedString()

std::string DropDown::getSelectedString ( ) const

Definition at line 461 of file dropdown.cpp.

462 {
463  ListModel *const listModel = mPopup->getListModel();
464  if (listModel == nullptr)
465  return "";
466 
467  return listModel->getElementAt(getSelected());
468 }
virtual std::string getElementAt(int i)=0

References ListModel::getElementAt(), PopupList::getListModel(), getSelected(), and mPopup.

Referenced by Setup_Theme::action(), and TextCommandEditor::save().

◆ hideDrop()

void DropDown::hideDrop ( bool  event)

Definition at line 378 of file dropdown.cpp.

379 {
380  if (event)
383 }
void setVisible(Visible visible)
Definition: widget.cpp:225
const bool Visible_false
Definition: visible.h:30

References Widget::distributeActionEvent(), mPopup, Widget::setVisible(), and Visible_false.

Referenced by mousePressed(), InventoryWindow::setVisible(), InventoryWindow::~InventoryWindow(), and LoginDialog::~LoginDialog().

◆ keyPressed()

void DropDown::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 335 of file dropdown.cpp.

336 {
337  if (event.isConsumed())
338  return;
339 
340  const InputActionT actionId = event.getActionId();
341  PRAGMA45(GCC diagnostic push)
342  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
343  switch (actionId)
344  {
347  dropDown();
348  break;
349 
350  case InputAction::GUI_UP:
351  setSelected(getSelected() - 1);
352  break;
353 
355  setSelected(getSelected() + 1);
356  break;
357 
359  setSelected(0);
360  break;
361 
363  if (mPopup->getListModel() != nullptr)
364  {
366  getNumberOfElements() - 1);
367  }
368  break;
369 
370  default:
371  return;
372  }
373  PRAGMA45(GCC diagnostic pop)
374 
375  event.consume();
376 }
void setSelected(int selected)
Definition: dropdown.cpp:514
void dropDown()
Definition: dropdown.cpp:475
bool isConsumed() const
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wredundant-decls") PRAGMA45(GCC diagnostic pop) class TestMain
InputAction ::T InputActionT
Definition: inputaction.h:717

References dropDown(), PopupList::getListModel(), getSelected(), InputAction::GUI_DOWN, InputAction::GUI_END, InputAction::GUI_HOME, InputAction::GUI_SELECT, InputAction::GUI_SELECT2, InputAction::GUI_UP, InputGuiEvent::isConsumed(), mPopup, PRAGMA45(), and setSelected().

◆ mouseDragged()

void DropDown::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.

Definition at line 427 of file dropdown.cpp.

428 {
429  mIsDragged = true;
430  event.consume();
431 }

References mIsDragged.

◆ mousePressed()

void DropDown::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.

Definition at line 385 of file dropdown.cpp.

386 {
387  event.consume();
388  // If we have a mouse press on the widget.
389  if (event.getButton() == MouseButton::LEFT
390  && !mDroppedDown && event.getSource() == this)
391  {
392  mPushed = true;
393  dropDown();
394  }
395  else
396  {
397  mPushed = false;
398  foldUp();
399  hideDrop(true);
400  }
401 }
void hideDrop(bool event)
Definition: dropdown.cpp:378
Widget * getSource() const
Definition: event.h:104
MouseButtonT getButton() const
Definition: mouseevent.h:116

References dropDown(), foldUp(), MouseEvent::getButton(), Event::getSource(), hideDrop(), MouseButton::LEFT, mDroppedDown, and mPushed.

◆ mouseReleased()

void DropDown::mouseReleased ( MouseEvent event)
virtual

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

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 403 of file dropdown.cpp.

404 {
405  if (mIsDragged)
406  mPushed = false;
407 
408  const MouseButtonT button = event.getButton();
409  const int x = event.getX();
410  const int y = event.getY();
411  // Released outside of widget. Can happen when we have modal
412  // input focus.
413  if ((0 > y || y >= mDimension.height || x < 0 || x >= mDimension.width)
414  && button == MouseButton::LEFT)
415  {
416  if (mIsDragged)
417  foldUp();
418  }
419  else if (button == MouseButton::LEFT)
420  {
421  mPushed = false;
422  }
423 
424  mIsDragged = false;
425 }
MouseButton ::T MouseButtonT
Definition: mousebutton.h:78

References foldUp(), Rect::height, MouseButton::LEFT, Widget::mDimension, mIsDragged, mPushed, Rect::width, x, and y.

◆ mouseWheelMovedDown()

void DropDown::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 439 of file dropdown.cpp.

440 {
441  setSelected(getSelected() + 1);
442  event.consume();
443 }

References getSelected(), and setSelected().

◆ mouseWheelMovedUp()

void DropDown::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 433 of file dropdown.cpp.

434 {
435  setSelected(getSelected() - 1);
436  event.consume();
437 }

References getSelected(), and setSelected().

◆ removeSelectionListener()

void DropDown::removeSelectionListener ( SelectionListener selectionListener)

Definition at line 570 of file dropdown.cpp.

571 {
573 }

References anonymous_namespace{itemlinkhandler.cpp}::listener, and mSelectionListeners.

◆ safeDraw()

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

Implements Widget.

Definition at line 296 of file dropdown.cpp.

297 {
298  DropDown::draw(graphics);
299 }
void draw(Graphics *const graphics)
Definition: dropdown.cpp:217

References draw().

◆ safeDrawFrame()

void DropDown::safeDrawFrame ( Graphics *const  graphics)
virtual

Reimplemented from Widget.

Definition at line 312 of file dropdown.cpp.

313 {
314  BLOCK_START("DropDown::drawFrame")
315  const int bs2 = CAST_S32(getFrameSize());
316  const Rect &rect = mDimension;
317  graphics->drawImageRect(0, 0,
318  rect.width + bs2, rect.height + bs2,
319  skinRect);
321 }

References BLOCK_END, BLOCK_START, CAST_S32, Graphics::drawImageRect(), Widget::getFrameSize(), Rect::height, Widget::mDimension, skinRect, and Rect::width.

◆ setListModel()

void DropDown::setListModel ( ListModel *const  listModel)

Definition at line 520 of file dropdown.cpp.

521 {
522  mPopup->setListModel(listModel);
523 
524  if (mPopup->getSelected() < 0)
525  mPopup->setSelected(0);
526 
527  adjustHeight();
528 }
void setListModel(ListModel *const model)
Definition: popuplist.cpp:123

References adjustHeight(), PopupList::getSelected(), mPopup, PopupList::setListModel(), and PopupList::setSelected().

Referenced by DropDown().

◆ setSelected()

void DropDown::setSelected ( int  selected)

◆ setSelectedString()

void DropDown::setSelectedString ( const std::string &  str)

Definition at line 445 of file dropdown.cpp.

446 {
447  ListModel *const listModel = mPopup->getListModel();
448  if (listModel == nullptr)
449  return;
450 
451  for (int f = 0; f < listModel->getNumberOfElements(); f ++)
452  {
453  if (listModel->getElementAt(f) == str)
454  {
455  setSelected(f);
456  break;
457  }
458  }
459 }
virtual int getNumberOfElements()=0

References ListModel::getElementAt(), PopupList::getListModel(), ListModel::getNumberOfElements(), mPopup, and setSelected().

Referenced by LoginDialog::LoginDialog(), Setup_Theme::Setup_Theme(), and TextCommandEditor::TextCommandEditor().

◆ updateAlpha()

void DropDown::updateAlpha ( )

Update the alpha value to the graphic components.

Definition at line 191 of file dropdown.cpp.

192 {
193  const float alpha = std::max(settings.guiAlpha,
195 
196  if (mAlpha != alpha)
197  {
198  mAlpha = alpha;
199 
200  if (buttons[0][0] != nullptr)
201  buttons[0][0]->setAlpha(mAlpha);
202  if (buttons[0][1] != nullptr)
203  buttons[0][1]->setAlpha(mAlpha);
204  if (buttons[1][0] != nullptr)
205  buttons[1][0]->setAlpha(mAlpha);
206  if (buttons[1][1] != nullptr)
207  buttons[1][1]->setAlpha(mAlpha);
208 
209  for (int a = 0; a < 9; a++)
210  {
211  if (skinRect.grid[a] != nullptr)
212  skinRect.grid[a]->setAlpha(mAlpha);
213  }
214  }
215 }
float guiAlpha
Definition: settings.h:131
float getMinimumOpacity() const
Definition: theme.h:124
Settings settings
Definition: settings.cpp:32

References buttons, Theme::getMinimumOpacity(), ImageRect::grid, Settings::guiAlpha, mAlpha, settings, skinRect, and theme.

Referenced by draw().

◆ updateSelection()

void DropDown::updateSelection ( )

Definition at line 557 of file dropdown.cpp.

558 {
559  mDroppedDown = false;
560  mPushed = false;
563 }
void distributeValueChangedEvent()
Definition: dropdown.cpp:575

References Widget::distributeActionEvent(), distributeValueChangedEvent(), mDroppedDown, and mPushed.

Referenced by PopupList::focusGained(), PopupList::focusLost(), and PopupList::mouseReleased().

◆ valueChanged()

void DropDown::valueChanged ( const SelectionEvent event)
virtual

Called when the value of a selection has been changed in a Widget. It is used to be able to recieve a notification that a value has been changed.

Parameters
eventThe event of the value change.

Reimplemented from SelectionListener.

Definition at line 553 of file dropdown.cpp.

554 {
555 }

Field Documentation

◆ buttons

Image * DropDown::buttons
staticprotected

Definition at line 161 of file dropdown.h.

Referenced by drawButton(), DropDown(), updateAlpha(), and ~DropDown().

◆ instances

int DropDown::instances = 0
staticprotected

Definition at line 160 of file dropdown.h.

Referenced by DropDown(), and ~DropDown().

◆ mAlpha

float DropDown::mAlpha = 1.0
staticprotected

Definition at line 163 of file dropdown.h.

Referenced by draw(), DropDown(), and updateAlpha().

◆ mDroppedDown

bool DropDown::mDroppedDown
protected

◆ mExtended

bool DropDown::mExtended
protected

Definition at line 154 of file dropdown.h.

Referenced by draw().

◆ mFoldedUpHeight

int DropDown::mFoldedUpHeight
protected

Definition at line 148 of file dropdown.h.

Referenced by draw(), drawButton(), dropDown(), and getChildrenArea().

◆ mHighlightColor

Color DropDown::mHighlightColor
protected

Definition at line 144 of file dropdown.h.

Referenced by draw().

◆ mImagePadding

int DropDown::mImagePadding
protected

Definition at line 146 of file dropdown.h.

Referenced by draw(), drawButton(), and DropDown().

◆ mIsDragged

bool DropDown::mIsDragged
protected

Definition at line 157 of file dropdown.h.

Referenced by mouseDragged(), and mouseReleased().

◆ mPadding

int DropDown::mPadding
protected

Definition at line 145 of file dropdown.h.

Referenced by adjustHeight(), draw(), dropDown(), and DropDown().

◆ mPopup

PopupList* DropDown::mPopup
protected

◆ mPushed

bool DropDown::mPushed
protected

Definition at line 156 of file dropdown.h.

Referenced by drawButton(), mousePressed(), mouseReleased(), and updateSelection().

◆ mSelectionListeners

SelectionListenerList DropDown::mSelectionListeners
protected

◆ mShadowColor

Color DropDown::mShadowColor
protected

Definition at line 143 of file dropdown.h.

Referenced by draw().

◆ mSkin

Skin * DropDown::mSkin = 0
staticprotected

Definition at line 164 of file dropdown.h.

Referenced by DropDown(), and ~DropDown().

◆ mSpacing

int DropDown::mSpacing
protected

Definition at line 147 of file dropdown.h.

Referenced by draw(), and DropDown().

◆ skinRect

ImageRect DropDown::skinRect
staticprotected

Definition at line 162 of file dropdown.h.

Referenced by drawFrame(), DropDown(), safeDrawFrame(), updateAlpha(), and ~DropDown().


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