ManaPlus
dropdown.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2006-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_WIDGETS_DROPDOWN_H
25 #define GUI_WIDGETS_DROPDOWN_H
26 
28 
30 
33 #include "listeners/keylistener.h"
36 
37 #include "localconsts.h"
38 
39 class Image;
40 class ListModel;
41 class PopupList;
42 class Skin;
43 
51 class DropDown final : public ActionListener,
52  public BasicContainer,
53  public KeyListener,
54  public MouseListener,
55  public FocusListener,
56  public SelectionListener
57 {
58  public:
59  DropDown(const Widget2 *const widget,
60  ListModel *const listModel,
61  const bool extended,
62  const Modal modal,
63  ActionListener *const listener,
64  const std::string &eventId);
65 
67 
68  ~DropDown() override final;
69 
73  void updateAlpha();
74 
75  void draw(Graphics *const graphics) override final A_NONNULL(2);
76 
77  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
78 
79  void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
80 
81  void safeDrawFrame(Graphics *const graphics) override final
82  A_NONNULL(2);
83 
84  // Inherited from KeyListener
85 
86  void keyPressed(KeyEvent& event) override final;
87 
88  // Inherited from MouseListener
89 
90  void mousePressed(MouseEvent& event) override final;
91 
92  void mouseReleased(MouseEvent& event) override final;
93 
94  void mouseDragged(MouseEvent& event) override final;
95 
96  void mouseWheelMovedUp(MouseEvent& event) override final;
97 
98  void mouseWheelMovedDown(MouseEvent& event) override final;
99 
100  void setSelectedString(const std::string &str);
101 
102  std::string getSelectedString() const A_WARN_UNUSED;
103 
104  void valueChanged(const SelectionEvent& event) override final;
105 
106  void updateSelection();
107 
108  void adjustHeight();
109 
110  void dropDown();
111 
112  void foldUp();
113 
114  void hideDrop(bool event);
115 
116  int getSelected() const;
117 
118  void setSelected(int selected);
119 
120  void setListModel(ListModel *const listModel);
121 
123 
125 
126  void removeSelectionListener(SelectionListener* selectionListener);
127 
128  Rect getChildrenArea() override;
129 
130  void action(const ActionEvent &actionEvent) override;
131 
133 
134  protected:
140  void drawButton(Graphics *const graphics) A_NONNULL(2);
141 
145  int mPadding;
147  int mSpacing;
149 
150  typedef std::list<SelectionListener*> SelectionListenerList;
152  typedef SelectionListenerList::iterator SelectionListenerIterator;
153 
154  bool mExtended;
156  bool mPushed;
158 
159  // Add own Images.
160  static int instances;
161  static Image *buttons[2][2];
163  static float mAlpha;
164  static Skin *mSkin;
165 };
166 
167 #endif // GUI_WIDGETS_DROPDOWN_H
Definition: color.h:76
static Skin * mSkin
Definition: dropdown.h:164
bool mExtended
Definition: dropdown.h:154
std::string getSelectedString() const
Definition: dropdown.cpp:461
static int instances
Definition: dropdown.h:160
bool mDroppedDown
Definition: dropdown.h:155
int getSelected() const
Definition: dropdown.cpp:509
void drawFrame(Graphics *const graphics)
Definition: dropdown.cpp:301
bool mPushed
Definition: dropdown.h:156
void adjustHeight()
Definition: dropdown.cpp:470
int mSpacing
Definition: dropdown.h:147
void hideDrop(bool event)
Definition: dropdown.cpp:378
void action(const ActionEvent &actionEvent)
Definition: dropdown.cpp:535
void setSelected(int selected)
Definition: dropdown.cpp:514
void removeSelectionListener(SelectionListener *selectionListener)
Definition: dropdown.cpp:570
void valueChanged(const SelectionEvent &event)
Definition: dropdown.cpp:553
Color mShadowColor
Definition: dropdown.h:143
void keyPressed(KeyEvent &event)
Definition: dropdown.cpp:335
SelectionListenerList::iterator SelectionListenerIterator
Definition: dropdown.h:152
PopupList * mPopup
Definition: dropdown.h:142
Rect getChildrenArea()
Definition: dropdown.cpp:541
int mImagePadding
Definition: dropdown.h:146
void updateAlpha()
Definition: dropdown.cpp:191
void draw(Graphics *const graphics)
Definition: dropdown.cpp:217
void mousePressed(MouseEvent &event)
Definition: dropdown.cpp:385
static ImageRect skinRect
Definition: dropdown.h:162
void safeDraw(Graphics *const graphics)
Definition: dropdown.cpp:296
static float mAlpha
Definition: dropdown.h:163
Color mHighlightColor
Definition: dropdown.h:144
ListModel * getListModel()
Definition: dropdown.cpp:530
void mouseWheelMovedUp(MouseEvent &event)
Definition: dropdown.cpp:433
bool mIsDragged
Definition: dropdown.h:157
static Image * buttons[2][2]
Definition: dropdown.h:161
void dropDown()
Definition: dropdown.cpp:475
SelectionListenerList mSelectionListeners
Definition: dropdown.h:151
void mouseDragged(MouseEvent &event)
Definition: dropdown.cpp:427
std::list< SelectionListener * > SelectionListenerList
Definition: dropdown.h:150
void updateSelection()
Definition: dropdown.cpp:557
int mPadding
Definition: dropdown.h:145
void safeDrawFrame(Graphics *const graphics)
Definition: dropdown.cpp:312
int mFoldedUpHeight
Definition: dropdown.h:148
void setListModel(ListModel *const listModel)
Definition: dropdown.cpp:520
void foldUp()
Definition: dropdown.cpp:500
void drawButton(Graphics *const graphics)
Definition: dropdown.cpp:323
void mouseWheelMovedDown(MouseEvent &event)
Definition: dropdown.cpp:439
DropDown(const Widget2 *const widget, ListModel *const listModel, const bool extended, const Modal modal, ActionListener *const listener, const std::string &eventId)
Definition: dropdown.cpp:56
void distributeValueChangedEvent()
Definition: dropdown.cpp:575
void mouseReleased(MouseEvent &event)
Definition: dropdown.cpp:403
void setSelectedString(const std::string &str)
Definition: dropdown.cpp:445
void addSelectionListener(SelectionListener *listener)
Definition: dropdown.cpp:565
Definition: rect.h:74
Definition: skin.h:37
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
bool Modal
Definition: modal.h:30